1 /*************************************************************************** 2 qgsmodelviewmouseevent.h 3 ------------------------- 4 Date : March 2020 5 Copyright : (C) 2020 Nyall Dawson 6 Email : nyall dot dawson at gmail dot 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 #ifndef QGSMODELVIEWMOUSEEVENT_H 17 #define QGSMODELVIEWMOUSEEVENT_H 18 19 #include <QMouseEvent> 20 21 #include "qgis_gui.h" 22 23 #define SIP_NO_FILE 24 25 class QgsModelGraphicsView; 26 27 /** 28 * \ingroup gui 29 * \brief A QgsModelViewMouseEvent is the result of a user interaction with the mouse on a QgsModelGraphicsView. 30 * 31 * It is sent whenever the user moves, clicks, releases or double clicks the mouse. 32 * In addition to the coordinates in pixel space it also knows the coordinates the model space. 33 * 34 * \since QGIS 3.14 35 */ 36 class GUI_EXPORT QgsModelViewMouseEvent : public QMouseEvent 37 { 38 39 public: 40 41 /** 42 * Constructor for QgsModelViewMouseEvent. Should only be required to be called from the QgsModelGraphicsView. 43 * \param view The view in which the event occurred. 44 * \param event The original mouse event 45 * \param snaps set to TRUE if the event should be snapped 46 */ 47 QgsModelViewMouseEvent( QgsModelGraphicsView *view, QMouseEvent *event, bool snaps ); 48 49 /** 50 * Manually triggers a snap for the mouse event position using the model's snapper. 51 */ 52 void snapPoint(); 53 54 /** 55 * Returns the event point location in model coordinates. 56 */ 57 QPointF modelPoint() const; 58 59 /** 60 * Returns the snapped event point location in model coordinates. The snapped point will consider 61 * all possible snapping methods, such as snapping to grid. 62 * \see isSnapped() 63 */ snappedPoint()64 QPointF snappedPoint() const { return mSnappedPoint; } 65 66 /** 67 * Returns TRUE if point was snapped, e.g. to grid. 68 * \see snappedPoint() 69 */ isSnapped()70 bool isSnapped() const { return mSnapped; } 71 72 73 private: 74 75 //! The view in which the event was triggered. 76 QgsModelGraphicsView *mView = nullptr; 77 78 QPointF mModelPoint; 79 bool mSnapped = false; 80 QPointF mSnappedPoint; 81 }; 82 83 #endif // QGSMODELVIEWMOUSEEVENT_H 84