From: vsr Date: Thu, 2 Aug 2007 14:03:51 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: qt4_porting_delivery_220807~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a022bf40a1744d0f6aeed8a0e310f2cdb37320e9;p=modules%2Fgui.git *** empty log message *** --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 631d87b2d..cbc77d065 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -2305,7 +2305,9 @@ void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopu LightApp_Browser* ob = objectBrowser(); if ( ob && type == ob->popupClientType() ) { thePopup->addSeparator(); - thePopup->addAction( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); + QAction* a = thePopup->addAction( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); + if ( ob->updateKey() ) + a->setShortcut( ob->updateKey() ); } } diff --git a/src/LightApp/LightApp_Browser.cxx b/src/LightApp/LightApp_Browser.cxx index 5cd4124c3..1a53bdf18 100644 --- a/src/LightApp/LightApp_Browser.cxx +++ b/src/LightApp/LightApp_Browser.cxx @@ -143,6 +143,80 @@ void LightApp_Browser::setUpdateKey( const int key ) myShortcut->setKey( key ); } +/*! + \brief Get list of selected data objects. + \return list of the currently selected data objects +*/ +DataObjectList LightApp_Browser::getSelected() const +{ + DataObjectList lst; + getSelected( lst ); + return lst; +} + +/*! + \brief Get list of selected data objects. + \overload + \param lst list to be filled with the currently selected data objects +*/ +void LightApp_Browser::getSelected( DataObjectList& lst ) const +{ + lst.clear(); + + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndexList sel = selectedIndexes(); + QModelIndex idx; + + foreach( idx, sel ) { + SUIT_DataObject* obj = m->object( idx ); + if ( obj ) + lst.append( obj ); + } + } +} + +/*! + \brief Set selected object. + \param obj data object to set selected + \param append if \c true, the object is added to the current selection; + otherwise the previous selection is first cleared +*/ +void LightApp_Browser::setSelected( const SUIT_DataObject* obj, const bool append ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndex index = m->index( obj ); + if ( index.isValid() ) + select( index, true, append ); + } +} + +/*! + \brief Set list of selected data objects. + \param lst list of the data object to set selected + \param append if \c true, the objects are added to the current selection; + otherwise the previous selection is first cleared +*/ +void LightApp_Browser::setSelected( const DataObjectList& lst, const bool append ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndexList indexes; + SUIT_DataObject* obj; + + foreach( obj, lst ) { + QModelIndex index = m->index( obj ); + if ( index.isValid() ) + indexes.append( index ); + } + select( indexes, true, append ); // if !indexes.isEmpty() ??? + } +} + /*! \brief Initialize object browser. \param root root data object diff --git a/src/LightApp/LightApp_Browser.h b/src/LightApp/LightApp_Browser.h index 0fe98b3f8..831f4ea49 100644 --- a/src/LightApp/LightApp_Browser.h +++ b/src/LightApp/LightApp_Browser.h @@ -25,8 +25,8 @@ #include "LightApp.h" #include +#include -class SUIT_DataObject; class QShortcut; class LIGHTAPP_EXPORT LightApp_Browser : public OB_Browser @@ -48,6 +48,12 @@ public: int updateKey() const; void setUpdateKey( const int ); + DataObjectList getSelected() const; + void getSelected( DataObjectList& ) const; + + void setSelected( const SUIT_DataObject*, const bool = false ); + void setSelected( const DataObjectList&, const bool = false ); + private: void init( SUIT_DataObject* ); diff --git a/src/LightApp/LightApp_OBSelector.cxx b/src/LightApp/LightApp_OBSelector.cxx index c9716877d..c29ddb91d 100644 --- a/src/LightApp/LightApp_OBSelector.cxx +++ b/src/LightApp/LightApp_OBSelector.cxx @@ -16,76 +16,115 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : LightApp_OBSelector.cxx +// Author : +// + #include "LightApp_OBSelector.h" #include "LightApp_DataOwner.h" #include "LightApp_DataObject.h" #include "LightApp_Application.h" - -// temporary commented -//#include - +#include "LightApp_Browser.h" #include #include - #include - #include /*! - Constructor + \class LightApp_OBSelector + \brief Object browser selection handler class. */ -LightApp_OBSelector::LightApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr ) - : SUIT_Selector( mgr/* temporary commented : , ob */ )/*,*/ - // temporary commented : myBrowser( ob ) + +/*! + \brief Constructor. + \param ob object browser + \param mgr selection manager +*/ +LightApp_OBSelector::LightApp_OBSelector( LightApp_Browser* ob, SUIT_SelectionMgr* mgr ) +: SUIT_Selector( mgr, ob ), + myBrowser( ob ) { - // temporary commented - /*if ( myBrowser ) { + if ( myBrowser ) { connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); - }*/ - + } setModified(); } /*! - Destructor + \brief Destructor. */ LightApp_OBSelector::~LightApp_OBSelector() { } /*! - Gets browser. + \brief Get object browser. + \return a pointer to the object browser */ -OB_Browser* LightApp_OBSelector::browser() const +LightApp_Browser* LightApp_OBSelector::browser() const { return myBrowser; } /*! - Gets selection. + \brief Get selector type. + \return selector type +*/ +QString LightApp_OBSelector::type() const +{ + return "ObjectBrowser"; +} + +/*! + \brief Get the time of the last selection changing. + \return latest selection changing time +*/ +unsigned long LightApp_OBSelector::getModifiedTime() const +{ + return myModifiedTime; +} + +/*! + \brief Update the time of the latest selection changing. +*/ +void LightApp_OBSelector::setModified() +{ + myModifiedTime = clock(); +} + +/*! + \brief Called when the Object browser selection is changed. +*/ +void LightApp_OBSelector::onSelectionChanged() +{ + QTime t1 = QTime::currentTime(); + mySelectedList.clear(); + selectionChanged(); + QTime t2 = QTime::currentTime(); + qDebug( QString( "selection time = %1 msecs" ).arg( t1.msecsTo( t2 ) ).toLatin1().constData() ); +} + +/*! + \brief Get list of currently selected objects. + \param theList list to be filled with the selected objects owners */ void LightApp_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const { - if (mySelectedList.count() == 0 ) { + 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 ) + if( !app || !myBrowser ) return; - if ( !myBrowser ) - return; DataObjectList objlist; - // temporary commented - //myBrowser->getSelected( objlist ); + myBrowser->getSelected( objlist ); LightApp_OBSelector* that = (LightApp_OBSelector*)this; QListIterator it( objlist ); - while ( it.hasNext() ) - { + while ( it.hasNext() ) { LightApp_DataObject* obj = dynamic_cast( it.next() ); - if ( obj && app->checkDataObject(obj) ) - { + if ( obj && app->checkDataObject( obj) ) { #ifndef DISABLE_SALOMEOBJECT Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject ( obj->entry().toLatin1().constData(), @@ -102,63 +141,48 @@ void LightApp_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const theList = mySelectedList; } -/*!Sets selection.*/ +/*! + \brief Set selection. + \param theList list of the object owners to be set selected +*/ void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) { if ( !myBrowser ) return; - if( myEntries.count() == 0 - // temporary commented - /*|| - myModifiedTime < myBrowser->getModifiedTime()*/ ) + if( myEntries.count() == 0 || myModifiedTime < myBrowser->getModifiedTime() ) fillEntries( myEntries ); DataObjectList objList; - for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) - { + 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()] ); } - // temporary commented - //myBrowser->setSelected( objList ); - mySelectedList.clear(); -} - -/*!On selection changed.*/ -void LightApp_OBSelector::onSelectionChanged() -{ - QTime t1 = QTime::currentTime(); + myBrowser->setSelected( objList ); mySelectedList.clear(); - selectionChanged(); - QTime t2 = QTime::currentTime(); - qDebug( QString( "selection time = %1 msecs" ).arg( t1.msecsTo( t2 ) ).toLatin1().constData() ); } -/*!Fill entries.*/ -void LightApp_OBSelector::fillEntries( QMap& entires ) +/*! + \brief Fill map of the data objects currently shown in the Object Browser. + \param entries map to be filled +*/ +void LightApp_OBSelector::fillEntries( QMap& entries ) { - entires.clear(); + entries.clear(); if ( !myBrowser ) return; - // temporary commented - /*for ( SUIT_DataObjectIterator it( myBrowser->getRootObject(), - SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) - { + for ( SUIT_DataObjectIterator it( myBrowser->root(), + SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) { LightApp_DataObject* obj = dynamic_cast( it.current() ); if ( obj ) - entires.insert( obj->entry(), obj ); - }*/ + entries.insert( obj->entry(), obj ); + } setModified(); } -/*!Update modified time.*/ -void LightApp_OBSelector::setModified() -{ - myModifiedTime = clock(); -} diff --git a/src/LightApp/LightApp_OBSelector.h b/src/LightApp/LightApp_OBSelector.h index 9645e951b..758cc3e58 100644 --- a/src/LightApp/LightApp_OBSelector.h +++ b/src/LightApp/LightApp_OBSelector.h @@ -16,6 +16,10 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : LightApp_OBSelector.h +// Author : +// + #ifndef LIGHTAPP_OBSELECTOR_H #define LIGHTAPP_OBSELECTOR_H @@ -26,46 +30,39 @@ #include -class OB_Browser; +class LightApp_Browser; class LightApp_DataObject; -/*! - \class LightApp_OBSelector - Custom selector to get/set selection from object browser -*/ class LIGHTAPP_EXPORT LightApp_OBSelector : public QObject, public SUIT_Selector { Q_OBJECT public: - LightApp_OBSelector( OB_Browser*, SUIT_SelectionMgr* ); + LightApp_OBSelector( LightApp_Browser*, SUIT_SelectionMgr* ); virtual ~LightApp_OBSelector(); - OB_Browser* browser() const; + LightApp_Browser* browser() const; - /*!Return "ObjectBrowser"*/ - virtual QString type() const { return "ObjectBrowser"; } + virtual QString type() const; - void setModified(); - unsigned long getModifiedTime() { return myModifiedTime; } + unsigned long getModifiedTime() const; + void setModified(); private slots: - void onSelectionChanged(); + void onSelectionChanged(); protected: - virtual void getSelection( SUIT_DataOwnerPtrList& ) const; - virtual void setSelection( const SUIT_DataOwnerPtrList& ); + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); private: - void fillEntries( QMap& ); + void fillEntries( QMap& ); private: - OB_Browser* myBrowser; - SUIT_DataOwnerPtrList mySelectedList; - + LightApp_Browser* myBrowser; + SUIT_DataOwnerPtrList mySelectedList; QMap myEntries; - - unsigned long myModifiedTime; + unsigned long myModifiedTime; }; #endif