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 "GeoSceneMap.h" 0008 0009 #include "GeoSceneTypes.h" 0010 #include "GeoSceneLayer.h" 0011 #include "GeoSceneFilter.h" 0012 #include "DgmlAuxillaryDictionary.h" 0013 0014 #include <QColor> 0015 0016 #include <GeoDataCoordinates.h> 0017 0018 namespace Marble 0019 { 0020 0021 // FIXME: Filters are a Dataset. 0022 0023 class GeoSceneMapPrivate 0024 { 0025 public: 0026 GeoSceneMapPrivate() 0027 { 0028 } 0029 0030 ~GeoSceneMapPrivate() 0031 { 0032 qDeleteAll( m_layers ); 0033 qDeleteAll( m_filters ); 0034 } 0035 0036 QVariantList m_center; 0037 0038 /// The vector holding all the sections in the legend. 0039 /// (We want to preserve the order and don't care 0040 /// much about speed here), so we don't use a hash 0041 QVector<GeoSceneLayer*> m_layers; 0042 0043 /// The vector holding all the filters in the map. 0044 QVector<GeoSceneFilter*> m_filters; 0045 0046 QColor m_backgroundColor; 0047 QColor m_labelColor; 0048 0049 /// This color will be used to highlight 0050 /// a region when it's clicked on. 0051 QColor m_highlightBrushColor; 0052 QColor m_highlightPenColor; 0053 }; 0054 0055 0056 GeoSceneMap::GeoSceneMap() 0057 : d ( new GeoSceneMapPrivate ) 0058 { 0059 } 0060 0061 GeoSceneMap::~GeoSceneMap() 0062 { 0063 delete d; 0064 } 0065 0066 const char* GeoSceneMap::nodeType() const 0067 { 0068 return GeoSceneTypes::GeoSceneMapType; 0069 } 0070 0071 void GeoSceneMap::addLayer( GeoSceneLayer* layer ) 0072 { 0073 // Remove any layer that has the same name 0074 QVector<GeoSceneLayer*>::iterator it = d->m_layers.begin(); 0075 while (it != d->m_layers.end()) { 0076 GeoSceneLayer* currentLayer = *it; 0077 if ( currentLayer->name() == layer->name() ) { 0078 delete currentLayer; 0079 d->m_layers.erase(it); 0080 break; 0081 } 0082 else { 0083 ++it; 0084 } 0085 } 0086 0087 if ( layer ) { 0088 d->m_layers.append( layer ); 0089 } 0090 } 0091 0092 GeoSceneLayer* GeoSceneMap::layer( const QString& name ) 0093 { 0094 GeoSceneLayer* layer = nullptr; 0095 0096 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin(); 0097 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd(); 0098 for (; it != end; ++it) { 0099 if ( (*it)->name() == name ) { 0100 layer = *it; 0101 break; 0102 } 0103 } 0104 0105 if ( !layer ) { 0106 layer = new GeoSceneLayer( name ); 0107 addLayer( layer ); 0108 } 0109 0110 return layer; 0111 } 0112 0113 const GeoSceneLayer* GeoSceneMap::layer( const QString& name ) const 0114 { 0115 const GeoSceneLayer* layer = nullptr; 0116 0117 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin(); 0118 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd(); 0119 for (; it != end; ++it) { 0120 if ( (*it)->name() == name ) { 0121 layer = *it; 0122 break; 0123 } 0124 } 0125 return layer; 0126 } 0127 0128 QVector<GeoSceneLayer*> GeoSceneMap::layers() const 0129 { 0130 return d->m_layers; 0131 } 0132 0133 void GeoSceneMap::addFilter( GeoSceneFilter* filter ) 0134 { 0135 // Remove any filter that has the same name 0136 QVector<GeoSceneFilter*>::iterator it = d->m_filters.begin(); 0137 while (it != d->m_filters.end()) { 0138 GeoSceneFilter* currentFilter = *it; 0139 if ( currentFilter->name() == filter->name() ) { 0140 delete currentFilter; 0141 d->m_filters.erase(it); 0142 break; 0143 } 0144 else { 0145 ++it; 0146 } 0147 } 0148 0149 if ( filter ) { 0150 d->m_filters.append( filter ); 0151 } 0152 } 0153 0154 QVariantList GeoSceneMap::center() const 0155 { 0156 return d->m_center; 0157 } 0158 0159 void GeoSceneMap::setCenter(const QString & coordinatesString) 0160 { 0161 QStringList coordinatesList = coordinatesString.split(QLatin1String(",")); 0162 if (coordinatesList.count() == 2) { 0163 bool success = false; 0164 const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success); 0165 0166 if ( success ) { 0167 QVariantList lonLat; 0168 lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) ) 0169 << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) ); 0170 d->m_center = lonLat; 0171 } 0172 } 0173 // LatLonBox 0174 else if (coordinatesList.count() == 4) { 0175 QVariantList northSouthEastWest; 0176 d->m_center << QVariant(coordinatesList.at(0)) << QVariant(coordinatesList.at(1)) 0177 << QVariant(coordinatesList.at(2)) << QVariant(coordinatesList.at(3)); 0178 } 0179 } 0180 0181 GeoSceneFilter* GeoSceneMap::filter( const QString& name ) 0182 { 0183 GeoSceneFilter* filter = nullptr; 0184 0185 QVector<GeoSceneFilter*>::const_iterator it = d->m_filters.constBegin(); 0186 QVector<GeoSceneFilter*>::const_iterator end = d->m_filters.constEnd(); 0187 for (; it != end; ++it) { 0188 if ( (*it)->name() == name ) { 0189 filter = *it; 0190 break; 0191 } 0192 } 0193 0194 if ( !filter ) { 0195 filter = new GeoSceneFilter( name ); 0196 addFilter( filter ); 0197 } 0198 0199 return filter; 0200 } 0201 0202 QVector<GeoSceneFilter*> GeoSceneMap::filters() const 0203 { 0204 return d->m_filters; 0205 } 0206 0207 bool GeoSceneMap::hasTextureLayers() const 0208 { 0209 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin(); 0210 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd(); 0211 for (; it != end; ++it) { 0212 if (((*it)->backend() == QLatin1String(dgml::dgmlValue_texture) || 0213 (*it)->backend() == QLatin1String(dgml::dgmlValue_vectortile)) && (*it)->datasets().count() > 0) 0214 return true; 0215 } 0216 0217 return false; 0218 } 0219 0220 bool GeoSceneMap::hasVectorLayers() const 0221 { 0222 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin(); 0223 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd(); 0224 for (; it != end; ++it) { 0225 if (((*it)->backend() == QLatin1String(dgml::dgmlValue_vectortile) || 0226 (*it)->backend() == QLatin1String(dgml::dgmlValue_vector)) && (*it)->datasets().count() > 0) 0227 return true; 0228 } 0229 0230 return false; 0231 } 0232 0233 QColor GeoSceneMap::backgroundColor() const 0234 { 0235 return d->m_backgroundColor; 0236 } 0237 0238 void GeoSceneMap::setBackgroundColor( const QColor& backgroundColor ) 0239 { 0240 d->m_backgroundColor = backgroundColor; 0241 } 0242 0243 0244 QColor GeoSceneMap::labelColor() const 0245 { 0246 return d->m_labelColor; 0247 } 0248 0249 void GeoSceneMap::setLabelColor( const QColor& backgroundColor ) 0250 { 0251 d->m_labelColor = backgroundColor; 0252 } 0253 0254 QColor GeoSceneMap::highlightBrushColor() const 0255 { 0256 return d->m_highlightBrushColor; 0257 } 0258 0259 void GeoSceneMap::setHighlightBrushColor( const QColor & highlightBrushColor ) 0260 { 0261 d->m_highlightBrushColor = highlightBrushColor; 0262 } 0263 0264 QColor GeoSceneMap::highlightPenColor() const 0265 { 0266 return d->m_highlightPenColor; 0267 } 0268 0269 void GeoSceneMap::setHighlightPenColor( const QColor &highlightPenColor ) 0270 { 0271 d->m_highlightPenColor = highlightPenColor; 0272 } 0273 0274 }