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. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I781aedba8dcc4251193b55d82fe684c9b5da241a Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
This commit is contained in:
parent
705e4e63c6
commit
5fd4a65d95
@ -10,12 +10,9 @@
|
||||
//! [0]
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
QStringList labels;
|
||||
labels << tr("Title") << tr("Location");
|
||||
|
||||
treeWidget = new QTreeWidget;
|
||||
treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
treeWidget->setHeaderLabels(labels);
|
||||
treeWidget->setHeaderLabels(QStringList{ tr("Title"), tr("Location") });
|
||||
#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD)
|
||||
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(treeWidget, &QWidget::customContextMenuRequested,
|
||||
|
@ -69,9 +69,7 @@ void XbelReader::readXBEL()
|
||||
void XbelReader::readTitle(QTreeWidgetItem *item)
|
||||
{
|
||||
Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("title"));
|
||||
|
||||
QString title = xml.readElementText();
|
||||
item->setText(0, title);
|
||||
item->setText(0, xml.readElementText());
|
||||
}
|
||||
//! [4]
|
||||
|
||||
@ -129,12 +127,7 @@ void XbelReader::readBookmark(QTreeWidgetItem *item)
|
||||
|
||||
QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item)
|
||||
{
|
||||
QTreeWidgetItem *childItem;
|
||||
if (item) {
|
||||
childItem = new QTreeWidgetItem(item);
|
||||
} else {
|
||||
childItem = new QTreeWidgetItem(treeWidget);
|
||||
}
|
||||
QTreeWidgetItem *childItem = item ? new QTreeWidgetItem(item) : new QTreeWidgetItem(treeWidget);
|
||||
childItem->setData(0, Qt::UserRole, xml.name().toString());
|
||||
return childItem;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user