Skip to content

Commit

Permalink
Remove CRS on del key pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Apr 24, 2023
1 parent e5e65ec commit 3852bd4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Expand Up @@ -198,6 +198,9 @@ Emitted when the selection in the tree is changed from a valid selection to an i
virtual void resizeEvent( QResizeEvent *event );


virtual bool eventFilter( QObject *obj, QEvent *ev );


};

/************************************************************************
Expand Down
22 changes: 22 additions & 0 deletions src/gui/qgsprojectionselectiontreewidget.cpp
Expand Up @@ -98,6 +98,9 @@ QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *par
menu.exec( lstRecent->viewport()->mapToGlobal( pos ) );
} );

// Install event fiter to catch delete key press on the recent crs list
lstRecent->installEventFilter( this );

mRecentProjections = QgsCoordinateReferenceSystem::recentCoordinateReferenceSystems();

mCheckBoxNoProjection->setHidden( true );
Expand Down Expand Up @@ -174,6 +177,25 @@ void QgsProjectionSelectionTreeWidget::showEvent( QShowEvent *event )
mInitialized = true;
}


bool QgsProjectionSelectionTreeWidget::eventFilter( QObject *obj, QEvent *ev )
{
if ( obj != lstRecent )
return false;

if ( ev->type() != QEvent::KeyPress )
return false;

QKeyEvent *keyEvent = static_cast<QKeyEvent *>( ev );
if ( keyEvent->matches( QKeySequence::Delete ) )
{
removeRecentCrsItem( lstRecent->currentItem() );
return true;
}

return false;
}

QString QgsProjectionSelectionTreeWidget::ogcWmsCrsFilterAsSqlExpression( QSet<QString> *crsFilter )
{
QString sqlExpression = QStringLiteral( "1" ); // it's "SQL" for "true"
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsprojectionselectiontreewidget.h
Expand Up @@ -186,6 +186,9 @@ class GUI_EXPORT QgsProjectionSelectionTreeWidget : public QWidget, private Ui::
// Used to manage column sizes
void resizeEvent( QResizeEvent *event ) override;

// Used to catch key presses on the recent projections list
bool eventFilter( QObject *obj, QEvent *ev ) override;

private:

/**
Expand Down

0 comments on commit 3852bd4

Please sign in to comment.