• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • scene
GeoSceneSettings.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 Torsten Rahn <rahn@kde.org>
3 
4  This file is part of the KDE project
5 
6  This library is free software you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  aint with this library see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "GeoSceneSettings.h"
23 
24 #include "MarbleDebug.h"
25 
26 #include "GeoSceneProperty.h"
27 #include "GeoSceneGroup.h"
28 #include "GeoSceneTypes.h"
29 
30 namespace Marble
31 {
32 
33 class GeoSceneSettingsPrivate
34 {
35  public:
36  ~GeoSceneSettingsPrivate()
37  {
38  qDeleteAll(m_properties);
39  qDeleteAll(m_groups);
40  }
41 
43  QVector<GeoSceneProperty*> m_properties;
44  QVector<GeoSceneGroup*> m_groups;
45 
46  const char* nodeType() const
47  {
48  return GeoSceneTypes::GeoSceneSettingsType;
49  }
50 };
51 
52 
53 GeoSceneSettings::GeoSceneSettings()
54  : d( new GeoSceneSettingsPrivate )
55 {
56 }
57 
58 GeoSceneSettings::~GeoSceneSettings()
59 {
60  delete d;
61 }
62 
63 const char* GeoSceneSettings::nodeType() const
64 {
65  return d->nodeType();
66 }
67 
68 bool GeoSceneSettings::propertyAvailable( const QString& name, bool& available ) const
69 {
70  QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
71  QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
72  for (; it != propEnd; ++it) {
73  if ( (*it)->name() == name ) {
74  available = (*it)->available();
75  return true;
76  }
77  }
78 
79  QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
80  QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
81  for (; itGroup != groupEnd; ++itGroup) {
82  bool success = (*itGroup)->propertyAvailable( name, available );
83  if ( success ) {
84  return true;
85  }
86  }
87 
88  available = false;
89 
90  return false;
91 }
92 
93 bool GeoSceneSettings::setPropertyValue( const QString& name, bool value )
94 {
95  mDebug() << "GeoSceneSettings: Property " << name << "to" << value;
96 
97  QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
98  QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
99  for (; it != propEnd; ++it) {
100  if ( (*it)->name() == name ) {
101  (*it)->setValue( value );
102  return true;
103  }
104  }
105 
106  QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
107  QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
108  for (; itGroup != groupEnd; ++itGroup) {
109  bool success = (*itGroup)->setPropertyValue( name, value );
110  if ( success ) {
111  return true;
112  }
113  }
114 
115  return false;
116 }
117 
118 bool GeoSceneSettings::propertyValue( const QString& name, bool& value ) const
119 {
120  QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
121  QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
122  for (; it != propEnd; ++it) {
123  if ( (*it)->name() == name ) {
124  value = (*it)->value();
125  return true;
126  }
127  }
128 
129  QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
130  QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
131  for (; itGroup != groupEnd; ++itGroup) {
132  bool success = (*itGroup)->propertyValue( name, value );
133  if ( success ) {
134  return true;
135  }
136  }
137 
138  value = false;
139 
140  return false;
141 }
142 
143 QVector<GeoSceneProperty*> GeoSceneSettings::allProperties()
144 {
145  QVector<GeoSceneProperty*> allProperties;
146 
147  QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
148  QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
149  for (; itGroup != groupEnd; ++itGroup) {
150  allProperties << (*itGroup)->properties();
151  }
152 
153  allProperties << d->m_properties;
154 
155  return allProperties;
156 }
157 
158 QVector<const GeoSceneProperty*> GeoSceneSettings::allProperties() const
159 {
160  QVector<const GeoSceneProperty*> allProperties;
161 
162  QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin();
163  QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
164  for (; itGroup != groupEnd; ++itGroup) {
165  allProperties << const_cast<const GeoSceneGroup*>(*itGroup)->properties();
166  }
167 
168  foreach ( const GeoSceneProperty *property, d->m_properties ) {
169  allProperties << property;
170  }
171 
172  return allProperties;
173 }
174 
175 void GeoSceneSettings::addGroup( GeoSceneGroup* group )
176 {
177  // Remove any property that has the same name
178  QVector<GeoSceneGroup*>::iterator it = d->m_groups.begin();
179  while (it != d->m_groups.end()) {
180  GeoSceneGroup* currentGroup = *it;
181  if ( currentGroup->name() == group->name() ) {
182  delete currentGroup;
183  it = d->m_groups.erase(it);
184  break;
185  }
186  else {
187  ++it;
188  }
189  }
190 
191  if ( group ) {
192  d->m_groups.append( group );
193 
194  // Establish connection to the outside, e.g. the LegendBrowser
195  connect ( group, SIGNAL(valueChanged(QString,bool)),
196  SIGNAL(valueChanged(QString,bool)) );
197  }
198 }
199 
200 const GeoSceneGroup* GeoSceneSettings::group( const QString& name ) const
201 {
202  GeoSceneGroup* group = 0;
203 
204  QVector<GeoSceneGroup*>::const_iterator it = d->m_groups.constBegin();
205  QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd();
206  for (; it != groupEnd; ++it) {
207  if ( (*it)->name() == name ) {
208  group = *it;
209  break;
210  }
211  }
212 
213  return group;
214 }
215 
216 // implement non-const method by means of const method,
217 // for details, see "Effective C++" (third edition)
218 GeoSceneGroup* GeoSceneSettings::group( const QString& name )
219 {
220  return const_cast<GeoSceneGroup*>( static_cast<GeoSceneSettings const *>( this )->group( name ));
221 }
222 
223 void GeoSceneSettings::addProperty( GeoSceneProperty* property )
224 {
225  // Remove any property that has the same name
226  QVector<GeoSceneProperty*>::iterator it = d->m_properties.begin();
227  while (it != d->m_properties.end()) {
228  GeoSceneProperty* currentProperty = *it;
229  if ( currentProperty->name() == property->name() ) {
230  delete currentProperty;
231  it = d->m_properties.erase(it);
232  break;
233  }
234  else {
235  ++it;
236  }
237  }
238 
239  if ( property ) {
240  d->m_properties.append( property );
241 
242  // Establish connection to the outside, e.g. the LegendBrowser
243  connect ( property, SIGNAL(valueChanged(QString,bool)),
244  SIGNAL(valueChanged(QString,bool)) );
245  emit valueChanged( property->name(), property->value() );
246  }
247 }
248 
249 const GeoSceneProperty* GeoSceneSettings::property( const QString& name ) const
250 {
251  GeoSceneProperty* property = 0;
252 
253  QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin();
254  QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd();
255  for (; it != propEnd; ++it) {
256  if ( (*it)->name() == name ) {
257  property = *it;
258  break;
259  }
260  }
261 
262  return property;
263 }
264 
265 // implement non-const method by means of const method,
266 // for details, see "Effective C++" (third edition)
267 GeoSceneProperty* GeoSceneSettings::property( const QString& name )
268 {
269  return const_cast<GeoSceneProperty*>
270  ( static_cast<GeoSceneSettings const *>( this )->property( name ));
271 }
272 
273 QVector<GeoSceneProperty*> GeoSceneSettings::rootProperties()
274 {
275  return d->m_properties;
276 }
277 
278 }
279 
280 #include "GeoSceneSettings.moc"
GeoSceneTypes.h
GeoSceneProperty.h
Marble::GeoSceneSettings
Settings of a GeoScene document.
Definition: GeoSceneSettings.h:44
Marble::GeoSceneSettings::rootProperties
QVector< GeoSceneProperty * > rootProperties()
Get the properties that are categorized into groups.
Definition: GeoSceneSettings.cpp:273
Marble::GeoSceneSettings::GeoSceneSettings
GeoSceneSettings()
Definition: GeoSceneSettings.cpp:53
Marble::GeoSceneProperty
Settings property within a GeoScene document.
Definition: GeoSceneProperty.h:39
GeoSceneGroup.h
MarbleDebug.h
Marble::GeoSceneGroup::name
QString name() const
Definition: GeoSceneGroup.cpp:154
Marble::GeoSceneSettings::propertyAvailable
bool propertyAvailable(const QString &name, bool &available) const
Get the availability of a property across groups.
Definition: GeoSceneSettings.cpp:68
Marble::GeoSceneGroup
Group inside the settings of a GeoScene document.
Definition: GeoSceneGroup.h:40
Marble::GeoSceneSettings::propertyValue
bool propertyValue(const QString &name, bool &value) const
Get the value of a property across groups.
Definition: GeoSceneSettings.cpp:118
Marble::GeoSceneSettings::property
const GeoSceneProperty * property(const QString &name) const
Get a property from the settings.
Definition: GeoSceneSettings.cpp:249
Marble::GeoSceneSettings::setPropertyValue
bool setPropertyValue(const QString &name, bool value)
Set the value of a property across groups.
Definition: GeoSceneSettings.cpp:93
GeoSceneSettings.h
Marble::GeoSceneSettings::addGroup
void addGroup(GeoSceneGroup *group)
Add a group to the settings.
Definition: GeoSceneSettings.cpp:175
Marble::GeoSceneSettings::~GeoSceneSettings
virtual ~GeoSceneSettings()
Definition: GeoSceneSettings.cpp:58
Marble::GeoSceneProperty::name
QString name() const
Definition: GeoSceneProperty.cpp:43
Marble::GeoSceneSettings::valueChanged
void valueChanged(QString, bool)
Marble::GeoSceneSettings::nodeType
virtual const char * nodeType() const
Definition: GeoSceneSettings.cpp:63
Marble::GeoSceneSettings::group
const GeoSceneGroup * group(const QString &name) const
Get a group from the settings.
Definition: GeoSceneSettings.cpp:200
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::GeoSceneSettings::allProperties
QVector< GeoSceneProperty * > allProperties()
Get the whole list of properties stored in the settings.
Definition: GeoSceneSettings.cpp:143
Marble::GeoSceneTypes::GeoSceneSettingsType
const char * GeoSceneSettingsType
Definition: GeoSceneTypes.cpp:31
Marble::GeoSceneSettings::addProperty
void addProperty(GeoSceneProperty *property)
Add a property to the settings.
Definition: GeoSceneSettings.cpp:223
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal