From: nds Date: Mon, 10 Dec 2007 10:43:07 +0000 (+0000) Subject: New method appends header menu acions. X-Git-Tag: TG_Saint_Valentine-Day~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cfec17d2dcdf37abe31b09008175e4a401c7fe4e;p=modules%2Fgui.git New method appends header menu acions. --- diff --git a/src/Qtx/QtxTreeView.cxx b/src/Qtx/QtxTreeView.cxx index 09100e5a7..001ebd6d3 100644 --- a/src/Qtx/QtxTreeView.cxx +++ b/src/Qtx/QtxTreeView.cxx @@ -41,11 +41,15 @@ public: void setSortMenuEnabled( const bool ); bool sortMenuEnabled() const; + void addMenuAction( QAction* ); + protected: void contextMenuEvent( QContextMenuEvent* ); private: - bool myEnableSortMenu; + typedef QMap ActionsMap; + bool myEnableSortMenu; + ActionsMap myActions; }; /*! @@ -88,6 +92,21 @@ bool QtxTreeView::Header::sortMenuEnabled() const return myEnableSortMenu; } +/* + \brief Appends action to header popup menu. + \param action the action + \internal +*/ +void QtxTreeView::Header::addMenuAction( QAction* action ) +{ + bool aFind = false; + ActionsMap::const_iterator anIt = myActions.begin(), aLast = myActions.end(); + for ( ; anIt != aLast && !aFind; anIt++ ) + aFind = anIt.value() == action; + if ( !aFind ) + myActions[myActions.size()] = action; +} + /*! \brief Customize context menu event. \internal @@ -127,6 +146,12 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) sortAction->setCheckable( true ); sortAction->setChecked( isSortIndicatorShown() ); } + if ( myActions.size() > 0 ) { + menu.addSeparator(); + ActionsMap::const_iterator anIt = myActions.begin(), aLast = myActions.end(); + for ( ; anIt != aLast; anIt++ ) + menu.addAction( anIt.value() ); + } if ( !menu.isEmpty() ) { Qtx::simplifySeparators( &menu ); QAction* a = menu.exec( e->globalPos() ); @@ -271,6 +296,17 @@ bool QtxTreeView::sortMenuEnabled() const return h ? h->sortMenuEnabled() : false; } +/* + \brief Appends header menu action. + \param action the action +*/ +void QtxTreeView::addHeaderMenuAction( QAction* action ) +{ + Header* h = dynamic_cast( header() ); + if ( h ) + h->addMenuAction( action ); +} + /* \brief Called when the header section is clicked. \param column header column index diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h index 4d5935f8d..b11a31c40 100644 --- a/src/Qtx/QtxTreeView.h +++ b/src/Qtx/QtxTreeView.h @@ -51,6 +51,8 @@ public: void setSortMenuEnabled( const bool ); bool sortMenuEnabled() const; + void addHeaderMenuAction( QAction* ); + protected slots: void onHeaderClicked( int ); void selectionChanged( const QItemSelection&, const QItemSelection& );