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 <m.weghorn@posteo.de>
Tested-by: Jenkins
This commit is contained in:
Michael Weghorn 2024-12-05 23:46:35 +01:00
parent 31d0c99c31
commit 42f8227fdd
2 changed files with 4 additions and 4 deletions

View file

@ -189,7 +189,7 @@ private:
private Q_SLOTS: private Q_SLOTS:
void handleActivated(); void handleActivated();
void handleCurrentChanged(); void handleSelectionChanged();
}; };
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View file

@ -28,8 +28,8 @@ QtInstanceTreeView::QtInstanceTreeView(QTreeView* pTreeView)
assert(m_pSelectionModel); assert(m_pSelectionModel);
connect(m_pTreeView, &QTreeView::activated, this, &QtInstanceTreeView::handleActivated); connect(m_pTreeView, &QTreeView::activated, this, &QtInstanceTreeView::handleActivated);
connect(m_pSelectionModel, &QItemSelectionModel::currentChanged, this, connect(m_pSelectionModel, &QItemSelectionModel::selectionChanged, this,
&QtInstanceTreeView::handleCurrentChanged); &QtInstanceTreeView::handleSelectionChanged);
} }
void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int pos, const OUString* pStr, void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int pos, const OUString* pStr,
@ -737,7 +737,7 @@ void QtInstanceTreeView::handleActivated()
signal_row_activated(); signal_row_activated();
} }
void QtInstanceTreeView::handleCurrentChanged() void QtInstanceTreeView::handleSelectionChanged()
{ {
SolarMutexGuard g; SolarMutexGuard g;
signal_changed(); signal_changed();