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 "mapcssloader.h"
10#include "mapcssparser.h"
11#include "mapcssparser_p.h"
12#include "mapcssrule_p.h"
13#include "mapcssstyle_p.h"
14
15using namespace KOSMIndoorMap;
16
17bool MapCSSParserContext::addImport(char* fileName, ClassSelectorKey importClass)
18{
19 const auto cssUrl = MapCSSLoader::resolve(QString::fromUtf8(fileName), m_currentUrl);
20 free(fileName);
21
23 MapCSSParserPrivate::get(&p)->parse(m_currentStyle, cssUrl, importClass);
24 if (p.hasError()) {
25 m_error = p.error();
26 m_errorMsg = p.errorMessage();
27 if (m_error == MapCSSParser::FileNotFoundError) {
28 m_currentUrl = p.url();
29 }
30 }
31 return !p.hasError();
32}
33
34void MapCSSParserContext::addRule(MapCSSRule *rule)
35{
36 if (!m_importClass.isNull()) {
37 auto decl = new MapCSSDeclaration(MapCSSDeclaration::ClassDeclaration);
38 decl->setClassSelectorKey(m_importClass);
39 rule->addDeclaration(decl);
40 }
41 MapCSSStylePrivate::get(m_currentStyle)->m_rules.push_back(std::unique_ptr<MapCSSRule>(rule));
42}
43
44void MapCSSParserContext::setError(const QString &msg, int line, int column)
45{
46 m_error = MapCSSParser::SyntaxError;
47 m_errorMsg = msg;
48 m_line = line;
49 m_column = column;
50}
51
52ClassSelectorKey MapCSSParserContext::makeClassSelector(const char *str, std::size_t len) const
53{
54 return MapCSSStylePrivate::get(m_currentStyle)->m_classSelectorRegistry.makeKey(str, len, OSM::StringMemory::Transient);
55}
56
57LayerSelectorKey MapCSSParserContext::makeLayerSelector(const char *str, std::size_t len) const
58{
59 if (!str || std::strcmp(str, "default") == 0) {
60 return {};
61 }
62 return MapCSSStylePrivate::get(m_currentStyle)->m_layerSelectorRegistry.makeKey(str, len, OSM::StringMemory::Transient);
63}
static QUrl resolve(const QString &style, const QUrl &baseUrl={})
Resolve style to an absolute URL to load.
QUrl url() const
URL of the parsed MapCSS style sheet.
bool hasError() const
Returns true if an error occured during parsing and the returned style is invalid.
OSM-based multi-floor indoor maps for buildings.
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.