QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsmaptoolidentifyfeature.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolidentifyfeature.cpp
3 --------------------------------------
4 Date : 22.5.2014
5 Copyright : (C) 2014 Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16
18#include "qgsmapcanvas.h"
19#include "qgsmapmouseevent.h"
20
22 : QgsMapToolIdentify( canvas )
23 , mLayer( vl )
24{
25 mToolName = tr( "Identify feature" );
26
27 // set cursor
28 mCursor = QCursor( Qt::CrossCursor );
29}
30
32{
33
34 const QgsPointXY point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
35
36 QList<IdentifyResult> results;
37 if ( !identifyVectorLayer( &results, mLayer, point ) )
38 return;
39
40 // TODO: display a menu when several features identified
41
42 emit featureIdentified( results[0].mFeature );
43 emit featureIdentified( results[0].mFeature.id() );
44}
45
47{
48 if ( e->key() == Qt::Key_Escape )
49 {
50 mCanvas->unsetMapTool( this );
51 }
52}
Map canvas is a class for displaying all GIS data types on a canvas.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
void featureIdentified(const QgsFeature &)
QgsMapToolIdentifyFeature(QgsMapCanvas *canvas, QgsVectorLayer *vl=nullptr)
QgsMapToolIdentifyFeature is a map tool to identify a feature on a chosen layer.
void keyPressEvent(QKeyEvent *e) override
Key event for overriding. Default implementation does nothing.
void canvasReleaseEvent(QgsMapMouseEvent *e) override
Mouse release event for overriding. Default implementation does nothing.
Map tool for identifying features in layers.
bool identifyVectorLayer(QList< QgsMapToolIdentify::IdentifyResult > *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext=QgsIdentifyContext())
Performs the identification against a given vector layer.
QPointer< QgsMapCanvas > mCanvas
The pointer to the map canvas.
Definition qgsmaptool.h:349
QString mToolName
The translated name of the map tool.
Definition qgsmaptool.h:367
QCursor mCursor
The cursor used in the map tool.
Definition qgsmaptool.h:352
A class to represent a 2D point.
Definition qgspointxy.h:59
Represents a vector layer which manages a vector based data sets.