Skip to content
Permalink
Browse files

[FEATURE] Identify: more selection modes (simple / polygon / freehand…

… / radius)

This extends identify tool with the ability to switch to different selection modes
(the ones offered also by the selection map tool)
  • Loading branch information
wonder-sk committed Apr 20, 2018
1 parent d87f75a commit bac30807543b75108ffeddd083f3697dc14d6145
@@ -144,6 +144,7 @@
%Include qgsmaptoolidentify.sip
%Include qgsmaptoolidentifyfeature.sip
%Include qgsmaptoolpan.sip
%Include qgsmaptoolselectionhandler.sip
%Include qgsmaptoolzoom.sip
%Include qgsmaplayerconfigwidget.sip
%Include qgsmenuheader.sip
@@ -108,6 +108,10 @@ this has been made private and two publics methods are offered
:return: a list of IdentifyResult*
%End

QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType );
QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType );


QgsIdentifyMenu *identifyMenu();
%Docstring
return a pointer to the identify menu which will be used in layer selection mode
@@ -144,9 +148,12 @@ this has been made private and two publics methods are offered
%Docstring
Call the right method depending on layer type
%End
bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, LayerType layerType );

bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel );
bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel );
bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point );
bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry );

};

@@ -0,0 +1,104 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsmaptoolselectionhandler.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/








class QgsMapToolSelectionHandler : QObject
{
%Docstring
Utility class for handling various methods to create geometry for selection in layers.

.. versionadded:: 3.2
%End

%TypeHeaderCode
#include "qgsmaptoolselectionhandler.h"
%End
public:

enum SelectionMode
{
//! SelectSimple
SelectSimple,
//! SelectPolygon
SelectPolygon,
//! SelectFreehand
SelectFreehand,
//! SelectRadius
SelectRadius
};

QgsMapToolSelectionHandler( QgsMapCanvas *canvas,
QgsMapToolSelectionHandler::SelectionMode selectionMode = QgsMapToolSelectionHandler::SelectionMode::SelectSimple );
%Docstring
constructor
%End

~QgsMapToolSelectionHandler();

void setInterface( QgisInterface *iface );
%Docstring
Configures QGIS interface - used to register selection radius widget
%End

QgsGeometry selectedGeometry();
%Docstring
Returns most recently selected geometry (may be a point or a polygon)
%End

SelectionMode selectionMode();
%Docstring
Sets the current selection mode
%End
void setSelectionMode( SelectionMode mode );
%Docstring
Returns the current selection mode
%End

void deactivate();
%Docstring
Deactivates handler (when map tool gets deactivated)
%End

void canvasMoveEvent( QgsMapMouseEvent *e );
%Docstring
Handles mouse move event from map tool
%End
void canvasPressEvent( QgsMapMouseEvent *e );
%Docstring
Handles mouse press event from map tool
%End
void canvasReleaseEvent( QgsMapMouseEvent *e );
%Docstring
Handles mouse releasae event from map tool
%End
bool keyReleaseEvent( QKeyEvent *e );
%Docstring
Handles escape press event - returns true if the even has been processed
%End

signals:
void geometryChanged( Qt::KeyboardModifiers modifiers = Qt::NoModifier );
%Docstring
emitted when a new geometry has been picked (selectedGeometry())
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsmaptoolselectionhandler.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -97,10 +97,6 @@ SET(QGIS_APP_SRCS
qgsmaptoolrotatelabel.cpp
qgsmaptoolrotatepointsymbols.cpp
qgsmaptoolselect.cpp
qgsmaptoolselectrectangle.cpp
qgsmaptoolselectfreehand.cpp
qgsmaptoolselectpolygon.cpp
qgsmaptoolselectradius.cpp
qgsmaptoolselectutils.cpp
qgsmaptoolsimplify.cpp
qgsmaptoolsplitfeatures.cpp
@@ -310,11 +306,7 @@ SET (QGIS_APP_MOC_HDRS
qgsmaptoolrotatefeature.h
qgsmaptoolrotatelabel.h
qgsmaptoolrotatepointsymbols.h
qgsmaptoolselectfreehand.h
qgsmaptoolselect.h
qgsmaptoolselectpolygon.h
qgsmaptoolselectradius.h
qgsmaptoolselectrectangle.h
qgsmaptoolsimplify.h
qgsmaptoolsplitfeatures.h
qgsmaptoolsplitparts.h
@@ -384,10 +384,6 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsmaptooloffsetpointsymbol.h"
#include "qgsmaptoolpan.h"
#include "qgsmaptoolselect.h"
#include "qgsmaptoolselectrectangle.h"
#include "qgsmaptoolselectfreehand.h"
#include "qgsmaptoolselectpolygon.h"
#include "qgsmaptoolselectradius.h"
#include "qgsmaptoolsvgannotation.h"
#include "qgsmaptoolreshape.h"
#include "qgsmaptoolrotatepointsymbols.h"
@@ -1315,6 +1311,12 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
// should come after fileNewBlank to ensure project is properly set up to receive any data source files
QgsApplication::setFileOpenEventReceiver( this );

// finish initialization of map tools that need access to QGIS interface
mMapTools.mSelectFeatures->setInterface( mQgisInterface );
mMapTools.mSelectPolygon->setInterface( mQgisInterface );
mMapTools.mSelectFreehand->setInterface( mQgisInterface );
mMapTools.mSelectRadius->setInterface( mQgisInterface );
mMapTools.mIdentify->setInterface( mQgisInterface );

#ifdef ANDROID
toggleFullScreen();
@@ -3406,14 +3408,18 @@ void QgisApp::createCanvasTools()
mMapTools.mSplitFeatures->setAction( mActionSplitFeatures );
mMapTools.mSplitParts = new QgsMapToolSplitParts( mMapCanvas );
mMapTools.mSplitParts->setAction( mActionSplitParts );
mMapTools.mSelectFeatures = new QgsMapToolSelectFeatures( mMapCanvas );
mMapTools.mSelectFeatures = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectFeatures->setAction( mActionSelectFeatures );
mMapTools.mSelectPolygon = new QgsMapToolSelectPolygon( mMapCanvas );
mMapTools.mSelectFeatures->setSelectionMode( QgsMapToolSelectionHandler::SelectSimple );
mMapTools.mSelectPolygon = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectPolygon->setAction( mActionSelectPolygon );
mMapTools.mSelectFreehand = new QgsMapToolSelectFreehand( mMapCanvas );
mMapTools.mSelectPolygon->setSelectionMode( QgsMapToolSelectionHandler::SelectPolygon );
mMapTools.mSelectFreehand = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectFreehand->setAction( mActionSelectFreehand );
mMapTools.mSelectRadius = new QgsMapToolSelectRadius( mMapCanvas );
mMapTools.mSelectFreehand->setSelectionMode( QgsMapToolSelectionHandler::SelectFreehand );
mMapTools.mSelectRadius = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelectRadius->setAction( mActionSelectRadius );
mMapTools.mSelectRadius->setSelectionMode( QgsMapToolSelectionHandler::SelectRadius );
mMapTools.mAddRing = new QgsMapToolAddRing( mMapCanvas );
mMapTools.mAddRing->setAction( mActionAddRing );
mMapTools.mFillRing = new QgsMapToolFillRing( mMapCanvas );
@@ -76,6 +76,7 @@ class QgsMapToolAddFeature;
class QgsMapToolDigitizeFeature;
class QgsMapToolAdvancedDigitizing;
class QgsMapToolIdentifyAction;
class QgsMapToolSelect;
class QgsPluginLayer;
class QgsPluginLayer;
class QgsPluginManager;
@@ -1962,11 +1963,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mReshapeFeatures = nullptr;
QgsMapTool *mSplitFeatures = nullptr;
QgsMapTool *mSplitParts = nullptr;
QgsMapTool *mSelect = nullptr;
QgsMapTool *mSelectFeatures = nullptr;
QgsMapTool *mSelectPolygon = nullptr;
QgsMapTool *mSelectFreehand = nullptr;
QgsMapTool *mSelectRadius = nullptr;
QgsMapToolSelect *mSelectFeatures = nullptr;
QgsMapToolSelect *mSelectPolygon = nullptr;
QgsMapToolSelect *mSelectFreehand = nullptr;
QgsMapToolSelect *mSelectRadius = nullptr;
QgsMapTool *mVertexAdd = nullptr;
QgsMapTool *mVertexMove = nullptr;
QgsMapTool *mVertexDelete = nullptr;
@@ -27,6 +27,7 @@
#include "qgsfeaturestore.h"
#include "qgsgeometry.h"
#include "qgshighlight.h"
#include "qgsmaptoolidentifyaction.h"
#include "qgsidentifyresultsdialog.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
@@ -408,6 +409,8 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
connect( mOpenFormAction, &QAction::triggered, this, &QgsIdentifyResultsDialog::featureForm );
connect( mClearResultsAction, &QAction::triggered, this, &QgsIdentifyResultsDialog::clear );
connect( mHelpToolButton, &QAbstractButton::clicked, this, &QgsIdentifyResultsDialog::showHelp );

initSelectionModes();
}

QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
@@ -424,6 +427,31 @@ QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
mPlotCurves.clear();
}

void QgsIdentifyResultsDialog::initSelectionModes()
{
mSelectModeButton = new QToolButton( mIdentifyToolbar );
mSelectModeButton->setPopupMode( QToolButton::MenuButtonPopup );
QList<QAction *> selectActions;
selectActions << mActionSelectFeatures << mActionSelectPolygon
<< mActionSelectFreehand << mActionSelectRadius;

QActionGroup *group = new QActionGroup( this );
group->addAction( mActionSelectFeatures );
group->addAction( mActionSelectPolygon );
group->addAction( mActionSelectFreehand );
group->addAction( mActionSelectRadius );

mSelectModeButton->addActions( selectActions );
mSelectModeButton->setDefaultAction( mActionSelectFeatures );

mIdentifyToolbar->addWidget( mSelectModeButton );

connect( mActionSelectFeatures, &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 );
}

QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *object )
{
for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
@@ -1991,6 +2019,40 @@ void QgsIdentifyResultsDialog::showHelp()
QgsHelp::openHelp( QStringLiteral( "introduction/general_tools.html#identify" ) );
}

void QgsIdentifyResultsDialog::setSelectionMode()
{
QObject *obj = sender();
QgsMapToolSelectionHandler::SelectionMode oldMode = mSelectionMode;
if ( obj == mActionSelectFeatures )
{
mSelectModeButton->setDefaultAction( mActionSelectFeatures );
mSelectionMode = QgsMapToolSelectionHandler::SelectSimple;
}
else if ( obj == mActionSelectPolygon )
{
mSelectModeButton->setDefaultAction( mActionSelectPolygon );
mSelectionMode = QgsMapToolSelectionHandler::SelectPolygon;
}
else if ( obj == mActionSelectFreehand )
{
mSelectModeButton->setDefaultAction( mActionSelectFreehand );
mSelectionMode = QgsMapToolSelectionHandler::SelectFreehand;
}
else if ( obj == mActionSelectRadius )
{
mSelectModeButton->setDefaultAction( mActionSelectRadius );
mSelectionMode = QgsMapToolSelectionHandler::SelectRadius;
}

if ( oldMode != mSelectionMode )
emit selectionModeChanged();
}

QgsMapToolSelectionHandler::SelectionMode QgsIdentifyResultsDialog::selectionMode()
{
return mSelectionMode;
}

void QgsIdentifyResultsDialog::setExpressionContextScope( const QgsExpressionContextScope &scope )
{
mExpressionContextScope = scope;
@@ -26,6 +26,7 @@
#include "qgsmaptoolidentify.h"
#include "qgswebview.h"
#include "qgsexpressioncontext.h"
#include "qgsmaptoolselectionhandler.h"

#include <QWidget>
#include <QList>
@@ -167,6 +168,8 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
*/
QgsExpressionContextScope expressionContextScope() const;

QgsMapToolSelectionHandler::SelectionMode selectionMode();

signals:
void selectedFeatureChanged( QgsVectorLayer *, QgsFeatureId featureId );

@@ -177,6 +180,8 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti

void activateLayer( QgsMapLayer * );

void selectionModeChanged();

public slots:
//! Remove results
void clear();
@@ -251,6 +256,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
QList<QgsFeature> mFeatures;
QMap< QString, QMap< QString, QVariant > > mWidgetCaches;
QgsExpressionContextScope mExpressionContextScope;
QToolButton *mSelectModeButton;

QgsMapLayer *layer( QTreeWidgetItem *item );
QgsVectorLayer *vectorLayer( QTreeWidgetItem *item );
@@ -259,6 +265,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
QTreeWidgetItem *layerItem( QTreeWidgetItem *item );
QTreeWidgetItem *layerItem( QObject *layer );


void highlightLayer( QTreeWidgetItem *object );
void layerProperties( QTreeWidgetItem *object );
void disconnectLayer( QObject *object );
@@ -279,6 +286,12 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
QVector<QgsIdentifyPlotCurve *> mPlotCurves;

void showHelp();

QgsMapToolSelectionHandler::SelectionMode mSelectionMode = QgsMapToolSelectionHandler::SelectSimple;

void setSelectionMode();

void initSelectionModes();
};

class QgsIdentifyResultsDialogMapLayerAction : public QAction

0 comments on commit bac3080

Please sign in to comment.
You can’t perform that action at this time.