File indexing completed on 2025-01-05 03:58:54
0001 /* 0002 SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com> 0003 SPDX-FileCopyrightText: 2007 Nikolas Zimmermann <zimmermann@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "GeoDataDocument.h" 0009 #include "GeoDataDocument_p.h" 0010 0011 #include "GeoDataStyleMap.h" 0012 #include "GeoDataNetworkLinkControl.h" 0013 #include "GeoDataSchema.h" 0014 0015 #include "digikam_debug.h" 0016 0017 #include <QDataStream> 0018 0019 namespace Marble 0020 { 0021 0022 GeoDataDocument::GeoDataDocument() 0023 : GeoDataContainer( new GeoDataDocumentPrivate ) 0024 { 0025 } 0026 0027 GeoDataDocument::GeoDataDocument( const GeoDataDocument& other ) 0028 : GeoDocument(), 0029 GeoDataContainer(other, new GeoDataDocumentPrivate(*other.d_func())) 0030 { 0031 } 0032 0033 GeoDataDocument::~GeoDataDocument() 0034 { 0035 } 0036 0037 GeoDataDocument& GeoDataDocument::operator=(const GeoDataDocument& other) 0038 { 0039 if (this != &other) { 0040 Q_D(GeoDataDocument); 0041 *d = *other.d_func(); 0042 } 0043 0044 return *this; 0045 } 0046 0047 bool GeoDataDocument::operator==( const GeoDataDocument &other ) const 0048 { 0049 if (!GeoDataContainer::equals(other)) { 0050 return false; 0051 } 0052 0053 Q_D(const GeoDataDocument); 0054 const GeoDataDocumentPrivate* const other_d = other.d_func(); 0055 if (!(d->m_styleHash.size() == other_d->m_styleHash.size() && 0056 d->m_styleMapHash == other_d->m_styleMapHash && 0057 d->m_schemaHash == other_d->m_schemaHash && 0058 d->m_filename == other_d->m_filename && 0059 d->m_baseUri == other_d->m_baseUri && 0060 d->m_networkLinkControl == other_d->m_networkLinkControl && 0061 d->m_property == other_d->m_property && 0062 d->m_documentRole == other_d->m_documentRole)) { 0063 return false; 0064 } 0065 0066 auto iter = d->m_styleHash.constBegin(); 0067 auto const end = d->m_styleHash.constEnd(); 0068 for (; iter != end; ++iter) { 0069 if (!other_d->m_styleHash.contains(iter.key())) { 0070 return false; 0071 } 0072 0073 if (*iter.value() != *other_d->m_styleHash[iter.key()]) { 0074 return false; 0075 } 0076 } 0077 0078 return true; 0079 } 0080 0081 bool GeoDataDocument::operator!=( const GeoDataDocument &other ) const 0082 { 0083 return !this->operator==( other ); 0084 } 0085 0086 const char* GeoDataDocument::nodeType() const 0087 { 0088 return GeoDataTypes::GeoDataDocumentType; 0089 } 0090 0091 0092 GeoDataFeature * GeoDataDocument::clone() const 0093 { 0094 return new GeoDataDocument(*this); 0095 } 0096 0097 DocumentRole GeoDataDocument::documentRole() const 0098 { 0099 Q_D(const GeoDataDocument); 0100 return d->m_documentRole; 0101 } 0102 0103 void GeoDataDocument::setDocumentRole( DocumentRole role ) 0104 { 0105 Q_D(GeoDataDocument); 0106 d->m_documentRole = role; 0107 } 0108 0109 QString GeoDataDocument::property() const 0110 { 0111 Q_D(const GeoDataDocument); 0112 return d->m_property; 0113 } 0114 0115 void GeoDataDocument::setProperty( const QString& property ) 0116 { 0117 Q_D(GeoDataDocument); 0118 d->m_property = property; 0119 } 0120 0121 QString GeoDataDocument::fileName() const 0122 { 0123 Q_D(const GeoDataDocument); 0124 return d->m_filename; 0125 } 0126 0127 void GeoDataDocument::setFileName( const QString &value ) 0128 { 0129 Q_D(GeoDataDocument); 0130 d->m_filename = value; 0131 } 0132 0133 QString GeoDataDocument::baseUri() const 0134 { 0135 Q_D(const GeoDataDocument); 0136 return d->m_baseUri; 0137 } 0138 0139 void GeoDataDocument::setBaseUri( const QString &baseUrl ) 0140 { 0141 Q_D(GeoDataDocument); 0142 d->m_baseUri = baseUrl; 0143 } 0144 0145 GeoDataNetworkLinkControl GeoDataDocument::networkLinkControl() const 0146 { 0147 Q_D(const GeoDataDocument); 0148 return d->m_networkLinkControl; 0149 } 0150 0151 void GeoDataDocument::setNetworkLinkControl( const GeoDataNetworkLinkControl &networkLinkControl ) 0152 { 0153 Q_D(GeoDataDocument); 0154 d->m_networkLinkControl = networkLinkControl; 0155 } 0156 0157 void GeoDataDocument::addStyle( const GeoDataStyle::Ptr &style ) 0158 { 0159 Q_D(GeoDataDocument); 0160 d->m_styleHash.insert(style->id(), style); 0161 d->m_styleHash[style->id()]->setParent(this); 0162 } 0163 0164 void GeoDataDocument::removeStyle( const QString& styleId ) 0165 { 0166 Q_D(GeoDataDocument); 0167 d->m_styleHash.remove(styleId); 0168 } 0169 0170 GeoDataStyle::Ptr GeoDataDocument::style( const QString& styleId ) 0171 { 0172 /* 0173 * FIXME: m_styleHash always should contain at least default 0174 * GeoDataStyle element 0175 */ 0176 Q_D(GeoDataDocument); 0177 return d->m_styleHash[styleId]; 0178 } 0179 0180 GeoDataStyle::ConstPtr GeoDataDocument::style( const QString &styleId ) const 0181 { 0182 Q_D(const GeoDataDocument); 0183 return d->m_styleHash.value(styleId); 0184 } 0185 0186 QList<GeoDataStyle::ConstPtr> GeoDataDocument::styles() const 0187 { 0188 Q_D(const GeoDataDocument); 0189 QList<GeoDataStyle::ConstPtr> result; 0190 for(auto const & style: d->m_styleHash.values()) { 0191 result << style; 0192 } 0193 0194 return result; 0195 } 0196 0197 QList<GeoDataStyle::Ptr> GeoDataDocument::styles() 0198 { 0199 Q_D(GeoDataDocument); 0200 return d->m_styleHash.values(); 0201 } 0202 0203 void GeoDataDocument::addStyleMap( const GeoDataStyleMap& map ) 0204 { 0205 Q_D(GeoDataDocument); 0206 d->m_styleMapHash.insert(map.id(), map); 0207 d->m_styleMapHash[map.id()].setParent(this); 0208 } 0209 0210 void GeoDataDocument::removeStyleMap( const QString& mapId ) 0211 { 0212 Q_D(GeoDataDocument); 0213 d->m_styleMapHash.remove(mapId); 0214 } 0215 0216 GeoDataStyleMap& GeoDataDocument::styleMap( const QString& styleId ) 0217 { 0218 Q_D(GeoDataDocument); 0219 return d->m_styleMapHash[styleId]; 0220 } 0221 0222 GeoDataStyleMap GeoDataDocument::styleMap( const QString &styleId ) const 0223 { 0224 Q_D(const GeoDataDocument); 0225 return d->m_styleMapHash.value(styleId); 0226 } 0227 0228 QList<GeoDataStyleMap> GeoDataDocument::styleMaps() const 0229 { 0230 Q_D(const GeoDataDocument); 0231 return d->m_styleMapHash.values(); 0232 } 0233 0234 void GeoDataDocument::addSchema( const GeoDataSchema& schema ) 0235 { 0236 Q_D(GeoDataDocument); 0237 d->m_schemaHash.insert(schema.id(), schema); 0238 d->m_schemaHash[schema.id()].setParent(this); 0239 } 0240 0241 void GeoDataDocument::removeSchema( const QString& schemaId ) 0242 { 0243 Q_D(GeoDataDocument); 0244 GeoDataSchema schema = d->m_schemaHash.take(schemaId); 0245 schema.setParent( nullptr ); 0246 } 0247 0248 GeoDataSchema GeoDataDocument::schema( const QString& schemaId ) const 0249 { 0250 Q_D(const GeoDataDocument); 0251 return d->m_schemaHash.value(schemaId); 0252 } 0253 0254 GeoDataSchema &GeoDataDocument::schema( const QString &schemaId ) 0255 { 0256 Q_D(GeoDataDocument); 0257 return d->m_schemaHash[schemaId]; 0258 } 0259 0260 QList<GeoDataSchema> GeoDataDocument::schemas() const 0261 { 0262 Q_D(const GeoDataDocument); 0263 return d->m_schemaHash.values(); 0264 } 0265 0266 void GeoDataDocument::pack( QDataStream& stream ) const 0267 { 0268 Q_D(const GeoDataDocument); 0269 GeoDataContainer::pack( stream ); 0270 0271 stream << d->m_styleHash.size(); 0272 0273 for( QMap<QString, GeoDataStyle::Ptr>::const_iterator iterator 0274 = d->m_styleHash.constBegin(); 0275 iterator != d->m_styleHash.constEnd(); 0276 ++iterator ) { 0277 iterator.value()->pack( stream ); 0278 } 0279 } 0280 0281 0282 void GeoDataDocument::unpack( QDataStream& stream ) 0283 { 0284 Q_D(GeoDataDocument); 0285 GeoDataContainer::unpack( stream ); 0286 0287 int size = 0; 0288 0289 stream >> size; 0290 for( int i = 0; i < size; i++ ) { 0291 GeoDataStyle::Ptr style; 0292 style->unpack( stream ); 0293 d->m_styleHash.insert(style->id(), style); 0294 } 0295 } 0296 0297 }