Marble

DgmlPenTagHandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Nikolas Zimmermann <[email protected]>
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 
18 namespace Marble
19 {
20 namespace dgml
21 {
22 DGML_DEFINE_TAG_HANDLER(Pen)
23 
24 GeoNode* 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")) {
42  pen.setStyle(Qt::NoPen);
43  } else if (style == QLatin1String("solidline")) {
45  } else if (style == QLatin1String("dashline")) {
47  } else if (style == QLatin1String("dotline")) {
48  pen.setStyle(Qt::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 }
QString trimmed() const const
void setWidthF(qreal width)
void setColor(const QColor &color)
bool isEmpty() const const
Binds a QML item to a specific geodetic location in screen coordinates.
double toDouble(bool *ok) const const
QString toLower() const const
bool isValid(QStringView ifopt)
void setStyle(Qt::PenStyle style)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.