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 "DgmlElementDictionary.h"
15#include "DgmlAttributeDictionary.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(QLatin1String(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(QLatin1String("transparent"))) {
39 brushColor.setAlphaF( 0.0 );
40 }
41 else {
42 brushColor.setAlphaF( alpha );
43 }
44 brush.setColor( brushColor );
45 }
46
47 // Checking for parent item
48 GeoStackItem parentItem = parser.parentElement();
49 if ( parentItem.represents( dgmlTag_Vector )
50 || parentItem.represents( dgmlTag_Geodata ) ) {
51 GeoSceneGeodata *geodata = parentItem.nodeAs<GeoSceneGeodata>();
52 geodata->setBrush( brush );
53 if ( !colorMap.isEmpty() ) {
54 const QStringList colorString = colorMap.split(QLatin1Char(','));
55
56 QVector<QColor> colorList;
57 colorList.reserve(colorString.size());
58 for(const QString& colorName: colorString) {
59 colorList.append(QColor(colorName));
60 }
61 geodata->setColors( colorList );
62 }
63 geodata->setAlpha( alpha );
64 }
65
66 return nullptr;
67}
68
69}
70}
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 Fri Jun 7 2024 12:03:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.