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;
// 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());
}
}
}
//**************************************************************
-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,
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());
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());
*/
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)
/// \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();