1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_DataBrowser.h"
24 #include "HYDROGUI_Module.h"
25 #include "HYDROGUI_DataObject.h"
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>
38 #define VISIBILITY_COLUMN_WIDTH 25
40 HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_DataObject* theRoot, QWidget* theParent )
41 : SUIT_DataBrowser( theRoot, theParent ), myModule( theModule )
43 SUIT_ResourceMgr* resMgr = theModule->getApp()->resourceMgr();
45 if ( ( !theRoot ) && theModule )
47 // Initialize the root with the module data model
48 setRoot( new CAM_ModuleObject( theModule->dataModel(), NULL ) );
51 setSortMenuEnabled( true );
52 setAutoUpdate( true );
53 setUpdateModified( true );
55 if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
56 searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
58 setWindowTitle( tr( "OBJECT_BROWSER" ) );
59 connect( this, SIGNAL( requestUpdate() ), theModule->getApp(), SLOT( onRefresh() ) );
61 QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
62 QString RefObjCol = tr( "REF_OBJECT_COLUMN" );
63 QString BathymetryCol = tr( "BATHYMETRY_COLUMN" );
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, BathymetryCol, HYDROGUI_DataObject::BathymetryId );
73 treeModel->setAppropriate( BathymetryCol, Qtx::Toggled );
75 // Mantis issue 0020136: Drag&Drop in OB
76 SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
79 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
80 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
82 //// Connect signal emitted after editing for updating after objects renaming
83 SUIT_TreeModel* aMiniModel = dynamic_cast<SUIT_TreeModel*>( proxyModel->sourceModel() );
86 connect( aMiniModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ),
87 SIGNAL( dataChanged() ) );
90 // Do updating also in the module's main object browser.
93 SUIT_DataBrowser* aModulBrowser = theModule->getApp()->objectBrowser();
96 SUIT_ProxyModel* aPModel = dynamic_cast<SUIT_ProxyModel*>(aModulBrowser->model());
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() ) );
110 // temporary commented
112 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( listView() ) );
114 ob_list->setColumnMaxWidth( 0, theModule->getApp()->desktop()->width()/4 );
116 setFilter( new LightApp_OBFilter( theModule->getApp()->selectionMgr() ) );
120 new LightApp_OBSelector( this, theModule->getApp()->selectionMgr() );
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* ) ) );
130 HYDROGUI_DataBrowser::~HYDROGUI_DataBrowser()
134 SUIT_DataObject* HYDROGUI_DataBrowser::findObject( const QString& theEntry ) const
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 )