summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-11-14 21:19:30 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2022-11-15 10:56:23 +0100
commit76c0afd59040b158379c2b9fe116a8fead82f308 (patch)
treef124521fb4012cc73dc01b4f4ba462ca355408fc
parent70c6c9df8ea961d28e7e513450856db7e497abd7 (diff)
downloadqtlocation-76c0afd59040b158379c2b9fe116a8fead82f308.tar.gz
Get the geojson example working again
fdbbfa4a6723b816478ee011ab4098e5332dc2f5 removed MapObjectView, but this example continued to depend on it. This reverts parts of commit be7cbed7411d024d178377bd327d5916c80e02a0. Also: - use QtCore.StandardPaths rather than Qt.labs.platform - remove the widgets dependency - use FileDialog.nameFilters to read and write geojson files Let's assume that FileDialog.selectedFile will actually output a QUrl to save the file to, as opposed to a plain path, since the dumpGeoJSON() function is calling toLocalFile() on it. At least that works with native dialogs. Task-number: QTBUG-108455 Change-Id: I1f14c6425115aa95ac2080438ff0c3a24b1b7196 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--examples/location/geojson_viewer/CMakeLists.txt2
-rw-r--r--examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml152
-rw-r--r--examples/location/geojson_viewer/geojson_viewer.pro2
-rw-r--r--examples/location/geojson_viewer/main.cpp4
-rw-r--r--examples/location/geojson_viewer/main.qml41
-rw-r--r--examples/location/geojson_viewer/qml.qrc1
6 files changed, 9 insertions, 193 deletions
diff --git a/examples/location/geojson_viewer/CMakeLists.txt b/examples/location/geojson_viewer/CMakeLists.txt
index 7de77f58..8a584b8c 100644
--- a/examples/location/geojson_viewer/CMakeLists.txt
+++ b/examples/location/geojson_viewer/CMakeLists.txt
@@ -22,7 +22,6 @@ find_package(Qt6 COMPONENTS Network)
find_package(Qt6 COMPONENTS Quick)
find_package(Qt6 COMPONENTS Positioning)
find_package(Qt6 COMPONENTS Location)
-find_package(Qt6 COMPONENTS Widgets)
qt_add_executable(qml_location_geojsonviewer WIN32 MACOSX_BUNDLE
main.cpp
@@ -35,7 +34,6 @@ target_link_libraries(qml_location_geojsonviewer PUBLIC
Qt::Positioning
Qt::Qml
Qt::Quick
- Qt::Widgets
)
diff --git a/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml b/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
deleted file mode 100644
index ba95b1c8..00000000
--- a/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 Paolo Angelelli <paolo.angelelli@gmail.com>
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick
-import QtPositioning
-import Qt.labs.qmlmodels 1.0
-import Qt.labs.location
-
-DelegateChooser {
- id: dc
- role: "type"
- property color defaultColor: "grey"
-
- DelegateChoice {
- roleValue: "Point"
- delegate: MapCircleObject {
- property string geojsonType: "Point"
- property var props: modelData.properties
- geoShape: modelData.data
- radius: 20*1000
- border.width: 3
- /* 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
- }
- }
-
- DelegateChoice {
- roleValue: "LineString"
- delegate: MapPolylineObject {
- property string geojsonType: "LineString"
- property var props: modelData.properties
- geoShape: modelData.data
- line.width: 4
- line.color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
- }
- }
-
- DelegateChoice {
- roleValue: "Polygon"
- delegate: MapPolygonObject {
- property string geojsonType: "Polygon"
- property var props: modelData.properties
- geoShape: modelData.data
- color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
- border.width: 4
- border.color: 'black'
- }
- }
-
- DelegateChoice {
- roleValue: "MultiPoint"
- delegate: MapObjectView {
- property string geojsonType: "MultiPoint"
- property var props: modelData.properties
- model: modelData.data
- delegate: dc
- }
- }
-
- DelegateChoice {
- roleValue: "MultiLineString"
- delegate: MapObjectView {
- property string geojsonType: "MultiLineString"
- property var props: modelData.properties
- model: modelData.data
- delegate: dc
- }
- }
-
- DelegateChoice {
- roleValue: "MultiPolygon"
- delegate: MapObjectView {
- property string geojsonType: "MultiPolygon"
- property var props: modelData.properties
- model: modelData.data
- delegate: dc
- }
- }
-
- DelegateChoice {
- roleValue: "GeometryCollection"
- delegate: MapObjectView {
- property string geojsonType: "GeometryCollection"
- property var props: modelData.properties
- model: modelData.data
- delegate: dc
- }
- }
-
- // Features are explicitly not generated by the parser, but converted straight to their content + the properties.
-
- DelegateChoice {
- roleValue: "FeatureCollection"
- delegate: MapObjectView {
- property string geojsonType: "FeatureCollection"
- property var props: modelData.properties
- model: modelData.data
- delegate: dc
- }
- }
-}
diff --git a/examples/location/geojson_viewer/geojson_viewer.pro b/examples/location/geojson_viewer/geojson_viewer.pro
index 00fbd303..78a877a9 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 += core qml network quick positioning location-private widgets
+QT += core qml network quick positioning location-private
android: QT += core-private
SOURCES += main.cpp
diff --git a/examples/location/geojson_viewer/main.cpp b/examples/location/geojson_viewer/main.cpp
index 08fba1ed..1ca551f2 100644
--- a/examples/location/geojson_viewer/main.cpp
+++ b/examples/location/geojson_viewer/main.cpp
@@ -49,7 +49,7 @@
**
****************************************************************************/
-#include <QApplication>
+#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QDebug>
#include <QFile>
@@ -275,7 +275,7 @@ bool requestStoragePermissions()
int main(int argc, char *argv[])
{
- QApplication app(argc, argv);
+ QGuiApplication app(argc, argv);
#ifdef Q_OS_ANDROID
if (!requestStoragePermissions())
diff --git a/examples/location/geojson_viewer/main.qml b/examples/location/geojson_viewer/main.qml
index ea65d1ac..3c42d9a5 100644
--- a/examples/location/geojson_viewer/main.qml
+++ b/examples/location/geojson_viewer/main.qml
@@ -54,8 +54,7 @@ import QtQuick.Dialogs
import QtQuick.Controls
import QtPositioning
import QtLocation
-import Qt.labs.location
-import Qt.labs.platform as Platform
+import QtCore
import Qt.GeoJson
ApplicationWindow {
@@ -73,6 +72,7 @@ ApplicationWindow {
title: "Choose a GeoJSON file"
fileMode: FileDialog.OpenFile
currentFolder: dataPath
+ nameFilters: ["GeoJSON files (*.geojson *.json)"]
onAccepted: {
geoJsoner.load(fileDialog.selectedFile)
}
@@ -83,7 +83,8 @@ ApplicationWindow {
id: fileWriteDialog
title: "Write your geometry to a file"
fileMode: FileDialog.SaveFile
- currentFolder: Platform.StandardPaths.writableLocation(Platform.StandardPaths.TempLocation)
+ currentFolder: StandardPaths.writableLocation(StandardPaths.TempLocation)
+ nameFilters: ["GeoJSON files (*.geojson *.json)"]
onAccepted: {
geoJsoner.dumpGeoJSON(geoJsoner.toGeoJson(miv), fileWriteDialog.selectedFile);
}
@@ -94,7 +95,8 @@ ApplicationWindow {
id: debugWriteDialog
title: "Write Qvariant debug view"
fileMode: FileDialog.SaveFile
- currentFolder: Platform.StandardPaths.writableLocation(Platform.StandardPaths.TempLocation)
+ currentFolder: StandardPaths.writableLocation(StandardPaths.TempLocation)
+ nameFilters: ["GeoJSON files (*.geojson *.json)"]
onAccepted: {
geoJsoner.writeDebug(geoJsoner.toGeoJson(miv), debugWriteDialog.selectedFile);
}
@@ -144,29 +146,7 @@ ApplicationWindow {
checkable: true
checked: false
}
-
- MenuItem {
- text: "Map Object Delegates"
- id: mapObjectsSelector
- checkable: true
- checked: false
-
- onCheckedChanged: {
- if (checked) {
- miv.model = undefined
- map.removeMapItemView(miv)
- rootMoV.addMapObject(mov)
- mov.model = geoJsoner.model
- } else {
- mov.model = undefined
- rootMoV.removeMapObject(mov)
- map.addMapItemView(miv)
- miv.model = geoJsoner.model
- }
- }
- }
}
-
}
GeoJsoner {
@@ -182,11 +162,6 @@ ApplicationWindow {
}
}
- MapObjectView {
- id: mov
- delegate: GeoJsonDelegateMapObject {}
- }
-
Map {
id: map
anchors.fill: parent
@@ -194,10 +169,6 @@ ApplicationWindow {
plugin: Plugin { name: "osm" }
zoomLevel: 4
- MapObjectView {
- id: rootMoV
- }
-
MapItemView {
id: miv
model: geoJsoner.model
diff --git a/examples/location/geojson_viewer/qml.qrc b/examples/location/geojson_viewer/qml.qrc
index 794a2093..ea443bb0 100644
--- a/examples/location/geojson_viewer/qml.qrc
+++ b/examples/location/geojson_viewer/qml.qrc
@@ -2,6 +2,5 @@
<qresource prefix="/">
<file>main.qml</file>
<file>GeoJsonDelegate.qml</file>
- <file>GeoJsonDelegateMapObject.qml</file>
</qresource>
</RCC>