vcl/inc/qt5/QtInstanceTreeView.hxx | 2 ++ vcl/qt5/QtInstanceTreeView.cxx | 30 ++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-)
New commits: commit ec395cfd2062f98af77029dee845c12bb2f9153a Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Nov 30 01:59:32 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Nov 30 09:40:56 2024 +0100 tdf#130857 qt weld: Add member for tree view selection model ... and use it in misc places instead of calling QTreeView::selectionModel repeatedly. Change-Id: I9d9ee622bb98bf3267d858ee484128b364d14ad2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177574 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx index b0e5aac93d0f..04cb4ae87337 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -20,6 +20,7 @@ class QtInstanceTreeView : public QObject, public QtInstanceWidget, public virtu QTreeView* m_pTreeView; QStandardItemModel* m_pModel; + QItemSelectionModel* m_pSelectionModel; public: QtInstanceTreeView(QTreeView* pTreeView); diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 738589c6d5a3..451987aaba1c 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -24,11 +24,11 @@ QtInstanceTreeView::QtInstanceTreeView(QTreeView* pTreeView) m_pModel = qobject_cast<QStandardItemModel*>(m_pTreeView->model()); assert(m_pModel && "tree view doesn't have expected item model set"); - connect(m_pTreeView, &QTreeView::activated, this, &QtInstanceTreeView::handleActivated); + m_pSelectionModel = m_pTreeView->selectionModel(); + assert(m_pSelectionModel); - QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); - assert(pSelectionModel); - connect(pSelectionModel, &QItemSelectionModel::currentChanged, this, + connect(m_pTreeView, &QTreeView::activated, this, &QtInstanceTreeView::handleActivated); + connect(m_pSelectionModel, &QItemSelectionModel::currentChanged, this, &QtInstanceTreeView::handleCurrentChanged); } @@ -76,9 +76,7 @@ OUString QtInstanceTreeView::get_selected_text() const OUString sText; GetQtInstance().RunInMainThread([&] { - QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); - assert(pSelectionModel); - const QModelIndexList aSelectedIndexes = pSelectionModel->selectedIndexes(); + const QModelIndexList aSelectedIndexes = m_pSelectionModel->selectedIndexes(); if (aSelectedIndexes.empty()) return; @@ -94,9 +92,7 @@ OUString QtInstanceTreeView::get_selected_id() const OUString sId; GetQtInstance().RunInMainThread([&] { - QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); - assert(pSelectionModel); - const QModelIndexList aSelectedIndexes = pSelectionModel->selectedIndexes(); + const QModelIndexList aSelectedIndexes = m_pSelectionModel->selectedIndexes(); if (aSelectedIndexes.empty()) return; @@ -124,11 +120,8 @@ int QtInstanceTreeView::get_selected_index() const void QtInstanceTreeView::select(int nPos) { SolarMutexGuard g; - GetQtInstance().RunInMainThread([&] { - QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); - assert(pSelectionModel); - pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Select); - }); + GetQtInstance().RunInMainThread( + [&] { m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Select); }); } void QtInstanceTreeView::unselect(int) { assert(false && "Not implemented yet"); } @@ -216,9 +209,7 @@ std::vector<int> QtInstanceTreeView::get_selected_rows() const std::vector<int> aSelectedRows; GetQtInstance().RunInMainThread([&] { - QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); - assert(pSelectionModel); - const QModelIndexList aSelectionIndexes = pSelectionModel->selection().indexes(); + const QModelIndexList aSelectionIndexes = m_pSelectionModel->selection().indexes(); for (const QModelIndex& aIndex : aSelectionIndexes) aSelectedRows.push_back(aIndex.row()); }); commit 7003cb1d74aafd40fc4d3ac5ec81063b6926199a Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Nov 30 01:51:28 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Nov 30 09:40:48 2024 +0100 tdf#130857 qt weld: Notify about current tree view item change When the current (focus) item in the tree view changes, call weld::TreeView::signal_changed to notify about this. While QTreeView doesn't have a signal for that itself, its QItemSelectionModel does, so connect to that one. With this in place, SvPasteObjectDialog::SelectHdl now gets called when switching between items in the "Past Special" dialog when using the qt6 VCL plugin with native Qt widgets, as is the case with the gtk3 VCL plugin. Change-Id: I5aab68055f711480d56b043252d15621f18c4919 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177573 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx index 0b9608724005..b0e5aac93d0f 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -188,6 +188,7 @@ private: private Q_SLOTS: void handleActivated(); + void handleCurrentChanged(); }; /* 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 aaf230163879..738589c6d5a3 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -25,6 +25,11 @@ QtInstanceTreeView::QtInstanceTreeView(QTreeView* pTreeView) assert(m_pModel && "tree view doesn't have expected item model set"); connect(m_pTreeView, &QTreeView::activated, this, &QtInstanceTreeView::handleActivated); + + QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel(); + assert(pSelectionModel); + connect(pSelectionModel, &QItemSelectionModel::currentChanged, this, + &QtInstanceTreeView::handleCurrentChanged); } void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int pos, const OUString* pStr, @@ -720,4 +725,10 @@ void QtInstanceTreeView::handleActivated() signal_row_activated(); } +void QtInstanceTreeView::handleCurrentChanged() +{ + SolarMutexGuard g; + signal_changed(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */