summaryrefslogtreecommitdiffstats
path: root/map-widget/qml
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-11-27 17:13:57 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-11-27 22:59:22 +0100
commit837ed67d867991fd82773205970813426a806852 (patch)
tree47deb413f1c0b9c3057d6a27ac5ace6f511e26fa /map-widget/qml
parent1d80b08a8fb1fe06fd5cf60eac43b9ae1dc1197c (diff)
downloadsubsurface-837ed67d867991fd82773205970813426a806852.tar.gz
mapwidget.qml: return early instead of doing branching
The centerOn*() functions can just return early for invalid input, instead of branching the conditions. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'map-widget/qml')
-rw-r--r--map-widget/qml/MapWidget.qml112
1 files changed, 56 insertions, 56 deletions
diff --git a/map-widget/qml/MapWidget.qml b/map-widget/qml/MapWidget.qml
index 12b4554eb..af9b47135 100644
--- a/map-widget/qml/MapWidget.qml
+++ b/map-widget/qml/MapWidget.qml
@@ -151,73 +151,73 @@ Item {
stopZoomAnimations()
if (!coordIsValid(coord)) {
console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()")
- } else {
- var newZoomOutFound = false
- var zoomStored = zoomLevel
- var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
- newZoomOut = zoomLevel
- newCenter = coord
- zoomLevel = Math.floor(zoomLevel)
- while (zoomLevel > minimumZoomLevel) {
- var pt = fromCoordinate(coord)
- if (pointIsVisible(pt)) {
- newZoomOut = zoomLevel
- newZoomOutFound = true
- break
- }
- zoomLevel -= 1.0
+ return
+ }
+ var newZoomOutFound = false
+ var zoomStored = zoomLevel
+ var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
+ newZoomOut = zoomLevel
+ newCenter = coord
+ zoomLevel = Math.floor(zoomLevel)
+ while (zoomLevel > minimumZoomLevel) {
+ var pt = fromCoordinate(coord)
+ if (pointIsVisible(pt)) {
+ newZoomOut = zoomLevel
+ newZoomOutFound = true
+ break
}
- if (!newZoomOutFound)
- newZoomOut = defaultZoomOut
- zoomLevel = zoomStored
- center = centerStored
- newZoom = zoomStored
- mapAnimationZoomIn.restart()
+ zoomLevel -= 1.0
}
+ if (!newZoomOutFound)
+ newZoomOut = defaultZoomOut
+ zoomLevel = zoomStored
+ center = centerStored
+ newZoom = zoomStored
+ mapAnimationZoomIn.restart()
}
function centerOnRectangle(topLeft, bottomRight, centerRect) {
stopZoomAnimations()
if (newCenter.latitude === 0.0 && newCenter.longitude === 0.0) {
// Do nothing
- } else {
- var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
- var zoomStored = zoomLevel
- var newZoomOutFound = false
- newCenter = centerRect
- // calculate zoom out
- newZoomOut = zoomLevel
- while (zoomLevel > minimumZoomLevel) {
- var ptCenter = fromCoordinate(centerStored)
- var ptCenterRect = fromCoordinate(centerRect)
- if (pointIsVisible(ptCenter) && pointIsVisible(ptCenterRect)) {
- newZoomOut = zoomLevel
- newZoomOutFound = true
- break
- }
- zoomLevel -= 1.0
+ return
+ }
+ var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
+ var zoomStored = zoomLevel
+ var newZoomOutFound = false
+ newCenter = centerRect
+ // calculate zoom out
+ newZoomOut = zoomLevel
+ while (zoomLevel > minimumZoomLevel) {
+ var ptCenter = fromCoordinate(centerStored)
+ var ptCenterRect = fromCoordinate(centerRect)
+ if (pointIsVisible(ptCenter) && pointIsVisible(ptCenterRect)) {
+ newZoomOut = zoomLevel
+ newZoomOutFound = true
+ break
}
- if (!newZoomOutFound)
- newZoomOut = defaultZoomOut
- // calculate zoom in
- center = newCenter
- zoomLevel = Math.floor(maximumZoomLevel)
- var diagonalRect = topLeft.distanceTo(bottomRight)
- while (zoomLevel > minimumZoomLevel) {
- var c0 = toCoordinate(Qt.point(0.0, 0.0))
- var c1 = toCoordinate(Qt.point(width, height))
- if (c0.distanceTo(c1) > diagonalRect) {
- newZoom = zoomLevel - 2.0
- break
- }
- zoomLevel -= 1.0
+ zoomLevel -= 1.0
+ }
+ if (!newZoomOutFound)
+ newZoomOut = defaultZoomOut
+ // calculate zoom in
+ center = newCenter
+ zoomLevel = Math.floor(maximumZoomLevel)
+ var diagonalRect = topLeft.distanceTo(bottomRight)
+ while (zoomLevel > minimumZoomLevel) {
+ var c0 = toCoordinate(Qt.point(0.0, 0.0))
+ var c1 = toCoordinate(Qt.point(width, height))
+ if (c0.distanceTo(c1) > diagonalRect) {
+ newZoom = zoomLevel - 2.0
+ break
}
- if (newZoom > defaultZoomIn)
- newZoom = defaultZoomIn
- zoomLevel = zoomStored
- center = centerStored
- mapAnimationZoomIn.restart()
+ zoomLevel -= 1.0
}
+ if (newZoom > defaultZoomIn)
+ newZoom = defaultZoomIn
+ zoomLevel = zoomStored
+ center = centerStored
+ mapAnimationZoomIn.restart()
}
function deselectMapLocation() {