Commit b6393382 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Notifications KCM] Fixup current item syncing logic

Instead of relying on currentIndex and some massively complicated logic to track when the index didn't change
but the item behind that index, just use currentItem.
The updateCurrentIndex being called during model changes massively confused ListView leading to inconsistent view state.

BUG: 410842
FIXED-IN: 5.17.5

Differential Revision: https://phabricator.kde.org/D26425
parent d2d30a96
......@@ -59,17 +59,6 @@ Kirigami.Page {
value: searchField.text
}
// We need to manually keep track of the index as we store the sourceModel index
// and then use a proxy model to filter it. We don't get any QML change signals anywhere
// and ListView needs a currentIndex number
Connections {
target: kcm.filteredModel
onRowsRemoved: sourcesList.updateCurrentIndex()
onRowsInserted: sourcesList.updateCurrentIndex()
// TODO re-create model index if possible
onModelReset: appConfiguration.rootIndex = undefined
}
RowLayout {
id: rootRow
anchors.fill: parent
......@@ -120,26 +109,9 @@ Kirigami.Page {
}
}
// We need to manually keep track of the index when we filter
function updateCurrentIndex() {
if (!appConfiguration.rootIndex || !appConfiguration.rootIndex.valid) {
currentIndex = -1;
return;
}
var filteredIdx = kcm.filteredModel.mapFromSource(appConfiguration.rootIndex);
if (!filteredIdx.valid) {
currentIndex = -1;
return;
}
currentIndex = filteredIdx.row;
}
onCurrentIndexChanged: {
onCurrentItemChanged: {
var sourceIdx = kcm.filteredModel.mapToSource(kcm.filteredModel.index(sourcesList.currentIndex, 0));
appConfiguration.rootIndex = kcm.sourcesModel.makePersistentModelIndex(sourceIdx);
sourcesList.updateCurrentIndex();
}
delegate: QtControls.ItemDelegate {
......@@ -150,7 +122,6 @@ Kirigami.Page {
onClicked: {
sourcesList.forceActiveFocus();
sourcesList.currentIndex = index;
sourcesList.updateCurrentIndex();
}
contentItem: RowLayout {
......@@ -196,7 +167,6 @@ Kirigami.Page {
ApplicationConfiguration {
id: appConfiguration
anchors.fill: parent
onRootIndexChanged: sourcesList.updateCurrentIndex()
visible: typeof appConfiguration.rootIndex !== "undefined" && appConfiguration.rootIndex.valid
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment