//
#include "XGUI_DataModel.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_ObjectsBrowser.h"
+#include "XGUI_Displayer.h"
#include <ModuleBase_IconFactory.h>
XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)//,
//myIsEventsProcessingBlocked(false)
{
+ XGUI_ObjectsBrowser* aOB = qobject_cast<XGUI_ObjectsBrowser*>(theParent);
+ myWorkshop = aOB->workshop();
+
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
} else {
int aFolderId = myXMLReader->rootFolderId(aObjType);
if (aFolderId != -1) {
- insertRow(aRow, createIndex(aFolderId, 0, (void*)Q_NULLPTR));
+ insertRow(aRow, createIndex(aFolderId, 1, (void*)Q_NULLPTR));
}
}
}
if (aRow != -1) {
int aFolderId = folderId(aObjType, aDoc.get());
if (aFolderId != -1) {
- QModelIndex aParentFolder = createIndex(aFolderId, 0, aDoc.get());
+ QModelIndex aParentFolder = createIndex(aFolderId, 1, aDoc.get());
insertRow(aRow, aParentFolder);
emit dataChanged(aParentFolder, aParentFolder);
}
// Process root sub-folder
int aFolderId = myXMLReader->rootFolderId(aGroup);
if (aFolderId != -1) {
- QModelIndex aFolderIndex = createIndex(aFolderId, 0, (void*)Q_NULLPTR);
+ QModelIndex aFolderIndex = createIndex(aFolderId, 1, (void*)Q_NULLPTR);
removeRow(aRow, aFolderIndex);
//rebuildBranch(0, aRow);
}
// List of objects under a folder
int aFolderId = folderId(aGroup, aDoc.get());
if (aFolderId != -1) {
- QModelIndex aFolderRoot = createIndex(aFolderId, 0, aDoc.get());
+ QModelIndex aFolderRoot = createIndex(aFolderId, 1, aDoc.get());
removeRow(aRow, aFolderRoot);
//rebuildBranch(0, aRow, aFolderRoot);
}
if (aGroup == myXMLReader->rootType()) // Update objects under root
aStartId = foldersCount();
else // Update objects in folder under root
- aParent = createIndex(folderId(aGroup), 0, (void*)Q_NULLPTR);
+ aParent = createIndex(folderId(aGroup), 1, (void*)Q_NULLPTR);
} else {
// Update a sub-document
if (aGroup == myXMLReader->subType()) {
aStartId = foldersCount(aDoc.get());
} else
// update folder in sub-document
- aParent = createIndex(folderId(aGroup, aDoc.get()), 0, aDoc.get());
+ aParent = createIndex(folderId(aGroup, aDoc.get()), 1, aDoc.get());
}
int aChildNb = rowCount(aParent);
rebuildBranch(aStartId, aChildNb - aStartId, aParent);
}
//******************************************************
-QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject) const
+QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn) const
{
std::string aType = theObject->groupName();
DocumentPtr aDoc = theObject->document();
if (aRow == -1)
return QModelIndex();
else
- return createIndex(aRow, 0, theObject.get());
+ return createIndex(aRow, theColumn, theObject.get());
}
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
// The object from sub document
aRow += foldersCount(aDoc.get());
}
- return createIndex(aRow, 0, theObject.get());
+ return createIndex(aRow, theColumn, theObject.get());
}
//******************************************************
int aNbFolders = foldersCount();
int theIndexRow = theIndex.row();
- if ((theRole == Qt::DecorationRole) && (theIndex == lastHistoryIndex()))
- return QIcon(":pictures/arrow.png");
+ if (theRole == Qt::DecorationRole) {
+ if (theIndex == lastHistoryIndex())
+ return QIcon(":pictures/arrow.png");
+ else if (theIndex.column() == 0) {
+ VisibilityState aState = getVisibilityState(theIndex);
+ switch (aState) {
+ case NoneState:
+ return QIcon();
+ case Visible:
+ return QIcon(":pictures/eyeopen.png");
+ case SemiVisible:
+ return QIcon(":pictures/eyemiclosed.png");
+ case Hidden:
+ return QIcon(":pictures/eyeclosed.png");
+ }
+ }
+ }
- if (theIndex.column() == 1)
+ //if (theIndex.column() == 1)
+ if (theIndex.column() != 1)
return QVariant();
quintptr aParentId = theIndex.internalId();
//******************************************************
int XGUI_DataModel::columnCount(const QModelIndex& theParent) const
{
- return 2;
+ return 3;
}
//******************************************************
int aObjId = theRow - aNbFolders;
if (aObjId < aRootDoc->size(aType)) {
ObjectPtr aObj = aRootDoc->object(aType, aObjId);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
}
} else {
std::string aType = myXMLReader->rootFolderType(aParentPos);
if (theRow < aRootDoc->size(aType)) {
ObjectPtr aObj = aRootDoc->object(aType, theRow);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
} else {
// It is an object which could have children
std::string aType = myXMLReader->subFolderType(aParentRow);
if (theRow < aDoc->size(aType)) {
ObjectPtr aObj = aDoc->object(aType, theRow);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
}
} else {
// this is an object under sub document root
std::string aType = myXMLReader->subType();
ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
} else {
// Check for composite object
ModelAPI_CompositeFeature* aCompFeature =
dynamic_cast<ModelAPI_CompositeFeature*>(aParentObj);
if (aCompFeature) {
- aIndex = objectIndex(aCompFeature->subFeature(theRow));
+ aIndex = objectIndex(aCompFeature->subFeature(theRow), theColumn);
} else {
ModelAPI_ResultCompSolid* aCompRes =
dynamic_cast<ModelAPI_ResultCompSolid*>(aParentObj);
if (aCompRes)
- aIndex = objectIndex(aCompRes->subResult(theRow));
+ aIndex = objectIndex(aCompRes->subResult(theRow), theColumn);
else {
ModelAPI_ResultField* aFieldRes =
dynamic_cast<ModelAPI_ResultField*>(aParentObj);
if (aFieldRes) {
- aIndex = createIndex(theRow, 0, aFieldRes->step(theRow));
+ aIndex = createIndex(theRow, theColumn, aFieldRes->step(theRow));
}
}
}
}
}
}
- if (theColumn != 0)
- return createIndex(aIndex.row(), theColumn, aIndex.internalPointer());
return aIndex;
}
// return first level of folder index
int aFolderId = myXMLReader->rootFolderId(aType);
// Items in a one row must have the same parent
- return createIndex(aFolderId, 0, (void*)Q_NULLPTR);
+ return createIndex(aFolderId, 1, (void*)Q_NULLPTR);
}
} else {
if (aType == myXMLReader->subType())
// return first level of folder index
int aFolderId = folderId(aType, aSubDoc.get());
// Items in a one row must have the same parent
- return createIndex(aFolderId, 0, aSubDoc.get());
+ return createIndex(aFolderId, 1, aSubDoc.get());
}
}
}
if (aObj) {
// An object
if (aObj->isDisabled())
- return theIndex.column() == 1? Qt::ItemIsSelectable : aNullFlag;
+ return theIndex.column() == 2? Qt::ItemIsSelectable : aNullFlag;
if (aSession->moduleDocument() != aObj->document())
if (aActiveDoc != aObj->document())
- return theIndex.column() == 1? Qt::ItemIsSelectable : aNullFlag;
+ return theIndex.column() == 2? Qt::ItemIsSelectable : aNullFlag;
bool isCompositeSub = false;
- // An object which is sub-object of a composite object can not be accessible in column 1
- if (theIndex.column() == 1) {
+ // An object which is sub-object of a composite object can not be accessible in column 2
+ if (theIndex.column() == 2) {
ObjectPtr aObjPtr = aObj->data()->owner();
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjPtr);
if (aFeature.get()) {
}
//******************************************************
-QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc) const
+QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc, int aColumn) const
{
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
if (myXMLReader->rootType() == ModelAPI_Feature::group()) {
aRow += foldersCount();
}
- return createIndex(aRow, 0, aObj.get());
+ return createIndex(aRow, aColumn, aObj.get());
}
}
} else { // If document is attached to feature
int aRow = i;
if (myXMLReader->rootType() == ModelAPI_Feature::group())
aRow += foldersCount();
- return createIndex(aRow, 0, aObj.get());
+ return createIndex(aRow, aColumn, aObj.get());
}
}
}
}
//******************************************************
-QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc) const
+QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc, int theColumn) const
{
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
if (theDoc == aRootDoc)
return QModelIndex();
else
- return findDocumentRootIndex(theDoc.get());
+ return findDocumentRootIndex(theDoc.get(), theColumn);
}
//******************************************************
FeaturePtr aFeature = aCurDoc->currentFeature(true);
if (aFeature.get()) {
QModelIndex aInd = objectIndex(aFeature);
- return createIndex(aInd.row(), 1, aInd.internalPointer());
+ return createIndex(aInd.row(), 2, aInd.internalPointer());
} else {
if (aCurDoc == aSession->moduleDocument())
- return createIndex(foldersCount() - 1, 1, -1);
+ return createIndex(foldersCount() - 1, 2, -1);
else
- return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get());
+ return createIndex(foldersCount(aCurDoc.get()) - 1, 2, aCurDoc.get());
}
}
// myIsEventsProcessingBlocked = theState;
// return aPreviousState;
//}
+
+//******************************************************
+XGUI_DataModel::VisibilityState
+ XGUI_DataModel::getVisibilityState(const QModelIndex& theIndex) const
+{
+ ObjectPtr aObj = object(theIndex);
+ if (aObj.get()) {
+ ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ if (aResObj.get()) {
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
+ if (aCompRes.get()) {
+ VisibilityState aState = NoneState;
+ for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
+ ResultPtr aSubRes = aCompRes->subResult(i, true);
+ VisibilityState aS = aDisplayer->isVisible(aSubRes)? Visible : Hidden;
+ if (aState == NoneState)
+ aState = aS;
+ else if (aState != aS) {
+ aState = SemiVisible;
+ break;
+ }
+ }
+ return aState;
+ } else {
+ if (aDisplayer->isVisible(aResObj))
+ return Visible;
+ else
+ return Hidden;
+ }
+ }
+ }
+ return NoneState;
+}
#include <QStyledItemDelegate>
#include <QMessageBox>
+#ifdef DEBUG_INDXES
+#include <QToolTip>
+#endif
/// Width of second column (minimum acceptable = 27)
+#define FIRST_COL_WIDTH 30
#define SECOND_COL_WIDTH 30
: QTreeView(theParent)
{
setHeaderHidden(true);
+ setTreePosition(1);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::ExtendedSelection);
- setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this));
+ setItemDelegateForColumn(1, new XGUI_TreeViewItemDelegate(this));
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
SLOT(onDoubleClick(const QModelIndex&)));
QTreeView::resizeEvent(theEvent);
QSize aSize = theEvent->size();
if (aSize.isValid()) {
- setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH - 7);
- setColumnWidth(1, SECOND_COL_WIDTH);
+ setColumnWidth(0, FIRST_COL_WIDTH);
+ setColumnWidth(1, aSize.width() - SECOND_COL_WIDTH - FIRST_COL_WIDTH - 12);
+ setColumnWidth(2, SECOND_COL_WIDTH);
}
}
-void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
+#ifdef DEBUG_INDXES
+void XGUI_DataTree::mousePressEvent(QMouseEvent* theEvent)
{
- if (theIndex.column() != 1)
+ QTreeView::mousePressEvent(theEvent);
+ if (theEvent->button() != Qt::MidButton)
return;
+ QModelIndex aInd = indexAt(theEvent->pos());
+ QString aTxt = QString("r=%1 c=%2 p=%3").arg(aInd.row()).arg(aInd.column()).arg((long)aInd.internalPointer());
+
+ QModelIndex aPar = aInd.parent();
+ QString aTxt1 = QString("r=%1 c=%2 p=%3").arg(aPar.row()).arg(aPar.column()).arg((long)aPar.internalPointer());
+ QToolTip::showText(theEvent->globalPos(), aTxt + '\n' + aTxt1);
+}
+#endif
+
+void XGUI_DataTree::mouseReleaseEvent(QMouseEvent* theEvent)
+{
+ QTreeView::mouseReleaseEvent(theEvent);
+#ifdef DEBUG_INDXES
+ if (theEvent->button() != Qt::MidButton)
+ return;
+ QToolTip::hideText();
+#endif
+ if (theEvent->button() == Qt::LeftButton) {
+ QModelIndex aInd = indexAt(theEvent->pos());
+ if (aInd.column() == 0)
+ processEyeClick(aInd);
+ }
+}
+
+void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex)
+{
SessionPtr aMgr = ModelAPI_Session::get();
// When operation is opened then we can not change history
if (aMgr->isOperation())
for (int i = 0; i < aSize; i++) {
update(aModel->index(i, 0, aParent));
update(aModel->index(i, 1, aParent));
+ update(aModel->index(i, 2, aParent));
+ }
+}
+
+void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex)
+{
+ XGUI_DataModel* aModel = dataModel();
+ ObjectPtr aObj = aModel->object(theIndex);
+ if (aObj.get()) {
+ ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ if (aResObj.get()) {
+ aResObj->setDisplayed(!aResObj->isDisplayed());
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ update(theIndex);
+ }
+ // Update list of selected objects because this event happens after selection event in object browser
+ XGUI_ObjectsBrowser* aObjBrowser = qobject_cast<XGUI_ObjectsBrowser*>(parent());
+ if (aObjBrowser) {
+ aObjBrowser->onSelectionChanged();
+ }
+ }
+}
+
+void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
+{
+ switch (theIndex.column()) {
+ case 2:
+ processHistoryChange(theIndex);
+ break;
}
}
//********************************************************************
//********************************************************************
//********************************************************************
-XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
- : QWidget(theParent), myDocModel(0)
+XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop)
+ : QWidget(theParent), myDocModel(0), myWorkshop(theWorkshop)
{
QVBoxLayout* aLayout = new QVBoxLayout(this);
ModuleBase_Tools::zeroMargins(aLayout);
myTreeView->clear();
}
+//***************************************************
void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
const QItemSelection& theDeselected)
+{
+ onSelectionChanged();
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::onSelectionChanged()
{
emit selectionChanged();
}
+//***************************************************
QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const
{
QObjectPtrList aList;
XGUI_DataModel* aModel = dataModel();
QModelIndexList::const_iterator aIt;
for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
- if ((*aIt).column() == 0) {
+ if ((*aIt).column() == 1) {
ObjectPtr aObject = aModel->object(*aIt);
if (aObject) {
aList.append(aObject);
QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
int aNbChild = aModel->rowCount(aRootIdx);
for (int i = 0; i < aNbChild; i++) {
- QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
+ QModelIndex aIdx = aModel->index(i, 1, aRootIdx);
aStates.push_back(myTreeView->isExpanded(aIdx));
}
return aStates;