Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qplaceicon.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qplaceicon.h"
6
#
include
"qplaceicon_p.h"
7
#
include
"qplacemanager.h"
8
#
include
"qplacemanagerengine.h"
9
10
#
include
<
QtCore
/
QVariant
>
11
#
include
<
QtQml
/
QJSValue
>
12
13
QT_USE_NAMESPACE
14
15
QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QPlaceIconPrivate)
16
17
bool
QPlaceIconPrivate::operator == (
const
QPlaceIconPrivate &other)
const
18
{
19
return
manager == other.manager
20
&& parameters == other.parameters;
21
}
22
23
/*!
24
\class QPlaceIcon
25
\inmodule QtLocation
26
\ingroup QtLocation-places
27
\ingroup QtLocation-places-data
28
\since 5.6
29
30
\brief The QPlaceIcon class represents an icon.
31
32
The typical usage of an icon is to use the url() function to specify
33
a preferred icon size.
34
35
\snippet places/requesthandler.h icon
36
37
The icons are typically backend dependent, if a manager backend does not support a given size, the URL of the icon that most
38
closely matches those parameters is returned.
39
40
The icon class also has a key-value set of parameters. The precise key one
41
needs to use depends on the \l {Qt Location#Plugin References and Parameters}{plugin}
42
being used. These parameters influence which icon URL is returned by
43
the manager and may also be used to specify icon URL locations when
44
saving icons.
45
46
If there is only ever one image for an icon, then QPlaceIcon::SingleUrl can be used as a parameter
47
key with a QUrl as the associated value. If this key is set, then the url() function will always return the specified URL
48
and not defer to any manager.
49
*/
50
51
/*!
52
\qmlvaluetype icon
53
\inqmlmodule QtLocation
54
\ingroup qml-QtLocation5-places
55
\ingroup qml-QtLocation5-places-data
56
\since QtLocation 5.5
57
58
\brief The icon type represents the icon of a place.
59
60
The typical usage of an icon is to use the url() function to specify
61
a preferred icon size.
62
63
The icons are typically backend dependent, if a manager backend does not support a given size, the URL of the icon that most
64
closely matches those parameters is returned.
65
66
The icon class also has a key-value set of parameters. The precise key one
67
needs to use depends on the \l {Qt Location#Plugin References and Parameters}{plugin}
68
being used. These parameters influence which icon URL is returned by
69
the manager and may also be used to specify icon URL locations when
70
saving icons.
71
72
If there is only ever one image for an icon, then QPlaceIcon::SingleUrl can be used as a parameter
73
key with a QUrl as the associated value. If this key is set, then the url() function will always return the specified URL
74
and not defer to any manager.
75
*/
76
77
/*!
78
\variable QPlaceIcon::SingleUrl
79
\brief Parameter key for an icon that only has a single image URL.
80
81
The parameter value to be used with this key is a QUrl. An icon with this parameter set will
82
always return the specified URL regardless of the requested size when url() is called.
83
*/
84
const
QString QPlaceIcon::SingleUrl(QLatin1String(
"singleUrl"
));
85
86
/*!
87
Constructs an icon.
88
*/
89
QPlaceIcon::QPlaceIcon()
90
: d(
new
QPlaceIconPrivate)
91
{
92
}
93
94
/*!
95
Constructs a copy of \a other.
96
*/
97
QPlaceIcon::QPlaceIcon(
const
QPlaceIcon &other)
noexcept
=
default
;
98
99
/*!
100
Destroys the icon.
101
*/
102
QPlaceIcon::~QPlaceIcon() =
default
;
103
104
/*!
105
Assigns \a other to this icon and returns a reference to this icon.
106
*/
107
QPlaceIcon &QPlaceIcon::operator=(
const
QPlaceIcon &other)
noexcept
108
{
109
if
(
this
== &other)
110
return
*
this
;
111
112
d = other.d;
113
return
*
this
;
114
}
115
116
/*!
117
\fn bool QPlaceIcon::operator==(const QPlaceIcon &lhs, const QPlaceIcon &rhs) noexcept
118
119
Returns true if \a lhs is equal to \a rhs, otherwise returns false.
120
*/
121
122
/*!
123
\fn bool QPlaceIcon::operator!=(const QPlaceIcon &lhs, const QPlaceIcon &rhs) noexcept
124
125
Returns true if \a lhs is not equal to \a rhs, otherwise returns false.
126
*/
127
128
bool
QPlaceIcon::isEqual(
const
QPlaceIcon &other)
const
noexcept
129
{
130
return
*d == *(other.d);
131
}
132
133
/* ### Need to evaluate whether we need this at all (or perhaps only for tests)
134
\qmlproperty Plugin Icon::plugin
135
136
The property holds the plugin that is responsible for managing this icon.
137
*/
138
139
/*!
140
Returns an icon URL according to the given \a size.
141
142
If no manager has been assigned to the icon, and the parameters do not contain the QPlaceIcon::SingleUrl key, a default constructed QUrl
143
is returned.
144
*/
145
QUrl QPlaceIcon::url(
const
QSize &size)
const
146
{
147
if
(d->parameters.contains(QPlaceIcon::SingleUrl)) {
148
QVariant value = d->parameters.value(QPlaceIcon::SingleUrl);
149
if
(value.typeId() == QMetaType::QUrl)
150
return
value.toUrl();
151
else
if
(value.typeId() == QMetaType::QString)
152
return
QUrl::fromUserInput(value.toString());
153
154
return
QUrl();
155
}
156
157
if
(!d->manager)
158
return
QUrl();
159
160
return
d->manager->d->constructIconUrl(*
this
, size);
161
}
162
163
/*!
164
\property QPlaceIcon::parameters
165
\brief the set of parameters for the icon that are manager or plugin specific.
166
*/
167
168
/*!
169
Returns a set of parameters for the icon that are manager/plugin specific.
170
These parameters are used by the manager to return the appropriate
171
URL when url() is called and to specify locations to save to
172
when saving icons.
173
174
Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation}
175
for what parameters are supported and how they should be used.
176
*/
177
QVariantMap QPlaceIcon::parameters()
const
178
{
179
return
d->parameters;
180
}
181
182
/*!
183
Sets the parameters of the icon to \a parameters.
184
*/
185
void
QPlaceIcon::setParameters(
const
QVariantMap ¶meters)
186
{
187
d->parameters = parameters;
188
}
189
190
/*!
191
\property QPlaceIcon::manager
192
\brief the manager of this icon.
193
*/
194
195
/*!
196
Returns the manager that this icon is associated with.
197
*/
198
QPlaceManager *QPlaceIcon::manager()
const
199
{
200
return
d->manager;
201
}
202
203
/*!
204
Sets the \a manager that this icon is associated with. The icon does not take
205
ownership of the pointer.
206
*/
207
void
QPlaceIcon::setManager(QPlaceManager *manager)
208
{
209
d->manager = manager;
210
}
211
212
/*!
213
Returns a boolean indicating whether the all the fields of the icon are empty or not.
214
*/
215
bool
QPlaceIcon::isEmpty()
const
216
{
217
return
(d->manager == 0
218
&& d->parameters.isEmpty());
219
}
220
221
#
include
"moc_qplaceicon.cpp"
qtlocation
src
location
places
qplaceicon.cpp
Generated on
for Qt by
1.18.0