Marble

GeoSceneGroup.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "GeoSceneGroup.h"
8
9#include "MarbleDebug.h"
10
11#include "GeoSceneProperty.h"
12#include "GeoSceneTypes.h"
13
14namespace Marble
15{
16
17GeoSceneGroup::GeoSceneGroup( const QString& name )
18 : m_name( name )
19{
20}
21
22GeoSceneGroup::~GeoSceneGroup()
23{
24 qDeleteAll( m_properties );
25}
26
27bool GeoSceneGroup::propertyAvailable( const QString& name, bool& available ) const
28{
29 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
30 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
31 for (; it != end; ++it) {
32 if ( (*it)->name() == name ) {
33 available = (*it)->available();
34 return true;
35 }
36 }
37
38 available = false;
39
40 return false;
41}
42
43bool GeoSceneGroup::setPropertyValue( const QString& name, bool value )
44{
45 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
46 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
47 for (; it != end; ++it) {
48 if ( (*it)->name() == name ) {
49 (*it)->setValue( value );
50 emit valueChanged( name, value );
51 return true;
52 }
53 }
54
55 return false;
56}
57
58bool GeoSceneGroup::propertyValue( const QString& name, bool& value ) const
59{
60 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
61 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
62 for (; it != end; ++it) {
63 if ( (*it)->name() == name ) {
64 value = (*it)->value();
65 return true;
66 }
67 }
68
69 value = false;
70
71 return false;
72}
73
74void GeoSceneGroup::addProperty( GeoSceneProperty* property )
75{
76 Q_ASSERT(property);
77 if (!property) {
78 return;
79 }
80
81 // Remove any property that has the same name
82 QVector<GeoSceneProperty*>::iterator it = m_properties.begin();
83 while (it != m_properties.end()) {
84 GeoSceneProperty* currentProperty = *it;
85 if ( currentProperty->name() == property->name() ) {
86 delete currentProperty;
87 m_properties.erase(it);
88 break;
89 }
90 else {
91 ++it;
92 }
93 }
94
95 m_properties.append( property );
96
97 // Establish connection to the outside, e.g. the LegendBrowser
98 connect ( property, SIGNAL(valueChanged(QString,bool)),
99 SIGNAL(valueChanged(QString,bool)) );
100 emit valueChanged( property->name(), property->value() );
101}
102
103const GeoSceneProperty* GeoSceneGroup::property( const QString& name ) const
104{
105 GeoSceneProperty* property = nullptr;
106
107 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
108 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
109 for (; it != end; ++it) {
110 if ( (*it)->name() == name ) {
111 property = *it;
112 break;
113 }
114 }
115
116 return property;
117}
118
119// implement non-const method by means of const method,
120// for details, see "Effective C++" (third edition)
121GeoSceneProperty* GeoSceneGroup::property( const QString& name )
122{
123 return const_cast<GeoSceneProperty*>
124 ( static_cast<GeoSceneGroup const *>( this )->property( name ));
125}
126
127QVector<GeoSceneProperty*> GeoSceneGroup::properties()
128{
129 return m_properties;
130}
131
132QVector<const GeoSceneProperty*> GeoSceneGroup::properties() const
133{
135 result.reserve(m_properties.size());
136
137 for ( const GeoSceneProperty *property: m_properties ) {
138 result << property;
139 }
140
141 return result;
142}
143
144QString GeoSceneGroup::name() const
145{
146 return m_name;
147}
148
149const char *GeoSceneGroup::nodeType() const
150{
151 return GeoSceneTypes::GeoSceneGroupType;
152}
153
154}
155
156#include "moc_GeoSceneGroup.cpp"
Settings property within a GeoScene document.
QString name(StandardShortcut id)
Binds a QML item to a specific geodetic location in screen coordinates.
void reserve(qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.