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.weghorn@posteo.de>
This commit is contained in:
parent
36ab4833c9
commit
77f4c8c78a
4 changed files with 20 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue