Commit 2242019c authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Port EarthquakePlugin from QtScript to QJson*

parent 881e5d0c
......@@ -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} )
......@@ -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 ) ) {
......
Supports Markdown
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