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 "GeoSceneLegend.h" 0008 0009 #include "GeoSceneTypes.h" 0010 #include "GeoSceneSection.h" 0011 0012 namespace Marble 0013 { 0014 0015 class GeoSceneLegendPrivate 0016 { 0017 public: 0018 ~GeoSceneLegendPrivate() 0019 { 0020 qDeleteAll( m_sections ); 0021 } 0022 0023 /// The vector holding all the sections in the legend. 0024 /// (We want to preserve the order and don't care 0025 /// much about speed here), so we don't use a hash 0026 QVector<const GeoSceneSection*> m_sections; 0027 }; 0028 0029 0030 GeoSceneLegend::GeoSceneLegend() 0031 : d( new GeoSceneLegendPrivate ) 0032 { 0033 } 0034 0035 GeoSceneLegend::~GeoSceneLegend() 0036 { 0037 delete d; 0038 } 0039 0040 const char* GeoSceneLegend::nodeType() const 0041 { 0042 return GeoSceneTypes::GeoSceneLegendType; 0043 } 0044 0045 void GeoSceneLegend::addSection( const GeoSceneSection* section ) 0046 { 0047 // Remove any section that has the same name 0048 QVector<const GeoSceneSection*>::iterator it = d->m_sections.begin(); 0049 while (it != d->m_sections.end()) { 0050 const GeoSceneSection* currentSection = *it; 0051 if ( currentSection->name() == section->name() ) { 0052 delete currentSection; 0053 d->m_sections.erase(it); 0054 break; 0055 } 0056 else { 0057 ++it; 0058 } 0059 } 0060 0061 if ( section ) { 0062 d->m_sections.append( section ); 0063 } 0064 } 0065 0066 QVector<const GeoSceneSection*> GeoSceneLegend::sections() const 0067 { 0068 return d->m_sections; 0069 } 0070 0071 }