Salome HOME
Issue #761 - Check and error for unique parameter name -- Code improvements
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 16 Jul 2015 11:04:36 +0000 (14:04 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Thu, 23 Jul 2015 06:15:15 +0000 (09:15 +0300)
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h

index 658a1d1e2e59003fc076cb6826c06886c9c94a17..641de07f7af20dc9875502a7683a08ed0ef8cefc 100644 (file)
@@ -95,7 +95,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
     SessionPtr aMgr = ModelAPI_Session::get();
     aMgr->startOperation("Rename");
 
-    if (!canRename(aObj, aName)) {
+    if (!XGUI_Tools::canRename(this, aObj, aName)) {
       aMgr->abortOperation();
       return;
     }
@@ -105,21 +105,6 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
   }
 }
 
-bool XGUI_DataTree::canRename(const ObjectPtr& theObject, const QString& theName)
-{
-  double aValue;
-  ResultParameterPtr aParam;
-
-  bool isVariableFound = ModelAPI_Tools::findVariable(theObject->document(), qPrintable(theName), aValue, aParam);
-
-  if (isVariableFound)
-    QMessageBox::information(this, tr("Rename parameter"),
-      QString(tr("Selected parameter can not be renamed to: %1. \
-There is a parameter with the same name. Its value is: %2.")).arg(qPrintable(theName)).arg(aValue));
-
-  return !isVariableFound;
-}
-
 void XGUI_DataTree::clear() 
 {
   ModuleBase_IDocumentDataModel* aModel = dataModel();
index a59ec8bd313a8ba99e5b299d8f6b85988a5a3919..de53db9130ce27ed041fe9d8b96b9093f47274fd 100644 (file)
@@ -47,9 +47,6 @@ public slots:
   /// Commit modified data (used for renaming of objects)
   virtual void commitData(QWidget* theEditor);
 
-  /// Returns true if theObject can be renamed in theName
-  bool canRename(const ObjectPtr& theObject, const QString& theName);
-
  protected:
    /// Redefinition of virtual method
   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
index b835629a7e37dbbb877aef8592f488b87741f4e0..5663298017804a0df23d6a3d9e61bfea31f51872 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomAPI_Shape.h>
 
@@ -104,6 +105,23 @@ bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects)
   return aResult;
 }
 
+//******************************************************************
+bool canRename(QWidget* theParent, const ObjectPtr& theObject, const QString& theName)
+{
+  if (std::dynamic_pointer_cast<ModelAPI_ResultParameter>(theObject).get()) {
+    double aValue;
+    ResultParameterPtr aParam;
+    if (ModelAPI_Tools::findVariable(theObject->document(), qPrintable(theName), aValue, aParam)) {
+      QMessageBox::information(theParent, QObject::tr("Rename parameter"),
+          QString(QObject::tr("Selected parameter can not be renamed to: %1. \
+There is a parameter with the same name. Its value is: %2.")).arg(qPrintable(theName)).arg(aValue));
+      return false;
+    }
+  }
+
+  return true;
+}
+
 //******************************************************************
 bool allDocumentsActivated(QString& theNotActivatedNames)
 {
index 4869f30377a394826de75d9436a6837e7592972f..279e08560b6e60116bd8abbabce9c8c37c1bb1e0 100644 (file)
@@ -78,6 +78,11 @@ std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
  */
 bool XGUI_EXPORT canRemoveOrRename(QWidget* theParent, const QObjectPtrList& aList);
 
+/*! 
+ Returns true if theObject can be renamed in theName
+ */
+bool canRename(QWidget* theParent, const ObjectPtr& theObject, const QString& theName);
+
 /*!
  Returns true if there are no parts in the document, which are not activated
  \return a boolean value