From: vsv Date: Thu, 19 Jul 2018 14:44:36 +0000 (+0300) Subject: Improvement of the structure X-Git-Tag: SHAPER_V9_1_0RC1~73^2~58 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=19bb05de476981034a5e78bb07336bb6a208ba04;p=modules%2Fshaper.git Improvement of the structure --- diff --git a/src/ModuleBase/ModuleBase_ITreeNode.h b/src/ModuleBase/ModuleBase_ITreeNode.h index 9e33eeae5..ffb697672 100644 --- a/src/ModuleBase/ModuleBase_ITreeNode.h +++ b/src/ModuleBase/ModuleBase_ITreeNode.h @@ -132,6 +132,22 @@ public: virtual ModuleBase_ITreeNode* findParent(const DocumentPtr& theDoc, QString theGroup) { return 0; } + /// Returns root node of a data tree of the given document + /// \param theDoc a document + /// \return a tree node which is a root of the document structure + virtual ModuleBase_ITreeNode* findRoot(const DocumentPtr& theDoc) + { + if (document() == theDoc) + return this; + ModuleBase_ITreeNode* aRoot; + foreach(ModuleBase_ITreeNode* aNode, myChildren) { + aRoot = aNode->findRoot(theDoc); + if (aRoot) + return aRoot; + } + return 0; + } + protected: ModuleBase_ITreeNode* myParent; //!< Parent of the node QTreeNodesList myChildren; //!< Children of the node diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index d8fd37391..dd78f272b 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -117,8 +117,10 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess std::set aObjects = aUpdMsg->objects(); QObjectPtrList aCreated; std::set::const_iterator aIt; - for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) - aCreated.append(*aIt); + for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) { + if ((*aIt)->isInHistory()) + aCreated.append(*aIt); + } QTreeNodesList aNodes = myRoot->objectCreated(aCreated); ModuleBase_ITreeNode* aParent; int aRow = 0; @@ -149,18 +151,16 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess ModuleBase_ITreeNode* aNode = myRoot->findParent(aDoc, aGroup.c_str()); if (aNode) { aNode->update(); - int aRows = aNode->childrenCount(); - if (aRows) { - QModelIndex aParent = getIndex(aNode, 0); - QModelIndex aFirstIdx = aParent.child(0, 0); - QModelIndex aLastIdx = aParent.child(aRows - 1, 2); - dataChanged(aFirstIdx, aLastIdx); - } + updateSubTree(aNode); } } } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument(); + ModuleBase_ITreeNode* aRoot = myRoot->findRoot(aDoc); + if (aRoot) { + updateSubTree(aRoot); + } } //if (myIsEventsProcessingBlocked) // return; @@ -460,11 +460,10 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn { ModuleBase_ITreeNode* aNode = myRoot->subNode(theObject); if (aNode) { - ModuleBase_ITreeNode* aParent = aNode->parent(); - assert(aParent); return getIndex(aNode, theColumn); } return QModelIndex(); + //std::string aType = theObject->groupName(); //DocumentPtr aDoc = theObject->document(); //int aRow = aDoc->index(theObject, true); @@ -1336,6 +1335,20 @@ QModelIndex XGUI_DataModel::getParentIndex(ModuleBase_ITreeNode* theNode, int th QModelIndex XGUI_DataModel::getIndex(ModuleBase_ITreeNode* theNode, int thCol) const { + if (theNode == myRoot) + return QModelIndex(); int aRow = theNode->parent()->nodeRow(theNode); - return createIndex(aRow, 0, theNode); + return createIndex(aRow, thCol, theNode); +} + + +void XGUI_DataModel::updateSubTree(ModuleBase_ITreeNode* theParent) +{ + int aRows = theParent->childrenCount(); + if (aRows) { + QModelIndex aParent = getIndex(theParent, 0); + QModelIndex aFirstIdx = aParent.child(0, 0); + QModelIndex aLastIdx = aParent.child(aRows - 1, 2); + dataChanged(aFirstIdx, aLastIdx); + } } diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 477370cc6..5e446bf0e 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -172,6 +172,8 @@ private: QModelIndex getIndex(ModuleBase_ITreeNode* theNode, int thCol) const; + void updateSubTree(ModuleBase_ITreeNode* theParent); + /// Find a root index which contains objects of the given document /// \param theDoc the document object //QModelIndex findDocumentRootIndex(const ModelAPI_Document* theDoc, int aColumn = 1) const;