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
ifeaturerenderer.h
Go to the documentation of this file.
1
36#ifndef OPENSWMM_RENDER_IFEATURERENDERER_H
37#define OPENSWMM_RENDER_IFEATURERENDERER_H
38
39#include "render/featureref.h"
41#include "render/symbolstyle.h"
42
43#include <QColor>
44#include <QJsonObject>
45#include <QList>
46#include <QString>
47#include <QVariantMap>
48
49#include <memory>
50
51namespace OpenSWMM::Render
52{
53
64enum class ClassEditKind {
65 Color,
66 Size,
67 Width,
68 Symbol
69};
70
85{
86public:
87 virtual ~IFeatureRenderer() = default;
88
93 [[nodiscard]] virtual QString rendererId() const = 0;
94
102 [[nodiscard]] virtual SymbolStyle symbolFor(const FeatureRef &f,
103 const QVariantMap &attrs) const = 0;
104
110 [[nodiscard]] virtual QList<LegendSymbolItem> legendSymbolItems() const = 0;
111
117 [[nodiscard]] virtual QJsonObject toJson() const = 0;
118
124 virtual void fromJson(const QJsonObject &j) = 0;
125
130 [[nodiscard]] virtual std::unique_ptr<IFeatureRenderer> clone() const = 0;
131
132 // ── Per-class editing (Slice BB Phase 8.6.16) ──────────────────────
133 //
134 // Lets the legend's right-click "Change color…/size…/symbol…" entries
135 // and the LegendPropertiesDialog Layers tab mutate a specific legend
136 // row in place. The classKey identifies which row to edit; its format
137 // is renderer-specific (per-renderer doc on the overrides):
138 // - GraduatedRenderer: stringified bin index ("0", "1", …)
139 // - CategorizedRenderer: stringified category index ("0", "1", …)
140 // - SingleSymbolRenderer: "single" (only one class)
141 //
142 // Default implementations are no-ops returning false / doing nothing
143 // so a renderer that supports nothing (e.g. RuleBasedRenderer today)
144 // doesn't need to override anything. Callers MUST query
145 // supportsClassEdit(kind) before invoking the matching setter.
146
149 [[nodiscard]] virtual bool supportsClassEdit(ClassEditKind /*kind*/) const { return false; }
150
158 [[nodiscard]] virtual QColor colorForClass(const QString & /*classKey*/) const
159 { return {}; }
160
166 [[nodiscard]] virtual qreal sizeForClass(const QString & /*classKey*/) const
167 { return -1.0; }
168
171 virtual void setColorForClass(const QString & /*classKey*/, const QColor & /*color*/) {}
172
175 virtual void setSizeForClass(const QString & /*classKey*/, qreal /*size*/) {}
176
179 virtual void setWidthForClass(const QString & /*classKey*/, qreal /*width*/) {}
180
183 virtual void setSymbolForClass(const QString & /*classKey*/,
184 const SymbolStyle & /*style*/) {}
185
189 virtual void clearClassEditOverrides() {}
190
191protected:
192 IFeatureRenderer() = default;
197};
198
199} // namespace OpenSWMM::Render
200
201#endif // OPENSWMM_RENDER_IFEATURERENDERER_H
Abstract interface — every vector layer's paint path goes here.
Definition ifeaturerenderer.h:85
IFeatureRenderer(IFeatureRenderer &&)=default
virtual QList< LegendSymbolItem > legendSymbolItems() const =0
Returns one LegendSymbolItem per visible legend row. Drives the legend dock, the on-canvas legend ove...
virtual qreal sizeForClass(const QString &) const
Read the current marker / line size for classKey. Returns a negative value when the renderer has no e...
Definition ifeaturerenderer.h:166
virtual QJsonObject toJson() const =0
Serialises this renderer to a JSON object. The "id" field equals rendererId(); remaining keys are ren...
virtual bool supportsClassEdit(ClassEditKind) const
True if this renderer can mutate kind on a per-class basis. Defaults to false so opt-in is explicit.
Definition ifeaturerenderer.h:149
virtual QColor colorForClass(const QString &) const
Read the current colour for classKey. Returns an invalid QColor when the renderer has no explicit val...
Definition ifeaturerenderer.h:158
virtual QString rendererId() const =0
Stable string id ("single", "graduated", "categorized", "rule"). Used as the discriminator in JSON ro...
virtual void setWidthForClass(const QString &, qreal)
Override the line width for classKey. No-op when supportsClassEdit(Width) is false.
Definition ifeaturerenderer.h:179
virtual void setSymbolForClass(const QString &, const SymbolStyle &)
Wholesale-replace the SymbolStyle for classKey. No-op when supportsClassEdit(Symbol) is false.
Definition ifeaturerenderer.h:183
IFeatureRenderer & operator=(IFeatureRenderer &&)=default
virtual void setColorForClass(const QString &, const QColor &)
Override the colour for the class identified by classKey. Has no effect when supportsClassEdit(Color)...
Definition ifeaturerenderer.h:171
virtual SymbolStyle symbolFor(const FeatureRef &f, const QVariantMap &attrs) const =0
Returns the SymbolStyle to paint for one feature.
virtual void setSizeForClass(const QString &, qreal)
Override the marker size for classKey (points / squares / triangles…). No-op when supportsClassEdit(S...
Definition ifeaturerenderer.h:175
IFeatureRenderer(const IFeatureRenderer &)=default
virtual void clearClassEditOverrides()
Drop every per-class override applied via the setters above. The renderer falls back to its ramp / ca...
Definition ifeaturerenderer.h:189
virtual std::unique_ptr< IFeatureRenderer > clone() const =0
Deep copy. Owning layers / map presets / undo stack call this when they need a renderer snapshot deco...
IFeatureRenderer & operator=(const IFeatureRenderer &)=default
virtual void fromJson(const QJsonObject &j)=0
Restores this renderer from a JSON object previously produced by toJson(). Implementations should tol...
Stable identifier passed to IFeatureRenderer::symbolFor().
One row in a layer's legend — label + swatch symbol + optional range.
Definition gisrasterlayer.h:40
ClassEditKind
Categories of per-class mutation that a renderer may support.
Definition ifeaturerenderer.h:64
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
A stack of SymbolLayer paint passes plus a layer-level opacity.