KOSMIndoorMap

mapcssstyle.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_MAPCSSSTYLE_H
8#define KOSMINDOORMAP_MAPCSSSTYLE_H
9
10#include "kosmindoormap_export.h"
11
12#include <memory>
13
14class QIODevice;
15
16namespace OSM {
17class DataSet;
18}
19
20namespace KOSMIndoorMap {
21
22class MapCSSResult;
23class MapCSSState;
24class MapCSSStylePrivate;
25
26class ClassSelectorKey;
27class LayerSelectorKey;
28
29/** A parsed MapCSS style sheet.
30 * @see MapCSSParser::parse for how to obtain a valid instance
31 */
32class KOSMINDOORMAP_EXPORT MapCSSStyle
33{
34public:
35 /** Creates an invalid/empty style. */
36 explicit MapCSSStyle();
37 MapCSSStyle(const MapCSSStyle&) = delete;
38 MapCSSStyle(MapCSSStyle&&) noexcept;
40
41 MapCSSStyle& operator=(const MapCSSStyle&) = delete;
42 MapCSSStyle& operator=(MapCSSStyle&&) noexcept;
43
44 /** Returns @c true if this is a default-constructed or otherwise empty/invalud style. */
45 [[nodiscard]] bool isEmpty() const;
46
47 /** Optimizes style sheet rules for application against @p dataSet.
48 * This does resolve tag keys and is therefore mandatory when changing the data set.
49 */
50 void compile(OSM::DataSet &dataSet);
51
52 /** Initializes the evaluation state.
53 * Call this on a MapCSSState instance for each element being evaluated.
54 * The state object can be reused for multiple elements to reduce allocations.
55 * The state object can also be reused for expression evaluations on the style
56 * sheet evaluation result.
57 */
58 void initializeState(MapCSSState &state) const;
59
60 /** Evaluates the style sheet for a given state @p state (OSM element, view state, element state, etc).
61 * The result is not returned but added to @p result for reusing allocated memory
62 * between evaluations.
63 * @note @p state has to be initialized using MapCSSStyle initializeState() for this
64 * to produce correct results.
65 */
66 void evaluate(const MapCSSState &state, MapCSSResult &result) const;
67
68 /** Evaluate canvas style rules. */
69 void evaluateCanvas(const MapCSSState &state, MapCSSResult &result) const;
70
71 /** Write this style as MapCSS to @p out.
72 * Mainly used for testing.
73 */
74 void write(QIODevice *out) const;
75
76 /** Look up a class selector key for the given name, if it exists.
77 * If no such key exists in the style sheet, an null key is returned.
78 * Use this for checking if a class is set on an evaluation result.
79 */
80 [[nodiscard]] ClassSelectorKey classKey(const char *className) const;
81
82 /** Look up a layer selector key for the given name, if it exists.
83 * If no such key exists in the style sheet, an null key is returned.
84 * Use this for accessing specific result layers.
85 */
86 [[nodiscard]] LayerSelectorKey layerKey(const char *layerName) const;
87
88private:
89 friend class MapCSSStylePrivate;
90 std::unique_ptr<MapCSSStylePrivate> d;
91};
92
93}
94
95#endif // KOSMINDOORMAP_MAPCSSSTYLE_H
Result of MapCSS stylesheet evaluation for all layer selectors.
A parsed MapCSS style sheet.
Definition mapcssstyle.h:33
A set of nodes, ways and relations.
Definition datatypes.h:343
OSM-based multi-floor indoor maps for buildings.
Low-level types and functions to work with raw OSM data as efficiently as possible.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:57:46 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.