KOSMIndoorMap

mapcssstyle.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "mapcssstyle.h"
8#include "mapcssstyle_p.h"
9#include "mapcssparser.h"
10#include "mapcssresult.h"
11#include "mapcssrule_p.h"
12#include "mapcssstate_p.h"
13#include "mapcsstypes.h"
14
15#include <QDebug>
16#include <QIODevice>
17
18using namespace KOSMIndoorMap;
19
21 : d(new MapCSSStylePrivate)
22{}
23
24MapCSSStyle::MapCSSStyle(MapCSSStyle&&) noexcept = default;
25MapCSSStyle::~MapCSSStyle() = default;
26MapCSSStyle& MapCSSStyle::operator=(MapCSSStyle&&) noexcept = default;
27
28bool MapCSSStyle::isEmpty() const
29{
30 return d->m_rules.empty();
31}
32
34{
35 d->m_areaKey = dataSet.tagKey("area");
36 d->m_typeKey = dataSet.tagKey("type");
37 for (const auto &rule : d->m_rules) {
38 rule->compile(dataSet);
39 }
40}
41
42void MapCSSStyle::initializeState(MapCSSState &state) const
43{
44 // determine object type of the input element
45 // This involves tag lookups (and thus cost), but as long as there is at least
46 // one area and one line selector for each zoom level this is break-even. In practice
47 // there are actually many more than that, which means this is a useful optimization
48 // over doing this in MapCSSBasicSelector after checking for the zoom level
49 switch (state.element.type()) {
50 case OSM::Type::Null:
51 Q_UNREACHABLE();
52 case OSM::Type::Node:
53 state.objectType = MapCSSObjectType::Node;
54 break;
55 case OSM::Type::Way:
56 {
57 if (!state.element.way()->isClosed()) {
58 state.objectType = MapCSSObjectType::Line;
59 break;
60 }
61 const auto area = state.element.tagValue(d->m_areaKey);
62 if (area == "yes") {
63 state.objectType = MapCSSObjectType::Area;
64 } else {
65 state.objectType = MapCSSObjectType::LineOrArea;
66 }
67 break;
68 }
69 case OSM::Type::Relation:
70 state.objectType = state.element.tagValue(d->m_typeKey) == "multipolygon" ? MapCSSObjectType::Area : MapCSSObjectType::Relation;
71 break;
72 }
73}
74
75void MapCSSStyle::evaluate(const MapCSSState &state, MapCSSResult &result) const
76{
77 result.clear();
78
79 for (const auto &rule : d->m_rules) {
80 rule->evaluate(state, result);
81 }
82}
83
84void MapCSSStyle::evaluateCanvas(const MapCSSState &state, MapCSSResult &result) const
85{
86 result.clear();
87 for (const auto &rule : d->m_rules) {
88 rule->evaluateCanvas(state, result);
89 }
90}
91
93{
94 for (const auto &rule : d->m_rules) {
95 rule->write(out);
96 }
97}
98
99ClassSelectorKey MapCSSStyle::classKey(const char *className) const
100{
101 return d->m_classSelectorRegistry.key(className);
102}
103
104LayerSelectorKey MapCSSStyle::layerKey(const char *layerName) const
105{
106 return d->m_layerSelectorRegistry.key(layerName);
107}
Result of MapCSS stylesheet evaluation for all layer selectors.
void clear()
Reset result state from a previous evaluation, while retaining previously allocated resource for reus...
A parsed MapCSS style sheet.
Definition mapcssstyle.h:33
void evaluate(const MapCSSState &state, MapCSSResult &result) const
Evaluates the style sheet for a given state state (OSM element, view state, element state,...
MapCSSStyle()
Creates an invalid/empty style.
void write(QIODevice *out) const
Write this style as MapCSS to out.
LayerSelectorKey layerKey(const char *layerName) const
Look up a layer selector key for the given name, if it exists.
ClassSelectorKey classKey(const char *className) const
Look up a class selector key for the given name, if it exists.
void compile(OSM::DataSet &dataSet)
Optimizes style sheet rules for application against dataSet.
void initializeState(MapCSSState &state) const
Initializes the evaluation state.
void evaluateCanvas(const MapCSSState &state, MapCSSResult &result) const
Evaluate canvas style rules.
A set of nodes, ways and relations.
Definition datatypes.h:346
TagKey tagKey(const char *keyName) const
Look up a tag key for the given tag name, if it exists.
Definition datatypes.cpp:38
OSM-based multi-floor indoor maps for buildings.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.