From: vsv Date: Thu, 22 Oct 2015 09:55:42 +0000 (+0300) Subject: Define Rename as an operation X-Git-Tag: V_2.0.0_alfa1~74 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=40f3b736db0100d3793d72f22aecf23fb21cbe1b;p=modules%2Fshaper.git Define Rename as an operation --- diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 406cc673c..190f2ef3d 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -9,6 +9,8 @@ #include "XGUI_Selection.h" #include "XGUI_SalomeConnector.h" #include "XGUI_DataModel.h" +#include "XGUI_OperationMgr.h" +#include "XGUI_Tools.h" #include @@ -26,6 +28,7 @@ #include #include +#include #include #include @@ -492,5 +495,9 @@ QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName) void XGUI_ContextMenuMgr::onRename() { + ModuleBase_OperationAction* anAction = new ModuleBase_OperationAction("Rename", this); + XGUI_OperationMgr* anOpMgr = myWorkshop->operationMgr(); + anOpMgr->startOperation(anAction); myWorkshop->objectBrowser()->onEditItem(); + anOpMgr->commitOperation(); } diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 74d04d931..2df67c449 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -88,23 +89,23 @@ void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent) void XGUI_DataTree::commitData(QWidget* theEditor) { - QLineEdit* aEditor = dynamic_cast(theEditor); - if (aEditor) { - QString aName = aEditor->text(); - QModelIndexList aIndexList = selectionModel()->selectedIndexes(); - XGUI_DataModel* aModel = dataModel(); - ObjectPtr aObj = aModel->object(aIndexList.first()); - SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->startOperation("Rename"); + static int aEntrance = 0; + if (aEntrance == 0) { + // We have to check number of enter and exit of this function because it can be called recursively by Qt + // in order to avoid double modifying of a data + aEntrance = 1; + QLineEdit* aEditor = dynamic_cast(theEditor); + if (aEditor) { + QString aName = aEditor->text(); + QModelIndexList aIndexList = selectionModel()->selectedIndexes(); + XGUI_DataModel* aModel = dataModel(); + ObjectPtr aObj = aModel->object(aIndexList.first()); - if (!XGUI_Tools::canRename(this, aObj, aName)) { - aMgr->abortOperation(); - return; + if (XGUI_Tools::canRename(aObj, aName)) + aObj->data()->setName(qPrintable(aName)); } - - aObj->data()->setName(qPrintable(aName)); - aMgr->finishOperation(); } + aEntrance = 0; } void XGUI_DataTree::clear() diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index fb0a8f256..b0bc95106 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -106,15 +107,16 @@ bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects) } //****************************************************************** -bool canRename(QWidget* theParent, const ObjectPtr& theObject, const QString& theName) +bool canRename(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)); + QString aErrMsg(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)); + // We can not use here a dialog box for message - it will crash editing process in ObjectBrowser + Events_Error::send(aErrMsg.toStdString()); return false; } } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 7cf55846e..21ca7356d 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -80,11 +80,10 @@ bool XGUI_EXPORT canRemoveOrRename(QWidget* theParent, const QObjectPtrList& aLi /*! Check possibility to rename object - \param theParent a parent widget \param theObject an object to rename \param theName a name */ -bool canRename(QWidget* theParent, const ObjectPtr& theObject, const QString& theName); +bool canRename(const ObjectPtr& theObject, const QString& theName); /*! Returns true if there are no parts in the document, which are not activated