summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 00:33:34 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 02:19:19 (GMT)
commit2242019ccaed1b48d4884eb20825a8fb367a89dd (patch)
tree69439c30867ef46dacb959a61a3e29c59621d9a6
parent881e5d0c8f8a614f2b36b41d8059690bb90c9648 (diff)
Port EarthquakePlugin from QtScript to QJson*
-rw-r--r--src/plugins/render/earthquake/CMakeLists.txt2
-rw-r--r--src/plugins/render/earthquake/EarthquakeModel.cpp39
2 files changed, 20 insertions, 21 deletions
diff --git a/src/plugins/render/earthquake/CMakeLists.txt b/src/plugins/render/earthquake/CMakeLists.txt
index 8be158d..6155743 100644
--- a/src/plugins/render/earthquake/CMakeLists.txt
+++ b/src/plugins/render/earthquake/CMakeLists.txt
@@ -15,6 +15,6 @@ set( earthquake_UI EarthquakeConfigWidget.ui )
qt_wrap_ui(my_SRCS ${earthquake_UI})
qt_add_resources(my_SRCS earthquake.qrc)
-set( EarthquakePlugin_LIBS Qt5::Script Qt5::Svg )
+set(EarthquakePlugin_LIBS Qt5::Svg)
marble_add_plugin( EarthquakePlugin ${my_SRCS} )
diff --git a/src/plugins/render/earthquake/EarthquakeModel.cpp b/src/plugins/render/earthquake/EarthquakeModel.cpp
index 8afd784..92afb9e 100644
--- a/src/plugins/render/earthquake/EarthquakeModel.cpp
+++ b/src/plugins/render/earthquake/EarthquakeModel.cpp
@@ -20,9 +20,9 @@
#include <QDebug>
#include <QString>
#include <QUrl>
-#include <QScriptEngine>
-#include <QScriptValue>
-#include <QScriptValueIterator>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
namespace Marble {
@@ -74,27 +74,26 @@ void EarthquakeModel::getAdditionalItems( const GeoDataLatLonAltBox& box, qint32
void EarthquakeModel::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 earthquakesValue = jsonDoc.object().value(QStringLiteral("earthquakes"));
// Parse if any result exists
- if ( data.property( "earthquakes" ).isArray() ) {
- QScriptValueIterator iterator( data.property( "earthquakes" ) );
+ if (earthquakesValue.isArray()) {
// Add items to the list
QList<AbstractDataPluginItem*> items;
- while ( iterator.hasNext() ) {
- iterator.next();
- // Converting earthquake's properties from QScriptValue to appropriate types
- QString eqid = iterator.value().property( "eqid" ).toString(); // Earthquake's ID
- double longitude = iterator.value().property( "lng" ).toNumber();
- double latitude = iterator.value().property( "lat" ).toNumber();
- double magnitude = iterator.value().property( "magnitude" ).toNumber();
- QString data = iterator.value().property( "datetime" ).toString();
- QDateTime date = QDateTime::fromString( data, "yyyy-MM-dd hh:mm:ss" );
- double depth = iterator.value().property( "depth" ).toNumber();
+
+ QJsonArray earthquakeArray = earthquakesValue.toArray();
+ for (int earthquakeIndex = 0; earthquakeIndex < earthquakeArray.size(); ++earthquakeIndex) {
+ QJsonObject levelObject = earthquakeArray[earthquakeIndex].toObject();
+
+ // Converting earthquake's properties from JSON to appropriate types
+ const QString eqid = levelObject.value(QStringLiteral("eqid")).toString(); // Earthquake's ID
+ const double longitude = levelObject.value(QStringLiteral("lng")).toDouble();
+ const double latitude = levelObject.value(QStringLiteral("lat")).toDouble();
+ const double magnitude = levelObject.value(QStringLiteral("magnitude")).toDouble();
+ const QString dateString = levelObject.value(QStringLiteral("datetime")).toString();
+ const QDateTime date = QDateTime::fromString(dateString, QStringLiteral("yyyy-MM-dd hh:mm:ss"));
+ const double depth = levelObject.value(QStringLiteral("depth")).toDouble();
if( date <= m_endDate && date >= m_startDate && magnitude >= m_minMagnitude ) {
if( !itemExists( eqid ) ) {