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
maptoolselect.h
Go to the documentation of this file.
1
9#ifndef MAPTOOLSELECT_H
10#define MAPTOOLSELECT_H
11
12#include "map/tools/maptool.h"
13#include "plot/plotattribute.h"
16
17#include <QPoint>
18#include <QPointF>
19#include <QRect>
20#include <QSet>
21#include <QVector>
22
24class SWMMModelLayer;
25class FeatureLayer;
26
41{
42 Q_OBJECT
43
48
49public:
50
51 explicit OpenSWMMVisMapToolSelect(MapCanvas *canvas, QObject *parent = nullptr);
52
53 [[nodiscard]] QCursor cursor() const override;
54
55 // ----- Configuration -------------------------------------------------
56
57 [[nodiscard]] int pixelTolerance() const;
58 void setPixelTolerance(int pixels);
59
60 [[nodiscard]] QColor rubberBandColor() const;
61 void setRubberBandColor(const QColor &color);
62
63 // ----- Tool interface ------------------------------------------------
64
65 void activate() override;
66 void deactivate() override;
67
68 void mousePressEvent(QMouseEvent *event) override;
69 void mouseMoveEvent(QMouseEvent *event) override;
70 void mouseReleaseEvent(QMouseEvent *event) override;
71 void mouseDoubleClickEvent(QMouseEvent *event) override;
72 void keyPressEvent(QKeyEvent *event) override;
73
74 void paint(QPainter *painter,
75 const MapExtent &canvasExtent,
76 const SpatialReferenceSystem *canvasSRS) override;
77
78signals:
79 void pixelToleranceChanged(int pixels);
80 void rubberBandColorChanged(const QColor &color);
81
86
94
99 const openswmmvis::plot::ResultDescriptor &descriptor);
100
107 const openswmmvis::plot::ResultDescriptor &descriptor,
108 class SWMMResultsLayer *layer);
109
113 void plotSystemRequested(openswmmvis::plot::PlotAttribute attribute);
114
121
127
128private:
129 void selectAtPoint(const QPoint &pixel, Qt::KeyboardModifiers mods);
130 void selectInRect(const QRect &pixelRect, Qt::KeyboardModifiers mods);
131
133 void showContextMenu(const QPoint &pixel);
134
137 void deleteSelectedObjects();
138
139 // ----- Inline edit sub-mode -------------------------------------------
140 // Activated by double-clicking a node or link. Vertex handles appear in
141 // the overlay and can be dragged without switching tools. Escape or
142 // double-clicking empty space exits back to normal selection behaviour.
143
144 // Gage rides the Node code path (one whole-object handle, drag =
145 // move) but previews/commits through the rain-gage move APIs.
146 enum class EditKind { None, Node, Gage, Link, Subcatch };
147
149 void enterEditMode(SWMMModelLayer *layer, const QString &name,
150 EditKind kind, int soaIndex);
152 void clearEditMode();
154 int hitTestEditHandle(const QPoint &pixel) const;
156 void selectHandlesInRect(const QRect &pixelRect);
158 void applyGroupDragDelta(double dx, double dy);
160 void commitNodeDrag(double newX, double newY);
162 void commitGageDrag(double newX, double newY);
164 void commitLinkDrag(QVector<QPointF> newInterior);
166 void commitSubcatchDrag(QVector<QPointF> newVertices);
167
172 void deleteSelectedEditHandles();
173
174 EditKind m_editKind = EditKind::None;
175 SWMMModelLayer *m_editLayer = nullptr;
176 QString m_editName;
177 int m_editSoaIdx = -1;
178 // Handle layout per EditKind:
179 // Node: [0] = node position (circle+crosshair, translates node)
180 // Link: [0..N-1] = interior vertices (squares)
181 // Subcatch:[0] = centroid (filled square, translates all vertices)
182 // [1..N] = polygon vertices (circles)
183 QVector<QPointF> m_editHandles;
184 QVector<QPointF> m_editSubcatchVerts; // cached polygon vertices (Subcatch mode)
185 bool m_editDragging = false;
186 int m_editDragHandle = -1;
187 QPointF m_editDragOrigPt; // pre-drag map position of dragged vertex (for snap exclusion)
188 QPointF m_editCentroidPrev; // centroid before current drag tick (Subcatch)
189 QPointF m_editGroupDragPrev; // map pos of previous move tick (group drag)
190 double m_editNodeOrigX = 0.0;
191 double m_editNodeOrigY = 0.0;
192
193 // Rubber-band vertex selection within edit mode
194 QSet<int> m_editSelectedHandles;
195 bool m_editRubberbanding = false;
196 bool m_editPressedEmpty = false; // pressed on empty, not yet a drag
197 QPoint m_editRubberStart;
198 QPoint m_editRubberCurrent;
199
200 static constexpr int kEditHandlePx = 7; // half-size of a vertex handle in pixels
201 static constexpr int kSnapRadiusPx = 15; // pixel radius within which snap kicks in
202
203 // Snap state — updated each drag tick, consumed by paint()
204 bool m_snapping = false;
205 QPointF m_snapPt; // snapped position in map/layer CRS
206
207 // ----- Normal selection state -----------------------------------------
208
209 bool m_dragging = false;
210 QPoint m_startPixel;
211 QPoint m_currentPixel;
212 // Default user-preference tolerance. The EFFECTIVE pixel radius
213 // used at pick time is `max(m_pixelTol, largest-rendered-marker-
214 // half-bounds + halo)`, so clicks inside the visible glyph always
215 // succeed regardless of this number. See
216 // `selectAtPoint` in the .cpp — it pulls the marker floor from
217 // the layer's symbology. Slice V will turn this into a
218 // user-configurable preference.
219 int m_pixelTol = 16;
220 // Drag threshold — only start the rubber-band once the cursor
221 // moves this many pixels from the press point. Trackpad micro-
222 // jitter on a click commonly hits 10–12 px, which used to flip
223 // the tool into rubber-band mode and select a node + its
224 // connected line together. 15 leaves enough slack to kill that
225 // while still responding to intentional drags. Override via
226 // PreferencesManager.
227 int m_dragThreshPx = 15;
228 QColor m_rubberColor = QColor(0, 120, 255, 80);
229};
230
231#endif // MAPTOOLSELECT_H
An editable, GeoPackage-backed vector layer.
Definition featurelayer.h:127
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 all layers displayed in the MapCanvas.
Definition openswmmvislayer.h:116
Abstract base class for interactive map tools used in the MapCanvas.
Definition maptool.h:43
MapCanvas * canvas() const
Returns the MapCanvas this tool is attached to.
Definition maptool.cpp:29
Tool that selects features in vector and SWMM model layers.
Definition maptoolselect.h:41
void deleteFeaturesRequested(FeatureLayer *layer)
The user chose "Delete selected feature(s)" from the background right-click menu, offered only while ...
void rainfallVisualizationRequested(const SWMMObjectRef &ref)
Emitted from the right-click menu's "Rainfall Visualization…" action on a rain gage hit....
void selectionChanged(OpenSWMMVisLayer *layer)
Emitted after the selection changes, carrying the names/IDs of selected elements.
void mouseDoubleClickEvent(QMouseEvent *event) override
Definition maptoolselect.cpp:1782
QCursor cursor() const override
Returns the mouse cursor to display while this tool is active.
Definition maptoolselect.cpp:120
void paint(QPainter *painter, const MapExtent &canvasExtent, const SpatialReferenceSystem *canvasSRS) override
Called by the canvas in drawForeground() so the tool can draw transient overlay graphics (rubber-band...
Definition maptoolselect.cpp:997
void pixelToleranceChanged(int pixels)
void deactivate() override
Called by the canvas when another tool replaces this one.
Definition maptoolselect.cpp:153
void mouseReleaseEvent(QMouseEvent *event) override
Definition maptoolselect.cpp:566
void mouseMoveEvent(QMouseEvent *event) override
Definition maptoolselect.cpp:419
void activate() override
Called by the canvas when this tool becomes the active tool.
Definition maptoolselect.cpp:147
void keyPressEvent(QKeyEvent *event) override
Definition maptoolselect.cpp:630
void rubberBandColorChanged(const QColor &color)
void plotAttributeForLayerRequested(const SWMMObjectRef &ref, const openswmmvis::plot::ResultDescriptor &descriptor, class SWMMResultsLayer *layer)
Variant of plotAttributeRequested that names a specific results layer. Emitted from the two-level "Pl...
void mousePressEvent(QMouseEvent *event) override
Definition maptoolselect.cpp:160
QColor rubberBandColor
Definition maptoolselect.h:47
int pixelTolerance
Definition maptoolselect.h:45
void setPixelTolerance(int pixels)
Definition maptoolselect.cpp:127
void setRubberBandColor(const QColor &color)
Definition maptoolselect.cpp:138
void plotAttributeRequested(const SWMMObjectRef &ref, const openswmmvis::plot::ResultDescriptor &descriptor)
Slice AT.2 — emitted when the user picks a specific attribute from the right-click attribute submenu ...
void plotTimeSeriesRequested(const SWMMObjectRef &ref)
Emitted from the right-click context menu's "Plot Time Series…" action. Handled at the main-window le...
void plotSystemRequested(openswmmvis::plot::PlotAttribute attribute)
Slice AT.2 — emitted when the user picks a system-wide variable from the background right-click menu ...
Renders the SWMM network elements (nodes, links, subcatchments, rain gages) for one OpenSWMMEngine mo...
Definition swmmmodellayer.h:133
Overlays time-stepped simulation results on the SWMM network geometry.
Definition swmmresultslayer.h:96
Represents a coordinate reference system backed by a GDAL OGRSpatialReference.
Definition spatialreferencesystem.h:28
Abstract base class for all interactive tools attached to a MapCanvas.
std::vector< float > dx
Definition mesh2dresultsexport.cpp:611
std::vector< float > dy
Green–Gauss only, parallel to cell
Definition mesh2dresultsexport.cpp:611
Definition aquiferprovider.h:21
Slice BL — canonical enumeration of plottable result attributes.
EdgeRef ref
Definition pslgminsize.cpp:377
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
TokenKind kind
Definition queryparser.cpp:34
Y2b-1 (amendment D-Y4) — one plottable result, fixed or species.
QString name
Definition sectionmodelbuilders.cpp:474
Identifies a single SWMM object.
Definition selectionmanager.h:32