Marble

GeoSceneSettings.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Torsten Rahn <[email protected]>
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 
15 namespace Marble
16 {
17 
18 class 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;
29  QVector<GeoSceneGroup*> m_groups;
30 };
31 
32 
33 GeoSceneSettings::GeoSceneSettings()
34  : d( new GeoSceneSettingsPrivate )
35 {
36 }
37 
38 GeoSceneSettings::~GeoSceneSettings()
39 {
40  delete d;
41 }
42 
43 const char* GeoSceneSettings::nodeType() const
44 {
45  return GeoSceneTypes::GeoSceneSettingsType;
46 }
47 
48 bool 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 
73 bool GeoSceneSettings::setPropertyValue( const QString& name, bool value )
74 {
75  mDebug() << "GeoSceneSettings: Property " << 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 
98 bool 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 
124 {
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 
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 ) {
151  }
152 
153  return allProperties;
154 }
155 
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 
181 const 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)
200 {
201  return const_cast<GeoSceneGroup*>( static_cast<GeoSceneSettings const *>( this )->group( name ));
202 }
203 
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 
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)
249 {
250  return const_cast<GeoSceneProperty*>
251  ( static_cast<GeoSceneSettings const *>( this )->property( name ));
252 }
253 
255 {
256  return d->m_properties;
257 }
258 
259 }
260 
261 #include "moc_GeoSceneSettings.cpp"
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
void addProperty(GeoSceneProperty *property)
Add a property to the settings.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addGroup(GeoSceneGroup *group)
Add a group to the settings.
Group inside the settings of a GeoScene document.
Definition: GeoSceneGroup.h:25
Settings property within a GeoScene document.
Binds a QML item to a specific geodetic location in screen coordinates.
Settings of a GeoScene document.
const GeoSceneProperty * property(const QString &name) const
Get a property from the settings.
QVector< GeoSceneProperty * > allProperties()
Get the whole list of properties stored in the settings.
bool setPropertyValue(const QString &name, bool value)
Set the value of a property across groups.
QVector< GeoSceneProperty * > rootProperties()
Get the properties that are categorized into groups.
bool propertyValue(const QString &name, bool &value) const
Get the value of a property across groups.
bool propertyAvailable(const QString &name, bool &available) const
Get the availability of a property across groups.
const GeoSceneGroup * group(const QString &name) const
Get a group from the settings.
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:02:29 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.