From 6a19f180c2dc7aee9676352a3d0bb79279dfd0ce Mon Sep 17 00:00:00 2001 From: rnv Date: Tue, 5 Apr 2011 09:21:57 +0000 Subject: [PATCH] Implementation "21042: EDF 1600 ALL: Rename objects in the OB" issue. --- src/LightApp/LightApp_Application.cxx | 47 +++++++++++- src/LightApp/LightApp_Application.h | 3 + src/LightApp/LightApp_DataObject.cxx | 50 +++++++++++- src/LightApp/LightApp_DataObject.h | 2 + src/LightApp/LightApp_Module.cxx | 20 +++++ src/LightApp/LightApp_Module.h | 2 + src/LightApp/resources/LightApp_msg_en.ts | 4 + src/ObjBrowser/OB_Browser.cxx | 6 +- .../SALOME_PYQT_DataObjectLight.cxx | 3 +- .../SALOME_PYQT_DataObjectLight.h | 2 +- src/SUIT/SUIT_DataBrowser.cxx | 50 +++++++----- src/SUIT/SUIT_DataBrowser.h | 11 ++- src/SUIT/SUIT_DataObject.cxx | 26 +++++++ src/SUIT/SUIT_DataObject.h | 2 + src/SUIT/SUIT_TreeModel.cxx | 17 +++++ src/SalomeApp/SalomeApp_Application.cxx | 76 ++++++++++--------- src/SalomeApp/SalomeApp_Application.h | 6 +- src/SalomeApp/SalomeApp_Module.cxx | 53 +++++++++++++ src/SalomeApp/SalomeApp_Module.h | 3 + 19 files changed, 317 insertions(+), 66 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index cf4a79140..532f43e27 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -3082,14 +3082,36 @@ void LightApp_Application::moduleIconNames( QMap& iconMap ) co */ void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title ) { + //Add "Rename" item + LightApp_SelectionMgr* selMgr = LightApp_Application::selectionMgr(); + SUIT_DataBrowser* ob = objectBrowser(); + CAM_Application::contextMenuPopup( type, thePopup, title ); - SUIT_DataBrowser* ob = objectBrowser(); if ( ob && type == ob->popupClientType() ) { thePopup->addSeparator(); QAction* a = thePopup->addAction( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); - if ( ob->updateKey() ) - a->setShortcut( ob->updateKey() ); + if ( ob->shortcutKey(SUIT_DataBrowser::UpdateShortcut) ) + a->setShortcut( ob->shortcutKey(SUIT_DataBrowser::UpdateShortcut) ); + } + + if(selMgr && ob) { + SALOME_ListIO selected; + selMgr->selectedObjects( selected ); + if(selected.Extent() == 1){ + Handle(SALOME_InteractiveObject) anIObject = selected.First(); + SUIT_DataObject* obj = findObject(anIObject->getEntry()); + if(obj && obj->renameAllowed()) { + QAction* a = new QAction(tr("MEN_RENAME_OBJ"), thePopup); + connect( a, SIGNAL( triggered(bool) ), ob, SLOT( onStartEditing() ) ); + if ( ob->shortcutKey(SUIT_DataBrowser::RenameShortcut) ) + a->setShortcut( ob->shortcutKey(SUIT_DataBrowser::RenameShortcut) ); + + QList acts = thePopup->actions(); + QAction* firstAction = acts.count() > 0 ? acts.first() : 0; + thePopup->insertAction(firstAction,a); + } + } } } @@ -3589,3 +3611,22 @@ SUIT_DataObject* LightApp_Application::findObject( const QString& id ) const LightApp_Study* study = dynamic_cast( activeStudy() ); return study ? study->findObjectByEntry( id ) : 0; } + +/*! + Checks that an object can be renamed. + \param entry entry of the object + \brief Return \c true if object can be renamed +*/ +bool LightApp_Application::renameAllowed( const QString& /*entry*/) const { + return false; +} + +/*! + Rename object by entry. + \param entry entry of the object + \param name new name of the object + \brief Return \c true if rename operation finished successfully, \c false otherwise. +*/ +bool LightApp_Application::renameObject( const QString& entry, const QString& ) { + return false; +} diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 59dba611e..246d75c7c 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -166,6 +166,9 @@ public: virtual SUIT_DataObject* findObject( const QString& ) const; + virtual bool renameAllowed( const QString& ) const; + virtual bool renameObject( const QString&, const QString& ); + signals: void studyOpened(); void studySaved(); diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx index 8723a26e4..78f1ddb0a 100644 --- a/src/LightApp/LightApp_DataObject.cxx +++ b/src/LightApp/LightApp_DataObject.cxx @@ -26,9 +26,11 @@ #include "LightApp_DataObject.h" #include "LightApp_Study.h" #include "LightApp_DataModel.h" +#include "LightApp_Module.h" +#include "LightApp_Application.h" #include -#include +#include #include @@ -148,6 +150,52 @@ bool LightApp_DataObject::isVisible() const return r && r->study() && componentDataType() != r->study()->getVisualComponentName(); } + +/*! + \brief Check if this object is can't be renamed in place + + This method can be re-implemented in the subclasses. + Default implementation returns \c false (all objects can not be renamed). + + \param id column id + \return \c true if the item can be renamed by the user in place (e.g. in the Object browser) +*/ +bool LightApp_DataObject::renameAllowed( const int id ) const +{ + if ( id == NameId ) { + LightApp_Module* m = dynamic_cast( module() ); + LightApp_Application* app = 0; + LightApp_RootObject* r = dynamic_cast( root() ); + if(r && r->study()) + app = dynamic_cast(r->study()->application()); + + return ( m && m->renameAllowed( entry() ) ) || + ( app && app->renameAllowed( entry() ) ); + } + return CAM_DataObject::renameAllowed( id ); +} + + +/*! + \brief Set name of the this object. + + This method can be re-implemented in the subclasses. + Default implementation returns \c false. + + \return \c true if rename operation finished successfully, \c false otherwise. +*/ +bool LightApp_DataObject::setName(const QString& name) +{ + LightApp_Module* m = dynamic_cast( module() ); + LightApp_RootObject* r = dynamic_cast( root() ); + LightApp_Application* app = (r && r->study()) ? dynamic_cast(r->study()->application()) : 0; + + return ( m && m->renameObject( entry(), name ) ) || + ( app && app->renameObject( entry(), name ) ); + return CAM_DataObject::setName(name); +} + + /*! \brief Get object string identifier. diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h index cff5cde01..8bac24554 100644 --- a/src/LightApp/LightApp_DataObject.h +++ b/src/LightApp/LightApp_DataObject.h @@ -60,6 +60,8 @@ public: virtual QVariant customData(Qtx::CustomDataType type); virtual bool isVisible() const; + virtual bool renameAllowed( const int = NameId ) const; + virtual bool setName( const QString& ); protected: QString myCompDataType; diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index c456acd82..451ee3efe 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -702,6 +702,26 @@ void LightApp_Module::paste() { } +/*! + \brief Return \c true if object can be renamed +*/ +bool LightApp_Module::renameAllowed( const QString& /*entry*/ ) const +{ + return false; +} + +/*! + Rename object by entry. + \param entry entry of the object + \param name new name of the object + \brief Return \c true if rename operation finished successfully, \c false otherwise. +*/ +bool LightApp_Module::renameObject( const QString& /*entry*/, const QString& /*name*/ ) +{ + return false; +} + + int LightApp_Module::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) { diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index e86ce87a2..f7bc9c586 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -97,6 +97,8 @@ public: virtual bool canPaste() const; virtual void copy(); virtual void paste(); + virtual bool renameAllowed( const QString& ) const; + virtual bool renameObject( const QString&, const QString& ); int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 ); int createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 ); diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index e09fca139..4141f4291 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -318,6 +318,10 @@ The changes will be applied on the next application session. TOT_RENAME Rename + + MEN_RENAME_OBJ + Rename + LOG_WINDOW Message Window diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 5e5d4a601..8fa666c71 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -358,7 +358,8 @@ void OB_Browser::setShowToolTips( const bool theDisplay ) */ int OB_Browser::numberOfSelected() const { - return myView->selectionModel() ? myView->selectionModel()->selectedIndexes().count() : 0; + // we take selection by rows + return myView->selectionModel() ? myView->selectionModel()->selectedRows().count() : 0; } /*! @@ -367,7 +368,8 @@ int OB_Browser::numberOfSelected() const */ QModelIndexList OB_Browser::selectedIndexes() const { - return myView->selectionModel() ? myView->selectionModel()->selectedIndexes() : QModelIndexList(); + // we take selection by rows + return myView->selectionModel() ? myView->selectionModel()->selectedRows() : QModelIndexList(); } /*! diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx index 7b9df644c..d4879e5e0 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx @@ -101,9 +101,10 @@ QString SALOME_PYQT_DataObjectLight::toolTip(const int index) const } -void SALOME_PYQT_DataObjectLight::setName(const QString& name) +bool SALOME_PYQT_DataObjectLight::setName(const QString& name) { myName = name; + return true; } void SALOME_PYQT_DataObjectLight::setIcon(const QString& iconname) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h index e2bca6dcc..7170d43b1 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h @@ -47,7 +47,7 @@ class SALOME_PYQT_LIGHT_EXPORT SALOME_PYQT_DataObjectLight : public virtual Ligh QPixmap icon(const int = NameId) const; QString toolTip(const int = NameId) const; - void setName(const QString& name); + bool setName(const QString& name); void setIcon(const QString& icon); void setToolTip(const QString& tooltip); diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index 5742350eb..d8b7df304 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -158,29 +158,27 @@ void SUIT_DataBrowser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) } /*! - \brief Get current key accelerator used for the - object browser update operation. + \brief Get current key accelerator by id. \return current key accelerator - \sa setUpdateKey(), requestUpdate() + \sa setShortcutKey(), requestUpdate(), requestRename() */ -int SUIT_DataBrowser::updateKey() const +int SUIT_DataBrowser::shortcutKey(const int id) const { - return myShortcut->key(); + return myShortcutMap.value(id)->key(); } /*! - \brief Assign the key accelerator to be used for the - object browser update operation. - - By default, \c [F5] key is assigned for the update operation. - To disable the accelerator, pass 0 to this method. - + \brief Assign the key accelerator for the shortcut. + + \param id id of the shortcut \param key new key accelerator - \sa updateKey(), requestUpdate() + \sa shortcutKey(), requestUpdate(), requestRename() */ -void SUIT_DataBrowser::setUpdateKey( const int key ) -{ - myShortcut->setKey( key ); +void SUIT_DataBrowser::setShortcutKey( const int id, const int key ) +{ + ShortcutMap::iterator it = myShortcutMap.find( key ); + if( it != myShortcutMap.end() ) + (*it)->setKey(key); } /*! @@ -349,7 +347,11 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) this, SLOT( onDblClicked( const QModelIndex& ) ) ); connect( treeView(), SIGNAL( expanded( const QModelIndex& ) ), this, SLOT( onExpanded( const QModelIndex& ) ) ); - myShortcut = new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) ); + connect( this , SIGNAL( requestRename() ), + this , SLOT ( onStartEditing() )); + + myShortcutMap.insert(UpdateShortcut , new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) ) ); + myShortcutMap.insert(RenameShortcut , new QShortcut( Qt::Key_F2, this, SIGNAL( requestRename() ), SIGNAL( requestRename() ) ) ); myAutoSizeFirstColumn = true; myAutoSizeColumns = false; @@ -362,9 +364,9 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) assigned for the update operation is pressed by the user. By default, \c [F5] key is assigned for the update operation. - The key accelerator can be changed with the setUpdateKey() method. + The key accelerator can be changed with the setShortcutKey() method. - \sa updateKey(), setUpdateKey() + \sa shortcutKey(), setShortcutKey() */ /*! @@ -442,3 +444,15 @@ void SUIT_DataBrowser::onExpanded( const QModelIndex& index ) } } +/*! + \brief Make editable selected item in place. + \internal +*/ +void SUIT_DataBrowser::onStartEditing() { + DataObjectList sel = getSelected(); + SUIT_ProxyModel* m = qobject_cast( model() ); + if(treeView() && m && sel.count() == 1){ + treeView()->edit(m->index( sel.first(), SUIT_DataObject::NameId )); + } +} + diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index 92ba03b8e..af0e7e8ff 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -38,6 +38,8 @@ public: SUIT_DataBrowser( QWidget* = 0 ); SUIT_DataBrowser( SUIT_DataObject*, QWidget* = 0 ); ~SUIT_DataBrowser(); + + enum {UpdateShortcut = 0, RenameShortcut}; virtual QString popupClientType() const; @@ -52,8 +54,8 @@ public: void updateTree( SUIT_DataObject* = 0, const bool = true ); - int updateKey() const; - void setUpdateKey( const int ); + int shortcutKey(const int) const; + void setShortcutKey( const int, const int ); DataObjectList getSelected() const; void getSelected( DataObjectList& ) const; @@ -75,6 +77,7 @@ private: signals: void requestUpdate(); + void requestRename(); void clicked( SUIT_DataObject* ); void doubleClicked( SUIT_DataObject* ); @@ -83,9 +86,11 @@ private slots: void onClicked( const QModelIndex& ); void onDblClicked( const QModelIndex& ); void onExpanded( const QModelIndex& ); + void onStartEditing(); private: - QShortcut* myShortcut; + typedef QMap ShortcutMap; + ShortcutMap myShortcutMap; bool myAutoSizeFirstColumn; bool myAutoSizeColumns; diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index f8d8f23a9..77f951c26 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -634,6 +634,32 @@ bool SUIT_DataObject::isCheckable( const int /*id*/ ) const return false; } +/*! + \brief Check if this object is can't be renamed in place + + This method can be re-implemented in the subclasses. + Default implementation returns \c false (all objects can not be renamed). + + \param id column id + \return \c true if the item can be renamed by the user in place (e.g. in the Object browser) +*/ +bool SUIT_DataObject::renameAllowed( const int /*id*/ ) const +{ + return false; +} + +/*! + \brief Set name of the this object. + + This method can be re-implemented in the subclasses. + Default implementation returns \c false. + + \return \c true if rename operation finished successfully, \c false otherwise. +*/ +bool SUIT_DataObject::setName(const QString& /*name*/) { + return false; +} + /*! \brief Get the checked state of the object (if it is checkable) for the specified column. diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 73792a514..7f0f04b20 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -121,6 +121,8 @@ public: virtual bool isEnabled() const; virtual bool isSelectable() const; virtual bool isCheckable( const int = NameId ) const; + virtual bool renameAllowed( const int = NameId ) const; + virtual bool setName(const QString& name); virtual bool isOn( const int = NameId ) const; virtual void setOn( const bool, const int = NameId ); diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 2583d8a84..98257d17b 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -822,6 +822,10 @@ QVariant SUIT_TreeModel::data( const QModelIndex& index, int role ) const // data object text for the specified column val = obj->text( id ); break; + case EditRole: + // data object text for the specified column (for editor) + val = obj->text( id ); + break; case DecorationRole: { if(id == SUIT_DataObject::VisibilityId) { int anId = obj->customData(Qtx::IdType).toInt(); @@ -942,6 +946,15 @@ bool SUIT_TreeModel::setData( const QModelIndex& index, return true; } break; + case EditRole: { + QString val = value.toString(); + if ( !val.isEmpty() && obj->setName(val) ) { + emit( dataChanged( index, index ) ); + return true; + } + return false; + break; + } default: break; } @@ -975,6 +988,10 @@ Qt::ItemFlags SUIT_TreeModel::flags( const QModelIndex& index ) const // data object is checkable if ( obj->isCheckable( index.column() ) ) f = f | Qt::ItemIsUserCheckable; + + // data object can be renamed + if ( obj->renameAllowed( index.column() ) ) + f = f | Qt::ItemIsEditable; } return f; } diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 296ebec85..afbcbb1d0 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1268,8 +1268,9 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePop QString( aList.First()->getEntry() ).startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) ) { thePopup->addSeparator(); thePopup->addAction( tr( "MEN_RESTORE_VS" ), this, SLOT( onRestoreGUIState() ) ); - thePopup->addAction( tr( "MEN_RENAME_VS" ), this, SLOT( onRenameGUIState() ) ); - thePopup->addAction( tr( "MEN_DELETE_VS" ), this, SLOT( onDeleteGUIState() ) ); + thePopup->addAction( tr( "MEN_RENAME_VS" ), objectBrowser(), + SLOT( onStartEditing() ), objectBrowser()->shortcutKey(SUIT_DataBrowser::RenameShortcut) ); + thePopup->addAction( tr( "MEN_DELETE_VS" ), this, SLOT( onDeleteGUIState() ) ); } // "Delete reference" item should appear only for invalid references @@ -1443,14 +1444,17 @@ int getSelectedSavePoint( const LightApp_SelectionMgr* selMgr ) { SALOME_ListIO aList; selMgr->selectedObjects( aList ); - Handle(SALOME_InteractiveObject) aIObj = aList.First(); - QString entry( aIObj->getEntry() ); - QString startStr = QObject::tr( "SAVE_POINT_DEF_NAME" ); - if ( !entry.startsWith( startStr ) ) // it's a "GUI state" object - return -1; - bool ok; // conversion to integer is ok? - int savePoint = entry.right( entry.length() - startStr.length() ).toInt( &ok ); - return ok ? savePoint : -1; + if( aList.Extent() > 0 ) { + Handle(SALOME_InteractiveObject) aIObj = aList.First(); + QString entry( aIObj->getEntry() ); + QString startStr = QObject::tr( "SAVE_POINT_DEF_NAME" ); + if ( !entry.startsWith( startStr ) ) // it's a "GUI state" object + return -1; + bool ok; // conversion to integer is ok? + int savePoint = entry.right( entry.length() - startStr.length() ).toInt( &ok ); + return ok ? savePoint : -1; + } + return -1; } /*!Called on Restore GUI State popup command*/ @@ -1462,26 +1466,6 @@ void SalomeApp_Application::onRestoreGUIState() SalomeApp_VisualState( this ).restoreState( savePoint ); } -/*!Called on Rename GUI State popup command*/ -void SalomeApp_Application::onRenameGUIState() -{ - int savePoint = ::getSelectedSavePoint( selectionMgr() ); - if ( savePoint == -1 ) - return; - SalomeApp_Study* study = dynamic_cast( activeStudy() ); - if ( !study ) - return; - - QString newName = LightApp_NameDlg::getName( desktop(), study->getNameOfSavePoint( savePoint ) ); - if ( !newName.isNull() && !newName.isEmpty() ) { - study->setNameOfSavePoint( savePoint, newName ); - updateSavePointDataObjects( study ); - // temporary commented - //objectBrowser()->updateTree( study->root() ); - } -} - - /*!Called on Delete GUI State popup command*/ void SalomeApp_Application::onDeleteGUIState() { @@ -1820,11 +1804,33 @@ void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) { } /*! - Called then study closed + Checks that an object can be renamed. + \param entry entry of the object + \brief Return \c true if object can be renamed */ -void SalomeApp_Application::onStudyClosed( SUIT_Study* theStudy){ - LightApp_Application::onStudyClosed(theStudy); +bool SalomeApp_Application::renameAllowed( const QString& entry) const { + return entry.startsWith( tr( "SAVE_POINT_DEF_NAME") ); +} - disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), - this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); +/*! + Rename object by entry. + \param entry entry of the object + \param name new name of the object + \brief Return \c true if rename operation finished successfully, \c false otherwise. +*/ +bool SalomeApp_Application::renameObject( const QString& entry, const QString& name ) { + + SalomeApp_Study* aStudy = dynamic_cast( activeStudy() ); + + int savePoint = ::getSelectedSavePoint( selectionMgr() ); + + if(!aStudy || savePoint == -1) + return false; + + if ( !name.isNull() && !name.isEmpty() ) { + aStudy->setNameOfSavePoint( savePoint, name ); + updateSavePointDataObjects( aStudy ); + return true; + } + return false; } diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 2278671bc..99fb5ab5a 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -111,8 +111,11 @@ public: //! update visibility state of objects void updateVisibilityState( DataObjectList& theList, - SUIT_ViewModel* theViewModel ); + SUIT_ViewModel* theViewModel ); + virtual bool renameAllowed( const QString& ) const; + virtual bool renameObject( const QString&, const QString& ); + public slots: virtual void onLoadDoc(); virtual void onNewWithScript(); @@ -164,7 +167,6 @@ private slots: void onDeleteGUIState(); void onRestoreGUIState(); - void onRenameGUIState(); void onCatalogGen(); void onRegDisplay(); diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index 4e176537d..27c6d7e78 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -41,10 +41,13 @@ #include #include +#include #include #include #include +#include +#include #include @@ -238,3 +241,53 @@ void SalomeApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColum if ( id != -1 ) startOperation( id ); } + + +/*! + Called then study closed +*/ +void SalomeApp_Application::onStudyClosed( SUIT_Study* theStudy){ + LightApp_Application::onStudyClosed(theStudy); + + disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); +} + +/*! + \brief Check if this object is can't be renamed in place + + This method can be re-implemented in the subclasses. + Return true in case if object isn't reference or component (module root). + + \param id column id + \return \c true if the item can be renamed by the user in place (e.g. in the Object browser) +*/ +bool SalomeApp_Module::renameAllowed( const QString& entry) const { + + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + + SalomeApp_Study* appStudy = app ? dynamic_cast( app->activeStudy() ) : 0; + + SalomeApp_DataObject* obj = appStudy ? dynamic_cast(appStudy->findObjectByEntry(entry)) : 0; + + return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference()); +} + +/*! + \brief Show warning message box and return c\ false in case if current study locked, + \c true otherwise. +*/ +bool SalomeApp_Module::renameObject( const QString& /*entry*/, const QString& /*name*/) { + + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + SalomeApp_Study* appStudy = app ? dynamic_cast(app->activeStudy()) : 0; + + if ( appStudy && appStudy->studyDS()) { + bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked(); + if ( aLocked ) { + SUIT_MessageBox::warning ( app->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") ); + return false; + } + } + return true; +} diff --git a/src/SalomeApp/SalomeApp_Module.h b/src/SalomeApp/SalomeApp_Module.h index 8f12259e3..dc1f84513 100644 --- a/src/SalomeApp/SalomeApp_Module.h +++ b/src/SalomeApp/SalomeApp_Module.h @@ -63,6 +63,9 @@ public: virtual void storeVisualParameters(int savePoint); virtual void restoreVisualParameters(int savePoint); virtual LightApp_Selection* createSelection() const; + + virtual bool renameAllowed( const QString& ) const; + virtual bool renameObject( const QString&, const QString& ); public slots: virtual bool activateModule( SUIT_Study* ); -- 2.39.2