KOSMIndoorMap

mapcssparsercontext.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "mapcssparsercontext_p.h"
7
8#include "mapcssdeclaration_p.h"
9#include "mapcssparser.h"
10#include "mapcssparser_p.h"
11#include "mapcssrule_p.h"
12#include "mapcssstyle_p.h"
13#include "logging.h"
14
15#include <QFileInfo>
16
17using namespace KOSMIndoorMap;
18
19bool MapCSSParserContext::addImport(char* fileName, ClassSelectorKey importClass)
20{
21 auto cssFile = QString::fromUtf8(fileName);
22 free(fileName);
23
24 if (QFileInfo(cssFile).isRelative()) {
25 cssFile = QFileInfo(m_currentFileName).absolutePath() + QLatin1Char('/') + cssFile;
26 }
27
29 MapCSSParserPrivate::get(&p)->parse(m_currentStyle, cssFile, importClass);
30 if (p.hasError()) {
31 m_error = true;
32 m_errorMsg = p.errorMessage();
33 }
34 return !p.hasError();
35}
36
37void MapCSSParserContext::addRule(MapCSSRule *rule)
38{
39 if (!m_importClass.isNull()) {
40 auto decl = new MapCSSDeclaration(MapCSSDeclaration::ClassDeclaration);
41 decl->setClassSelectorKey(m_importClass);
42 rule->addDeclaration(decl);
43 }
44 MapCSSStylePrivate::get(m_currentStyle)->m_rules.push_back(std::unique_ptr<MapCSSRule>(rule));
45}
46
47void MapCSSParserContext::setError(const QString &msg, int line, int column)
48{
49 m_error = true;
50 m_errorMsg = msg;
51 m_line = line;
52 m_column = column;
53}
54
55ClassSelectorKey MapCSSParserContext::makeClassSelector(const char *str, std::size_t len) const
56{
57 return MapCSSStylePrivate::get(m_currentStyle)->m_classSelectorRegistry.makeKey(str, len, OSM::StringMemory::Transient);
58}
59
60LayerSelectorKey MapCSSParserContext::makeLayerSelector(const char *str, std::size_t len) const
61{
62 if (!str || std::strcmp(str, "default") == 0) {
63 return {};
64 }
65 return MapCSSStylePrivate::get(m_currentStyle)->m_layerSelectorRegistry.makeKey(str, len, OSM::StringMemory::Transient);
66}
OSM-based multi-floor indoor maps for buildings.
QString absolutePath() const const
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:53:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.