X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FXGUI%2FXGUI_DataModel.cpp;h=d624d14ad7d06ceecef304ebe80dc6fb8225ab72;hb=227323fca46747847e850a1d6e3bdaac882e209e;hp=5cfb093044560a612438d04079886a28c6f99257;hpb=2e688609a4fa5428edd3700f1bce92406d3ade18;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 5cfb09304..d624d14ad 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "XGUI_DataModel.h" @@ -25,6 +24,7 @@ #include #include +#include #include @@ -47,6 +47,7 @@ XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParen aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_ORDER_UPDATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } XGUI_DataModel::~XGUI_DataModel() @@ -59,36 +60,76 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess { if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(theMessage); std::set aObjects = aUpdMsg->objects(); QObjectPtrList aCreated; std::set::const_iterator aIt; for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) { if ((*aIt)->isInHistory()) aCreated.append(*aIt); + if ((*aIt)->groupName() == ModelAPI_ResultPart::group()) { + emit beforeTreeRebuild(); + myRoot->update(); + rebuildDataTree(); + emit treeRebuilt(); + return; + } } + if (aCreated.length() == 0) + return; + + emit beforeTreeRebuild(); QTreeNodesList aNodes = myRoot->objectCreated(aCreated); ModuleBase_ITreeNode* aParent; int aRow = 0; QModelIndex aParentIndex1, aParentIndex2; + ObjectPtr aObj; + bool aRebuildAll = false; + foreach(ModuleBase_ITreeNode* aNode, aNodes) { + aObj = aNode->object(); aParent = aNode->parent(); - aRow = aParent->nodeRow(aNode); - aParentIndex1 = getParentIndex(aNode, 0); - aParentIndex2 = getParentIndex(aNode, 2); - insertRows(aRow, 1, aParentIndex1); - dataChanged(aParentIndex1, aParentIndex2); + if (aObj.get() && (aObj->groupName() == ModelAPI_Folder::group())) { + aParent->update(); + aRebuildAll = true; + } + else { + aRow = aParent->nodeRow(aNode); + aParentIndex1 = getParentIndex(aNode, 0); + aParentIndex2 = getParentIndex(aNode, 2); + insertRows(aRow, 1, aParentIndex1); + dataChanged(aParentIndex1, aParentIndex2); + } } + if (aRebuildAll) + rebuildDataTree(); + + emit treeRebuilt(); } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { - std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); - const std::list, std::string>>& aMsgGroups = - aUpdMsg->groups(); - std::list, std::string>>::const_iterator aIt; - for (aIt = aMsgGroups.cbegin(); aIt != aMsgGroups.cend(); aIt++) - QTreeNodesList aList = myRoot->objectsDeleted(aIt->first, aIt->second.c_str()); - rebuildDataTree(); + std::shared_ptr aUpdMsg = + std::dynamic_pointer_cast(theMessage); + const std::list, std::string>>& aMsgGroups = + aUpdMsg->groups(); + QTreeNodesList aList; + std::list, std::string>>::const_iterator aIt; + emit beforeTreeRebuild(); + for (aIt = aMsgGroups.cbegin(); aIt != aMsgGroups.cend(); aIt++) { + aList.append(myRoot->objectsDeleted(aIt->first, aIt->second.c_str())); + } + // Remove obsolete nodes + QTreeNodesList aRemaining; + foreach(ModuleBase_ITreeNode* aNode, aList) { + if (myRoot->hasSubNode(aNode)) + aRemaining.append(aNode); + } + // Update remaining nodes + foreach(ModuleBase_ITreeNode* aNode, aRemaining) { + if (aNode->parent()) + aNode->parent()->update(); + } + rebuildDataTree(); + emit treeRebuilt(); } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) { std::shared_ptr aUpdMsg = @@ -98,6 +139,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess QObjectPtrList aCreated; std::set::const_iterator aIt; bool aRebuildAll = false; + emit beforeTreeRebuild(); for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) { ObjectPtr aObj = (*aIt); if (!aObj->isInHistory()) @@ -113,17 +155,31 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } if (aRebuildAll) { myRoot->update(); - rebuildDataTree(); - } else { + } + else { + QSet aParents; foreach(ObjectPtr aObj, aCreated) { ModuleBase_ITreeNode* aNode = myRoot->subNode(aObj); if (aNode) { - QModelIndex aFirstIdx = getIndex(aNode, 0); - QModelIndex aLastIdx = getIndex(aNode, 2); - dataChanged(aFirstIdx, aLastIdx); + if (aNode->parent()) { + if (aNode->parent() == myRoot) { + aParents.clear(); + aParents.insert(myRoot); + break; + } + else { + aNode = aNode->parent(); + } + } + aParents.insert(aNode); } } + foreach(ModuleBase_ITreeNode* aNode, aParents) { + aNode->update(); + } } + rebuildDataTree(); + emit treeRebuilt(); } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) { std::shared_ptr aUpdMsg = @@ -133,8 +189,10 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess std::string aGroup = aUpdMsg->reordered()->group(); ModuleBase_ITreeNode* aNode = myRoot->findParent(aDoc, aGroup.c_str()); if (aNode) { + emit beforeTreeRebuild(); aNode->update(); - updateSubTree(aNode); + rebuildDataTree(); + emit treeRebuilt(); } } } @@ -145,6 +203,47 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess updateSubTree(aRoot); } } + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) { + std::shared_ptr aUpdMsg = + std::dynamic_pointer_cast(theMessage); + std::set aObjects = aUpdMsg->objects(); + + QObjectPtrList aCreated; + std::set::const_iterator aIt; + bool aRebuildAll = false; + for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) { + ObjectPtr aObj = (*aIt); + if (aObj->groupName() == ModelAPI_ResultField::group()) { + aCreated.append(aObj); + } + } + if (aCreated.length() == 0) + return; + emit beforeTreeRebuild(); + foreach(ObjectPtr aObj, aCreated) { + ModuleBase_ITreeNode* aNode = myRoot->subNode(aObj); + if (aNode) { + int aOldNb = aNode->childrenCount(); + aNode->update(); + int aNewNb = aNode->childrenCount(); + + QModelIndex aFirstIdx = getIndex(aNode, 0); + QModelIndex aLastIdx = getIndex(aNode, 2); + + if (aNewNb > aOldNb) { + insertRows(aOldNb - 1, aNewNb - aOldNb, aFirstIdx); + } + else if (aNewNb < aOldNb) { + if (aNewNb) + removeRows(aNewNb - 1, aOldNb - aNewNb, aFirstIdx); + else if (aOldNb) + removeRows(0, aOldNb, aFirstIdx); + } + dataChanged(aFirstIdx, aLastIdx); + } + } + emit treeRebuilt(); + } } //****************************************************** @@ -159,7 +258,6 @@ void XGUI_DataModel::rebuildDataTree() { beginResetModel(); endResetModel(); - emit treeRebuilt(); } //****************************************************** @@ -215,7 +313,6 @@ int XGUI_DataModel::columnCount(const QModelIndex& theParent) const //****************************************************** QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const { - int aa = theParent.row(); ModuleBase_ITreeNode* aParentNode = (theParent.isValid()) ? (ModuleBase_ITreeNode*)theParent.internalPointer() : myRoot; ModuleBase_ITreeNode* aSubNode = aParentNode->subNode(theRow); @@ -338,3 +435,18 @@ 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(); +} + + +//****************************************************** +bool XGUI_DataModel::hasNode(ModuleBase_ITreeNode* theNode) const +{ + return myRoot->hasSubNode(theNode); +}