2007-01-09 02:39:15 +00:00
|
|
|
|
2007-08-06 23:33:00 +00:00
|
|
|
%ModuleHeaderCode
|
|
|
|
// fix to allow compilation with sip 4.7 that for some reason
|
|
|
|
// doesn't add these includes to the file where the code from
|
|
|
|
// ConvertToSubClassCode goes.
|
|
|
|
#include <qgsmaptoolzoom.h>
|
|
|
|
#include <qgsmaptoolpan.h>
|
|
|
|
#include <qgsmaptoolemitpoint.h>
|
2013-01-25 08:06:30 +01:00
|
|
|
#include <qgsmaptoolidentify.h>
|
2007-08-06 23:33:00 +00:00
|
|
|
%End
|
|
|
|
|
2007-04-23 14:57:08 +00:00
|
|
|
class QgsMapTool : QObject
|
2007-01-09 02:39:15 +00:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsmaptool.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
%ConvertToSubClassCode
|
|
|
|
if (dynamic_cast<QgsMapToolZoom*>(sipCpp) != NULL)
|
2015-10-20 18:09:33 +02:00
|
|
|
sipType = sipType_QgsMapToolZoom;
|
2007-01-09 02:39:15 +00:00
|
|
|
else if (dynamic_cast<QgsMapToolPan*>(sipCpp) != NULL)
|
2015-10-20 18:09:33 +02:00
|
|
|
sipType = sipType_QgsMapToolPan;
|
2007-06-09 10:54:46 +00:00
|
|
|
else if (dynamic_cast<QgsMapToolEmitPoint*>(sipCpp) != NULL)
|
2015-10-20 18:09:33 +02:00
|
|
|
sipType = sipType_QgsMapToolEmitPoint;
|
2013-01-25 08:06:30 +01:00
|
|
|
else if (dynamic_cast<QgsMapToolIdentify*>(sipCpp) != NULL)
|
2015-10-20 18:09:33 +02:00
|
|
|
sipType = sipType_QgsMapToolIdentify;
|
2007-01-09 02:39:15 +00:00
|
|
|
else
|
2015-10-20 18:09:33 +02:00
|
|
|
sipType = NULL;
|
2007-01-09 02:39:15 +00:00
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
2013-01-12 23:48:58 +01:00
|
|
|
|
2016-05-30 02:42:12 +10:00
|
|
|
//! Enumeration of flags that adjust the way the map tool operates
|
|
|
|
//! @note added in QGIS 2.16
|
|
|
|
enum Flag
|
|
|
|
{
|
|
|
|
Transient, /*!< Indicates that this map tool performs a transient (one-off) operation.
|
|
|
|
If it does, the tool can be operated once and then a previous map
|
|
|
|
tool automatically restored. */
|
|
|
|
EditTool, /*!< Map tool is an edit tool, which can only be used when layer is editable*/
|
2016-05-30 06:19:34 +10:00
|
|
|
AllowZoomRect, /*!< Allow zooming by rectangle (by holding shift and dragging) while the tool is active*/
|
2016-05-30 02:42:12 +10:00
|
|
|
};
|
|
|
|
typedef QFlags<QgsMapTool::Flag> Flags;
|
|
|
|
|
|
|
|
/** Returns the flags for the map tool.
|
|
|
|
* @note added in QGIS 2.16
|
|
|
|
*/
|
|
|
|
virtual Flags flags() const;
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! virtual destructor
|
|
|
|
virtual ~QgsMapTool();
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Mouse move event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void canvasMoveEvent( QgsMapMouseEvent *e );
|
2008-05-29 15:59:57 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Mouse double click event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void canvasDoubleClickEvent( QgsMapMouseEvent *e );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Mouse press event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void canvasPressEvent( QgsMapMouseEvent *e );
|
2009-02-06 15:42:35 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Mouse release event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void canvasReleaseEvent( QgsMapMouseEvent *e );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2013-03-30 20:12:02 +01:00
|
|
|
//! Mouse wheel event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void wheelEvent( QWheelEvent *e );
|
2013-03-30 20:12:02 +01:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Key event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void keyPressEvent( QKeyEvent *e );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! Key event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void keyReleaseEvent( QKeyEvent *e );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! gesture event for overriding. Default implementation does nothing.
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual bool gestureEvent( QGestureEvent *e );
|
2009-02-06 15:42:35 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/** Use this to associate a QAction to this maptool. Then when the setMapTool
|
2007-01-09 02:39:15 +00:00
|
|
|
* method of mapcanvas is called the action state will be set to on.
|
|
|
|
* Usually this will cause e.g. a toolbutton to appear pressed in and
|
|
|
|
* the previously used toolbutton to pop out. */
|
2017-05-01 16:42:33 +02:00
|
|
|
void setAction( QAction *action );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
/** Return associated action with map tool or NULL if no action is associated */
|
2017-05-01 16:42:33 +02:00
|
|
|
QAction *action();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
/** Use this to associate a button to this maptool. It has the same meaning
|
|
|
|
* as setAction() function except it works with a button instead of an QAction. */
|
2017-05-01 16:42:33 +02:00
|
|
|
void setButton( QAbstractButton *button );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
/** Return associated button with map tool or NULL if no button is associated */
|
2017-05-01 16:42:33 +02:00
|
|
|
QAbstractButton *button();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2013-06-28 09:56:56 +02:00
|
|
|
/** Set a user defined cursor */
|
2017-05-01 16:42:33 +02:00
|
|
|
virtual void setCursor( const QCursor &cursor );
|
2013-06-28 09:56:56 +02:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! called when set as currently active map tool
|
|
|
|
virtual void activate();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! called when map tool is being deactivated
|
|
|
|
virtual void deactivate();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2008-11-25 21:37:38 +00:00
|
|
|
//! returns pointer to the tool's map canvas
|
2017-05-01 16:42:33 +02:00
|
|
|
QgsMapCanvas *canvas();
|
2014-05-02 10:32:37 +02:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
//! Emit map tool changed with the old tool
|
|
|
|
//! @note added in 2.3
|
2014-01-29 16:35:20 +01:00
|
|
|
QString toolName();
|
2014-03-19 08:16:33 +01:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/** Get search radius in mm. Used by identify, tip etc.
|
|
|
|
* The values is currently set in identify tool options (move somewhere else?)
|
2016-07-21 22:01:38 +10:00
|
|
|
* and defaults to Qgis::DEFAULT_SEARCH_RADIUS_MM.
|
2014-05-27 23:22:50 +02:00
|
|
|
* @note added in 2.3 */
|
2014-03-27 13:45:25 +01:00
|
|
|
static double searchRadiusMM();
|
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/** Get search radius in map units for given context. Used by identify, tip etc.
|
|
|
|
* The values is calculated from searchRadiusMM().
|
|
|
|
* @note added in 2.3 */
|
2017-05-01 16:42:33 +02:00
|
|
|
static double searchRadiusMU( const QgsRenderContext &context );
|
2014-03-27 13:45:25 +01:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/** Get search radius in map units for given canvas. Used by identify, tip etc.
|
|
|
|
* The values is calculated from searchRadiusMM().
|
|
|
|
* @note added in 2.3 */
|
2017-05-03 07:45:22 +02:00
|
|
|
static double searchRadiusMU( QgsMapCanvas *canvas );
|
2014-03-27 13:45:25 +01:00
|
|
|
|
2014-03-19 08:16:33 +01:00
|
|
|
signals:
|
|
|
|
//! emit a message
|
2017-05-01 16:42:33 +02:00
|
|
|
void messageEmitted( const QString &message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
|
2014-03-19 08:16:33 +01:00
|
|
|
|
|
|
|
//! emit signal to clear previous message
|
2014-03-21 07:08:56 +01:00
|
|
|
void messageDiscarded();
|
2014-09-11 10:41:02 +02:00
|
|
|
|
|
|
|
//! signal emitted once the map tool is activated
|
|
|
|
void activated();
|
|
|
|
|
|
|
|
//! signal emitted once the map tool is deactivated
|
|
|
|
void deactivated();
|
2008-11-25 21:37:38 +00:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
//! constructor takes map canvas as a parameter
|
2017-05-01 16:42:33 +02:00
|
|
|
QgsMapTool( QgsMapCanvas *canvas /TransferThis/ );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! transformation from screen coordinates to map coordinates
|
2017-06-01 12:18:43 +02:00
|
|
|
QgsPointXY toMapCoordinates( QPoint point );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! transformation from screen coordinates to layer's coordinates
|
2017-06-01 12:18:43 +02:00
|
|
|
QgsPointXY toLayerCoordinates( const QgsMapLayer *layer, QPoint point );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! transformation from map coordinates to layer's coordinates
|
2017-06-01 12:18:43 +02:00
|
|
|
QgsPointXY toLayerCoordinates( const QgsMapLayer *layer, const QgsPointXY &point );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2008-11-25 21:37:38 +00:00
|
|
|
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
|
2017-06-01 12:18:43 +02:00
|
|
|
QgsPointXY toMapCoordinates( const QgsMapLayer *layer, const QgsPointXY &point );
|
2008-11-25 21:37:38 +00:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
|
|
|
|
//! @note available in python bindings as toMapCoordinatesV2
|
2017-06-01 12:18:43 +02:00
|
|
|
QgsPoint toMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) /PyName=toMapCoordinatesV2/;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! trnasformation of the rect from map coordinates to layer's coordinates
|
2017-05-01 16:42:33 +02:00
|
|
|
QgsRectangle toLayerCoordinates( const QgsMapLayer *layer, const QgsRectangle &rect );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! transformation from map coordinates to screen coordinates
|
2017-06-01 12:18:43 +02:00
|
|
|
QPoint toCanvasCoordinates( const QgsPointXY &point );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2013-01-12 23:48:58 +01:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
};
|
2016-05-30 06:19:34 +10:00
|
|
|
|
|
|
|
|
|
|
|
QFlags<QgsMapTool::Flag> operator|(QgsMapTool::Flag f1, QFlags<QgsMapTool::Flag> f2);
|