From 8bad89cf539815bcafb2a8072baeaa882ad2c586 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 8 Jun 2023 18:36:19 +0200 Subject: [PATCH] XBEL examples: construct the text of the separators cleanly Create the fixed string once and reuse it. Also give a name to the escape code that's its repeated character. Task-number: QTBUG-111228 Change-Id: I3d6416070f1d5490ec137e251daff0e1637fb788 Reviewed-by: Konrad Kujawa Reviewed-by: Marc Mutz (cherry picked from commit 97f68cd3068587103c8b0a0ccdcd6e61431efc1e) --- examples/corelib/serialization/streambookmarks/xbelreader.cpp | 4 +++- examples/xml/dombookmarks/xbeltree.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/corelib/serialization/streambookmarks/xbelreader.cpp b/examples/corelib/serialization/streambookmarks/xbelreader.cpp index d062a3bd1d..0c50cd6bba 100644 --- a/examples/corelib/serialization/streambookmarks/xbelreader.cpp +++ b/examples/corelib/serialization/streambookmarks/xbelreader.cpp @@ -80,10 +80,12 @@ void XbelReader::readTitle(QTreeWidgetItem *item) void XbelReader::readSeparator(QTreeWidgetItem *item) { Q_ASSERT(xml.isStartElement() && xml.name() == "separator"_L1); + constexpr char16_t midDot = u'\xB7'; + static const QString dots(30, midDot); QTreeWidgetItem *separator = createChildItem(item); separator->setFlags(item ? item->flags() & ~Qt::ItemIsSelectable : Qt::ItemFlags{}); - separator->setText(0, QString(30, u'\xB7')); + separator->setText(0, dots); xml.skipCurrentElement(); } //! [5] diff --git a/examples/xml/dombookmarks/xbeltree.cpp b/examples/xml/dombookmarks/xbeltree.cpp index 7bd1a36fb7..eff2fea8f0 100644 --- a/examples/xml/dombookmarks/xbeltree.cpp +++ b/examples/xml/dombookmarks/xbeltree.cpp @@ -153,6 +153,8 @@ void XbelTree::parseFolderElement(const QDomElement &element, bool folded = (element.attribute(foldedAttribute) != "no"_L1); item->setExpanded(!folded); + constexpr char16_t midDot = u'\xB7'; + static const QString dots = QString(30, midDot); QDomElement child = element.firstChildElement(); while (!child.isNull()) { if (child.tagName() == folderElement) { @@ -171,7 +173,7 @@ void XbelTree::parseFolderElement(const QDomElement &element, } else if (child.tagName() == "separator"_L1) { QTreeWidgetItem *childItem = createItem(child, item); childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable)); - childItem->setText(0, QString(30, u'\xB7')); + childItem->setText(0, dots); } child = child.nextSiblingElement(); }