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
timeseriesprovider.h
Go to the documentation of this file.
1
26#ifndef OPENSWMMVIS_TIMESERIES_TIMESERIESPROVIDER_H
27#define OPENSWMMVIS_TIMESERIES_TIMESERIESPROVIDER_H
28
29#include <QDateTime>
30#include <QObject>
31#include <QString>
32#include <QVector>
33
35
38 QDateTime time;
39 double value = 0.0;
40};
41
42class TimeseriesProvider : public QObject
43{
44 Q_OBJECT
45
46public:
48 enum class SourceMode {
49 Inline,
52 };
53 Q_ENUM(SourceMode)
54
55
66 enum class TimeMode {
67 Absolute,
68 Relative,
69 Mixed
70 };
71 Q_ENUM(TimeMode)
72
73 explicit TimeseriesProvider(QString name, QObject *parent = nullptr);
75
76 // ── Identity / metadata ─────────────────────────────────────────────────
77
79 QString name() const noexcept { return m_name; }
80
83 QString unitsLabel() const noexcept { return m_unitsLabel; }
84
87 QString description() const noexcept { return m_description; }
88
89 // ── Source mode + file/gpkg metadata ────────────────────────────────────
90
91 SourceMode sourceMode() const noexcept { return m_sourceMode; }
92
94 QString filePath() const noexcept { return m_filePath; }
95
97 QString columnSelector() const noexcept { return m_columnSelector; }
98
100 QDateTime fileMTime() const noexcept { return m_fileMTime; }
101
102 // ── Point access ────────────────────────────────────────────────────────
103
106 int pointCount() const noexcept { return m_points.size(); }
107
108 // ── Lazy cache (Step F — ExternalFile mode only) ────────────────────────
109
114 bool isPointCacheLoaded() const noexcept;
115
124 void disposePointCache();
125
127 const TimeseriesPoint& pointAt(int i) const { return m_points.at(i); }
128
130 const QVector<TimeseriesPoint>& points() const noexcept { return m_points; }
131
132 // ── Mutators (return false + emit mutationRejected on invariant violation) ──
133
136 bool setAllPoints(QVector<TimeseriesPoint> newPoints, QString *reasonOut = nullptr);
137
140 bool setValueAt(int i, double newValue, QString *reasonOut = nullptr);
141
144 bool setValueLive(int i, double newValue);
145
148 bool setPointAt(int i, QDateTime newTime, double newValue, QString *reasonOut = nullptr);
149
153 int insertPoint(QDateTime time, double value, QString *reasonOut = nullptr);
154
157 void removePointsAt(QVector<int> indices);
158
159 // ── Identity / metadata mutators ────────────────────────────────────────
160
163 void setName(QString newName);
164
165 void setUnitsLabel(QString units);
166 void setDescription(QString d);
167
169 void setFileSource(QString path, QString columnSelector, QDateTime mtime);
170
171 // ── Time mode (relative / absolute authoring form) ──────────────────────
172
176 TimeMode timeMode() const noexcept;
177
179 int relativeCount() const noexcept { return m_relativeCount; }
180
183 QDateTime relativeAnchor() const noexcept { return m_relativeAnchor; }
184
191 void setRelativeInfo(int count, QDateTime anchor, int allRelativeIntent = -1);
192
197 void setTimeMode(TimeMode mode, QDateTime anchorForRelative = {});
198
199signals:
203
205 void pointsChanged(int firstIndex, int count);
206
208 void pointsInserted(int at, int count);
209
211 void pointsRemoved(int at, int count);
212
216
219
222 void nameChanged(QString prev, QString now);
223
226 void mutationRejected(QString reason);
227
233
234private:
235 QString m_name;
236 QString m_unitsLabel;
237 QString m_description;
238 SourceMode m_sourceMode = SourceMode::Inline;
239 QString m_filePath;
240 QString m_columnSelector;
241 QDateTime m_fileMTime;
242 QVector<TimeseriesPoint> m_points;
243
244 // Time-mode state (see the TimeMode enum). m_allRelative is the sticky
245 // authoring intent: while true, mutators keep the prefix covering every
246 // point (and an empty series stays Relative for its first insert).
247 int m_relativeCount = 0;
248 bool m_allRelative = false;
249 QDateTime m_relativeAnchor;
250
252 static bool isStrictMonotone_(const QVector<TimeseriesPoint>& pts);
253
257 void reconcileRelativeAfterMutation_(TimeMode prevMode);
258};
259
260} // namespace openswmmvis::timeseries
261
262#endif // OPENSWMMVIS_TIMESERIES_TIMESERIESPROVIDER_H
Definition timeseriesprovider.h:43
void pointCacheDisposed()
Step F — ExternalFile mode: the lazy point cache was dropped via disposePointCache....
bool setAllPoints(QVector< TimeseriesPoint > newPoints, QString *reasonOut=nullptr)
Replace the entire point list. Validates strict-monotone time before applying. Atomic: either all rep...
Definition timeseriesprovider.cpp:124
int insertPoint(QDateTime time, double value, QString *reasonOut=nullptr)
Insert one point. Returns the new index on success.
Definition timeseriesprovider.cpp:214
TimeMode timeMode() const noexcept
Derived mode: Relative when every point is in the relative prefix (or an empty series carries relativ...
Definition timeseriesprovider.cpp:56
void pointsRemoved(int at, int count)
count points were removed starting at at.
int relativeCount() const noexcept
Leading points authored as elapsed-time-from-start.
Definition timeseriesprovider.h:179
int pointCount() const noexcept
Number of stored points. ExternalFile mode reports 0 until the read-through cache is implemented in i...
Definition timeseriesprovider.h:106
void setFileSource(QString path, QString columnSelector, QDateTime mtime)
Definition timeseriesprovider.cpp:285
void setUnitsLabel(QString units)
Definition timeseriesprovider.cpp:263
const QVector< TimeseriesPoint > & points() const noexcept
All points (const ref).
Definition timeseriesprovider.h:130
void setSourceMode(SourceMode mode)
Definition timeseriesprovider.cpp:277
QString filePath() const noexcept
External file path (meaningful only when sourceMode == ExternalFile).
Definition timeseriesprovider.h:94
void setRelativeInfo(int count, QDateTime anchor, int allRelativeIntent=-1)
Raw restore used by registry load and undo: sets the prefix count (clamped to [0, pointCount()]),...
Definition timeseriesprovider.cpp:65
void pointsInserted(int at, int count)
count points were inserted starting at at.
QDateTime relativeAnchor() const noexcept
Simulation start the relative points' absolute times are anchored to (invalid when the series has no ...
Definition timeseriesprovider.h:183
void setName(QString newName)
Rename the Tseries. Uniqueness is the registry's responsibility; this just stores + notifies.
Definition timeseriesprovider.cpp:254
bool isPointCacheLoaded() const noexcept
True iff the in-memory point vector is populated. Inline / GeopackageObserved modes always return tru...
Definition timeseriesprovider.cpp:31
QString name() const noexcept
Tseries ID. Uniqueness within a project is owned by the registry.
Definition timeseriesprovider.h:79
QString description() const noexcept
Optional free-text description; surfaced by the editor's header context menu.
Definition timeseriesprovider.h:87
void timeModeChanged()
The derived timeMode() flipped, or the relative anchor moved. Payload-free; subscribers re-read (meta...
void sourceModeChanged(SourceMode prev, SourceMode now)
Source mode flipped.
bool setValueLive(int i, double newValue)
Live variant of setValueAt for drag-edit: does NOT push undo per-frame (caller handles batching)....
Definition timeseriesprovider.cpp:179
bool setPointAt(int i, QDateTime newTime, double newValue, QString *reasonOut=nullptr)
Change both time + value at index i. Validates that the new time still slots between neighbours stric...
Definition timeseriesprovider.cpp:188
bool setValueAt(int i, double newValue, QString *reasonOut=nullptr)
Change only the value at index i. Time stays put so monotonicity is preserved by construction.
Definition timeseriesprovider.cpp:164
QString columnSelector() const noexcept
Column selector inside the external file ("" = first / name-match).
Definition timeseriesprovider.h:97
QDateTime fileMTime() const noexcept
Last-known file mtime for staleness detection.
Definition timeseriesprovider.h:100
void setDescription(QString d)
Definition timeseriesprovider.cpp:270
const TimeseriesPoint & pointAt(int i) const
Read a single point by index. Caller must ensure 0 ≤ i < pointCount().
Definition timeseriesprovider.h:127
void removePointsAt(QVector< int > indices)
Remove points by index. Indices are deduplicated + sorted descending internally so the loop is safe.
Definition timeseriesprovider.cpp:238
TimeMode
How the series' times were authored in the .inp.
Definition timeseriesprovider.h:66
@ Relative
Every row is elapsed time from the simulation start.
@ Mixed
Elapsed head rows + dated tail (loaded, not authored).
@ Absolute
Every row carries (or inherits) an explicit date.
void metadataChanged()
Identity / units / description changed (signal carries no payload; subscribers re-read).
QString unitsLabel() const noexcept
Units label inferred from column suffix or set explicitly (e.g. "m", "ft³/s"). UI hint only — no unit...
Definition timeseriesprovider.h:83
void mutationRejected(QString reason)
A mutator was refused because it would have violated an invariant. Surfaced to UI so the drag-edit st...
void setTimeMode(TimeMode mode, QDateTime anchorForRelative={})
User-facing mode switch. Relative marks every current point relative and records anchorForRelative (w...
Definition timeseriesprovider.cpp:82
SourceMode
Where the data lives.
Definition timeseriesprovider.h:48
@ Inline
Stored in the project (.inp [TIMESERIES] rows).
@ ExternalFile
Linked to a CSV / TSV / .dat file on disk.
@ GeopackageObserved
Stored in the project geopackage observed_* tables.
SourceMode sourceMode() const noexcept
Definition timeseriesprovider.h:91
void disposePointCache()
Drop the in-memory point vector for ExternalFile-mode providers to reclaim memory when the editor swi...
Definition timeseriesprovider.cpp:41
void nameChanged(QString prev, QString now)
Tseries was renamed; dependent-reference cascading is the registry's job (subscribers should not rewr...
void pointsChanged(int firstIndex, int count)
Points in [firstIndex, firstIndex+count) had their value changed in place.
size_t i
Definition contourjob.cpp:27
QuadRegionMode mode
Resolved mode.
Definition meshgenerator.cpp:154
QVector< QPointF > pts
Definition meshpatch.cpp:62
Definition timeseriesprovider.h:34
int count
Definition numberformat.cpp:101
int path
Definition pslgminsize.cpp:234
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
One (time, value) sample.
Definition timeseriesprovider.h:37
double value
Definition timeseriesprovider.h:39
QDateTime time
Definition timeseriesprovider.h:38