From 77f4c8c78aa1b79f1e81d7dac477ed1676e1d5df Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Sat, 7 Dec 2024 21:04:49 +0100 Subject: [PATCH] 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 --- include/vcl/builderbase.hxx | 1 + vcl/qt5/QtBuilder.cxx | 11 ++++++++++- vcl/qt5/QtInstanceTreeView.cxx | 5 ++++- vcl/source/window/builder.cxx | 10 +++++----- 4 files changed, 20 insertions(+), 7 deletions(-) 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(pParentWidget); + assert(pTreeView && "Tree view column doesn't have a tree view parent"); + QStandardItemModel* pModel = qobject_cast(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;