Changeset View
Changeset View
Standalone View
Standalone View
applets/weather/package/contents/ui/config/WeatherStationPicker.qml
Show All 11 Lines | |||||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | import QtQuick 2.9 | 18 | import QtQuick 2.9 | ||
19 | 19 | | |||
20 | import QtQuick.Controls 1.4 as QQC1 | | |||
21 | import QtQuick.Controls 2.5 as QQC2 | 20 | import QtQuick.Controls 2.5 as QQC2 | ||
22 | import QtQuick.Layouts 1.3 | 21 | import QtQuick.Layouts 1.3 | ||
23 | 22 | | |||
24 | import org.kde.plasma.private.weather 1.0 | 23 | import org.kde.plasma.private.weather 1.0 | ||
25 | 24 | | |||
26 | 25 | | |||
27 | ColumnLayout { | 26 | ColumnLayout { | ||
28 | id: root | 27 | id: root | ||
29 | 28 | | |||
30 | property alias selectedServices: serviceListModel.selectedServices | 29 | property alias selectedServices: serviceListModel.selectedServices | ||
31 | property string source | 30 | property string source | ||
32 | readonly property bool canSearch: !!searchStringEdit.text && selectedServices.length | 31 | readonly property bool canSearch: !!searchStringEdit.text && selectedServices.length | ||
33 | readonly property bool handlesEnterKey: canSearch && searchStringEdit.activeFocus | 32 | readonly property bool handlesEnterKey: canSearch && searchStringEdit.activeFocus | ||
34 | 33 | | |||
35 | function searchLocation() { | 34 | function searchLocation() { | ||
36 | if (!canSearch) { | 35 | if (!canSearch) { | ||
37 | return; | 36 | return; | ||
38 | } | 37 | } | ||
39 | | ||||
40 | // avoid automatic selection once model is refilled | | |||
41 | locationListView.currentRow = -1; | | |||
42 | locationListView.selection.clear(); | | |||
43 | noSearchResultReport.visible = false; | | |||
44 | source = ""; | 38 | source = ""; | ||
45 | locationListView.forceActiveFocus(); | | |||
46 | | ||||
47 | locationListModel.searchLocations(searchStringEdit.text, selectedServices); | 39 | locationListModel.searchLocations(searchStringEdit.text, selectedServices); | ||
broulik: You no longer hide the `noSearchResultsReport` label when a new query starts, awkwardly… | |||||
48 | } | 40 | } | ||
49 | 41 | | |||
50 | function handleLocationSearchDone(success, searchString) { | 42 | LocationListModel { | ||
Given the item is hidden anyway, you can probably assign this as a binding right away broulik: Given the item is hidden anyway, you can probably assign this as a binding right away | |||||
43 | id: locationListModel | ||||
44 | onLocationSearchDone: { | ||||
51 | if (!success) { | 45 | if (!success) { | ||
52 | noSearchResultReport.text = i18nc("@info", "No weather stations found for '%1'", searchString); | | |||
53 | noSearchResultReport.visible = true; | 46 | noSearchResultReport.visible = true; | ||
47 | } else { | ||||
48 | // If we got any results, pre-select the top item to potentially | ||||
49 | // save the user a step | ||||
50 | locationListView.currentIndex = 0; | ||||
51 | locationListView.forceActiveFocus(); | ||||
52 | noSearchResultReport.visible = false; | ||||
54 | } | 53 | } | ||
55 | } | 54 | } | ||
56 | | ||||
57 | LocationListModel { | | |||
58 | id: locationListModel | | |||
59 | onLocationSearchDone: handleLocationSearchDone(success, searchString); | | |||
60 | } | 55 | } | ||
61 | 56 | | |||
62 | ServiceListModel { | 57 | ServiceListModel { | ||
63 | id: serviceListModel | 58 | id: serviceListModel | ||
64 | } | 59 | } | ||
65 | 60 | | |||
66 | QQC2.Menu { | 61 | QQC2.Menu { | ||
67 | id: serviceSelectionMenu | 62 | id: serviceSelectionMenu | ||
Show All 20 Lines | |||||
88 | RowLayout { | 83 | RowLayout { | ||
89 | Layout.fillWidth: true | 84 | Layout.fillWidth: true | ||
90 | 85 | | |||
91 | QQC2.TextField { | 86 | QQC2.TextField { | ||
92 | id: searchStringEdit | 87 | id: searchStringEdit | ||
93 | 88 | | |||
94 | Layout.fillWidth: true | 89 | Layout.fillWidth: true | ||
95 | Layout.minimumWidth: implicitWidth | 90 | Layout.minimumWidth: implicitWidth | ||
91 | focus: true | ||||
Maybe explicitly focus this it when the dialog opens again otherwise on subsequent opening of the dialog it will instead have whatever item was focused previously? broulik: Maybe explicitly focus this it when the dialog opens again otherwise on subsequent opening of… | |||||
96 | placeholderText: i18nc("@info:placeholder", "Enter location") | 92 | placeholderText: i18nc("@info:placeholder", "Enter location") | ||
97 | onAccepted: { | 93 | onAccepted: { | ||
98 | searchLocation(); | 94 | searchLocation(); | ||
99 | } | 95 | } | ||
100 | } | 96 | } | ||
101 | 97 | | |||
102 | QQC2.Button { | 98 | QQC2.Button { | ||
103 | id: serviceSelectionButton | 99 | id: serviceSelectionButton | ||
Show All 18 Lines | 113 | QQC2.Button { | |||
122 | enabled: canSearch | 118 | enabled: canSearch | ||
123 | 119 | | |||
124 | onClicked: { | 120 | onClicked: { | ||
125 | searchLocation(); | 121 | searchLocation(); | ||
126 | } | 122 | } | ||
127 | } | 123 | } | ||
128 | } | 124 | } | ||
129 | 125 | | |||
130 | QQC1.TableView { | 126 | QQC2.ScrollView { | ||
131 | id: locationListView | | |||
132 | | ||||
133 | function tableItemActivated() { | | |||
134 | if (locationListView.row !== -1 && locationListView.rowCount) { | | |||
135 | source = locationListModel.valueForListIndex(locationListView.row); | | |||
136 | } | | |||
137 | } | | |||
138 | | ||||
139 | Layout.minimumWidth: implicitWidth | | |||
140 | Layout.minimumHeight: implicitHeight | | |||
141 | Layout.fillWidth: true | 127 | Layout.fillWidth: true | ||
142 | Layout.fillHeight: true | 128 | Layout.fillHeight: true | ||
143 | 129 | | |||
144 | headerVisible: false | 130 | Component.onCompleted: { | ||
145 | model: locationListModel | 131 | background.visible = true; | ||
132 | } | ||||
Does focus: true on the TextField instead of the ListView make this redundant? broulik: Does `focus: true` on the `TextField` instead of the `ListView` make this redundant? | |||||
146 | 133 | | |||
147 | onActivated: tableItemActivated(); | 134 | ListView { | ||
148 | onClicked: { | 135 | id: locationListView | ||
149 | locationListView.forceActiveFocus; | 136 | model: locationListModel | ||
150 | tableItemActivated(); | 137 | clip: true | ||
138 | focus: true | ||||
139 | activeFocusOnTab: true | ||||
140 | keyNavigationEnabled: true | ||||
141 | keyNavigationWraps: true | ||||
broulik: This is unlike any other list we have in settings? | |||||
ngraham: I copied it from the notifications KCM :) | |||||
broulik: The notifications KCM doesn't wrap, though? | |||||
142 | | ||||
143 | onCurrentItemChanged: { | ||||
144 | source = locationListModel.valueForListIndex(locationListView.currentIndex); | ||||
151 | } | 145 | } | ||
152 | 146 | | |||
153 | QQC1.TableViewColumn { | 147 | delegate: QQC2.ItemDelegate { | ||
154 | id: locationListViewStationColumn | 148 | id: sourceDelegate | ||
broulik: Unused `id` | |||||
149 | width: locationListView.width | ||||
150 | text: model.display | ||||
151 | highlighted: ListView.isCurrentItem | ||||
155 | 152 | | |||
156 | movable: false | 153 | onClicked: { | ||
157 | resizable: false | 154 | locationListView.forceActiveFocus(); | ||
158 | role: "display" | 155 | locationListView.currentIndex = index; | ||
156 | } | ||||
159 | } | 157 | } | ||
160 | 158 | | |||
161 | QQC2.Label { | 159 | QQC2.Label { | ||
162 | id: noSearchResultReport | 160 | id: noSearchResultReport | ||
163 | 161 | | |||
164 | anchors.fill: parent | 162 | anchors.fill: parent | ||
165 | horizontalAlignment: Text.AlignHCenter | 163 | horizontalAlignment: Text.AlignHCenter | ||
166 | verticalAlignment: Text.AlignVCenter | 164 | verticalAlignment: Text.AlignVCenter | ||
165 | text: i18nc("@info", "No weather stations found for '%1'", searchStringEdit.text); | ||||
This should be set programatically when the query finishes like before instead of a binding. Otherwise you'll end up in the weird situation where it says "Nothing found for foo" and then you start typing a new query and it live updates to "Nothing found for bar" even though you didn't actually launch a new query broulik: This should be set programatically when the query finishes like before instead of a binding. | |||||
167 | wrapMode: Text.WordWrap | 166 | wrapMode: Text.WordWrap | ||
You're constantly breaking this binding by assigning to it elsewhere programmatically. broulik: You're constantly breaking this binding by assigning to it elsewhere programmatically. | |||||
168 | visible: false | 167 | visible: false | ||
168 | enabled: false | ||||
169 | } | 169 | } | ||
170 | 170 | | |||
171 | QQC2.BusyIndicator { | 171 | QQC2.BusyIndicator { | ||
172 | id: busy | 172 | id: busy | ||
173 | 173 | | |||
174 | anchors.centerIn: parent | 174 | anchors.centerIn: parent | ||
175 | 175 | | |||
176 | visible: locationListModel.validatingInput | 176 | visible: locationListModel.validatingInput | ||
177 | } | 177 | } | ||
178 | } | 178 | } | ||
179 | | ||||
180 | Component.onCompleted: { | | |||
181 | searchStringEdit.forceActiveFocus(); | | |||
182 | } | 179 | } | ||
183 | } | 180 | } |
You no longer hide the noSearchResultsReport label when a new query starts, awkwardly overlapping the busy indicator until the new one completes.