Marble

GeoSceneGroup.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Torsten Rahn <[email protected]>
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 
14 namespace Marble
15 {
16 
17 GeoSceneGroup::GeoSceneGroup( const QString& name )
18  : m_name( name )
19 {
20 }
21 
22 GeoSceneGroup::~GeoSceneGroup()
23 {
24  qDeleteAll( m_properties );
25 }
26 
27 bool 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 
43 bool 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 
58 bool 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 
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 
103 const 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)
121 GeoSceneProperty* GeoSceneGroup::property( const QString& name )
122 {
123  return const_cast<GeoSceneProperty*>
124  ( static_cast<GeoSceneGroup const *>( this )->property( name ));
125 }
126 
127 QVector<GeoSceneProperty*> GeoSceneGroup::properties()
128 {
129  return m_properties;
130 }
131 
132 QVector<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 
144 QString GeoSceneGroup::name() const
145 {
146  return m_name;
147 }
148 
149 const char *GeoSceneGroup::nodeType() const
150 {
151  return GeoSceneTypes::GeoSceneGroupType;
152 }
153 
154 }
155 
156 #include "moc_GeoSceneGroup.cpp"
bool propertyValue(const QString &name, bool &value) const
Get the value of a property in this group.
bool setPropertyValue(const QString &name, bool value)
Set the value of a property in this group.
bool propertyAvailable(const QString &name, bool &available) const
Get the availability of a property in this group.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Settings property within a GeoScene document.
Binds a QML item to a specific geodetic location in screen coordinates.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
void addProperty(GeoSceneProperty *)
Add a property to this setting group.
void reserve(int size)
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.