QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
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.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:202
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:191
Map tool for identifying features in layers.
A class to represent a point.
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.
const char * cross_hair_cursor[]
Definition: qgscursors.cpp:159
Represents a vector layer which manages a vector based data sets.
QgsMapToolIdentifyFeature(QgsMapCanvas *canvas, QgsVectorLayer *vl=0)
QgsMapToolIdentifyFeature is a map tool to identify a feature on a chosen layer.
bool identifyVectorLayer(QList< IdentifyResult > *results, QgsVectorLayer *layer, QgsPoint point)
#define tr(sourceText)