~ubuntu-branches/ubuntu/quantal/marble/quantal

« back to all changes in this revision

Viewing changes to src/lib/geodata/scene/GeoSceneGroup.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-11 15:43:02 UTC
  • Revision ID: james.westby@ubuntu.com-20110711154302-lq69ftcx125g1jx5
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "GeoSceneGroup.h"
 
23
 
 
24
#include "MarbleDebug.h"
 
25
 
 
26
#include "GeoSceneProperty.h"
 
27
 
 
28
namespace Marble
 
29
{
 
30
 
 
31
GeoSceneGroup::GeoSceneGroup( const QString& name )
 
32
    : m_name( name )
 
33
{
 
34
}
 
35
 
 
36
GeoSceneGroup::~GeoSceneGroup()
 
37
{
 
38
    qDeleteAll( m_properties );
 
39
}
 
40
 
 
41
bool GeoSceneGroup::propertyAvailable( const QString& name, bool& available ) const
 
42
{
 
43
    QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
 
44
    QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
 
45
    for (; it != end; ++it) {
 
46
        if ( (*it)->name() == name ) {
 
47
            available = (*it)->available();
 
48
            return true;
 
49
        }
 
50
    }
 
51
 
 
52
    available = false;
 
53
 
 
54
    return false;
 
55
}
 
56
 
 
57
bool GeoSceneGroup::setPropertyValue( const QString& name, bool value )
 
58
{
 
59
    QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
 
60
    QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
 
61
    for (; it != end; ++it) {
 
62
        if ( (*it)->name() == name ) {
 
63
            (*it)->setValue( value );
 
64
            emit valueChanged( name, value );
 
65
            return true;
 
66
        }
 
67
    }
 
68
 
 
69
    return false;
 
70
}
 
71
 
 
72
bool GeoSceneGroup::propertyValue( const QString& name, bool& value ) const
 
73
{
 
74
    QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
 
75
    QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
 
76
    for (; it != end; ++it) {
 
77
        if ( (*it)->name() == name ) {
 
78
            value = (*it)->value();
 
79
            return true;
 
80
        }
 
81
    }
 
82
 
 
83
    value = false;
 
84
 
 
85
    return false;
 
86
}
 
87
 
 
88
void GeoSceneGroup::addProperty( GeoSceneProperty* property )
 
89
{
 
90
    // Remove any property that has the same name
 
91
    QVector<GeoSceneProperty*>::iterator it = m_properties.begin();
 
92
    while (it != m_properties.end()) {
 
93
        GeoSceneProperty* currentProperty = *it;
 
94
        if ( currentProperty->name() == property->name() ) {
 
95
            delete currentProperty;
 
96
            it = m_properties.erase(it);
 
97
            break;
 
98
        }
 
99
        else {
 
100
            ++it;
 
101
        }
 
102
    }
 
103
 
 
104
    if ( property ) {
 
105
        m_properties.append( property );
 
106
 
 
107
        // Establish connection to the outside, e.g. the LegendBrowser
 
108
        connect ( property, SIGNAL( valueChanged( QString, bool ) ), 
 
109
                            SIGNAL( valueChanged( QString, bool ) ) );
 
110
        emit valueChanged( property->name(), property->value() );
 
111
    }
 
112
}
 
113
 
 
114
const GeoSceneProperty* GeoSceneGroup::property( const QString& name ) const
 
115
{
 
116
    GeoSceneProperty* property = 0;
 
117
 
 
118
    QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin();
 
119
    QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd();
 
120
    for (; it != end; ++it) {
 
121
        if ( (*it)->name() == name ) {
 
122
            property = *it;
 
123
            break;
 
124
        }
 
125
    }
 
126
 
 
127
    return property;
 
128
}
 
129
 
 
130
// implement non-const method by means of const method,
 
131
// for details, see "Effective C++" (third edition)
 
132
GeoSceneProperty* GeoSceneGroup::property( const QString& name )
 
133
{
 
134
    return const_cast<GeoSceneProperty*>
 
135
        ( static_cast<GeoSceneGroup const *>( this )->property( name ));
 
136
}
 
137
 
 
138
QVector<GeoSceneProperty*> GeoSceneGroup::properties() const
 
139
{
 
140
    return m_properties;
 
141
}
 
142
 
 
143
QString GeoSceneGroup::name() const
 
144
{
 
145
    return m_name;
 
146
}
 
147
 
 
148
}
 
149
 
 
150
#include "GeoSceneGroup.moc"