Skip to content

Commit

Permalink
Identify on mouse move, no mouse click
Browse files Browse the repository at this point in the history
Adds an option to allow for identify on mouse move
without clicking on the canvas.

This option behaves almost like the default identify
option, the only difference is that the used doesn't
need to click to trigger the identify action.

A 300ms timer takes care of triggering the actual identify
to avoid performance issues when moving the mouse.
  • Loading branch information
elpaso authored and nyalldawson committed Nov 8, 2022
1 parent 25a69f2 commit c7e62d6
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -966,6 +966,7 @@
<file>themes/default/mIconFonts.svg</file>
<file>themes/default/mActionNewFileGeodatabase.svg</file>
<file>themes/default/mIconBrowserRelations.svg</file>
<file>themes/default/mActionIdentifyByMouseMove.svg</file>
<file>themes/default/gpsicons/mIconGpsConnect.svg</file>
<file>themes/default/gpsicons/mIconGpsDisconnect.svg</file>
<file>themes/default/gpsicons/mActionRecenter.svg</file>
Expand Down
22 changes: 22 additions & 0 deletions images/themes/default/mActionIdentifyByMouseMove.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -466,11 +466,12 @@ void QgsIdentifyResultsDialog::initSelectionModes()
mSelectModeButton = new QToolButton( mIdentifyToolbar );
mSelectModeButton->setPopupMode( QToolButton::MenuButtonPopup );
QList<QAction *> selectActions;
selectActions << mActionSelectFeatures << mActionSelectPolygon
selectActions << mActionSelectFeatures << mActionSelectFeaturesOnMouseMove << mActionSelectPolygon
<< mActionSelectFreehand << mActionSelectRadius;

QActionGroup *group = new QActionGroup( this );
group->addAction( mActionSelectFeatures );
group->addAction( mActionSelectFeaturesOnMouseMove );
group->addAction( mActionSelectPolygon );
group->addAction( mActionSelectFreehand );
group->addAction( mActionSelectRadius );
Expand All @@ -481,6 +482,7 @@ void QgsIdentifyResultsDialog::initSelectionModes()
mIdentifyToolbar->addWidget( mSelectModeButton );

connect( mActionSelectFeatures, &QAction::triggered, this, &QgsIdentifyResultsDialog::setSelectionMode );
connect( mActionSelectFeaturesOnMouseMove, &QAction::triggered, this, &QgsIdentifyResultsDialog::setSelectionMode );
connect( mActionSelectPolygon, &QAction::triggered, this, &QgsIdentifyResultsDialog::setSelectionMode );
connect( mActionSelectFreehand, &QAction::triggered, this, &QgsIdentifyResultsDialog::setSelectionMode );
connect( mActionSelectRadius, &QAction::triggered, this, &QgsIdentifyResultsDialog::setSelectionMode );
Expand Down Expand Up @@ -2543,6 +2545,11 @@ void QgsIdentifyResultsDialog::setSelectionMode()
mSelectModeButton->setDefaultAction( mActionSelectPolygon );
mSelectionMode = QgsMapToolSelectionHandler::SelectPolygon;
}
else if ( obj == mActionSelectFeaturesOnMouseMove )
{
mSelectModeButton->setDefaultAction( mActionSelectFeaturesOnMouseMove );
mSelectionMode = QgsMapToolSelectionHandler::SelectOnMouseMove;
}
else if ( obj == mActionSelectFreehand )
{
mSelectModeButton->setDefaultAction( mActionSelectFreehand );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmaptoolselect.cpp
Expand Up @@ -133,6 +133,7 @@ QgsMapTool::Flags QgsMapToolSelect::flags() const
break;

case QgsMapToolSelectionHandler::SelectSimple:
case QgsMapToolSelectionHandler::SelectOnMouseMove:
case QgsMapToolSelectionHandler::SelectFreehand:
case QgsMapToolSelectionHandler::SelectRadius:
return QgsMapTool::flags() | QgsMapTool::ShowContextMenu;
Expand Down
15 changes: 15 additions & 0 deletions src/app/qgsmaptoolselectionhandler.cpp
Expand Up @@ -117,6 +117,7 @@ void QgsMapToolSelectionHandler::canvasReleaseEvent( QgsMapMouseEvent *e )
switch ( mSelectionMode )
{
case QgsMapToolSelectionHandler::SelectSimple:
case QgsMapToolSelectionHandler::SelectOnMouseMove:
selectFeaturesReleaseEvent( e );
break;
case QgsMapToolSelectionHandler::SelectPolygon:
Expand All @@ -135,6 +136,7 @@ void QgsMapToolSelectionHandler::canvasMoveEvent( QgsMapMouseEvent *e )
{
switch ( mSelectionMode )
{
case QgsMapToolSelectionHandler::SelectOnMouseMove:
case QgsMapToolSelectionHandler::SelectSimple:
selectFeaturesMoveEvent( e );
break;
Expand All @@ -154,6 +156,7 @@ void QgsMapToolSelectionHandler::canvasPressEvent( QgsMapMouseEvent *e )
{
switch ( mSelectionMode )
{
case QgsMapToolSelectionHandler::SelectOnMouseMove:
case QgsMapToolSelectionHandler::SelectSimple:
selectFeaturesPressEvent( e );
break;
Expand Down Expand Up @@ -192,6 +195,18 @@ void QgsMapToolSelectionHandler::selectFeaturesPressEvent( QgsMapMouseEvent *e )

void QgsMapToolSelectionHandler::selectFeaturesMoveEvent( QgsMapMouseEvent *e )
{

if ( mSelectionMode == QgsMapToolSelectionHandler::SelectOnMouseMove )
{
mOnMouseMoveDelayTimer.reset( new QTimer( ) );
mOnMouseMoveDelayTimer->singleShot( 300, mOnMouseMoveDelayTimer.get(), [ = ]
{
setSelectedGeometry( QgsGeometry::fromPointXY( toMapCoordinates( e->pos() ) ), e->modifiers() );
} );

return;
}

if ( e->buttons() != Qt::LeftButton )
return;

Expand Down
12 changes: 11 additions & 1 deletion src/app/qgsmaptoolselectionhandler.h
Expand Up @@ -18,6 +18,7 @@

#include <QObject>
#include <QWidget>
#include <QTimer>

#include "qgsgeometry.h"

Expand Down Expand Up @@ -94,7 +95,13 @@ class QgsMapToolSelectionHandler : public QObject
//! SelectFreehand - free hand selection
SelectFreehand,
//! SelectRadius - a circle selection
SelectRadius
SelectRadius,

/**
* SelectOnMouseMove - selection on mouse move
* \since QGIS 3.30
*/
SelectOnMouseMove
};
Q_ENUM( SelectionMode )

Expand Down Expand Up @@ -200,6 +207,9 @@ class QgsMapToolSelectionHandler : public QObject

//! Shows features to select polygon from existing features
QgsIdentifyMenu *mIdentifyMenu = nullptr; // owned by canvas

//! Delay timer for continuous selection mode
std::unique_ptr<QTimer> mOnMouseMoveDelayTimer;
};

#endif
13 changes: 13 additions & 0 deletions src/ui/qgsidentifyresultsbase.ui
Expand Up @@ -325,6 +325,18 @@
<string>Identify Features by area or single click</string>
</property>
</action>
<action name="mActionSelectFeaturesOnMouseMove">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionIdentifyByMouseMove.svg</normaloff>:/images/themes/default/mActionIdentifyByMouseMove.svg</iconset>
</property>
<property name="text">
<string>Identify Feature(s) on mouse move</string>
</property>
<property name="toolTip">
<string>Identify Features by mouse over</string>
</property>
</action>
<action name="mActionSelectPolygon">
<property name="icon">
<iconset resource="../../images/images.qrc">
Expand Down Expand Up @@ -407,6 +419,7 @@
<resources>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit c7e62d6

Please sign in to comment.