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
std::set<ObjectPtr> aObjects = aUpdMsg->objects();
QObjectPtrList aCreated;
std::set<ObjectPtr>::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;
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;
{
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);
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);
+ }
}