Merge lp:~martin-borho/ubuntu-weather-app/fix-1383042-location-names into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Martin Borho
Status: Merged
Approved by: Martin Borho
Approved revision: 388
Merged at revision: 387
Proposed branch: lp:~martin-borho/ubuntu-weather-app/fix-1383042-location-names
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 261 lines (+55/-41)
4 files modified
components/AddLocationPage.qml (+0/-1)
components/LocationTab.qml (+1/-1)
po/com.ubuntu.weather.pot (+14/-14)
ubuntu-weather-app.qml (+40/-25)
To merge this branch: bzr merge lp:~martin-borho/ubuntu-weather-app/fix-1383042-location-names
Reviewer Review Type Date Requested Status
Alan Pope 🍺🐧🐱 πŸ¦„ (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+241125@code.launchpad.net

Commit message

Replaced present solution for dynamic tab handling with a repeater based solution.

Description of the change

Replaced present solution for dynamic tab handling with a repeater based solution.

To post a comment you must log in.
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
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Looks good to me, tested on device.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components/AddLocationPage.qml'
2--- components/AddLocationPage.qml 2014-09-20 10:55:31 +0000
3+++ components/AddLocationPage.qml 2014-11-07 18:27:26 +0000
4@@ -57,7 +57,6 @@
5 Cities.preList.forEach(function(loc) {
6 citiesModel.append(loc)
7 })
8- console.log(addCallback)
9 }
10
11 function searchResponseHandler(messageObject) {
12
13=== modified file 'components/LocationTab.qml'
14--- components/LocationTab.qml 2014-09-20 10:55:31 +0000
15+++ components/LocationTab.qml 2014-11-07 18:27:26 +0000
16@@ -68,7 +68,7 @@
17 }
18 }
19
20- Component.onCompleted: {
21+ function ready() {
22 var locData = mainView.locationsList[locationIndex],
23 units = (mainView.settings.units === 'imperial') ? 'imperial' : 'metric',
24 wind_units = (mainView.settings.wind_units === 'mph') ? 'imperial' : 'metric',
25
26=== modified file 'po/com.ubuntu.weather.pot'
27--- po/com.ubuntu.weather.pot 2014-09-25 09:16:21 +0000
28+++ po/com.ubuntu.weather.pot 2014-11-07 18:27:26 +0000
29@@ -8,7 +8,7 @@
30 msgstr ""
31 "Project-Id-Version: ubuntu-weather-app\n"
32 "Report-Msgid-Bugs-To: \n"
33-"POT-Creation-Date: 2014-09-25 10:14+0100\n"
34+"POT-Creation-Date: 2014-11-07 19:15+0100\n"
35 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
36 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
37 "Language-Team: LANGUAGE <LL@li.org>\n"
38@@ -18,16 +18,16 @@
39 "Content-Transfer-Encoding: 8bit\n"
40
41 #: ../components/AddLocationPage.qml:31
42-#: ../components/LocationManagerPage.qml:372
43+#: ../components/LocationManagerPage.qml:350
44 msgid "Add city"
45 msgstr ""
46
47-#: ../components/AddLocationPage.qml:87
48+#: ../components/AddLocationPage.qml:86
49 #, qt-format
50 msgid "No location was found for %1"
51 msgstr ""
52
53-#: ../components/AddLocationPage.qml:159
54+#: ../components/AddLocationPage.qml:158
55 msgid "Enter a city name"
56 msgstr ""
57
58@@ -118,37 +118,37 @@
59 msgid "Edit locations"
60 msgstr ""
61
62-#: ../components/LocationManagerPage.qml:140
63+#: ../components/LocationManagerPage.qml:126
64 msgid "Location already added."
65 msgstr ""
66
67-#: ../components/LocationManagerPage.qml:142
68+#: ../components/LocationManagerPage.qml:128
69 msgid "OK"
70 msgstr ""
71
72-#: ../components/LocationManagerPage.qml:177
73+#: ../components/LocationManagerPage.qml:159
74 msgid "Current location"
75 msgstr ""
76
77-#: ../components/LocationManagerPage.qml:202
78+#: ../components/LocationManagerPage.qml:184
79 msgid "Scan for location"
80 msgstr ""
81
82 #. TRANSLATORS: this is the button to add a location (city) that has been
83 #. detected to be the current position
84-#: ../components/LocationManagerPage.qml:269
85+#: ../components/LocationManagerPage.qml:251
86 msgid "Add"
87 msgstr ""
88
89-#: ../components/LocationManagerPage.qml:289 ../components/LocationTab.qml:147
90+#: ../components/LocationManagerPage.qml:271 ../components/LocationTab.qml:147
91 msgid "Locations"
92 msgstr ""
93
94-#: ../components/LocationManagerPage.qml:384
95+#: ../components/LocationManagerPage.qml:362
96 msgid "Remove a city first."
97 msgstr ""
98
99-#: ../components/LocationManagerPage.qml:407
100+#: ../components/LocationManagerPage.qml:385
101 msgid "Couldn't specify your current location, please try later again!"
102 msgstr ""
103
104@@ -218,11 +218,11 @@
105 msgid "Couldn't load weather data, please try later again!"
106 msgstr ""
107
108-#: ../components/TabFooter.qml:98
109+#: ../components/TabFooter.qml:105
110 msgid "10 days forecast"
111 msgstr ""
112
113-#: ../components/TabFooter.qml:120
114+#: ../components/TabFooter.qml:127
115 msgid "Hourly forecast"
116 msgstr ""
117
118
119=== modified file 'ubuntu-weather-app.qml'
120--- ubuntu-weather-app.qml 2014-09-20 10:55:31 +0000
121+++ ubuntu-weather-app.qml 2014-11-07 18:27:26 +0000
122@@ -48,7 +48,6 @@
123 property bool wideAspect: width >= units.gu(80)
124
125 property var locationsList: []
126- property var tabsObject: null
127 property int tabIndexAtRefresh: -1
128 property bool shortCutsLimited: false
129
130@@ -58,13 +57,13 @@
131 // keyboard shortcuts
132 focus: true
133 Keys.onPressed: {
134- if(!shortCutsLimited && tabsObject && event.modifiers & Qt.ControlModifier) {
135+ if(!shortCutsLimited && tabs.count > 0 && event.modifiers >= 0 && Qt.ControlModifier) {
136 switch(event.key) {
137 case Qt.Key_Tab: // CRTL-TAB
138- tabsObject.selectedTabIndex = (tabsObject.count!==tabsObject.selectedTabIndex+1) ? tabsObject.selectedTabIndex+1 : 0;
139+ tabs.selectedTabIndex = (tabs.count!==tabs.selectedTabIndex+1) ? tabs.selectedTabIndex+1 : 0;
140 break;
141 case Qt.Key_Backtab: // CRTL-ALT-TAB
142- tabsObject.selectedTabIndex = (tabsObject.selectedTabIndex>0) ? tabsObject.selectedTabIndex-1 : tabsObject.count-1;
143+ tabs.selectedTabIndex = (tabs.selectedTabIndex>0) ? tabs.selectedTabIndex-1 : tabs.count-1;
144 break;
145 case Qt.Key_N:// CRTL-N
146 mainView.showLocationManager();
147@@ -77,22 +76,22 @@
148 event.accepted = false;
149 }
150 Keys.onSpacePressed: {
151- if(!shortCutsLimited && tabsObject)
152- tabsObject.tabChildren[tabsObject.selectedTabIndex].toggle();
153+ if(!shortCutsLimited && tabs)
154+ tabs.tabChildren[tabs.selectedTabIndex].toggle();
155 event.accepted = false;
156 }
157 Keys.onUpPressed: {
158- if(!shortCutsLimited && tabsObject)
159- tabsObject.tabChildren[tabsObject.selectedTabIndex].toDayBefore();
160+ if(!shortCutsLimited && tabs)
161+ tabs.tabChildren[tabs.selectedTabIndex].toDayBefore();
162 event.accepted = false;
163 }
164 Keys.onDownPressed: {
165- if(!shortCutsLimited && tabsObject)
166- tabsObject.tabChildren[tabsObject.selectedTabIndex].toNextDay();
167+ if(!shortCutsLimited && tabs)
168+ tabs.tabChildren[tabs.selectedTabIndex].toNextDay();
169 event.accepted = false;
170 }
171 Keys.onEscapePressed: {
172- if(tabsObject) escapeKey();
173+ if(tabs) escapeKey();
174 event.accepted = false;
175 }
176
177@@ -160,7 +159,7 @@
178 }
179 }
180
181- // see https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1124071, temporary workaround
182+ // see https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1124071, temporary workaround
183 function buildTabs(locations) {
184 // check if there was a location added
185 var locLength = locations.length,
186@@ -175,28 +174,31 @@
187 if(locLength === 0) {
188 showLocationManager()
189 return;
190- }
191- locationsList = locations;
192- if(tabsObject !== null) {
193- tabsObject.destroy()
194 }
195- var tabsString = "import QtQuick 2.3; import Ubuntu.Components 1.1; import Ubuntu.Components.Popups 1.0; import \"components\" as Components; "
196- + "Tabs {id: tabs; objectName: 'rootTabs'; anchors.fill: parent;"
197+ locationsList = locations;
198+ // reset the tab reapeater to get a full rebuild
199+ tabRepeater.model = 0;
200+ // add/re-add the tabs to the repeater
201+ tabRepeater.model = locLength;
202 if(locLength > 0) {
203 for(var x=0;x<locLength;x++) {
204- tabsString += "Components.LocationTab {title: '"+locations[x].location.name+"'; locationIndex: "+x+"} "
205- };
206+ var tab = tabRepeater.itemAt(x);
207+ tab.title = locations[x].location.name;
208+ tab.locationIndex = x;
209+ tab.ready();
210+ }
211 }
212- tabsString += "}"; // END Tabs componen
213- tabsObject = Qt.createQmlObject(tabsString, pageStack, "tabs")
214 if(focusToLast) {
215- tabsObject.selectedTabIndex = locLength -1;
216- } else if(tabIndexAtRefresh > -1) {
217- tabsObject.selectedTabIndex = tabIndexAtRefresh
218+ tabs.selectedTabIndex = locLength -1;
219+ } else if(tabIndexAtRefresh > -1 && tabIndexAtRefresh < tabRepeater.count) {
220+ tabs.selectedTabIndex = tabIndexAtRefresh
221 tabIndexAtRefresh = -1
222+ } else {
223+ tabs.selectedTabIndex = 0;
224 }
225 }
226
227+
228 function refreshData(from_storage, force_refresh) {
229 refresh.visible = true;
230 if(from_storage === true && force_refresh !== true) {
231@@ -220,10 +222,12 @@
232 }
233
234 function showLocationManager() {
235+ tabIndexAtRefresh = tabs.selectedTabIndex
236 pageStack.push(Qt.resolvedUrl("components/LocationManagerPage.qml"))
237 }
238
239 function showSettings() {
240+ tabIndexAtRefresh = tabs.selectedTabIndex
241 pageStack.push(Qt.resolvedUrl("components/SettingsPage.qml"))
242 }
243
244@@ -259,6 +263,17 @@
245 PageStack {
246 id:pageStack
247 anchors.fill: parent
248+ Component.onCompleted: push(tabs)
249+ Tabs {
250+ id: tabs;
251+ objectName: 'rootTabs';
252+
253+ Repeater {
254+ id: tabRepeater
255+ model: 0
256+ Components.LocationTab {}
257+ }
258+ }
259 }
260
261 }

Subscribers

People subscribed via source and target branches