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<SUIT_ProxyModel*>( 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<SUIT_ProxyModel*>( 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<SUIT_ProxyModel*>( 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
//
// 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 <OB_Browser.h>
-
+#include "LightApp_Browser.h"
#include <SUIT_Session.h>
#include <SUIT_DataObjectIterator.h>
-
#include <QTime>
-
#include <time.h>
/*!
- 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<LightApp_Application*>( 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<SUIT_DataObject*> it( objlist );
- while ( it.hasNext() )
- {
+ while ( it.hasNext() ) {
LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( 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(),
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<const LightApp_DataOwner*>( (*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<QString, LightApp_DataObject*>& 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<QString, LightApp_DataObject*>& 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<LightApp_DataObject*>( it.current() );
if ( obj )
- entires.insert( obj->entry(), obj );
- }*/
+ entries.insert( obj->entry(), obj );
+ }
setModified();
}
-/*!Update modified time.*/
-void LightApp_OBSelector::setModified()
-{
- myModifiedTime = clock();
-}
//
// 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
#include <QObject>
-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<QString, LightApp_DataObject*>& );
+ void fillEntries( QMap<QString, LightApp_DataObject*>& );
private:
- OB_Browser* myBrowser;
- SUIT_DataOwnerPtrList mySelectedList;
-
+ LightApp_Browser* myBrowser;
+ SUIT_DataOwnerPtrList mySelectedList;
QMap<QString, LightApp_DataObject*> myEntries;
-
- unsigned long myModifiedTime;
+ unsigned long myModifiedTime;
};
#endif