From: vsv Date: Thu, 6 Sep 2018 10:55:09 +0000 (+0300) Subject: Issue #2625: Provide correct behavior of arrow of current feature X-Git-Tag: V9_2_0a1~55 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8949ea64bcce6c1ce9f5694523f3ad427255dff6;p=modules%2Fshaper.git Issue #2625: Provide correct behavior of arrow of current feature --- diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index a57bb1775..bf050f723 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -440,6 +440,20 @@ QVariant PartSet_FolderNode::data(int theColumn, int theRole) const } } } + if ((theColumn == 2) && (theRole == Qt::DecorationRole)) { + FeaturePtr aFeature = document()->currentFeature(true); + if (!aFeature.get()) { // There is no current feature + ModuleBase_ITreeNode* aLastFolder = 0; + foreach(ModuleBase_ITreeNode* aNode, parent()->children()) { + if (aNode->type() == PartSet_FolderNode::typeId()) + aLastFolder = aNode; + else + break; + } + if (aLastFolder == this) + return QIcon(":pictures/arrow.png"); + } + } return PartSet_TreeNode::data(theColumn, theRole); } @@ -910,10 +924,6 @@ QVariant PartSet_PartRootNode::data(int theColumn, int theRole) const case Qt::DecorationRole: return ModuleBase_IconFactory::get()->getIcon(myObject); } - case 2: - if (theRole == Qt::DecorationRole) - if (isCurrentFeature(myObject)) - return QIcon(":pictures/arrow.png"); } return PartSet_TreeNode::data(theColumn, theRole); } @@ -1007,37 +1017,42 @@ void PartSet_ObjectFolderNode::update() } DocumentPtr aDoc = myObject->document(); - // Delete obsolete nodes - int aId = 0; - while (aId < myChildren.size()) { - ModuleBase_ITreeNode* aNode = myChildren.at(aId); - if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) { - if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) { + if (aNbItems < myChildren.size()) { + // Delete obsolete nodes + int aId = 0; + int aNbOfFeatures = aDoc->size(ModelAPI_Feature::group(), true); + while (aId < myChildren.size()) { + ModuleBase_ITreeNode* aNode = myChildren.at(aId); + if ((aFirst + aId) < aNbOfFeatures) { + if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) { + myChildren.removeAll(aNode); + delete aNode; + continue; + } + } + else { myChildren.removeAll(aNode); delete aNode; continue; } + aId++; } - else { - myChildren.removeAll(aNode); - delete aNode; - continue; - } - aId++; } - - // Add new nodes - ModuleBase_ITreeNode* aNode; - for (int i = 0; i < aNbItems; i++) { - ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i); - if (i < myChildren.size()) { - if (aObj != myChildren.at(i)->object()) { + if (aNbItems > myChildren.size()) { + // Add new nodes + ModuleBase_ITreeNode* aNode; + for (int i = 0; i < aNbItems; i++) { + ObjectPtr aObj = aDoc->object(ModelAPI_Feature::group(), aFirst + i); + if (i < myChildren.size()) { + if (aObj != myChildren.at(i)->object()) { + aNode = new PartSet_ObjectNode(aObj, this); + myChildren.insert(i, aNode); + } + } + else { aNode = new PartSet_ObjectNode(aObj, this); - myChildren.insert(i, aNode); + myChildren.append(aNode); } - } else { - aNode = new PartSet_ObjectNode(aObj, this); - myChildren.append(aNode); } } } @@ -1087,13 +1102,17 @@ QTreeNodesList PartSet_ObjectFolderNode::objectsDeleted(const DocumentPtr& theDo if (!aNbItems) { return aResult; } + if (aNbItems >= myChildren.size()) // Nothing was deleted here + return aResult; + DocumentPtr aDoc = myObject->document(); // Delete obsolete nodes bool aRemoved = false; int aId = 0; + int aNbOfFeatures = aDoc->size(ModelAPI_Feature::group(), true); while (aId < myChildren.size()) { ModuleBase_ITreeNode* aNode = myChildren.at(aId); - if ((aFirst + aId) < aDoc->size(ModelAPI_Feature::group(), true)) { + if ((aFirst + aId) < aNbOfFeatures) { if (aNode->object() != aDoc->object(ModelAPI_Feature::group(), aFirst + aId)) { myChildren.removeAll(aNode); delete aNode; diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index b31e32f36..4528e5595 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -392,3 +392,11 @@ void XGUI_DataModel::updateSubTree(ModuleBase_ITreeNode* theParent) dataChanged(aFirstIdx, aLastIdx); } } + + +//****************************************************** +DocumentPtr XGUI_DataModel::document(const QModelIndex& theIndex) const +{ + ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer(); + return aNode->document(); +} diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 5e446bf0e..929f3afb3 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -156,6 +156,8 @@ public: /// \param theIndex an index to check bool hasIndex(const QModelIndex& theIndex) const; + DocumentPtr document(const QModelIndex& theIndex) const; + signals: /// Signal about tree had been rebuilt void treeRebuilt(); diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index ff78af48c..4cb07f5b2 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -211,7 +211,7 @@ void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex) if ((theIndex.internalId() == 0) && (aDoc != aMgr->moduleDocument())) // Clicked folder under root but active document is another return; - if ((theIndex.internalId() != 0) && (aDoc.get() != theIndex.internalPointer())) + if ((theIndex.internalId() != 0) && (aDoc != aModel->document(theIndex))) // Cliced not on active document folder return;