Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdeclarativecategory.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
6#include "error_messages_p.h"
7
8#include <QtQml/QQmlInfo>
9#include <QtLocation/QGeoServiceProvider>
10#include <QtLocation/QPlaceIcon>
11#include <QtLocation/QPlaceManager>
12#include <QtLocation/QPlaceIdReply>
13#include <QCoreApplication>
14
16
52
55 QObject *parent)
56 : QObject(parent), m_category(category), m_plugin(plugin)
57{
59}
60
62
63// From QQmlParserStatus
65{
66 m_complete = true;
67}
68
75{
76 if (m_plugin == plugin)
77 return;
78
79 m_plugin = plugin;
80 if (m_complete)
82
83 if (!m_plugin)
84 return;
85
86 if (m_plugin->isAttached()) {
87 pluginReady();
88 } else {
90 this, &QDeclarativeCategory::pluginReady);
91 }
92}
93
98
102void QDeclarativeCategory::pluginReady()
103{
104 QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
105 QPlaceManager *placeManager = serviceProvider->placeManager();
106 if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) {
108 .arg(m_plugin->name()).arg(serviceProvider->errorString()));
109 return;
110 }
111}
112
113
118{
119 QPlaceCategory previous = m_category;
120 m_category = category;
121
122 if (category.name() != previous.name())
124
125 if (category.categoryId() != previous.categoryId())
127
128 if (category.icon() != previous.icon())
130}
131
133{
134 return m_category;
135}
136
144{
145 if (m_category.categoryId() != id) {
146 m_category.setCategoryId(id);
148 }
149}
150
152{
153 return m_category.categoryId();
154}
155
162{
163 if (m_category.name() != name) {
164 m_category.setName(name);
166 }
167}
168
170{
171 return m_category.name();
172}
173
207
209{
210 if (static_cast<QDeclarativeCategory::Visibility>(m_category.visibility()) == visibility)
211 return;
212
213 m_category.setVisibility(static_cast<QLocation::Visibility>(visibility));
215}
216
224{
225 return m_category.icon();
226}
227
229{
230 if (m_category.icon() != icon) {
231 m_category.setIcon(icon);
233 }
234}
235
243{
244 return m_errorString;
245}
246
247void QDeclarativeCategory::setStatus(Status status, const QString &errorString)
248{
249 Status originalStatus = m_status;
250 m_status = status;
251 m_errorString = errorString;
252
253 if (originalStatus != m_status)
255}
256
282{
283 return m_status;
284}
285
292{
293 QPlaceManager *placeManager = manager();
294 if (!placeManager)
295 return;
296
297 m_reply = placeManager->saveCategory(category(), parentId);
299 this, &QDeclarativeCategory::replyFinished);
301}
302
309{
310 QPlaceManager *placeManager = manager();
311 if (!placeManager)
312 return;
313
314 m_reply = placeManager->removeCategory(m_category.categoryId());
316 this, &QDeclarativeCategory::replyFinished);
318}
319
323void QDeclarativeCategory::replyFinished()
324{
325 if (!m_reply)
326 return;
327
328 if (m_reply->error() == QPlaceReply::NoError) {
329 switch (m_reply->type()) {
330 case (QPlaceReply::IdReply) : {
331 QPlaceIdReply *idReply = qobject_cast<QPlaceIdReply *>(m_reply);
332
333 switch (idReply->operationType()) {
335 setCategoryId(idReply->id());
336 break;
339 break;
340 default:
341 //Other operation types shouldn't ever be received.
342 break;
343 }
344 break;
345 }
346 default:
347 //other types of replies shouldn't ever be received.
348 break;
349 }
350
351 m_errorString.clear();
352
353 m_reply->deleteLater();
354 m_reply = nullptr;
355
357 } else {
358 QString errorString = m_reply->errorString();
359
360 m_reply->deleteLater();
361 m_reply = nullptr;
362
364 }
365}
366
373QPlaceManager *QDeclarativeCategory::manager()
374{
375 if (m_status != QDeclarativeCategory::Ready && m_status != QDeclarativeCategory::Error)
376 return nullptr;
377
378 if (m_reply) {
379 m_reply->abort();
380 m_reply->deleteLater();
381 m_reply = nullptr;
382 }
383
384 if (!m_plugin) {
386 return nullptr;
387 }
388
389 QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
390 if (!serviceProvider) {
392 return nullptr;
393 }
394 QPlaceManager *placeManager = serviceProvider->placeManager();
395 if (!placeManager) {
397 .arg(m_plugin->name()).arg(serviceProvider->errorString()));
398 return nullptr;
399 }
400
401 return placeManager;
402}
403
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
void setName(const QString &name)
\qmlproperty string Category::name
void setStatus(Status status, const QString &errorString=QString())
Q_INVOKABLE void save(const QString &parentId=QString())
\qmlmethod void Category::save()
QDeclarativeGeoServiceProvider * plugin
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setVisibility(Visibility visibility)
void setCategory(const QPlaceCategory &category)
void setPlugin(QDeclarativeGeoServiceProvider *plugin)
\qmlproperty Plugin Category::plugin
Q_INVOKABLE void remove()
\qmlmethod void Category::remove()
Q_INVOKABLE QString errorString() const
\qmlmethod string Category::errorString()
void setIcon(const QPlaceIcon &icon)
QDeclarativeCategory(QObject *parent=nullptr)
\qmltype Category \instantiates QDeclarativeCategory \inqmlmodule QtLocation
void setCategoryId(const QString &catID)
\qmlproperty string Category::categoryId
QGeoServiceProvider * sharedGeoServiceProvider() const
\inmodule QtLocation
Error error() const
Returns an error code describing the error which occurred during the last operation that was performe...
QPlaceManager * placeManager() const
Returns the QPlaceManager made available by the service provider.
QString errorString() const
Returns a string describing the error which occurred during the last operation that was performed by ...
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
\inmodule QtLocation
void setVisibility(QLocation::Visibility visibility)
Sets the visibility of the category.
void setCategoryId(const QString &identifier)
Sets the identifier of the category.
QString categoryId() const
Returns the identifier of the category.
void setIcon(const QPlaceIcon &icon)
Sets the icon of the category.
QLocation::Visibility visibility() const
Returns the visibility of the category.
void setName(const QString &name)
Sets the name of the category.
QString name() const
Returns the name of category.
QPlaceIcon icon() const
Returns the icon associated with the category.
\inmodule QtLocation
Definition qplaceicon.h:23
\inmodule QtLocation
\inmodule QtLocation
QPlaceIdReply * removeCategory(const QString &categoryId)
Removes the category corresponding to categoryId from the manager.
QPlaceIdReply * saveCategory(const QPlaceCategory &category, const QString &parentId=QString())
Saves a category that is a child of the category specified by parentId.
QPlaceReply::Error error() const
Returns the error code.
void finished()
This signal is emitted when this reply has finished processing.
virtual void abort()
Cancels the operation immediately.
QString errorString() const
Returns the error string of the reply.
virtual Type type() const
Returns the type of the reply.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1252
const QLoggingCategory & category()
[1]
QT_BEGIN_NAMESPACE const char CONTEXT_NAME[]
const char PLUGIN_NOT_VALID[]
const char PLUGIN_ERROR[]
const char PLUGIN_PROPERTY_NOT_SET[]
Combined button and popup list for selecting options.
GLuint name
SSL_CTX int void * arg
#define emit