Salome HOME
Add an example for inplace rename functionality usage
[samples/light.git] / src / LIGHTGUI / LIGHTGUI.cxx
index b6d5c75a52768a9e5e65869b7f13082b00b86319..cf33c861c5f31e78e6875bcca7a33ff2c4751f17 100644 (file)
@@ -589,6 +589,43 @@ void LIGHTGUI::onClear()
   updateObjBrowser( true );
 }
 
+/*!
+  \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 entry column id
+  \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
+*/
+bool LIGHTGUI::renameAllowed( const QString& entry ) const
+{
+  LIGHTGUI_DataModel* dm = dynamic_cast<LIGHTGUI_DataModel*>( dataModel() );
+  return dm && dm->lineNb( entry ) >= 0;
+}
+
+/*!
+  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 LIGHTGUI::renameObject( const QString& entry, const QString& name )
+{
+  bool result = false;
+
+  LIGHTGUI_DataModel* dm = dynamic_cast<LIGHTGUI_DataModel*>( dataModel() );
+  if ( dm && dm->lineNb( entry ) ) {
+    int id = LIGHTGUI_DataModel::id( entry );
+    result = dm->setLineText( id, name );
+    if ( result ) {
+      updateLine( id, true );
+      updateObjBrowser( true );
+    }
+  }
+  return result;
+}
+
 /*!
   \fn CAM_Module* createModule();
   \brief Export module instance (factory function).