File indexing completed on 2024-05-12 03:50:10

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Harshit Jain <hjain.itbhu@gmail.com>
0004 // SPDX-FileCopyrightText: 2011 Niko Sams <niko.sams@gmail.com>
0005 //
0006 
0007 #include "GeoDataExtendedData.h"
0008 #include "GeoDataExtendedData_p.h"
0009 #include <QDataStream>
0010 
0011 #include "GeoDataTypes.h"
0012 
0013 namespace Marble
0014 {
0015 
0016 GeoDataExtendedData::GeoDataExtendedData() :
0017     GeoNode(),
0018     Serializable(),
0019     d(new GeoDataExtendedDataPrivate)
0020 {
0021 }
0022 
0023 GeoDataExtendedData::GeoDataExtendedData(const GeoDataExtendedData &other) :
0024     GeoNode(other),
0025     Serializable(),
0026     d(new GeoDataExtendedDataPrivate(*other.d))
0027 {
0028 }
0029 
0030 bool GeoDataExtendedData::operator==( const GeoDataExtendedData& other ) const
0031 {
0032     return d->hash == other.d->hash &&
0033            d->arrayHash == other.d->arrayHash;
0034 }
0035 
0036 GeoDataExtendedData::~GeoDataExtendedData()
0037 {
0038     qDeleteAll( d->arrayHash );
0039     delete d;
0040 }
0041 
0042 GeoDataExtendedData& GeoDataExtendedData::operator=( const GeoDataExtendedData& other )
0043 {
0044     GeoNode::operator=(other);
0045     *d = *other.d;
0046     return *this;
0047 }
0048 
0049 bool GeoDataExtendedData::operator!=( const GeoDataExtendedData &other ) const
0050 {
0051     return !this->operator==(other);
0052 }
0053 
0054 const char* GeoDataExtendedData::nodeType() const
0055 {
0056     return GeoDataTypes::GeoDataExtendedDataType;
0057 }
0058 
0059 GeoDataData& GeoDataExtendedData::valueRef( const QString& key ) const
0060 {
0061     return d->hash[ key ];
0062 }
0063 
0064 GeoDataData GeoDataExtendedData::value( const QString& key ) const
0065 {
0066     return d->hash.value( key );
0067 }
0068 
0069 void GeoDataExtendedData::addValue( const GeoDataData& data )
0070 {
0071     d->hash.insert( data.name(), data );
0072 }
0073 
0074 void GeoDataExtendedData::removeKey(const QString &key)
0075 {
0076     d->hash.remove(key);
0077 }
0078 
0079 QHash< QString, GeoDataData >::const_iterator GeoDataExtendedData::constBegin( ) const
0080 {
0081     return d->hash.constBegin();
0082 }
0083 
0084 QHash< QString, GeoDataData >::const_iterator GeoDataExtendedData::constEnd( ) const
0085 {
0086     return d->hash.constEnd();
0087 }
0088 
0089 int GeoDataExtendedData::size() const
0090 {
0091     return d->hash.size();
0092 }
0093 
0094 bool GeoDataExtendedData::isEmpty( ) const
0095 {
0096     return d->hash.empty() && d->schemaDataHash.empty();
0097 }
0098 
0099 bool GeoDataExtendedData::contains( const QString &key ) const
0100 {
0101     return d->hash.contains( key );
0102 }
0103 
0104 void GeoDataExtendedData::setSimpleArrayData( const QString& key, GeoDataSimpleArrayData *values )
0105 {
0106     d->arrayHash[ key ] = values;
0107 }
0108 
0109 GeoDataSimpleArrayData* GeoDataExtendedData::simpleArrayData( const QString& key ) const
0110 {
0111     if ( !d->arrayHash.contains( key ) ) return nullptr;
0112     return d->arrayHash[ key ];
0113 }
0114 
0115 GeoDataSchemaData& GeoDataExtendedData::schemaData( const QString& schemaUrl ) const
0116 {
0117     return d->schemaDataHash[ schemaUrl ];
0118 }
0119 
0120 void GeoDataExtendedData::addSchemaData( const GeoDataSchemaData& schemaData )
0121 {
0122     d->schemaDataHash.insert( schemaData.schemaUrl(), schemaData );
0123     d->schemaDataHash[schemaData.schemaUrl()].setParent( this );
0124 }
0125 
0126 void GeoDataExtendedData::removeSchemaData( const QString& schemaUrl )
0127 {
0128     GeoDataSchemaData schemaData = d->schemaDataHash.take( schemaUrl );
0129     schemaData.setParent( nullptr );
0130 }
0131 
0132 QList<GeoDataSchemaData> GeoDataExtendedData::schemaDataList() const
0133 {
0134     return d->schemaDataHash.values();
0135 }
0136 
0137 void GeoDataExtendedData::pack( QDataStream& stream ) const
0138 {
0139     Q_UNUSED(stream)
0140 }
0141 
0142 void GeoDataExtendedData::unpack( QDataStream& stream )
0143 {
0144     Q_UNUSED(stream)
0145 }
0146 
0147 }