From 5f8c57345f356fb9bfdb4dcb9f811a880c7a7db8 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 27 Nov 2018 18:16:44 +0300 Subject: [PATCH] Issue #2754: Prevent renaming of object with a name which already exists --- src/XGUI/XGUI_Tools.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index e5bc7a308..3f5ba6636 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include #include @@ -149,14 +151,29 @@ bool canRemoveOrRename(QWidget* theParent, const std::set& theFeatur //****************************************************************** bool canRename(const ObjectPtr& theObject, const QString& theName) { - if (std::dynamic_pointer_cast(theObject).get()) { + std::string aType = theObject->groupName(); + if (aType == ModelAPI_ResultParameter::group()) { double aValue; ResultParameterPtr aParam; if (ModelAPI_Tools::findVariable(theObject->document(), FeaturePtr(), qPrintable(theName), aValue, aParam)) { const char* aKeyStr = "Selected parameter can not be renamed to: %1. " "There is a parameter with the same name. Its value is: %2."; - QString aErrMsg(QObject::tr(aKeyStr).arg(qPrintable(theName)).arg(aValue)); + QString aErrMsg(QObject::tr(aKeyStr).arg(theName).arg(aValue)); + // We can not use here a dialog box for message - + // it will crash editing process in ObjectBrowser + Events_InfoMessage("XGUI_Tools", aErrMsg.toStdString()).send(); + return false; + } + } + else if ((aType == ModelAPI_ResultConstruction::group()) || (aType == ModelAPI_ResultBody::group())) { + DocumentPtr aDoc = theObject->document(); + ObjectPtr aObj = aDoc->objectByName(ModelAPI_ResultConstruction::group(), theName.toStdString()); + if (!aObj.get()) + aObj = aDoc->objectByName(ModelAPI_ResultBody::group(), theName.toStdString()); + + if (aObj.get()) { + QString aErrMsg(QObject::tr("Object with name %1 already exists.").arg(theName)); // We can not use here a dialog box for message - // it will crash editing process in ObjectBrowser Events_InfoMessage("XGUI_Tools", aErrMsg.toStdString()).send(); -- 2.39.2