vcl/qt5/QtInstanceTreeView.cxx | 67 ++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 10 deletions(-)
New commits: commit 210088db7c9d07c7600550bd6525d2f3299b9a39 Author: Michael Weghorn <[email protected]> AuthorDate: Sat Nov 30 01:09:10 2024 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Nov 30 09:40:21 2024 +0100 tdf#130857 qt weld: Implement QtInstanceTreeView::get_selected_{id,text} Change-Id: I6a732606c6bf762033744824e857f861077b0237 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177569 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 83b0d77515d3..c829788148c9 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -65,14 +65,40 @@ void QtInstanceTreeView::insert_separator(int, const OUString&) OUString QtInstanceTreeView::get_selected_text() const { - assert(false && "Not implemented yet"); - return OUString(); + SolarMutexGuard g; + + OUString sText; + GetQtInstance().RunInMainThread([&] { + QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); + assert(pSelectionModel); + const QModelIndexList aSelectedIndexes = pSelectionModel->selectedIndexes(); + if (aSelectedIndexes.empty()) + return; + + sText = toOUString(m_pModel->itemFromIndex(aSelectedIndexes.first())->text()); + }); + + return sText; } OUString QtInstanceTreeView::get_selected_id() const { - assert(false && "Not implemented yet"); - return OUString(); + SolarMutexGuard g; + + OUString sId; + GetQtInstance().RunInMainThread([&] { + QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); + assert(pSelectionModel); + const QModelIndexList aSelectedIndexes = pSelectionModel->selectedIndexes(); + if (aSelectedIndexes.empty()) + return; + + QVariant aIdData = aSelectedIndexes.first().data(ROLE_ID); + if (aIdData.canConvert<QString>()) + sId = toOUString(aIdData.toString()); + }); + + return sId; } void QtInstanceTreeView::enable_toggle_buttons(weld::ColumnToggleType) commit 17b49c778dbbb99407891ebbcc17775e89df5bf5 Author: Michael Weghorn <[email protected]> AuthorDate: Sat Nov 30 00:48:16 2024 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Nov 30 09:40:12 2024 +0100 tdf#130857 qt weld: Implement QtInstanceTreeView::find_{id,text} Still untested. Change-Id: I2124852eb00bc515264ae99798e4b05a37c7266b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177568 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 7b008a1f8713..83b0d77515d3 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -214,10 +214,18 @@ int QtInstanceTreeView::get_cursor_index() const void QtInstanceTreeView::set_cursor(int) { assert(false && "Not implemented yet"); } -int QtInstanceTreeView::find_text(const OUString&) const +int QtInstanceTreeView::find_text(const OUString& rText) const { - assert(false && "Not implemented yet"); - return -1; + SolarMutexGuard g; + + int nIndex = -1; + GetQtInstance().RunInMainThread([&] { + const QList<QStandardItem*> aItems = m_pModel->findItems(toQString(rText)); + if (!aItems.empty()) + nIndex = aItems.at(0)->index().row(); + }); + + return nIndex; } OUString QtInstanceTreeView::get_id(int nPos) const @@ -234,10 +242,23 @@ OUString QtInstanceTreeView::get_id(int nPos) const return sId; } -int QtInstanceTreeView::find_id(const OUString&) const +int QtInstanceTreeView::find_id(const OUString& rId) const { - assert(false && "Not implemented yet"); - return -1; + SolarMutexGuard g; + + int nIndex = -1; + GetQtInstance().RunInMainThread([&] { + for (int i = 0; i < m_pModel->rowCount(); i++) + { + if (get_id(i) == rId) + { + nIndex = i; + return; + } + } + }); + + return nIndex; } std::unique_ptr<weld::TreeIter> QtInstanceTreeView::make_iterator(const weld::TreeIter*) const
