mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
new map tool to select single feature
This commit is contained in:
parent
1b205be604
commit
4588d9bd6c
@ -74,6 +74,7 @@
|
||||
%Include qgsmaptool.sip
|
||||
%Include qgsmaptoolemitpoint.sip
|
||||
%Include qgsmaptoolidentify.sip
|
||||
%Include qgsmaptoolidentifyfeature.sip
|
||||
%Include qgsmaptoolpan.sip
|
||||
%Include qgsmaptooltouch.sip
|
||||
%Include qgsmaptoolzoom.sip
|
||||
|
@ -78,10 +78,6 @@ class QgsMapToolIdentify : QgsMapTool
|
||||
@return a list of IdentifyResult*/
|
||||
QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
|
||||
|
||||
protected:
|
||||
//! rubber bands for layer select mode
|
||||
void deleteRubberBands();
|
||||
|
||||
public slots:
|
||||
void formatChanged( QgsRasterLayer *layer );
|
||||
void layerDestroyed();
|
||||
@ -90,4 +86,25 @@ class QgsMapToolIdentify : QgsMapTool
|
||||
void identifyProgress( int, int );
|
||||
void identifyMessage( QString );
|
||||
void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult>& );
|
||||
|
||||
protected:
|
||||
//! rubber bands for layer select mode
|
||||
void deleteRubberBands();
|
||||
|
||||
/** Performs the identification.
|
||||
To avoid beeing forced to specify IdentifyMode with a list of layers
|
||||
this has been made private and two publics methods are offered
|
||||
@param x x coordinates of mouseEvent
|
||||
@param y y coordinates of mouseEvent
|
||||
@param mode Identification mode. Can use Qgis default settings or a defined mode.
|
||||
@param layerList Performs the identification within the given list of layers.
|
||||
@param layerType Only performs identification in a certain type of layers (raster, vector).
|
||||
@return true if identification succeeded and a feature has been found, false otherwise.*/
|
||||
QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
|
||||
|
||||
/** call the right method depending on layer type */
|
||||
bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
|
||||
|
||||
bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
|
||||
bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
|
||||
};
|
||||
|
14
python/gui/qgsmaptoolidentifyfeature.sip
Normal file
14
python/gui/qgsmaptoolidentifyfeature.sip
Normal file
@ -0,0 +1,14 @@
|
||||
class QgsMapToolIdentifyFeature : QgsMapToolIdentify
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsmaptoolidentifyfeature.h>
|
||||
%End
|
||||
|
||||
public:
|
||||
QgsMapToolIdentifyFeature( QgsVectorLayer* vl, QgsMapCanvas* canvas );
|
||||
|
||||
void canvasReleaseEvent( QMouseEvent* e );
|
||||
|
||||
signals:
|
||||
void featureIdentified( QgsFeature );
|
||||
};
|
@ -181,6 +181,7 @@ qgsmaptip.cpp
|
||||
qgsmaptool.cpp
|
||||
qgsmaptoolemitpoint.cpp
|
||||
qgsmaptoolidentify.cpp
|
||||
qgsmaptoolidentifyfeature.cpp
|
||||
qgsmaptoolpan.cpp
|
||||
qgsmaptoolzoom.cpp
|
||||
qgsmessagebar.cpp
|
||||
@ -372,6 +373,7 @@ qgsmapoverviewcanvas.h
|
||||
qgsmaptool.h
|
||||
qgsmaptoolemitpoint.h
|
||||
qgsmaptoolidentify.h
|
||||
qgsmaptoolidentifyfeature.h
|
||||
qgsmessagebaritem.h
|
||||
qgsmessagebar.h
|
||||
qgsmessagelogviewer.h
|
||||
@ -454,6 +456,7 @@ qgsmaptip.h
|
||||
qgsmaptool.h
|
||||
qgsmaptoolemitpoint.h
|
||||
qgsmaptoolidentify.h
|
||||
qgsmaptoolidentifyfeature.h
|
||||
qgsmaptoolpan.h
|
||||
qgsmaptoolzoom.h
|
||||
qgsmessagebaritem.h
|
||||
|
@ -85,6 +85,8 @@ void QgsMapTool::activate()
|
||||
// set cursor (map tools usually set it in constructor)
|
||||
mCanvas->setCursor( mCursor );
|
||||
QgsDebugMsg( "Cursor has been set" );
|
||||
|
||||
emit activated();
|
||||
}
|
||||
|
||||
|
||||
@ -94,6 +96,8 @@ void QgsMapTool::deactivate()
|
||||
mAction->setChecked( false );
|
||||
if ( mButton )
|
||||
mButton->setChecked( false );
|
||||
|
||||
emit deactivated();
|
||||
}
|
||||
|
||||
void QgsMapTool::setAction( QAction* action )
|
||||
|
@ -153,6 +153,12 @@ class GUI_EXPORT QgsMapTool : public QObject
|
||||
//! emit signal to clear previous message
|
||||
void messageDiscarded();
|
||||
|
||||
//! signal emitted once the map tool is activated
|
||||
void activated();
|
||||
|
||||
//! signal emitted once the map tool is deactivated
|
||||
void deactivated();
|
||||
|
||||
private slots:
|
||||
//! clear pointer when action is destroyed
|
||||
void actionDestroyed();
|
||||
|
@ -123,10 +123,6 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
|
||||
@return a list of IdentifyResult*/
|
||||
QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
|
||||
|
||||
protected:
|
||||
//! rubber bands for layer select mode
|
||||
void deleteRubberBands();
|
||||
|
||||
public slots:
|
||||
void formatChanged( QgsRasterLayer *layer );
|
||||
void layerDestroyed();
|
||||
@ -136,7 +132,10 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
|
||||
void identifyMessage( QString );
|
||||
void changedRasterResults( QList<IdentifyResult>& );
|
||||
|
||||
private:
|
||||
protected:
|
||||
//! rubber bands for layer select mode
|
||||
void deleteRubberBands();
|
||||
|
||||
/** Performs the identification.
|
||||
To avoid beeing forced to specify IdentifyMode with a list of layers
|
||||
this has been made private and two publics methods are offered
|
||||
@ -154,6 +153,8 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
|
||||
bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
|
||||
bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
|
||||
|
||||
|
||||
private:
|
||||
//! Private helper
|
||||
virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
|
||||
|
||||
|
49
src/gui/qgsmaptoolidentifyfeature.cpp
Normal file
49
src/gui/qgsmaptoolidentifyfeature.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/***************************************************************************
|
||||
qgsmaptoolidentifyfeature.cpp
|
||||
--------------------------------------
|
||||
Date : 22.5.2014
|
||||
Copyright : (C) 2014 Denis Rouzaud
|
||||
Email : denis.rouzaud@gmail.com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "qgsmaptoolidentifyfeature.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
QgsMapToolIdentifyFeature::QgsMapToolIdentifyFeature( QgsVectorLayer* vl, QgsMapCanvas* canvas )
|
||||
: QgsMapToolIdentify( canvas )
|
||||
, mLayer( vl )
|
||||
, mCanvas( canvas )
|
||||
{
|
||||
}
|
||||
|
||||
void QgsMapToolIdentifyFeature::canvasReleaseEvent( QMouseEvent* e )
|
||||
{
|
||||
|
||||
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
|
||||
|
||||
QList<IdentifyResult> results;
|
||||
if ( !identifyVectorLayer( &results, mLayer, point ) )
|
||||
return;
|
||||
|
||||
// TODO: display a menu when several features identified
|
||||
|
||||
emit featureIdentified( results[0].mFeature );
|
||||
emit featureIdentified( results[0].mFeature.id() );
|
||||
}
|
||||
|
||||
void QgsMapToolIdentifyFeature::keyPressEvent( QKeyEvent* e )
|
||||
{
|
||||
if ( e->key() == Qt::Key_Escape )
|
||||
{
|
||||
deactivate();
|
||||
}
|
||||
}
|
47
src/gui/qgsmaptoolidentifyfeature.h
Normal file
47
src/gui/qgsmaptoolidentifyfeature.h
Normal file
@ -0,0 +1,47 @@
|
||||
/***************************************************************************
|
||||
qgsmaptoolidentifyfeature.h
|
||||
--------------------------------------
|
||||
Date : 22.5.2014
|
||||
Copyright : (C) 2014 Denis Rouzaud
|
||||
Email : denis.rouzaud@gmail.com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSMAPTOOLIDENTIFYFEATURE_H
|
||||
#define QGSMAPTOOLIDENTIFYFEATURE_H
|
||||
|
||||
#include "qgsmaptoolidentify.h"
|
||||
|
||||
/**
|
||||
* @brief The QgsMapToolIdentifyFeature class is a map tool to be used 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.
|
||||
*/
|
||||
class GUI_EXPORT QgsMapToolIdentifyFeature : public QgsMapToolIdentify
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsMapToolIdentifyFeature( QgsVectorLayer* vl, QgsMapCanvas* canvas );
|
||||
|
||||
virtual void canvasReleaseEvent( QMouseEvent* e );
|
||||
|
||||
signals:
|
||||
void featureIdentified( const QgsFeature& );
|
||||
void featureIdentified( QgsFeatureId );
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent( QKeyEvent* e );
|
||||
|
||||
private:
|
||||
QgsVectorLayer* mLayer;
|
||||
QgsMapCanvas* mCanvas;
|
||||
};
|
||||
|
||||
#endif // QGSMAPTOOLIDENTIFYFEATURE_H
|
Loading…
x
Reference in New Issue
Block a user