r24729 by craig - Some code cleanup and conversion from QStringRef to QStringView

scribus-commit scribus-commit at lists.scribus.net
Sun Oct 3 15:06:00 UTC 2021


Author: craig
Date: Sun Oct  3 15:06:00 2021
New Revision: 24729

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24729
Log:
Some code cleanup and conversion from QStringRef to QStringView

Modified:
    trunk/Scribus/scribus/latexhelpers.cpp
    trunk/Scribus/scribus/latexhelpers.h
    trunk/Scribus/scribus/nftrcreader.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
    trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
    trunk/Scribus/scribus/scribusXml.cpp
    trunk/Scribus/scribus/ui/helpbrowser.cpp
    trunk/Scribus/scribus/ui/latexeditor.cpp

Modified: trunk/Scribus/scribus/latexhelpers.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/latexhelpers.cpp
==============================================================================
--- trunk/Scribus/scribus/latexhelpers.cpp	(original)
+++ trunk/Scribus/scribus/latexhelpers.cpp	Sun Oct  3 15:06:00 2021
@@ -171,11 +171,11 @@
 	m_error += new_error + "\n";
 }
 
-bool LatexConfigParser::StrRefToBool(const QStringRef &str) const
-{
-	if (str == "1" || str == "true")
+bool LatexConfigParser::StrViewToBool(const QStringView &str) const
+{
+	if (str == QStringView(u"1") || str == QStringView(u"true"))
 		return true;
-	if (str == "0" || str == "false" || str.isEmpty())
+	if (str == QStringView(u"0") || str == QStringView(u"false") || str.isEmpty())
 		return false;
 	qWarning() << "Invalid bool string:" << str.toString();
 	return false;
@@ -202,10 +202,10 @@
 			continue;
 		}
 		QString regex = xml.attributes().value("regex").toString();
-		bool bold = StrRefToBool(xml.attributes().value("bold"));
-		bool italic = StrRefToBool(xml.attributes().value("italic"));
-		bool underline = StrRefToBool(xml.attributes().value("underline"));
-		bool minimal = StrRefToBool(xml.attributes().value("minimal"));
+		bool bold = StrViewToBool(xml.attributes().value("bold"));
+		bool italic = StrViewToBool(xml.attributes().value("italic"));
+		bool underline = StrViewToBool(xml.attributes().value("underline"));
+		bool minimal = StrViewToBool(xml.attributes().value("minimal"));
 		QString colorStr = xml.attributes().value("color").toString();
 		QColor color(colorStr);
 		if (!color.isValid())

Modified: trunk/Scribus/scribus/latexhelpers.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/latexhelpers.h
==============================================================================
--- trunk/Scribus/scribus/latexhelpers.h	(original)
+++ trunk/Scribus/scribus/latexhelpers.h	Sun Oct  3 15:06:00 2021
@@ -23,12 +23,12 @@
 #ifndef LATEXHELPERS_H
 #define LATEXHELPERS_H
 
+#include <QObject>
+#include <QPointer>
+#include <QString>
+#include <QStringView>
 #include <QSyntaxHighlighter>
 #include <QXmlStreamReader>
-#include <QString>
-#include <QStringRef>
-#include <QObject>
-#include <QPointer>
 
 class LatexHighlighterRule
 {
@@ -89,11 +89,12 @@
 		void parseTab();
 		void parseHighlighter();
 		void ignoreList();
-		bool StrRefToBool(const QStringRef &str) const;
+		bool StrViewToBool(const QStringView& str) const;
 };
 
 class LatexConfigCache;
-class LatexConfigCache {
+class LatexConfigCache
+{
 	public:
 		static LatexConfigCache* instance();
 		static QStringList defaultConfigs();

Modified: trunk/Scribus/scribus/nftrcreader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/nftrcreader.cpp
==============================================================================
--- trunk/Scribus/scribus/nftrcreader.cpp	(original)
+++ trunk/Scribus/scribus/nftrcreader.cpp	Sun Oct  3 15:06:00 2021
@@ -7,6 +7,8 @@
 /***************************************************************************
  *   Riku Leino, tsoots at gmail.com                                          *
  ***************************************************************************/
+
+#include <QStringView>
 
 #include "nftrcreader.h"
 
@@ -34,16 +36,16 @@
 		if (tType != QXmlStreamReader::StartElement)
 			continue;
 
-		QStringRef tagName = reader.name();
+		QStringView tagName = reader.name();
 		if (firstElement)
 		{
-			if (tagName != "templates")
+			if (tagName != QStringView(u"templates"))
 				return false;
 			firstElement = false;
 			continue;
 		}
 
-		if (tagName == "template")
+		if (tagName == QStringView(u"template"))
 		{
 			QXmlStreamAttributes attrs = reader.attributes();
 			QString attrCat  = attrs.value("category").toString();
@@ -70,8 +72,8 @@
 	if (!reader.isStartElement())
 		return false;
 
-	QStringRef elemName = reader.name();
-	if (elemName != "template")
+	QStringView elemName = reader.name();
+	if (elemName != QStringView(u"template"))
 		return false;
 
 	while (!reader.atEnd() && !reader.hasError())
@@ -85,10 +87,10 @@
 		if (tType != QXmlStreamReader::StartElement)
 			continue;
 
-		QStringRef tagName = reader.name();
-		if (tagName == "name")
+		QStringView tagName = reader.name();
+		if (tagName == QStringView(u"name"))
 			nftTemplate->name = reader.readElementText();
-		else if (tagName == "file")
+		else if (tagName == QStringView(u"file"))
 		{
 			QString tmp = reader.readElementText();
 			if (tmp.left(1) == "/")
@@ -96,7 +98,7 @@
 			else 
 				nftTemplate->file = currentDir + "/" + tmp;
 		}
-		else if (tagName == "tnail")
+		else if (tagName == QStringView(u"tnail"))
 		{
 			QString tmp = reader.readElementText();
 			if (tmp.left(1) == "/")
@@ -104,7 +106,7 @@
 			else 
 				nftTemplate->tnail = currentDir + "/" + tmp;
 		}
-		else if (tagName == "img")
+		else if (tagName == QStringView(u"img"))
 		{
 			QString tmp = reader.readElementText();
 			if (tmp.left(1) == "/")
@@ -112,21 +114,21 @@
 			else 
 				nftTemplate->img = currentDir + "/" + tmp;
 		}
-		else if (tagName == "psize")
+		else if (tagName == QStringView(u"psize"))
 			nftTemplate->psize = reader.readElementText();
-		else if (tagName == "color")
+		else if (tagName == QStringView(u"color"))
 			nftTemplate->color = reader.readElementText();
-		else if (tagName == "descr")
+		else if (tagName == QStringView(u"descr"))
 			nftTemplate->descr = reader.readElementText();
-		else if (tagName == "usage")
+		else if (tagName == QStringView(u"usage"))
 			nftTemplate->usage = reader.readElementText();
-		else if (tagName == "scribus_version")
+		else if (tagName == QStringView(u"scribus_version"))
 			nftTemplate->scribusVersion = reader.readElementText();
-		else if (tagName == "date")
+		else if (tagName == QStringView(u"date"))
 			nftTemplate->date = reader.readElementText();
-		else if (tagName == "author")
+		else if (tagName == QStringView(u"author"))
 			nftTemplate->author = reader.readElementText();
-		else if (tagName == "email")
+		else if (tagName == QStringView(u"email"))
 			nftTemplate->email = reader.readElementText();
 		else
 		{

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp	Sun Oct  3 15:06:00 2021
@@ -18,6 +18,7 @@
 #include <QIODevice>
 #include <QList>
 #include <QScopedPointer>
+#include <QStringView>
 
 #include "../../formatidlist.h"
 #include "commonstrings.h"

Modified: trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp	(original)
+++ trunk/Scribus/scribus/plugins/saveastemplateplugin/satdialog.cpp	Sun Oct  3 15:06:00 2021
@@ -36,7 +36,7 @@
 
 		QXmlStreamReader sReader(&qFile);
 		QXmlStreamReader::TokenType tagType;
-		QStringRef tagName;
+		QStringView tagName;
 
 		while (!sReader.atEnd() && !sReader.hasError())
 		{
@@ -45,7 +45,7 @@
 				continue;
 
 			tagName = sReader.name();
-			if (tagName != "template")
+			if (tagName != QStringView(u"template"))
 				continue;
 
 			QXmlStreamAttributes attrs = sReader.attributes();

Modified: trunk/Scribus/scribus/scribusXml.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/scribusXml.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusXml.cpp	(original)
+++ trunk/Scribus/scribus/scribusXml.cpp	Sun Oct  3 15:06:00 2021
@@ -83,7 +83,7 @@
 		ff  = file;
 
 	bool succeed = false;
-	QStringRef tName;
+	QStringView tName;
 	QXmlStreamReader sReader(ff);
 	QXmlStreamReader::TokenType tType;
 	while (!sReader.atEnd() && !sReader.hasError())
@@ -92,7 +92,7 @@
 		if (tType == QXmlStreamReader::StartElement)
 		{
 			tName = sReader.name();
-			if ((tName == "SCRIBUSELEM") || (tName == "SCRIBUSELEMUTF8"))
+			if ((tName == QStringView(u"SCRIBUSELEM")) || (tName == QStringView(u"SCRIBUSELEMUTF8")))
 			{
 				QXmlStreamAttributes attrs = sReader.attributes();;
 				QString attx = attrs.value("XP").toString();
@@ -238,4 +238,4 @@
 	for (auto item : selectedItems)
 		items.insert(doc->Items->indexOf(item), item);
 	return items.values();
-}
+}

Modified: trunk/Scribus/scribus/ui/helpbrowser.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/ui/helpbrowser.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/helpbrowser.cpp	(original)
+++ trunk/Scribus/scribus/ui/helpbrowser.cpp	Sun Oct  3 15:06:00 2021
@@ -81,7 +81,7 @@
 
 			QXmlStreamReader sReader(&qFile);
 			QXmlStreamReader::TokenType tagType;
-			QStringRef tagName;
+			QStringView tagName;
 
 			while (!sReader.atEnd() && !sReader.hasError())
 			{
@@ -90,7 +90,7 @@
 					continue;
 
 				tagName = sReader.name();
-				if (tagName != "item")
+				if (tagName != QStringView(u"item"))
 					continue;
 
 				struct histd2 his;
@@ -126,7 +126,7 @@
 
 			QXmlStreamReader sReader(&qFile);
 			QXmlStreamReader::TokenType tagType;
-			QStringRef tagName;
+			QStringView tagName;
 
 			while (!sReader.atEnd() && !sReader.hasError())
 			{
@@ -135,7 +135,7 @@
 					continue;
 
 				tagName = sReader.name();
-				if (tagName != "item")
+				if (tagName != QStringView(u"item"))
 					continue;
 
 				QXmlStreamAttributes attrs = sReader.attributes();

Modified: trunk/Scribus/scribus/ui/latexeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24729&path=/trunk/Scribus/scribus/ui/latexeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/latexeditor.cpp	(original)
+++ trunk/Scribus/scribus/ui/latexeditor.cpp	Sun Oct  3 15:06:00 2021
@@ -28,12 +28,13 @@
 
 #include <QDebug>
 #include <QFile>
+#include <QFontComboBox>
 #include <QFrame>
-#include <QFontComboBox>
 #include <QLineEdit>
-#include <QPushButton>
 #include <QListWidget>
 #include <QMessageBox>
+#include <QPushButton>
+#include <QStringView>
 #include <QTemporaryFile>
 #include <cmath>
 #include "filewatcher.h"
@@ -449,12 +450,12 @@
 	{
 		xml.readNext();
 		if (xml.isWhitespace() || xml.isComment()) continue;
-		if (xml.isStartElement() && xml.name() == "tab")
-		{
-			if (xml.attributes().value("type") == "settings")
+		if (xml.isStartElement() && xml.name() == QStringView(u"tab"))
+		{
+			if (xml.attributes().value("type") == QStringView(u"settings"))
 			{
 				createNewSettingsTab(&xml);
-			} else if (xml.attributes().value("type") == "items")
+			} else if (xml.attributes().value("type") == QStringView(u"items"))
 			{
 				createNewItemsTab(&xml);
 			}
@@ -475,7 +476,7 @@
 
 void LatexEditor::createNewSettingsTab(I18nXmlStreamReader *xml)
 {
-	QStringRef tagname;
+	QStringView tagname;
 	QFrame *newTab = new QFrame();
 	newTab->setFrameShape(QFrame::NoFrame);
 	QGridLayout *layout = new QGridLayout(newTab);
@@ -487,24 +488,32 @@
 		xml->readNext();
 		if (xml->isWhitespace() || xml->isComment()) continue;
 		tagname = xml->name();
-		if (xml->isEndElement() && (tagname == "tab")) {
+		if (xml->isEndElement() && (tagname == QStringView(u"tab")))
+		{
 			break;
 		}
-		if (!xml->isStartElement()) {
+		if (!xml->isStartElement())
+		{
 			xmlError() << "Unexpected element (not a start element)!";
 			continue;
 		}
 		
-		if (tagname == "comment") {
+		if (tagname == QStringView(u"comment"))
+		{
 			QLabel *label = new QLabel(xml->readI18nText());
 			int row = layout->rowCount();
 			label->setWordWrap(true);
 			layout->addWidget(label, row, 0, 1, 3);
-		} else if (tagname == "title") {
+		}
+		else if (tagname == QStringView(u"title"))
+		{
 			title = xml->readI18nText();
-		} else {
+		}
+		else
+		{
 			XmlWidget *widget = XmlWidget::fromXml(xml);
-			if (dynamic_cast<QWidget *>(widget)) {
+			if (dynamic_cast<QWidget *>(widget))
+			{
 				QLabel *label = new QLabel(widget->description());
 				label->setWordWrap(true);
 				QString name = widget->name();
@@ -522,15 +531,12 @@
 						this, SLOT(tagButtonClicked(QString)));
 				layout->addWidget(button, row, 2);*/
 			
-				if (widgetMap.contains(name)) {
-					xmlError() << "There is already an widget with name" << 
-						name << "!";
-				}
+				if (widgetMap.contains(name))
+					xmlError() << "There is already an widget with name" << name << "!";
 				widgetMap[name] = widget;
-			} else {
-				xmlError() << "Unexpected tag" << tagname.toString() << 
-						"in settings tab";
 			}
+			else
+				xmlError() << "Unexpected tag" << tagname.toString() << "in settings tab";
 		}
 	}
 	layout->setRowStretch(layout->rowCount(), 10);
@@ -539,8 +545,7 @@
 
 void LatexEditor::createNewItemsTab(I18nXmlStreamReader *xml) 
 {
-	QString title = "No Title!";
-	
+	QString title("No Title!");
 	
 	QFrame *newTab = new QFrame();
 	newTab->setFrameShape(QFrame::NoFrame);
@@ -567,24 +572,24 @@
 	vLayout->addWidget(iconList, 100);
 	vLayout->addLayout(hLayout, 0);
 	
-	QStringRef tagname;
+	QStringView tagname;
 	while (!xml->atEnd()) 
 	{
 		xml->readNext();
 		if (xml->isWhitespace() || xml->isComment()) continue;
 		tagname = xml->name();
-		if (xml->isEndElement() && (tagname == "tab")) 
+		if (xml->isEndElement() && (tagname == QStringView(u"tab")))
 			break;
 		if (!xml->isStartElement()) 
 		{
 			xmlError() << "Unexpected end element "	<<tagname.toString()<<"in item tab";
 			continue;
 		}
-		if (tagname == "title") 
+		if (tagname == QStringView(u"title"))
 		{
 			title = xml->readI18nText();
 		} 
-		else if (tagname == "item") 
+		else if (tagname == QStringView(u"item"))
 		{
 			QString value = xml->attributes().value("value").toString();
 			QString img = xml->attributes().value("image").toString();
@@ -611,8 +616,7 @@
 		} 
 		else
 		{
-			xmlError() << "Unexpected tag" << tagname.toString() << 
-				"in item tab!";
+			xmlError() << "Unexpected tag" << tagname.toString() << "in item tab!";
 			continue;
 		}
 	}
@@ -652,11 +656,13 @@
 			fromString(m_defaultValue);
 		}
 		
-		QString toString() const {
+		QString toString() const
+		{
 			return currentFont().toString();
 		}
 		
-		void fromString(QString str) {
+		void fromString(QString str)
+		{
 			QFont font;
 			font.fromString(str);
 			this->setCurrentFont(font);
@@ -730,15 +736,18 @@
 class SCRIBUS_API XmlLineEdit : public XmlWidget, public QLineEdit
 {
 	public:
-		XmlLineEdit(I18nXmlStreamReader *xml) :  XmlWidget(xml) {
+		XmlLineEdit(I18nXmlStreamReader *xml) :  XmlWidget(xml)
+		{
 			fromString(m_defaultValue);
 		}
 		
-		QString toString() const override {
+		QString toString() const override
+		{
 			return text();
 		}
 		
-		void fromString(QString str) override {
+		void fromString(QString str) override
+		{
 			setText(str);
 		}
 };
@@ -746,15 +755,18 @@
 class SCRIBUS_API XmlTextEdit : public XmlWidget, public QTextEdit
 {
 	public:
-		XmlTextEdit(I18nXmlStreamReader *xml) :  XmlWidget(xml) {
+		XmlTextEdit(I18nXmlStreamReader *xml) :  XmlWidget(xml)
+		{
 			fromString(m_defaultValue);
 		}
 		
-		QString toString() const override {
+		QString toString() const override
+		{
 			return toPlainText();
 		}
 		
-		void fromString(QString str) override {
+		void fromString(QString str) override
+		{
 			setPlainText(str);
 		}
 };
@@ -769,11 +781,13 @@
 			fromString(m_defaultValue);
 		}
 		
-		QString toString() const override {
+		QString toString() const override
+		{
 			return "Not implemented!";
 		}
 		
-		void fromString(QString str) override {
+		void fromString(QString str) override
+		{
 			qDebug() << "Color pickers are not implemented yet!";
 		}
 };
@@ -783,61 +797,69 @@
 	public:
 		XmlComboBox(I18nXmlStreamReader *xml) :  XmlWidget(xml, false)
 		{
-			QStringRef tagname;
+			QStringView tagname;
 			while (!xml->atEnd()) {
 				xml->readNext();
 				if (xml->isWhitespace() || xml->isComment()) continue;
 				tagname = xml->name();
-				if (xml->isEndElement() && (tagname == "list")) {
+				if (xml->isEndElement() && (tagname == QStringView(u"list")))
+				{
 					fromString(m_defaultValue);
 					return;
 				}
-				if (xml->isEndElement()) {
+				if (xml->isEndElement())
+				{
 					xmlError() << "Unexpected end element" << tagname.toString();
 					continue;
 				}
-				if (tagname == "title") {
+				if (tagname == QStringView(u"title"))
+				{
 					m_description = xml->readI18nText();
-				} else if (tagname == "option") {
+				}
+				else if (tagname == QStringView(u"option"))
+				{
 					QString value = xml->attributes().value("value").toString();
 					QString text = xml->readI18nText();
 					addItem(text, value);
-				} else {
-					xmlError() << "Unexpected tag" << tagname.toString() << 
-						"in list!";
+				}
+				else
+				{
+					xmlError() << "Unexpected tag" << tagname.toString() << "in list!";
 				}
 			}
 		}
 		
-		QString toString() const override {
+		QString toString() const override
+		{
 			return itemData(currentIndex()).toString();
 		}
 		
-		void fromString(QString str) override {
+		void fromString(QString str) override
+		{
 			setCurrentIndex(findData(str));
 		}
 };
 
 XmlWidget* XmlWidget::fromXml(I18nXmlStreamReader *xml)
 {
-	QStringRef tagname = xml->name();
-	if (tagname == "font")
+	QStringView tagname = xml->name();
+	if (tagname == QStringView(u"font"))
 		return new XmlFontComboBox(xml);
-	if (tagname == "spinbox")
+	if (tagname == QStringView(u"spinbox"))
 	{
 		if (xml->attributes().value("type") == "double")
 			return new XmlDoubleSpinBox(xml);
 		return new XmlSpinBox(xml);
 	}
-	if (tagname == "color")
+	if (tagname == QStringView(u"color"))
 		return new XmlColorPicker(xml);
-	if (tagname == "text")
+	if (tagname == QStringView(u"text"))
 	{
 		if (xml->attributes().value("type") == "long")
 			return new XmlTextEdit(xml);
 		return new XmlLineEdit(xml);
 	}
-	if (tagname == "list")
+	if (tagname == QStringView(u"list"))
 		return new XmlComboBox(xml);
 	return nullptr;
 }
@@ -852,7 +874,8 @@
 
 void IconBuffer::loadFile(const QString& filename)
 {
-	if (loadedFiles.contains(filename)) return;
+	if (loadedFiles.contains(filename))
+		return;
 	loadedFiles << filename;
 	file = new QFile(filename);
 	if (!file->open(QIODevice::ReadOnly))
@@ -873,7 +896,7 @@
 QIcon *IconBuffer::icon(const QString& filename, const QString& name)
 {
 	loadFile(filename);
-	QString cname = filename + ":" + name;
+	QString cname(filename + ":" + name);
 	if (icons.contains(cname))
 		return &(icons[cname]);
 	qWarning() << "Icon" << cname << "not found!";




More information about the scribus-commit mailing list