Marble

DgmlBrushTagHandler.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 "DgmlBrushTagHandler.h"
8
9#include <QBrush>
10#include <QColor>
11#include <QList>
12#include <QString>
13
14#include "DgmlAttributeDictionary.h"
15#include "DgmlElementDictionary.h"
16#include "GeoParser.h"
17#include "GeoSceneGeodata.h"
18
19namespace Marble
20{
21namespace dgml
22{
23DGML_DEFINE_TAG_HANDLER(Brush)
24
25GeoNode *DgmlBrushTagHandler::parse(GeoParser &parser) const
26{
27 // Check whether the tag is valid
28 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1StringView(dgmlTag_Brush)));
29
30 QString color = parser.attribute(dgmlAttr_color).trimmed();
31 QString colorMap = parser.attribute(dgmlAttr_colorMap).trimmed();
32 qreal alpha = parser.attribute(dgmlAttr_alpha).isEmpty() ? 1.0 : parser.attribute(dgmlAttr_alpha).toDouble();
33
34 QBrush brush;
35
36 if (!color.isEmpty() && QColor(color).isValid()) {
37 QColor brushColor(color);
38 if (color.contains(QLatin1StringView("transparent"))) {
39 brushColor.setAlphaF(0.0);
40 } else {
41 brushColor.setAlphaF(alpha);
42 }
43 brush.setColor(brushColor);
44 }
45
46 // Checking for parent item
47 GeoStackItem parentItem = parser.parentElement();
48 if (parentItem.represents(dgmlTag_Vector) || parentItem.represents(dgmlTag_Geodata)) {
49 auto geodata = parentItem.nodeAs<GeoSceneGeodata>();
50 geodata->setBrush(brush);
51 if (!colorMap.isEmpty()) {
52 const QStringList colorString = colorMap.split(QLatin1Char(','));
53
54 QList<QColor> colorList;
55 colorList.reserve(colorString.size());
56 for (const QString &colorName : colorString) {
57 colorList.append(QColor(colorName));
58 }
59 geodata->setColors(colorList);
60 }
61 geodata->setAlpha(alpha);
62 }
63
64 return nullptr;
65}
66
67}
68}
bool isValid(QStringView ifopt)
Binds a QML item to a specific geodetic location in screen coordinates.
void setColor(Qt::GlobalColor color)
void append(QList< T > &&value)
void reserve(qsizetype size)
qsizetype size() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) 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.