From 634e226c6b0b0fea7c620395a4e84c4701179a86 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Fri, 6 Dec 2024 09:59:32 +0100 Subject: [PATCH] tdf#130857 qt weld: Implement getting/setting cursor This is independent of the selection. (For selection, there is weld::TreeView::select and weld::TreeView::get_selected_index instead.) Change-Id: I3698a080cebaf4411740b0e7a95c54743e84d881 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178024 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- vcl/qt5/QtInstanceTreeView.cxx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 2644ac9fdce1..e2d28af9932c 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -248,11 +248,27 @@ bool QtInstanceTreeView::is_selected(int) const int QtInstanceTreeView::get_cursor_index() const { - assert(false && "Not implemented yet"); - return -1; + SolarMutexGuard g; + + int nIndex = -1; + GetQtInstance().RunInMainThread([&] { + const QModelIndex aCurrentIndex = m_pSelectionModel->currentIndex(); + if (aCurrentIndex.isValid()) + nIndex = aCurrentIndex.row(); + + }); + + return nIndex; } -void QtInstanceTreeView::set_cursor(int) { assert(false && "Not implemented yet"); } +void QtInstanceTreeView::set_cursor(int nPos) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + m_pSelectionModel->setCurrentIndex(m_pModel->index(nPos, 0), QItemSelectionModel::NoUpdate); + }); +} int QtInstanceTreeView::find_text(const OUString& rText) const {