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
41 #include <SUIT_Selector.h>
42 #include <SUIT_DataOwner.h>
46 class SUIT_DataBrowser;
47 class LightApp_DataObject;
50 #include "LightApp_DataOwner.h"
51 #include "LightApp_DataObject.h"
52 #include "LightApp_Application.h"
53 #include <SUIT_DataBrowser.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_DataObjectIterator.h>
60 // The selector is redefined in order to correct the selection in the browser.
61 // The main modification is to call fillEntries without the selector modified
62 // time compare. The modified time is result of the clock() method.
63 // On Linux, the method clock() returns the same values with some delay. So, it is possible,
64 // that time has the same value, but the browser has already other objects.
65 // So, the obsole entries can be in the saved entries by the filled method.
66 // May be it will be improved in the latest version of GUI_SRC.
67 // This redefinition is done for tag V7_3_0 of GUI_SRC.
68 class HYDROGUI_OBSelector : public LightApp_OBSelector
71 HYDROGUI_OBSelector( SUIT_DataBrowser*, SUIT_SelectionMgr* );
72 virtual ~HYDROGUI_OBSelector();
75 virtual void getSelection( SUIT_DataOwnerPtrList& ) const;
76 virtual void setSelection( const SUIT_DataOwnerPtrList& );
79 void fillEntries( QMap<QString, LightApp_DataObject*>& );
82 SUIT_DataOwnerPtrList mySelectedList;
83 QMap<QString, LightApp_DataObject*> myEntries;
86 HYDROGUI_OBSelector::HYDROGUI_OBSelector( SUIT_DataBrowser* ob, SUIT_SelectionMgr* mgr )
87 : LightApp_OBSelector( ob, mgr )
94 HYDROGUI_OBSelector::~HYDROGUI_OBSelector()
99 \brief Get list of currently selected objects.
100 \param theList list to be filled with the selected objects owners
101 \ This method is necessary to fill the cach containter mySelectedList
102 \ It is the same as in LightApp_OBSelector
104 void HYDROGUI_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
106 SUIT_DataBrowser* aBrowser = browser();
108 if ( mySelectedList.count() == 0 ) {
109 SUIT_Session* session = SUIT_Session::session();
110 SUIT_Application* sapp = session ? session->activeApplication() : 0;
111 LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
112 if( !app || !aBrowser )
115 DataObjectList objlist;
116 aBrowser->getSelected( objlist );
117 HYDROGUI_OBSelector* that = (HYDROGUI_OBSelector*)this;
118 QListIterator<SUIT_DataObject*> it( objlist );
119 while ( it.hasNext() ) {
120 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.next() );
121 if ( obj && app->checkDataObject( obj) ) {
122 #ifndef DISABLE_SALOMEOBJECT
123 Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject
124 ( obj->entry().toLatin1().constData(),
125 obj->componentDataType().toLatin1().constData(),
126 obj->name().toLatin1().constData() );
127 LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj );
129 LightApp_DataOwner* owner = new LightApp_DataOwner( obj->entry() );
131 that->mySelectedList.append( SUIT_DataOwnerPtr( owner ) );
135 theList = mySelectedList;
139 \brief Set selection.
140 \param theList list of the object owners to be set selected
141 \ It is the same as in LightApp_OBSelector. The difference is in the row with
142 \ the modification time check.
144 void HYDROGUI_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
146 SUIT_DataBrowser* aBrowser = browser();
150 // this is the difference to LightApp_OBSelector. For this, this class is redefined
151 //if( myEntries.count() == 0 || myModifiedTime < aBrowser->getModifiedTime() )
153 fillEntries( myEntries );
156 DataObjectList objList;
157 for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin();
158 it != theList.end(); ++it ) {
159 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
161 if ( owner && myEntries.contains( owner->entry() ) )
162 objList.append( myEntries[owner->entry()] );
165 aBrowser->setSelected( objList );
166 mySelectedList.clear();
170 \brief Fill map of the data objects currently shown in the Object Browser.
171 \param entries map to be filled
172 \ It is the same as in LightApp_OBSelector
174 void HYDROGUI_OBSelector::fillEntries( QMap<QString, LightApp_DataObject*>& entries )
178 SUIT_DataBrowser* aBrowser = browser();
182 for ( SUIT_DataObjectIterator it( aBrowser->root(),
183 SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
184 LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.current() );
186 entries.insert( obj->entry(), obj );
193 HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_DataObject* theRoot, QWidget* theParent )
194 : SUIT_DataBrowser( theRoot, theParent ), myModule( theModule )
196 SUIT_ResourceMgr* resMgr = theModule->getApp()->resourceMgr();
198 if ( ( !theRoot ) && theModule )
200 // Initialize the root with the module data model
201 setRoot( new CAM_ModuleObject( theModule->dataModel(), NULL ) );
204 setSortMenuEnabled( true );
205 setAutoUpdate( true );
206 setUpdateModified( true );
208 if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
209 searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
211 setWindowTitle( tr( "OBJECT_BROWSER" ) );
212 connect( this, SIGNAL( requestUpdate() ), theModule->getApp(), SLOT( onRefresh() ) );
214 QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
215 QString RefObjCol = tr( "REF_OBJECT_COLUMN" );
216 QString AltitudeCol = tr( "ALTITUDE_COLUMN" );
218 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( model() );
219 //RKV: treeModel->setSearcher( theModule->getApp() );
220 treeModel->setSearcher( this ); //RKV
221 treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId );
222 treeModel->setAppropriate( EntryCol, Qtx::Toggled );
223 treeModel->registerColumn( 0, RefObjCol, HYDROGUI_DataObject::RefObjectId );
224 treeModel->setAppropriate( RefObjCol, Qtx::Toggled );
225 treeModel->registerColumn( 0, AltitudeCol, HYDROGUI_DataObject::AltitudeObjId );
226 treeModel->setAppropriate( AltitudeCol, Qtx::Toggled );
228 // Mantis issue 0020136: Drag&Drop in OB
229 SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
232 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
233 SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
235 //// Connect signal emitted after editing for updating after objects renaming
236 SUIT_TreeModel* aMiniModel = dynamic_cast<SUIT_TreeModel*>( proxyModel->sourceModel() );
239 connect( aMiniModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ),
240 SIGNAL( dataChanged() ) );
243 // Do updating also in the module's main object browser.
246 SUIT_DataBrowser* aModulBrowser = theModule->getApp()->objectBrowser();
249 SUIT_ProxyModel* aPModel = dynamic_cast<SUIT_ProxyModel*>(aModulBrowser->model());
252 SUIT_TreeModel* aModel = dynamic_cast<SUIT_TreeModel*>(aPModel->sourceModel());
253 //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ),
254 // aPModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
255 //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ),
256 // aModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
257 connect( proxyModel, SIGNAL( modelUpdated() ), aModel, SIGNAL( modelUpdated() ) );
263 // temporary commented
265 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( listView() ) );
267 ob_list->setColumnMaxWidth( 0, theModule->getApp()->desktop()->width()/4 );
269 setFilter( new LightApp_OBFilter( theModule->getApp()->selectionMgr() ) );
273 new HYDROGUI_OBSelector( this, theModule->getApp()->selectionMgr() );
275 treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
276 treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);
277 treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH);
278 treeView()->hideColumn( SUIT_DataObject::VisibilityId );
279 treeView()->hideColumn( LightApp_DataObject::EntryId );
280 //RKV: connectPopupRequest( theModule->getApp(), SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
283 HYDROGUI_DataBrowser::~HYDROGUI_DataBrowser()
287 SUIT_DataObject* HYDROGUI_DataBrowser::findObject( const QString& theEntry ) const
289 LightApp_DataObject* aCurObj;
290 for ( SUIT_DataObjectIterator it( root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
291 aCurObj = dynamic_cast<LightApp_DataObject*>( it.current() );
292 if ( aCurObj && aCurObj->entry() == theEntry )