summaryrefslogtreecommitdiff
path: root/src/location/labs/qmapiconobject.cpp
blob: be82ebbfe99d11beaa5db5ba60688515f5fbb735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qmapiconobject_p.h"
#include "qmapiconobject_p_p.h"
#include <QExplicitlySharedDataPointer>

QT_BEGIN_NAMESPACE

/*!
    \qmltype MapIconObject
    \instantiates QMapIconObject
    \inqmlmodule Qt.labs.location
    \ingroup qml-QtLocation5-maps
    \inherits QGeoMapObject

    \brief The MapIconObject displays an icon on a Map.

    The MapIconObject displays an icon on a Map.
    The MapIconObject type only makes sense when contained in a Map or in a \l MapObjectView.
*/

QMapIconObjectPrivate::~QMapIconObjectPrivate()
{

}

QMapIconObjectPrivate::QMapIconObjectPrivate(QGeoMapObject *q) : QGeoMapObjectPrivate(q)
{

}

QGeoMapObject::Type QMapIconObjectPrivate::type() const
{
    return QGeoMapObject::IconType;
}

bool QMapIconObjectPrivate::equals(const QGeoMapObjectPrivate &other) const
{
    if (other.type() != type()) // This check might be unnecessary, depending on how equals gets used
        return false;

    const QMapIconObjectPrivate &o = static_cast<const QMapIconObjectPrivate &>(other);
    return (QGeoMapObjectPrivate::equals(o)
            && content() == o.content()
            && coordinate() == o.coordinate());
}

//
// QGeoMapIconPrivate default implementation
//

QMapIconObjectPrivateDefault::QMapIconObjectPrivateDefault(QGeoMapObject *q) : QMapIconObjectPrivate(q)
{

}
QMapIconObjectPrivateDefault::QMapIconObjectPrivateDefault(const QMapIconObjectPrivate &other) : QMapIconObjectPrivate(other.q)
{
    m_coordinate = other.coordinate();
    m_content = other.content();
    m_size = other.size();
}

QMapIconObjectPrivateDefault::~QMapIconObjectPrivateDefault()
{

}

QGeoCoordinate QMapIconObjectPrivateDefault::coordinate() const
{
    return m_coordinate;
}

void QMapIconObjectPrivateDefault::setCoordinate(const QGeoCoordinate &center)
{
    m_coordinate = center;
}

QVariant QMapIconObjectPrivateDefault::content() const
{
    return m_content;
}

void QMapIconObjectPrivateDefault::setContent(const QVariant &content)
{
    m_content = content;
}

QSizeF QMapIconObjectPrivateDefault::size() const
{
    return m_size;
}

void QMapIconObjectPrivateDefault::setSize(const QSizeF &size)
{
    m_size = size;
}

QGeoMapObjectPrivate *QMapIconObjectPrivateDefault::clone()
{
    return new QMapIconObjectPrivateDefault(static_cast<QMapIconObjectPrivate &>(*this));
}


/*

    QGeoMapIconPrivate default implementation

*/


QMapIconObject::QMapIconObject(QObject *parent)
    : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapIconObjectPrivateDefault(this)), parent)
{}

QMapIconObject::~QMapIconObject()
{

}

/*!
    \qmlproperty Variant Qt.labs.location::MapIconObject::content

    This property holds the content to be used for the icon. The actual content of this property is somehow
    backend-dependent. The implementation for the raster engine accepts local urls or paths.
    Other implementations may accept additional content types.
*/
QVariant QMapIconObject::content() const
{
    const QMapIconObjectPrivate *d = static_cast<const QMapIconObjectPrivate *>(d_ptr.data());
    return d->content();
}

/*!
    \qmlproperty Variant Qt.labs.location::MapIconObject::coordinate

    The coordinate where the icon is going to be shown.
    What pixel of the icon matches the coordinate is somehow backend-dependent.
    For example, due to limitations, some backends might associate the center of the icon with the
    coordinate, others one of the corners.
    If there is a choice, backend developers should use the center of the icon as the default anchor
    point.

    The behavior is also intended to be customizable with a \l DynamicParameter, when
    using backends that support anchoring arbitrary points of the icon to the coordinate.
    What kind of parameter to use and how to achieve this behavior is intended to be
    documented per-backend.
*/
QGeoCoordinate QMapIconObject::coordinate() const
{
    const QMapIconObjectPrivate *d = static_cast<const QMapIconObjectPrivate *>(d_ptr.data());
    return d->coordinate();
}

void QMapIconObject::setContent(QVariant content)
{
    QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate *>(d_ptr.data());
    if (d->content() == content)
        return;

    d->setContent(content);
    emit contentChanged(content);
}

void QMapIconObject::setCoordinate(const QGeoCoordinate &center)
{
    QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate*>(d_ptr.data());
    if (d->coordinate() == center)
        return;

    d->setCoordinate(center);
    emit coordinateChanged(center);
}

/*!
    \qmlproperty Variant Qt.labs.location::MapIconObject::size

    The size of the icon as it will be shown on the map.
*/
QSizeF QMapIconObject::size() const
{
    const QMapIconObjectPrivate *d = static_cast<const QMapIconObjectPrivate *>(d_ptr.data());
    return d->size();
}


void QMapIconObject::setSize(const QSizeF &size)
{
    QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate*>(d_ptr.data());
    if (d->size() == size)
        return;

    d->setSize(size);
    emit sizeChanged();
}

void QMapIconObject::setMap(QGeoMap *map)
{
    QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate *>(d_ptr.data());
    if (d->m_map == map)
        return;

    QGeoMapObject::setMap(map); // This is where the specialized pimpl gets created and injected

    if (!map) {
        // Map was set, now it has ben re-set to NULL, but not inside d_ptr.
        // so m_map inside d_ptr can still be used to remove itself, inside the destructor.
        d_ptr = new QMapIconObjectPrivateDefault(*d);
        // Old pimpl deleted implicitly by QExplicitlySharedDataPointer
    }
}

QT_END_NAMESPACE