9#include <QtQml/QQmlInfo>
10#include <QtLocation/QGeoServiceProvider>
11#include <QtLocation/QPlaceIcon>
12#include <QtLocation/QPlaceManager>
13#include <QtLocation/QPlaceIdReply>
14#include <QCoreApplication>
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
49QDeclarativeCategory::QDeclarativeCategory(QObject *parent)
54QDeclarativeCategory::QDeclarativeCategory(
const QPlaceCategory &category,
55 QDeclarativeGeoServiceProvider *plugin,
57 : QObject(parent), m_category(category), m_plugin(plugin)
59 setCategory(category);
62QDeclarativeCategory::~QDeclarativeCategory() {}
65void QDeclarativeCategory::componentComplete()
71
72
73
74
75void QDeclarativeCategory::setPlugin(QDeclarativeGeoServiceProvider *plugin)
77 if (m_plugin == plugin)
87 if (m_plugin->isAttached()) {
90 connect(m_plugin, &QDeclarativeGeoServiceProvider::attached,
91 this, &QDeclarativeCategory::pluginReady);
95QDeclarativeGeoServiceProvider *QDeclarativeCategory::plugin()
const
101
102
103void QDeclarativeCategory::pluginReady()
105 QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
106 QPlaceManager *placeManager = serviceProvider->placeManager();
107 if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) {
108 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
109 .arg(m_plugin->name()).arg(serviceProvider->errorString()));
116
117
118void QDeclarativeCategory::setCategory(
const QPlaceCategory &category)
120 QPlaceCategory previous = m_category;
121 m_category = category;
123 if (category.name() != previous.name())
126 if (category.categoryId() != previous.categoryId())
127 emit categoryIdChanged();
129 if (category.icon() != previous.icon())
133QPlaceCategory QDeclarativeCategory::category()
139
140
141
142
143
144void QDeclarativeCategory::setCategoryId(
const QString &id)
146 if (m_category.categoryId() != id) {
147 m_category.setCategoryId(id);
148 emit categoryIdChanged();
152QString QDeclarativeCategory::categoryId()
const
154 return m_category.categoryId();
158
159
160
161
162void QDeclarativeCategory::setName(
const QString &name)
164 if (m_category.name() != name) {
165 m_category.setName(name);
170QString QDeclarativeCategory::name()
const
172 return m_category.name();
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
204QDeclarativeCategory::Visibility QDeclarativeCategory::visibility()
const
206 return static_cast<QDeclarativeCategory::Visibility>(m_category.visibility());
209void QDeclarativeCategory::setVisibility(Visibility visibility)
211 if (
static_cast<QDeclarativeCategory::Visibility>(m_category.visibility()) == visibility)
214 m_category.setVisibility(
static_cast<QLocation::Visibility>(visibility));
215 emit visibilityChanged();
219
220
221
222
223
224QPlaceIcon QDeclarativeCategory::icon()
const
226 return m_category.icon();
229void QDeclarativeCategory::setIcon(
const QPlaceIcon &icon)
231 if (m_category.icon() != icon) {
232 m_category.setIcon(icon);
238
239
240
241
242
243QString QDeclarativeCategory::errorString()
const
245 return m_errorString;
248void QDeclarativeCategory::setStatus(Status status,
const QString &errorString)
250 Status originalStatus = m_status;
252 m_errorString = errorString;
254 if (originalStatus != m_status)
255 emit statusChanged();
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282QDeclarativeCategory::Status QDeclarativeCategory::status()
const
288
289
290
291
292void QDeclarativeCategory::save(
const QString &parentId)
294 QPlaceManager *placeManager = manager();
298 m_reply = placeManager->saveCategory(category(), parentId);
299 connect(m_reply, &QPlaceReply::finished,
300 this, &QDeclarativeCategory::replyFinished);
301 setStatus(QDeclarativeCategory::Saving);
305
306
307
308
309void QDeclarativeCategory::remove()
311 QPlaceManager *placeManager = manager();
315 m_reply = placeManager->removeCategory(m_category.categoryId());
316 connect(m_reply, &QPlaceReply::finished,
317 this, &QDeclarativeCategory::replyFinished);
318 setStatus(QDeclarativeCategory::Removing);
322
323
324void QDeclarativeCategory::replyFinished()
329 if (m_reply->error() == QPlaceReply::NoError) {
330 switch (m_reply->type()) {
331 case (QPlaceReply::IdReply) : {
332 QPlaceIdReply *idReply = qobject_cast<QPlaceIdReply *>(m_reply);
334 switch (idReply->operationType()) {
335 case QPlaceIdReply::SaveCategory:
336 setCategoryId(idReply->id());
338 case QPlaceIdReply::RemoveCategory:
339 setCategoryId(QString());
352 m_errorString.clear();
354 m_reply->deleteLater();
357 setStatus(QDeclarativeCategory::Ready);
359 QString errorString = m_reply->errorString();
361 m_reply->deleteLater();
364 setStatus(QDeclarativeCategory::Error, errorString);
369
370
371
372
373
374QPlaceManager *QDeclarativeCategory::manager()
376 if (m_status != QDeclarativeCategory::Ready && m_status != QDeclarativeCategory::Error)
381 m_reply->deleteLater();
386 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_PROPERTY_NOT_SET));
390 QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
391 if (!serviceProvider) {
392 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_NOT_VALID));
395 QPlaceManager *placeManager = serviceProvider->placeManager();
397 setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
398 .arg(m_plugin->name()).arg(serviceProvider->errorString()));
Combined button and popup list for selecting options.