From fb30b84cfb24e9d95d010ccd968c063a81d64995 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Tue, 16 Sep 2014 09:33:51 +0200 Subject: [PATCH] [QgsMapToolIdentifyFeature] allow initializing without any layer --- python/gui/qgsmaptoolidentifyfeature.sip | 10 +++++++++- .../editorwidgets/qgsrelationreferencewidget.cpp | 2 +- src/gui/qgsmaptoolidentifyfeature.cpp | 4 ++-- src/gui/qgsmaptoolidentifyfeature.h | 14 +++++++++++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/python/gui/qgsmaptoolidentifyfeature.sip b/python/gui/qgsmaptoolidentifyfeature.sip index c02b796c438..93604d3a705 100644 --- a/python/gui/qgsmaptoolidentifyfeature.sip +++ b/python/gui/qgsmaptoolidentifyfeature.sip @@ -5,7 +5,15 @@ class QgsMapToolIdentifyFeature : QgsMapToolIdentify %End public: - QgsMapToolIdentifyFeature( QgsVectorLayer* vl, QgsMapCanvas* canvas ); + /** + * @brief QgsMapToolIdentifyFeature is a map tool to identify a feature on a chosen layer + * @param canvas the map canvas + * @param vl the vector layer. The map tool can be initialized without any layer and can be set afterward. + */ + QgsMapToolIdentifyFeature( QgsMapCanvas* canvas, QgsVectorLayer* vl = 0 ); + + //! change the layer used by the map tool to identify + void setLayer( QgsVectorLayer* vl ); void canvasReleaseEvent( QMouseEvent* e ); diff --git a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp index 7da05576fb6..f512508f05c 100644 --- a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp +++ b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp @@ -516,7 +516,7 @@ void QgsRelationReferenceWidget::mapIdentification() if ( !mCanvas ) return; - mMapTool = new QgsMapToolIdentifyFeature( mReferencedLayer, mCanvas ); + mMapTool = new QgsMapToolIdentifyFeature( mCanvas, mReferencedLayer ); mCanvas->setMapTool( mMapTool ); mWindowWidget = window(); mWindowWidget->hide(); diff --git a/src/gui/qgsmaptoolidentifyfeature.cpp b/src/gui/qgsmaptoolidentifyfeature.cpp index 28d0ca20609..5fb7680904c 100644 --- a/src/gui/qgsmaptoolidentifyfeature.cpp +++ b/src/gui/qgsmaptoolidentifyfeature.cpp @@ -18,10 +18,10 @@ #include "qgsmaptoolidentifyfeature.h" #include "qgsmapcanvas.h" -QgsMapToolIdentifyFeature::QgsMapToolIdentifyFeature( QgsVectorLayer* vl, QgsMapCanvas* canvas ) +QgsMapToolIdentifyFeature::QgsMapToolIdentifyFeature( QgsMapCanvas* canvas, QgsVectorLayer* vl ) : QgsMapToolIdentify( canvas ) - , mLayer( vl ) , mCanvas( canvas ) + , mLayer( vl ) { } diff --git a/src/gui/qgsmaptoolidentifyfeature.h b/src/gui/qgsmaptoolidentifyfeature.h index 87cbf68bc66..8da70d37782 100644 --- a/src/gui/qgsmaptoolidentifyfeature.h +++ b/src/gui/qgsmaptoolidentifyfeature.h @@ -19,7 +19,7 @@ #include "qgsmaptoolidentify.h" /** - * @brief The QgsMapToolIdentifyFeature class is a map tool to be used to identify a feature on a chosen layer. + * @brief The QgsMapToolIdentifyFeature class is a map tool to identify a feature on a chosen layer. * Once the map tool is enable, user can click on the map canvas to identify a feature. * A signal will then be emitted. */ @@ -28,7 +28,15 @@ class GUI_EXPORT QgsMapToolIdentifyFeature : public QgsMapToolIdentify Q_OBJECT public: - QgsMapToolIdentifyFeature( QgsVectorLayer* vl, QgsMapCanvas* canvas ); + /** + * @brief QgsMapToolIdentifyFeature is a map tool to identify a feature on a chosen layer + * @param canvas the map canvas + * @param vl the vector layer. The map tool can be initialized without any layer and can be set afterward. + */ + QgsMapToolIdentifyFeature( QgsMapCanvas* canvas, QgsVectorLayer* vl = 0 ); + + //! change the layer used by the map tool to identify + void setLayer( QgsVectorLayer* vl ){ mLayer = vl; } virtual void canvasReleaseEvent( QMouseEvent* e ); @@ -40,8 +48,8 @@ class GUI_EXPORT QgsMapToolIdentifyFeature : public QgsMapToolIdentify virtual void keyPressEvent( QKeyEvent* e ); private: - QgsVectorLayer* mLayer; QgsMapCanvas* mCanvas; + QgsVectorLayer* mLayer; }; #endif // QGSMAPTOOLIDENTIFYFEATURE_H