1
/****************************************************************************
3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the Qt Mobility Components.
9
** $QT_BEGIN_LICENSE:LGPL$
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.
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.
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.
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.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at qt-sales@nokia.com.
40
****************************************************************************/
42
#include "qgeomapgroupobject.h"
43
#include "qgeomapgroupobject_p.h"
45
#include "qgeocoordinate.h"
46
#include "qgeoboundingbox.h"
51
\class QGeoMapGroupObject
52
\brief The QGeoMapGroupObject class is a QGeoMapObject used to
53
manager a group of other map objects.
57
\ingroup maps-mapping-objects
59
The QGeoMapGroupObject class can be used to quickly add and remove
60
groups of objects to a map.
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.
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.
74
Constructs a new group object.
76
QGeoMapGroupObject::QGeoMapGroupObject()
77
: d_ptr(new QGeoMapGroupObjectPrivate()) {}
80
Destroys this group object.
82
QGeoMapGroupObject::~QGeoMapGroupObject()
90
QGeoMapObject::Type QGeoMapGroupObject::type() const
92
return QGeoMapObject::GroupType;
96
Returns a bounding box which contains this map object.
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.
101
QGeoBoundingBox QGeoMapGroupObject::boundingBox() const
103
QGeoBoundingBox bounds;
105
if (d_ptr->children.size() == 0)
108
for (int i = 0; i < d_ptr->children.size(); ++i)
109
bounds = bounds.united(d_ptr->children.at(i)->boundingBox());
115
Returns whether \a coordinate is contained with the boundary of this
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.
122
bool QGeoMapGroupObject::contains(const QGeoCoordinate &coordinate) const
124
for (int i = 0; i < d_ptr->children.size(); ++i)
125
if (d_ptr->children.at(i)->contains(coordinate))
132
Adds \a childObject to the list of children of this map object.
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.
138
The map object will take ownership of \a childObject.
140
void QGeoMapGroupObject::addChildObject(QGeoMapObject *childObject)
142
if (!childObject || d_ptr->children.contains(childObject))
145
childObject->setMapData(mapData());
148
QList<QGeoMapObject*>::iterator i = qUpperBound(d_ptr->children.begin(), d_ptr->children.end(), childObject);
149
d_ptr->children.insert(i, childObject);
151
emit childAdded(childObject);
155
Removes \a childObject from the list of children of this map object.
157
The map object will release ownership of \a childObject.
159
void QGeoMapGroupObject::removeChildObject(QGeoMapObject *childObject)
164
if (d_ptr->children.removeAll(childObject) > 0) {
165
emit childRemoved(childObject);
166
childObject->setMapData(0);
171
Returns the children of this object.
173
QList<QGeoMapObject*> QGeoMapGroupObject::childObjects() const
175
return d_ptr->children;
179
Clears the children of this object.
181
The child objects will be deleted.
183
void QGeoMapGroupObject::clearChildObjects()
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];
191
d_ptr->children.clear();
197
void QGeoMapGroupObject::setMapData(QGeoMapData *mapData)
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]);
207
\fn void QGeoMapGroupObject::childAdded(QGeoMapObject *childObject)
209
This signal will be emitted when the map object \a childObject
210
is added to the group.
214
\fn void QGeoMapGroupObject::childRemoved(QGeoMapObject *childObject)
216
This signal will be emitted when the map object \a childObject
217
is removed from the group.
220
/*******************************************************************************
221
*******************************************************************************/
223
QGeoMapGroupObjectPrivate::QGeoMapGroupObjectPrivate() {}
225
QGeoMapGroupObjectPrivate::~QGeoMapGroupObjectPrivate()
227
qDeleteAll(children);
230
#include "moc_qgeomapgroupobject.cpp"