X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_DataBrowser.cxx;h=eb5f2539e9528b890fa1fa61dd49f6743b6bd33f;hb=39a306b77b32044c89bf6cef4445d5bfdea43149;hp=b6cdedb224516b134715593cbfc522844e113e1a;hpb=abe63c42525c9299302649cdb5dcff4f83368c26;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx index b6cdedb2..eb5f2539 100644 --- a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx +++ b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx @@ -1,12 +1,8 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -33,16 +29,182 @@ #include #include #include +#include #define VISIBILITY_COLUMN_WIDTH 25 -HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_DataObject* theRoot, QWidget* theParent ) + +#include +#include + +#include +#include +#include + +class SUIT_DataBrowser; +class LightApp_DataObject; + + +#include "LightApp_DataOwner.h" +#include "LightApp_DataObject.h" +#include "LightApp_Application.h" +#include +#include +#include +#include +#include + + +// The selector is redefined in order to correct the selection in the browser. +// The main modification is to call fillEntries without the selector modified +// time compare. The modified time is result of the clock() method. +// On Linux, the method clock() returns the same values with some delay. So, it is possible, +// that time has the same value, but the browser has already other objects. +// So, the obsole entries can be in the saved entries by the filled method. +// May be it will be improved in the latest version of GUI_SRC. +// This redefinition is done for tag V7_3_0 of GUI_SRC. +class HYDROGUI_OBSelector : public LightApp_OBSelector +{ +public: + HYDROGUI_OBSelector( SUIT_DataBrowser*, SUIT_SelectionMgr* ); + virtual ~HYDROGUI_OBSelector(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + +private: + void fillEntries( QMap& ); + +private: + SUIT_DataOwnerPtrList mySelectedList; + QMap myEntries; +}; + +HYDROGUI_OBSelector::HYDROGUI_OBSelector( SUIT_DataBrowser* ob, SUIT_SelectionMgr* mgr ) +: LightApp_OBSelector( ob, mgr ) +{ +} + +/*! + \brief Destructor. +*/ +HYDROGUI_OBSelector::~HYDROGUI_OBSelector() +{ +} + +/*! + \brief Get list of currently selected objects. + \param theList list to be filled with the selected objects owners + \ This method is necessary to fill the cach containter mySelectedList + \ It is the same as in LightApp_OBSelector +*/ +void HYDROGUI_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const +{ + SUIT_DataBrowser* aBrowser = browser(); + + if ( mySelectedList.count() == 0 ) { + SUIT_Session* session = SUIT_Session::session(); + SUIT_Application* sapp = session ? session->activeApplication() : 0; + LightApp_Application* app = dynamic_cast( sapp ); + if( !app || !aBrowser ) + return; + + DataObjectList objlist; + aBrowser->getSelected( objlist ); + HYDROGUI_OBSelector* that = (HYDROGUI_OBSelector*)this; + QListIterator it( objlist ); + while ( it.hasNext() ) { + LightApp_DataObject* obj = dynamic_cast( it.next() ); + if ( obj && app->checkDataObject( obj) ) { +#ifndef DISABLE_SALOMEOBJECT + Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject + ( obj->entry().toLatin1().constData(), + obj->componentDataType().toLatin1().constData(), + obj->name().toLatin1().constData() ); + LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj ); +#else + LightApp_DataOwner* owner = new LightApp_DataOwner( obj->entry() ); +#endif + that->mySelectedList.append( SUIT_DataOwnerPtr( owner ) ); + } + } + } + theList = mySelectedList; +} + +/*! + \brief Set selection. + \param theList list of the object owners to be set selected + \ It is the same as in LightApp_OBSelector. The difference is in the row with + \ the modification time check. +*/ +void HYDROGUI_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) +{ + SUIT_DataBrowser* aBrowser = browser(); + if ( !aBrowser ) + return; + + // this is the difference to LightApp_OBSelector. For this, this class is redefined + //if( myEntries.count() == 0 || myModifiedTime < aBrowser->getModifiedTime() ) + { + fillEntries( myEntries ); + } + + DataObjectList objList; + for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); + it != theList.end(); ++it ) { + const LightApp_DataOwner* owner = dynamic_cast( (*it).operator->() ); + + if ( owner && myEntries.contains( owner->entry() ) ) + objList.append( myEntries[owner->entry()] ); + } + + aBrowser->setSelected( objList ); + mySelectedList.clear(); +} + +/*! + \brief Fill map of the data objects currently shown in the Object Browser. + \param entries map to be filled + \ It is the same as in LightApp_OBSelector +*/ +void HYDROGUI_OBSelector::fillEntries( QMap& entries ) +{ + entries.clear(); + + SUIT_DataBrowser* aBrowser = browser(); + if ( !aBrowser ) + return; + + for ( SUIT_DataObjectIterator it( aBrowser->root(), + SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) { + LightApp_DataObject* obj = dynamic_cast( it.current() ); + if ( obj ) + entries.insert( obj->entry(), obj ); + } + + setModified(); +} + + +HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, + SUIT_DataObject* theRoot, + QWidget* theParent, + bool theLandCover/* = false*/) : SUIT_DataBrowser( theRoot, theParent ), myModule( theModule ) { 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 +212,58 @@ 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; + if ( theLandCover ) + AltitudeCol = tr( "LAND_COVER_COLUMN" ); + else + AltitudeCol = tr( "ALTITUDE_COLUMN" ); + SUIT_AbstractModel* treeModel = dynamic_cast( 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(treeModel); - //RKV: if ( proxyModel ) { - //RKV: connect( proxyModel, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), - //RKV: theModule->getApp(), SLOT( onDropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); - //RKV: } + SUIT_ProxyModel* proxyModel = dynamic_cast(treeModel); + if ( proxyModel ) { + connect( proxyModel, + SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), + SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); + + //// Connect signal emitted after editing for updating after objects renaming + SUIT_TreeModel* aMiniModel = dynamic_cast( 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(aModulBrowser->model()); + if ( aPModel ) + { + SUIT_TreeModel* aModel = dynamic_cast(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 /* @@ -77,14 +275,95 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat */ // Create OBSelector - new LightApp_OBSelector( this, theModule->getApp()->selectionMgr() ); + new HYDROGUI_OBSelector( this, theModule->getApp()->selectionMgr() ); 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); - //RKV: connectPopupRequest( theModule->getApp(), SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + treeView()->hideColumn( SUIT_DataObject::VisibilityId ); + treeView()->hideColumn( LightApp_DataObject::EntryId ); + 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( it.current() ); + if ( aCurObj && aCurObj->entry() == theEntry ) + return aCurObj; + } + return NULL; +} + +/*! + \brief Switch read only mode for the Object Browser. + \param theIsReadOnly if true - read only mode will be turned on +*/ +void HYDROGUI_DataBrowser::setReadOnly( const bool theIsReadOnly ) +{ + //TODO: to be reimplemented + + // Enable/disable edit triggers + foreach ( QTreeView* aView, findChildren() ) { + aView->setDragEnabled ( !theIsReadOnly ); + aView->setEditTriggers ( theIsReadOnly ? + QAbstractItemView::NoEditTriggers : + QAbstractItemView::DoubleClicked ); + } + + // Enable/disable rename shortcut + QList aShortcuts = findChildren(); + QShortcut* aShortcut; + foreach( aShortcut, aShortcuts ) { + if ( aShortcut->key() == QKeySequence( shortcutKey( RenameShortcut ) ) ) { + aShortcut->setEnabled( !theIsReadOnly ); + } + } +} + +void HYDROGUI_DataBrowser::createPopupMenu( QMenu* theMenu ) +{ + theMenu->clear(); + DataObjectList aSelection = getSelected(); + bool isOnlyZones = aSelection.size() > 0; + foreach( SUIT_DataObject* anObj, aSelection ) + { + HYDROGUI_DataObject* aHydroObj = dynamic_cast( anObj ); + if( aHydroObj ) + { + Handle(HYDROData_Entity) aModelObj = aHydroObj->modelObject(); + if( !aModelObj.IsNull() ) + { + isOnlyZones = aModelObj->GetKind()==KIND_ZONE; + if( !isOnlyZones ) + break; + + SUIT_DataObject* aParentObj = aHydroObj->parent(); + if ( aParentObj ) + { + isOnlyZones = aParentObj->childCount() > 1; + if( !isOnlyZones ) + break; + } + } + else + { + isOnlyZones = false; + break; + } + } + else + { + isOnlyZones = false; + break; + } + } + + if( isOnlyZones ) + theMenu->addAction( tr( "ZONE_TO_NEW_REGION" ), this, SIGNAL( newRegion() ) ); +}