From 446153820da6f3fff5c721888385adecc883a3d8 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 20 Apr 2016 17:42:12 +0300 Subject: [PATCH] Rebuild data tree in case of inconsistence with data model. Correct warning with wrong using of QString.arg() --- src/XGUI/XGUI_DataModel.cpp | 23 +++++++++++------------ src/XGUI/XGUI_DataModel.h | 3 +++ src/XGUI/XGUI_ObjectsBrowser.cpp | 20 +++++++++++++++----- src/XGUI/XGUI_ObjectsBrowser.h | 7 +++++++ src/XGUI/XGUI_Tools.cpp | 11 +++++++---- src/XGUI/XGUI_Workshop.cpp | 4 ++-- 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 3e7b0e796..6bcee6721 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -150,11 +150,8 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } } } - } -#ifdef _DEBUG - else - Events_Error::send("Problem with Data Model definition of sub-document"); -#endif + } else + rebuildDataTree(); } } // Deleted object event *********************** @@ -233,9 +230,14 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess std::string aObjType; for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) { ObjectPtr aObject = (*aIt); - QModelIndex aIndex = objectIndex(aObject); - if (aIndex.isValid()) - emit dataChanged(aIndex, aIndex); + if (aObject->data()->isValid()) { + QModelIndex aIndex = objectIndex(aObject); + if (aIndex.isValid()) + emit dataChanged(aIndex, aIndex); + } else { + rebuildDataTree(); + break; + } } } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) { std::shared_ptr aUpdMsg = @@ -272,10 +274,6 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess else // We have got a new document rebuildDataTree(); -//#ifdef _DEBUG -// else -// Events_Error::send("Problem with Data Model definition of sub-document"); -//#endif } } } @@ -291,6 +289,7 @@ void XGUI_DataModel::rebuildDataTree() { beginResetModel(); endResetModel(); + emit treeRebuilt(); } //****************************************************** diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 47b0f7b6b..b43edd8a8 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -123,6 +123,9 @@ public: /// Initialises XML data model reader. It must be initialised before DataModel using. void setXMLReader(Config_DataModelReader* theReader) { myXMLReader = theReader; } +signals: + void treeRebuilt(); + private: /// Find a root index which contains objects of the given document /// \param theDoc the document object diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 9ff3f6e00..be2ff3db8 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -361,6 +361,8 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelWgt->setPalette(aPalet); myDocModel = new XGUI_DataModel(this); + connect(myDocModel, SIGNAL(modelAboutToBeReset()), SLOT(onBeforeReset())); + connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset())); connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, SLOT(onContextMenuRequested(QContextMenuEvent*))); @@ -470,11 +472,7 @@ QModelIndexList XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) //*************************************************** void XGUI_ObjectsBrowser::rebuildDataTree() { - QModelIndexList aIndexList = expandedItems(); myDocModel->rebuildDataTree(); - foreach(QModelIndex aIndex, aIndexList) { - myTreeView->setExpanded(aIndex, true); - } update(); } @@ -523,4 +521,16 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) } } return aList; -} \ No newline at end of file +} + +void XGUI_ObjectsBrowser::onBeforeReset() +{ + myExpandedItems = expandedItems(); +} + +void XGUI_ObjectsBrowser::onAfterModelReset() +{ + foreach(QModelIndex aIndex, myExpandedItems) { + myTreeView->setExpanded(aIndex, true); + } +} diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index c71206dcc..eff2ffc10 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -209,6 +209,10 @@ signals: //! Called when selection in Data Tree is changed void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected); + void onBeforeReset(); + + void onAfterModelReset(); + private: QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const; @@ -216,6 +220,9 @@ signals: XGUI_DataModel* myDocModel; XGUI_ActiveDocLbl* myActiveDocLbl; XGUI_DataTree* myTreeView; + + /// A field to store expanded items before model reset + QModelIndexList myExpandedItems; }; #endif diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 6d4009a4a..e9000eff1 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -66,11 +66,14 @@ QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theS { QStringList aObjectNames; foreach (ObjectPtr aObj, theObjects) { - if (!aObj->data()->isValid()) - continue; - aObjectNames << QString::fromStdString(aObj->data()->name()); + if (aObj->data()->isValid()) + aObjectNames << QString::fromStdString(aObj->data()->name()); } - return aObjectNames.join(", "); + if (aObjectNames.count() == 0) + return QString(); + if (aObjectNames.count() == 1) + return aObjectNames.first(); + return aObjectNames.join(theSeparator); } //****************************************************************** diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index fd0fc2d81..45240ddb7 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1290,8 +1290,8 @@ void XGUI_Workshop::deleteObjects() if (ModuleBase_Tools::isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures, desktop(), doDeleteReferences)) { // start operation - QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text(); - aDescription += " " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", ")); + QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1"; + aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", ")); ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module()); operationMgr()->startOperation(anOpAction); -- 2.39.2