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 <QPen>
10#include <QColor>
11#include <QString>
12
13#include "DgmlElementDictionary.h"
14#include "DgmlAttributeDictionary.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(QLatin1String(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 == QLatin1String("nopen")) {
43 } else if (style == QLatin1String("solidline")) {
45 } else if (style == QLatin1String("dashline")) {
47 } else if (style == QLatin1String("dotline")) {
49 } else if (style == QLatin1String("dashdotline")) {
51 } else if (style == QLatin1String("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 )
63 || parentItem.represents( dgmlTag_Geodata ) ) {
64 GeoSceneGeodata *geodata = parentItem.nodeAs<GeoSceneGeodata>();
65 geodata->setPen( pen );
66 }
67
68 return nullptr;
69}
70
71}
72}
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 Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.