vcl/inc/qt5/QtInstanceTreeView.hxx | 3 +- vcl/qt5/QtInstanceTreeView.cxx | 39 ++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 16 deletions(-)
New commits: commit 0202d8a9d58d49c6b75d01cd72146c8c84ce7cdf Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Feb 20 22:40:37 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Feb 21 08:43:17 2025 +0100 tdf#130857 qt weld: Use QtInstanceTreeView::modelIndex helper Change-Id: I51ef89d08a5a56141355121dcd6b83bff4f5d99a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181972 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 0789e2855c4a..024a63c3cbba 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -135,15 +135,14 @@ void QtInstanceTreeView::select(int nPos) { SolarMutexGuard g; GetQtInstance().RunInMainThread( - [&] { m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Select); }); + [&] { m_pSelectionModel->select(modelIndex(nPos), QItemSelectionModel::Select); }); } void QtInstanceTreeView::unselect(int nPos) { SolarMutexGuard g; - GetQtInstance().RunInMainThread([&] { - m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Deselect); - }); + GetQtInstance().RunInMainThread( + [&] { m_pSelectionModel->select(modelIndex(nPos), QItemSelectionModel::Deselect); }); } void QtInstanceTreeView::remove(int nPos) @@ -319,7 +318,7 @@ void QtInstanceTreeView::set_cursor(int nPos) SolarMutexGuard g; GetQtInstance().RunInMainThread([&] { - m_pSelectionModel->setCurrentIndex(m_pModel->index(nPos, 0), QItemSelectionModel::NoUpdate); + m_pSelectionModel->setCurrentIndex(modelIndex(nPos), QItemSelectionModel::NoUpdate); }); } commit ce0217d6a812974c04be21315541bb48fe3fce16 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Feb 20 22:34:34 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Feb 21 08:43:10 2025 +0100 tdf#130857 qt weld: Implement more treeview methods using first text col Following Change-Id: Ibba0f99d6be006d7b8d896b0bfc396cfabbec084 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Thu Feb 20 22:24:37 2025 +0100 tdf#130857 qt weld: Add logic to find first treeview text column , implement the remaining weld::TreeView methods whose doc says that a column index of -1 refers to the first text column. Also implement handling of other col indices where that wasn't done yet. Whether the logic introduced commit will turn out to be sufficient in the end remains to be seen. (E.g. whether other text data are always already set at the point in time that QtInstanceTreeView::set_text gets called with a col index of -1, which is a prerequisite for the logic to find the correct column.) Change-Id: I49298245f2773309ceb33fe05971dbc1907c5675 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181971 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 2ae97d3158cc..91d70762a837 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -101,7 +101,7 @@ public: virtual void set_text_align(const weld::TreeIter& rIter, double fAlign, int col) override; virtual void set_toggle(const weld::TreeIter& rIter, TriState bOn, int col = -1) override; virtual TriState get_toggle(const weld::TreeIter& rIter, int col = -1) const override; - virtual OUString get_text(const weld::TreeIter& rIter, int col = -1) const override; + virtual OUString get_text(const weld::TreeIter& rIter, int nCol = -1) const override; virtual void set_id(const weld::TreeIter& rIter, const OUString& rId) override; virtual OUString get_id(const weld::TreeIter& rIter) const override; virtual void set_image(const weld::TreeIter& rIter, const OUString& rImage, diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 0287f2f81a72..0789e2855c4a 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -155,14 +155,12 @@ void QtInstanceTreeView::remove(int nPos) OUString QtInstanceTreeView::get_text(int nRow, int nCol) const { - assert(nCol == -1 && "Column support not implemented yet"); - (void)nCol; // for release build - SolarMutexGuard g; OUString sText; GetQtInstance().RunInMainThread([&] { - const QModelIndex aIndex = firstTextColumnModelIndex(nRow); + const QModelIndex aIndex + = nCol == -1 ? firstTextColumnModelIndex(nRow) : modelIndex(nRow, nCol); const QVariant aData = m_pModel->data(aIndex); assert(aData.canConvert<QString>() && "model data not a string"); sText = toOUString(aData.toString()); @@ -173,12 +171,11 @@ OUString QtInstanceTreeView::get_text(int nRow, int nCol) const void QtInstanceTreeView::set_text(int nRow, const OUString& rText, int nCol) { - assert(nCol != -1 && "Support for special index -1 (first text column) not implemented yet"); - SolarMutexGuard g; GetQtInstance().RunInMainThread([&] { - QModelIndex aIndex = modelIndex(nRow, nCol); + const QModelIndex aIndex + = nCol == -1 ? firstTextColumnModelIndex(nRow) : modelIndex(nRow, nCol); m_pModel->setData(aIndex, toQString(rText)); }); } @@ -538,10 +535,9 @@ TriState QtInstanceTreeView::get_toggle(const weld::TreeIter&, int) const return TRISTATE_INDET; } -OUString QtInstanceTreeView::get_text(const weld::TreeIter&, int) const +OUString QtInstanceTreeView::get_text(const weld::TreeIter& rIter, int nCol) const { - assert(false && "Not implemented yet"); - return OUString(); + return get_text(rowIndex(rIter), nCol); } void QtInstanceTreeView::set_id(const weld::TreeIter& rIter, const OUString& rId) commit 4decd1b668899f54bd55990a9e72c2d4ec0c045e Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Feb 20 22:24:37 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Feb 21 08:43:03 2025 +0100 tdf#130857 qt weld: Add logic to find first treeview text column The weld::TreeView::get_text doc says: // col index -1 gets the first text column So far, the QtInstanceTreeView implementation was simply assuming that the first text column is the first column, i.e. the column at index 0. Add new method QtInstanceTreeView::firstTextColumnModelIndex that tries to find the first text column in a given row by finding the first column where data of type Qt::DisplayRole ("The key data to be rendered in the form of text. (QString)" [1]) is set. Assert if no such column was found. This at least works as expected for Calc's "Sheet" -> "Show Sheet" dialog for which initial support was added in commit 5d94ffde5125960fff0c177635292b2de5e20d38 Author: Michael Weghorn <m.wegh...@posteo.de> Date: Fri Nov 29 15:44:55 2024 +0100 tdf#130857 qt weld: Support Calc's "Show Sheet" dialog [1] https://doc.qt.io/qt-6/qt.html#ItemDataRole-enum Change-Id: Ibba0f99d6be006d7b8d896b0bfc396cfabbec084 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181970 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx index fb3ba51aa7f7..2ae97d3158cc 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -189,6 +189,7 @@ private: QModelIndex modelIndex(int nRow, int nCol = 0) const; QModelIndex modelIndex(const weld::TreeIter& rIter, int nCol = 0) const; static int rowIndex(const weld::TreeIter& rIter); + QModelIndex firstTextColumnModelIndex(int nRow) const; static QAbstractItemView::SelectionMode mapSelectionMode(SelectionMode eMode); private Q_SLOTS: diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index a904a8400e73..0287f2f81a72 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -162,7 +162,7 @@ OUString QtInstanceTreeView::get_text(int nRow, int nCol) const OUString sText; GetQtInstance().RunInMainThread([&] { - const QModelIndex aIndex = m_pModel->index(nRow, 0); + const QModelIndex aIndex = firstTextColumnModelIndex(nRow); const QVariant aData = m_pModel->data(aIndex); assert(aData.canConvert<QString>() && "model data not a string"); sText = toOUString(aData.toString()); @@ -867,6 +867,20 @@ int QtInstanceTreeView::rowIndex(const weld::TreeIter& rIter) return aModelIndex.row(); } +QModelIndex QtInstanceTreeView::firstTextColumnModelIndex(int nRow) const +{ + for (int i = 0; i < m_pModel->columnCount(); i++) + { + const QModelIndex aIndex = modelIndex(nRow, i); + QVariant data = m_pModel->data(aIndex, Qt::DisplayRole); + if (data.canConvert<QString>()) + return aIndex; + } + + assert(false && "No text column found"); + return QModelIndex(); +} + void QtInstanceTreeView::handleActivated() { SolarMutexGuard g;