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

KDE's Doxygen guidelines are available online.