File indexing completed on 2025-01-05 03:59:00
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2014 Abhinav Gangwar <abhgang@gmail.com> 0004 // 0005 0006 #include "GeoDataSchemaData.h" 0007 0008 // Qt 0009 #include <QDataStream> 0010 #include <QString> 0011 #include <QHash> 0012 0013 // Marble 0014 #include "GeoDataSimpleData.h" 0015 #include "GeoDataTypes.h" 0016 0017 namespace Marble 0018 { 0019 0020 class GeoDataSchemaDataPrivate 0021 { 0022 public: 0023 GeoDataSchemaDataPrivate() 0024 : m_parent( nullptr ) 0025 { 0026 // nothing to do 0027 } 0028 0029 QString m_schemaUrl; 0030 QHash<QString, GeoDataSimpleData> m_simpleData; // Map for name and SimpleData 0031 GeoDataExtendedData *m_parent; 0032 }; 0033 0034 GeoDataSchemaData::GeoDataSchemaData() 0035 : d( new GeoDataSchemaDataPrivate ) 0036 { 0037 } 0038 0039 GeoDataSchemaData::GeoDataSchemaData( const GeoDataSchemaData &other ) 0040 : d( new GeoDataSchemaDataPrivate( *other.d ) ) 0041 { 0042 } 0043 0044 GeoDataSchemaData &GeoDataSchemaData::operator=( const GeoDataSchemaData &rhs ) 0045 { 0046 *d = *rhs.d; 0047 return *this; 0048 } 0049 0050 bool GeoDataSchemaData::operator==( const GeoDataSchemaData &other ) const 0051 { 0052 if ( d->m_schemaUrl != other.d->m_schemaUrl || 0053 d->m_simpleData.size() != other.d->m_simpleData.size() ) 0054 { 0055 return false; 0056 } 0057 0058 QHash<QString, GeoDataSimpleData>::iterator begin = d->m_simpleData.begin(); 0059 QHash<QString, GeoDataSimpleData>::iterator end = d->m_simpleData.end(); 0060 QHash<QString, GeoDataSimpleData>::iterator beginOther = other.d->m_simpleData.begin(); 0061 0062 for( ; begin != end; ++begin, ++beginOther ) { 0063 if ( *begin != *beginOther ) { 0064 return false; 0065 } 0066 } 0067 0068 return true; 0069 } 0070 0071 bool GeoDataSchemaData::operator!=( const GeoDataSchemaData &other ) const 0072 { 0073 return !this->operator==(other); 0074 } 0075 0076 GeoDataSchemaData::~GeoDataSchemaData() 0077 { 0078 delete d; 0079 } 0080 0081 QString GeoDataSchemaData::schemaUrl() const 0082 { 0083 return d->m_schemaUrl; 0084 } 0085 0086 void GeoDataSchemaData::setSchemaUrl( const QString &schemaUrl ) 0087 { 0088 d->m_schemaUrl = schemaUrl; 0089 } 0090 0091 GeoDataSimpleData &GeoDataSchemaData::simpleData( const QString &name ) const 0092 { 0093 return d->m_simpleData[ name ]; 0094 } 0095 0096 void GeoDataSchemaData::addSimpleData( const GeoDataSimpleData &data ) 0097 { 0098 d->m_simpleData.insert( data.name(), data ); 0099 } 0100 0101 QList<GeoDataSimpleData> GeoDataSchemaData::simpleDataList() const 0102 { 0103 return d->m_simpleData.values(); 0104 } 0105 0106 void GeoDataSchemaData::setParent(GeoDataExtendedData *parent) 0107 { 0108 d->m_parent = parent; 0109 } 0110 0111 const GeoDataExtendedData *GeoDataSchemaData::parent() const 0112 { 0113 return d->m_parent; 0114 } 0115 0116 GeoDataExtendedData *GeoDataSchemaData::parent() 0117 { 0118 return d->m_parent; 0119 } 0120 0121 const char* GeoDataSchemaData::nodeType() const 0122 { 0123 return GeoDataTypes::GeoDataSchemaDataType; 0124 } 0125 0126 void GeoDataSchemaData::pack( QDataStream &stream ) const 0127 { 0128 stream << d->m_schemaUrl; 0129 stream << d->m_simpleData.size(); 0130 0131 QHash<QString, GeoDataSimpleData>::const_iterator iter = d->m_simpleData.constBegin(); 0132 QHash<QString, GeoDataSimpleData>::const_iterator end = d->m_simpleData.constEnd(); 0133 0134 for( ; iter != end; ++iter ) { 0135 iter.value().pack( stream ); 0136 } 0137 } 0138 0139 void GeoDataSchemaData::unpack( QDataStream &stream ) 0140 { 0141 stream >> d->m_schemaUrl; 0142 int size = 0; 0143 stream >> size; 0144 0145 for( int i = 0; i < size; i++ ) { 0146 GeoDataSimpleData simpleData; 0147 simpleData.unpack( stream ); 0148 d->m_simpleData.insert( simpleData.name(), simpleData ); 0149 } 0150 } 0151 0152 } // namespace Marble