include/vcl/builderbase.hxx | 1 + vcl/inc/qt5/QtInstanceTreeView.hxx | 2 +- vcl/qt5/QtBuilder.cxx | 11 ++++++++++- vcl/qt5/QtInstanceTreeView.cxx | 30 ++++++++++++++++++++++++++---- vcl/source/window/builder.cxx | 10 +++++----- 5 files changed, 43 insertions(+), 11 deletions(-)
New commits: commit 77f4c8c78aa1b79f1e81d7dac477ed1676e1d5df Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Dec 7 21:04:49 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Dec 8 01:22:33 2024 +0100 tdf#130857 qt weld: Set tree view column header title Make the `extractTitle` helper function used by VclBuilder a static method in the BuilderBase base class for reuse by QtBuilder. In QtBuilder::makeObject, when encountering a "GtkTreeViewColumn" object, add a new column to the QTreeView and set the column title in the underlying model using QStandardItemModel::setHeaderData. Return the parent (tree view). (Returning no object would cause WidgetBuilder::handleObject to call WidgetBuilder::insertObject again, and thus result in every column being processed twice, i.e. the double amount of columns would be inserted). Adjust QtInstanceTreeView::clear to no longer call QStandardItemModel::clear [1], as that would not only remove the "actual" items, but also the header items, i.e. the column titles would get lost as well. Remove all rows instead. With this in place, the tree view in Writer's "Tool" -> "XML Filter Settings" dialog has the correct data + title set on open in a WIP branch where support for that dialog is declared in QtInstanceBuilder. (Other aspects in the dialog still need to be addressed however.) [1] https://doc.qt.io/qt-6/qstandarditemmodel.html#clear Change-Id: I59956c007ed73cddb299ad2374afd88199ddc94d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178063 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/builderbase.hxx b/include/vcl/builderbase.hxx index 04b534b92a4e..573817315f72 100644 --- a/include/vcl/builderbase.hxx +++ b/include/vcl/builderbase.hxx @@ -88,6 +88,7 @@ protected: static bool extractEntry(stringmap& rMap); static OUString extractIconName(stringmap& rMap); static bool extractShowExpanders(stringmap& rMap); + static OUString extractTitle(stringmap& rMap); static OUString extractTooltipText(stringmap& rMap); static bool extractVisible(stringmap& rMap); void extractClassAndIdAndCustomProperty(xmlreader::XmlReader& reader, OUString& rClass, diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index 89c8a36d2573..e282ce872790 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -296,7 +296,16 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, std: } else if (sName == u"GtkTreeViewColumn") { - SAL_WARN("vcl.qt", "GtkTreeViewColumn properties not evaluated yet"); + QTreeView* pTreeView = qobject_cast<QTreeView*>(pParentWidget); + assert(pTreeView && "Tree view column doesn't have a tree view parent"); + QStandardItemModel* pModel = qobject_cast<QStandardItemModel*>(pTreeView->model()); + assert(pModel && "Tree view doesn't have QStandardItemModel set"); + const int nCol = pModel->columnCount(); + pModel->insertColumn(nCol); + pModel->setHeaderData(nCol, Qt::Horizontal, toQString(extractTitle(rMap))); + + // nothing else to do, return tree view parent for the widget + return pTreeView; } else { diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index d65bcdd4746e..10fb36413f6f 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -644,7 +644,10 @@ void QtInstanceTreeView::clear() { SolarMutexGuard g; - GetQtInstance().RunInMainThread([&] { m_pModel->clear(); }); + GetQtInstance().RunInMainThread([&] { + // don't use QStandardItemModel::clear, as that would remove header data as well + m_pModel->removeRows(0, m_pModel->rowCount()); + }); } int QtInstanceTreeView::get_height_rows(int) const diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 74a4aa479b0e..66924872b649 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -1007,11 +1007,6 @@ namespace return f; } - OUString extractTitle(VclBuilder::stringmap &rMap) - { - return extractStringEntry(rMap, u"title"_ustr); - } - bool extractSortIndicator(VclBuilder::stringmap &rMap) { return extractBoolEntry(rMap, u"sort-indicator"_ustr, false); @@ -3411,6 +3406,11 @@ bool BuilderBase::extractShowExpanders(VclBuilder::stringmap& rMap) return extractBoolEntry(rMap, u"show-expanders"_ustr, true); } +OUString BuilderBase::extractTitle(VclBuilder::stringmap &rMap) +{ + return extractStringEntry(rMap, u"title"_ustr); +} + OUString BuilderBase::extractTooltipText(stringmap& rMap) { OUString sTooltipText; commit 36ab4833c96bf9568e7fb06880c01729f2c75ece Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Dec 7 20:02:08 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Dec 8 01:22:26 2024 +0100 tdf#130857 qt weld: Implement QtInstanceTreeView::columns_autosize QTreeView::resizeColumnToContents [1] looks like the Qt equivalent for GTK's gtk_tree_view_columns_autosize [2]. [1] https://doc.qt.io/qt-6/qtreeview.html#resizeColumnToContents [2] https://docs.gtk.org/gtk3/method.TreeView.columns_autosize.html Change-Id: I4771896fb932834f51fa48ceaa3557181f474fcc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178062 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 23fe407e8033..d65bcdd4746e 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -653,7 +653,15 @@ int QtInstanceTreeView::get_height_rows(int) const return 0; } -void QtInstanceTreeView::columns_autosize() { assert(false && "Not implemented yet"); } +void QtInstanceTreeView::columns_autosize() +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + for (int i = 0; i < m_pModel->columnCount(); i++) + m_pTreeView->resizeColumnToContents(i); + }); +} void QtInstanceTreeView::set_column_fixed_widths(const std::vector<int>&) { commit 23ea73587adead7b41e39a9c2cf55d5bb5f8b926 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Dec 7 19:53:28 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Dec 8 01:22:20 2024 +0100 tdf#130857 qt weld: Implement QtInstanceTreeView::set_text For now, require that the actual column index is passed. The weld::TreeView::set_text doc mentions // col index -1 sets the first text column , but that is not supported yet, so assert a different index is passed for now. Revisit when implementing support for a dialog that actually makes use of this. Change-Id: I8ba6e965ba22542bf3151548200b92c8c6b085d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178061 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 15fab0ff0792..110bc09c8bd2 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -44,7 +44,7 @@ public: virtual void unselect(int nPos) override; virtual void remove(int pos) override; virtual OUString get_text(int nRow, int nCol = -1) const override; - virtual void set_text(int row, const OUString& rText, int col = -1) override; + virtual void set_text(int nRow, const OUString& rText, int nCol = -1) override; virtual void set_sensitive(int row, bool bSensitive, int col = -1) override; virtual bool get_sensitive(int row, int col) const override; virtual void set_id(int row, const OUString& rId) override; diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index e2d28af9932c..23fe407e8033 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -162,9 +162,20 @@ OUString QtInstanceTreeView::get_text(int nRow, int nCol) const return sText; } -void QtInstanceTreeView::set_text(int, const OUString&, int) +void QtInstanceTreeView::set_text(int nRow, const OUString& rText, int nCol) { - assert(false && "Not implemented yet"); + assert(nCol != -1 && "Support for special index -1 (first text column) not implemented yet"); + + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { + QStandardItem* pItem = m_pModel->item(nRow, nCol); + if (!pItem) + { + pItem = new QStandardItem; + m_pModel->setItem(nRow, nCol, pItem); + } + pItem->setText(toQString(rText)); + }); } void QtInstanceTreeView::set_sensitive(int, bool, int) { assert(false && "Not implemented yet"); }