summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2019-01-21 21:50:19 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2019-01-25 12:40:02 +0000
commitdba67b9f0130dd680dc728524323af664158e230 (patch)
tree174c0a563cfd61d0865f376ca60caa443fb3122f /examples
parent20a64642c1c4a535b750e8b86435141ca432b050 (diff)
downloadqtlocation-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')
-rw-r--r--examples/location/geojson_viewer/GeoJsonDelegate.qml23
-rw-r--r--examples/location/geojson_viewer/data/09-featurecollection.json6
-rw-r--r--examples/location/geojson_viewer/geojson_viewer.pro3
-rw-r--r--examples/location/geojson_viewer/main.cpp22
-rw-r--r--examples/location/geojson_viewer/main.qml70
5 files changed, 72 insertions, 52 deletions
diff --git a/examples/location/geojson_viewer/GeoJsonDelegate.qml b/examples/location/geojson_viewer/GeoJsonDelegate.qml
index 2f550e8a..d3e8db93 100644
--- a/examples/location/geojson_viewer/GeoJsonDelegate.qml
+++ b/examples/location/geojson_viewer/GeoJsonDelegate.qml
@@ -1,6 +1,7 @@
/****************************************************************************
**
-** 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/
**
** This file is part of the examples of the Qt Toolkit.
@@ -57,7 +58,7 @@ DelegateChooser {
id: dc
role: "type"
property color defaultColor: "grey"
- property real defaultOpacity: 0.4
+ property real defaultOpacity: 0.7
DelegateChoice {
roleValue: "Point"
@@ -65,11 +66,14 @@ DelegateChooser {
property string geojsonType: "Point"
property var props: modelData.properties
geoShape: modelData.data
- radius: 100*100
+ radius: 20*1000
border.width: 3
opacity: dc.defaultOpacity
- color: ((props !== undefined && props["color"] !== undefined) ? props["color"] :
- ((parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"]: dc.defaultColor))
+ /* The expression below is equivalent to:
+ ((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 {
property string geojsonType: "LineString"
property var props: modelData.properties
geoShape: modelData.data
- line.width: 1
+ line.width: 3
opacity: dc.defaultOpacity
- line.color: ((props !== undefined && props["color"] !== undefined) ? props["color"] :
- ((parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"]: dc.defaultColor))
+ line.color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
}
}
@@ -93,8 +96,8 @@ DelegateChooser {
property var props: modelData.properties
geoShape: modelData.data
opacity: dc.defaultOpacity
- color: ((props !== undefined && props["color"] !== undefined) ? props["color"] :
- ((parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"]: dc.defaultColor))
+ color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
+ border.width: 0
}
}
diff --git a/examples/location/geojson_viewer/data/09-featurecollection.json b/examples/location/geojson_viewer/data/09-featurecollection.json
index 6fc20f21..e3e9a2d2 100644
--- a/examples/location/geojson_viewer/data/09-featurecollection.json
+++ b/examples/location/geojson_viewer/data/09-featurecollection.json
@@ -1,5 +1,8 @@
{
"type" : "FeatureCollection",
+ "properties" : {
+ "color" : "crimson"
+ },
"features" : [
{
"type" : "Feature",
@@ -30,7 +33,8 @@
"type" : "Feature",
"id" : "MultiLine",
"properties" : {
- "text" : "This is a Feature with a MultiLineString"
+ "text" : "This is a Feature with a MultiLineString",
+ "color" : "deepskyblue"
},
"geometry" : {
"type" : "MultiLineString",
diff --git a/examples/location/geojson_viewer/geojson_viewer.pro b/examples/location/geojson_viewer/geojson_viewer.pro
index 891c636d..cf261b36 100644
--- a/examples/location/geojson_viewer/geojson_viewer.pro
+++ b/examples/location/geojson_viewer/geojson_viewer.pro
@@ -1,7 +1,7 @@
TARGET = qml_location_geojsonviewer
TEMPLATE = app
-QT += qml network quick positioning location-private
+QT += core qml network quick positioning location-private widgets
SOURCES += main.cpp
CONFIG += c++11
CONFIG += install_ok
@@ -17,3 +17,4 @@ OTHER_FILES += \
target.path = $$[QT_INSTALL_EXAMPLES]/location/geojsonviewer
INSTALLS += target
+DEFINES += $$shell_quote(SRC_PATH=$$PWD)
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();
}
diff --git a/examples/location/geojson_viewer/main.qml b/examples/location/geojson_viewer/main.qml
index cc3fbd3f..01faef5f 100644
--- a/examples/location/geojson_viewer/main.qml
+++ b/examples/location/geojson_viewer/main.qml
@@ -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.
@@ -50,9 +50,9 @@
****************************************************************************/
import QtQuick 2.11
-import QtQuick.Controls 1.4
+import QtQuick.Controls 1.4 as C1
import QtQuick.Controls.Styles 1.4
-import QtQuick.Dialogs 1.3
+import Qt.labs.platform 1.1
import QtQuick.Layouts 1.11
import QtQuick.Window 2.11
import QtPositioning 5.12
@@ -60,7 +60,7 @@ import QtLocation 5.12
import Qt.labs.qmlmodels 1.0
import Qt.GeoJson 1.0
-ApplicationWindow {
+C1.ApplicationWindow {
visible: true
width: 1024
height: 1024
@@ -70,71 +70,73 @@ ApplicationWindow {
FileDialog {
visible: false
id: fileDialog
- title: "Please choose a GeoJSON file"
- folder: shortcuts.home
+ title: "Choose a GeoJSON file"
+ fileMode: FileDialog.OpenFile
+ folder: dataPath
onAccepted: {
- geoJsoner.load(fileDialog.fileUrl)
+ geoJsoner.load(fileDialog.file)
}
}
FileDialog {
- selectExisting : false
visible: false
id: fileWriteDialog
title: "Write your geometry to a file"
- folder: shortcuts.home
+ fileMode: FileDialog.SaveFile
+ folder: StandardPaths.writableLocation(StandardPaths.TempLocation)
onAccepted: {
- geoJsoner.dumpGeoJSON(geoJsoner.toGeoJson(miv), fileWriteDialog.fileUrl);
+ geoJsoner.dumpGeoJSON(geoJsoner.toGeoJson(miv), fileWriteDialog.file);
}
}
FileDialog {
- selectExisting : false
visible: false
id: debugWriteDialog
title: "Write Qvariant debug view"
- folder: shortcuts.home
+ fileMode: FileDialog.SaveFile
+ folder: StandardPaths.writableLocation(StandardPaths.TempLocation)
onAccepted: {
- geoJsoner.writeDebug(geoJsoner.toGeoJson(miv), debugWriteDialog.fileUrl);
+ geoJsoner.writeDebug(geoJsoner.toGeoJson(miv), debugWriteDialog.file);
}
}
- MenuBar {
+ C1.MenuBar {
id: mainMenu
- Menu {
- title: "GeoJSON"
+ C1.Menu {
+ title: "&File"
id : geoJsonMenu
- MenuItem {
- text: "Import"
- shortcut: "Ctrl+I"
- id : geoJsonMenuOpen
+ C1.MenuItem {
+ text: "&Open"
+ shortcut: StandardKey.Open
onTriggered: {
fileDialog.open()
}
}
- MenuItem {
- text: "Export"
- shortcut: "Ctrl+E"
- id : geoJsonWrite
- onTriggered: {
+ C1.MenuItem {
+ text: "&Export"
+ shortcut: StandardKey.Save
+ onTriggered: {
fileWriteDialog.open()
}
}
+ C1.MenuItem {
+ text: "E&xit"
+ shortcut: StandardKey.Quit
+ onTriggered: Qt.quit()
+ }
}
- Menu {
- title: "Debug"
+ C1.Menu {
+ title: "&Debug"
id : debugMenu
- MenuItem {
- text: "Print debug data to file"
- shortcut: "Ctrl+D"
- id : debugMenuWrite
+ C1.MenuItem {
+ text: "Print debug data to &file"
onTriggered: {
debugWriteDialog.open()
}
}
- MenuItem {
- text: "Print debug data"
+ C1.MenuItem {
+ text: "&Print debug data"
onTriggered: {
geoJsoner.print(miv)
}