ob->setAutoUpdate( true );
//ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
ob->setWindowTitle( tr( "OBJECT_BROWSER" ) );
+ connect( ob, SIGNAL( requestUpdate() ), this, SLOT( onRefresh() ) );
// temporary commented
/*
//
#include "LightApp_Browser.h"
+
#include <SUIT_DataObject.h>
#include <SUIT_TreeModel.h>
#include <QtxTreeView.h>
+#include <QShortcut>
+
/*!
\class LightApp_Browser
\brief Object browser customization.
LightApp_Browser::LightApp_Browser( QWidget* parent )
: OB_Browser( parent )
{
- setModel( new SUIT_ProxyModel( this ) );
+ init( 0 );
}
/*!
LightApp_Browser::LightApp_Browser( SUIT_DataObject* root, QWidget* parent )
: OB_Browser( parent )
{
- setModel( new SUIT_ProxyModel( root, this ) );
- connect( treeView(), SIGNAL( sortingEnabled(bool ) ),
- model(), SLOT( setSortingEnabled( bool ) ) );
+ init( root );
}
/*!
openLevels();
}
}
+
+/*!
+ \brief Get current key accelerator used for the
+ object browser update operation.
+ \return current key accelerator
+ \sa setUpdateKey(), requestUpdate()
+*/
+int LightApp_Browser::updateKey() const
+{
+ return myShortcut->key();
+}
+
+/*!
+ \brief Assign the key accelerator to be used for the
+ object browser update operation.
+
+ By default, \c [F5] key is assigned for the update operation.
+ To disable the accelerator, pass 0 to this method.
+
+ \param key new key accelerator
+ \sa updateKey(), requestUpdate()
+*/
+void LightApp_Browser::setUpdateKey( const int key )
+{
+ myShortcut->setKey( key );
+}
+
+/*!
+ \brief Initialize object browser.
+ \param root root data object
+*/
+void LightApp_Browser::init( SUIT_DataObject* root )
+{
+ setModel( new SUIT_ProxyModel( root, this ) );
+ setItemDelegate( qobject_cast<SUIT_ProxyModel*>( model() )->delegate() );
+ connect( treeView(), SIGNAL( sortingEnabled(bool ) ),
+ model(), SLOT( setSortingEnabled( bool ) ) );
+ myShortcut = new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) );
+}
+
+/*!
+ \fn void LightApp_Browser::requestUpdate();
+ \brief The signal is emitted when the key accelerator
+ assigned for the update operation is pressed by the user.
+
+ By default, \c [F5] key is assigned for the update operation.
+ The key accelerator can be changed with the setUpdateKey() method.
+
+ \sa updateKey(), setUpdateKey()
+*/
#include <OB_Browser.h>
class SUIT_DataObject;
+class QShortcut;
class LIGHTAPP_EXPORT LightApp_Browser : public OB_Browser
{
void updateTree( SUIT_DataObject* = 0, const bool = true );
+ int updateKey() const;
+ void setUpdateKey( const int );
+
+private:
+ void init( SUIT_DataObject* );
+
+signals:
+ void requestUpdate();
+
+private:
+ QShortcut* myShortcut;
};
#endif // LIGHTAPP_BROWSER_H
//#include <SUIT_DataObjectIterator.h>
#include <QAction>
+#include <QMenu>
#include <QItemSelection>
-#include <QLinkedList>
#include <QKeyEvent>
#include <QVBoxLayout>
+#include <QAbstractItemModel>
+#include <QAbstractItemDelegate>
#include <time.h>
setModified();
}
+/*!
+ \brief Get current item delegate.
+ \return currently used item delegate
+ \sa setItemDelegate()
+*/
+QAbstractItemDelegate* OB_Browser::itemDelegate() const
+{
+ return treeView() ? treeView()->itemDelegate() : 0;
+}
+
+/*!
+ \brief Set item delegate.
+ \param d custom item delegate
+ \sa itemDelegate()
+*/
+void OB_Browser::setItemDelegate( QAbstractItemDelegate* d )
+{
+ if ( treeView() )
+ treeView()->setItemDelegate( d );
+}
+
+
/*!
\brief Check if controls for expanding and collapsing top-level items are shown.
\return \c true if top-level items are decorated
{
return myShowToolTips;
}
-
+*/
/*!
Sets new value of state "are tooltips shown"
\param theDisplay - new value
i = i->nextSibling();
}
}
-
+*/
/*!
Connects all children to SLOT onDestroyed
*/
return DataObjectKey( obj->key() );
}
*/
+
/*!
- Custom key press event handler, updates tree by F5
+ \brief Process context menu request event.
+ \param e context menu event
*/
-void OB_Browser::keyPressEvent( QKeyEvent* e )
+void OB_Browser::contextMenuEvent( QContextMenuEvent* e )
{
- if ( e->key() == Qt::Key_F5 )
- //updateTree( 0, false );
- update();
-
- QWidget::keyPressEvent( e );
+ contextMenuRequest( e );
}
/*!
- SLOT: called if action "Expand all" is activated
+ \brief Called when "Expand all" popup menu command is activated.
+
+ Expands all selected items recursively.
*/
-/* TODO: to be revised
void OB_Browser::onExpand()
{
- DataObjectList selected;
- getSelected( selected );
- for ( DataObjectListIterator itr( selected ); itr.current(); ++itr )
- expand( listViewItem( itr.current() ) );
+ QModelIndexList indexes = treeView()->selectionModel()->selectedIndexes();
+ QModelIndex index;
+
+ foreach ( index, indexes ) {
+ treeView()->expandAll( index );
+ }
}
-*/
+
/*!
SLOT: called if action "Show/hide column" is activated by popup
*/
item->setText( it.data(), obj->text( it.key() ) );
}
*/
-/*!
- Custom event filter
-*/
-/*
-bool OB_Browser::eventFilter( QObject* o, QEvent* e )
-{
- if ( o == myView && e->type() == QEvent::ContextMenu )
- {
- QContextMenuEvent* ce = (QContextMenuEvent*)e;
- if ( ce->reason() != QContextMenuEvent::Mouse )
- contextMenuRequest( ce );
- return true;
- }
- if ( o == myView->viewport() && e->type() == QEvent::MouseButtonRelease )
- {
- QMouseEvent* me = (QMouseEvent*)e;
- if ( me->button() == RightButton )
- {
- QContextMenuEvent ce( QContextMenuEvent::Mouse, me->pos(), me->globalPos(), me->state() );
- contextMenuRequest( &ce );
- return true;
- }
- }
-
- return QWidget::eventFilter( o, e );
-}
-*/
/*!
Adds custom actions to popup
\param menu - popup menu
*/
void OB_Browser::contextMenuPopup( QMenu* menu )
{
-/* QValueList<int> cols;
- for ( QMap<int, int>::ConstIterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it )
- {
- if ( appropriateColumn( it.key() ) )
- cols.append( it.key() );
- }
-
- uint num = menu->count();
- menu->setCheckable( true );
- for ( QValueList<int>::const_iterator iter = cols.begin(); iter != cols.end(); ++iter )
- {
- QString name = columnTitle( *iter );
- if ( name.isEmpty() )
- continue;
-
- int id = menu->insertItem( name, this, SLOT( onColumnVisible( int ) ) );
- menu->setItemChecked( id, isColumnVisible( *iter ) );
- menu->setItemParameter( id, *iter );
- }
- if ( menu->count() != num )
- menu->insertSeparator();
+ menu->addSeparator();
- DataObjectList selected;
- getSelected( selected );
+ QModelIndexList indexes = treeView()->selectionModel()->selectedIndexes();
bool closed = false;
- for ( DataObjectListIterator itr( selected ); itr.current() && !closed; ++itr )
- closed = hasClosed( listViewItem( itr.current() ) );
+
+ for ( QModelIndexList::Iterator it = indexes.begin();
+ it != indexes.end() && !closed; ++it ) {
+ closed = hasCollased( *it );
+ }
if ( closed )
- {
- menu->insertItem( tr( "MEN_EXPAND_ALL" ), this, SLOT( onExpand() ) );
- menu->insertSeparator();
- }
-*/
+ menu->addAction( tr( "MEN_EXPAND_ALL" ), this, SLOT( onExpand() ) );
+
+ menu->addSeparator();
}
/*!
/*!
\return true if item or one of it's children isn't opened
*/
-/* TODO: to be revised
-bool OB_Browser::hasClosed( QListViewItem* item ) const
+bool OB_Browser::hasCollased( const QModelIndex& index ) const
{
- if ( !item )
- return false;
-
- if ( item->childCount() && !item->isOpen() )
- return true;
-
- bool has = false;
- for ( QListViewItem* child = item->firstChild(); child && !has; child = child->nextSibling() )
- has = hasClosed( child );
+ bool result = false;
- return has;
+ if ( index.isValid() ) {
+ bool hasChildren = treeView()->model()->hasChildren( index );
+ result = hasChildren && !treeView()->isExpanded( index );
+ if ( !result && hasChildren ) {
+ int rows = treeView()->model()->rowCount( index );
+ for ( int i = 0; i < rows && !result; i ++ ) {
+ QModelIndex child = treeView()->model()->index( i, 0, index );
+ result = hasCollased( child );
+ }
+ }
+ }
+ return result;
}
-*/
/*!
Removes SUIT object
\param obj - SUIT object to be removed
#endif
class QAbstractItemModel;
+class QAbstractItemDelegate;
class QToolTip;
class QtxTreeView;
OB_Browser( QWidget* = 0, QAbstractItemModel* = 0 );
virtual ~OB_Browser();
- QtxTreeView* treeView() const;
+ QtxTreeView* treeView() const;
- virtual QString popupClientType() const;
+ virtual QString popupClientType() const;
- QAbstractItemModel* model() const;
- void setModel( QAbstractItemModel* );
+ QAbstractItemModel* model() const;
+ void setModel( QAbstractItemModel* );
- bool rootIsDecorated() const;
- void setRootIsDecorated( const bool );
+ QAbstractItemDelegate* itemDelegate() const;
+ void setItemDelegate( QAbstractItemDelegate* );
- int autoOpenLevel() const;
- void setAutoOpenLevel( const int );
- void openLevels( const int = -1 );
+ bool rootIsDecorated() const;
+ void setRootIsDecorated( const bool );
+
+ int autoOpenLevel() const;
+ void setAutoOpenLevel( const int );
+ void openLevels( const int = -1 );
//bool isShowToolTips();
//void setShowToolTips( const bool theDisplay );
- int numberOfSelected() const;
- QModelIndexList getSelected() const;
- const QItemSelection selection() const;
+ int numberOfSelected() const;
+ QModelIndexList getSelected() const;
+ const QItemSelection selection() const;
- virtual void setSelected( const QModelIndex&, const bool = false );
- virtual void setSelected( const QModelIndexList&, const bool = false );
+ virtual void setSelected( const QModelIndex&, const bool = false );
+ virtual void setSelected( const QModelIndexList&, const bool = false );
- bool isOpen( const QModelIndex& ) const;
- virtual void setOpen( const QModelIndex& theObject, const bool theOpen = true );
+ bool isOpen( const QModelIndex& ) const;
+ virtual void setOpen( const QModelIndex& theObject, const bool theOpen = true );
- void adjustWidth();
+ void adjustWidth();
// san - To be revised or removed
// QTreeView::indexAt() should be used
//bool appropriateColumn( const int ) const;
//virtual void setAppropriateColumn( const int, const bool );
- //virtual bool eventFilter(QObject* watched, QEvent* e);
-
- virtual void contextMenuPopup( QMenu* );
+ virtual void contextMenuPopup( QMenu* );
- void setModified();
- unsigned long getModifiedTime() { return myModifiedTime; }
+ void setModified();
+ unsigned long getModifiedTime() { return myModifiedTime; }
// san - moved to SUIT_TreeModel
//OB_Updater* getUpdater() const;
//virtual void setUpdater( OB_Updater* theUpdate = 0 );
signals:
- void selectionChanged();
- void doubleClicked( SUIT_DataObject* );
- void dropped( DataObjectList, SUIT_DataObject*, int );
+ void selectionChanged();
+ void doubleClicked( SUIT_DataObject* );
+ void dropped( DataObjectList, SUIT_DataObject*, int );
private slots:
- //void onExpand();
+ void onExpand();
//void onColumnVisible( int );
//void onDestroyed( SUIT_DataObject* );
//void onDoubleClicked ( QListViewItem* );
//virtual void updateView( SUIT_DataObject* = 0 );
//virtual void updateText();
- virtual void keyPressEvent( QKeyEvent* );
+ virtual void contextMenuEvent( QContextMenuEvent* );
private:
//typedef QMap<SUIT_DataObject*, QListViewItem*> ItemMap;
//typedef QMap<DataObjectKey, int> DataObjectKeyMap;
private:
- //void expand( QListViewItem* );
- //bool hasClosed( QListViewItem* ) const;
+ bool hasCollased( const QModelIndex& ) const;
//void autoOpenBranches();
//void openBranch( QListViewItem*, const int );
// const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& );
private:
- QtxTreeView* myView;
+ QtxTreeView* myView;
// TODO: decide what to do with tooltip
//QToolTip* myTooltip;
//QMap<int, int> myColumnIds;
// TODO: decide what to do with tooltip
//bool myShowToolTips;
- int myAutoOpenLevel;
- unsigned long myModifiedTime;
+ int myAutoOpenLevel;
+ unsigned long myModifiedTime;
// TODO: decide what to do with tooltip
//friend class OB_Browser::ToolTip;