summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 22:56:44 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 22:56:44 (GMT)
commitaa3e0ffe312ed796f7cfb716438a6faa2038f6d5 (patch)
tree9321690682daf946006df9c78459cd86efebba11
parentc97daf2039ac42b70ab776f139d7c82a21c59099 (diff)
Port FoursquarePlugin from QtScript to QJson*
-rw-r--r--src/plugins/render/foursquare/CMakeLists.txt2
-rw-r--r--src/plugins/render/foursquare/FoursquareModel.cpp67
2 files changed, 36 insertions, 33 deletions
diff --git a/src/plugins/render/foursquare/CMakeLists.txt b/src/plugins/render/foursquare/CMakeLists.txt
index 68cf33b..1f6c139 100644
--- a/src/plugins/render/foursquare/CMakeLists.txt
+++ b/src/plugins/render/foursquare/CMakeLists.txt
@@ -11,7 +11,5 @@ set( my_SRCS
FoursquareItem.cpp
)
-set( FoursquarePlugin_LIBS Qt5::Script Qt5::Svg )
-
marble_add_plugin( FoursquarePlugin ${my_SRCS} )
diff --git a/src/plugins/render/foursquare/FoursquareModel.cpp b/src/plugins/render/foursquare/FoursquareModel.cpp
index e6ce0d2..12ef8de 100644
--- a/src/plugins/render/foursquare/FoursquareModel.cpp
+++ b/src/plugins/render/foursquare/FoursquareModel.cpp
@@ -20,9 +20,9 @@
#include "MarbleMath.h"
#include <QUrl>
-#include <QScriptEngine>
-#include <QScriptValue>
-#include <QScriptValueIterator>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
namespace Marble
{
@@ -71,40 +71,46 @@ void FoursquareModel::getAdditionalItems( const GeoDataLatLonAltBox& box, qint32
void FoursquareModel::parseFile( const QByteArray& file )
{
- QScriptValue data;
- QScriptEngine engine;
- // Qt requires parentheses around JSON
- data = engine.evaluate(QLatin1Char('(') + QString::fromUtf8(file) + QLatin1Char(')'));
- data = data.property("response");
-
+ const QJsonDocument jsonDoc = QJsonDocument::fromJson(file);
+ const QJsonObject responseObject = jsonDoc.object().value(QStringLiteral("response")).toObject();
+ const QJsonValue venuesValue = responseObject.value(QStringLiteral("response"));
+
// Parse if any result exists
- if ( data.property( "venues" ).isArray() ) {
- QScriptValueIterator iterator( data.property( "venues" ) );
+ if (venuesValue.isArray()) {
// Add items to the list
QList<AbstractDataPluginItem*> items;
- do {
- iterator.next();
- QString id = iterator.value().property( "id" ).toString();
- QString name = iterator.value().property( "name" ).toString();
- QString category = iterator.value().property( "categories" ).property( 0 ).property( "name" ).toString();
- QString address = iterator.value().property( "location" ).property( "address" ).toString();
- QString city = iterator.value().property( "location" ).property( "city" ).toString();
- QString country = iterator.value().property( "location" ).property( "country" ).toString();
- double latitude = iterator.value().property( "location" ).property( "lat" ).toString().toDouble();
- double longitude = iterator.value().property( "location" ).property( "lng" ).toString().toDouble();
- int usersCount = iterator.value().property( "stats" ).property( "usersCount" ).toInteger();
-
- QScriptValue categoryIcon = iterator.value().property( "categories" ).property( 0 ).property( "icon" );
+
+ const QJsonArray venueArray = venuesValue.toArray();
+ for (int venueIndex = 0; venueIndex < venueArray.size(); ++venueIndex) {
+ const QJsonObject venueObject = venueArray[venueIndex].toObject();
+
+ const QJsonObject firstCategoryObject = venueObject.value(QStringLiteral("categories")).toArray().at(0).toObject();
+
+ const QString id = venueObject.value(QStringLiteral("id")).toString();
+ const QString name = venueObject.value(QStringLiteral("name")).toString();
+ const QString category = firstCategoryObject.value(QStringLiteral("name")).toString();
+ const QJsonObject locationObject = venueObject.value(QStringLiteral("location")).toObject();
+ const QString address = locationObject.value(QStringLiteral("address")).toString();
+ const QString city = locationObject.value(QStringLiteral("city")).toString();
+ const QString country = locationObject.value(QStringLiteral("country")).toString();
+ const double latitude = locationObject.value(QStringLiteral("lat")).toString().toDouble();
+ const double longitude = locationObject.value(QStringLiteral("lng")).toString().toDouble();
+ const int usersCount = venueObject.value(QStringLiteral("stats")).toObject().value(QStringLiteral("usersCount")).toInt();
+
+ const QJsonValue categoryIconValue = firstCategoryObject.value(QStringLiteral("icon"));
QString iconUrl;
QString largeIconUrl;
- if ( categoryIcon.isValid() ) {
- iconUrl = categoryIcon.property( "prefix" ).toString()
+ if (categoryIconValue.isObject()) {
+ const QJsonObject categoryIconObject = categoryIconValue.toObject();
+ const QString iconPrefix = categoryIconObject.value(QStringLiteral("prefix")).toString();
+ const QString iconName = categoryIconObject.value(QStringLiteral("name")).toString();
+ iconUrl = iconPrefix
+ QLatin1String("32") // That's the icon size hardcoded
- + categoryIcon.property( "name" ).toString();
-
- largeIconUrl = categoryIcon.property( "prefix" ).toString()
+ + iconName;
+
+ largeIconUrl = iconPrefix
+ QLatin1String("64") // Larger icon
- + categoryIcon.property( "name" ).toString();
+ + iconName;
}
if( !itemExists( id ) ) {
@@ -124,7 +130,6 @@ void FoursquareModel::parseFile( const QByteArray& file )
items << item;
}
}
- while ( iterator.hasNext() );
addItemsToList( items );
}
}