Skip to content

Commit

Permalink
Show helpful status bar tooltip informing of the current select tool …
Browse files Browse the repository at this point in the history
…behavior

whenever ctrl/shift/alt modifiers are changed during a selection operation
  • Loading branch information
nyalldawson committed Dec 6, 2019
1 parent 6cd5ade commit 7478e79
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -4023,15 +4023,19 @@ void QgisApp::createCanvasTools()
mMapTools.mSelectFeatures = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectFeatures->setAction( mActionSelectFeatures );
mMapTools.mSelectFeatures->setSelectionMode( QgsMapToolSelectionHandler::SelectSimple );
connect( mMapTools.mSelectFeatures, &QgsMapToolSelect::modeChanged, this, &QgisApp::selectionModeChanged );
mMapTools.mSelectPolygon = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectPolygon->setAction( mActionSelectPolygon );
mMapTools.mSelectPolygon->setSelectionMode( QgsMapToolSelectionHandler::SelectPolygon );
connect( mMapTools.mSelectPolygon, &QgsMapToolSelect::modeChanged, this, &QgisApp::selectionModeChanged );
mMapTools.mSelectFreehand = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectFreehand->setAction( mActionSelectFreehand );
mMapTools.mSelectFreehand->setSelectionMode( QgsMapToolSelectionHandler::SelectFreehand );
connect( mMapTools.mSelectFreehand, &QgsMapToolSelect::modeChanged, this, &QgisApp::selectionModeChanged );
mMapTools.mSelectRadius = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectRadius->setAction( mActionSelectRadius );
mMapTools.mSelectRadius->setSelectionMode( QgsMapToolSelectionHandler::SelectRadius );
connect( mMapTools.mSelectRadius, &QgsMapToolSelect::modeChanged, this, &QgisApp::selectionModeChanged );
mMapTools.mAddRing = new QgsMapToolAddRing( mMapCanvas );
mMapTools.mAddRing->setAction( mActionAddRing );
mMapTools.mFillRing = new QgsMapToolFillRing( mMapCanvas );
Expand Down Expand Up @@ -12809,6 +12813,43 @@ void QgisApp::showPanMessage( double distance, QgsUnitTypes::DistanceUnit unit,
QgsCoordinateFormatter::formatX( bearing, QgsCoordinateFormatter::FormatDecimalDegrees, 1, QgsCoordinateFormatter::FlagDegreesUseStringSuffix ) ), 2000 );
}

void QgisApp::selectionModeChanged( QgsMapToolSelect::Mode mode )
{
switch ( mode )
{
case QgsMapToolSelect::GeometryIntersectsSetSelection:
mStatusBar->showMessage( QString() );
break;
case QgsMapToolSelect::GeometryIntersectsAddToSelection:
mStatusBar->showMessage( tr( "Add to the current selection" ) );
break;

case QgsMapToolSelect::GeometryIntersectsSubtractFromSelection:
mStatusBar->showMessage( tr( "Subtract from the current selection" ) );
break;

case QgsMapToolSelect::GeometryIntersectsIntersectWithSelection:
mStatusBar->showMessage( tr( "Intersect with the current selection" ) );
break;

case QgsMapToolSelect::GeometryWithinSetSelection:
mStatusBar->showMessage( tr( "Select features completely within" ) );
break;

case QgsMapToolSelect::GeometryWithinAddToSelection:
mStatusBar->showMessage( tr( "Add features completely within to the current selection" ) );
break;

case QgsMapToolSelect::GeometryWithinSubtractFromSelection:
mStatusBar->showMessage( tr( "Subtract features completely within from the current selection" ) );
break;

case QgsMapToolSelect::GeometryWithinIntersectWithSelection:
mStatusBar->showMessage( tr( "Intersect features completely within with the current selection" ) );
break;

}
}

void QgisApp::updateMouseCoordinatePrecision()
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -158,6 +158,7 @@ class QgsNetworkRequestParameters;
#include "qgsoptionswidgetfactory.h"
#include "qgsattributetablefiltermodel.h"
#include "qgsmasterlayoutinterface.h"
#include "qgsmaptoolselect.h"
#include "ogr/qgsvectorlayersaveasdialog.h"
#include "ui_qgisapp.h"
#include "qgis_app.h"
Expand Down Expand Up @@ -1530,6 +1531,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void showPanMessage( double distance, QgsUnitTypes::DistanceUnit unit, double bearing );

void selectionModeChanged( QgsMapToolSelect::Mode mode );

void displayMapToolMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );
void displayMessage( const QString &title, const QString &message, Qgis::MessageLevel level );
void removeMapToolMessage();
Expand Down
65 changes: 65 additions & 0 deletions src/app/qgsmaptoolselect.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgspointxy.h"
#include "qgis.h"
#include "qgsapplication.h"
#include "qgslogger.h"

#include <QMouseEvent>
#include <QRect>
Expand Down Expand Up @@ -63,11 +64,55 @@ void QgsMapToolSelect::canvasReleaseEvent( QgsMapMouseEvent *e )
mSelectionHandler->canvasReleaseEvent( e );
}

void QgsMapToolSelect::keyPressEvent( QKeyEvent *e )
{
if ( !e->isAutoRepeat() )
{
switch ( e->key() )
{
case Qt::Key_Shift:
case Qt::Key_Control:
case Qt::Key_Alt:
case Qt::Key_Meta:
//note -- if ctrl and shift are already depressed, pressing alt reports the "meta" key eventZ
modifiersChanged( e->modifiers() & Qt::ControlModifier || e->key() == Qt::Key_Control,
e->modifiers() & Qt::ShiftModifier || e->key() == Qt::Key_Shift,
e->modifiers() & Qt::AltModifier || e->key() == Qt::Key_Alt ||
( e->modifiers() & Qt::ControlModifier && e->modifiers() & Qt::ShiftModifier && e->key() == Qt::Key_Meta ) );
break;

default:
break;
}
}

QgsMapTool::keyPressEvent( e );
}

void QgsMapToolSelect::keyReleaseEvent( QKeyEvent *e )
{
if ( mSelectionHandler->keyReleaseEvent( e ) )
return;

if ( !e->isAutoRepeat() )
{
switch ( e->key() )
{
case Qt::Key_Shift:
case Qt::Key_Control:
case Qt::Key_Alt:
case Qt::Key_Meta:
modifiersChanged( e->modifiers() & Qt::ControlModifier && e->key() != Qt::Key_Control,
e->modifiers() & Qt::ShiftModifier && e->key() != Qt::Key_Shift,
e->modifiers() & Qt::AltModifier && e->key() != Qt::Key_Alt &&
!( e->modifiers() & Qt::ControlModifier && e->modifiers() & Qt::ShiftModifier && e->key() == Qt::Key_Meta ) );
break;

default:
break;
}
}

QgsMapTool::keyReleaseEvent( e );
}

Expand All @@ -89,3 +134,23 @@ void QgsMapToolSelect::selectFeatures( Qt::KeyboardModifiers modifiers )
else
QgsMapToolSelectUtils::selectMultipleFeatures( mCanvas, mSelectionHandler->selectedGeometry(), modifiers );
}

void QgsMapToolSelect::modifiersChanged( bool ctrlModifier, bool shiftModifier, bool altModifier )
{
if ( !ctrlModifier && !shiftModifier && !altModifier )
emit modeChanged( GeometryIntersectsSetSelection );
else if ( !ctrlModifier && !shiftModifier && altModifier )
emit modeChanged( GeometryWithinSetSelection );
else if ( !ctrlModifier && shiftModifier && !altModifier )
emit modeChanged( GeometryIntersectsAddToSelection );
else if ( !ctrlModifier && shiftModifier && altModifier )
emit modeChanged( GeometryWithinAddToSelection );
else if ( ctrlModifier && !shiftModifier && !altModifier )
emit modeChanged( GeometryIntersectsSubtractFromSelection );
else if ( ctrlModifier && !shiftModifier && altModifier )
emit modeChanged( GeometryWithinSubtractFromSelection );
else if ( ctrlModifier && shiftModifier && !altModifier )
emit modeChanged( GeometryIntersectsIntersectWithSelection );
else if ( ctrlModifier && shiftModifier && altModifier )
emit modeChanged( GeometryWithinIntersectWithSelection );
}
20 changes: 20 additions & 0 deletions src/app/qgsmaptoolselect.h
Expand Up @@ -27,21 +27,41 @@ class APP_EXPORT QgsMapToolSelect : public QgsMapTool
{
Q_OBJECT
public:

enum Mode
{
GeometryIntersectsSetSelection,
GeometryIntersectsAddToSelection,
GeometryIntersectsSubtractFromSelection,
GeometryIntersectsIntersectWithSelection,
GeometryWithinSetSelection,
GeometryWithinAddToSelection,
GeometryWithinSubtractFromSelection,
GeometryWithinIntersectWithSelection,
};

QgsMapToolSelect( QgsMapCanvas *canvas );

void setSelectionMode( QgsMapToolSelectionHandler::SelectionMode selectionMode );

void canvasPressEvent( QgsMapMouseEvent *e ) override;
void canvasMoveEvent( QgsMapMouseEvent *e ) override;
void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
void keyPressEvent( QKeyEvent *e ) override;
void keyReleaseEvent( QKeyEvent *e ) override;
void deactivate() override;

signals:

void modeChanged( Mode mode );

private slots:
void selectFeatures( Qt::KeyboardModifiers modifiers );

private:
std::unique_ptr<QgsMapToolSelectionHandler> mSelectionHandler;

void modifiersChanged( bool ctrlModifier, bool shiftModifier, bool altModifier );
};

#endif

0 comments on commit 7478e79

Please sign in to comment.