Navigation Menu

Skip to content

Commit

Permalink
Add context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Apr 24, 2023
1 parent b44d991 commit 48bc3c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/gui/qgsprojectionselectiontreewidget.cpp
Expand Up @@ -28,6 +28,8 @@
#include "qgsunittypes.h"

//qt includes
#include <QAction>
#include <QMenu>
#include <QFileInfo>
#include <QHeaderView>
#include <QResizeEvent>
Expand Down Expand Up @@ -74,6 +76,28 @@ QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *par
lstRecent->header()->setStretchLastSection( false );
lstRecent->header()->resizeSection( ClearColumn, 20 );

// Clear recent crs context menu
lstRecent->setContextMenuPolicy( Qt::CustomContextMenu );
connect( lstRecent, &QTreeWidget::customContextMenuRequested, this, [this]( const QPoint & pos )
{
// If list is empty, do nothing
if ( lstRecent->topLevelItemCount() == 0 )
return;
QMenu menu;
// Clear selected
QTreeWidgetItem *currentItem = lstRecent->itemAt( pos );
if ( currentItem )
{
QAction *clearSelected = menu.addAction( QgsApplication::getThemeIcon( "/mIconClearItem.svg" ), tr( "Clear selected CRS from recently used CRS" ) );
connect( clearSelected, &QAction::triggered, this, [this, currentItem ] { removeRecentCrsItem( currentItem ); } );
menu.addSeparator();
}
// Clear all
QAction *clearAll = menu.addAction( QgsApplication::getThemeIcon( "/console/iconClearConsole.svg" ), tr( "Clear all recently used CRS" ) );
connect( clearAll, &QAction::triggered, this, &QgsProjectionSelectionTreeWidget::clearRecentCrs );
menu.exec( lstRecent->viewport()->mapToGlobal( pos ) );
} );

mRecentProjections = QgsCoordinateReferenceSystem::recentCoordinateReferenceSystems();

mCheckBoxNoProjection->setHidden( true );
Expand Down Expand Up @@ -266,7 +290,7 @@ void QgsProjectionSelectionTreeWidget::insertRecent( const QgsCoordinateReferenc
QToolButton *clearButton = new QToolButton();
clearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClearItem.svg" ) );
clearButton->setAutoRaise( true );
clearButton->setToolTip( tr( "Clear from recently used coordinate reference systems" ) );
clearButton->setToolTip( tr( "Clear from recently used CRS" ) );
connect( clearButton, &QToolButton::clicked, this, [this, item] { removeRecentCrsItem( item ); } );
lstRecent->setItemWidget( item, ClearColumn, clearButton );

Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgsprojectionselectorbase.ui
Expand Up @@ -99,7 +99,7 @@
<item>
<widget class="QToolButton" name="mClearRecentCrs">
<property name="toolTip">
<string>Clear all recently used coordinate reference systems</string>
<string>Clear all recently used CRS</string>
</property>
<property name="text">
<string>Clear</string>
Expand Down

0 comments on commit 48bc3c1

Please sign in to comment.