QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsmapmouseevent.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapmouseevent.h - mouse event in map coordinates and ability to snap
3  ----------------------
4  begin : October 2014
5  copyright : (C) Denis Rouzaud
6  email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPMOUSEEVENT_H
17 #define QGSMAPMOUSEEVENT_H
18 
19 #include <QMouseEvent>
20 
21 #include "qgspoint.h"
22 #include "qgspointlocator.h"
23 #include "qgssnappingutils.h"
24 
25 class QgsMapCanvas;
27 
34 class GUI_EXPORT QgsMapMouseEvent : public QMouseEvent
35 {
36  public:
37 
39  {
43  };
44 
51  QgsMapMouseEvent( QgsMapCanvas* mapCanvas, QMouseEvent* event );
52 
63  QgsMapMouseEvent( QgsMapCanvas* mapCanvas, QEvent::Type type, QPoint pos, Qt::MouseButton button = Qt::NoButton,
64  Qt::MouseButtons buttons = Qt::NoButton, Qt::KeyboardModifiers modifiers = Qt::NoModifier );
65 
70  QgsPoint snapPoint( SnappingMode snappingMode );
71 
80  QList<QgsPoint> snapSegment( SnappingMode snappingMode, bool* snapped = nullptr, bool allLayers = false ) const;
81 
88  bool isSnapped() const { return mSnapMatch.isValid(); }
89 
94  inline QgsPoint mapPoint() const { return mMapPoint; }
95 
101  QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
102 
109  void setMapPoint( const QgsPoint& point );
110 
116  QgsPoint originalMapPoint() const { return mMapPoint; }
117 
123  QPoint pixelPoint() const { return mPixelPoint; }
124 
131  QPoint originalPixelPoint() const { return pos(); }
132 
133  private:
134 
135  QPoint mapToPixelCoordinates( const QgsPoint& point );
136 
137  SnappingMode mSnappingMode;
138 
140  QgsPoint mOriginalMapPoint;
141 
143  QgsPoint mMapPoint;
144 
147  QPoint mPixelPoint;
148 
150  QgsMapCanvas* mMapCanvas;
151 
152  QgsPointLocator::Match mSnapMatch;
153 };
154 
155 #endif // QGSMAPMOUSEEVENT_H
snap to all rendered layers (tolerance and type from defaultSettings())
QgsPoint mapPoint() const
mapPoint returns the point in coordinates
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
bool isSnapped() const
Returns true if there is a snapped point cached.
The QgsMapToolAdvancedDigitizing class is a QgsMapTool whcih gives event directly in map coordinates ...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
snap according to the configuration set in the snapping settings
A class to represent a point.
Definition: qgspoint.h:117
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
typedef MouseButtons
QPoint originalPixelPoint() const
The unsnapped, real mouse cursor position in pixel coordinates.
QgsPoint originalMapPoint() const
Returns the original, unmodified map point of the mouse cursor.
const QPoint & pos() const
QPoint pixelPoint() const
The snapped mouse cursor in pixel coordinates.
typedef KeyboardModifiers