summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 01:41:39 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-09-11 02:19:19 (GMT)
commit63137bfa68c53b0621f0cceaababb2c6d7fafe80 (patch)
treeb74fcad81e61efe38e7da17af0eb0872e4b0ae54
parent6fc39be28efede63c67a18de1fad180be257cf40 (diff)
Port PostalCode plugin from QtScript to QJson*
-rw-r--r--src/plugins/render/postalcode/CMakeLists.txt2
-rw-r--r--src/plugins/render/postalcode/PostalCodeModel.cpp41
2 files changed, 19 insertions, 24 deletions
diff --git a/src/plugins/render/postalcode/CMakeLists.txt b/src/plugins/render/postalcode/CMakeLists.txt
index 1561a27..5c88664 100644
--- a/src/plugins/render/postalcode/CMakeLists.txt
+++ b/src/plugins/render/postalcode/CMakeLists.txt
@@ -12,6 +12,4 @@ set( postalcode_SRCS PostalCodePlugin.cpp
PostalCodeItem.cpp
PostalCodeItem.h )
-set( PostalCode_LIBS Qt5::Script )
-
marble_add_plugin( PostalCode ${postalcode_SRCS} )
diff --git a/src/plugins/render/postalcode/PostalCodeModel.cpp b/src/plugins/render/postalcode/PostalCodeModel.cpp
index 1a30374..cf15a7e 100644
--- a/src/plugins/render/postalcode/PostalCodeModel.cpp
+++ b/src/plugins/render/postalcode/PostalCodeModel.cpp
@@ -25,9 +25,9 @@
// Qt
#include <QString>
#include <QUrl>
-#include <QScriptEngine>
-#include <QScriptValue>
-#include <QScriptValueIterator>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
#include <QUrlQuery>
@@ -66,29 +66,26 @@ void PostalCodeModel::getAdditionalItems( const GeoDataLatLonAltBox& box,
void PostalCodeModel::parseFile( const QByteArray& file )
{
- QScriptValue data;
- QScriptEngine engine;
-
- // Qt requires parentheses around json code
- data = engine.evaluate(QLatin1Char('(') + QString::fromUtf8(file) + QLatin1Char(')'));
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(file);
+ QJsonValue postalCodesValue = jsonDoc.object().value(QStringLiteral("postalCodes"));
// Parse if any result exists
- if ( data.property( "postalCodes" ).isArray() ) {
- QScriptValueIterator iterator( data.property( "postalCodes" ) );
-
+ if (postalCodesValue.isArray()) {
// Add items to the list
QList<AbstractDataPluginItem*> items;
- while ( iterator.hasNext() ) {
- iterator.next();
-
- QString const placeName = iterator.value().property( "placeName" ).toString();
- QString const adminName1 = iterator.value().property( "adminName1" ).toString();
- QString const adminName2 = iterator.value().property( "adminName2" ).toString();
- QString const adminName3 = iterator.value().property( "adminName3" ).toString();
- QString const postalCode = iterator.value().property( "postalCode" ).toString();
- QString const countryCode = iterator.value().property( "countryCode" ).toString();
- double const longitude = iterator.value().property( "lng" ).toNumber();
- double const latitude = iterator.value().property( "lat" ).toNumber();
+
+ QJsonArray postalCodesArray = postalCodesValue.toArray();
+ for (int index = 0; index < postalCodesArray.size(); ++index) {
+ QJsonObject postalCodeObject = postalCodesArray[index].toObject();
+
+ QString const placeName = postalCodeObject.value(QStringLiteral("placeName")).toString();
+ QString const adminName1 = postalCodeObject.value(QStringLiteral("adminName1")).toString();
+ QString const adminName2 = postalCodeObject.value(QStringLiteral("adminName2")).toString();
+ QString const adminName3 = postalCodeObject.value(QStringLiteral("adminName3")).toString();
+ QString const postalCode = postalCodeObject.value(QStringLiteral("postalCode")).toString();
+ QString const countryCode = postalCodeObject.value(QStringLiteral("countryCode")).toString();
+ double const longitude = postalCodeObject.value(QStringLiteral("lng")).toDouble();
+ double const latitude = postalCodeObject.value(QStringLiteral("lat")).toDouble();
QString const id = QLatin1String("postalCode_") + countryCode + postalCode;