diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-01-21 21:50:19 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-01-25 12:40:02 +0000 |
commit | dba67b9f0130dd680dc728524323af664158e230 (patch) | |
tree | 174c0a563cfd61d0865f376ca60caa443fb3122f /examples/location/geojson_viewer/main.cpp | |
parent | 20a64642c1c4a535b750e8b86435141ca432b050 (diff) | |
download | qtlocation-dba67b9f0130dd680dc728524323af664158e230.tar.gz |
Improve GeoJson Viewer example
Switches to Qt.labs.platform FileDialog and sets the proper initial
directory, as well as handles command line argument
Change-Id: I2ae4fc3244d1e2566556d3966aedf273ac98e3d1
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples/location/geojson_viewer/main.cpp')
-rw-r--r-- | examples/location/geojson_viewer/main.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/examples/location/geojson_viewer/main.cpp b/examples/location/geojson_viewer/main.cpp index 451df7ed..996c0925 100644 --- a/examples/location/geojson_viewer/main.cpp +++ b/examples/location/geojson_viewer/main.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2018 Julian Sherollari <jdotsh@gmail.com> +** Copyright (C) 2019 Julian Sherollari <jdotsh@gmail.com> +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -49,7 +49,7 @@ ** ****************************************************************************/ -#include <QGuiApplication> +#include <QApplication> #include <QQmlApplicationEngine> #include <QDebug> #include <QFile> @@ -68,6 +68,8 @@ #include <QtLocation/private/qdeclarativerectanglemapitem_p.h> #include <QJsonObject> #include <QJsonArray> +#include <QFileInfo> +#include <QtCore/qobjectdefs.h> class extractor { @@ -193,7 +195,6 @@ public slots: // Import geographic data to a QVariantList QVariantList modelList = QGeoJson::importGeoJson(loadDoc); - qDebug() << "Testing instant export for bbox and id members: " << QGeoJson::exportGeoJson(modelList); m_importedGeoJson = modelList; emit modelChanged(); return true; @@ -249,15 +250,24 @@ public: int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication app(argc, argv); + QApplication app(argc, argv); - // Switch to QML app QQmlApplicationEngine engine; + QUrl absoluteFilePath = argc > 1 ? + QUrl(QStringLiteral("file://") + QFileInfo(argv[1]).absoluteFilePath()) : + QUrl(); + engine.rootContext()->setContextProperty("dataPath", QUrl(QStringLiteral("file://") + + qPrintable(QT_STRINGIFY(SRC_PATH)) + + QStringLiteral("/data"))); qmlRegisterType<GeoJsoner>("Qt.GeoJson", 1, 0, "GeoJsoner"); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; + if (!absoluteFilePath.isEmpty()) { + GeoJsoner *geoJsoner = engine.rootObjects().first()->findChild<GeoJsoner*>(); + QMetaObject::invokeMethod(geoJsoner, "load", Qt::QueuedConnection, Q_ARG(QUrl, absoluteFilePath)); + } return app.exec(); } |