[education/rkward] rkward: Port away from deprecated QString::SplitBehavior

Thomas Friedrichsmeier null at kde.org
Sat May 14 10:29:14 BST 2022


Git commit f5231df6f4145426310c73549c6903e514bb52af by Thomas Friedrichsmeier.
Committed on 14/05/2022 at 09:28.
Pushed by tfry into branch 'master'.

Port away from deprecated QString::SplitBehavior

M  +1    -1    rkward/core/rkvariable.cpp
M  +11   -1    rkward/misc/rkcommonfunctions.h
M  +2    -2    rkward/plugin/rkcomponentmeta.cpp
M  +2    -2    rkward/plugin/rkcomponentproperties.cpp
M  +2    -2    rkward/plugin/rkmatrixinput.cpp
M  +2    -2    rkward/plugin/rkoptionset.cpp
M  +2    -2    rkward/plugin/rkvarslot.cpp
M  +2    -2    rkward/rkconsole.cpp
M  +2    -2    rkward/windows/rkhtmlwindow.cpp
M  +1    -1    rkward/windows/rkworkplace.cpp

https://invent.kde.org/education/rkward/commit/f5231df6f4145426310c73549c6903e514bb52af

diff --git a/rkward/core/rkvariable.cpp b/rkward/core/rkvariable.cpp
index 21872648..d99ca3cd 100644
--- a/rkward/core/rkvariable.cpp
+++ b/rkward/core/rkvariable.cpp
@@ -861,7 +861,7 @@ RKVariable::FormattingOptions RKVariable::parseFormattingOptionsString (const QS
 	formatting_options.precision_mode = FormattingOptions::PrecisionDefault;
 	formatting_options.precision = 0;
 
-	QStringList list = string.split ('#', QString::SkipEmptyParts);
+	QStringList list = string.split ('#', RKCommonFunctions::SkipEmptyParts());
 	QString option, parameter;
 	for (QStringList::const_iterator it = list.constBegin (); it != list.constEnd (); ++it) {
 		option = (*it).section (':', 0, 0);
diff --git a/rkward/misc/rkcommonfunctions.h b/rkward/misc/rkcommonfunctions.h
index 15f5eeb1..4d5ecc5c 100644
--- a/rkward/misc/rkcommonfunctions.h
+++ b/rkward/misc/rkcommonfunctions.h
@@ -9,9 +9,9 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include <QChar>
 #include <QRect>
+#include <QString>
 
 class QStringList;
-class QString;
 class QDomNode;
 class KXMLGUIClient;
 class QWidget;
@@ -57,8 +57,18 @@ namespace RKCommonFunctions {
 /** create a QLabel that has wordwarp enabled, *and* clickable links (opened inside RKWard), in a single line of code. */
 	QLabel* linkedWrappedLabel (const QString &text);
 
+//// NOTE: Functions / constants below are porting aids, to be removed, eventually. ////
 /** Small wrapper around QScreen::availableGeometry(), mostly to ease porting */
 	QRect availableGeometry(QWidget *for_widget);
+
+/** Porting aid: Qt::SplitBehaviorFlags was added in Qt 5.14, deprecating the previous flags in QString. Remove, once we depend on Qt >= 5.14 */
+#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
+	inline Qt::SplitBehaviorFlags KeepEmptyParts() { return Qt::KeepEmptyParts; };
+	inline Qt::SplitBehaviorFlags SkipEmptyParts() { return Qt::SkipEmptyParts; };
+#else
+	inline QString::SplitBehavior KeepEmptyParts() { return RKCommonFunctions::KeepEmptyParts(); };
+	inline QString::SplitBehavior SkipEmptyParts() { return QString::SkipEmptyParts; };
+#endif
 };
 
 #endif
diff --git a/rkward/plugin/rkcomponentmeta.cpp b/rkward/plugin/rkcomponentmeta.cpp
index 4ea4963f..9da593c6 100644
--- a/rkward/plugin/rkcomponentmeta.cpp
+++ b/rkward/plugin/rkcomponentmeta.cpp
@@ -92,8 +92,8 @@ QString RKComponentAboutData::toHtml () const {
 	}
 
 	if (!translator_names.isNull ()) {
-		QStringList tns = translator_names.split (QLatin1Char(','), QString::KeepEmptyParts);
-		QStringList tes = translator_emails.split (QLatin1Char(','), QString::KeepEmptyParts);
+		QStringList tns = translator_names.split (QLatin1Char(','), RKCommonFunctions::KeepEmptyParts());
+		QStringList tes = translator_emails.split (QLatin1Char(','), RKCommonFunctions::KeepEmptyParts());
 		ret.append ("\n<p><b>" + i18n ("Translators:") + "</b></p>\n<p><ul>");
 		for (int i = 0; i < tns.size (); ++i) {
 			QString tn = tns.value (i);
diff --git a/rkward/plugin/rkcomponentproperties.cpp b/rkward/plugin/rkcomponentproperties.cpp
index 824df7d1..5f194ca8 100644
--- a/rkward/plugin/rkcomponentproperties.cpp
+++ b/rkward/plugin/rkcomponentproperties.cpp
@@ -1004,13 +1004,13 @@ bool RKComponentPropertyRObjects::setValueList (const QStringList& values) {
 bool RKComponentPropertyRObjects::setValue (const QString &value) {
 	RK_TRACE (PLUGIN);
 
-	return setValueList (value.split (sep, QString::SkipEmptyParts));
+	return setValueList (value.split (sep, RKCommonFunctions::SkipEmptyParts()));
 }
 
 bool RKComponentPropertyRObjects::isStringValid (const QString &value) {
 	RK_TRACE (PLUGIN);
 
-	QStringList slist = value.split (sep, QString::SkipEmptyParts);
+	QStringList slist = value.split (sep, RKCommonFunctions::SkipEmptyParts());
 
 	for (QStringList::const_iterator it = slist.cbegin (); it != slist.cend (); ++it) {
 		RObject *obj = RObjectList::getObjectList ()->findObject (*it);
diff --git a/rkward/plugin/rkmatrixinput.cpp b/rkward/plugin/rkmatrixinput.cpp
index 4f680b79..51f349d6 100644
--- a/rkward/plugin/rkmatrixinput.cpp
+++ b/rkward/plugin/rkmatrixinput.cpp
@@ -184,7 +184,7 @@ void RKMatrixInput::setColumnValue (int column, const QString& value) {
 	RK_TRACE (PLUGIN);
 
 	if (!expandStorageForColumn (column)) return;
-	columns[column].storage = value.split ('\t', QString::KeepEmptyParts);
+	columns[column].storage = value.split ('\t', RKCommonFunctions::KeepEmptyParts());
 	updateColumn (column);
 	emit model->dataChanged (model->index(0, column), model->index(row_count->intValue() + trailing_rows, column));
 }
@@ -333,7 +333,7 @@ void RKMatrixInput::tsvPropertyChanged () {
 	RK_TRACE (PLUGIN);
 
 	columns.clear ();
-	QStringList coldata = fetchStringValue (tsv_data).split ('\n', QString::KeepEmptyParts);
+	QStringList coldata = fetchStringValue (tsv_data).split ('\n', RKCommonFunctions::KeepEmptyParts());
 	for (int i = 0; i < coldata.size (); ++i) {
 		setColumnValue (i, coldata[i]);
 	}
diff --git a/rkward/plugin/rkoptionset.cpp b/rkward/plugin/rkoptionset.cpp
index 73b7f7d0..714e899b 100644
--- a/rkward/plugin/rkoptionset.cpp
+++ b/rkward/plugin/rkoptionset.cpp
@@ -190,7 +190,7 @@ QString serializeList (const QStringList &list) {
 }
 
 QStringList unserializeList  (const QString &serial) {
-	QStringList ret = serial.split ('\t', QString::KeepEmptyParts);
+	QStringList ret = serial.split ('\t', RKCommonFunctions::KeepEmptyParts());
 	for (int i = 0; i < ret.size (); ++i) {
 		ret[i] = RKCommonFunctions::unescape (ret[i]);
 	}
@@ -210,7 +210,7 @@ QString serializeMap (const RKComponent::PropertyValueMap &map) {
 
 RKComponent::PropertyValueMap unserializeMap (const QString &serial) {
 	RKComponent::PropertyValueMap ret;
-	QStringList l = serial.split ('\t', QString::KeepEmptyParts);
+	QStringList l = serial.split ('\t', RKCommonFunctions::KeepEmptyParts());
 	for (int i = 0; i < l.size (); ++i) {
 		QString &line = l[i];
 		int sep = line.indexOf ('=');
diff --git a/rkward/plugin/rkvarslot.cpp b/rkward/plugin/rkvarslot.cpp
index 7c02aa4e..830d67f1 100644
--- a/rkward/plugin/rkvarslot.cpp
+++ b/rkward/plugin/rkvarslot.cpp
@@ -98,8 +98,8 @@ RKVarSlot::RKVarSlot (const QDomElement &element, RKComponent *parent_component,
 
 	if (mode == Varslot) {
 		// initialize filters
-		static_cast<RKComponentPropertyRObjects*> (available)->setClassFilter (xml->getStringAttribute (element, "classes", QString (), DL_INFO).split (' ', QString::SkipEmptyParts));
-		static_cast<RKComponentPropertyRObjects*> (available)->setTypeFilter (xml->getStringAttribute (element, "types", QString (), DL_INFO).split (' ', QString::SkipEmptyParts));
+		static_cast<RKComponentPropertyRObjects*> (available)->setClassFilter (xml->getStringAttribute (element, "classes", QString (), DL_INFO).split (' ', RKCommonFunctions::SkipEmptyParts()));
+		static_cast<RKComponentPropertyRObjects*> (available)->setTypeFilter (xml->getStringAttribute (element, "types", QString (), DL_INFO).split (' ', RKCommonFunctions::SkipEmptyParts()));
 		static_cast<RKComponentPropertyRObjects*> (available)->setDimensionFilter (xml->getIntAttribute (element, "num_dimensions", 0, DL_INFO), xml->getIntAttribute (element, "min_length", 0, DL_INFO), xml->getIntAttribute (element, "max_length", INT_MAX, DL_INFO));
 		static_cast<RKComponentPropertyRObjects*> (available)->setObjectProblemsAreErrors (false);
 	}
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 07133060..28533daa 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -712,7 +712,7 @@ void RKConsole::userLoadHistory (const QUrl &_url) {
 
 	QFile file (filename);
 	if (!file.open (QIODevice::Text | QIODevice::ReadOnly)) return;
-	setCommandHistory (QString (file.readAll ()).split ('\n', QString::SkipEmptyParts), false);
+	setCommandHistory (QString (file.readAll ()).split ('\n', RKCommonFunctions::SkipEmptyParts()), false);
 	file.close ();
 
 	delete (tmpfile);
@@ -896,7 +896,7 @@ void RKConsole::pipeCommandThroughConsoleLocal (const QString &command_string) {
 		}
 	}
 	if (RKSettingsModuleConsole::addPipedCommandsToHistory() != RKSettingsModuleConsole::DontAdd) {
-		QStringList lines = command_string.split ('\n', QString::SkipEmptyParts);
+		QStringList lines = command_string.split ('\n', RKCommonFunctions::SkipEmptyParts());
 		if ((RKSettingsModuleConsole::addPipedCommandsToHistory() == RKSettingsModuleConsole::AlwaysAdd) || (lines.count () == 1)) {
 			for (int i = 0; i < lines.count (); ++i) {
 				commands_history.append (lines[i]);
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index 33885b73..c81bce38 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -574,7 +574,7 @@ bool RKHTMLWindow::handleRKWardURL (const QUrl &url, RKHTMLWindow *window) {
 			if (path.startsWith ('/')) path = path.mid (1);
 			int sep = path.indexOf ('/');
 			// NOTE: These links may originate externally, even from untrusted sources. The submit mode *must* remain "ManualSubmit" for this reason!
-			RKComponentMap::invokeComponent (path.left (sep), path.mid (sep+1).split ('\n', QString::SkipEmptyParts), RKComponentMap::ManualSubmit);
+			RKComponentMap::invokeComponent (path.left (sep), path.mid (sep+1).split ('\n', RKCommonFunctions::SkipEmptyParts()), RKComponentMap::ManualSubmit);
 		} else if (url.host () == "rhelp") {
 			// TODO: find a nice solution to render this in the current window
 			QStringList spec = url.path ().mid (1).split ('/');
@@ -1352,7 +1352,7 @@ QString RKHelpRenderer::prepareHelpLink (const QString &href, const QString &tex
 QString RKHelpRenderer::componentPathToId (const QString &path) {
 	RK_TRACE (APP);
 
-	QStringList path_segments = path.split ('/', QString::SkipEmptyParts);
+	QStringList path_segments = path.split ('/', RKCommonFunctions::SkipEmptyParts());
 	if (path_segments.count () > 2) return 0;
 	if (path_segments.count () < 1) return 0;
 	if (path_segments.count () == 1) path_segments.push_front ("rkward");
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 082b222a..b008b8e6 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -890,7 +890,7 @@ ItemSpecification parseItemDescription (const QString &description) {
 			RK_ASSERT (false);
 			return ret;
 		}
-		ret.params = description.mid (typeend + 2, specstart - typeend - 2).split (':', QString::SkipEmptyParts);
+		ret.params = description.mid (typeend + 2, specstart - typeend - 2).split (':', RKCommonFunctions::SkipEmptyParts());
 		ret.specification = description.mid (specstart + 2);
 	} else {
 		ret.specification = description.mid (typeend + 1);


More information about the rkward-tracker mailing list