From 72579ed9e40e44dc8386e11bfc8cb020fa0c4f72 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 17 Apr 2008 08:15:49 +0000 Subject: [PATCH] Improve data browser: support double click action for the data object --- src/SUIT/SUIT_DataBrowser.cxx | 74 +++++++++++++++++++++++------------ src/SUIT/SUIT_DataBrowser.h | 2 + 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index 08376398f..4828d6e97 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -245,6 +245,34 @@ void SUIT_DataBrowser::contextMenuPopup( QMenu* menu ) createPopupMenu( menu ); } +/*! + \brief Set 'auto-size first column' flag value. + + If this flag is set to \c true (by default), the first column width is resized + to its contents. + + \param on 'auto-size first column' flag value + \sa setAutoSizeColumns() +*/ +void SUIT_DataBrowser::setAutoSizeFirstColumn( const bool on ) +{ + myAutoSizeFirstColumn = on; +} + +/*! + \brief Set 'auto-size columns' flag value. + + If this flag is set to \c true (by default is false), columns width except + the first column is resized to its contents. + + \param on 'auto-size columns' flag value + \sa setAutoSizeFirstColumn() +*/ +void SUIT_DataBrowser::setAutoSizeColumns( const bool on ) +{ + myAutoSizeColumns = on; +} + /*! \brief Process context menu request event. \param e context menu event @@ -265,8 +293,10 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) setModel( m ); setItemDelegate( qobject_cast( model() )->delegate() ); - connect( treeView(), SIGNAL( sortingEnabled(bool ) ), - model(), SLOT( setSortingEnabled( bool ) ) ); + connect( treeView(), SIGNAL( sortingEnabled( bool ) ), + model(), SLOT( setSortingEnabled( bool ) ) ); + connect( treeView(), SIGNAL( doubleClicked( const QModelIndex& ) ), + this, SLOT( onDblClicked( const QModelIndex& ) ) ); myShortcut = new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) ); myAutoSizeFirstColumn = true; @@ -284,7 +314,15 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) \sa updateKey(), setUpdateKey() */ +/*! + \fn void SUIT_DataBrowser::doubleClicked( SUIT_DataObject* o ); + \brief This signal is emitted when a mouse button is double-clicked. + The data object the mouse was double-clicked on is specified by \a o. + The signal is only emitted when the object is valid. + + \param o data object which is double-clicked +*/ /*! \brief Update internal modification time just after data model update @@ -295,29 +333,17 @@ void SUIT_DataBrowser::onModelUpdated() } /*! - \brief Set 'auto-size first column' flag value. - - If this flag is set to \c true (by default), the first column width is resized - to its contents. - - \param on 'auto-size first column' flag value - \sa setAutoSizeColumns() + \brief Called when item is double-clicked in the tree view + \internal + + Emits signal doubleClicked( SUIT_DataObject* ); */ -void SUIT_DataBrowser::setAutoSizeFirstColumn( const bool on ) +void SUIT_DataBrowser::onDblClicked( const QModelIndex& index ) { - myAutoSizeFirstColumn = on; -} - -/*! - \brief Set 'auto-size columns' flag value. - - If this flag is set to \c true (by default is false), columns width except - the first column is resized to its contents. + SUIT_ProxyModel* m = qobject_cast( model() ); - \param on 'auto-size columns' flag value - \sa setAutoSizeFirstColumn() -*/ -void SUIT_DataBrowser::setAutoSizeColumns( const bool on ) -{ - myAutoSizeColumns = on; + if ( m ) { + SUIT_DataObject* obj = m->object( index ); + if ( obj ) emit( doubleClicked( obj ) ); + } } diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index f75b5a425..b1bc41f43 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -71,9 +71,11 @@ private: signals: void requestUpdate(); + void doubleClicked( SUIT_DataObject* ); private slots: void onModelUpdated(); + void onDblClicked( const QModelIndex& ); private: QShortcut* myShortcut; -- 2.39.2