vcl/inc/qt5/QtInstanceTreeView.hxx | 5 +++++ vcl/qt5/QtInstanceTreeView.cxx | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
New commits: commit 371c20f3dcc6fe9262765cab6b570f1736b3d8e1 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Tue May 27 09:41:33 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue May 27 11:56:59 2025 +0200 tdf#130857 qt weld: Notify about tree view toggle change Call weld::TreeView::signal_toggled when the toggle button inside of a QtInstanceTreeView column gets toggled. To do that, connect to the QSortFilterProxyModel::dataChanged signal and handle the case where the Qt::CheckStateRole has changed. For now, only signals for a single changed item are implemented and others trigger an assert. Support for multiple changed items at once should however be relatively straightforward to implement if the need arises, by iterating over all model indices between `rTopLeft` and `rBottomRight`. The new helper QtInstanceTreeView::externalColumnIndex gives the column index as used in the weld::TreeView API, i.e. logically does the opposite of QtInstanceTreeView::modelIndex to hand the special column index of -1 used for the extra toggle button column. With this commit in place, the toolbars in the "View" -> "User Interface" dialog's new "Toolbars" tab page introduced in commit 4ab26f4ea0c627844531144a6a903c357a604a5e Date: Mon May 26 12:03:40 2025 +0200 Resolves tdf#158880 - Let users select multiple toolbars at once become visible/invisible as expected when toggling their status by clicking on the checkbox when using the qt6 VCL plugin with SAL_VCL_QT_USE_WELDED_WIDGETS=1. Change-Id: Iff2fb77bfb226bd2234bb176fd00a8b9b6be7b86 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185885 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 c0684bafdb87..7bc55cb8be6b 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -201,6 +201,9 @@ public: using QtInstanceWidget::get_sensitive; private: + // Returns column index as used in the weld::TreeView API + int externalColumnIndex(const QModelIndex& rIndex); + QModelIndex modelIndex(int nRow, int nCol = 0, const QModelIndex& rParentIndex = QModelIndex()) const; QModelIndex modelIndex(const weld::TreeIter& rIter, int nCol = 0) const; @@ -215,6 +218,8 @@ private: private Q_SLOTS: void handleActivated(); + void handleDataChanged(const QModelIndex& rTopLeft, const QModelIndex& rBottomRight, + const QVector<int>& rRoles); void handleSelectionChanged(); }; diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 22398ec57e7f..2977c3cdb169 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -35,6 +35,8 @@ QtInstanceTreeView::QtInstanceTreeView(QTreeView* pTreeView) connect(m_pTreeView, &QTreeView::activated, this, &QtInstanceTreeView::handleActivated); connect(m_pSelectionModel, &QItemSelectionModel::selectionChanged, this, &QtInstanceTreeView::handleSelectionChanged); + connect(m_pModel, &QSortFilterProxyModel::dataChanged, this, + &QtInstanceTreeView::handleDataChanged); } void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int nPos, const OUString* pStr, @@ -1007,6 +1009,14 @@ QAbstractItemView::SelectionMode QtInstanceTreeView::mapSelectionMode(SelectionM } } +int QtInstanceTreeView::externalColumnIndex(const QModelIndex& rIndex) +{ + if (m_bExtraToggleButtonColumnEnabled) + return rIndex.column() - 1; + + return rIndex.column(); +} + QModelIndex QtInstanceTreeView::modelIndex(int nRow, int nCol, const QModelIndex& rParentIndex) const { @@ -1094,6 +1104,22 @@ void QtInstanceTreeView::handleActivated() signal_row_activated(); } +void QtInstanceTreeView::handleDataChanged(const QModelIndex& rTopLeft, + const QModelIndex& rBottomRight, + const QVector<int>& rRoles) +{ + SolarMutexGuard g; + + // only notify about check state changes + if (!rRoles.contains(Qt::CheckStateRole)) + return; + + assert(rTopLeft == rBottomRight && "Case of multiple changes not implemented yet"); + (void)rBottomRight; + + signal_toggled(iter_col(QtInstanceTreeIter(rTopLeft), externalColumnIndex(rTopLeft))); +} + void QtInstanceTreeView::handleSelectionChanged() { SolarMutexGuard g;