|
| 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 : denis.rouzaud@gmail.com |
| 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 | +/** |
| 17 | + * A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas. |
| 18 | + * It is sent whenever the user moves, clicks, releases or double clicks the mouse. |
| 19 | + * In addition to the coordiantes in pixel space it also knows the coordinates in the mapcanvas' CRS |
| 20 | + * as well as it knows the concept of snapping. |
| 21 | + */ |
| 22 | +class QgsMapMouseEvent : QMouseEvent |
| 23 | +{ |
| 24 | +%TypeHeaderCode |
| 25 | +#include "qgsmapmouseevent.h" |
| 26 | +%End |
| 27 | + public: |
| 28 | + |
| 29 | + enum SnappingMode |
| 30 | + { |
| 31 | + NoSnapping, |
| 32 | + SnapProjectConfig, //!< snap according to the configuration set in the snapping settings |
| 33 | + SnapAllLayers, //!< snap to all rendered layers (tolerance and type from defaultSettings()) |
| 34 | + }; |
| 35 | + |
| 36 | + /** |
| 37 | + * Creates a new QgsMapMouseEvent. Should only be required to be called from the QgsMapCanvas. |
| 38 | + * |
| 39 | + * @param mapCanvas The map canvas on which the event occured |
| 40 | + * @param event The original mouse event |
| 41 | + */ |
| 42 | + QgsMapMouseEvent( QgsMapCanvas* mapCanvas, QMouseEvent* event ); |
| 43 | + |
| 44 | + /** |
| 45 | + * @brief snapPoint will snap the points using the map canvas snapping utils configuration |
| 46 | + * @note if snapping did not succeeded, the map point will be reset to its original position |
| 47 | + */ |
| 48 | + QgsPoint snapPoint( SnappingMode snappingMode ); |
| 49 | + |
| 50 | + /** |
| 51 | + * returns the first snapped segment. If the cached snapped match is a segment, it will simply return it. |
| 52 | + * Otherwise it will try to snap a segment according to the event's snapping mode. In this case the cache |
| 53 | + * will not be overwritten. |
| 54 | + * @param snapped if given, determines if a segment has been snapped |
| 55 | + * @param allLayers if true, override snapping mode |
| 56 | + */ |
| 57 | + QList<QgsPoint> snapSegment( SnappingMode snappingMode, bool* snapped = 0, bool allLayers = false ) const; |
| 58 | + |
| 59 | + /** |
| 60 | + * Returns true if there is a snapped point cached. |
| 61 | + * Will only be useful after snapPoint has previously been called. |
| 62 | + * |
| 63 | + * @return True if there is a snapped point cached. |
| 64 | + */ |
| 65 | + bool isSnapped() const; |
| 66 | + |
| 67 | + /** |
| 68 | + * @brief mapPoint returns the point in coordinates |
| 69 | + * @return the point in map coordinates, after snapping if requested in the event. |
| 70 | + */ |
| 71 | + QgsPoint mapPoint() const; |
| 72 | + |
| 73 | + QgsPoint originalMapPoint() const; |
| 74 | + |
| 75 | + QPoint pixelPoint() const; |
| 76 | + |
| 77 | + QPoint originalPixelPoint() const; |
| 78 | +}; |
0 commit comments