QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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
6  Email : [email protected]
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 #include <QMouseEvent>
17 
18 #include "qgscursors.h"
20 #include "qgsmapcanvas.h"
21 
23  : QgsMapToolIdentify( canvas )
24  , mCanvas( canvas )
25  , mLayer( vl )
26 {
27  mToolName = tr( "Identify feature" );
28 
29  // set cursor
30  QPixmap cursorPixmap = QPixmap(( const char ** ) cross_hair_cursor );
31  mCursor = QCursor( cursorPixmap, 1, 1 );
32 }
33 
35 {
36 }
37 
39 {
40 
41  QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
42 
43  QList<IdentifyResult> results;
44  if ( !identifyVectorLayer( &results, mLayer, point ) )
45  return;
46 
47  // TODO: display a menu when several features identified
48 
49  emit featureIdentified( results[0].mFeature );
50  emit featureIdentified( results[0].mFeature.id() );
51 }
52 
54 {
55  if ( e->key() == Qt::Key_Escape )
56  {
57  mCanvas->unsetMapTool( this );
58  }
59 }
void unsetMapTool(QgsMapTool *mapTool)
Unset the current map tool or last non zoom tool.
int x() const
int y() const
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsPoint toMapCoordinates(int x, int y) const
virtual void keyPressEvent(QKeyEvent *e) override
Key event for overriding. Default implementation does nothing.
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:227
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:216
Map tool for identifying features in layers.
A class to represent a point.
Definition: qgspoint.h:117
int key() const
QgsMapToolIdentifyFeature(QgsMapCanvas *canvas, QgsVectorLayer *vl=nullptr)
QgsMapToolIdentifyFeature is a map tool to identify a feature on a chosen layer.
virtual void canvasReleaseEvent(QgsMapMouseEvent *e) override
Overridden mouse release event.
void featureIdentified(const QgsFeature &)
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
const char * cross_hair_cursor[]
Definition: qgscursors.cpp:159
Represents a vector layer which manages a vector based data sets.
bool identifyVectorLayer(QList< IdentifyResult > *results, QgsVectorLayer *layer, const QgsPoint &point)