KOSMIndoorMap

scenegraphitem.h
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KOSMINDOORMAP_SCENEGRAPHITEM_H
8#define KOSMINDOORMAP_SCENEGRAPHITEM_H
9
10#include <KOSM/Element>
11
12#include <style/mapcsstypes.h>
13
14#include <QBrush>
15#include <QColor>
16#include <QFont>
17#include <QIcon>
18#include <QPainterPath>
19#include <QPen>
20#include <QPolygonF>
21#include <QSizeF>
22#include <QStaticText>
23#include <QString>
24
25#include <memory>
26
27namespace KOSMIndoorMap {
28
29class SceneGraphItemPayload;
30class View;
31
32/** Unit for geometry sizes. */
33enum class Unit : uint8_t {
34 Pixel,
35 Meter,
36};
37
38/** Scene graph item description and handle for its content.
39 * This is a minimal and cheap part that can be used allocation-free,
40 * and it holds the expensive polymorphic parts (geometry, materials) depending on the
41 * type of this is item.
42 * This split allows to use this part for searching/sorting/indexing.
43 */
45{
46public:
47 /** The OSM::Element this item refers to. */
49
50 int level = 0;
51 int layer = 0;
52
53 LayerSelectorKey layerSelector;
54
55 std::unique_ptr<SceneGraphItemPayload> payload;
56};
57
58/** Payload base class for scene graph items. */
60{
61public:
62 virtual ~SceneGraphItemPayload();
63
64 /** See MapCSS spec: "Within a layer, first all fills are rendered, then all casings, then all strokes, then all icons and labels." .*/
65 enum RenderPhase : uint8_t {
66 NoPhase = 0,
67 FillPhase = 1,
68 CasingPhase = 2,
69 StrokePhase = 4,
70 IconPhase = 8,
71 LabelPhase = 16,
72 };
73 /** Returns in which phase this item needs to be rendered (can be multiple). */
74 [[nodiscard]] virtual uint8_t renderPhases() const = 0;
75
76 /** Bounding box of this item in scene coordinates.
77 * Performance trumps precision here, so estimating this slightly larger rather than computing it expensively makes sense.
78 */
79 [[nodiscard]] virtual QRectF boundingRect(const View *view) const = 0;
80
81 /** Is this item drawn in scene coordinates (as oposed to HUD coordinates)? */
82 [[nodiscard]] bool inSceneSpace() const;
83 /** Is this item drawn in HUD coordinates (as oposed to scene coordinates)? */
84 [[nodiscard]] bool inHUDSpace() const;
85
86 int z = 0;
87};
88
89
90/** A path/way/line item in the scenegraph. */
92{
93public:
94 uint8_t renderPhases() const override;
95 QRectF boundingRect(const View *view) const override;
96
97 QPolygonF path;
98 QPen pen;
99 QPen casingPen;
100 Unit penWidthUnit = Unit::Meter;
101 Unit casingPenWidthUnit = Unit::Pixel;
102};
103
104
105/** Base item for filled polygons. */
107{
108public:
109 [[nodiscard]] uint8_t renderPhases() const override;
110
111 /** Render like lines, ie casing and filling in the stroke phase, rather than the default. */
112 [[nodiscard]] bool useCasingFillMode() const;
113
114 QBrush fillBrush = Qt::NoBrush;
115 QBrush textureBrush = Qt::NoBrush;
116 QPen pen;
117 QPen casingPen;
118 Unit penWidthUnit = Unit::Pixel;
119 Unit casingPenWidthUnit = Unit::Pixel;
120};
121
122
123/** A single filled polygon. */
125{
126public:
127 QRectF boundingRect(const View *view) const override;
128
129 QPolygonF polygon;
130};
131
132
133/** Multi-polygon item, used for polygons with "holes" in them. */
135{
136public:
137 QRectF boundingRect(const View *view) const override;
138
139 QPainterPath path;
140};
141
142/** A text or icon label */
144{
145public:
146 [[nodiscard]] uint8_t renderPhases() const override;
147 [[nodiscard]] QRectF boundingRect(const View *view) const override;
148
149 [[nodiscard]] QRectF iconHitBox(const View *view) const;
150 [[nodiscard]] QRectF textHitBox(const View *view) const;
151 [[nodiscard]] QRectF shieldHitBox(const View *view) const;
152
153 [[nodiscard]] QSizeF iconOutputSize(const View *view) const;
154 [[nodiscard]] QSizeF textOutputSize() const;
155 [[nodiscard]] double casingAndFrameWidth() const;
156
157 [[nodiscard]] bool hasIcon() const;
158 [[nodiscard]] inline bool hasText() const { return textIsSet; }
159 [[nodiscard]] bool hasShield() const;
160
161 QPointF pos;
162 QColor color;
163 QFont font;
164 QStaticText text;
165 mutable QSizeF textOutputSizeCache;
166
167 QIcon icon;
168 QSizeF iconSize;
169 double iconOpacity = 1.0;
170 Unit iconWidthUnit = Unit::Pixel;
171 Unit iconHeightUnit = Unit::Pixel;
172
173 double casingWidth = 0.0;
174 QColor casingColor = Qt::transparent;
175 double frameWidth = 0.0;
176 QColor frameColor = Qt::transparent;
177 QColor shieldColor = Qt::transparent;
178
179 double angle = 0.0;
180 double textOffset = 0.0;
181
182 QColor haloColor = Qt::transparent;
183 double haloRadius = 0.0;
184
185 bool allowTextOverlap : 1 = false;
186 bool allowIconOverlap : 1 = false;
187 bool iconHidden : 1 = false;
188 bool textHidden : 1 = false;
189 bool textIsSet : 1 = false;
190 bool isComplexText : 1 = false; // means: don't render QStaticText
191};
192
193
194}
195
196#endif // KOSMINDOORMAP_SCENEGRAPHITEM_H
A text or icon label.
QRectF boundingRect(const View *view) const override
Bounding box of this item in scene coordinates.
uint8_t renderPhases() const override
Returns in which phase this item needs to be rendered (can be multiple).
Multi-polygon item, used for polygons with "holes" in them.
QRectF boundingRect(const View *view) const override
Bounding box of this item in scene coordinates.
Base item for filled polygons.
uint8_t renderPhases() const override
Returns in which phase this item needs to be rendered (can be multiple).
bool useCasingFillMode() const
Render like lines, ie casing and filling in the stroke phase, rather than the default.
A single filled polygon.
QRectF boundingRect(const View *view) const override
Bounding box of this item in scene coordinates.
A path/way/line item in the scenegraph.
uint8_t renderPhases() const override
Returns in which phase this item needs to be rendered (can be multiple).
QRectF boundingRect(const View *view) const override
Bounding box of this item in scene coordinates.
Payload base class for scene graph items.
virtual uint8_t renderPhases() const =0
Returns in which phase this item needs to be rendered (can be multiple).
bool inSceneSpace() const
Is this item drawn in scene coordinates (as oposed to HUD coordinates)?
RenderPhase
See MapCSS spec: "Within a layer, first all fills are rendered, then all casings, then all strokes,...
bool inHUDSpace() const
Is this item drawn in HUD coordinates (as oposed to scene coordinates)?
virtual QRectF boundingRect(const View *view) const =0
Bounding box of this item in scene coordinates.
Scene graph item description and handle for its content.
OSM::Element element
The OSM::Element this item refers to.
View transformations and transformation manipulation.
Definition view.h:40
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
Definition element.h:24
OSM-based multi-floor indoor maps for buildings.
Unit
Unit for geometry sizes.
transparent
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:09:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.