8#include <QtQml/QQmlInfo>
9#include <QtLocation/QGeoServiceProvider>
10#include <QtLocation/QPlaceIcon>
11#include <QtLocation/QPlaceManager>
12#include <QtLocation/QPlaceIdReply>
13#include <QCoreApplication>
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
48QDeclarativeCategory::QDeclarativeCategory(QObject *parent)
53QDeclarativeCategory::QDeclarativeCategory(
const QPlaceCategory &category,
54 QDeclarativeGeoServiceProvider *plugin,
56 : QObject(parent), m_category(category), m_plugin(plugin)
58 setCategory(category);
61QDeclarativeCategory::~QDeclarativeCategory() {}
64void QDeclarativeCategory::componentComplete()
70
71
72
73
74void QDeclarativeCategory::setPlugin(QDeclarativeGeoServiceProvider *plugin)
76 if (m_plugin == plugin)
86 if (m_plugin->isAttached()) {
89 connect(m_plugin, &QDeclarativeGeoServiceProvider::attached,
90 this, &QDeclarativeCategory::pluginReady);
94QDeclarativeGeoServiceProvider *QDeclarativeCategory::plugin()
const
100
101
102void QDeclarativeCategory::pluginReady()
104 QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
105 QPlaceManager *placeManager = serviceProvider->placeManager();
106 if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) {
107 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
108 .arg(m_plugin->name()).arg(serviceProvider->errorString()));
115
116
117void QDeclarativeCategory::setCategory(
const QPlaceCategory &category)
119 QPlaceCategory previous = m_category;
120 m_category = category;
122 if (category.name() != previous.name())
125 if (category.categoryId() != previous.categoryId())
126 emit categoryIdChanged();
128 if (category.icon() != previous.icon())
132QPlaceCategory QDeclarativeCategory::category()
138
139
140
141
142
143void QDeclarativeCategory::setCategoryId(
const QString &id)
145 if (m_category.categoryId() != id) {
146 m_category.setCategoryId(id);
147 emit categoryIdChanged();
151QString QDeclarativeCategory::categoryId()
const
153 return m_category.categoryId();
157
158
159
160
161void QDeclarativeCategory::setName(
const QString &name)
163 if (m_category.name() != name) {
164 m_category.setName(name);
169QString QDeclarativeCategory::name()
const
171 return m_category.name();
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
203QDeclarativeCategory::Visibility QDeclarativeCategory::visibility()
const
205 return static_cast<QDeclarativeCategory::Visibility>(m_category.visibility());
208void QDeclarativeCategory::setVisibility(Visibility visibility)
210 if (
static_cast<QDeclarativeCategory::Visibility>(m_category.visibility()) == visibility)
213 m_category.setVisibility(
static_cast<QLocation::Visibility>(visibility));
214 emit visibilityChanged();
218
219
220
221
222
223QPlaceIcon QDeclarativeCategory::icon()
const
225 return m_category.icon();
228void QDeclarativeCategory::setIcon(
const QPlaceIcon &icon)
230 if (m_category.icon() != icon) {
231 m_category.setIcon(icon);
237
238
239
240
241
242QString QDeclarativeCategory::errorString()
const
244 return m_errorString;
247void QDeclarativeCategory::setStatus(Status status,
const QString &errorString)
249 Status originalStatus = m_status;
251 m_errorString = errorString;
253 if (originalStatus != m_status)
254 emit statusChanged();
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281QDeclarativeCategory::Status QDeclarativeCategory::status()
const
287
288
289
290
291void QDeclarativeCategory::save(
const QString &parentId)
293 QPlaceManager *placeManager = manager();
297 m_reply = placeManager->saveCategory(category(), parentId);
298 connect(m_reply, &QPlaceReply::finished,
299 this, &QDeclarativeCategory::replyFinished);
300 setStatus(QDeclarativeCategory::Saving);
304
305
306
307
308void QDeclarativeCategory::remove()
310 QPlaceManager *placeManager = manager();
314 m_reply = placeManager->removeCategory(m_category.categoryId());
315 connect(m_reply, &QPlaceReply::finished,
316 this, &QDeclarativeCategory::replyFinished);
317 setStatus(QDeclarativeCategory::Removing);
321
322
323void QDeclarativeCategory::replyFinished()
328 if (m_reply->error() == QPlaceReply::NoError) {
329 switch (m_reply->type()) {
330 case (QPlaceReply::IdReply) : {
331 QPlaceIdReply *idReply = qobject_cast<QPlaceIdReply *>(m_reply);
333 switch (idReply->operationType()) {
334 case QPlaceIdReply::SaveCategory:
335 setCategoryId(idReply->id());
337 case QPlaceIdReply::RemoveCategory:
338 setCategoryId(QString());
351 m_errorString.clear();
353 m_reply->deleteLater();
356 setStatus(QDeclarativeCategory::Ready);
358 QString errorString = m_reply->errorString();
360 m_reply->deleteLater();
363 setStatus(QDeclarativeCategory::Error, errorString);
368
369
370
371
372
373QPlaceManager *QDeclarativeCategory::manager()
375 if (m_status != QDeclarativeCategory::Ready && m_status != QDeclarativeCategory::Error)
380 m_reply->deleteLater();
385 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_PROPERTY_NOT_SET));
389 QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
390 if (!serviceProvider) {
391 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_NOT_VALID));
394 QPlaceManager *placeManager = serviceProvider->placeManager();
396 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
397 .arg(m_plugin->name()).arg(serviceProvider->errorString()));