From 42f8227fdd3a0bb92a5eb50fd580e76d7d35fcb0 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Thu, 5 Dec 2024 23:46:35 +0100 Subject: [PATCH] tdf#130857 qt weld: Return selected item when requested in callback The current item and the selected item(s) are not necessarily the same. Looking into the gtk and VCL implementations, weld::TreeView::signal_changed is called when the selection (not the current item) changes, so connect to the QItemSelectionModel::selectionChanged signal instead of the QItemSelectionModel::currentChanged one in the Qt implementation. At the point in time that the QItemSelectionModel::selectionChanged signal gets emitted, QItemSelectionModel::selectedIndexes returns the newly selected indices while that was not yet the case with QItemSelectionModel::currentChanged. For the "Device" tab in the "File" -> "Printer Settings" -> "Properties" dialog (for which support will be added in an upcoming commit), this resulted in the PPD values (in the tree view on the right) not being shown for the actually selected PPD option/key (in the left tree view), but for the one selected previously. (See RTSDevicePage::SelectHdl for the logic filling the tree view with items, which gets triggered when weld::TreeView::signal_changed gets called.) Change-Id: I31ec5aaaa47cd3d4704f25086b24645fb708be0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177922 Reviewed-by: Michael Weghorn Tested-by: Jenkins --- vcl/inc/qt5/QtInstanceTreeView.hxx | 2 +- vcl/qt5/QtInstanceTreeView.cxx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx index dd252c3e2b47..15fab0ff0792 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -189,7 +189,7 @@ private: private Q_SLOTS: void handleActivated(); - void handleCurrentChanged(); + void handleSelectionChanged(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 70bfd40e0ea6..e72826ce8734 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -28,8 +28,8 @@ QtInstanceTreeView::QtInstanceTreeView(QTreeView* pTreeView) assert(m_pSelectionModel); connect(m_pTreeView, &QTreeView::activated, this, &QtInstanceTreeView::handleActivated); - connect(m_pSelectionModel, &QItemSelectionModel::currentChanged, this, - &QtInstanceTreeView::handleCurrentChanged); + connect(m_pSelectionModel, &QItemSelectionModel::selectionChanged, this, + &QtInstanceTreeView::handleSelectionChanged); } void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int pos, const OUString* pStr, @@ -737,7 +737,7 @@ void QtInstanceTreeView::handleActivated() signal_row_activated(); } -void QtInstanceTreeView::handleCurrentChanged() +void QtInstanceTreeView::handleSelectionChanged() { SolarMutexGuard g; signal_changed();