QGIS/python/gui/qgsmaptool.sip

170 lines
6.3 KiB
Plaintext
Raw Normal View History

%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>
#include <qgsmaptoolidentify.h>
%End
class QgsMapTool : QObject
{
%TypeHeaderCode
#include <qgsmaptool.h>
%End
%ConvertToSubClassCode
if (dynamic_cast<QgsMapToolZoom*>(sipCpp) != NULL)
sipType = sipType_QgsMapToolZoom;
else if (dynamic_cast<QgsMapToolPan*>(sipCpp) != NULL)
sipType = sipType_QgsMapToolPan;
else if (dynamic_cast<QgsMapToolEmitPoint*>(sipCpp) != NULL)
sipType = sipType_QgsMapToolEmitPoint;
else if (dynamic_cast<QgsMapToolIdentify*>(sipCpp) != NULL)
sipType = sipType_QgsMapToolIdentify;
else
sipType = NULL;
%End
public:
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*/
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;
//! virtual destructor
virtual ~QgsMapTool();
//! Mouse move event for overriding. Default implementation does nothing.
virtual void canvasMoveEvent( QgsMapMouseEvent *e );
//! Mouse double click event for overriding. Default implementation does nothing.
virtual void canvasDoubleClickEvent( QgsMapMouseEvent *e );
//! Mouse press event for overriding. Default implementation does nothing.
virtual void canvasPressEvent( QgsMapMouseEvent *e );
//! Mouse release event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent( QgsMapMouseEvent *e );
//! Mouse wheel event for overriding. Default implementation does nothing.
virtual void wheelEvent( QWheelEvent *e );
//! Key event for overriding. Default implementation does nothing.
virtual void keyPressEvent( QKeyEvent *e );
//! Key event for overriding. Default implementation does nothing.
virtual void keyReleaseEvent( QKeyEvent *e );
//! gesture event for overriding. Default implementation does nothing.
virtual bool gestureEvent( QGestureEvent *e );
/** Use this to associate a QAction to this maptool. Then when the setMapTool
* 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. */
void setAction( QAction *action );
/** Return associated action with map tool or NULL if no action is associated */
QAction *action();
/** 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. */
void setButton( QAbstractButton *button );
/** Return associated button with map tool or NULL if no button is associated */
QAbstractButton *button();
2013-06-28 09:56:56 +02:00
/** Set a user defined cursor */
virtual void setCursor( const QCursor &cursor );
2013-06-28 09:56:56 +02:00
//! called when set as currently active map tool
virtual void activate();
//! called when map tool is being deactivated
virtual void deactivate();
//! returns pointer to the tool's map canvas
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
QString toolName();
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?)
* 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 */
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 */
static double searchRadiusMU( QgsMapCanvas *canvas );
2014-03-27 13:45:25 +01:00
signals:
//! emit a message
void messageEmitted( const QString &message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
//! 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();
protected:
//! constructor takes map canvas as a parameter
QgsMapTool( QgsMapCanvas *canvas /TransferThis/ );
//! transformation from screen coordinates to map coordinates
QgsPoint toMapCoordinates( QPoint point );
//! transformation from screen coordinates to layer's coordinates
QgsPoint toLayerCoordinates( const QgsMapLayer *layer, QPoint point );
//! transformation from map coordinates to layer's coordinates
QgsPoint toLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point );
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
QgsPoint toMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point );
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
QgsPointV2 toMapCoordinates( const QgsMapLayer *layer, const QgsPointV2 &point ) /PyName=toMapCoordinatesV2/;
2016-02-14 03:50:23 +01:00
//! trnasformation of the rect from map coordinates to layer's coordinates
QgsRectangle toLayerCoordinates( const QgsMapLayer *layer, const QgsRectangle &rect );
//! transformation from map coordinates to screen coordinates
QPoint toCanvasCoordinates( const QgsPoint &point );
};
QFlags<QgsMapTool::Flag> operator|(QgsMapTool::Flag f1, QFlags<QgsMapTool::Flag> f2);