From 050daed3be88790f9af16a51e7923d1ce3b6fb16 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 11 Apr 2014 18:57:58 +0400 Subject: [PATCH] Update tree on Undo/Redo --- src/XGUI/XGUI_DataTreeModel.h | 3 +++ src/XGUI/XGUI_DocumentDataModel.cpp | 35 ++++++++++++++++++++++++----- src/XGUI/XGUI_PartDataModel.cpp | 18 +++++++++++++++ src/XGUI/XGUI_PartDataModel.h | 7 ++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/XGUI/XGUI_DataTreeModel.h b/src/XGUI/XGUI_DataTreeModel.h index 8f0ffd8d3..359fbdabd 100644 --- a/src/XGUI/XGUI_DataTreeModel.h +++ b/src/XGUI/XGUI_DataTreeModel.h @@ -25,6 +25,9 @@ public: //! Returns parent index of the given feature virtual QModelIndex findParent(const std::shared_ptr& theFeature) const = 0; + //! Returns index corresponded to the group + virtual QModelIndex findGroup(const std::string& theGroup) const = 0; + protected: std::shared_ptr myDocument; }; diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 7c4a0c2c8..b5d86ed23 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -83,12 +83,37 @@ void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage) std::shared_ptr aDoc = aUpdMsg->document(); if (aDoc == myDocument) { // If root objects - int aStart = myPartModels.count() - 2; - delete myPartModels.last(); - myPartModels.removeLast(); - beginRemoveRows(QModelIndex(), aStart, aStart); - endRemoveRows(); + if (aUpdMsg->group().compare(PARTS_GROUP) == 0) { // Updsate only Parts group + int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size() - 1; + beginRemoveRows(QModelIndex(), aStart, aStart); + delete myPartModels.last(); + myPartModels.removeLast(); + endRemoveRows(); + } else { // Update top groups (other except parts + QModelIndex aIndex = myModel->findGroup(aUpdMsg->group()); + int aStart = myModel->rowCount(aIndex); + aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)); + beginRemoveRows(aIndex, aStart, aStart); + endRemoveRows(); + } + } else { + XGUI_PartModel* aPartModel = 0; + QList::const_iterator aIt; + for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) { + if ((*aIt)->hasDocument(aDoc)) { + aPartModel = (*aIt); + break; + } + } + if (aPartModel) { + QModelIndex aIndex = aPartModel->findGroup(aUpdMsg->group()); + int aStart = aPartModel->rowCount(aIndex); + aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)); + beginRemoveRows(aIndex, aStart, aStart); + endRemoveRows(); + } } + // Reset whole tree ************************** } else { beginResetModel(); diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index e58d06ef0..f0e1d9f4b 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -152,6 +152,15 @@ QModelIndex XGUI_TopDataModel::findParent(const std::shared_ptrgetGroup().compare(CONSTRUCTIONS_GROUP) == 0) return createIndex(1, 0, (quintptr) ConstructFolder); return QModelIndex(); +} + +QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const +{ + if (theGroup.compare(PARAMETERS_GROUP) == 0) + return createIndex(0, 0, (quintptr) ParamsFolder); + if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0) + return createIndex(1, 0, (quintptr) ConstructFolder); + return QModelIndex(); } \ No newline at end of file diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index 1b3b069bf..7910724aa 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -35,8 +35,12 @@ public: //! Returns 0 if the given index is not index of a feature virtual FeaturePtr feature(const QModelIndex& theIndex) const; + //! Returns parent index of the given feature virtual QModelIndex findParent(const std::shared_ptr& theFeature) const; + //! Returns index corresponded to the group + virtual QModelIndex findGroup(const std::string& theGroup) const; + private: //! Types of QModelIndexes enum DataIds { @@ -86,6 +90,9 @@ public: //! Returns parent index of the given feature virtual QModelIndex findParent(const std::shared_ptr& theFeature) const; + //! Returns index corresponded to the group + virtual QModelIndex findGroup(const std::string& theGroup) const; + private: std::shared_ptr featureDocument() const; -- 2.39.2