summaryrefslogtreecommitdiff
path: root/examples/positioning/weatherinfo/weatherinfo.qml
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-08-17 16:34:59 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-24 10:54:27 +0000
commit7b4e87f3431516159998749add5d898629955591 (patch)
treeb1916a4644ee0ebe64d4f59bcd97a9c9386bec12 /examples/positioning/weatherinfo/weatherinfo.qml
parentc21a2d2062db154a2039dbccdbd6ada447cda103 (diff)
downloadqtlocation-7b4e87f3431516159998749add5d898629955591.tar.gz
Introduce WeatherApi backend
This patch introduces the weather backend from weatherapi.com and provides the means to switch between backends at runtime. This will be done automatically in case one of the backends does not respond. As we currently use different backends, we had to update the QML part that is responsible for showing the icons. We no longer use the icons from web-site for the forecast, but use the same icon set as for the current weather. This required introducing methods to convert backend-specific weather icon information to a common format used in the application. While on it, a new type of weather icon was introduced (taken from the same icon set). Different weather backends provide weather forecast for different amount of days (due to license restrictions), so the QML code now makes use of the Repeater that dynamically changes the amount of shown days. Task-number: QTBUG-60467 Change-Id: Ic9aa3a97ec440dddb38f06edfff8a8434724d118 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 6458b9b60a016bbe0ad6574a1965c49dcd9383f3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/positioning/weatherinfo/weatherinfo.qml')
-rw-r--r--examples/positioning/weatherinfo/weatherinfo.qml104
1 files changed, 36 insertions, 68 deletions
diff --git a/examples/positioning/weatherinfo/weatherinfo.qml b/examples/positioning/weatherinfo/weatherinfo.qml
index 730ae754..62bbe7d7 100644
--- a/examples/positioning/weatherinfo/weatherinfo.qml
+++ b/examples/positioning/weatherinfo/weatherinfo.qml
@@ -75,9 +75,9 @@ Item {
]
//! [1]
AppModel {
- id: model
+ id: appModel
onReadyChanged: {
- if (model.ready)
+ if (appModel.ready)
window.state = "ready"
else
window.state = "loading"
@@ -113,7 +113,7 @@ Item {
color: "lightgrey"
Text {
- text: (model.hasValidCity ? model.city : "Unknown location") + (model.useGps ? " (GPS)" : "")
+ text: (appModel.hasValidCity ? appModel.city : "Unknown location") + (appModel.useGps ? " (GPS)" : "")
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
@@ -122,22 +122,22 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: {
- if (model.useGps) {
- model.useGps = false
- model.city = "Brisbane"
+ if (appModel.useGps) {
+ appModel.useGps = false
+ appModel.city = "Brisbane"
} else {
- switch (model.city) {
+ switch (appModel.city) {
case "Brisbane":
- model.city = "Oslo"
+ appModel.city = "Oslo"
break
case "Oslo":
- model.city = "Helsinki"
+ appModel.city = "Helsinki"
break
case "Helsinki":
- model.city = "New York"
+ appModel.city = "New York"
break
case "New York":
- model.useGps = true
+ appModel.useGps = true
break
}
}
@@ -152,21 +152,21 @@ Item {
width: main.width -12
height: 2 * (main.height - 25 - 12) / 3
- weatherIcon: (model.hasValidWeather
- ? model.weather.weatherIcon
- : "01d")
+ weatherIcon: (appModel.hasValidWeather
+ ? appModel.weather.weatherIcon
+ : "sunny")
//! [3]
- topText: (model.hasValidWeather
- ? model.weather.temperature
+ topText: (appModel.hasValidWeather
+ ? appModel.weather.temperature
: "??")
- bottomText: (model.hasValidWeather
- ? model.weather.weatherDescription
+ bottomText: (appModel.hasValidWeather
+ ? appModel.weather.weatherDescription
: "No weather data")
MouseArea {
anchors.fill: parent
onClicked: {
- model.refreshWeather()
+ appModel.refreshWeather()
}
}
//! [4]
@@ -180,58 +180,26 @@ Item {
width: main.width - 12
height: (main.height - 25 - 24) / 3
- property real iconWidth: iconRow.width / 4 - 10
+ property int daysCount: appModel.forecast.length
+ property real iconWidth: (daysCount > 0) ? (iconRow.width / daysCount) - 10
+ : iconRow.width
property real iconHeight: iconRow.height
- ForecastIcon {
- id: forecast1
- width: iconRow.iconWidth
- height: iconRow.iconHeight
-
- topText: (model.hasValidWeather ?
- model.forecast[0].dayOfWeek : "??")
- bottomText: (model.hasValidWeather ?
- model.forecast[0].temperature : "??/??")
- weatherIcon: (model.hasValidWeather ?
- model.forecast[0].weatherIcon : "01d")
- }
- ForecastIcon {
- id: forecast2
- width: iconRow.iconWidth
- height: iconRow.iconHeight
-
- topText: (model.hasValidWeather ?
- model.forecast[1].dayOfWeek : "??")
- bottomText: (model.hasValidWeather ?
- model.forecast[1].temperature : "??/??")
- weatherIcon: (model.hasValidWeather ?
- model.forecast[1].weatherIcon : "01d")
- }
- ForecastIcon {
- id: forecast3
- width: iconRow.iconWidth
- height: iconRow.iconHeight
-
- topText: (model.hasValidWeather ?
- model.forecast[2].dayOfWeek : "??")
- bottomText: (model.hasValidWeather ?
- model.forecast[2].temperature : "??/??")
- weatherIcon: (model.hasValidWeather ?
- model.forecast[2].weatherIcon : "01d")
- }
- ForecastIcon {
- id: forecast4
- width: iconRow.iconWidth
- height: iconRow.iconHeight
-
- topText: (model.hasValidWeather ?
- model.forecast[3].dayOfWeek : "??")
- bottomText: (model.hasValidWeather ?
- model.forecast[3].temperature : "??/??")
- weatherIcon: (model.hasValidWeather ?
- model.forecast[3].weatherIcon : "01d")
+ Repeater {
+ model: appModel.forecast
+ ForecastIcon {
+ id: forecast1
+ width: iconRow.iconWidth
+ height: iconRow.iconHeight
+
+ topText: (appModel.hasValidWeather ?
+ modelData.dayOfWeek : "??")
+ bottomText: (appModel.hasValidWeather ?
+ modelData.temperature : "??/??")
+ weatherIcon: (appModel.hasValidWeather ?
+ modelData.weatherIcon : "sunny")
+ }
}
-
}
}
}