Salome HOME
Fix for the bug #255: VTK viewer is not updated after modification of objects.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataBrowser.cxx
index b6cdedb224516b134715593cbfc522844e113e1a..2c16b0c6383c3efdc03373dc493ce0ad033d9aab 100644 (file)
@@ -33,6 +33,7 @@
 #include <SUIT_DataObject.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_SelectionMgr.h>
+#include <SUIT_DataObjectIterator.h>
         
 #define VISIBILITY_COLUMN_WIDTH 25
 
@@ -41,8 +42,15 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat
 {
   SUIT_ResourceMgr* resMgr = theModule->getApp()->resourceMgr();
 
+  if ( ( !theRoot ) && theModule )
+  {
+    // Initialize the root with the module data model
+    setRoot( new CAM_ModuleObject( theModule->dataModel(), NULL ) );
+  }
+
   setSortMenuEnabled( true );
   setAutoUpdate( true );
+  setUpdateModified( true );
 
   if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
     searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
@@ -50,22 +58,54 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat
   setWindowTitle( tr( "OBJECT_BROWSER" ) );
   connect( this, SIGNAL( requestUpdate() ), theModule->getApp(), SLOT( onRefresh() ) );
 
+  QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
   QString RefObjCol = tr( "REF_OBJECT_COLUMN" );
-  QString BathymetryCol = tr( "BATHYMETRY_COLUMN" );
+  QString AltitudeCol = tr( "ALTITUDE_COLUMN" );
+
   SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( model() );
-  treeModel->setSearcher( theModule->getApp() );
+  //RKV: treeModel->setSearcher( theModule->getApp() );
+  treeModel->setSearcher( this ); //RKV
+  treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId );
+  treeModel->setAppropriate( EntryCol, Qtx::Toggled );
   treeModel->registerColumn( 0, RefObjCol, HYDROGUI_DataObject::RefObjectId );
   treeModel->setAppropriate( RefObjCol, Qtx::Toggled );
-  treeModel->registerColumn( 0, BathymetryCol, HYDROGUI_DataObject::BathymetryId );
-  treeModel->setAppropriate( BathymetryCol, Qtx::Toggled );
+  treeModel->registerColumn( 0, AltitudeCol, HYDROGUI_DataObject::AltitudeObjId );
+  treeModel->setAppropriate( AltitudeCol, Qtx::Toggled );
 
   // Mantis issue 0020136: Drag&Drop in OB
-  //RKV: TODO: Uncomment for drag and drop
-  //RKV: SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
-  //RKV: if ( proxyModel ) {
-  //RKV:   connect( proxyModel, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
-  //RKV:            theModule->getApp(), SLOT( onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
-  //RKV: }
+  SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
+  if ( proxyModel ) {
+    connect( proxyModel, 
+      SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
+      SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
+
+    //// Connect signal emitted after editing for updating after objects renaming
+    SUIT_TreeModel* aMiniModel = dynamic_cast<SUIT_TreeModel*>( proxyModel->sourceModel() );
+    if ( aMiniModel )
+    {
+      connect( aMiniModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
+        SIGNAL( dataChanged() ) );
+    }
+
+    // Do updating also in the module's main object browser.
+    if ( theModule )
+    {
+      SUIT_DataBrowser* aModulBrowser = theModule->getApp()->objectBrowser();
+      if ( aModulBrowser )
+      {
+        SUIT_ProxyModel* aPModel = dynamic_cast<SUIT_ProxyModel*>(aModulBrowser->model());
+        if ( aPModel )
+        {
+          SUIT_TreeModel* aModel = dynamic_cast<SUIT_TreeModel*>(aPModel->sourceModel());
+          //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
+          //  aPModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
+          //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
+          //  aModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
+          connect( proxyModel, SIGNAL( modelUpdated() ), aModel, SIGNAL( modelUpdated() ) );
+        }
+      }
+    }
+  }
 
   // temporary commented
   /*
@@ -82,9 +122,22 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat
   treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
   treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);
   treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH);
+  treeView()->hideColumn( SUIT_DataObject::VisibilityId );
+  treeView()->hideColumn( LightApp_DataObject::EntryId );
   //RKV: connectPopupRequest( theModule->getApp(), SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
 }
 
 HYDROGUI_DataBrowser::~HYDROGUI_DataBrowser()
 {
 }
+
+SUIT_DataObject* HYDROGUI_DataBrowser::findObject( const QString& theEntry ) const
+{
+  LightApp_DataObject* aCurObj;
+  for ( SUIT_DataObjectIterator it( root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
+    aCurObj = dynamic_cast<LightApp_DataObject*>( it.current() );
+    if ( aCurObj && aCurObj->entry() == theEntry )
+      return aCurObj;
+  }
+  return NULL;
+}