[graphics/koko/release/26.08] src/qml/gallery: GalleryPage: Workaround ItemSelectionModel hasSelection not notifying

Oliver Beard <[email protected]> Tue, 4 Aug 2026 13:30:43 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit e98daca024ba19b22b40d51802dc86214ffc2a88 by Oliver Beard.
Committed on 04/08/2026 at 13:25.
Pushed by olib into branch 'release/26.08'.

GalleryPage: Workaround ItemSelectionModel hasSelection not notifying

`ItemSelectionModel`, when its model resets, loses all selections but does not emit `hasSelectionChanged` despite changing to false.

As such, the page's `selectionMode` property, a binding to this property, is not updated, and selection mode sticks when moving from one location to another.

Work around this by replacing it with a new binding to the value.

M  +9    -0    src/qml/gallery/GalleryPage.qml

https://invent.kde.org/graphics/koko/-/commit/e98daca024ba19b22b40d51802dc86214ffc2a88

diff --git a/src/qml/gallery/GalleryPage.qml b/src/qml/gallery/GalleryPage.qml
index 21c9ee1a..5aafe130 100644
--- a/src/qml/gallery/GalleryPage.qml
+++ b/src/qml/gallery/GalleryPage.qml
@@ -558,6 +558,15 @@ Kirigami.ScrollablePage {
         model: gallerySortFilterProxyModel
     }
 
+    Connections {
+        target: gallerySortFilterProxyModel
+        function onModelReset() {
+            // HACK: ItemSelectionModel does not emit hasSelectionChanged
+            //       after model reset results in no selection
+            page.selectionMode = Qt.binding(() => selectionModel.hasSelection);
+        }
+    }
+
     bottomPadding: inlineStatusBar.effectiveHeight
 
     GridView {