]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Delete action modification: selection is lost even if we answer that we do not wish...
authornds <nds@opencascade.com>
Fri, 22 Jan 2016 13:34:35 +0000 (16:34 +0300)
committernds <nds@opencascade.com>
Fri, 22 Jan 2016 13:34:35 +0000 (16:34 +0300)
Selection clear should be done after message dialog show.

src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 8818366a0d8c6d2c2a4b31279d3b09128e54293d..9ce705c4f8b4102ca4d9fd57e0f6537a270ba818 100755 (executable)
@@ -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<FeaturePtr> anIgnoredFeatures;
-  if (deleteFeatures(anObjects, anIgnoredFeatures, desktop(), true)) {
-    operationMgr()->commitOperation();
-  }
-  else {
-    operationMgr()->abortOperation(operationMgr()->currentOperation());
+  std::set<FeaturePtr> 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<FeaturePtr>& theIgnoredFeatures,
-                                   QWidget* theParent,
-                                   const bool theAskAboutDeleteReferences)
+void XGUI_Workshop::findReferences(const QObjectPtrList& theList,
+                                   std::set<FeaturePtr>& aDirectRefFeatures,
+                                   std::set<FeaturePtr>& 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<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
   foreach (ObjectPtr aDeletedObj, theList) {
     std::set<FeaturePtr> 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<FeaturePtr>& aDirectRefFeatures,
+                                   const std::set<FeaturePtr>& 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<FeaturePtr>& theIgnoredFeatures)
+{
+  std::set<FeaturePtr> aDirectRefFeatures, aIndirectRefFeatures;
+  findReferences(theFeatures, aDirectRefFeatures, aIndirectRefFeatures);
+  return deleteFeaturesInternal(theFeatures, aDirectRefFeatures, aIndirectRefFeatures,
+                                theIgnoredFeatures);
+}
+
+bool XGUI_Workshop::deleteFeaturesInternal(const QObjectPtrList& theList,
+                                           const std::set<FeaturePtr>& theIgnoredFeatures,
+                                           const std::set<FeaturePtr>& aDirectRefFeatures,
+                                           const std::set<FeaturePtr>& aIndirectRefFeatures,
+                                           const bool doDeleteReferences)
+{
   if (doDeleteReferences) {
     std::set<FeaturePtr> aFeaturesToDelete = aDirectRefFeatures;
     aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
index 5bb898533422e55d0fb6dac75623d416da96ce6b..66c08f0854b1af97d939dfd0d324cadba71a578d 100755 (executable)
@@ -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<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>(),
-                      QWidget* theParent = 0,
-                      const bool theAskAboutDeleteReferences = false);
+  bool deleteFeatures(const QObjectPtrList& theFeatures,
+                      const std::set<FeaturePtr>& theIgnoredFeatures = std::set<FeaturePtr>());
 
   /// 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<FeaturePtr>& aDirectRefFeatures,
+                      std::set<FeaturePtr>& 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<FeaturePtr>& aDirectRefFeatures,
+                                     const std::set<FeaturePtr>& 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<FeaturePtr>& aDirectRefFeatures,
+                              const std::set<FeaturePtr>& aIndirectRefFeatures,
+                              const std::set<FeaturePtr>& theIgnoredFeatures,
+                              const bool doDeleteReferences = true);
+
 private:
   /// Display all results
   //void displayAllResults();