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
jsonparserhelpers.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 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 "jsonparserhelpers.h"
6
7#include <QtCore/QCoreApplication>
8#include <QtCore/QDateTime>
9#include <QtCore/QJsonObject>
10#include <QtCore/QJsonArray>
11#include <QtCore/QVariantMap>
12#include <QtPositioning/QGeoCoordinate>
13#include <QtLocation/QPlaceContentRequest>
14#include <QtLocation/QPlaceIcon>
15#include <QtLocation/QPlaceSupplier>
16#include <QtLocation/QPlaceContent>
17#include <QtLocation/QPlaceUser>
18#include <QtLocation/QPlaceContactDetail>
19#include <QtLocation/QPlaceCategory>
20
22
24{
25 return QGeoCoordinate(coordinateArray.at(0).toDouble(), coordinateArray.at(1).toDouble());
26}
27
30{
32
33 QPlaceSupplier supplier;
34 supplier.setName(supplierObject.value(QStringLiteral("title")).toString());
35 supplier.setUrl(supplierObject.value(QStringLiteral("href")).toString());
36
37 supplier.setIcon(engine->icon(supplierObject.value(QStringLiteral("icon")).toString()));
38
39 return supplier;
40}
41
44{
46
48
49 category.setName(categoryObject.value(QStringLiteral("title")).toString());
50
51 const QUrl href(categoryObject.value(QStringLiteral("href")).toString());
52 const QString hrefPath(href.path());
53 category.setCategoryId(hrefPath.mid(hrefPath.lastIndexOf(QLatin1Char('/')) + 1));
54
55
56 category.setIcon(engine->icon(categoryObject.value(QStringLiteral("icon")).toString()));
57 return category;
58}
59
60QList<QPlaceCategory> parseCategories(const QJsonArray &categoryArray,
62{
64
65 QList<QPlaceCategory> categoryList;
66 for (int i = 0; i < categoryArray.count(); ++i)
67 categoryList.append(parseCategory(categoryArray.at(i).toObject(),
68 engine));
69
70 return categoryList;
71}
72
73QList<QPlaceContactDetail> parseContactDetails(const QJsonArray &contacts)
74{
75 QList<QPlaceContactDetail> contactDetails;
76
77 for (int i = 0; i < contacts.count(); ++i) {
78 QJsonObject contact = contacts.at(i).toObject();
79
81 detail.setLabel(contact.value(QStringLiteral("label")).toString());
82 detail.setValue(contact.value(QStringLiteral("value")).toString());
83
84 contactDetails.append(detail);
85 }
86
87 return contactDetails;
88}
89
92{
94
96
97 image.setValue(QPlaceContent::ContentAttribution, imageObject.value(
98 QStringLiteral("attribution")).toString());
99 image.setValue(QPlaceContent::ImageUrl, imageObject.value(
100 QStringLiteral("src")).toString());
102 imageObject.value(QStringLiteral("supplier")).toObject(), engine)));
103
104 return image;
105}
106
109{
111
113
114 review.setValue(QPlaceContent::ReviewDateTime, QDateTime::fromString(
115 reviewObject.value(QStringLiteral("date")).toString()));
116
117 if (reviewObject.contains(QStringLiteral("title"))) {
118 review.setValue(QPlaceContent::ReviewTitle, reviewObject.value(
119 QStringLiteral("title")).toString());
120 }
121
122 if (reviewObject.contains(QStringLiteral("rating"))) {
123 review.setValue(QPlaceContent::ReviewRating, reviewObject.value(
124 QStringLiteral("rating")).toDouble());
125 }
126
127 review.setValue(QPlaceContent::ReviewText, reviewObject.value(
128 QStringLiteral("description")).toString());
129
130 QJsonObject userObject = reviewObject.value(QStringLiteral("user")).toObject();
131
132 QPlaceUser user;
133 user.setUserId(userObject.value(QStringLiteral("id")).toString());
134 user.setName(userObject.value(QStringLiteral("title")).toString());
135 review.setValue(QPlaceContent::ContentUser, QVariant::fromValue(user));
136
137 review.setValue(QPlaceContent::ContentAttribution, reviewObject.value(
138 QStringLiteral("attribution")).toString());
139
140 review.setValue(QPlaceContent::ReviewLanguage, reviewObject.value(
141 QStringLiteral("language")).toString());
142
144 reviewObject.value(QStringLiteral("supplier")).toObject(), engine)));
145
146 //if (reviewObject.contains(QStringLiteral("via"))) {
147 // QJsonObject viaObject = reviewObject.value(QStringLiteral("via")).toObject();
148 //}
149
150 return review;
151}
152
155{
157
159
160 editorial.setValue(QPlaceContent::ContentAttribution, editorialObject.value(QStringLiteral("attribution")).toString());
161
162 //if (editorialObject.contains(QStringLiteral("via"))) {
163 // QJsonObject viaObject = editorialObject.value(QStringLiteral("via")).toObject();
164 //}
165
167 editorialObject.value(QStringLiteral("supplier")).toObject(), engine)));
168 editorial.setValue(QPlaceContent::EditorialLanguage, editorialObject.value(
169 QStringLiteral("language")).toString());
170 editorial.setValue(QPlaceContent::EditorialText, editorialObject.value(
171 QStringLiteral("description")).toString());
172
173 return editorial;
174}
175
177 QPlaceContent::Collection *collection, int *totalCount,
180{
182
183 if (totalCount)
184 *totalCount = object.value(QStringLiteral("available")).toDouble();
185
186 int offset = 0;
187 if (object.contains(QStringLiteral("offset")))
188 offset = object.value(QStringLiteral("offset")).toDouble();
189
190 if (previous && object.contains(QStringLiteral("previous"))) {
191 previous->setContentType(type);
192 previous->setContentContext(QUrl(object.value(QStringLiteral("previous")).toString()));
193 }
194
195 if (next && object.contains(QStringLiteral("next"))) {
196 next->setContentType(type);
197 next->setContentContext(QUrl(object.value(QStringLiteral("next")).toString()));
198 }
199
200 if (collection) {
201 QJsonArray items = object.value(QStringLiteral("items")).toArray();
202 for (int i = 0; i < items.count(); ++i) {
203 QJsonObject itemObject = items.at(i).toObject();
204
205 switch (type) {
207 collection->insert(offset + i, parseImage(itemObject, engine));
208 break;
210 collection->insert(offset + i, parseReview(itemObject, engine));
211 break;
213 collection->insert(offset + i, parseEditorial(itemObject, engine));
214 break;
216 default:
217 break;
218 }
219 }
220 }
221}
222
\inmodule QtPositioning
\inmodule QtCore\reentrant
Definition qjsonarray.h:18
qsizetype count() const
Same as size().
Definition qjsonarray.h:42
QJsonValue at(qsizetype i) const
Returns a QJsonValue representing the value for index i.
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
QJsonValue value(const QString &key) const
Returns a QJsonValue representing the value for the key key.
QJsonObject toObject() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
T value(qsizetype i) const
Definition qlist.h:664
qsizetype count() const noexcept
Definition qlist.h:398
\inmodule QtLocation
The QPlaceContactDetail class represents a contact detail such as a phone number or website url.
\inmodule QtLocation
void setContentContext(const QVariant &context)
Sets the content context to context.
void setContentType(QPlaceContent::Type type)
Sets the type of content to be requested.
\inmodule QtLocation
Type
Defines the type of content.
\inmodule QtLocation
void setUrl(const QUrl &data)
Sets the url of the supplier's website.
void setName(const QString &data)
Sets the name of the supplier.
void setIcon(const QPlaceIcon &icon)
Sets the icon of the supplier.
\inmodule QtLocation
Definition qplaceuser.h:18
void setUserId(const QString &identifier)
void setName(const QString &name)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Definition qurl.cpp:2468
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
const QLoggingCategory & category()
[1]
QList< QPlaceContactDetail > parseContactDetails(const QJsonArray &contacts)
QList< QPlaceCategory > parseCategories(const QJsonArray &categoryArray, const QPlaceManagerEngineNokiaV2 *engine)
QT_BEGIN_NAMESPACE QGeoCoordinate parseCoordinate(const QJsonArray &coordinateArray)
QPlaceSupplier parseSupplier(const QJsonObject &supplierObject, const QPlaceManagerEngineNokiaV2 *engine)
QPlaceContent parseReview(const QJsonObject &reviewObject, const QPlaceManagerEngineNokiaV2 *engine)
QPlaceCategory parseCategory(const QJsonObject &categoryObject, const QPlaceManagerEngineNokiaV2 *engine)
void parseCollection(QPlaceContent::Type type, const QJsonObject &object, QPlaceContent::Collection *collection, int *totalCount, QPlaceContentRequest *previous, QPlaceContentRequest *next, const QPlaceManagerEngineNokiaV2 *engine)
QPlaceContent parseImage(const QJsonObject &imageObject, const QPlaceManagerEngineNokiaV2 *engine)
QPlaceContent parseEditorial(const QJsonObject &editorialObject, const QPlaceManagerEngineNokiaV2 *engine)
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition image.cpp:4
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLenum type
GLenum GLuint GLintptr offset
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
static double toDouble(Value v)
QList< QTreeWidgetItem * > items
char * toString(const MyType &t)
[31]
QJSEngine engine
[0]
\inmodule QtCore \reentrant
Definition qchar.h:18