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
graduatedrenderer.h
Go to the documentation of this file.
1
27#ifndef OPENSWMM_RENDER_GRADUATEDRENDERER_H
28#define OPENSWMM_RENDER_GRADUATEDRENDERER_H
29
31#include "render/colorramp.h"
34
35#include <QColor>
36#include <QHash>
37#include <QList>
38#include <QString>
39#include <QVector>
40
41namespace OpenSWMM::Render
42{
43
63{
64public:
65 GraduatedRenderer() = default;
66 ~GraduatedRenderer() override = default;
67
72 [[nodiscard]] QString classifyAttribute() const { return m_classifyAttribute; }
73 void setClassifyAttribute(QString name) { m_classifyAttribute = std::move(name); }
74
83 [[nodiscard]] QString sizeAttribute() const { return m_sizeAttribute; }
84 void setSizeAttribute(QString name)
85 {
86 if (name == m_sizeAttribute) return;
87 m_sizeAttribute = std::move(name);
88 // New attribute → the sampled value range is stale; invalidate so
89 // the owning layer's next rebuild re-derives it from data.
90 m_sizeValueMin = m_sizeValueMax = 0.0;
91 }
92
94 [[nodiscard]] QString effectiveSizeAttribute() const
95 {
96 return m_sizeAttribute.isEmpty() ? m_classifyAttribute : m_sizeAttribute;
97 }
98
101 [[nodiscard]] bool sizeAxisIndependent() const
102 {
103 return !m_sizeAttribute.isEmpty()
104 && m_sizeAttribute != m_classifyAttribute;
105 }
106
109 [[nodiscard]] double sizeValueMin() const { return m_sizeValueMin; }
110 [[nodiscard]] double sizeValueMax() const { return m_sizeValueMax; }
111 [[nodiscard]] bool sizeValueRangeValid() const
112 { return m_sizeValueMax > m_sizeValueMin; }
113 void setSizeValueRange(double mn, double mx)
114 { m_sizeValueMin = mn; m_sizeValueMax = mx; }
115
121 [[nodiscard]] AttributeSourceKind sourceKind() const { return m_sourceKind; }
122 void setSourceKind(AttributeSourceKind k) { m_sourceKind = k; }
123
129 [[nodiscard]] RangeMode rangeMode() const { return m_rangeMode; }
130 void setRangeMode(RangeMode m) { m_rangeMode = m; }
131
137 [[nodiscard]] double minValue() const { return m_ramp.minValue; }
138 [[nodiscard]] double maxValue() const { return m_ramp.maxValue; }
139 void setRange(double minValue, double maxValue);
140
145 [[nodiscard]] const RasterColorRamp &ramp() const { return m_ramp; }
147
151 [[nodiscard]] const IntervalBinner &binner() const { return m_binner; }
153
159 [[nodiscard]] const QVector<double> &lastBreaks() const { return m_lastBreaks; }
160
167 void clearBreaks() { m_lastBreaks.clear(); }
168
176 static void classifyIfNeeded(GraduatedRenderer *g, const QVector<double> &samples)
177 {
178 if (g && g->lastBreaks().isEmpty() && !samples.isEmpty())
179 g->autoClassify(samples);
180 }
181
187 [[nodiscard]] QList<QColor> binColors() const;
188 void setBinColors(QList<QColor> colors);
189 [[nodiscard]] int binCount() const { return m_binner.binCount(); }
190
196 [[nodiscard]] const SymbolStyle &baseSymbol() const { return m_baseSymbol; }
198
204 void autoClassify(const QVector<double> &samples);
205
211 [[nodiscard]] QColor colorForValue(double v) const;
212
217 [[nodiscard]] QColor colorForBin(int bin) const;
218
227 [[nodiscard]] bool outputSizeEnabled() const { return m_outputSizeEnabled; }
228 void setOutputSizeEnabled(bool on) { m_outputSizeEnabled = on; }
229
230 [[nodiscard]] bool outputColorEnabled() const { return m_outputColorEnabled; }
231 void setOutputColorEnabled(bool on) { m_outputColorEnabled = on; }
232
233 [[nodiscard]] double outputSizeMin() const { return m_outputSizeMin; }
234 [[nodiscard]] double outputSizeMax() const { return m_outputSizeMax; }
235 void setOutputSizeRange(double minPx, double maxPx);
236
243 [[nodiscard]] double sizeForBin(int bin) const;
244
251 [[nodiscard]] double sizeForValue(double v) const;
252
264 [[nodiscard]] bool outputWidthEnabled() const { return m_outputWidthEnabled; }
265 void setOutputWidthEnabled(bool on) { m_outputWidthEnabled = on; }
266
267 [[nodiscard]] double outputWidthMin() const { return m_outputWidthMin; }
268 [[nodiscard]] double outputWidthMax() const { return m_outputWidthMax; }
269 void setOutputWidthRange(double minPx, double maxPx);
270
275 [[nodiscard]] double widthForBin(int bin) const;
276
279 [[nodiscard]] double widthForValue(double v) const;
280
281 // IFeatureRenderer.
282 [[nodiscard]] QString rendererId() const override { return QStringLiteral("graduated"); }
283 [[nodiscard]] SymbolStyle symbolFor(const FeatureRef &f,
284 const QVariantMap &attrs) const override;
285 [[nodiscard]] QList<LegendSymbolItem> legendSymbolItems() const override;
286 [[nodiscard]] QJsonObject toJson() const override;
287 void fromJson(const QJsonObject &j) override;
288 [[nodiscard]] std::unique_ptr<IFeatureRenderer> clone() const override;
289
290 // ── Per-class editing (Slice BB Phase 8.6.16) ──────────────────────
291 // classKey is the bin index as a string ("0", "1", …). Only colour
292 // is editable for graduated — size/width are global on this renderer.
293 // Overrides persist through ramp changes but become "dormant" if the
294 // bin count drops below the override index (they re-emerge if the
295 // bin count grows again, modelling undo-friendly user intent).
296 [[nodiscard]] bool supportsClassEdit(ClassEditKind kind) const override
297 {
298 return kind == ClassEditKind::Color;
299 }
300 [[nodiscard]] QColor colorForClass(const QString &classKey) const override;
301 void setColorForClass(const QString &classKey, const QColor &color) override;
302 void clearClassEditOverrides() override;
303
306 [[nodiscard]] const QHash<int, QColor> &binColorOverrides() const noexcept
307 { return m_binColorOverrides; }
308
309private:
310 QString m_classifyAttribute;
311 // Independent size/width attribute (empty = follow classifyAttribute)
312 // + its sampled value range (invalid until the owning layer derives it).
313 QString m_sizeAttribute;
314 double m_sizeValueMin = 0.0;
315 double m_sizeValueMax = 0.0;
316 RasterColorRamp m_ramp = RasterColorRamp::viridis(0.0, 1.0);
317 IntervalBinner m_binner; // EqualInterval, 5 bins by default
318 QVector<double> m_lastBreaks;
319 SymbolStyle m_baseSymbol;
320
321 // Slice BI Phase 8.13.43-α — output-axis toggles.
322 bool m_outputColorEnabled = true;
323 bool m_outputSizeEnabled = false;
324 double m_outputSizeMin = 2.0;
325 double m_outputSizeMax = 14.0;
326
327 // VS.4 — independent line-width output axis.
328 bool m_outputWidthEnabled = false;
329 double m_outputWidthMin = 0.5;
330 double m_outputWidthMax = 6.0;
331
332 // P2 — static/dynamic source + range-mode spine.
335
336 // Slice BB Phase 8.6.16 — sparse per-bin colour overrides.
337 QHash<int, QColor> m_binColorOverrides;
338};
339
340} // namespace OpenSWMM::Render
341
342#endif // OPENSWMM_RENDER_GRADUATEDRENDERER_H
P2 — the static/dynamic styling spine.
Classifies a numeric attribute into bins and assigns a colour per bin.
Definition graduatedrenderer.h:63
double minValue() const
Convenience accessor for the ramp's value range. Equivalent to ramp().minValue / ....
Definition graduatedrenderer.h:137
QColor colorForBin(int bin) const
Returns the colour for one already-computed bin index. Sampled from the ramp at midpoint (i + 0....
Definition graduatedrenderer.cpp:183
double sizeForValue(double v) const
Value-interpolated size for the independent size axis: linear map of v (clamped) from [sizeValueMin,...
Definition graduatedrenderer.cpp:148
bool sizeValueRangeValid() const
Definition graduatedrenderer.h:111
QString sizeAttribute() const
Independent attribute driving the size / width output axes. Empty (the default) = follow classifyAttr...
Definition graduatedrenderer.h:83
double widthForValue(double v) const
Definition graduatedrenderer.cpp:174
bool supportsClassEdit(ClassEditKind kind) const override
True if this renderer can mutate kind on a per-class basis. Defaults to false so opt-in is explicit.
Definition graduatedrenderer.h:296
void clearClassEditOverrides() override
Drop every per-class override applied via the setters above. The renderer falls back to its ramp / ca...
Definition graduatedrenderer.cpp:222
double widthForBin(int bin) const
Bin-mapped line width, mirroring sizeForBin over the width range. Returns outputWidthMin for single-b...
Definition graduatedrenderer.cpp:163
void setColorForClass(const QString &classKey, const QColor &color) override
Override the colour for the class identified by classKey. Has no effect when supportsClassEdit(Color)...
Definition graduatedrenderer.cpp:211
RangeMode rangeMode() const
P2 — how the value range behaves over the time axis. The owning results layer consumes this on each t...
Definition graduatedrenderer.h:129
bool outputWidthEnabled() const
VS.4 — independent line-WIDTH output axis. Marker "size" and line "width" are distinct visual channel...
Definition graduatedrenderer.h:264
void setSourceKind(AttributeSourceKind k)
Definition graduatedrenderer.h:122
void setRangeMode(RangeMode m)
Definition graduatedrenderer.h:130
std::unique_ptr< IFeatureRenderer > clone() const override
Deep copy. Owning layers / map presets / undo stack call this when they need a renderer snapshot deco...
Definition graduatedrenderer.cpp:487
double sizeValueMax() const
Definition graduatedrenderer.h:110
bool outputSizeEnabled() const
Slice BI Phase 8.13.43-α — Graduated tab's "Output axes" toggle for size/width. When outputSizeEnable...
Definition graduatedrenderer.h:227
double outputSizeMin() const
Definition graduatedrenderer.h:233
QString effectiveSizeAttribute() const
Definition graduatedrenderer.h:94
void setBinner(IntervalBinner b)
Definition graduatedrenderer.cpp:68
QColor colorForValue(double v) const
Returns the colour for one raw attribute value. Clamps to [bin 0, bin N−1]. Returns Qt::transparent w...
Definition graduatedrenderer.cpp:227
void fromJson(const QJsonObject &j) override
Restores this renderer from a JSON object previously produced by toJson(). Implementations should tol...
Definition graduatedrenderer.cpp:394
bool sizeAxisIndependent() const
Definition graduatedrenderer.h:101
void setSizeValueRange(double mn, double mx)
Definition graduatedrenderer.h:113
SymbolStyle symbolFor(const FeatureRef &f, const QVariantMap &attrs) const override
Returns the SymbolStyle to paint for one feature.
Definition graduatedrenderer.cpp:249
void setClassifyAttribute(QString name)
Definition graduatedrenderer.h:73
void setOutputWidthEnabled(bool on)
Definition graduatedrenderer.h:265
void setOutputWidthRange(double minPx, double maxPx)
Definition graduatedrenderer.cpp:157
void setBinColors(QList< QColor > colors)
Definition graduatedrenderer.cpp:89
double outputWidthMax() const
Definition graduatedrenderer.h:268
QList< QColor > binColors() const
Per-bin colours (derived view). Computed from the ramp + binCount at request time; kept on the legacy...
Definition graduatedrenderer.cpp:79
double outputWidthMin() const
Definition graduatedrenderer.h:267
void setBaseSymbol(SymbolStyle s)
Definition graduatedrenderer.cpp:100
QList< LegendSymbolItem > legendSymbolItems() const override
Returns one LegendSymbolItem per visible legend row. Drives the legend dock, the on-canvas legend ove...
Definition graduatedrenderer.cpp:318
QString classifyAttribute() const
Name of the attribute key (in QVariantMap attrs) to classify on. Typical SWMM values: "depth",...
Definition graduatedrenderer.h:72
void setRange(double minValue, double maxValue)
Definition graduatedrenderer.cpp:57
const SymbolStyle & baseSymbol() const
The SymbolStyle template. At paint time the renderer overrides the "color" property of every SymbolLa...
Definition graduatedrenderer.h:196
QString rendererId() const override
Stable string id ("single", "graduated", "categorized", "rule"). Used as the discriminator in JSON ro...
Definition graduatedrenderer.h:282
QColor colorForClass(const QString &classKey) const override
Read the current colour for classKey. Returns an invalid QColor when the renderer has no explicit val...
Definition graduatedrenderer.cpp:200
const IntervalBinner & binner() const
The interval binner that maps attribute values → bin indices.
Definition graduatedrenderer.h:151
void autoClassify(const QVector< double > &samples)
Recomputes interval breaks + ramp range from a sample of attribute values. NaNs and infinities are sk...
Definition graduatedrenderer.cpp:105
~GraduatedRenderer() override=default
bool outputColorEnabled() const
Definition graduatedrenderer.h:230
int binCount() const
Definition graduatedrenderer.h:189
void clearBreaks()
Drops the cached breaks so the next classify pass (driven by the owning layer's rebuild) re-derives t...
Definition graduatedrenderer.h:167
void setRamp(RasterColorRamp ramp)
Definition graduatedrenderer.cpp:63
double maxValue() const
Definition graduatedrenderer.h:138
const QHash< int, QColor > & binColorOverrides() const noexcept
Inspect currently-stored per-bin colour overrides — primarily for unit tests + the property dialog's ...
Definition graduatedrenderer.h:306
void setOutputColorEnabled(bool on)
Definition graduatedrenderer.h:231
double outputSizeMax() const
Definition graduatedrenderer.h:234
QJsonObject toJson() const override
Serialises this renderer to a JSON object. The "id" field equals rendererId(); remaining keys are ren...
Definition graduatedrenderer.cpp:352
void setOutputSizeEnabled(bool on)
Definition graduatedrenderer.h:228
const RasterColorRamp & ramp() const
The colour ramp used to derive per-bin colours. Sampled at each bin's midpoint (i + 0....
Definition graduatedrenderer.h:145
AttributeSourceKind sourceKind() const
P2 — whether classifyAttribute() is a STATIC model/GIS field (classified once) or a DYNAMIC SWMM outp...
Definition graduatedrenderer.h:121
const QVector< double > & lastBreaks() const
The last set of interior break values computed by the binner. Kept on the renderer so paint-time binF...
Definition graduatedrenderer.h:159
double sizeForBin(int bin) const
Returns the bin-midpoint-mapped size for a bin index, when outputSizeEnabled. Linear interpolation be...
Definition graduatedrenderer.cpp:137
double sizeValueMin() const
Definition graduatedrenderer.h:109
void setSizeAttribute(QString name)
Definition graduatedrenderer.h:84
void setOutputSizeRange(double minPx, double maxPx)
Definition graduatedrenderer.cpp:131
static void classifyIfNeeded(GraduatedRenderer *g, const QVector< double > &samples)
Shared classify gate used by every owning layer's rebuild so the model + results paths cannot drift....
Definition graduatedrenderer.h:176
Abstract interface — every vector layer's paint path goes here.
Definition ifeaturerenderer.h:85
Computes break values + maps a value to a bin index.
Definition intervalbinner.h:49
int binCount() const
Definition intervalbinner.h:56
RasterColorRamp — gradient mapping from a normalised value in [0,1] to a display QColor.
The single seam every layer paint path goes through.
double s
Scene px per model length unit.
Definition inletdrawingview.cpp:82
Slice BB-α — classifies a set of numeric samples into N bins.
MaskMode m
Definition maskspec.cpp:18
int k
Definition mesh2dresultsexport.cpp:549
int b
local residual indices, a < b
Definition meshquadmatch.cpp:46
Definition gisrasterlayer.h:40
RangeMode
Definition attributesource.h:39
ClassEditKind
Categories of per-class mutation that a renderer may support.
Definition ifeaturerenderer.h:64
AttributeSourceKind
Definition attributesource.h:34
QVector< int > v
pool vertex indices
Definition pslgminsize.cpp:159
TokenKind kind
Definition queryparser.cpp:34
QString name
Definition sectionmodelbuilders.cpp:474
Identifies one feature in one layer for the renderer pipeline.
Definition featureref.h:35
Stack of SymbolLayer paint passes (bottom-up) plus an overall opacity.
Definition symbolstyle.h:39
Gradient mapping from a normalised value in [0,1] to a QColor.
Definition colorramp.h:71
double minValue
Definition colorramp.h:72
static RasterColorRamp viridis(double min=0.0, double max=1.0)
Definition colorramp.cpp:200
double maxValue
Definition colorramp.h:73