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
selectionmanager.h
Go to the documentation of this file.
1
16#ifndef SELECTIONMANAGER_H
17#define SELECTIONMANAGER_H
18
19#include <QHash>
20#include <QObject>
21#include <QSet>
22#include <QString>
23
32{
39 enum ObjectType : int {
41 Node = 1,
42 Link = 2,
48 // Non-spatial data objects (Slice BM.0). Values appended at end so
49 // existing serialisation / sidecar `.oswp` files keep working.
50 Curve = 8,
54 Aquifer = 12,
58 Street = 16,
59 Inlet = 17,
60 // 2D mesh elements (Slice §V.VA — Mesh Editing Toolbar). The
61 // `name` field encodes mesh-layer persistent id + element index
62 // (see `MeshObjectRef::vertex` / `::edge` on `SWMM2DMeshLayer`),
63 // so multiple meshes on one canvas can co-exist in selection
64 // without collision.
67 MeshCell = 20,
68 // GIS vector feature layers (SVBC round B). The `name` field encodes
69 // "gis::<layerId>#f<fid>" (see `GisObjectRef::feature`), so features
70 // from several imported layers co-exist on the bus without
71 // collision, keyed by the layer's stable id.
72 Feature = 21,
73 };
74
76 QString name;
77
78 constexpr SWMMObjectRef() = default;
80 : objectType(t), name(std::move(n)) {}
81
82 bool isValid() const { return objectType != Unknown && !name.isEmpty(); }
83
84 bool operator==(const SWMMObjectRef &o) const
85 { return objectType == o.objectType && name == o.name; }
86 bool operator!=(const SWMMObjectRef &o) const { return !(*this == o); }
87};
88
89inline size_t qHash(const SWMMObjectRef &r, size_t seed = 0)
90{
91 return qHash(r.name, seed) ^ static_cast<size_t>(r.objectType);
92}
93
94Q_DECLARE_METATYPE(SWMMObjectRef)
95
96
111class SelectionManager : public QObject
112{
113 Q_OBJECT
114
115public:
116 enum Mode {
117 Replace = 0,
118 Add = 1,
119 Toggle = 2,
120 Subtract = 3,
121 };
122
123 explicit SelectionManager(QObject *parent = nullptr);
125
127 void select(const QSet<SWMMObjectRef> &refs, Mode mode = Replace);
128
130 void select(const SWMMObjectRef &ref, Mode mode = Replace);
131
133 void clear();
134
136 [[nodiscard]] const QSet<SWMMObjectRef> &selection() const { return m_selection; }
137
139 [[nodiscard]] bool contains(const SWMMObjectRef &ref) const
140 { return m_selection.contains(ref); }
141
142 [[nodiscard]] int size() const { return m_selection.size(); }
143 [[nodiscard]] bool isEmpty() const { return m_selection.isEmpty(); }
144
145signals:
148 void selectionChanged(const QSet<SWMMObjectRef> &current,
149 const QSet<SWMMObjectRef> &added,
150 const QSet<SWMMObjectRef> &removed);
151
152private:
153 void applyChange(const QSet<SWMMObjectRef> &next);
154
155 QSet<SWMMObjectRef> m_selection;
156};
157
158#endif // SELECTIONMANAGER_H
Owner of the canonical selection set for one SWMM project.
Definition selectionmanager.h:112
bool contains(const SWMMObjectRef &ref) const
True if ref is in the current selection.
Definition selectionmanager.h:139
bool isEmpty() const
Definition selectionmanager.h:143
Mode
Definition selectionmanager.h:116
int size() const
Definition selectionmanager.h:142
const QSet< SWMMObjectRef > & selection() const
Read-only view of the current selection.
Definition selectionmanager.h:136
void selectionChanged(const QSet< SWMMObjectRef > &current, const QSet< SWMMObjectRef > &added, const QSet< SWMMObjectRef > &removed)
Emitted on every set change. added / removed are disjoint and convey the delta from the previous sele...
~SelectionManager() override
DiagramType t
Definition diagramspec.cpp:20
std::size_t n
Definition mesh2dresultsexport.cpp:426
QuadRegionMode mode
Resolved mode.
Definition meshgenerator.cpp:154
EdgeRef ref
Definition pslgminsize.cpp:377
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
size_t qHash(const SWMMObjectRef &r, size_t seed=0)
Definition selectionmanager.h:89
Identifies a single SWMM object.
Definition selectionmanager.h:32
ObjectType
Coarse object kind. Mirrors the engine's logical groupings; finer subtypes (e.g. junction vs outfall)...
Definition selectionmanager.h:39
@ Aquifer
Definition selectionmanager.h:54
@ Inlet
Definition selectionmanager.h:59
@ Hydrograph
Definition selectionmanager.h:57
@ MeshCell
2D mesh triangle/cell (see MeshObjectRef::cell)
Definition selectionmanager.h:67
@ RainGage
Definition selectionmanager.h:44
@ Control
Definition selectionmanager.h:47
@ Subcatchment
Definition selectionmanager.h:43
@ Street
Definition selectionmanager.h:58
@ Transect
Definition selectionmanager.h:56
@ Unknown
Definition selectionmanager.h:40
@ Node
Junction / outfall / divider / storage.
Definition selectionmanager.h:41
@ Curve
Definition selectionmanager.h:50
@ Feature
Definition selectionmanager.h:72
@ LandUse
Definition selectionmanager.h:46
@ TimePattern
Definition selectionmanager.h:52
@ Pollutant
Definition selectionmanager.h:45
@ TimeSeries
Definition selectionmanager.h:51
@ Snowpack
Definition selectionmanager.h:55
@ MeshEdge
Definition selectionmanager.h:66
@ Link
Conduit / pump / orifice / weir / outlet.
Definition selectionmanager.h:42
@ MeshVertex
Definition selectionmanager.h:65
@ LIDControl
Definition selectionmanager.h:53
QString name
Definition selectionmanager.h:76
ObjectType objectType
Definition selectionmanager.h:75
constexpr SWMMObjectRef()=default
bool operator!=(const SWMMObjectRef &o) const
Definition selectionmanager.h:86
bool operator==(const SWMMObjectRef &o) const
Definition selectionmanager.h:84
bool isValid() const
Definition selectionmanager.h:82
SWMMObjectRef(ObjectType t, QString n)
Definition selectionmanager.h:79