1 /*
2     SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "GeoSceneLegend.h"
8 
9 #include "GeoSceneTypes.h"
10 #include "GeoSceneSection.h"
11 
12 namespace Marble
13 {
14 
15 class GeoSceneLegendPrivate
16 {
17   public:
~GeoSceneLegendPrivate()18     ~GeoSceneLegendPrivate()
19     {
20         qDeleteAll( m_sections );
21     }
22 
23      /// The vector holding all the sections in the legend.
24     /// (We want to preserve the order and don't care
25     /// much about speed here), so we don't use a hash
26     QVector<const GeoSceneSection*> m_sections;
27 };
28 
29 
GeoSceneLegend()30 GeoSceneLegend::GeoSceneLegend()
31     : d( new GeoSceneLegendPrivate )
32 {
33 }
34 
~GeoSceneLegend()35 GeoSceneLegend::~GeoSceneLegend()
36 {
37     delete d;
38 }
39 
nodeType() const40 const char* GeoSceneLegend::nodeType() const
41 {
42     return GeoSceneTypes::GeoSceneLegendType;
43 }
44 
addSection(const GeoSceneSection * section)45 void GeoSceneLegend::addSection( const GeoSceneSection* section )
46 {
47     // Remove any section that has the same name
48     QVector<const GeoSceneSection*>::iterator it = d->m_sections.begin();
49     while (it != d->m_sections.end()) {
50         const GeoSceneSection* currentSection = *it;
51         if ( currentSection->name() == section->name() ) {
52             delete currentSection;
53             d->m_sections.erase(it);
54             break;
55         }
56         else {
57             ++it;
58         }
59      }
60 
61     if ( section ) {
62         d->m_sections.append( section );
63     }
64 }
65 
sections() const66 QVector<const GeoSceneSection*> GeoSceneLegend::sections() const
67 {
68     return d->m_sections;
69 }
70 
71 }
72