From 781aab61fcaac1cf70e40bdcc06d7e81405c8bb3 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 11 Apr 2014 17:53:33 +0400 Subject: [PATCH] Update tree --- src/ModuleBase/ModuleBase_Operation.cpp | 4 +- src/XGUI/XGUI_DocumentDataModel.cpp | 58 ++++++++++++++++--------- src/XGUI/XGUI_DocumentDataModel.h | 5 ++- src/XGUI/XGUI_MainWindow.cpp | 3 ++ src/XGUI/XGUI_Workshop.cpp | 1 + 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 2c0e7d9d7..a6afc4d5f 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -224,9 +224,9 @@ void ModuleBase_Operation::abort() emit aborted(); stopOperation(); - emit stopped(); document()->abortOperation(); + emit stopped(); } /*! @@ -242,9 +242,9 @@ void ModuleBase_Operation::commit() emit committed(); stopOperation(); - emit stopped(); document()->finishOperation(); + emit stopped(); } /*! diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index a17b618ee..a13cca535 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -25,6 +25,7 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) // Register in event loop Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_CREATED)); Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_UPDATED)); + Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_DELETED)); // Create a top part of data tree model myModel = new XGUI_TopDataModel(myDocument, this); @@ -39,30 +40,27 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel() void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage) { + // Created object event ******************* if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) { const ModelAPI_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); std::shared_ptr aDoc = aUpdMsg->document(); std::shared_ptr aFeature = aUpdMsg->feature(); - if (aDoc == myDocument) { - if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { + if (aDoc == myDocument) { // If root objects + if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Updsate only Parts group // Add a new part int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size(); - beginInsertRows(QModelIndex(), aStart, aStart + 1); XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this); aModel->setPartId(myPartModels.count()); myPartModels.append(aModel); - endInsertRows(); - } else { + insertRows(QModelIndex(), aStart, aStart); + } else { // Update top groups (other except parts QModelIndex aIndex = myModel->findParent(aFeature); int aStart = myModel->rowCount(aIndex); aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)); - beginInsertRows(aIndex, aStart-1, aStart); - endInsertRows(); - if (aStart == 1) // Update parent if this is a first child in order to update node decoration - emit dataChanged(aIndex, aIndex); + insertRows(aIndex, aStart-1, aStart); } - } else { + } else { // if sub-objects of first level nodes XGUI_PartModel* aPartModel = 0; QList::const_iterator aIt; for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) { @@ -75,14 +73,24 @@ void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage) QModelIndex aIndex = aPartModel->findParent(aFeature); int aStart = aPartModel->rowCount(aIndex); aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)); - beginInsertRows(aIndex, aStart-1, aStart); - endInsertRows(); - if (aStart == 1) // Update parent if this is a first child in order to update node decoration - emit dataChanged(aIndex, aIndex); + insertRows(aIndex, aStart-1, aStart); } } - } else { - // Reset whole tree + + // Deteted object event *********************** + } if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_DELETED) { + const ModelAPI_FeatureDeletedMessage* aUpdMsg = dynamic_cast(theMessage); + std::shared_ptr aDoc = aUpdMsg->document(); + + if (aDoc == myDocument) { // If root objects + int aStart = myPartModels.count() - 1; + delete myPartModels.last(); + myPartModels.removeLast(); + beginRemoveRows(QModelIndex(), aStart, aStart); + endRemoveRows(); + } + // Reset whole tree ************************** + } else { beginResetModel(); int aNbParts = myDocument->featuresIterator(PARTS_GROUP)->numIterationsLeft(); if (myPartModels.size() != aNbParts) { // resize internal models @@ -105,7 +113,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) { if (!theIndex.isValid()) return QVariant(); - return toSourceModel(theIndex).data(theRole); + return toSourceModelIndex(theIndex).data(theRole); } @@ -119,7 +127,7 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const if (!theParent.isValid()) return myModel->rowCount(theParent) + myPartModels.size(); - QModelIndex aParent = toSourceModel(theParent); + QModelIndex aParent = toSourceModelIndex(theParent); return aParent.model()->rowCount(aParent); } @@ -151,7 +159,7 @@ QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, const QMode QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const { - QModelIndex aParent = toSourceModel(theIndex); + QModelIndex aParent = toSourceModelIndex(theIndex); aParent = aParent.model()->parent(aParent); if (aParent.isValid()) return createIndex(aParent.row(), aParent.column(), (void*)getModelIndex(aParent)); @@ -167,7 +175,7 @@ bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const } -QModelIndex XGUI_DocumentDataModel::toSourceModel(const QModelIndex& theProxy) const +QModelIndex XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const { QModelIndex* aIndexPtr = static_cast(theProxy.internalPointer()); return (*aIndexPtr); @@ -206,7 +214,15 @@ void XGUI_DocumentDataModel::clearModelIndexes() FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const { - QModelIndex aIndex = toSourceModel(theIndex); + QModelIndex aIndex = toSourceModelIndex(theIndex); const XGUI_FeaturesModel* aModel = dynamic_cast(aIndex.model()); return aModel->feature(aIndex); +} + +void XGUI_DocumentDataModel::insertRows(const QModelIndex& theParent, int theStart, int theEnd) +{ + beginInsertRows(theParent, theStart, theEnd); + endInsertRows(); + if (theStart == 1) // Update parent if this is a first child in order to update node decoration + emit dataChanged(theParent, theParent); } \ No newline at end of file diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h index 8c57a61de..7e587ff0d 100644 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ b/src/XGUI/XGUI_DocumentDataModel.h @@ -52,7 +52,7 @@ public: private: //! Converts QModelIndex of this model to QModelIndex of a one of sub-models. - QModelIndex toSourceModel(const QModelIndex& theProxy) const; + QModelIndex toSourceModelIndex(const QModelIndex& theProxy) const; //! Finds a pointer on QModelIndex which is equal to the given one QModelIndex* findModelIndex(const QModelIndex& theIndex) const; @@ -63,6 +63,9 @@ private: //! Deletes all saved pointers on QModelIndex objects. void clearModelIndexes(); + //! Causes inserting of new nodes for given parent and indexes + void insertRows(const QModelIndex& theParent, int theStart, int theEnd); + //! Document std::shared_ptr myDocument; diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 25516792e..b648d59ce 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -147,15 +147,18 @@ QDockWidget* XGUI_MainWindow::createPropertyPanel() QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); aBtn->setFlat(true); + //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyHelpPressed())); aBtnLay->addWidget(aBtn); aBtnLay->addStretch(1); aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); aBtn->setObjectName(XGUI::PROP_PANEL_OK); aBtn->setFlat(true); + //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyOkPressed())); aBtnLay->addWidget(aBtn); aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL); aBtn->setFlat(true); + //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyClosePressed())); aBtnLay->addWidget(aBtn); return aPropPanel; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 284332eed..0aac474da 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -240,6 +240,7 @@ void XGUI_Workshop::connectToPropertyPanel(ModuleBase_Operation* theOperation) connect(theOperation, SIGNAL(started()), myMainWindow, SLOT(showPropertyPanel())); connect(theOperation, SIGNAL(stopped()), myMainWindow, SLOT(hidePropertyPanel())); + connect(theOperation, SIGNAL(stopped()), this, SLOT(updateCommandStatus())); } //****************************************************** -- 2.39.2