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
patternprovider.h
Go to the documentation of this file.
1
29#ifndef OPENSWMMVIS_PATTERN_PATTERNPROVIDER_H
30#define OPENSWMMVIS_PATTERN_PATTERNPROVIDER_H
31
32#include <QObject>
33#include <QString>
34#include <QVector>
35
37
41enum class PatternType {
42 Monthly = 0,
43 Daily = 1,
44 Hourly = 2,
45 Weekend = 3,
46};
47
48class PatternProvider : public QObject
49{
50 Q_OBJECT
51
52public:
55 PatternProvider(QString name, PatternType type, QObject *parent = nullptr);
56 ~PatternProvider() override;
57
58 // ── Identity / metadata ─────────────────────────────────────────────────
59
61 QString name() const noexcept { return m_name; }
62
64 PatternType type() const noexcept { return m_type; }
65
67 static int factorCountFor(PatternType t) noexcept;
68
70 int factorCount() const noexcept { return factorCountFor(m_type); }
71
75 static QString rowLabel(PatternType t, int i);
76
77 // ── Factor access ───────────────────────────────────────────────────────
78
80 double factor(int i) const { return m_factors.at(i); }
81
83 const QVector<double>& factors() const noexcept { return m_factors; }
84
86 double sumOfFactors() const noexcept;
87
88 // ── Mutators (return false + emit mutationRejected on invariant violation) ──
89
93 bool setFactor(int i, double v, QString *reasonOut = nullptr);
94
97 bool setFactorLive(int i, double v);
98
101 bool setAllFactors(QVector<double> f, QString *reasonOut = nullptr);
102
106 bool normalize(double targetSum = 1.0, QString *reasonOut = nullptr);
107
112 bool swapFactors(int i, int j, QString *reasonOut = nullptr);
113
116 void setName(QString newName);
117
121 void setType(PatternType t);
122
123signals:
125 void factorChanged(int i);
126
130
133 void nameChanged(QString prev, QString now);
134
137
140 void mutationRejected(QString reason);
141
142private:
143 QString m_name;
144 PatternType m_type;
145 QVector<double> m_factors;
146};
147
148} // namespace openswmmvis::pattern
149
150#endif // OPENSWMMVIS_PATTERN_PATTERNPROVIDER_H
Definition patternprovider.h:49
const QVector< double > & factors() const noexcept
All factors (const ref). Size is always factorCount().
Definition patternprovider.h:83
bool setFactorLive(int i, double v)
Live variant of setFactor for drag-edit: does NOT push undo per-frame (caller handles batching).
Definition patternprovider.cpp:90
void typeChanged(PatternType prev, PatternType now)
Pattern type changed (factors reset to 1.0).
static QString rowLabel(PatternType t, int i)
Human-readable label for a factor row index (1..factorCount-1). Returns "Jan".."Dec" / "Sun"....
Definition patternprovider.cpp:27
void nameChanged(QString prev, QString now)
Pattern was renamed; dependent-reference cascading is the registry's job (subscribers should not rewr...
int factorCount() const noexcept
Convenience: factorCountFor(type()).
Definition patternprovider.h:70
bool setFactor(int i, double v, QString *reasonOut=nullptr)
Replace one factor. Validates 0 ≤ i < factorCount() and v >= 0 (negative multipliers are nonsensical ...
Definition patternprovider.cpp:69
QString name() const noexcept
Pattern ID. Uniqueness within a project is owned by the registry.
Definition patternprovider.h:61
void factorsChanged()
All factors were replaced (setAllFactors / setType / normalize). Subscribers re-read the whole array.
PatternType type() const noexcept
Pattern shape (Monthly / Daily / Hourly / Weekend).
Definition patternprovider.h:64
bool setAllFactors(QVector< double > f, QString *reasonOut=nullptr)
Replace the entire factor array. Size of f must equal factorCount(); each value must be >= 0....
Definition patternprovider.cpp:100
bool normalize(double targetSum=1.0, QString *reasonOut=nullptr)
Rescale every factor so their sum equals targetSum. No-op (returns false) if the current sum is zero ...
Definition patternprovider.cpp:122
void setType(PatternType t)
Switch pattern type. Resets all factors to 1.0 because the factor count changes — there's no meaningf...
Definition patternprovider.cpp:166
double sumOfFactors() const noexcept
Sum of all factors. Used by the UI status strip + normalize.
Definition patternprovider.cpp:64
bool swapFactors(int i, int j, QString *reasonOut=nullptr)
Atomically swap the factor values at indices i and j. Used by the chart view's slot-reorder drag (hor...
Definition patternprovider.cpp:143
double factor(int i) const
Read a single factor by index. Caller must ensure 0 ≤ i < factorCount().
Definition patternprovider.h:80
void setName(QString newName)
Rename the pattern. Uniqueness is the registry's responsibility; this just stores + notifies.
Definition patternprovider.cpp:158
void factorChanged(int i)
One factor at index i had its value changed.
void mutationRejected(QString reason)
A mutator was refused because it would have violated an invariant. Surfaced to UI so the status bar c...
static int factorCountFor(PatternType t) noexcept
How many factors does this type need? Static helper.
Definition patternprovider.cpp:16
size_t i
Definition contourjob.cpp:27
DiagramType t
Definition diagramspec.cpp:20
Definition patternprovider.h:36
PatternType
Pattern shape — fixed factor count per type. Numeric values intentionally match the engine's PatternT...
Definition patternprovider.h:41
@ Weekend
24 factors, one per hour of day (weekend).
@ Hourly
24 factors, one per hour of day (weekday).
@ Monthly
12 factors, one per calendar month.
@ Daily
7 factors, one per day of week (Sun..Sat).
QVector< int > v
pool vertex indices
Definition pslgminsize.cpp:159
QVector< int > parent
union-find
Definition pslgminsize.cpp:176