diff --git a/applets/weather/package/contents/ui/config/WeatherStationPicker.qml b/applets/weather/package/contents/ui/config/WeatherStationPicker.qml --- a/applets/weather/package/contents/ui/config/WeatherStationPicker.qml +++ b/applets/weather/package/contents/ui/config/WeatherStationPicker.qml @@ -17,7 +17,6 @@ import QtQuick 2.9 -import QtQuick.Controls 1.4 as QQC1 import QtQuick.Controls 2.5 as QQC2 import QtQuick.Layouts 1.3 @@ -36,21 +35,20 @@ if (!canSearch) { return; } - - // avoid automatic selection once model is refilled - locationListView.currentRow = -1; - locationListView.selection.clear(); - noSearchResultReport.visible = false; source = ""; - locationListView.forceActiveFocus(); - locationListModel.searchLocations(searchStringEdit.text, selectedServices); } function handleLocationSearchDone(success, searchString) { if (!success) { noSearchResultReport.text = i18nc("@info", "No weather stations found for '%1'", searchString); noSearchResultReport.visible = true; + } else { + // If we got any results, pre-select the top item to potentially + // save the user a step + locationListView.currentIndex = 0; + locationListView.forceActiveFocus(); + noSearchResultReport.visible = false; } } @@ -127,57 +125,58 @@ } } - QQC1.TableView { - id: locationListView - - function tableItemActivated() { - if (locationListView.row !== -1 && locationListView.rowCount) { - source = locationListModel.valueForListIndex(locationListView.row); - } - } - - Layout.minimumWidth: implicitWidth - Layout.minimumHeight: implicitHeight + QQC2.ScrollView { Layout.fillWidth: true Layout.fillHeight: true - headerVisible: false - model: locationListModel - - onActivated: tableItemActivated(); - onClicked: { - locationListView.forceActiveFocus; - tableItemActivated(); + Component.onCompleted: { + background.visible = true; + searchStringEdit.forceActiveFocus(); } - QQC1.TableViewColumn { - id: locationListViewStationColumn + ListView { + id: locationListView + model: locationListModel + clip: true + focus: true + activeFocusOnTab: true + keyNavigationEnabled: true + keyNavigationWraps: true + + onCurrentItemChanged: { + source = locationListModel.valueForListIndex(locationListView.currentIndex); + } - movable: false - resizable: false - role: "display" - } + delegate: QQC2.ItemDelegate { + id: sourceDelegate + width: locationListView.width + text: model.display + highlighted: ListView.isCurrentItem - QQC2.Label { - id: noSearchResultReport + onClicked: { + locationListView.forceActiveFocus(); + locationListView.currentIndex = index; + } + } - anchors.fill: parent - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - wrapMode: Text.WordWrap - visible: false - } + QQC2.Label { + id: noSearchResultReport - QQC2.BusyIndicator { - id: busy + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + visible: locationListView.count === 0 && searchStringEdit.length > 0 + enabled: false + } - anchors.centerIn: parent + QQC2.BusyIndicator { + id: busy - visible: locationListModel.validatingInput - } - } + anchors.centerIn: parent - Component.onCompleted: { - searchStringEdit.forceActiveFocus(); + visible: locationListModel.validatingInput + } + } } }