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
curveprovider.h
Go to the documentation of this file.
1
24#ifndef OPENSWMMVIS_CURVE_CURVEPROVIDER_H
25#define OPENSWMMVIS_CURVE_CURVEPROVIDER_H
26
27#include <QObject>
28#include <QString>
29#include <QVector>
30
32
35enum class CurveType {
36 Storage = 1,
37 Diversion = 2,
38 Rating = 3,
39 Shape = 4,
40 Control = 5,
41 Tidal = 6,
42 Pump1 = 7,
43 Pump2 = 8,
44 Pump3 = 9,
45 Pump4 = 10,
46 Pump5 = 11,
47};
48
50struct CurvePoint {
51 double x = 0.0;
52 double y = 0.0;
53};
54
55class CurveProvider : public QObject
56{
57 Q_OBJECT
58
59public:
60 CurveProvider(QString name, CurveType type, QObject *parent = nullptr);
61 ~CurveProvider() override;
62
63 // ── Identity ────────────────────────────────────────────────────────────
64
65 QString name() const noexcept { return m_name; }
66 CurveType type() const noexcept { return m_type; }
67
68 // ── Type-driven labels (static for stateless callers) ───────────────────
69
71 static QString xLabel(CurveType t);
72
74 static QString yLabel(CurveType t);
75
77 static QString typeLabel(CurveType t);
78
79 // ── Point access ────────────────────────────────────────────────────────
80
81 int pointCount() const noexcept { return m_points.size(); }
82 const CurvePoint& pointAt(int i) const { return m_points.at(i); }
83 const QVector<CurvePoint>& points() const noexcept { return m_points; }
84
85 // ── Mutators (return false + emit mutationRejected on invariant violation) ──
86
89 bool setAllPoints(QVector<CurvePoint> newPoints, QString *reasonOut = nullptr);
90
93 bool setYAt(int i, double newY, QString *reasonOut = nullptr);
94
97 bool setPointAt(int i, double newX, double newY, QString *reasonOut = nullptr);
98
101 int insertPoint(double x, double y, QString *reasonOut = nullptr);
102
105 void removePointsAt(QVector<int> indices);
106
107 // ── Identity / type mutators ────────────────────────────────────────────
108
111 void setName(QString newName);
112
115 void setType(CurveType t);
116
117signals:
119 void pointsChanged(int firstIndex, int count);
120
122 void pointsInserted(int at, int count);
123
125 void pointsRemoved(int at, int count);
126
129 void nameChanged(QString prev, QString now);
130
133
135 void mutationRejected(QString reason);
136
137private:
139 static bool isStrictlyMonotoneX_(const QVector<CurvePoint> &pts);
140
141 QString m_name;
142 CurveType m_type;
143 QVector<CurvePoint> m_points;
144};
145
146} // namespace openswmmvis::curve
147
148#endif // OPENSWMMVIS_CURVE_CURVEPROVIDER_H
Definition curveprovider.h:56
void nameChanged(QString prev, QString now)
Curve was renamed; dependent-reference cascading is the registry's job.
CurveType type() const noexcept
Definition curveprovider.h:66
void pointsChanged(int firstIndex, int count)
Points in [firstIndex, firstIndex+count) had their (x,y) updated.
void pointsInserted(int at, int count)
count points were inserted starting at at.
int insertPoint(double x, double y, QString *reasonOut=nullptr)
Insert one point. Returns the new index on success; -1 if X collides or would break monotonicity.
Definition curveprovider.cpp:150
void typeChanged(CurveType prev, CurveType now)
Curve type changed (axis labels rebuild).
static QString typeLabel(CurveType t)
Human-readable type name ("Storage", "Pump 1: Volume → Flow", …).
Definition curveprovider.cpp:49
QString name() const noexcept
Definition curveprovider.h:65
const CurvePoint & pointAt(int i) const
Definition curveprovider.h:82
static QString yLabel(CurveType t)
Short axis label for the Y column for the given curve type.
Definition curveprovider.cpp:31
bool setAllPoints(QVector< CurvePoint > newPoints, QString *reasonOut=nullptr)
Replace the entire point list. Validates strict-monotone X before applying. Atomic.
Definition curveprovider.cpp:86
void mutationRejected(QString reason)
A mutator was refused because it would have violated an invariant.
void removePointsAt(QVector< int > indices)
Remove points by index. Indices are deduplicated + sorted descending internally so the loop is safe.
Definition curveprovider.cpp:168
int pointCount() const noexcept
Definition curveprovider.h:81
void setType(CurveType t)
Switch curve type. Does NOT touch points (X/Y still numeric); axis labels rebuild via signals.
Definition curveprovider.cpp:189
const QVector< CurvePoint > & points() const noexcept
Definition curveprovider.h:83
static QString xLabel(CurveType t)
Short axis label for the X column for the given curve type.
Definition curveprovider.cpp:13
void pointsRemoved(int at, int count)
count points were removed starting at at.
bool setYAt(int i, double newY, QString *reasonOut=nullptr)
Change the Y value at index i; X stays put so monotonicity is preserved by construction.
Definition curveprovider.cpp:106
bool setPointAt(int i, double newX, double newY, QString *reasonOut=nullptr)
Change both X + Y at index i. Validates that the new X still slots strictly between neighbours.
Definition curveprovider.cpp:120
void setName(QString newName)
Rename the curve. Uniqueness is the registry's responsibility; this just stores + notifies.
Definition curveprovider.cpp:181
size_t i
Definition contourjob.cpp:27
DiagramType t
Definition diagramspec.cpp:20
QVector< QPointF > pts
Definition meshpatch.cpp:62
Definition curveprovider.h:31
CurveType
Curve flavour. Numeric values match the engine's TableType (1..11) so static_cast<int>(type) is safe.
Definition curveprovider.h:35
@ Pump5
Depth → Flow (variable speed).
@ Pump2
Depth → Flow (on/off).
@ Pump4
Depth → Flow (continuous).
@ Shape
Depth → Width (custom cross-section).
@ Storage
Depth → Surface Area.
@ Diversion
Inflow → Diverted Flow.
@ Control
Variable → Setting.
@ Pump3
Head → Flow (continuous).
@ Rating
Head → Flow (outlets).
int count
Definition numberformat.cpp:101
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
One (x, y) sample on a curve.
Definition curveprovider.h:50
double x
Definition curveprovider.h:51
double y
Definition curveprovider.h:52