KOSMIndoorMap

mapcssrule.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 "mapcssrule_p.h"
8#include "mapcssresult.h"
9#include "mapcssstate_p.h"
10
11#include <QDebug>
12#include <QIODevice>
13
14#include <cmath>
15
16using namespace KOSMIndoorMap;
17
18MapCSSRule::MapCSSRule() = default;
19MapCSSRule::~MapCSSRule() = default;
20
21void MapCSSRule::compile(OSM::DataSet &dataSet)
22{
23 m_selector->compile(dataSet);
24 for (const auto &decl : m_declarations) {
25 decl->compile(dataSet);
26 }
27}
28
29void MapCSSRule::evaluate(const MapCSSState &state, MapCSSResult &result) const
30{
31 // TODO how do we deal with chained selectors here??
32 m_selector->matches(state, result, m_declarations);
33}
34
35void MapCSSRule::evaluateCanvas(const MapCSSState &state, MapCSSResult &result) const
36{
37 if (!m_selector->matchesCanvas(state)) {
38 return;
39 }
40
41 for (const auto &decl : m_declarations) {
42 if (decl->type() == MapCSSDeclaration::PropertyDeclaration) {
43 result[{}].addDeclaration(decl.get());
44 }
45 }
46}
47
48void MapCSSRule::write(QIODevice *out) const
49{
50 m_selector->write(out);
51 out->write("\n{\n");
52 for (const auto &decl : m_declarations) {
53 decl->write(out);
54 }
55 out->write("}\n\n");
56}
57
58void MapCSSRule::setSelector(MapCSSSelector *selector)
59{
60 m_selector.reset(selector);
61}
62
63void MapCSSRule::addDeclaration(MapCSSDeclaration *decl)
64{
65 std::unique_ptr<MapCSSDeclaration> declPtr(decl);
66 if (declPtr->isValid()) {
67 m_declarations.push_back(std::move(declPtr));
68 }
69}
Result of MapCSS stylesheet evaluation for all layer selectors.
A set of nodes, ways and relations.
Definition datatypes.h:346
OSM-based multi-floor indoor maps for buildings.
qint64 write(const QByteArray &data)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.