summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/location/geojson_viewer/GeoJsonDelegate.qml12
-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.cpp23
-rw-r--r--examples/location/geojson_viewer/main.qml54
-rw-r--r--examples/location/geojson_viewer/qml.qrc1
-rw-r--r--examples/location/minimal_map/main.qml6
-rw-r--r--examples/positioning/weatherinfo/appmodel.cpp46
-rw-r--r--examples/positioning/weatherinfo/appmodel.h1
-rw-r--r--examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc14
-rw-r--r--examples/positioning/weatherinfo/weatherinfo.pro1
11 files changed, 258 insertions, 54 deletions
diff --git a/examples/location/geojson_viewer/GeoJsonDelegate.qml b/examples/location/geojson_viewer/GeoJsonDelegate.qml
index ff0fbffa..afbafe95 100644
--- a/examples/location/geojson_viewer/GeoJsonDelegate.qml
+++ b/examples/location/geojson_viewer/GeoJsonDelegate.qml
@@ -51,14 +51,15 @@
import QtQuick 2.12
import QtPositioning 5.12
-import QtLocation 5.12
+import QtLocation 5.15
import Qt.labs.qmlmodels 1.0
DelegateChooser {
id: dc
role: "type"
property color defaultColor: "grey"
- property real defaultOpacity: 0.7
+ property real defaultOpacity: 0.6
+ property bool openGLBackends: false
DelegateChoice {
roleValue: "Point"
@@ -82,8 +83,9 @@ DelegateChooser {
delegate: MapPolyline {
property string geojsonType: "LineString"
property var props: modelData.properties
+ backend: (dc.openGLBackends) ? MapPolyline.OpenGLExtruded : MapPolyline.Software
geoShape: modelData.data
- line.width: 3
+ line.width: 4
opacity: dc.defaultOpacity
line.color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
}
@@ -97,7 +99,9 @@ DelegateChooser {
geoShape: modelData.data
opacity: dc.defaultOpacity
color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
- border.width: 0
+ border.width: 4
+ border.color: 'black'
+ backend: (dc.openGLBackends) ? MapPolygon.OpenGL : MapPolygon.Software
MouseArea {
anchors.fill: parent
onClicked: {
diff --git a/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml b/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
new file mode 100644
index 00000000..d1a144c8
--- /dev/null
+++ b/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** 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 2.12
+import QtPositioning 5.12
+import Qt.labs.location 1.0
+import Qt.labs.qmlmodels 1.0
+
+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 cf261b36..08b28144 100644
--- a/examples/location/geojson_viewer/geojson_viewer.pro
+++ b/examples/location/geojson_viewer/geojson_viewer.pro
@@ -2,6 +2,8 @@ TARGET = qml_location_geojsonviewer
TEMPLATE = app
QT += core qml network quick positioning location-private widgets
+android: QT += androidextras
+
SOURCES += main.cpp
CONFIG += c++11
CONFIG += install_ok
diff --git a/examples/location/geojson_viewer/main.cpp b/examples/location/geojson_viewer/main.cpp
index 996c0925..61f7d233 100644
--- a/examples/location/geojson_viewer/main.cpp
+++ b/examples/location/geojson_viewer/main.cpp
@@ -70,6 +70,9 @@
#include <QJsonArray>
#include <QFileInfo>
#include <QtCore/qobjectdefs.h>
+#ifdef Q_OS_ANDROID
+#include <QtAndroid>
+#endif
class extractor
{
@@ -247,10 +250,30 @@ public:
#include "main.moc"
+#ifdef Q_OS_ANDROID
+// Request permissions because we're using QStandardPaths::writableLocation()
+bool requestStoragePermissions() {
+ using namespace QtAndroid;
+
+ QString permission = QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE");
+ const QHash<QString, PermissionResult> results = requestPermissionsSync(QStringList({permission}));
+ if (!results.contains(permission) || results[permission] == PermissionResult::Denied) {
+ qWarning() << "Couldn't get permission: " << permission;
+ return false;
+ }
+
+ return true;
+}
+#endif
+
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
+#ifdef Q_OS_ANDROID
+ if (!requestStoragePermissions())
+ return -1;
+#endif
QQmlApplicationEngine engine;
QUrl absoluteFilePath = argc > 1 ?
diff --git a/examples/location/geojson_viewer/main.qml b/examples/location/geojson_viewer/main.qml
index 01faef5f..1b55ef8b 100644
--- a/examples/location/geojson_viewer/main.qml
+++ b/examples/location/geojson_viewer/main.qml
@@ -58,14 +58,17 @@ import QtQuick.Window 2.11
import QtPositioning 5.12
import QtLocation 5.12
import Qt.labs.qmlmodels 1.0
+import Qt.labs.location 1.0
import Qt.GeoJson 1.0
C1.ApplicationWindow {
+ id: win
visible: true
width: 1024
height: 1024
menuBar: mainMenu
title: qsTr("GeoJSON Viewer")
+ property bool openGLBackends: glBackendSelector.checked
FileDialog {
visible: false
@@ -141,6 +144,33 @@ C1.ApplicationWindow {
geoJsoner.print(miv)
}
}
+ C1.MenuItem {
+ text: "OpenGL Item backends"
+ id: glBackendSelector
+ checkable: true
+ checked: false
+ }
+
+ C1.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
+ }
+ }
+ }
}
}
@@ -149,17 +179,37 @@ C1.ApplicationWindow {
id: geoJsoner
}
+ Shortcut {
+ sequence: "Ctrl+P"
+ onActivated: {
+
+ console.log("Center : QtPositioning.coordinate(",map.center.latitude,",",map.center.longitude,")")
+ console.log("Zoom : ",map.zoomLevel)
+ }
+ }
+
+ MapObjectView {
+ id: mov
+ delegate: GeoJsonDelegateMapObject {}
+ }
+
Map {
id: map
anchors.fill: parent
center: QtPositioning.coordinate(43.59, 13.50) // Starting coordinates: Ancona, the city where I am studying :)
- plugin: Plugin { name: "mapboxgl" }
+ plugin: Plugin { name: "osm" }
zoomLevel: 4
+ MapObjectView {
+ id: rootMoV
+ }
+
MapItemView {
id: miv
model: geoJsoner.model
- delegate: GeoJsonDelegate {}
+ delegate: GeoJsonDelegate {
+ openGLBackends: win.openGLBackends
+ }
}
}
}
diff --git a/examples/location/geojson_viewer/qml.qrc b/examples/location/geojson_viewer/qml.qrc
index ea443bb0..794a2093 100644
--- a/examples/location/geojson_viewer/qml.qrc
+++ b/examples/location/geojson_viewer/qml.qrc
@@ -2,5 +2,6 @@
<qresource prefix="/">
<file>main.qml</file>
<file>GeoJsonDelegate.qml</file>
+ <file>GeoJsonDelegateMapObject.qml</file>
</qresource>
</RCC>
diff --git a/examples/location/minimal_map/main.qml b/examples/location/minimal_map/main.qml
index 40e1bb46..285eb31e 100644
--- a/examples/location/minimal_map/main.qml
+++ b/examples/location/minimal_map/main.qml
@@ -49,13 +49,13 @@
****************************************************************************/
import QtQuick 2.0
-import QtQuick.Window 2.0
+import QtQuick.Window 2.14
import QtLocation 5.6
import QtPositioning 5.6
Window {
- width: 512
- height: 512
+ width: Qt.platform.os == "android" ? Screen.width : 512
+ height: Qt.platform.os == "android" ? Screen.height : 512
visible: true
Plugin {
diff --git a/examples/positioning/weatherinfo/appmodel.cpp b/examples/positioning/weatherinfo/appmodel.cpp
index 93186aea..6d31d5ba 100644
--- a/examples/positioning/weatherinfo/appmodel.cpp
+++ b/examples/positioning/weatherinfo/appmodel.cpp
@@ -55,7 +55,6 @@
#include <qnmeapositioninfosource.h>
#include <qgeopositioninfo.h>
#include <qnetworkconfigmanager.h>
-#include <qnetworksession.h>
#include <QJsonDocument>
#include <QJsonObject>
@@ -150,7 +149,6 @@ public:
QString longitude, latitude;
QString city;
QNetworkAccessManager *nam;
- QNetworkSession *ns;
WeatherData now;
QList<WeatherData*> forecast;
QQmlListProperty<WeatherData> *fcProp;
@@ -166,7 +164,6 @@ public:
AppModelPrivate() :
src(NULL),
nam(NULL),
- ns(NULL),
fcProp(NULL),
ready(false),
useGps(true),
@@ -225,31 +222,7 @@ AppModel::AppModel(QObject *parent) :
//! [1]
- // make sure we have an active network session
d->nam = new QNetworkAccessManager(this);
-
- QNetworkConfigurationManager ncm;
- d->ns = new QNetworkSession(ncm.defaultConfiguration(), this);
- connect(d->ns, SIGNAL(opened()), this, SLOT(networkSessionOpened()));
- // the session may be already open. if it is, run the slot directly
- if (d->ns->isOpen())
- this->networkSessionOpened();
- // tell the system we want network
- d->ns->open();
-}
-//! [1]
-
-AppModel::~AppModel()
-{
- d->ns->close();
- if (d->src)
- d->src->stopUpdates();
- delete d;
-}
-
-//! [2]
-void AppModel::networkSessionOpened()
-{
d->src = QGeoPositionInfoSource::createDefaultSource(this);
if (d->src) {
@@ -266,9 +239,16 @@ void AppModel::networkSessionOpened()
this->refreshWeather();
}
}
-//! [2]
+//! [1]
+
+AppModel::~AppModel()
+{
+ if (d->src)
+ d->src->stopUpdates();
+ delete d;
+}
-//! [3]
+//! [2]
void AppModel::positionUpdated(QGeoPositionInfo gpsPos)
{
d->coord = gpsPos.coordinate();
@@ -278,7 +258,7 @@ void AppModel::positionUpdated(QGeoPositionInfo gpsPos)
queryCity();
}
-//! [3]
+//! [2]
void AppModel::queryCity()
{
@@ -347,7 +327,7 @@ void AppModel::handleGeoNetworkData(QNetworkReply *networkReply)
return;
}
- if (!networkReply->networkError()) {
+ if (!networkReply->error()) {
d->nErrors = 0;
if (!d->throttle.isValid())
d->throttle.start();
@@ -403,7 +383,7 @@ void AppModel::handleWeatherNetworkData(QNetworkReply *networkReply)
if (!networkReply)
return;
- if (!networkReply->networkError()) {
+ if (!networkReply->error()) {
foreach (WeatherData *inf, d->forecast)
delete inf;
d->forecast.clear();
@@ -455,7 +435,7 @@ void AppModel::handleForecastNetworkData(QNetworkReply *networkReply)
if (!networkReply)
return;
- if (!networkReply->networkError()) {
+ if (!networkReply->error()) {
QJsonDocument document = QJsonDocument::fromJson(networkReply->readAll());
QJsonObject jo;
diff --git a/examples/positioning/weatherinfo/appmodel.h b/examples/positioning/weatherinfo/appmodel.h
index a4d4e87a..f6657a59 100644
--- a/examples/positioning/weatherinfo/appmodel.h
+++ b/examples/positioning/weatherinfo/appmodel.h
@@ -156,7 +156,6 @@ public slots:
//! [2]
private slots:
void queryCity();
- void networkSessionOpened();
void positionUpdated(QGeoPositionInfo gpsPos);
void positionError(QGeoPositionInfoSource::Error e);
void handleGeoNetworkData(QNetworkReply *networkReply);
diff --git a/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc b/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc
index 089ae9d3..33a95f70 100644
--- a/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc
+++ b/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc
@@ -55,19 +55,13 @@
\snippet weatherinfo/appmodel.h 0
\snippet weatherinfo/appmodel.h 1
- AppModel models the state of the entire application. At startup, the
- application first begins by waiting for network connectivity. We do
- this using the QNetworkConfigurationManager and QNetworkSession family
- of C++ APIs.
+ AppModel models the state of the entire application. At startup, we
+ get the platform's default position source using
+ QGeoPositionInfo::createDefaultSource()
\snippet weatherinfo/appmodel.cpp 0
\snippet weatherinfo/appmodel.cpp 1
- Once the network session is open, we proceed to get the platform's
- default position source using QGeoPositionInfo::createDefaultSource()
-
- \snippet weatherinfo/appmodel.cpp 2
-
If no default source is available, we take a static position and fetch
weather for that. If, however, we do have a position source, we connect
its positionUpdated() signal to a slot on the AppModel and call
@@ -77,7 +71,7 @@
of the returned coordinate to retrieve the current "city" name for use
in the weather lookup.
- \snippet weatherinfo/appmodel.cpp 3
+ \snippet weatherinfo/appmodel.cpp 2
To inform the UI about this process, the cityChanged() signal is emitted
when a new city is used, and the weatherChanged() signal whenever a
diff --git a/examples/positioning/weatherinfo/weatherinfo.pro b/examples/positioning/weatherinfo/weatherinfo.pro
index d8f9675a..e2b2102d 100644
--- a/examples/positioning/weatherinfo/weatherinfo.pro
+++ b/examples/positioning/weatherinfo/weatherinfo.pro
@@ -2,7 +2,6 @@ TEMPLATE = app
TARGET = weatherinfo
QT += core network positioning qml quick
-requires(qtConfig(bearermanagement))
SOURCES += main.cpp \
appmodel.cpp