diff options
author | MohammadHossein Qanbari <mohammad.qanbari@qt.io> | 2024-02-01 14:21:53 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-02-13 12:29:21 +0000 |
commit | 085b74d7477e870f69d94d9f19e8bfcdd6a59be2 (patch) | |
tree | 118f07989a0c2cc2912a55640a5314d752f60f5a | |
parent | e8b358ebd84f0989d99698c49cb92b8ec218809d (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
Change-Id: Ia6cf7a11e6ce9b45c66f841ea027ed78fc2beda7
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit a642f3bdedc186b8b0e81b66f06b7fa867de4815)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/location/mapviewer/Main.qml | 44 |
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(); + } + } } |