Salome HOME
Fix for the bug #42: point C is not activated, but point C is shown in preview in...
[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   setSortMenuEnabled( true );
46   setAutoUpdate( true );
47
48   if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
49     searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
50
51   setWindowTitle( tr( "OBJECT_BROWSER" ) );
52   connect( this, SIGNAL( requestUpdate() ), theModule->getApp(), SLOT( onRefresh() ) );
53
54   QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
55   QString RefObjCol = tr( "REF_OBJECT_COLUMN" );
56   QString BathymetryCol = tr( "BATHYMETRY_COLUMN" );
57   SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( model() );
58   //RKV: treeModel->setSearcher( theModule->getApp() );
59   treeModel->setSearcher( this ); //RKV
60   treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId );
61   treeModel->setAppropriate( EntryCol, Qtx::Toggled );
62   treeModel->registerColumn( 0, RefObjCol, HYDROGUI_DataObject::RefObjectId );
63   treeModel->setAppropriate( RefObjCol, Qtx::Toggled );
64   treeModel->registerColumn( 0, BathymetryCol, HYDROGUI_DataObject::BathymetryId );
65   treeModel->setAppropriate( BathymetryCol, Qtx::Toggled );
66
67   // Mantis issue 0020136: Drag&Drop in OB
68   SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
69   if ( proxyModel ) {
70     connect( proxyModel, 
71       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
72       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
73   }
74
75   // temporary commented
76   /*
77   OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( listView() ) );
78   if( ob_list )
79     ob_list->setColumnMaxWidth( 0, theModule->getApp()->desktop()->width()/4 );
80
81   setFilter( new LightApp_OBFilter( theModule->getApp()->selectionMgr() ) );
82   */
83
84   // Create OBSelector
85   new LightApp_OBSelector( this, theModule->getApp()->selectionMgr() );
86
87   treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
88   treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);
89   treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH);
90   treeView()->hideColumn( SUIT_DataObject::VisibilityId );
91   treeView()->hideColumn( LightApp_DataObject::EntryId );
92   //RKV: connectPopupRequest( theModule->getApp(), SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
93 }
94
95 HYDROGUI_DataBrowser::~HYDROGUI_DataBrowser()
96 {
97 }
98
99 SUIT_DataObject* HYDROGUI_DataBrowser::findObject( const QString& theEntry ) const
100 {
101   LightApp_DataObject* aCurObj;
102   for ( SUIT_DataObjectIterator it( root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
103     aCurObj = dynamic_cast<LightApp_DataObject*>( it.current() );
104     if ( aCurObj && aCurObj->entry() == theEntry )
105       return aCurObj;
106   }
107   return NULL;
108 }