From cfec17d2dcdf37abe31b09008175e4a401c7fe4e Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 10 Dec 2007 10:43:07 +0000 Subject: [PATCH] New method appends header menu acions. --- src/Qtx/QtxTreeView.cxx | 38 +++++++++++++++++++++++++++++++++++++- src/Qtx/QtxTreeView.h | 2 ++ 2 files changed, 39 insertions(+), 1 deletion(-) 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& ); -- 2.39.2