summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohammadHossein Qanbari <mohammad.qanbari@qt.io>2024-02-01 14:21:53 +0100
committerMohammadHossein Qanbari <mohammad.qanbari@qt.io>2024-02-13 10:08:13 +0100
commita642f3bdedc186b8b0e81b66f06b7fa867de4815 (patch)
tree94ef8ec213038b557b477b29939bd94b64c9e2f4
parentc197c9c544df7bd181bba3ddbfd7924b8de11986 (diff)
MapViewer Example: Support LocationPermission
If the location permission is not granted, a message will be shown to inform the user that this app needs location permission which can be requested by the user or maybe not. If the user triggers "Follow Me" action, then it checks if the permission has already Granted, then toggles the follow-me property. Otherwise, it shows the permission request dialog. Task-number: QTBUG-121412 Pick-to: 6.6 6.7 Change-Id: Ia6cf7a11e6ce9b45c66f841ea027ed78fc2beda7 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--examples/location/mapviewer/Main.qml44
1 files changed, 43 insertions, 1 deletions
diff --git a/examples/location/mapviewer/Main.qml b/examples/location/mapviewer/Main.qml
index 65bfa6d6..95a13105 100644
--- a/examples/location/mapviewer/Main.qml
+++ b/examples/location/mapviewer/Main.qml
@@ -1,6 +1,7 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+import QtCore
import QtQuick
import QtQuick.Controls
import QtLocation
@@ -221,7 +222,10 @@ ApplicationWindow {
stackView.pop(page)
switch (state) {
case "FollowMe":
- mapview.followme = !mapview.followme
+ if (!mapview.followme && (permission.status !== Qt.Granted))
+ permissionDialog.open();
+ else
+ mapview.followme = !mapview.followme
break
case "MiniMap":
toggleMiniMapState()
@@ -457,4 +461,42 @@ support"
}
}
}
+
+ LocationPermission {
+ id: permission
+ accuracy: LocationPermission.Precise
+ availability: LocationPermission.WhenInUse
+ }
+
+ Dialog {
+ id: permissionDialog
+ anchors.centerIn: parent
+ padding: 20
+ standardButtons: (permission.status === Qt.Denied) ? Dialog.Close
+ : Dialog.Close | Dialog.Ok
+ closePolicy: Dialog.NoAutoClose
+ title: qsTr("Permission")
+
+ Label {
+ id: permissionRequestText
+ text: (permission.status === Qt.Denied)
+ ? qsTr("Grant the location permission then open the app again.")
+ : qsTr("Location permission is needed.")
+ }
+
+ onAccepted: {
+ if (permission.status !== Qt.Denied)
+ permission.request();
+ }
+
+ onStandardButtonsChanged: {
+ if (standardButtons & Dialog.Ok)
+ standardButton(Dialog.Ok).text = qsTr("Request Permission");
+ }
+
+ Component.onCompleted: {
+ if (permission.status !== Qt.Granted)
+ open();
+ }
+ }
}