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
legendoverlaystyle.h
Go to the documentation of this file.
1
21#ifndef OPENSWMM_RENDER_LEGENDOVERLAYSTYLE_H
22#define OPENSWMM_RENDER_LEGENDOVERLAYSTYLE_H
23
24#include <QColor>
25#include <QFont>
26#include <QHash>
27#include <QJsonObject>
28#include <QObject>
29#include <QPoint>
30#include <QString>
31#include <Qt>
32
33namespace OpenSWMM::Render
34{
35
49class LegendOverlayStyle : public QObject
50{
51 Q_OBJECT
52
53public:
57 Q_ENUM(Anchor)
58
59 enum class BackgroundMode {
61 };
62 Q_ENUM(BackgroundMode)
63
64 // ── General tab ─────────────────────────────────────────────────────
65 Q_PROPERTY(bool showTitle READ showTitle WRITE setShowTitle NOTIFY showTitleChanged)
66 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
67 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged)
68 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
69 Q_PROPERTY(QFont itemFont READ itemFont WRITE setItemFont NOTIFY itemFontChanged)
70 Q_PROPERTY(QColor itemColor READ itemColor WRITE setItemColor NOTIFY itemColorChanged)
73 Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
74 Q_PROPERTY(int swatchSize READ swatchSize WRITE setSwatchSize NOTIFY swatchSizeChanged)
75 Q_PROPERTY(int padding READ padding WRITE setPadding NOTIFY paddingChanged)
76 Q_PROPERTY(Anchor anchor READ anchor WRITE setAnchor NOTIFY anchorChanged)
77 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
78 // Slice US.B1 — explicit sizing (0 = auto-fit), free position (used when
79 // anchor == Free), and the per-row label wrap width.
83
84 // ── Frame tab ───────────────────────────────────────────────────────
85 Q_PROPERTY(bool showFrame READ showFrame WRITE setShowFrame NOTIFY showFrameChanged)
86 Q_PROPERTY(QColor frameColor READ frameColor WRITE setFrameColor NOTIFY frameColorChanged)
87 Q_PROPERTY(qreal frameWidth READ frameWidth WRITE setFrameWidth NOTIFY frameWidthChanged)
89
90 // ── Background tab ──────────────────────────────────────────────────
95
104 bool visible = true;
105 QString userLabel;
106 };
107
108 explicit LegendOverlayStyle(QObject *parent = nullptr);
109 ~LegendOverlayStyle() override = default;
110
116 static QString itemKey(const QObject *layer, const QString &classKey);
117
121 [[nodiscard]] ItemOverride itemOverride(const QString &layerKey,
122 const QString &classKey) const;
123
127 void setItemOverride(const QString &layerKey, const QString &classKey,
128 const ItemOverride &override);
129
131 void setItemVisible(const QString &layerKey, const QString &classKey, bool visible);
132
134 void setItemUserLabel(const QString &layerKey, const QString &classKey,
135 const QString &label);
136
138 void clearItemOverrides();
139
143 Q_INVOKABLE QString displayLabelFor(const QString &propertyName) const;
144
145 // Restore every field to its built-in default.
146 void resetToDefaults();
147
148 [[nodiscard]] QJsonObject toJson() const;
149 void fromJson(const QJsonObject &j);
150
151 // ── General getters ─────────────────────────────────────────────────
152 [[nodiscard]] bool showTitle() const noexcept { return m_showTitle; }
153 [[nodiscard]] QString title() const { return m_title; }
154 [[nodiscard]] QFont titleFont() const { return m_titleFont; }
155 [[nodiscard]] QColor titleColor() const noexcept { return m_titleColor; }
156 [[nodiscard]] QFont itemFont() const { return m_itemFont; }
157 [[nodiscard]] QColor itemColor() const noexcept { return m_itemColor; }
158 [[nodiscard]] QFont layerHeaderFont() const { return m_layerHeaderFont; }
159 [[nodiscard]] QColor layerHeaderColor() const noexcept { return m_layerHeaderColor; }
160 [[nodiscard]] int rowSpacing() const noexcept { return m_rowSpacing; }
161 [[nodiscard]] int swatchSize() const noexcept { return m_swatchSize; }
162 [[nodiscard]] int padding() const noexcept { return m_padding; }
163 [[nodiscard]] Anchor anchor() const noexcept { return m_anchor; }
164 [[nodiscard]] qreal opacity() const noexcept { return m_opacity; }
165
166 // ── Slice US.B1 — size / position ───────────────────────────────────
167 [[nodiscard]] int explicitWidth() const noexcept { return m_explicitWidth; }
168 [[nodiscard]] int explicitHeight() const noexcept { return m_explicitHeight; }
169 [[nodiscard]] int maxLabelWidth() const noexcept { return m_maxLabelWidth; }
172 [[nodiscard]] QPoint freePosition() const noexcept { return m_freePosition; }
173
174 // ── Frame getters ───────────────────────────────────────────────────
175 [[nodiscard]] bool showFrame() const noexcept { return m_showFrame; }
176 [[nodiscard]] QColor frameColor() const noexcept { return m_frameColor; }
177 [[nodiscard]] qreal frameWidth() const noexcept { return m_frameWidth; }
178 [[nodiscard]] int cornerRadius() const noexcept { return m_cornerRadius; }
179
180 // ── Background getters ──────────────────────────────────────────────
181 [[nodiscard]] BackgroundMode backgroundMode() const noexcept { return m_backgroundMode; }
182 [[nodiscard]] QColor backgroundColor() const noexcept { return m_backgroundColor; }
183 [[nodiscard]] QColor gradientEndColor() const noexcept { return m_gradientEndColor; }
184 [[nodiscard]] Qt::Orientation gradientOrientation() const noexcept { return m_gradientOrientation; }
185
186public slots:
187 void setShowTitle(bool on);
188 void setTitle(const QString &text);
189 void setTitleFont(const QFont &f);
190 void setTitleColor(const QColor &c);
191 void setItemFont(const QFont &f);
192 void setItemColor(const QColor &c);
193 void setLayerHeaderFont(const QFont &f);
194 void setLayerHeaderColor(const QColor &c);
195 void setRowSpacing(int v);
196 void setSwatchSize(int v);
197 void setPadding(int v);
199 void setOpacity(qreal v);
200 void setExplicitWidth(int px);
201 void setExplicitHeight(int px);
202 void setMaxLabelWidth(int px);
203 void setFreePosition(const QPoint &p);
204
205 void setShowFrame(bool on);
206 void setFrameColor(const QColor &c);
207 void setFrameWidth(qreal w);
208 void setCornerRadius(int r);
209
211 void setBackgroundColor(const QColor &c);
212 void setGradientEndColor(const QColor &c);
213 void setGradientOrientation(Qt::Orientation o);
214
215signals:
216 // Canonical aggregate — every per-property setter emits this too so
217 // views with one-paint-per-edit semantics can subscribe to just this.
218 void changed();
219
223 void itemOverrideChanged(const QString &layerKey, const QString &classKey);
224
226 void titleChanged(const QString &);
227 void titleFontChanged(const QFont &);
228 void titleColorChanged(const QColor &);
229 void itemFontChanged(const QFont &);
230 void itemColorChanged(const QColor &);
231 void layerHeaderFontChanged(const QFont &);
232 void layerHeaderColorChanged(const QColor &);
235 void paddingChanged(int);
237 void opacityChanged(qreal);
241 void freePositionChanged(const QPoint &);
242
244 void frameColorChanged(const QColor &);
245 void frameWidthChanged(qreal);
247
249 void backgroundColorChanged(const QColor &);
250 void gradientEndColorChanged(const QColor &);
251 void gradientOrientationChanged(Qt::Orientation);
252
253private:
254 // General
255 bool m_showTitle = false;
256 QString m_title;
257 QFont m_titleFont;
258 QColor m_titleColor = QColor(20, 20, 20);
259 QFont m_itemFont;
260 QColor m_itemColor = QColor(20, 20, 20);
261 QFont m_layerHeaderFont;
262 QColor m_layerHeaderColor = QColor(20, 20, 20);
263 int m_rowSpacing = 2;
264 int m_swatchSize = 14;
265 int m_padding = 8;
266 Anchor m_anchor = Anchor::BottomRight;
267 qreal m_opacity = 1.0;
268
269 // Slice US.B1 — size / position. 0 = auto-fit on that axis.
270 int m_explicitWidth = 0;
271 int m_explicitHeight = 0;
272 int m_maxLabelWidth = 220;
273 QPoint m_freePosition;
274
275 // Frame
276 bool m_showFrame = true;
277 QColor m_frameColor = QColor(80, 80, 80, 180);
278 qreal m_frameWidth = 1.0;
279 int m_cornerRadius = 6;
280
281 // Background
282 BackgroundMode m_backgroundMode = BackgroundMode::Solid;
283 QColor m_backgroundColor = QColor(255, 255, 255, 225);
284 QColor m_gradientEndColor = QColor(240, 240, 240, 225);
285 Qt::Orientation m_gradientOrientation = Qt::Vertical;
286
287 // Slice BB Phase 8.6.10 / 8.6.16 — per-(layer, class) overrides for
288 // visibility + label. Keyed by "<layerKey>|<classKey>". Persisted in
289 // toJson/fromJson alongside chrome.
290 QHash<QString, ItemOverride> m_itemOverrides;
291};
292
293} // namespace OpenSWMM::Render
294
295#endif // OPENSWMM_RENDER_LEGENDOVERLAYSTYLE_H
Model object holding the on-canvas legend's chrome configuration.
Definition legendoverlaystyle.h:50
Anchor
Definition legendoverlaystyle.h:54
void setExplicitHeight(int px)
Definition legendoverlaystyle.cpp:387
bool showTitle() const noexcept
Definition legendoverlaystyle.h:152
qreal opacity
Definition legendoverlaystyle.h:77
void resetToDefaults()
Definition legendoverlaystyle.cpp:148
QFont itemFont() const
Definition legendoverlaystyle.h:156
QColor itemColor() const noexcept
Definition legendoverlaystyle.h:157
qreal opacity() const noexcept
Definition legendoverlaystyle.h:164
QColor layerHeaderColor() const noexcept
Definition legendoverlaystyle.h:159
QColor itemColor
Definition legendoverlaystyle.h:70
void itemColorChanged(const QColor &)
int maxLabelWidth
Definition legendoverlaystyle.h:82
BackgroundMode
Definition legendoverlaystyle.h:59
QFont titleFont() const
Definition legendoverlaystyle.h:154
void layerHeaderFontChanged(const QFont &)
int cornerRadius() const noexcept
Definition legendoverlaystyle.h:178
int padding() const noexcept
Definition legendoverlaystyle.h:162
void titleFontChanged(const QFont &)
qreal frameWidth() const noexcept
Definition legendoverlaystyle.h:177
void setBackgroundColor(const QColor &c)
void layerHeaderColorChanged(const QColor &)
int cornerRadius
Definition legendoverlaystyle.h:88
void setItemOverride(const QString &layerKey, const QString &classKey, const ItemOverride &override)
Replace the override entry. visible == true + empty label removes the entry (defaults)....
Definition legendoverlaystyle.cpp:102
void backgroundModeChanged(BackgroundMode)
int explicitWidth() const noexcept
Definition legendoverlaystyle.h:167
QColor frameColor() const noexcept
Definition legendoverlaystyle.h:176
void setLayerHeaderColor(const QColor &c)
void fromJson(const QJsonObject &j)
Definition legendoverlaystyle.cpp:274
Anchor anchor
Definition legendoverlaystyle.h:76
void backgroundColorChanged(const QColor &)
QFont layerHeaderFont
Definition legendoverlaystyle.h:71
QColor backgroundColor() const noexcept
Definition legendoverlaystyle.h:182
BackgroundMode backgroundMode
Definition legendoverlaystyle.h:91
QString title
Definition legendoverlaystyle.h:66
void setItemUserLabel(const QString &layerKey, const QString &classKey, const QString &label)
Convenience: set only the userLabel.
Definition legendoverlaystyle.cpp:132
bool showFrame() const noexcept
Definition legendoverlaystyle.h:175
void setItemVisible(const QString &layerKey, const QString &classKey, bool visible)
Convenience: set only the visible flag.
Definition legendoverlaystyle.cpp:124
qreal frameWidth
Definition legendoverlaystyle.h:87
void setTitleColor(const QColor &c)
ItemOverride itemOverride(const QString &layerKey, const QString &classKey) const
Read the override for layerKey + classKey, or a default-constructed ItemOverride (visible=true,...
Definition legendoverlaystyle.cpp:95
int swatchSize() const noexcept
Definition legendoverlaystyle.h:161
QColor backgroundColor
Definition legendoverlaystyle.h:92
int explicitWidth
Definition legendoverlaystyle.h:80
int padding
Definition legendoverlaystyle.h:75
int rowSpacing() const noexcept
Definition legendoverlaystyle.h:160
QString title() const
Definition legendoverlaystyle.h:153
void setGradientEndColor(const QColor &c)
~LegendOverlayStyle() override=default
Anchor anchor() const noexcept
Definition legendoverlaystyle.h:163
void setFreePosition(const QPoint &p)
void setBackgroundMode(BackgroundMode m)
void setItemColor(const QColor &c)
Qt::Orientation gradientOrientation() const noexcept
Definition legendoverlaystyle.h:184
void gradientEndColorChanged(const QColor &)
void itemOverrideChanged(const QString &layerKey, const QString &classKey)
Fine-grained signal for per-item override edits — lets views (e.g. the dock tree) update just one row...
void setMaxLabelWidth(int px)
Definition legendoverlaystyle.cpp:397
void setGradientOrientation(Qt::Orientation o)
int maxLabelWidth() const noexcept
Definition legendoverlaystyle.h:169
QFont titleFont
Definition legendoverlaystyle.h:67
bool showTitle
Definition legendoverlaystyle.h:65
QPoint freePosition() const noexcept
Definition legendoverlaystyle.h:172
Qt::Orientation gradientOrientation
Definition legendoverlaystyle.h:94
Q_INVOKABLE QString displayLabelFor(const QString &propertyName) const
AT-style hook for QPropertyModel — returns human-readable, group-prefixed display labels (e....
Definition legendoverlaystyle.cpp:180
void setLayerHeaderFont(const QFont &f)
static QString itemKey(const QObject *layer, const QString &classKey)
Build the override hash key from a layer + classKey. Uses the layer's QObject::objectName (stable acr...
Definition legendoverlaystyle.cpp:76
QColor layerHeaderColor
Definition legendoverlaystyle.h:72
QFont itemFont
Definition legendoverlaystyle.h:69
QColor gradientEndColor
Definition legendoverlaystyle.h:93
bool showFrame
Definition legendoverlaystyle.h:85
QColor titleColor
Definition legendoverlaystyle.h:68
void setFrameColor(const QColor &c)
void setExplicitWidth(int px)
Definition legendoverlaystyle.cpp:377
int explicitHeight
Definition legendoverlaystyle.h:81
void titleChanged(const QString &)
QColor frameColor
Definition legendoverlaystyle.h:86
QColor titleColor() const noexcept
Definition legendoverlaystyle.h:155
int swatchSize
Definition legendoverlaystyle.h:74
QJsonObject toJson() const
Definition legendoverlaystyle.cpp:217
void gradientOrientationChanged(Qt::Orientation)
QFont layerHeaderFont() const
Definition legendoverlaystyle.h:158
void setTitle(const QString &text)
void frameColorChanged(const QColor &)
QColor gradientEndColor() const noexcept
Definition legendoverlaystyle.h:183
void freePositionChanged(const QPoint &)
int explicitHeight() const noexcept
Definition legendoverlaystyle.h:168
int rowSpacing
Definition legendoverlaystyle.h:73
void titleColorChanged(const QColor &)
BackgroundMode backgroundMode() const noexcept
Definition legendoverlaystyle.h:181
void clearItemOverrides()
Drop every per-item override.
Definition legendoverlaystyle.cpp:141
const char * label
Human label for the filter entry.
Definition gdaldrivers.cpp:22
ArrowPlacement p
Definition linesymbollayer.cpp:27
MaskMode m
Definition maskspec.cpp:18
int w
Definition mesh2dresultsexport.cpp:387
int a
Definition meshquadmatch.cpp:46
Definition gisrasterlayer.h:40
QVector< int > v
pool vertex indices
Definition pslgminsize.cpp:159
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
QString text
Definition queryparser.cpp:35
Per-(layer, class) overrides for a legend row's visibility + label. Slice BB Phase 8....
Definition legendoverlaystyle.h:103
QString userLabel
Definition legendoverlaystyle.h:105