Commit dba67b9f authored by Paolo Angelelli's avatar Paolo Angelelli
Browse files

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: default avatarShawn Rutledge <shawn.rutledge@qt.io>
parent 20a64642
No related merge requests found
Showing with 72 additions and 52 deletions
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2018 The Qt Company Ltd. ** Copyright (C) 2019 Julian Sherollari <jdotsh@gmail.com>
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
...@@ -57,7 +58,7 @@ DelegateChooser { ...@@ -57,7 +58,7 @@ DelegateChooser {
id: dc id: dc
role: "type" role: "type"
property color defaultColor: "grey" property color defaultColor: "grey"
property real defaultOpacity: 0.4 property real defaultOpacity: 0.7
DelegateChoice { DelegateChoice {
roleValue: "Point" roleValue: "Point"
...@@ -65,11 +66,14 @@ DelegateChooser { ...@@ -65,11 +66,14 @@ DelegateChooser {
property string geojsonType: "Point" property string geojsonType: "Point"
property var props: modelData.properties property var props: modelData.properties
geoShape: modelData.data geoShape: modelData.data
radius: 100*100 radius: 20*1000
border.width: 3 border.width: 3
opacity: dc.defaultOpacity opacity: dc.defaultOpacity
color: ((props !== undefined && props["color"] !== undefined) ? props["color"] : /* The expression below is equivalent to:
((parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"]: dc.defaultColor)) ((props !== undefined && props["color"] !== undefined) ? props["color"] :
((parent && parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"] : dc.defaultColor))
*/
color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
} }
} }
...@@ -79,10 +83,9 @@ DelegateChooser { ...@@ -79,10 +83,9 @@ DelegateChooser {
property string geojsonType: "LineString" property string geojsonType: "LineString"
property var props: modelData.properties property var props: modelData.properties
geoShape: modelData.data geoShape: modelData.data
line.width: 1 line.width: 3
opacity: dc.defaultOpacity opacity: dc.defaultOpacity
line.color: ((props !== undefined && props["color"] !== undefined) ? props["color"] : line.color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
((parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"]: dc.defaultColor))
} }
} }
...@@ -93,8 +96,8 @@ DelegateChooser { ...@@ -93,8 +96,8 @@ DelegateChooser {
property var props: modelData.properties property var props: modelData.properties
geoShape: modelData.data geoShape: modelData.data
opacity: dc.defaultOpacity opacity: dc.defaultOpacity
color: ((props !== undefined && props["color"] !== undefined) ? props["color"] : color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
((parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"]: dc.defaultColor)) border.width: 0
} }
} }
......
{ {
"type" : "FeatureCollection", "type" : "FeatureCollection",
"properties" : {
"color" : "crimson"
},
"features" : [ "features" : [
{ {
"type" : "Feature", "type" : "Feature",
...@@ -30,7 +33,8 @@ ...@@ -30,7 +33,8 @@
"type" : "Feature", "type" : "Feature",
"id" : "MultiLine", "id" : "MultiLine",
"properties" : { "properties" : {
"text" : "This is a Feature with a MultiLineString" "text" : "This is a Feature with a MultiLineString",
"color" : "deepskyblue"
}, },
"geometry" : { "geometry" : {
"type" : "MultiLineString", "type" : "MultiLineString",
......
TARGET = qml_location_geojsonviewer TARGET = qml_location_geojsonviewer
TEMPLATE = app TEMPLATE = app
QT += qml network quick positioning location-private QT += core qml network quick positioning location-private widgets
SOURCES += main.cpp SOURCES += main.cpp
CONFIG += c++11 CONFIG += c++11
CONFIG += install_ok CONFIG += install_ok
...@@ -17,3 +17,4 @@ OTHER_FILES += \ ...@@ -17,3 +17,4 @@ OTHER_FILES += \
target.path = $$[QT_INSTALL_EXAMPLES]/location/geojsonviewer target.path = $$[QT_INSTALL_EXAMPLES]/location/geojsonviewer
INSTALLS += target INSTALLS += target
DEFINES += $$shell_quote(SRC_PATH=$$PWD)
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2019 Julian Sherollari <jdotsh@gmail.com>
** Copyright (C) 2018 Julian Sherollari <jdotsh@gmail.com> ** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QGuiApplication> #include <QApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
...@@ -68,6 +68,8 @@ ...@@ -68,6 +68,8 @@
#include <QtLocation/private/qdeclarativerectanglemapitem_p.h> #include <QtLocation/private/qdeclarativerectanglemapitem_p.h>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QFileInfo>
#include <QtCore/qobjectdefs.h>
class extractor class extractor
{ {
...@@ -193,7 +195,6 @@ public slots: ...@@ -193,7 +195,6 @@ public slots:
// Import geographic data to a QVariantList // Import geographic data to a QVariantList
QVariantList modelList = QGeoJson::importGeoJson(loadDoc); QVariantList modelList = QGeoJson::importGeoJson(loadDoc);
qDebug() << "Testing instant export for bbox and id members: " << QGeoJson::exportGeoJson(modelList);
m_importedGeoJson = modelList; m_importedGeoJson = modelList;
emit modelChanged(); emit modelChanged();
return true; return true;
...@@ -249,15 +250,24 @@ public: ...@@ -249,15 +250,24 @@ public:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv); QApplication app(argc, argv);
// Switch to QML app
QQmlApplicationEngine engine; 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"); qmlRegisterType<GeoJsoner>("Qt.GeoJson", 1, 0, "GeoJsoner");
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())
return -1; 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(); return app.exec();
} }
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2019 Julian Sherollari <jdotsh@gmail.com>
** Copyright (C) 2018 Julian Sherollari <jdotsh@gmail.com> ** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
...@@ -50,9 +50,9 @@ ...@@ -50,9 +50,9 @@
****************************************************************************/ ****************************************************************************/
import QtQuick 2.11 import QtQuick 2.11
import QtQuick.Controls 1.4 import QtQuick.Controls 1.4 as C1
import QtQuick.Controls.Styles 1.4 import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.3 import Qt.labs.platform 1.1
import QtQuick.Layouts 1.11 import QtQuick.Layouts 1.11
import QtQuick.Window 2.11 import QtQuick.Window 2.11
import QtPositioning 5.12 import QtPositioning 5.12
...@@ -60,7 +60,7 @@ import QtLocation 5.12 ...@@ -60,7 +60,7 @@ import QtLocation 5.12
import Qt.labs.qmlmodels 1.0 import Qt.labs.qmlmodels 1.0
import Qt.GeoJson 1.0 import Qt.GeoJson 1.0
ApplicationWindow { C1.ApplicationWindow {
visible: true visible: true
width: 1024 width: 1024
height: 1024 height: 1024
...@@ -70,71 +70,73 @@ ApplicationWindow { ...@@ -70,71 +70,73 @@ ApplicationWindow {
FileDialog { FileDialog {
visible: false visible: false
id: fileDialog id: fileDialog
title: "Please choose a GeoJSON file" title: "Choose a GeoJSON file"
folder: shortcuts.home fileMode: FileDialog.OpenFile
folder: dataPath
onAccepted: { onAccepted: {
geoJsoner.load(fileDialog.fileUrl) geoJsoner.load(fileDialog.file)
} }
} }
FileDialog { FileDialog {
selectExisting : false
visible: false visible: false
id: fileWriteDialog id: fileWriteDialog
title: "Write your geometry to a file" title: "Write your geometry to a file"
folder: shortcuts.home fileMode: FileDialog.SaveFile
folder: StandardPaths.writableLocation(StandardPaths.TempLocation)
onAccepted: { onAccepted: {
geoJsoner.dumpGeoJSON(geoJsoner.toGeoJson(miv), fileWriteDialog.fileUrl); geoJsoner.dumpGeoJSON(geoJsoner.toGeoJson(miv), fileWriteDialog.file);
} }
} }
FileDialog { FileDialog {
selectExisting : false
visible: false visible: false
id: debugWriteDialog id: debugWriteDialog
title: "Write Qvariant debug view" title: "Write Qvariant debug view"
folder: shortcuts.home fileMode: FileDialog.SaveFile
folder: StandardPaths.writableLocation(StandardPaths.TempLocation)
onAccepted: { onAccepted: {
geoJsoner.writeDebug(geoJsoner.toGeoJson(miv), debugWriteDialog.fileUrl); geoJsoner.writeDebug(geoJsoner.toGeoJson(miv), debugWriteDialog.file);
} }
} }
MenuBar { C1.MenuBar {
id: mainMenu id: mainMenu
Menu { C1.Menu {
title: "GeoJSON" title: "&File"
id : geoJsonMenu id : geoJsonMenu
MenuItem { C1.MenuItem {
text: "Import" text: "&Open"
shortcut: "Ctrl+I" shortcut: StandardKey.Open
id : geoJsonMenuOpen
onTriggered: { onTriggered: {
fileDialog.open() fileDialog.open()
} }
} }
MenuItem { C1.MenuItem {
text: "Export" text: "&Export"
shortcut: "Ctrl+E" shortcut: StandardKey.Save
id : geoJsonWrite onTriggered: {
onTriggered: {
fileWriteDialog.open() fileWriteDialog.open()
} }
} }
C1.MenuItem {
text: "E&xit"
shortcut: StandardKey.Quit
onTriggered: Qt.quit()
}
} }
Menu { C1.Menu {
title: "Debug" title: "&Debug"
id : debugMenu id : debugMenu
MenuItem { C1.MenuItem {
text: "Print debug data to file" text: "Print debug data to &file"
shortcut: "Ctrl+D"
id : debugMenuWrite
onTriggered: { onTriggered: {
debugWriteDialog.open() debugWriteDialog.open()
} }
} }
MenuItem { C1.MenuItem {
text: "Print debug data" text: "&Print debug data"
onTriggered: { onTriggered: {
geoJsoner.print(miv) geoJsoner.print(miv)
} }
......
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