summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 02:03:45 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 02:33:49 (GMT)
commit243317e06dcdf963b581b79b98d9c65373717c2c (patch)
tree232c3092e018137ec9e6ad2c0f6646ce5ebe5cba
parent63137bfa68c53b0621f0cceaababb2c6d7fafe80 (diff)
Port Weather plugin from QtScript to QJson*
-rw-r--r--src/plugins/render/weather/CMakeLists.txt2
-rw-r--r--src/plugins/render/weather/GeoNamesWeatherService.cpp56
-rw-r--r--src/plugins/render/weather/GeoNamesWeatherService.h4
3 files changed, 31 insertions, 31 deletions
diff --git a/src/plugins/render/weather/CMakeLists.txt b/src/plugins/render/weather/CMakeLists.txt
index df2eb35..b1aa129 100644
--- a/src/plugins/render/weather/CMakeLists.txt
+++ b/src/plugins/render/weather/CMakeLists.txt
@@ -25,6 +25,6 @@ set( weather_UI WeatherConfigWidget.ui )
qt_wrap_ui( weather_SRCS ${weather_UI} )
qt_add_resources( weather_SRCS weather.qrc )
-set( Weather_LIBS Qt5::Script Qt5::Svg )
+set(Weather_LIBS Qt5::Svg)
marble_add_plugin( Weather ${weather_SRCS} )
diff --git a/src/plugins/render/weather/GeoNamesWeatherService.cpp b/src/plugins/render/weather/GeoNamesWeatherService.cpp
index 568068b..e806473 100644
--- a/src/plugins/render/weather/GeoNamesWeatherService.cpp
+++ b/src/plugins/render/weather/GeoNamesWeatherService.cpp
@@ -18,9 +18,9 @@
#include <QUrl>
#include <QDateTime>
-#include <QScriptEngine>
-#include <QScriptValue>
-#include <QScriptValueIterator>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
#include <QUrlQuery>
@@ -79,26 +79,26 @@ void GeoNamesWeatherService::getItem( const QString &id )
void GeoNamesWeatherService::parseFile( const QByteArray& file )
{
- QScriptValue data;
- QScriptEngine engine;
-
- // Qt requires parentheses around json code
- data = engine.evaluate(QLatin1Char('(') + QString(file) + QLatin1Char(')'));
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(file);
+ QJsonValue weatherObservationsValue = jsonDoc.object().value(QStringLiteral("weatherObservations"));
// Parse if any result exists
QList<AbstractDataPluginItem*> items;
- if ( data.property( "weatherObservations" ).isArray() ) {
- QScriptValueIterator iterator( data.property( "weatherObservations" ) );
+ if (weatherObservationsValue.isArray()) {
// Add items to the list
- while ( iterator.hasNext() ) {
- iterator.next();
- AbstractDataPluginItem* item = parse( iterator.value() );
+ QJsonArray weatherObservationsArray = weatherObservationsValue.toArray();
+ for (int index = 0; index < weatherObservationsArray.size(); ++index) {
+ QJsonObject weatherObservationObject = weatherObservationsArray[index].toObject();
+
+ AbstractDataPluginItem* item = parse(weatherObservationObject);
if ( item ) {
items << item;
}
}
} else {
- AbstractDataPluginItem* item = parse( data.property( "weatherObservation" ) );
+ QJsonValue weatherObservationValue = jsonDoc.object().value(QStringLiteral("weatherObservation"));
+ QJsonObject weatherObservationObject = weatherObservationValue.toObject();
+ AbstractDataPluginItem* item = parse(weatherObservationObject);
if ( item ) {
items << item;
}
@@ -107,21 +107,21 @@ void GeoNamesWeatherService::parseFile( const QByteArray& file )
emit createdItems( items );
}
-AbstractDataPluginItem *GeoNamesWeatherService::parse( const QScriptValue &value )
+AbstractDataPluginItem *GeoNamesWeatherService::parse(const QJsonObject &weatherObservationObject)
{
- QString condition = value.property( "weatherCondition" ).toString();
- QString clouds = value.property( "clouds" ).toString();
- int windDirection = value.property( "windDirection" ).toInteger();
- QString id = value.property( "ICAO" ).toString();
- int temperature = value.property( "temperature" ).toInteger();
- int windSpeed = value.property( "windSpeed" ).toInteger();
- int humidity = value.property( "humidity" ).toInteger();
- double pressure = value.property( "seaLevelPressure" ).toNumber();
- QString name = value.property( "stationName" ).toString();
- QDateTime date = QDateTime::fromString(
- value.property( "datetime" ).toString(), "yyyy-MM-dd hh:mm:ss" );
- double longitude = value.property( "lng" ).toNumber();
- double latitude = value.property( "lat" ).toNumber();
+ const QString condition = weatherObservationObject.value(QStringLiteral("weatherCondition")).toString();
+ const QString clouds = weatherObservationObject.value(QStringLiteral("clouds")).toString();
+ const int windDirection = weatherObservationObject.value(QStringLiteral("windDirection")).toInt();
+ QString id = weatherObservationObject.value(QStringLiteral("ICAO")).toString();
+ const double temperature = weatherObservationObject.value(QStringLiteral("temperature")).toString().toDouble(); //delivered as string
+ const int windSpeed = weatherObservationObject.value(QStringLiteral("windSpeed")).toString().toInt(); //delivered as string
+ const int humidity = weatherObservationObject.value(QStringLiteral("humidity")).toInt();
+ const double pressure = weatherObservationObject.value(QStringLiteral("seaLevelPressure")).toDouble();
+ const QString name = weatherObservationObject.value(QStringLiteral("stationName")).toString();
+ const QDateTime date = QDateTime::fromString(
+ weatherObservationObject.value(QStringLiteral("datetime")).toString(), "yyyy-MM-dd hh:mm:ss" );
+ const double longitude = weatherObservationObject.value(QStringLiteral("lng")).toDouble();
+ const double latitude = weatherObservationObject.value(QStringLiteral("lat")).toDouble();
if ( !id.isEmpty() ) {
WeatherData data;
diff --git a/src/plugins/render/weather/GeoNamesWeatherService.h b/src/plugins/render/weather/GeoNamesWeatherService.h
index de834eb..6fa5fa4 100644
--- a/src/plugins/render/weather/GeoNamesWeatherService.h
+++ b/src/plugins/render/weather/GeoNamesWeatherService.h
@@ -14,7 +14,7 @@
#include "AbstractWeatherService.h"
#include "WeatherData.h"
-class QScriptValue;
+class QJsonObject;
namespace Marble
{
@@ -34,7 +34,7 @@ class GeoNamesWeatherService : public AbstractWeatherService
void parseFile( const QByteArray& file );
private:
- AbstractDataPluginItem* parse( const QScriptValue &value );
+ AbstractDataPluginItem* parse(const QJsonObject &weatherObservationObject);
static void setupHashes();
static QHash<QString, WeatherData::WeatherCondition> dayConditions;