Marble

GeoSceneGroup.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 "GeoSceneGroup.h"
8
9#include "GeoSceneProperty.h"
10#include "GeoSceneTypes.h"
11
12namespace Marble
13{
14
15GeoSceneGroup::GeoSceneGroup(const QString &name)
16 : m_name(name)
17{
18}
19
20GeoSceneGroup::~GeoSceneGroup()
21{
22 qDeleteAll(m_properties);
23}
24
25bool GeoSceneGroup::propertyAvailable(const QString &name, bool &available) const
26{
27 QList<GeoSceneProperty *>::const_iterator it = m_properties.constBegin();
28 QList<GeoSceneProperty *>::const_iterator end = m_properties.constEnd();
29 for (; it != end; ++it) {
30 if ((*it)->name() == name) {
31 available = (*it)->available();
32 return true;
33 }
34 }
35
36 available = false;
37
38 return false;
39}
40
41bool GeoSceneGroup::setPropertyValue(const QString &name, bool value)
42{
43 QList<GeoSceneProperty *>::const_iterator it = m_properties.constBegin();
44 QList<GeoSceneProperty *>::const_iterator end = m_properties.constEnd();
45 for (; it != end; ++it) {
46 if ((*it)->name() == name) {
47 (*it)->setValue(value);
48 Q_EMIT valueChanged(name, value);
49 return true;
50 }
51 }
52
53 return false;
54}
55
56bool GeoSceneGroup::propertyValue(const QString &name, bool &value) const
57{
58 QList<GeoSceneProperty *>::const_iterator it = m_properties.constBegin();
59 QList<GeoSceneProperty *>::const_iterator end = m_properties.constEnd();
60 for (; it != end; ++it) {
61 if ((*it)->name() == name) {
62 value = (*it)->value();
63 return true;
64 }
65 }
66
67 value = false;
68
69 return false;
70}
71
72void GeoSceneGroup::addProperty(GeoSceneProperty *property)
73{
74 Q_ASSERT(property);
75 if (!property) {
76 return;
77 }
78
79 // Remove any property that has the same name
80 QList<GeoSceneProperty *>::iterator it = m_properties.begin();
81 while (it != m_properties.end()) {
82 GeoSceneProperty *currentProperty = *it;
83 if (currentProperty->name() == property->name()) {
84 delete currentProperty;
85 m_properties.erase(it);
86 break;
87 } else {
88 ++it;
89 }
90 }
91
92 m_properties.append(property);
93
94 // Establish connection to the outside, e.g. the LegendBrowser
95 connect(property, SIGNAL(valueChanged(QString, bool)), SIGNAL(valueChanged(QString, bool)));
96 Q_EMIT valueChanged(property->name(), property->value());
97}
98
99const GeoSceneProperty *GeoSceneGroup::property(const QString &name) const
100{
101 GeoSceneProperty *property = nullptr;
102
103 QList<GeoSceneProperty *>::const_iterator it = m_properties.constBegin();
104 QList<GeoSceneProperty *>::const_iterator end = m_properties.constEnd();
105 for (; it != end; ++it) {
106 if ((*it)->name() == name) {
107 property = *it;
108 break;
109 }
110 }
111
112 return property;
113}
114
115// implement non-const method by means of const method,
116// for details, see "Effective C++" (third edition)
117GeoSceneProperty *GeoSceneGroup::property(const QString &name)
118{
119 return const_cast<GeoSceneProperty *>(static_cast<GeoSceneGroup const *>(this)->property(name));
120}
121
122QList<GeoSceneProperty *> GeoSceneGroup::properties()
123{
124 return m_properties;
125}
126
127QList<const GeoSceneProperty *> GeoSceneGroup::properties() const
128{
130 result.reserve(m_properties.size());
131
132 for (const GeoSceneProperty *property : m_properties) {
133 result << property;
134 }
135
136 return result;
137}
138
139QString GeoSceneGroup::name() const
140{
141 return m_name;
142}
143
144const char *GeoSceneGroup::nodeType() const
145{
146 return GeoSceneTypes::GeoSceneGroupType;
147}
148
149}
150
151#include "moc_GeoSceneGroup.cpp"
Settings property within a GeoScene document.
QString name(GameStandardAction id)
Binds a QML item to a specific geodetic location in screen coordinates.
void reserve(qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.