From: nds Date: Fri, 22 Jan 2016 13:34:35 +0000 (+0300) Subject: Delete action modification: selection is lost even if we answer that we do not wish... X-Git-Tag: V_2.2.0~178 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b13073223d4c8ef310c38631c3f93fc22f1c9922;p=modules%2Fshaper.git Delete action modification: selection is lost even if we answer that we do not wish delete referenced features and abort delete operaion. Selection clear should be done after message dialog show. --- diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8818366a0..9ce705c4f 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1179,9 +1179,6 @@ void XGUI_Workshop::deleteObjects() QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); if (!abortAllOperations()) return; - // It is necessary to clear selection in order to avoid selection changed event during - // deletion and negative consequences connected with processing of already deleted items - mySelector->clearSelection(); // check whether the object can be deleted. There should not be parts which are not loaded if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects)) return; @@ -1202,11 +1199,20 @@ void XGUI_Workshop::deleteObjects() // 3. delete objects std::set anIgnoredFeatures; - if (deleteFeatures(anObjects, anIgnoredFeatures, desktop(), true)) { - operationMgr()->commitOperation(); - } - else { - operationMgr()->abortOperation(operationMgr()->currentOperation()); + std::set aDirectRefFeatures, aIndirectRefFeatures; + findReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures); + + bool doDeleteReferences = true; + if (isDeleteFeatureWithReferences(anObjects, aDirectRefFeatures, aIndirectRefFeatures, + desktop(), doDeleteReferences)) { + // It is necessary to clear selection in order to avoid selection changed event during + // deletion and negative consequences connected with processing of already deleted items + mySelector->clearSelection(); + if (deleteFeaturesInternal(anObjects, aDirectRefFeatures, aIndirectRefFeatures, + anIgnoredFeatures, doDeleteReferences)) + operationMgr()->commitOperation(); + else + operationMgr()->abortOperation(operationMgr()->currentOperation()); } } @@ -1322,23 +1328,10 @@ void XGUI_Workshop::moveObjects() } //************************************************************** -bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, - const std::set& theIgnoredFeatures, - QWidget* theParent, - const bool theAskAboutDeleteReferences) +void XGUI_Workshop::findReferences(const QObjectPtrList& theList, + std::set& aDirectRefFeatures, + std::set& aIndirectRefFeatures) { -#ifdef DEBUG_DELETE - QStringList aDInfo; - QObjectPtrList::const_iterator aDIt = theList.begin(), aDLast = theList.end(); - for (; aDIt != aDLast; ++aDIt) { - aDInfo.append(ModuleBase_Tools::objectInfo((*aDIt))); - } - QString anInfoStr = aDInfo.join(", "); - qDebug(QString("deleteFeatures: %1, %2").arg(theList.size()).arg(anInfoStr).toStdString().c_str()); -#endif - - // 1. find all referenced features - std::set aDirectRefFeatures, aIndirectRefFeatures; foreach (ObjectPtr aDeletedObj, theList) { std::set alreadyProcessed; XGUI_Tools::refsToFeatureInAllDocuments(aDeletedObj, aDeletedObj, theList, aDirectRefFeatures, @@ -1349,11 +1342,17 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, std::inserter(aDifference, aDifference.begin())); aIndirectRefFeatures = aDifference; } +} - bool doDeleteReferences = true; +bool XGUI_Workshop::isDeleteFeatureWithReferences(const QObjectPtrList& theList, + const std::set& aDirectRefFeatures, + const std::set& aIndirectRefFeatures, + QWidget* theParent, + bool& doDeleteReferences) +{ + doDeleteReferences = true; - // 2. warn about the references remove, break the delete operation if the user chose it - if (theAskAboutDeleteReferences && !aDirectRefFeatures.empty()) { + if (!aDirectRefFeatures.empty()) { QStringList aDirectRefNames; foreach (const FeaturePtr& aFeature, aDirectRefFeatures) aDirectRefNames.append(aFeature->name().c_str()); @@ -1401,8 +1400,24 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, doDeleteReferences = false; } } + return true; +} - // 3. remove referenced features +bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theFeatures, + const std::set& theIgnoredFeatures) +{ + std::set aDirectRefFeatures, aIndirectRefFeatures; + findReferences(theFeatures, aDirectRefFeatures, aIndirectRefFeatures); + return deleteFeaturesInternal(theFeatures, aDirectRefFeatures, aIndirectRefFeatures, + theIgnoredFeatures); +} + +bool XGUI_Workshop::deleteFeaturesInternal(const QObjectPtrList& theList, + const std::set& theIgnoredFeatures, + const std::set& aDirectRefFeatures, + const std::set& aIndirectRefFeatures, + const bool doDeleteReferences) +{ if (doDeleteReferences) { std::set aFeaturesToDelete = aDirectRefFeatures; aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end()); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 5bb898533..66c08f085 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -232,18 +232,12 @@ Q_OBJECT */ bool abortAllOperations(); - //! Delete features. Delete the referenced features. There can be a question with a list of referenced - //! objects. + //! Delete features. Delete the referenced features. There can be a question with a list of + //! referenced objects. //! \param theList an objects to be deleted //! \param theIgnoredFeatures a list of features to be ignored during delete - //! \param theParent a parent widget for the question message box - //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the - //! objects features appear. If the user chose do not continue, the deletion is not performed - //! \return the success of the delete - bool deleteFeatures(const QObjectPtrList& theList, - const std::set& theIgnoredFeatures = std::set(), - QWidget* theParent = 0, - const bool theAskAboutDeleteReferences = false); + bool deleteFeatures(const QObjectPtrList& theFeatures, + const std::set& theIgnoredFeatures = std::set()); /// Deactivates the object, if it is active and the module returns that the activation /// of selection for the object is not possible currently(the current operation uses it) @@ -360,6 +354,39 @@ signals: /// \param isToConnect a boolean value whether connect or disconnect void connectToPropertyPanel(const bool isToConnect); + //! Find all referenced features. Return direct and indirect lists of referenced object + //! \param theList an objects to be checked + //! \param aDirectRefFeatures a list of direct reference features + //! \param aIndirectRefFeatures a list of features which depend on the feature through others + void findReferences(const QObjectPtrList& theList, + std::set& aDirectRefFeatures, + std::set& aIndirectRefFeatures); + + //! Shows a dialog box about references. Ask whether they should be also removed. + //! \param theList an objects to be checked + //! \param aDirectRefFeatures a list of direct reference features + //! \param aIndirectRefFeatures a list of features which depend on the feature through others + //! \param theParent a parent widget for the question message box + //! \param doDeleteReferences if there are parameters between features, ask if they should be + //! replaced to their meaning without corresponded features remove + //! \return true if in message box answer is Yes + bool isDeleteFeatureWithReferences(const QObjectPtrList& theList, + const std::set& aDirectRefFeatures, + const std::set& aIndirectRefFeatures, + QWidget* theParent, + bool& doDeleteReferences); + + //! \param theIgnoredFeatures a list of features to be ignored during delete + //! \param theList an objects to be checked + //! \param aDirectRefFeatures a list of direct reference features + //! \param aIndirectRefFeatures a list of features which depend on the feature through others + //! \param doDeleteReferences flag if referenced features should be removed also + bool deleteFeaturesInternal(const QObjectPtrList& theList, + const std::set& aDirectRefFeatures, + const std::set& aIndirectRefFeatures, + const std::set& theIgnoredFeatures, + const bool doDeleteReferences = true); + private: /// Display all results //void displayAllResults();