Marble

GeoSceneSettings.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 "GeoSceneSettings.h"
8
9#include "MarbleDebug.h"
10
11#include "GeoSceneProperty.h"
12#include "GeoSceneGroup.h"
13#include "GeoSceneTypes.h"
14
15namespace Marble
16{
17
18class GeoSceneSettingsPrivate
19{
20 public:
21 ~GeoSceneSettingsPrivate()
22 {
23 qDeleteAll(m_properties);
24 qDeleteAll(m_groups);
25 }
26
27 /// The hash table holding all the properties in the settings.
28 QVector<GeoSceneProperty*> m_properties;
30};
31
32
33GeoSceneSettings::GeoSceneSettings()
34 : d( new GeoSceneSettingsPrivate )
35{
36}
37
38GeoSceneSettings::~GeoSceneSettings()
39{
40 delete d;
41}
42
43const char* GeoSceneSettings::nodeType() const
44{
45 return GeoSceneTypes::GeoSceneSettingsType;
46}
47
48bool GeoSceneSettings::propertyAvailable( const QString& name, bool& available ) const
49{
50 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
51 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
52 for (; it != propEnd; ++it) {
53 if ( (*it)->name() == name ) {
54 available = (*it)->available();
55 return true;
56 }
57 }
58
59 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
60 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
61 for (; itGroup != groupEnd; ++itGroup) {
62 bool success = (*itGroup)->propertyAvailable( name, available );
63 if ( success ) {
64 return true;
65 }
66 }
67
68 available = false;
69
70 return false;
71}
72
73bool GeoSceneSettings::setPropertyValue( const QString& name, bool value )
74{
75 mDebug() << name << "to" << value;
76
77 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
78 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
79 for (; it != propEnd; ++it) {
80 if ( (*it)->name() == name ) {
81 (*it)->setValue( value );
82 return true;
83 }
84 }
85
86 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
87 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
88 for (; itGroup != groupEnd; ++itGroup) {
89 bool success = (*itGroup)->setPropertyValue( name, value );
90 if ( success ) {
91 return true;
92 }
93 }
94
95 return false;
96}
97
98bool GeoSceneSettings::propertyValue( const QString& name, bool& value ) const
99{
100 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
101 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
102 for (; it != propEnd; ++it) {
103 if ( (*it)->name() == name ) {
104 value = (*it)->value();
105 return true;
106 }
107 }
108
109 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
110 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
111 for (; itGroup != groupEnd; ++itGroup) {
112 bool success = (*itGroup)->propertyValue( name, value );
113 if ( success ) {
114 return true;
115 }
116 }
117
118 value = false;
119
120 return false;
121}
122
123QVector<GeoSceneProperty*> GeoSceneSettings::allProperties()
124{
125 QVector<GeoSceneProperty*> allProperties;
126
127 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
128 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
129 for (; itGroup != groupEnd; ++itGroup) {
130 allProperties << (*itGroup)->properties();
131 }
132
133 allProperties << d->m_properties;
134
135 return allProperties;
136}
137
138QVector<const GeoSceneProperty*> GeoSceneSettings::allProperties() const
139{
141
142 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
143 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
144 for (; itGroup != groupEnd; ++itGroup) {
145 allProperties << const_cast<const GeoSceneGroup*>(*itGroup)->properties();
146 }
147
148 allProperties.reserve(allProperties.size() + d->m_properties.size());
149 for ( const GeoSceneProperty *property: d->m_properties ) {
150 allProperties << property;
151 }
152
153 return allProperties;
154}
155
156void GeoSceneSettings::addGroup( GeoSceneGroup* group )
157{
158 // Remove any property that has the same name
159 QVector<GeoSceneGroup*>::iterator it = d->m_groups.begin();
160 while (it != d->m_groups.end()) {
161 GeoSceneGroup* currentGroup = *it;
162 if ( currentGroup->name() == group->name() ) {
163 delete currentGroup;
164 d->m_groups.erase(it);
165 break;
166 }
167 else {
168 ++it;
169 }
170 }
171
172 if ( group ) {
173 d->m_groups.append( group );
174
175 // Establish connection to the outside, e.g. the LegendBrowser
176 connect ( group, SIGNAL(valueChanged(QString,bool)),
177 SIGNAL(valueChanged(QString,bool)) );
178 }
179}
180
181const GeoSceneGroup* GeoSceneSettings::group( const QString& name ) const
182{
183 GeoSceneGroup* group = nullptr;
184
185 QVector<GeoSceneGroup*>::const_iterator it = d->m_groups.constBegin();
186 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
187 for (; it != groupEnd; ++it) {
188 if ( (*it)->name() == name ) {
189 group = *it;
190 break;
191 }
192 }
193
194 return group;
195}
196
197// implement non-const method by means of const method,
198// for details, see "Effective C++" (third edition)
199GeoSceneGroup* GeoSceneSettings::group( const QString& name )
200{
201 return const_cast<GeoSceneGroup*>( static_cast<GeoSceneSettings const *>( this )->group( name ));
202}
203
204void GeoSceneSettings::addProperty( GeoSceneProperty* property )
205{
206 // Remove any property that has the same name
207 QVector<GeoSceneProperty*>::iterator it = d->m_properties.begin();
208 while (it != d->m_properties.end()) {
209 GeoSceneProperty* currentProperty = *it;
210 if ( currentProperty->name() == property->name() ) {
211 delete currentProperty;
212 d->m_properties.erase(it);
213 break;
214 }
215 else {
216 ++it;
217 }
218 }
219
220 if ( property ) {
221 d->m_properties.append( property );
222
223 // Establish connection to the outside, e.g. the LegendBrowser
224 connect ( property, SIGNAL(valueChanged(QString,bool)),
225 SIGNAL(valueChanged(QString,bool)) );
226 emit valueChanged( property->name(), property->value() );
227 }
228}
229
230const GeoSceneProperty* GeoSceneSettings::property( const QString& name ) const
231{
232 GeoSceneProperty* property = nullptr;
233
234 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
235 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
236 for (; it != propEnd; ++it) {
237 if ( (*it)->name() == name ) {
238 property = *it;
239 break;
240 }
241 }
242
243 return property;
244}
245
246// implement non-const method by means of const method,
247// for details, see "Effective C++" (third edition)
248GeoSceneProperty* GeoSceneSettings::property( const QString& name )
249{
250 return const_cast<GeoSceneProperty*>
251 ( static_cast<GeoSceneSettings const *>( this )->property( name ));
252}
253
254QVector<GeoSceneProperty*> GeoSceneSettings::rootProperties()
255{
256 return d->m_properties;
257}
258
259}
260
261#include "moc_GeoSceneSettings.cpp"
Group inside the settings of a GeoScene document.
Settings property within a GeoScene document.
Settings of a GeoScene document.
Binds a QML item to a specific geodetic location in screen coordinates.
void reserve(qsizetype size)
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.