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