KOSMIndoorMap

mapcssrule.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "mapcssrule_p.h"
8 #include "mapcssresult_p.h"
9 #include "mapcssstate_p.h"
10 
11 #include <QDebug>
12 #include <QIODevice>
13 
14 using namespace KOSMIndoorMap;
15 
16 MapCSSRule::MapCSSRule() = default;
17 MapCSSRule::~MapCSSRule() = default;
18 
19 void MapCSSRule::compile(const OSM::DataSet &dataSet)
20 {
21  m_selector->compile(dataSet);
22  for (const auto &decl : m_declarations) {
23  decl->compile(dataSet);
24  }
25 }
26 
27 void MapCSSRule::evaluate(const MapCSSState &state, MapCSSResult &result) const
28 {
29  // TODO how do we deal with chained selectors here??
30  m_selector->matches(state, result, [this](auto &result, auto layer) {
31  for (const auto &decl : m_declarations) {
32  switch (decl->type()) {
33  case MapCSSDeclaration::PropertyDeclaration:
34  result[layer].addDeclaration(decl.get());
35  break;
36  case MapCSSDeclaration::ClassDeclaration:
37  result[layer].addClass(decl->classSelectorKey());
38  break;
39  case MapCSSDeclaration::TagDeclaration:
40  // TODO
41  qDebug() << "MapCSS tag declaration not implemented yet.";
42  break;
43  }
44  }
45  });
46 }
47 
48 void MapCSSRule::evaluateCanvas(const MapCSSState &state, MapCSSResult &result) const
49 {
50  if (!m_selector->matchesCanvas(state)) {
51  return;
52  }
53 
54  for (const auto &decl : m_declarations) {
55  if (decl->type() == MapCSSDeclaration::PropertyDeclaration) {
56  result[{}].addDeclaration(decl.get());
57  }
58  }
59 }
60 
61 void MapCSSRule::write(QIODevice *out) const
62 {
63  m_selector->write(out);
64  out->write("\n{\n");
65  for (const auto &decl : m_declarations) {
66  decl->write(out);
67  }
68  out->write("}\n\n");
69 }
70 
71 void MapCSSRule::setSelector(MapCSSSelector *selector)
72 {
73  m_selector.reset(selector);
74 }
75 
76 void MapCSSRule::addDeclaration(MapCSSDeclaration *decl)
77 {
78  std::unique_ptr<MapCSSDeclaration> declPtr(decl);
79  if (declPtr->isValid()) {
80  m_declarations.push_back(std::move(declPtr));
81  }
82 }
OSM-based multi-floor indoor maps for buildings.
A set of nodes, ways and relations.
Definition: datatypes.h:283
qint64 write(const char *data, qint64 maxSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.