Port OpenDesktopPlugin from QtScript to QJson*

parent 2242019c
......@@ -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} )
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment