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 <QString>
11#include <QHash>
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 ||
53 d->m_simpleData.size() != other.d->m_simpleData.size() )
54 {
55 return false;
56 }
57
58 QHash<QString, GeoDataSimpleData>::iterator begin = d->m_simpleData.begin();
60 QHash<QString, GeoDataSimpleData>::iterator beginOther = other.d->m_simpleData.begin();
61
62 for( ; begin != end; ++begin, ++beginOther ) {
63 if ( *begin != *beginOther ) {
64 return false;
65 }
66 }
67
68 return true;
69}
70
71bool GeoDataSchemaData::operator!=( const GeoDataSchemaData &other ) const
72{
73 return !this->operator==(other);
74}
75
76GeoDataSchemaData::~GeoDataSchemaData()
77{
78 delete d;
79}
80
81QString GeoDataSchemaData::schemaUrl() const
82{
83 return d->m_schemaUrl;
84}
85
86void GeoDataSchemaData::setSchemaUrl( const QString &schemaUrl )
87{
88 d->m_schemaUrl = schemaUrl;
89}
90
91GeoDataSimpleData &GeoDataSchemaData::simpleData( const QString &name ) const
92{
93 return d->m_simpleData[ name ];
94}
95
96void GeoDataSchemaData::addSimpleData( const GeoDataSimpleData &data )
97{
98 d->m_simpleData.insert( data.name(), data );
99}
100
101QList<GeoDataSimpleData> GeoDataSchemaData::simpleDataList() const
102{
103 return d->m_simpleData.values();
104}
105
106void GeoDataSchemaData::setParent(GeoDataExtendedData *parent)
107{
108 d->m_parent = parent;
109}
110
111const GeoDataExtendedData *GeoDataSchemaData::parent() const
112{
113 return d->m_parent;
114}
115
116GeoDataExtendedData *GeoDataSchemaData::parent()
117{
118 return d->m_parent;
119}
120
121const char* GeoDataSchemaData::nodeType() const
122{
123 return GeoDataTypes::GeoDataSchemaDataType;
124}
125
126void GeoDataSchemaData::pack( QDataStream &stream ) const
127{
128 stream << d->m_schemaUrl;
129 stream << d->m_simpleData.size();
130
131 QHash<QString, GeoDataSimpleData>::const_iterator iter = d->m_simpleData.constBegin();
132 QHash<QString, GeoDataSimpleData>::const_iterator end = d->m_simpleData.constEnd();
133
134 for( ; iter != end; ++iter ) {
135 iter.value().pack( stream );
136 }
137}
138
139void GeoDataSchemaData::unpack( QDataStream &stream )
140{
141 stream >> d->m_schemaUrl;
142 int size = 0;
143 stream >> size;
144
145 for( int i = 0; i < size; i++ ) {
146 GeoDataSimpleData simpleData;
147 simpleData.unpack( stream );
148 d->m_simpleData.insert( simpleData.name(), simpleData );
149 }
150}
151
152} // namespace Marble
QString name(StandardAction id)
const QList< QKeySequence > & begin()
const QList< QKeySequence > & end()
Binds a QML item to a specific geodetic location in screen coordinates.
QString & insert(qsizetype position, QChar ch)
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.