XBEL example: minor simplifications

Pass one function's return as a parameter to another directly.
Use a ternary expression rather than conditional initialization.

Use initializer-list construction instead of appending to an empty
QStringList; and inline the result where it's used.

Task-number: QTBUG-111228
Change-Id: I781aedba8dcc4251193b55d82fe684c9b5da241a
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
(cherry picked from commit 5fd4a65d95)
This commit is contained in:
Edward Welbourne 2023-06-07 16:24:16 +02:00
parent cd1ef4db4f
commit 33d7e170e6

View File

@ -70,9 +70,7 @@ void XbelReader::readXBEL()
void XbelReader::readTitle(QTreeWidgetItem *item) void XbelReader::readTitle(QTreeWidgetItem *item)
{ {
Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("title")); Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("title"));
item->setText(0, xml.readElementText());
QString title = xml.readElementText();
item->setText(0, title);
} }
//! [4] //! [4]
@ -130,12 +128,7 @@ void XbelReader::readBookmark(QTreeWidgetItem *item)
QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item) QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item)
{ {
QTreeWidgetItem *childItem; QTreeWidgetItem *childItem = item ? new QTreeWidgetItem(item) : new QTreeWidgetItem(treeWidget);
if (item) {
childItem = new QTreeWidgetItem(item);
} else {
childItem = new QTreeWidgetItem(treeWidget);
}
childItem->setData(0, Qt::UserRole, xml.name().toString()); childItem->setData(0, Qt::UserRole, xml.name().toString());
return childItem; return childItem;
} }