Debian Codegraph @

src/app/qml/ui/settings/WindUnitPage.qml

raw
1 /*
2 * Copyright (C) 2015-2016 Canonical Ltd.
3 *
4 * This file is part of Lomiri Weather App
5 *
6 * Lomiri Weather App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Lomiri Weather App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 import QtQuick 2.12
20 import Lomiri.Components 1.3
21 import "../../components"
22
23 Item {
24 id: unitsPage
25 height: windSetting.height
26
27 ListModel {
28 id: windSpeedModel
29 function initialize() {
30 if (windSpeedModel.count == 0)
31 // TRANSLATORS: meter per second, metric SI unit for wind speed, only use abbreviated
32 windSpeedModel.append({"text": i18n.tr("m/s"), "value": "m/s"})
33
34 // TRANSLATORS: kilometer per hour, metric unit for wind speed, only use abbreviated
35 windSpeedModel.append({"text": i18n.tr("km/h"), "value": "km/h"})
36
37 // TRANSLATORS: miles per hour, imperial unit for wind speed, only use abbreviated
38 windSpeedModel.append({"text": i18n.tr("mph"), "value": "mph"})
39 }
40 }
41
42 OptionSelector {
43 id: windSetting
44 text: i18n.tr("Wind speed unit")
45 model: windSpeedModel
46 containerHeight: itemHeight * model.count
47 delegate: OptionSelectorDelegate {
48 text: model.text
49 height: units.gu(4)
50 }
51 onDelegateClicked: {
52 settings.windUnit = model.get(index).value
53 windSetting.selectedIndex = index
54 refreshData(true);
55 }
56 Component.onCompleted: {
57 /*
58 The Component.onCompleted of the OptionSelector finishes BEFORE
59 the onCompleted events of the delegates or the model.
60 That is why the initialize() needs to be called here rather than
61 in the Component.onCompleted of the ListModel.
62 */
63 windSpeedModel.initialize()
64 for (var i = 0; i < windSpeedModel.count; ++i) {
65 if (windSpeedModel.get(i).value === settings.windUnit) {
66 windSetting.selectedIndex = i
67 return
68 }
69 }
70 windSetting.selectedIndex = 0 // in case no match is found due to broken settings
71 }
72 }
73 }