SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
maptool.h
Go to the documentation of this file.
1
9#ifndef MAPTOOL_H
10#define MAPTOOL_H
11
12#include <QObject>
13#include <QCursor>
14#include <QString>
15
16class QMouseEvent;
17class QWheelEvent;
18class QKeyEvent;
19class QPainter;
20class QGraphicsScene;
21class MapCanvas;
22class MapExtent;
24
42class OpenSWMMVisMapTool : public QObject
43{
44 Q_OBJECT
45 Q_PROPERTY(QString toolName READ toolName CONSTANT)
46 Q_PROPERTY(QCursor cursor READ cursor NOTIFY cursorChanged)
47 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
48
49public:
50
51 explicit OpenSWMMVisMapTool(const QString &toolName,
53 QObject *parent = nullptr);
54
55 virtual ~OpenSWMMVisMapTool() = default;
56
57 // ----- Identity -------------------------------------------------------
58
62 [[nodiscard]] QString toolName() const;
63
67 [[nodiscard]] virtual QCursor cursor() const;
68
72 [[nodiscard]] bool isActive() const;
73
74 // ----- Canvas access --------------------------------------------------
75
79 [[nodiscard]] MapCanvas *canvas() const;
80
81 // ----- Lifecycle hooks ------------------------------------------------
82
86 virtual void activate();
87
91 virtual void deactivate();
92
93 // ----- Event handlers (override in subclasses) ------------------------
94
95 virtual void mousePressEvent(QMouseEvent *event);
96 virtual void mouseMoveEvent(QMouseEvent *event);
97 virtual void mouseReleaseEvent(QMouseEvent *event);
98 virtual void mouseDoubleClickEvent(QMouseEvent *event);
99 virtual void wheelEvent(QWheelEvent *event);
100 virtual void keyPressEvent(QKeyEvent *event);
101 virtual void keyReleaseEvent(QKeyEvent *event);
102
103 // ----- Painting (via scene items) --------------------------------------
104
111 virtual void paint(QPainter *painter,
112 const MapExtent &canvasExtent,
113 const SpatialReferenceSystem *canvasSRS);
114
118 [[nodiscard]] QGraphicsScene *scene() const;
119
120 // ----- Helpers provided to subclasses --------------------------------
121
129 void toMapCoords(int px, int py, double &mapX, double &mapY) const;
130
134 void toPixelCoords(double mapX, double mapY, int &px, int &py) const;
135
136signals:
137 void cursorChanged(const QCursor &cursor);
139
144
145protected:
146 QString m_toolName;
147 MapCanvas *m_canvas = nullptr;
148
149private:
150 bool m_active = false;
151
152 friend class MapCanvas;
153 void setActive(bool active);
154};
155
156#endif // MAPTOOL_H
The central map display widget — QGIS-style hybrid rendering.
Definition mapcanvas.h:63
An axis-aligned bounding box in the coordinate space of a given CRS.
Definition mapextent.h:26
Abstract base class for interactive map tools used in the MapCanvas.
Definition maptool.h:43
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition maptool.cpp:45
virtual void paint(QPainter *painter, const MapExtent &canvasExtent, const SpatialReferenceSystem *canvasSRS)
Called by the canvas in drawForeground() so the tool can draw transient overlay graphics (rubber-band...
Definition maptool.cpp:51
void repaintRequested()
Emitted to instruct the canvas to repaint its overlay.
void toMapCoords(int px, int py, double &mapX, double &mapY) const
Converts a widget pixel position to map coordinates.
Definition maptool.cpp:58
virtual void deactivate()
Called by the canvas when another tool replaces this one.
Definition maptool.cpp:32
QCursor cursor
Definition maptool.h:46
QGraphicsScene * scene() const
Returns the scene this tool's canvas is using.
Definition maptool.cpp:70
void toPixelCoords(double mapX, double mapY, int &px, int &py) const
Converts map coordinates to widget pixel position.
Definition maptool.cpp:64
MapCanvas * canvas() const
Returns the MapCanvas this tool is attached to.
Definition maptool.cpp:29
virtual void mousePressEvent(QMouseEvent *event)
Definition maptool.cpp:43
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition maptool.cpp:46
virtual void keyReleaseEvent(QKeyEvent *event)
Definition maptool.cpp:49
virtual void activate()
Called by the canvas when this tool becomes the active tool.
Definition maptool.cpp:31
virtual void wheelEvent(QWheelEvent *event)
Definition maptool.cpp:47
bool isActive() const
Returns true when this tool is the active tool on its canvas.
Definition maptool.cpp:28
MapCanvas * m_canvas
Definition maptool.h:147
QString toolName
Definition maptool.h:45
QString m_toolName
Definition maptool.h:146
bool active
Definition maptool.h:47
void cursorChanged(const QCursor &cursor)
void activeChanged(bool active)
virtual void mouseMoveEvent(QMouseEvent *event)
Definition maptool.cpp:44
virtual void keyPressEvent(QKeyEvent *event)
Definition maptool.cpp:48
Represents a coordinate reference system backed by a GDAL OGRSpatialReference.
Definition spatialreferencesystem.h:28
QVector< int > parent
union-find
Definition pslgminsize.cpp:176