Marble

GeoDataSchemaData.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2014 Abhinav Gangwar <abhgang@gmail.com>
4//
5
6#include "GeoDataSchemaData.h"
7
8// Qt
9#include <QDataStream>
10#include <QHash>
11#include <QString>
12
13// Marble
14#include "GeoDataSimpleData.h"
15#include "GeoDataTypes.h"
16
17namespace Marble
18{
19
20class GeoDataSchemaDataPrivate
21{
22public:
23 GeoDataSchemaDataPrivate()
24 : m_parent(nullptr)
25 {
26 // nothing to do
27 }
28
29 QString m_schemaUrl;
30 QHash<QString, GeoDataSimpleData> m_simpleData; // Map for name and SimpleData
31 GeoDataExtendedData *m_parent;
32};
33
34GeoDataSchemaData::GeoDataSchemaData()
35 : d(new GeoDataSchemaDataPrivate)
36{
37}
38
39GeoDataSchemaData::GeoDataSchemaData(const GeoDataSchemaData &other)
40 : d(new GeoDataSchemaDataPrivate(*other.d))
41{
42}
43
44GeoDataSchemaData &GeoDataSchemaData::operator=(const GeoDataSchemaData &rhs)
45{
46 *d = *rhs.d;
47 return *this;
48}
49
50bool GeoDataSchemaData::operator==(const GeoDataSchemaData &other) const
51{
52 if (d->m_schemaUrl != other.d->m_schemaUrl || d->m_simpleData.size() != other.d->m_simpleData.size()) {
53 return false;
54 }
55
56 QHash<QString, GeoDataSimpleData>::iterator begin = d->m_simpleData.begin();
58 QHash<QString, GeoDataSimpleData>::iterator beginOther = other.d->m_simpleData.begin();
59
60 for (; begin != end; ++begin, ++beginOther) {
61 if (*begin != *beginOther) {
62 return false;
63 }
64 }
65
66 return true;
67}
68
69bool GeoDataSchemaData::operator!=(const GeoDataSchemaData &other) const
70{
71 return !this->operator==(other);
72}
73
74GeoDataSchemaData::~GeoDataSchemaData()
75{
76 delete d;
77}
78
79QString GeoDataSchemaData::schemaUrl() const
80{
81 return d->m_schemaUrl;
82}
83
84void GeoDataSchemaData::setSchemaUrl(const QString &schemaUrl)
85{
86 d->m_schemaUrl = schemaUrl;
87}
88
89GeoDataSimpleData &GeoDataSchemaData::simpleData(const QString &name) const
90{
91 return d->m_simpleData[name];
92}
93
94void GeoDataSchemaData::addSimpleData(const GeoDataSimpleData &data)
95{
96 d->m_simpleData.insert(data.name(), data);
97}
98
99QList<GeoDataSimpleData> GeoDataSchemaData::simpleDataList() const
100{
101 return d->m_simpleData.values();
102}
103
104void GeoDataSchemaData::setParent(GeoDataExtendedData *parent)
105{
106 d->m_parent = parent;
107}
108
109const GeoDataExtendedData *GeoDataSchemaData::parent() const
110{
111 return d->m_parent;
112}
113
114GeoDataExtendedData *GeoDataSchemaData::parent()
115{
116 return d->m_parent;
117}
118
119const char *GeoDataSchemaData::nodeType() const
120{
121 return GeoDataTypes::GeoDataSchemaDataType;
122}
123
124void GeoDataSchemaData::pack(QDataStream &stream) const
125{
126 stream << d->m_schemaUrl;
127 stream << d->m_simpleData.size();
128
129 QHash<QString, GeoDataSimpleData>::const_iterator iter = d->m_simpleData.constBegin();
130 QHash<QString, GeoDataSimpleData>::const_iterator end = d->m_simpleData.constEnd();
131
132 for (; iter != end; ++iter) {
133 iter.value().pack(stream);
134 }
135}
136
137void GeoDataSchemaData::unpack(QDataStream &stream)
138{
139 stream >> d->m_schemaUrl;
140 int size = 0;
141 stream >> size;
142
143 for (int i = 0; i < size; i++) {
144 GeoDataSimpleData simpleData;
145 simpleData.unpack(stream);
146 d->m_simpleData.insert(simpleData.name(), simpleData);
147 }
148}
149
150} // namespace Marble
QString name(GameStandardAction id)
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
const QList< QKeySequence > & begin()
bool operator==(const StyleDelim &l, const StyleDelim &r)
Binds a QML item to a specific geodetic location in screen coordinates.
QString & insert(qsizetype position, QChar ch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:55:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.