Marble

DgmlPenTagHandler.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Nikolas Zimmermann <zimmermann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "DgmlPenTagHandler.h"
8
9#include <QColor>
10#include <QPen>
11#include <QString>
12
13#include "DgmlAttributeDictionary.h"
14#include "DgmlElementDictionary.h"
15#include "GeoParser.h"
16#include "GeoSceneGeodata.h"
17
18namespace Marble
19{
20namespace dgml
21{
22DGML_DEFINE_TAG_HANDLER(Pen)
23
24GeoNode *DgmlPenTagHandler::parse(GeoParser &parser) const
25{
26 // Check whether the tag is valid
27 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1StringView(dgmlTag_Pen)));
28
29 QString color = parser.attribute(dgmlAttr_color).trimmed();
30 QString style = parser.attribute(dgmlAttr_style).toLower().trimmed();
31 QString widthString = parser.attribute(dgmlAttr_width);
32 qreal width = widthString.isEmpty() ? 1.0 : widthString.toDouble();
33
34 QPen pen;
35
36 if (!color.isEmpty() && QColor(color).isValid()) {
37 pen.setColor(QColor(color));
38 }
39
40 if (!style.isEmpty()) {
41 if (style == QLatin1StringView("nopen")) {
43 } else if (style == QLatin1StringView("solidline")) {
45 } else if (style == QLatin1StringView("dashline")) {
47 } else if (style == QLatin1StringView("dotline")) {
49 } else if (style == QLatin1StringView("dashdotline")) {
51 } else if (style == QLatin1StringView("dashdotdotline")) {
53 }
54 }
55
56 if (width != 0.0) {
57 pen.setWidthF(width);
58 }
59
60 // Checking for parent item
61 GeoStackItem parentItem = parser.parentElement();
62 if (parentItem.represents(dgmlTag_Vector) || parentItem.represents(dgmlTag_Geodata)) {
63 auto geodata = parentItem.nodeAs<GeoSceneGeodata>();
64 geodata->setPen(pen);
65 }
66
67 return nullptr;
68}
69
70}
71}
bool isValid(QStringView ifopt)
Binds a QML item to a specific geodetic location in screen coordinates.
void setColor(const QColor &color)
void setStyle(Qt::PenStyle style)
void setWidthF(qreal width)
bool isEmpty() const const
double toDouble(bool *ok) const const
QString toLower() const const
QString trimmed() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.