1/**************************************************************************** 2** 3** Copyright (C) 2019 Julian Sherollari <jdotsh@gmail.com> 4** Copyright (C) 2019 The Qt Company Ltd. 5** Contact: https://www.qt.io/licensing/ 6** 7** This file is part of the examples of the Qt Toolkit. 8** 9** $QT_BEGIN_LICENSE:BSD$ 10** Commercial License Usage 11** Licensees holding valid commercial Qt licenses may use this file in 12** accordance with the commercial license agreement provided with the 13** Software or, alternatively, in accordance with the terms contained in 14** a written agreement between you and The Qt Company. For licensing terms 15** and conditions see https://www.qt.io/terms-conditions. For further 16** information use the contact form at https://www.qt.io/contact-us. 17** 18** BSD License Usage 19** Alternatively, you may use this file under the terms of the BSD license 20** as follows: 21** 22** "Redistribution and use in source and binary forms, with or without 23** modification, are permitted provided that the following conditions are 24** met: 25** * Redistributions of source code must retain the above copyright 26** notice, this list of conditions and the following disclaimer. 27** * Redistributions in binary form must reproduce the above copyright 28** notice, this list of conditions and the following disclaimer in 29** the documentation and/or other materials provided with the 30** distribution. 31** * Neither the name of The Qt Company Ltd nor the names of its 32** contributors may be used to endorse or promote products derived 33** from this software without specific prior written permission. 34** 35** 36** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 47** 48** $QT_END_LICENSE$ 49** 50****************************************************************************/ 51 52import QtQuick 2.11 53import QtQuick.Controls 1.4 as C1 54import QtQuick.Controls.Styles 1.4 55import Qt.labs.platform 1.1 56import QtQuick.Layouts 1.11 57import QtQuick.Window 2.11 58import QtPositioning 5.12 59import QtLocation 5.12 60import Qt.labs.qmlmodels 1.0 61import Qt.labs.location 1.0 62import Qt.GeoJson 1.0 63 64C1.ApplicationWindow { 65 id: win 66 visible: true 67 width: 1024 68 height: 1024 69 menuBar: mainMenu 70 title: qsTr("GeoJSON Viewer") 71 property bool openGLBackends: glBackendSelector.checked 72 73 FileDialog { 74 visible: false 75 id: fileDialog 76 title: "Choose a GeoJSON file" 77 fileMode: FileDialog.OpenFile 78 folder: dataPath 79 onAccepted: { 80 geoJsoner.load(fileDialog.file) 81 } 82 } 83 84 FileDialog { 85 visible: false 86 id: fileWriteDialog 87 title: "Write your geometry to a file" 88 fileMode: FileDialog.SaveFile 89 folder: StandardPaths.writableLocation(StandardPaths.TempLocation) 90 onAccepted: { 91 geoJsoner.dumpGeoJSON(geoJsoner.toGeoJson(miv), fileWriteDialog.file); 92 } 93 } 94 95 FileDialog { 96 visible: false 97 id: debugWriteDialog 98 title: "Write Qvariant debug view" 99 fileMode: FileDialog.SaveFile 100 folder: StandardPaths.writableLocation(StandardPaths.TempLocation) 101 onAccepted: { 102 geoJsoner.writeDebug(geoJsoner.toGeoJson(miv), debugWriteDialog.file); 103 } 104 } 105 106 C1.MenuBar { 107 id: mainMenu 108 109 C1.Menu { 110 title: "&File" 111 id : geoJsonMenu 112 C1.MenuItem { 113 text: "&Open" 114 shortcut: StandardKey.Open 115 onTriggered: { 116 fileDialog.open() 117 } 118 } 119 C1.MenuItem { 120 text: "&Export" 121 shortcut: StandardKey.Save 122 onTriggered: { 123 fileWriteDialog.open() 124 } 125 } 126 C1.MenuItem { 127 text: "E&xit" 128 shortcut: StandardKey.Quit 129 onTriggered: Qt.quit() 130 } 131 } 132 C1.Menu { 133 title: "&Debug" 134 id : debugMenu 135 C1.MenuItem { 136 text: "Print debug data to &file" 137 onTriggered: { 138 debugWriteDialog.open() 139 } 140 } 141 C1.MenuItem { 142 text: "&Print debug data" 143 onTriggered: { 144 geoJsoner.print(miv) 145 } 146 } 147 C1.MenuItem { 148 text: "OpenGL Item backends" 149 id: glBackendSelector 150 checkable: true 151 checked: false 152 } 153 154 C1.MenuItem { 155 text: "Map Object Delegates" 156 id: mapObjectsSelector 157 checkable: true 158 checked: false 159 160 onCheckedChanged: { 161 if (checked) { 162 miv.model = undefined 163 map.removeMapItemView(miv) 164 rootMoV.addMapObject(mov) 165 mov.model = geoJsoner.model 166 } else { 167 mov.model = undefined 168 rootMoV.removeMapObject(mov) 169 map.addMapItemView(miv) 170 miv.model = geoJsoner.model 171 } 172 } 173 } 174 } 175 176 } 177 178 GeoJsoner { 179 id: geoJsoner 180 } 181 182 Shortcut { 183 sequence: "Ctrl+P" 184 onActivated: { 185 186 console.log("Center : QtPositioning.coordinate(",map.center.latitude,",",map.center.longitude,")") 187 console.log("Zoom : ",map.zoomLevel) 188 } 189 } 190 191 MapObjectView { 192 id: mov 193 delegate: GeoJsonDelegateMapObject {} 194 } 195 196 Map { 197 id: map 198 anchors.fill: parent 199 center: QtPositioning.coordinate(43.59, 13.50) // Starting coordinates: Ancona, the city where I am studying :) 200 plugin: Plugin { name: "osm" } 201 zoomLevel: 4 202 203 MapObjectView { 204 id: rootMoV 205 } 206 207 MapItemView { 208 id: miv 209 model: geoJsoner.model 210 delegate: GeoJsonDelegate { 211 openGLBackends: win.openGLBackends 212 } 213 } 214 } 215} 216