File indexing completed on 2025-01-05 03:59:11
0001 /* 0002 SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "GeoSceneLayer.h" 0008 0009 #include "GeoSceneAbstractDataset.h" 0010 #include "GeoSceneFilter.h" 0011 #include "GeoSceneTypes.h" 0012 0013 namespace Marble 0014 { 0015 0016 class GeoSceneLayerPrivate 0017 { 0018 public: 0019 GeoSceneLayerPrivate(const QString &name); 0020 ~GeoSceneLayerPrivate(); 0021 0022 /// The vector holding all the data in the layer. 0023 /// (We want to preserve the order and don't care 0024 /// much about speed here), so we don't use a hash 0025 QVector<GeoSceneAbstractDataset *> m_datasets; 0026 0027 GeoSceneFilter *m_filter; 0028 0029 QString m_name; 0030 QString m_backend; 0031 QString m_role; 0032 0033 bool m_tiled; 0034 }; 0035 0036 GeoSceneLayerPrivate::GeoSceneLayerPrivate(const QString &name) : 0037 m_filter(nullptr), 0038 m_name(name), 0039 m_backend(), 0040 m_role(), 0041 m_tiled(true) 0042 { 0043 } 0044 0045 GeoSceneLayerPrivate::~GeoSceneLayerPrivate() 0046 { 0047 qDeleteAll(m_datasets); 0048 } 0049 0050 GeoSceneLayer::GeoSceneLayer(const QString &name) : 0051 d(new GeoSceneLayerPrivate(name)) 0052 { 0053 } 0054 0055 GeoSceneLayer::~GeoSceneLayer() 0056 { 0057 delete d; 0058 } 0059 0060 const char* GeoSceneLayer::nodeType() const 0061 { 0062 return GeoSceneTypes::GeoSceneLayerType; 0063 } 0064 0065 void GeoSceneLayer::addDataset( GeoSceneAbstractDataset* dataset ) 0066 { 0067 // Remove any dataset that has the same name 0068 QVector<GeoSceneAbstractDataset *>::iterator it = d->m_datasets.begin(); 0069 while (it != d->m_datasets.end()) { 0070 GeoSceneAbstractDataset * currentAbstractDataset = *it; 0071 if ( currentAbstractDataset->name() == dataset->name() ) { 0072 delete currentAbstractDataset; 0073 d->m_datasets.erase(it); 0074 break; 0075 } 0076 else { 0077 ++it; 0078 } 0079 } 0080 0081 if ( dataset ) { 0082 d->m_datasets.append( dataset ); 0083 } 0084 } 0085 0086 const GeoSceneAbstractDataset* GeoSceneLayer::dataset( const QString& name ) const 0087 { 0088 GeoSceneAbstractDataset* dataset = nullptr; 0089 0090 QVector<GeoSceneAbstractDataset*>::const_iterator it = d->m_datasets.constBegin(); 0091 QVector<GeoSceneAbstractDataset*>::const_iterator end = d->m_datasets.constEnd(); 0092 for (; it != end; ++it) { 0093 if ( (*it)->name() == name ) { 0094 dataset = *it; 0095 break; 0096 } 0097 } 0098 return dataset; 0099 } 0100 0101 // implement non-const method by means of const method, 0102 // for details, see "Effective C++" (third edition) 0103 GeoSceneAbstractDataset* GeoSceneLayer::dataset( const QString& name ) 0104 { 0105 return const_cast<GeoSceneAbstractDataset*> 0106 ( static_cast<GeoSceneLayer const *>( this )->dataset( name )); 0107 } 0108 0109 const GeoSceneAbstractDataset * GeoSceneLayer::groundDataset() const 0110 { 0111 if (d->m_datasets.isEmpty()) 0112 return nullptr; 0113 0114 return d->m_datasets.first(); 0115 } 0116 0117 // implement non-const method by means of const method, 0118 // for details, see "Effective C++" (third edition) 0119 GeoSceneAbstractDataset * GeoSceneLayer::groundDataset() 0120 { 0121 return const_cast<GeoSceneAbstractDataset*> 0122 ( static_cast<GeoSceneLayer const *>( this )->groundDataset() ); 0123 } 0124 0125 QVector<GeoSceneAbstractDataset *> GeoSceneLayer::datasets() const 0126 { 0127 return d->m_datasets; 0128 } 0129 0130 QString GeoSceneLayer::name() const 0131 { 0132 return d->m_name; 0133 } 0134 0135 QString GeoSceneLayer::backend() const 0136 { 0137 return d->m_backend; 0138 } 0139 0140 void GeoSceneLayer::setBackend( const QString& backend ) 0141 { 0142 d->m_backend = backend; 0143 } 0144 0145 bool GeoSceneLayer::isTiled() const 0146 { 0147 return d->m_tiled; 0148 } 0149 0150 void GeoSceneLayer::setTiled( bool tiled ) 0151 { 0152 d->m_tiled = tiled; 0153 } 0154 0155 QString GeoSceneLayer::role() const 0156 { 0157 return d->m_role; 0158 } 0159 0160 void GeoSceneLayer::setRole( const QString& role ) 0161 { 0162 d->m_role = role; 0163 } 0164 0165 const GeoSceneFilter* GeoSceneLayer::filter() const 0166 { 0167 return d->m_filter; 0168 } 0169 0170 GeoSceneFilter* GeoSceneLayer::filter() 0171 { 0172 return d->m_filter; 0173 } 0174 0175 void GeoSceneLayer::addFilter( GeoSceneFilter * filter ) 0176 { 0177 d->m_filter = filter; 0178 } 0179 0180 void GeoSceneLayer::removeFilter( GeoSceneFilter * filter ) 0181 { 0182 if (filter == d->m_filter) { 0183 d->m_filter = nullptr; 0184 } 0185 } 0186 0187 }