From: vsr Date: Tue, 31 Jul 2007 14:50:24 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: qt4_porting_delivery_220807~62 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b989766476a7619e4bb6f275c7e423dcbb410334;p=modules%2Fgui.git *** empty log message *** --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index b8b50f211..631d87b2d 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1621,6 +1621,7 @@ QWidget* LightApp_Application::createWindow( const int flag ) 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 /* diff --git a/src/LightApp/LightApp_Browser.cxx b/src/LightApp/LightApp_Browser.cxx index 3617f3182..5cd4124c3 100644 --- a/src/LightApp/LightApp_Browser.cxx +++ b/src/LightApp/LightApp_Browser.cxx @@ -21,10 +21,13 @@ // #include "LightApp_Browser.h" + #include #include #include +#include + /*! \class LightApp_Browser \brief Object browser customization. @@ -37,7 +40,7 @@ LightApp_Browser::LightApp_Browser( QWidget* parent ) : OB_Browser( parent ) { - setModel( new SUIT_ProxyModel( this ) ); + init( 0 ); } /*! @@ -48,9 +51,7 @@ LightApp_Browser::LightApp_Browser( QWidget* parent ) 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 ); } /*! @@ -115,3 +116,53 @@ void LightApp_Browser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) 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( 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() +*/ diff --git a/src/LightApp/LightApp_Browser.h b/src/LightApp/LightApp_Browser.h index 3378fd4ac..0fe98b3f8 100644 --- a/src/LightApp/LightApp_Browser.h +++ b/src/LightApp/LightApp_Browser.h @@ -27,6 +27,7 @@ #include class SUIT_DataObject; +class QShortcut; class LIGHTAPP_EXPORT LightApp_Browser : public OB_Browser { @@ -44,6 +45,17 @@ public: 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 diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 7db5a893b..c93eb0b1a 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -30,10 +30,12 @@ //#include #include +#include #include -#include #include #include +#include +#include #include @@ -203,6 +205,28 @@ void OB_Browser::setModel( QAbstractItemModel* model ) 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 @@ -268,7 +292,7 @@ bool OB_Browser::isShowToolTips() { return myShowToolTips; } - +*/ /*! Sets new value of state "are tooltips shown" \param theDisplay - new value @@ -893,7 +917,7 @@ void OB_Browser::removeReferences( QListViewItem* item ) i = i->nextSibling(); } } - +*/ /*! Connects all children to SLOT onDestroyed */ @@ -1054,30 +1078,31 @@ OB_Browser::DataObjectKey OB_Browser::objectKey( SUIT_DataObject* obj ) const 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 */ @@ -1179,74 +1204,27 @@ void OB_Browser::updateText( QListViewItem* item ) 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 cols; - for ( QMap::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::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(); } /*! @@ -1266,22 +1244,23 @@ void OB_Browser::expand( QListViewItem* item ) /*! \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 diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 4c330bbd5..885a2fd9f 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -39,6 +39,7 @@ #endif class QAbstractItemModel; +class QAbstractItemDelegate; class QToolTip; class QtxTreeView; @@ -53,34 +54,37 @@ public: 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 @@ -116,24 +120,22 @@ public: //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* ); @@ -144,7 +146,7 @@ protected: //virtual void updateView( SUIT_DataObject* = 0 ); //virtual void updateText(); - virtual void keyPressEvent( QKeyEvent* ); + virtual void contextMenuEvent( QContextMenuEvent* ); private: //typedef QMap ItemMap; @@ -153,8 +155,7 @@ private: //typedef QMap DataObjectKeyMap; private: - //void expand( QListViewItem* ); - //bool hasClosed( QListViewItem* ) const; + bool hasCollased( const QModelIndex& ) const; //void autoOpenBranches(); //void openBranch( QListViewItem*, const int ); @@ -179,14 +180,14 @@ private: // const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& ); private: - QtxTreeView* myView; + QtxTreeView* myView; // TODO: decide what to do with tooltip //QToolTip* myTooltip; //QMap 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;