QGIS API Documentation  2.8.2-Wien
 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 : [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 }