Merge lp:~martin-borho/ubuntu-weather-app/WindUnitsSetting into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Martin Borho
Status: Merged
Approved by: Raúl Yeguas
Approved revision: 105
Merged at revision: 104
Proposed branch: lp:~martin-borho/ubuntu-weather-app/WindUnitsSetting
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 304 lines (+122/-20)
6 files modified
components/CurrentWeather.qml (+3/-2)
components/LocationTab.qml (+3/-1)
components/SettingsSheet.qml (+24/-7)
components/WeatherDetailComponent.qml (+4/-3)
tests/autopilot/ubuntu_weather_app/tests/test_settings.py (+87/-6)
ubuntu-weather-app.qml (+1/-1)
To merge this branch: bzr merge lp:~martin-borho/ubuntu-weather-app/WindUnitsSetting
Reviewer Review Type Date Requested Status
Raúl Yeguas Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+183157@code.launchpad.net

Commit message

added option in settings to change the wind speed unit, fixes Bugs #1214934, #1218907 and #1190784

Description of the change

* added option in settings to change the wind speed unit, Bug #1214934
* added test for changing wind speed unit
* fixes Bug #1190784
* added missing icon, Bug #1218907
* fixed smaller Bug, selected units now also used in hourly forecasts

To post a comment you must log in.
105. By Martin Borho

added missing 12.png icon, fixes bug #1218907

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Raúl Yeguas (neokore) wrote :

Great (and fast) work, Martin!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components/CurrentWeather.qml'
2--- components/CurrentWeather.qml 2013-08-28 13:12:19 +0000
3+++ components/CurrentWeather.qml 2013-08-30 13:31:38 +0000
4@@ -20,7 +20,7 @@
5 property int pressure
6 property variant hourly
7 property string tempScale: (mainView.settings["units"] === "imperial") ? "F" : "C"
8- property string speedScale: (mainView.settings["units"] === "imperial") ? "mph" : "km/h"
9+ property string speedScale: (mainView.settings["wind_units"] === "mph") ? "mph" : "km/h"
10 property string precipScale: (mainView.settings["units"] === "imperial") ? "in" : "mm"
11
12 width: parent.width
13@@ -78,7 +78,7 @@
14 if(movement > 1){
15 if(currentWeather.hourly.get(movement) !== undefined) {
16 currentConditionIcon.condition = currentWeather.hourly.get(movement).icon;
17- var temp = currentWeather.hourly.get(movement)["metric"].temp;
18+ var temp = currentWeather.hourly.get(movement)[mainView.settings["units"]].temp;
19 currentConditionTempContent.currentTemp = temp;
20 adjustBackground(Math.round(temp));
21 var dateTime = new Date(currentWeather.hourly.get(movement).date);
22@@ -141,6 +141,7 @@
23 height: units.gu(15)
24
25 Components.WeatherDetailComponent {
26+ objectName: "WindSpeedValue"
27 value: currentWeather.windSpeed
28 measure: i18n.tr("Wind speed")
29 unit: currentWeather.speedScale + " " + currentWeather.windDir
30
31=== modified file 'components/LocationTab.qml'
32--- components/LocationTab.qml 2013-08-28 13:06:39 +0000
33+++ components/LocationTab.qml 2013-08-30 13:31:38 +0000
34@@ -50,6 +50,7 @@
35 Component.onCompleted: {
36 var locData = mainView.locationsList[locationIndex],
37 units = (mainView.settings.units === 'imperial') ? 'imperial' : 'metric',
38+ wind_units = (mainView.settings.wind_units === 'mph') ? 'imperial' : 'metric',
39 dailyForecasts = locData.data,
40 dailyLength = dailyForecasts.length,
41 todayForeCast = dailyForecasts[0];
42@@ -80,6 +81,7 @@
43 }else if(degrees >330 && degrees <= 360){
44 direction = "N";
45 }
46+ print(dailyForecasts[x].icon)
47 dayForecastModel.append({
48 dateRel: "",//Tomorrow",
49 date: formatTimestamp(dailyForecasts[x].timestamp, 'dddd, dd MMMM yyyy'),
50@@ -90,7 +92,7 @@
51 null,
52 cond: dailyForecasts[x].condition.id,
53 condIcon: dailyForecasts[x].icon,
54- wind_speed: dailyForecasts[x][units].windSpeed,
55+ wind_speed: dailyForecasts[x][wind_units].windSpeed,
56 wind_dir: direction,
57 humid: dailyForecasts[x].humidity,
58 precip: (dailyForecasts[x][units].rain !== null && dailyForecasts[x][units].rain !== undefined) ? dailyForecasts[x][units].rain : 0,
59
60=== modified file 'components/SettingsSheet.qml'
61--- components/SettingsSheet.qml 2013-08-05 18:53:33 +0000
62+++ components/SettingsSheet.qml 2013-08-30 13:31:38 +0000
63@@ -28,12 +28,23 @@
64 title: i18n.tr("Settings")
65 contentsHeight: parent.height
66
67- container: ListItem.ValueSelector {
68- id: unitsSelector
69- objectName: "UnitsSelector"
70- text: i18n.tr("Units")
71- values: [i18n.tr("Metric"), i18n.tr("Imperial")]
72- selectedIndex: (settings["units"] === "imperial") ? 1 : 0;
73+ container: Column {
74+ anchors.left: parent.left
75+ anchors.right: parent.right
76+ ListItem.ValueSelector {
77+ id: unitsSelector
78+ objectName: "UnitsSelector"
79+ text: i18n.tr("Temperature units")
80+ values: [i18n.tr("Celsius"), i18n.tr("Fahrenheit")]
81+ selectedIndex: (settings["units"] === "imperial") ? 1 : 0;
82+ }
83+ ListItem.ValueSelector {
84+ id: windUnitsSelector
85+ objectName: "WindUnitsSelector"
86+ text: i18n.tr("Wind speed units")
87+ values: [i18n.tr("Kilometers per hour"), i18n.tr("Miles per hour")]
88+ selectedIndex: (settings["wind_units"] === "mph") ? 1 : 0;
89+ }
90 }
91
92 Component.onCompleted: {
93@@ -42,12 +53,18 @@
94
95 onConfirmClicked: {
96 var refresh = false,
97- selectedUnit = (unitsSelector.selectedIndex === 0) ? "metric" : "imperial";
98+ selectedUnit = (unitsSelector.selectedIndex === 0) ? "metric" : "imperial",
99+ selectedWindUnit = (windUnitsSelector.selectedIndex === 0) ? "kmh" : "mph";
100 // check if temperaure scale was changed
101 if(settings["units"] !== selectedUnit) {
102 storage.saveSetting("units", selectedUnit);
103 refresh = true;
104 }
105+ //
106+ if(settings["wind_units"] !== selectedWindUnit) {
107+ storage.saveSetting("wind_units", selectedWindUnit);
108+ refresh = true;
109+ }
110 // handling of other settings here
111 // ....
112
113
114=== modified file 'components/WeatherDetailComponent.qml'
115--- components/WeatherDetailComponent.qml 2013-08-22 12:07:35 +0000
116+++ components/WeatherDetailComponent.qml 2013-08-30 13:31:38 +0000
117@@ -22,7 +22,7 @@
118 style: Text.Raised
119 font.bold: false
120 font.family: "Ubuntu"
121- font.pointSize: FontUtils.sizeToPixels("x-small") //9
122+ font.pointSize: FontUtils.sizeToPixels("x-small")
123 fontSizeMode: Text.Fit
124 verticalAlignment: Text.AlignVCenter
125 horizontalAlignment: Text.AlignHCenter
126@@ -63,7 +63,7 @@
127
128 Text {
129 id: value
130- objectName: "CurrentTempText"
131+ objectName: "WeatherDetailValue"
132 text: infoComponent.value.toPrecision()
133 color: Theme.palette.normal.baseText
134 style: Text.Raised
135@@ -111,7 +111,8 @@
136
137 Text {
138 id: unit
139- text: infoComponent.unit
140+ objectName: "WeatherDetailUnit"
141+ text: infoComponent.unit
142 color: Theme.palette.normal.baseText
143 style: Text.Raised
144 font.bold: false
145
146=== added file 'resources/images/12.png'
147Binary files resources/images/12.png 1970-01-01 00:00:00 +0000 and resources/images/12.png 2013-08-30 13:31:38 +0000 differ
148=== modified file 'tests/autopilot/ubuntu_weather_app/tests/test_settings.py'
149--- tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-08-29 19:27:52 +0000
150+++ tests/autopilot/ubuntu_weather_app/tests/test_settings.py 2013-08-30 13:31:38 +0000
151@@ -36,6 +36,7 @@
152
153 def _check_units(self, units):
154 """Checks selected units by values from the first location tab"""
155+ self.assertThat(lambda: self.main_window.get_objects('QQuickText', 'CurrentTempText'), Eventually(Not(Is(None))))
156 current_temps = self.main_window.get_objects('QQuickText', 'CurrentTempText')
157 if units == "imperial":
158 self.assertThat(current_temps[0].text, Eventually(Equals(u'72')))
159@@ -44,6 +45,22 @@
160 self.assertThat(current_temps[0].text, Eventually(Equals(u'22')))
161 self.assertThat(current_temps[1].text, Eventually(Equals(u'24')))
162
163+ def _check_wind_units(self, wind_units):
164+ """Checks selected units by values from the first location tab"""
165+ self.assertThat(lambda: self.main_window.get_objects('WeatherDetailComponent', 'WindSpeedValue')[0], Eventually(Not(Is(None))))
166+ wind_component = self.main_window.get_objects('WeatherDetailComponent', 'WindSpeedValue')[0]
167+ self.assertThat(lambda: wind_component.get_object('QQuickText', 'WeatherDetailUnit'), Eventually(Not(Is(None))))
168+ wind_unit = wind_component.get_object('QQuickText', 'WeatherDetailUnit')
169+ self.assertThat(lambda: wind_component.get_object('QQuickText', 'WeatherDetailValue'), Eventually(Not(Is(None))))
170+ wind_value = wind_component.get_object('QQuickText', 'WeatherDetailValue')
171+ if wind_units == "mph":
172+ self.assertThat(wind_unit.text, Eventually(Equals(u'mph NW')))
173+ self.assertThat(wind_value.text, Eventually(Equals(u'3')))
174+ else:
175+ self.assertThat(wind_unit.text, Eventually(Equals(u'km/h NW')))
176+ self.assertThat(wind_value.text, Eventually(Equals(u'4')))
177+
178+
179 def test_switch_scale(self):
180 """Tests switching the scale in the settings"""
181 # first check metric values and open the settings sheet
182@@ -58,8 +75,8 @@
183
184 # choose second option, fahrenheit
185 self._move_pointer_around()
186- self.assertThat(lambda: units_selector.get_children()[2], Eventually(Not(Is(None))))
187- imperial_option = units_selector.get_children()[2]
188+ self.assertThat(lambda: units_selector.select_many('LabelVisual')[3], Eventually(Not(Is(None))))
189+ imperial_option = units_selector.select_many('LabelVisual')[3]
190 self.pointing_device.click_object(imperial_option)
191 self.assertThat(units_selector.selectedIndex, Eventually(Equals(1)))
192 self._click_sheet_confirm()
193@@ -79,8 +96,8 @@
194
195 # click celsius option
196 self._move_pointer_around()
197- self.assertThat(lambda: units_selector.get_children()[3], Eventually(Not(Is(None))))
198- metric_option = units_selector.get_children()[3]
199+ self.assertThat(lambda: units_selector.select_many('LabelVisual')[2], Eventually(Not(Is(None))))
200+ metric_option = units_selector.select_many('LabelVisual')[2]
201 self.pointing_device.click_object(metric_option)
202
203 # confirm
204@@ -96,8 +113,10 @@
205 """Test canceling switching scale"""
206 # first check metric values and open the settings sheet
207 self._check_units('metric')
208+ self._check_wind_units('kmh')
209 self._open_settings_sheet()
210
211+ # open the temp value selector
212 self.assertThat(lambda: self.main_window.get_object('ValueSelector', 'UnitsSelector'), Eventually(Not(Is(None))))
213 units_selector = self.main_window.get_object('ValueSelector', "UnitsSelector")
214 self.assertThat(units_selector.selectedIndex, Eventually(Equals(0)))
215@@ -105,12 +124,74 @@
216
217 # choose second option, fahrenheit
218 self._move_pointer_around()
219- self.assertThat(lambda: units_selector.get_children()[2], Eventually(Not(Is(None))))
220- imperial_option = units_selector.get_children()[2]
221+ self.assertThat(lambda: units_selector.select_many('LabelVisual')[3], Eventually(Not(Is(None))))
222+ imperial_option = units_selector.select_many('LabelVisual')[3]
223 self.pointing_device.click_object(imperial_option)
224 self.assertThat(units_selector.selectedIndex, Eventually(Equals(1)))
225
226+ # open the wind value selector
227+ self.assertThat(lambda: self.main_window.get_object('ValueSelector', 'WindUnitsSelector'), Eventually(Not(Is(None))))
228+ units_selector = self.main_window.get_object('ValueSelector', "WindUnitsSelector")
229+ self.assertThat(units_selector.selectedIndex, Eventually(Equals(0)))
230+ self.pointing_device.click_object(units_selector)
231+
232+ # choose second option, mph
233+ self._move_pointer_around()
234+ self.assertThat(lambda: units_selector.select_many('LabelVisual')[3], Eventually(Not(Is(None))))
235+ mph_option = units_selector.select_many('LabelVisual')[3]
236+ self.pointing_device.click_object(mph_option)
237+ self.assertThat(units_selector.selectedIndex, Eventually(Equals(1)))
238+
239 # cancel and check
240 self._click_sheet_cancel()
241 self._check_units('metric')
242+ self._check_wind_units('kmh')
243+
244+ def test_switch_wind_scale(self):
245+ """Tests switching the wind scale in the settings"""
246+ # first check metric values and open the settings sheet
247+ self._check_wind_units('kmh')
248+ self._open_settings_sheet()
249+
250+ # open the wind value selector
251+ self.assertThat(lambda: self.main_window.get_object('ValueSelector', 'WindUnitsSelector'), Eventually(Not(Is(None))))
252+ units_selector = self.main_window.get_object('ValueSelector', "WindUnitsSelector")
253+ self.assertThat(units_selector.selectedIndex, Eventually(Equals(0)))
254+ self.pointing_device.click_object(units_selector)
255+
256+ # choose second option, mph
257+ self._move_pointer_around()
258+ self.assertThat(lambda: units_selector.select_many('LabelVisual')[3], Eventually(Not(Is(None))))
259+ mph_option = units_selector.select_many('LabelVisual')[3]
260+ self.pointing_device.click_object(mph_option)
261+ self.assertThat(units_selector.selectedIndex, Eventually(Equals(1)))
262+ self._click_sheet_confirm()
263+
264+ # wait for reload and check the mph values
265+ load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')
266+ self.assertThat(load_indicator.running, Eventually(Equals(False)))
267+ self._check_wind_units('mph')
268+
269+ # switch back to kmh values again
270+ self._open_settings_sheet()
271+ self.assertThat(lambda: self.main_window.get_object('ValueSelector', 'WindUnitsSelector'), Eventually(Not(Is(None))))
272+ units_selector = self.main_window.get_object('ValueSelector', "WindUnitsSelector")
273+ self.assertThat(units_selector.selectedIndex, Eventually(Equals(1)))
274+ self.pointing_device.click_object(units_selector)
275+ self.assertThat(units_selector.expanded, Eventually(Equals(True)))
276+
277+ # click celsius option
278+ self._move_pointer_around()
279+ self.assertThat(lambda: units_selector.select_many('LabelVisual')[2], Eventually(Not(Is(None))))
280+ metric_option = units_selector.select_many('LabelVisual')[2]
281+ self.pointing_device.click_object(metric_option)
282+
283+ # confirm
284+ self.assertThat(units_selector.selectedIndex, Eventually(Equals(0)))
285+ self._click_sheet_confirm()
286+
287+ # wait for reload and check the metric values again
288+ load_indicator = self.main_window.get_object('ActivityIndicator', 'LoadingSpinner')
289+ self.assertThat(load_indicator.running, Eventually(Equals(False)))
290+ self._check_units('metric')
291
292
293=== modified file 'ubuntu-weather-app.qml'
294--- ubuntu-weather-app.qml 2013-08-23 19:30:18 +0000
295+++ ubuntu-weather-app.qml 2013-08-30 13:31:38 +0000
296@@ -43,7 +43,7 @@
297 property var locationsList: []
298 property var tabsObject: null
299 // set default values for settings here
300- property var settings: {"units":"metric"}
301+ property var settings: {"units":"metric", "wind_units": "kmh"}
302
303 WorkerScript {
304 id: locationDataWorker

Subscribers

People subscribed via source and target branches