diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-16 17:28:47 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-20 12:10:38 +0200 |
commit | ab4b06741ee2dbb70e43ae1660d6ccca4913a32c (patch) | |
tree | bdefee840852c86b1f93fa0fa2846fcdc26785bb /examples/location/mapviewer/map | |
parent | 31c94ac5a7d905312e4459d44c24cbe5f105dc9d (diff) | |
download | qtlocation-ab4b06741ee2dbb70e43ae1660d6ccca4913a32c.tar.gz |
Fix mapviewer example issues and modernize code
Move the example away from imperative coding style, and fix code that
didn't following Qt 6 practices or caused warnings to be emitted to the
console:
Populate all menus consistently through items that bind their enabled
state to relevant properties. This avoids that we have to clear and
recreate the menus when switching provider.
Don't print debug output when updating the position of the minimap.
Capture parameters of signals correctly in the handlers.
Fix some UI issues:
We cannot replace the background of a styled button, so use
AbstractButton instead, otherwise the example will generate runtime
warnings with some styles, e.g.
qrc:/qt-project.org/imports/QtQuick/Controls/macOS/Button.qml:44:
TypeError: Property 'styleFont' of object QQuickRectangle(0x7fdfaa4e7bd0)
is not a function
Also don't squeeze the sliders by setting the spacing to -10, styled
sliders will overlap, and don't use anchors on items managed by layouts.
Change-Id: I118a52ae3d2ece77c662fd42bb868c9bbcf30e7a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'examples/location/mapviewer/map')
-rw-r--r-- | examples/location/mapviewer/map/MapComponent.qml | 18 | ||||
-rw-r--r-- | examples/location/mapviewer/map/MapSliders.qml | 8 | ||||
-rw-r--r-- | examples/location/mapviewer/map/Marker.qml | 6 | ||||
-rw-r--r-- | examples/location/mapviewer/map/MiniMap.qml | 4 |
4 files changed, 14 insertions, 22 deletions
diff --git a/examples/location/mapviewer/map/MapComponent.qml b/examples/location/mapviewer/map/MapComponent.qml index a9ace12f..8553cb8d 100644 --- a/examples/location/mapviewer/map/MapComponent.qml +++ b/examples/location/mapviewer/map/MapComponent.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -311,7 +311,7 @@ Map { mapItems = new Array(); } - Keys.onPressed: { + Keys.onPressed: (event) => { if (event.key === Qt.Key_Plus) { map.zoomLevel++; } else if (event.key === Qt.Key_Minus) { @@ -464,7 +464,7 @@ Map { hoverEnabled: false property variant lastCoordinate - onPressed : { + onPressed : (mouse) => { map.lastX = mouse.x + parent.x map.lastY = mouse.y + parent.y map.pressX = mouse.x + parent.x @@ -472,7 +472,7 @@ Map { lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) } - onPositionChanged: { + onPositionChanged: (mouse) => { if (mouse.button == Qt.LeftButton) { map.lastX = mouse.x + parent.x map.lastY = mouse.y + parent.y @@ -530,7 +530,7 @@ Map { hoverEnabled: false property variant lastCoordinate - onPressed : { + onPressed : (mouse) => { map.lastX = mouse.x + parent.x map.lastY = mouse.y + parent.y map.pressX = mouse.x + parent.x @@ -538,7 +538,7 @@ Map { lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) } - onPositionChanged: { + onPositionChanged: (mouse) => { if (Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || Math.abs(map.pressY - parent.y -mouse.y ) > map.jitterThreshold) { if (pressed) parent.radius = parent.center.distanceTo( @@ -550,7 +550,7 @@ Map { } } - onPressAndHold:{ + onPressAndHold: (mouse) => { if (Math.abs(map.pressX - parent.x- mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - parent.y - mouse.y ) < map.jitterThreshold) { showPointMenu(lastCoordinate); @@ -610,7 +610,7 @@ Map { } } - onDoubleClicked: { + onDoubleClicked: (mouse) => { var mouseGeoPos = map.toCoordinate(Qt.point(mouse.x, mouse.y)); var preZoomPoint = map.fromCoordinate(mouseGeoPos, false); if (mouse.button === Qt.LeftButton) { @@ -629,7 +629,7 @@ Map { lastY = -1; } - onPressAndHold:{ + onPressAndHold: (mouse) => { if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { showMainMenu(lastCoordinate); diff --git a/examples/location/mapviewer/map/MapSliders.qml b/examples/location/mapviewer/map/MapSliders.qml index 49fb5659..1a8c8013 100644 --- a/examples/location/mapviewer/map/MapSliders.qml +++ b/examples/location/mapviewer/map/MapSliders.qml @@ -70,7 +70,7 @@ Row { anchors.right: rightEdge() ? parent.right : undefined anchors.left: rightEdge() ? undefined : parent.left - Button { + AbstractButton { id: sliderToggler width: 32 height: 96 @@ -83,11 +83,6 @@ Row { xScale: rightEdge() ? 1 : -1 } -// style: ButtonStyle { -// background: Rectangle { -// color: "transparent" -// } -// } background: Rectangle { color: "transparent" } @@ -218,7 +213,6 @@ Row { // The sliders row Row { - spacing: -10 id: sliderRow height: sliderContainer.slidersHeight diff --git a/examples/location/mapviewer/map/Marker.qml b/examples/location/mapviewer/map/Marker.qml index 8c5d9284..3566397c 100644 --- a/examples/location/mapviewer/map/Marker.qml +++ b/examples/location/mapviewer/map/Marker.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -79,7 +79,7 @@ MapQuickItem { drag.target: marker preventStealing: true - onPressed : { + onPressed : (mouse) => { map.pressX = mouse.x map.pressY = mouse.y map.currentMarker = -1 @@ -91,7 +91,7 @@ MapQuickItem { } } - onPressAndHold:{ + onPressAndHold: (mouse) => { if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { var p = map.fromCoordinate(marker.coordinate) diff --git a/examples/location/mapviewer/map/MiniMap.qml b/examples/location/mapviewer/map/MiniMap.qml index 43298d85..2fe3093a 100644 --- a/examples/location/mapviewer/map/MiniMap.qml +++ b/examples/location/mapviewer/map/MiniMap.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -119,8 +119,6 @@ Rectangle{ topLeft.longitude= getMapVisibleRegion().topLeft.longitude bottomRight.latitude = getMapVisibleRegion().bottomRight.latitude bottomRight.longitude= getMapVisibleRegion().bottomRight.longitude - console.log("TopLeft: " + topLeft) - console.log("BotRigh: " + bottomRight) } } } |