summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 00:57:42 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 02:19:19 (GMT)
commit4915d5894b8808b7328317cea9a6895a0764e43d (patch)
tree3629cb1b56fcf32db8b0be5d464c7efedaf013c9
parent2242019ccaed1b48d4884eb20825a8fb367a89dd (diff)
Port OpenDesktopPlugin from QtScript to QJson*
-rw-r--r--src/plugins/render/opendesktop/CMakeLists.txt2
-rw-r--r--src/plugins/render/opendesktop/OpenDesktopModel.cpp49
2 files changed, 24 insertions, 27 deletions
diff --git a/src/plugins/render/opendesktop/CMakeLists.txt b/src/plugins/render/opendesktop/CMakeLists.txt
index 72c7129..a7a556b 100644
--- a/src/plugins/render/opendesktop/CMakeLists.txt
+++ b/src/plugins/render/opendesktop/CMakeLists.txt
@@ -14,6 +14,4 @@ set( my_SRCS
set( opendesktop_UI OpenDesktopConfigWidget.ui )
qt_wrap_ui( my_SRCS ${opendesktop_UI} )
-set( OpenDesktopPlugin_LIBS Qt5::Script )
-
marble_add_plugin( OpenDesktopPlugin ${my_SRCS} )
diff --git a/src/plugins/render/opendesktop/OpenDesktopModel.cpp b/src/plugins/render/opendesktop/OpenDesktopModel.cpp
index 6a61129..c040c81 100644
--- a/src/plugins/render/opendesktop/OpenDesktopModel.cpp
+++ b/src/plugins/render/opendesktop/OpenDesktopModel.cpp
@@ -17,10 +17,10 @@
#include "GeoDataCoordinates.h"
#include <QString>
#include <QUrl>
-#include <QScriptEngine>
-#include <QScriptValue>
-#include <QScriptValueIterator>
-
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+
using namespace Marble;
@@ -60,30 +60,29 @@ void OpenDesktopModel::getAdditionalItems( const GeoDataLatLonAltBox& box, qint3
void OpenDesktopModel::parseFile( const QByteArray& file )
{
- QScriptValue data;
- QScriptEngine engine;
- data = engine.evaluate(QLatin1Char('(') + QString(file) + QLatin1Char(')'));
-
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(file);
+ QJsonValue dataValue = jsonDoc.object().value(QStringLiteral("data"));
+
// Parse if any result exists
- if ( data.property( "data" ).isArray() )
- {
- QScriptValueIterator iterator( data.property( "data" ) );
+ if (dataValue.isArray()) {
// Add items to the list
QList<AbstractDataPluginItem*> items;
- while ( iterator.hasNext() )
- {
- iterator.next();
- // Convert profile's properties from QScriptValue to appropriate types
- QString personid = iterator.value().property( "personid" ).toString();
- QString firstName = iterator.value().property( "firstname" ).toString();
- QString lastName = iterator.value().property( "lastname" ).toString();
- QString city = iterator.value().property( "city" ).toString();
- QString country = iterator.value().property( "country" ).toString();
- QString role = iterator.value().property( "communityrole" ).toString();
- double longitude = iterator.value().property( "longitude" ).toNumber();
- double latitude = iterator.value().property( "latitude" ).toNumber();
- QUrl avatarUrl( iterator.value().property( "avatarpic" ).toString() );
-
+
+ QJsonArray dataArray = dataValue.toArray();
+ for (int index = 0; index < dataArray.size(); ++index) {
+ QJsonObject dataObject = dataArray[index].toObject();
+
+ // Convert profile's properties from JSON to appropriate types
+ const QString personid = dataObject.value(QStringLiteral("personid")).toString();
+ const QString firstName = dataObject.value(QStringLiteral("firstname")).toString();
+ const QString lastName = dataObject.value(QStringLiteral("lastname")).toString();
+ const QString city = dataObject.value(QStringLiteral("city")).toString();
+ const QString country = dataObject.value(QStringLiteral("country")).toString();
+ const QString role = dataObject.value(QStringLiteral("communityrole")).toString();
+ const double longitude = dataObject.value(QStringLiteral("longitude")).toDouble();
+ const double latitude = dataObject.value(QStringLiteral("latitude")).toDouble();
+ const QUrl avatarUrl(dataObject.value(QStringLiteral("avatarpic")).toString());
+
if( !itemExists( personid ) )
{
// If it does not exists, create it