From: spo Date: Thu, 16 Jul 2015 11:04:36 +0000 (+0300) Subject: Issue #761 - Check and error for unique parameter name -- Code improvements X-Git-Tag: V_1.4.0_beta4~452 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ac46240064eb9a206ddb2d45b5df5032295822b0;p=modules%2Fshaper.git Issue #761 - Check and error for unique parameter name -- Code improvements --- diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 658a1d1e2..641de07f7 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -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(); diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index a59ec8bd3..de53db913 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -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); diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index b835629a7..566329801 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -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(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) { diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 4869f3037..279e08560 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -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