From e36ce1d26c3654666a6328fc0f7032fb6d021e62 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 2 Dec 2016 11:16:21 +0300 Subject: [PATCH] Issue #1900 Fatal error when close study, Issue #1749 Not updating the list "Selected objects" in the feature "Group" --- .../ModuleBase_WidgetMultiSelector.cpp | 35 ++++++++++++++++++- src/XGUI/XGUI_DataModel.cpp | 12 +++++-- src/XGUI/XGUI_DataModel.h | 4 +-- src/XGUI/XGUI_Workshop.cpp | 4 ++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index d2e8355f3..2e8e7a6cb 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -395,7 +395,40 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { activateSelectionAndFilters(true); - clearSelection(); + if (!myFeature) + return; + /// store the selected type + AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); + std::string aType = anAttribute->attributeType(); + if (aType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID()); + aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString()); + } + + // clear attribute values + DataPtr aData = myFeature->data(); + if (aType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID()); + aSelectionListAttr->clear(); + } + else if (aType == ModelAPI_AttributeRefList::typeId()) { + AttributeRefListPtr aRefListAttr = aData->reflist(attributeID()); + aRefListAttr->clear(); + } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID()); + aRefAttrListAttr->clear(); + } + + // update object is necessary to flush update signal. It leads to objects references map update + // and the operation presentation will not contain deleted items visualized as parameters of + // the feature. + updateObject(myFeature); + restoreValue(); + myWorkshop->setSelected(getAttributeSelection()); + // may be the feature's result is not displayed, but attributes should be + myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments, + true); /// hope that something is redisplayed by object updated } //******************************************************************** diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 1a4efa787..3aa3e351c 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -63,7 +63,7 @@ ModelAPI_Document* getSubDocument(void* theObj) // Constructor ************************************************* XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent), - myIsEventsProcessingStopped(false) + myIsEventsProcessingBlocked(false) { Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); @@ -80,7 +80,7 @@ XGUI_DataModel::~XGUI_DataModel() //****************************************************** void XGUI_DataModel::processEvent(const std::shared_ptr& theMessage) { - if (myIsEventsProcessingStopped) + if (myIsEventsProcessingBlocked) return; DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); std::string aRootType = myXMLReader->rootType(); @@ -963,3 +963,11 @@ void XGUI_DataModel::rebuildBranch(int theRow, int theCount, const QModelIndex& insertRows(theRow, theCount, theParent); } } + +//****************************************************** +bool XGUI_DataModel::blockEventsProcessing(const bool theState) +{ + bool aPreviousState = myIsEventsProcessingBlocked; + myIsEventsProcessingBlocked = theState; + return aPreviousState; +} diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index f3dc27c13..20cfb3aac 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -126,7 +126,7 @@ public: void setXMLReader(Config_DataModelReader* theReader) { myXMLReader = theReader; } /// Do not processing anymore events of model loop - void stopEventsProcessing() { myIsEventsProcessingStopped = true; } + bool blockEventsProcessing(const bool theState); signals: /// Signal about tree had been rebuilt @@ -165,7 +165,7 @@ private: Config_DataModelReader* myXMLReader; - bool myIsEventsProcessingStopped; + bool myIsEventsProcessingBlocked; }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8b7aa83a5..86265430b 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -2032,10 +2032,12 @@ void XGUI_Workshop::closeDocument() // data model need not process the document's signals about objects modifications as // the document is closed - objectBrowser()->dataModel()->stopEventsProcessing(); + bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true); SessionPtr aMgr = ModelAPI_Session::get(); aMgr->closeAll(); + + objectBrowser()->dataModel()->blockEventsProcessing(isBlocked); } void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot) -- 2.39.2