vcl/qt5/QtInstanceTreeView.cxx |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit 23567fe2db2cefd934f971596c9cdc8835562889
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 26 23:02:43 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Apr 27 07:25:29 2025 +0200

    tdf#130857 qt weld: Make disabling tree view sorting work
    
    Set the QSortFilterProxyModel's sort column to -1 to
    disable sorting. Quoting from the QSortFilterProxyModel::sortColumn
    doc [1]:
    
    > Returns the column currently used for sorting
    >
    > This returns the most recently used sort column. The default value is -1,
    > which means that this proxy model does not sort.
    >
    > See also sort().
    
    It not working triggered a crash in SwGlossaryDlg::Init
    in a WIP branch for supporting the "Tools" -> "AutoText"
    dialog in Writer, because the QModelIndex set in the QtInstanceTreeIter
    returned as out param when inserting the item did not match
    the one in the sorted model when used later, and the `pData`
    in
    
        GroupUserData* pData = 
weld::fromId<GroupUserData*>(m_xCategoryBox->get_id(*xSearch));
        if (!pData->bReadonly)
    
    would be null.
    
    (Whether that needs additional work to make sure that a valid
    iterator is still returned for the case where sorting is enabled
    may still be a valid question to be asked separately, in particular
    if any similar issue shows again in the future.)
    
    [1] https://doc.qt.io/qt-6/qsortfilterproxymodel.html#sortColumn
    
    Change-Id: Ibcb8e4318ecc85494141f75644955d26278dec9a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184678
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index 508c0ee73590..4da7958dde22 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -819,7 +819,10 @@ void QtInstanceTreeView::make_unsorted()
 {
     SolarMutexGuard g;
 
-    GetQtInstance().RunInMainThread([&] { 
m_pTreeView->setSortingEnabled(false); });
+    GetQtInstance().RunInMainThread([&] {
+        m_pTreeView->setSortingEnabled(false);
+        m_pModel->sort(-1);
+    });
 }
 
 bool QtInstanceTreeView::get_sort_order() const

Reply via email to