~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to src/location/maps/qgeomapgroupobject.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
 
5
** Contact: Nokia Corporation (qt-info@nokia.com)
 
6
**
 
7
** This file is part of the Qt Mobility Components.
 
8
**
 
9
** $QT_BEGIN_LICENSE:LGPL$
 
10
** Commercial Usage
 
11
** Licensees holding valid Qt Commercial licenses may use this file in 
 
12
** accordance with the Qt Commercial License Agreement provided with
 
13
** the Software or, alternatively, in accordance with the terms
 
14
** contained in a written agreement between you and Nokia.
 
15
**
 
16
** GNU Lesser General Public License Usage
 
17
** Alternatively, this file may be used under the terms of the GNU Lesser
 
18
** General Public License version 2.1 as published by the Free Software
 
19
** Foundation and appearing in the file LICENSE.LGPL included in the
 
20
** packaging of this file.  Please review the following information to
 
21
** ensure the GNU Lesser General Public License version 2.1 requirements
 
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
23
**
 
24
** In addition, as a special exception, Nokia gives you certain additional
 
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
27
**
 
28
** GNU General Public License Usage
 
29
** Alternatively, this file may be used under the terms of the GNU
 
30
** General Public License version 3.0 as published by the Free Software
 
31
** Foundation and appearing in the file LICENSE.GPL included in the
 
32
** packaging of this file.  Please review the following information to
 
33
** ensure the GNU General Public License version 3.0 requirements will be
 
34
** met: http://www.gnu.org/copyleft/gpl.html.
 
35
**
 
36
** If you are unsure which license is appropriate for your use, please
 
37
** contact the sales department at qt-sales@nokia.com.
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include "qgeomapgroupobject.h"
 
43
#include "qgeomapgroupobject_p.h"
 
44
 
 
45
#include "qgeocoordinate.h"
 
46
#include "qgeoboundingbox.h"
 
47
 
 
48
QTM_BEGIN_NAMESPACE
 
49
 
 
50
/*!
 
51
    \class QGeoMapGroupObject
 
52
    \brief The QGeoMapGroupObject class is a QGeoMapObject used to
 
53
    manager a group of other map objects.
 
54
 
 
55
    \inmodule QtLocation
 
56
 
 
57
    \ingroup maps-mapping-objects
 
58
 
 
59
    The QGeoMapGroupObject class can be used to quickly add and remove
 
60
    groups of objects to a map.
 
61
 
 
62
    The map objects contained in the group will be ordered relative to
 
63
    one another in the usual manner, such that objects with higher z-values
 
64
    will be drawn over objects with lower z-values and objects with
 
65
    equal z-values will be drawn in insertion order.
 
66
 
 
67
    This ordering of the objects will be independent of the other
 
68
    objects that are added to the map, since the z-value and insertion
 
69
    order of the QGeoMapGroupObject is used to determine where the
 
70
    group is placed in the scene.
 
71
*/
 
72
 
 
73
/*!
 
74
    Constructs a new group object.
 
75
*/
 
76
QGeoMapGroupObject::QGeoMapGroupObject()
 
77
    : d_ptr(new QGeoMapGroupObjectPrivate()) {}
 
78
 
 
79
/*!
 
80
    Destroys this group object.
 
81
*/
 
82
QGeoMapGroupObject::~QGeoMapGroupObject()
 
83
{
 
84
    delete d_ptr;
 
85
}
 
86
 
 
87
/*!
 
88
    \reimp
 
89
*/
 
90
QGeoMapObject::Type QGeoMapGroupObject::type() const
 
91
{
 
92
    return QGeoMapObject::GroupType;
 
93
}
 
94
 
 
95
/*!
 
96
    Returns a bounding box which contains this map object.
 
97
 
 
98
    If this map object has children, the bounding box will be large
 
99
    enough to contain both this map object and all of its children.
 
100
*/
 
101
QGeoBoundingBox QGeoMapGroupObject::boundingBox() const
 
102
{
 
103
    QGeoBoundingBox bounds;
 
104
 
 
105
    if (d_ptr->children.size() == 0)
 
106
        return bounds;
 
107
 
 
108
    for (int i = 0; i < d_ptr->children.size(); ++i)
 
109
        bounds = bounds.united(d_ptr->children.at(i)->boundingBox());
 
110
 
 
111
    return bounds;
 
112
}
 
113
 
 
114
/*!
 
115
    Returns whether \a coordinate is contained with the boundary of this
 
116
    map object.
 
117
 
 
118
    If this map object has children, this function will return whether
 
119
    \a coordinate is contained within the boundary of this map object or
 
120
    within the boundary of any of its children.
 
121
*/
 
122
bool QGeoMapGroupObject::contains(const QGeoCoordinate &coordinate) const
 
123
{
 
124
    for (int i = 0; i < d_ptr->children.size(); ++i)
 
125
        if (d_ptr->children.at(i)->contains(coordinate))
 
126
            return true;
 
127
 
 
128
    return false;
 
129
}
 
130
 
 
131
/*!
 
132
    Adds \a childObject to the list of children of this map object.
 
133
 
 
134
    The children objects are drawn in order of the QGeoMapObject::zValue()
 
135
    value.  Children objects having the same z value will be drawn
 
136
    in the order they were added.
 
137
 
 
138
    The map object will take ownership of \a childObject.
 
139
*/
 
140
void QGeoMapGroupObject::addChildObject(QGeoMapObject *childObject)
 
141
{
 
142
    if (!childObject || d_ptr->children.contains(childObject))
 
143
        return;
 
144
 
 
145
    childObject->setMapData(mapData());
 
146
 
 
147
    //binary search
 
148
    QList<QGeoMapObject*>::iterator i = qUpperBound(d_ptr->children.begin(), d_ptr->children.end(), childObject);
 
149
    d_ptr->children.insert(i, childObject);
 
150
 
 
151
    emit childAdded(childObject);
 
152
}
 
153
 
 
154
/*!
 
155
    Removes \a childObject from the list of children of this map object.
 
156
 
 
157
    The map object will release ownership of \a childObject.
 
158
*/
 
159
void QGeoMapGroupObject::removeChildObject(QGeoMapObject *childObject)
 
160
{
 
161
    if (!childObject)
 
162
        return;
 
163
 
 
164
    if (d_ptr->children.removeAll(childObject) > 0) {
 
165
        emit childRemoved(childObject);
 
166
        childObject->setMapData(0);
 
167
    }
 
168
}
 
169
 
 
170
/*!
 
171
    Returns the children of this object.
 
172
*/
 
173
QList<QGeoMapObject*> QGeoMapGroupObject::childObjects() const
 
174
{
 
175
    return d_ptr->children;
 
176
}
 
177
 
 
178
/*!
 
179
    Clears the children of this object.
 
180
 
 
181
    The child objects will be deleted.
 
182
*/
 
183
void QGeoMapGroupObject::clearChildObjects()
 
184
{
 
185
    for (int i = 0; i < d_ptr->children.size(); ++i) {
 
186
        emit childRemoved(d_ptr->children[i]);
 
187
        d_ptr->children[i]->setMapData(0);
 
188
        delete d_ptr->children[i];
 
189
    }
 
190
 
 
191
    d_ptr->children.clear();
 
192
}
 
193
 
 
194
/*!
 
195
    \reimp
 
196
*/
 
197
void QGeoMapGroupObject::setMapData(QGeoMapData *mapData)
 
198
{
 
199
    QGeoMapObject::setMapData(mapData);
 
200
    for (int i = 0; i < d_ptr->children.size(); ++i) {
 
201
        d_ptr->children[i]->setMapData(mapData);
 
202
        emit childAdded(d_ptr->children[i]);
 
203
    }
 
204
}
 
205
 
 
206
/*!
 
207
\fn void QGeoMapGroupObject::childAdded(QGeoMapObject *childObject)
 
208
 
 
209
    This signal will be emitted when the map object \a childObject 
 
210
    is added to the group.
 
211
*/
 
212
 
 
213
/*!
 
214
\fn void QGeoMapGroupObject::childRemoved(QGeoMapObject *childObject)
 
215
 
 
216
    This signal will be emitted when the map object \a childObject 
 
217
    is removed from the group.
 
218
*/
 
219
 
 
220
/*******************************************************************************
 
221
*******************************************************************************/
 
222
 
 
223
QGeoMapGroupObjectPrivate::QGeoMapGroupObjectPrivate() {}
 
224
 
 
225
QGeoMapGroupObjectPrivate::~QGeoMapGroupObjectPrivate()
 
226
{
 
227
    qDeleteAll(children);
 
228
}
 
229
 
 
230
#include "moc_qgeomapgroupobject.cpp"
 
231
 
 
232
QTM_END_NAMESPACE
 
233