Salome HOME
The bathymetry is changed to their base altitude class for geometry objects (Bug...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataBrowser.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_DataBrowser.h"
24 #include "HYDROGUI_Module.h"
25 #include "HYDROGUI_DataObject.h"
26
27 #include <LightApp_Application.h>
28 #include <LightApp_OBSelector.h>
29 #include <LightApp_SelectionMgr.h>
30 #include <QHeaderView>
31 #include <QtxSearchTool.h>
32 #include <QtxTreeView.h>
33 #include <SUIT_DataObject.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_SelectionMgr.h>
36 #include <SUIT_DataObjectIterator.h>
37         
38 #define VISIBILITY_COLUMN_WIDTH 25
39
40 HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_DataObject* theRoot, QWidget* theParent )
41 : SUIT_DataBrowser( theRoot, theParent ), myModule( theModule )
42 {
43   SUIT_ResourceMgr* resMgr = theModule->getApp()->resourceMgr();
44
45   if ( ( !theRoot ) && theModule )
46   {
47     // Initialize the root with the module data model
48     setRoot( new CAM_ModuleObject( theModule->dataModel(), NULL ) );
49   }
50
51   setSortMenuEnabled( true );
52   setAutoUpdate( true );
53   setUpdateModified( true );
54
55   if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
56     searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
57
58   setWindowTitle( tr( "OBJECT_BROWSER" ) );
59   connect( this, SIGNAL( requestUpdate() ), theModule->getApp(), SLOT( onRefresh() ) );
60
61   QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
62   QString RefObjCol = tr( "REF_OBJECT_COLUMN" );
63   QString AltitudeCol = tr( "ALTITUDE_COLUMN" );
64
65   SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( model() );
66   //RKV: treeModel->setSearcher( theModule->getApp() );
67   treeModel->setSearcher( this ); //RKV
68   treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId );
69   treeModel->setAppropriate( EntryCol, Qtx::Toggled );
70   treeModel->registerColumn( 0, RefObjCol, HYDROGUI_DataObject::RefObjectId );
71   treeModel->setAppropriate( RefObjCol, Qtx::Toggled );
72   treeModel->registerColumn( 0, AltitudeCol, HYDROGUI_DataObject::AltitudeObjId );
73   treeModel->setAppropriate( AltitudeCol, Qtx::Toggled );
74
75   // Mantis issue 0020136: Drag&Drop in OB
76   SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
77   if ( proxyModel ) {
78     connect( proxyModel, 
79       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
80       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
81
82     //// Connect signal emitted after editing for updating after objects renaming
83     SUIT_TreeModel* aMiniModel = dynamic_cast<SUIT_TreeModel*>( proxyModel->sourceModel() );
84     if ( aMiniModel )
85     {
86       connect( aMiniModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
87         SIGNAL( dataChanged() ) );
88     }
89
90     // Do updating also in the module's main object browser.
91     if ( theModule )
92     {
93       SUIT_DataBrowser* aModulBrowser = theModule->getApp()->objectBrowser();
94       if ( aModulBrowser )
95       {
96         SUIT_ProxyModel* aPModel = dynamic_cast<SUIT_ProxyModel*>(aModulBrowser->model());
97         if ( aPModel )
98         {
99           SUIT_TreeModel* aModel = dynamic_cast<SUIT_TreeModel*>(aPModel->sourceModel());
100           //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
101           //  aPModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
102           //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
103           //  aModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
104           connect( proxyModel, SIGNAL( modelUpdated() ), aModel, SIGNAL( modelUpdated() ) );
105         }
106       }
107     }
108   }
109
110   // temporary commented
111   /*
112   OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( listView() ) );
113   if( ob_list )
114     ob_list->setColumnMaxWidth( 0, theModule->getApp()->desktop()->width()/4 );
115
116   setFilter( new LightApp_OBFilter( theModule->getApp()->selectionMgr() ) );
117   */
118
119   // Create OBSelector
120   new LightApp_OBSelector( this, theModule->getApp()->selectionMgr() );
121
122   treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
123   treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);
124   treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH);
125   treeView()->hideColumn( SUIT_DataObject::VisibilityId );
126   treeView()->hideColumn( LightApp_DataObject::EntryId );
127   //RKV: connectPopupRequest( theModule->getApp(), SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
128 }
129
130 HYDROGUI_DataBrowser::~HYDROGUI_DataBrowser()
131 {
132 }
133
134 SUIT_DataObject* HYDROGUI_DataBrowser::findObject( const QString& theEntry ) const
135 {
136   LightApp_DataObject* aCurObj;
137   for ( SUIT_DataObjectIterator it( root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
138     aCurObj = dynamic_cast<LightApp_DataObject*>( it.current() );
139     if ( aCurObj && aCurObj->entry() == theEntry )
140       return aCurObj;
141   }
142   return NULL;
143 }