QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 : denis.rouzaud@gmail.com
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 
19 #include "qgsmapcanvas.h"
20 
22  : QgsMapToolIdentify( canvas )
23  , mLayer( vl )
24  , mCanvas( canvas )
25 {
26 }
27 
29 {
30 
31  QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
32 
33  QList<IdentifyResult> results;
34  if ( !identifyVectorLayer( &results, mLayer, point ) )
35  return;
36 
37  // TODO: display a menu when several features identified
38 
39  emit featureIdentified( results[0].mFeature );
40  emit featureIdentified( results[0].mFeature.id() );
41 }
42 
44 {
45  if ( e->key() == Qt::Key_Escape )
46  {
47  deactivate();
48  }
49 }
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
virtual void deactivate()
called when map tool is being deactivated
Map tool for identifying features in layers.
QgsMapToolIdentifyFeature(QgsVectorLayer *vl, QgsMapCanvas *canvas)
A class to represent a point geometry.
Definition: qgspoint.h:63
QgsPoint toMapCoordinates(int x, int y) const
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
void featureIdentified(const QgsFeature &)
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
virtual void canvasReleaseEvent(QMouseEvent *e)
Overridden mouse release event.
Represents a vector layer which manages a vector based data sets.
bool identifyVectorLayer(QList< IdentifyResult > *results, QgsVectorLayer *layer, QgsPoint point)