Quantum GIS API Documentation  master-693a1fe
src/gui/qgsmaptoolidentify.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsmaptoolidentify.h  -  map tool for identifying features
00003     ---------------------
00004     begin                : January 2006
00005     copyright            : (C) 2006 by Martin Dobias
00006     email                : wonder.sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #ifndef QGSMAPTOOLIDENTIFY_H
00017 #define QGSMAPTOOLIDENTIFY_H
00018 
00019 
00020 #include "qgsmaptool.h"
00021 #include "qgspoint.h"
00022 #include "qgsfeature.h"
00023 #include "qgsfield.h"
00024 #include "qgsdistancearea.h"
00025 #include "qgsmaplayer.h"
00026 
00027 #include <QObject>
00028 #include <QPointer>
00029 
00030 class QgsRasterLayer;
00031 class QgsVectorLayer;
00032 class QgsMapLayer;
00033 class QgsMapCanvas;
00034 
00043 class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
00044 {
00045     Q_OBJECT
00046 
00047   public:
00048 
00049     enum IdentifyMode
00050     {
00051       DefaultQgsSetting = -1,
00052       ActiveLayer,
00053       TopDownStopAtFirst,
00054       TopDownAll
00055     };
00056 
00057     enum LayerType
00058     {
00059       AllLayers = -1,
00060       VectorLayer,
00061       RasterLayer
00062     };
00063 
00064     struct IdentifyResult
00065     {
00066       IdentifyResult() {}
00067 
00068       IdentifyResult( QgsMapLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
00069           mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes )  {}
00070 
00071       IdentifyResult( QgsMapLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes ):
00072           mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes )  {}
00073 
00074       IdentifyResult( QgsMapLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
00075           mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes )  {}
00076 
00077       QgsMapLayer* mLayer;
00078       QString mLabel;
00079       QgsFields mFields;
00080       QgsFeature mFeature;
00081       QMap< QString, QString > mAttributes;
00082       QMap< QString, QString > mDerivedAttributes;
00083       QMap< QString, QVariant > mParams;
00084     };
00085 
00087     QgsMapToolIdentify( QgsMapCanvas * canvas );
00088 
00089     virtual ~QgsMapToolIdentify();
00090 
00092     virtual void canvasMoveEvent( QMouseEvent * e );
00093 
00095     virtual void canvasPressEvent( QMouseEvent * e );
00096 
00098     virtual void canvasReleaseEvent( QMouseEvent * e );
00099 
00100     virtual void activate();
00101 
00102     virtual void deactivate();
00103 
00110     QList<IdentifyResult> identify( int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
00111 
00120     QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
00121 
00122   public slots:
00123     void formatChanged( QgsRasterLayer *layer );
00124 
00125   signals:
00126     void identifyProgress( int, int );
00127     void identifyMessage( QString );
00128     void changedRasterResults( QList<IdentifyResult>& );
00129 
00130   private:
00140     QList<IdentifyResult> identify( int x, int y, IdentifyMode mode,  QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
00141 
00143     bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
00144 
00145     bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
00146     bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
00147 
00149     virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
00150 
00152     virtual QGis::UnitType displayUnits();
00153 
00154     QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer );
00155 
00156     // Last point in canvas CRS
00157     QgsPoint mLastPoint;
00158 
00159     double mLastMapUnitsPerPixel;
00160 
00161     QgsRectangle mLastExtent;
00162 };
00163 
00164 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines