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::evaluate(MapCSSState &&state, MapCSSResult &result) const
43{
44 result.clear();
45
46 // determine object type of the input element
47 // This involves tag lookups (and thus cost), but as long as there is at least
48 // one area and one line selector for each zoom level this is break-even. In practice
49 // there are actually many more than that, which means this is a useful optimization
50 // over doing this in MapCSSBasicSelector after checking for the zoom level
51 switch (state.element.type()) {
52 case OSM::Type::Null:
53 Q_UNREACHABLE();
54 case OSM::Type::Node:
55 state.objectType = MapCSSObjectType::Node;
56 break;
57 case OSM::Type::Way:
58 {
59 if (!state.element.way()->isClosed()) {
60 state.objectType = MapCSSObjectType::Line;
61 break;
62 }
63 const auto area = state.element.tagValue(d->m_areaKey);
64 if (area == "yes") {
65 state.objectType = MapCSSObjectType::Area;
66 } else {
67 state.objectType = MapCSSObjectType::LineOrArea;
68 }
69 break;
70 }
71 case OSM::Type::Relation:
72 state.objectType = state.element.tagValue(d->m_typeKey) == "multipolygon" ? MapCSSObjectType::Area : MapCSSObjectType::Relation;
73 break;
74 }
75
76 for (const auto &rule : d->m_rules) {
77 rule->evaluate(state, result);
78 }
79}
80
81void MapCSSStyle::evaluateCanvas(const MapCSSState &state, MapCSSResult &result) const
82{
83 result.clear();
84 for (const auto &rule : d->m_rules) {
85 rule->evaluateCanvas(state, result);
86 }
87}
88
90{
91 for (const auto &rule : d->m_rules) {
92 rule->write(out);
93 }
94}
95
96ClassSelectorKey MapCSSStyle::classKey(const char *className) const
97{
98 return d->m_classSelectorRegistry.key(className);
99}
100
101LayerSelectorKey MapCSSStyle::layerKey(const char *layerName) const
102{
103 return d->m_layerSelectorRegistry.key(layerName);
104}
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 compile(const OSM::DataSet &dataSet)
Optimizes style sheet rules for application against dataSet.
MapCSSStyle()
Creates an invalid/empty style.
void write(QIODevice *out) const
Write this style as MapCSS to out.
void evaluate(MapCSSState &&state, MapCSSResult &result) const
Evaluates the style sheet for a given state state (OSM element, view state, element state,...
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 evaluateCanvas(const MapCSSState &state, MapCSSResult &result) const
Evaluate canvas style rules.
A set of nodes, ways and relations.
Definition datatypes.h:340
TagKey tagKey(const char *keyName) const
Look up a tag key for the given tag name, if it exists.
Definition datatypes.cpp:27
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 Tue Mar 26 2024 11:20:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.