From 2bb13bf7f7fe8993d2417cf650625cd7ca9409fa Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 1 May 2020 00:30:26 -0400 Subject: [PATCH] HStringFilterModel: Refilter when field changes --- src/gui/Base/HStringFilterModel.qml | 5 +++++ src/gui/ModelStore.qml | 3 +++ src/gui/PythonBridge/Privates/EventHandlers.qml | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/gui/Base/HStringFilterModel.qml b/src/gui/Base/HStringFilterModel.qml index 9e977865..5413e823 100644 --- a/src/gui/Base/HStringFilterModel.qml +++ b/src/gui/Base/HStringFilterModel.qml @@ -12,4 +12,9 @@ HFilterModel { property string field: "id" property string filter: "" property ListModel sourceModel + + readonly property Connections sourceModelConnections: Connections { + target: sourceModel // model is non-notifiable + onFieldsChanged: if (field in changes) refilterAt(index) + } } diff --git a/src/gui/ModelStore.qml b/src/gui/ModelStore.qml index dd351e85..0b4a6154 100644 --- a/src/gui/ModelStore.qml +++ b/src/gui/ModelStore.qml @@ -12,6 +12,9 @@ QtObject { readonly property Component model: Component { ListModel { + // Used by HFilterModel + signal fieldsChanged(int index, var changes) + property var modelId function findIndex(id, default_=null) { diff --git a/src/gui/PythonBridge/Privates/EventHandlers.qml b/src/gui/PythonBridge/Privates/EventHandlers.qml index 1843a195..6c5b3aa8 100644 --- a/src/gui/PythonBridge/Privates/EventHandlers.qml +++ b/src/gui/PythonBridge/Privates/EventHandlers.qml @@ -60,7 +60,10 @@ QtObject { // JSON.stringify(changedFields)) const model = ModelStore.get(syncId) model.set(indexThen, changedFields) + if (indexThen !== indexNow) model.move(indexThen, indexNow, 1) + + model.fieldsChanged(indexNow, changedFields) } }