[education/rkward/kf5] rkward: Port all the remaiming foreach usage

Thomas Friedrichsmeier null at kde.org
Wed Apr 10 16:12:08 BST 2024


Git commit e1e308bf7e371c0dabb5eeb6cc35f7443e755bf8 by Thomas Friedrichsmeier, on behalf of Carl Schwan.
Committed on 01/04/2024 at 11:45.
Pushed by tfry into branch 'kf5'.

Port all the remaiming foreach usage

M  +1    -1    rkward/agents/CMakeLists.txt
M  +3    -3    rkward/core/rcontainerobject.cpp
M  +5    -5    rkward/core/rkmodificationtracker.cpp
M  +1    -1    rkward/dialogs/CMakeLists.txt
M  +6    -8    rkward/dialogs/rkloadlibsdialog.cpp
M  +1    -1    rkward/misc/CMakeLists.txt
M  +2    -2    rkward/misc/rkdynamicsearchline.cpp
M  +2    -1    rkward/misc/rkdynamicsearchline.h
M  +10   -10   rkward/plugin/rkcomponent.cpp
M  +3    -3    rkward/plugin/rkcomponentcontext.cpp
M  +1    -1    rkward/plugin/rkmatrixinput.cpp
M  +3    -3    rkward/plugin/rkstandardcomponent.cpp
M  +1    -1    rkward/rbackend/rcommandstack.cpp
M  +8    -15   rkward/rbackend/rkrbackend.cpp
M  +7    -11   rkward/rbackend/rkrbackend.h
M  +5    -5    rkward/rbackend/rkrinterface.cpp
M  +4    -4    rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
M  +1    -1    rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
M  +4    -4    rkward/rkconsole.cpp
M  +4    -3    rkward/rkward.cpp
M  +1    -1    rkward/scriptbackends/qtscriptbackend.cpp
M  +0    -5    rkward/scriptbackends/qtscriptbackend.h
M  +2    -1    rkward/scriptbackends/rkcomponentscripting.cpp
M  +3    -1    rkward/settings/rksettingsmoduleconsole.cpp
M  +4    -4    rkward/settings/rksettingsmoduler.cpp
M  +1    -5    rkward/windows/CMakeLists.txt
M  +7    -4    rkward/windows/detachedwindowcontainer.cpp
M  +4    -9    rkward/windows/rkcommandeditorwindow.cpp
M  +0    -2    rkward/windows/rkcommandeditorwindow.h
M  +4    -9    rkward/windows/rkfilebrowser.cpp
M  +2    -1    rkward/windows/rktoolwindowbar.cpp
M  +4    -2    rkward/windows/rktoplevelwindowgui.cpp
M  +8    -6    rkward/windows/rkworkplace.cpp

https://invent.kde.org/education/rkward/-/commit/e1e308bf7e371c0dabb5eeb6cc35f7443e755bf8

diff --git a/rkward/agents/CMakeLists.txt b/rkward/agents/CMakeLists.txt
index 8020529ba..4a59a2c78 100644
--- a/rkward/agents/CMakeLists.txt
+++ b/rkward/agents/CMakeLists.txt
@@ -18,4 +18,4 @@ SET(agents_STAT_SRCS
    )
 
 ADD_LIBRARY(agents STATIC ${agents_STAT_SRCS})
-TARGET_LINK_LIBRARIES(agents Qt6::Widgets KF6::TextEditor KF6::I18n)
+TARGET_LINK_LIBRARIES(agents Qt6::Widgets KF6::TextEditor KF6::I18n KF6::Service KF6::KIOCore)
diff --git a/rkward/core/rcontainerobject.cpp b/rkward/core/rcontainerobject.cpp
index 774142bcc..1450a1d8a 100644
--- a/rkward/core/rcontainerobject.cpp
+++ b/rkward/core/rcontainerobject.cpp
@@ -6,7 +6,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 */
 #include "rcontainerobject.h"
 
-#include <qregexp.h>
+#include <QRegularExpression>
 
 #include "../rbackend/rkrinterface.h"
 #include "robjectlist.h"
@@ -375,8 +375,8 @@ QString RContainerObject::validizeName (const QString &child_name, bool unique)
 	QString ret = child_name;
 	if (ret.isEmpty ()) ret = "var";
 	else {
-		ret = ret.replace (QRegExp ("[^a-zA-Z0-9_]"), ".");
-		ret = ret.replace (QRegExp ("^\\.*[0-9]+"), ".");
+		ret = ret.replace (QRegularExpression ("[^a-zA-Z0-9_]"), ".");
+		ret = ret.replace (QRegularExpression ("^\\.*[0-9]+"), ".");
 	}
 	if (!unique) return ret;
 
diff --git a/rkward/core/rkmodificationtracker.cpp b/rkward/core/rkmodificationtracker.cpp
index 9086d41cc..8214e91f8 100644
--- a/rkward/core/rkmodificationtracker.cpp
+++ b/rkward/core/rkmodificationtracker.cpp
@@ -56,7 +56,7 @@ bool RKModificationTracker::removeObject (RObject *object, RKEditor *editor, boo
 	if (!object->isPseudoObject ()) {
 		if (removed_in_workspace) {
 			if (ed && (ed->getObject () == object) && object->canWrite ()) {	// NOTE: do not allow restoring of columns in a data.frame this way. See https://mail.kde.org/pipermail/rkward-devel/2012-March/003225.html and replies.
-				if (KMessageBox::questionYesNo (0, i18n ("The object '%1' was removed from workspace or changed to a different type of object, but is currently opened for editing. Do you want to restore it?", object->getFullName ()), i18n ("Restore object?")) == KMessageBox::Yes) {
+				if (KMessageBox::questionTwoActions (0, i18n ("The object '%1' was removed from workspace or changed to a different type of object, but is currently opened for editing. Do you want to restore it?", object->getFullName ()), i18n ("Restore object?"), KStandardGuiItem::ok(), KStandardGuiItem::cancel()) == KMessageBox::PrimaryAction) {
 					ed->restoreObject (object);
 					/* TODO: It would make a lot of sense to allow restoring to a different name, and possibly different location. This may need some thinking. Probably something like:
 					 * 	object->parentObject ()->removeChildNoDelete (parent);
@@ -72,12 +72,12 @@ bool RKModificationTracker::removeObject (RObject *object, RKEditor *editor, boo
 			}
 		} else {
 			if (editor || ed) {
-				if (KMessageBox::questionYesNo (0, i18n ("Do you really want to remove the object '%1'? The object is currently opened for editing, it will be removed in the editor, too. There's no way to get it back.", object->getFullName ()), i18n ("Remove object?")) != KMessageBox::Yes) {
+				if (KMessageBox::questionTwoActions (nullptr, i18n ("Do you really want to remove the object '%1'? The object is currently opened for editing, it will be removed in the editor, too. There's no way to get it back.", object->getFullName ()), i18n ("Remove object?"), KStandardGuiItem::remove(), KStandardGuiItem::cancel()) != KMessageBox::PrimaryAction) {
 					return false;
 				}
 			} else {
 				// TODO: check for other editors editing this object
-				if (KMessageBox::questionYesNo (0, i18n ("Do you really want to remove the object '%1'? There's no way to get it back.", object->getFullName ()), i18n ("Remove object?")) != KMessageBox::Yes) {
+				if (KMessageBox::questionTwoActions (nullptr, i18n ("Do you really want to remove the object '%1'? There's no way to get it back.", object->getFullName ()), i18n ("Remove object?"), KStandardGuiItem::remove(), KStandardGuiItem::cancel()) != KMessageBox::PrimaryAction) {
 					return false;
 				}
 			}
@@ -98,7 +98,7 @@ bool RKModificationTracker::removeObject (RObject *object, RKEditor *editor, boo
 		beginRemoveRows (object_index, object_row, object_row);
 	}
 
-	if (!(updates_locked || object->isPseudoObject ())) sendListenerNotification (RObjectListener::ObjectRemoved, object, 0, 0, 0);
+	if (!(updates_locked || object->isPseudoObject ())) sendListenerNotification (RObjectListener::ObjectRemoved, object, 0, 0, nullptr);
 
 	object->remove (removed_in_workspace);
 
@@ -138,7 +138,7 @@ void RKModificationTracker::renameObject (RObject *object, const QString &new_na
 	object->rename (new_name);
 
 	if (!updates_locked) {
-		sendListenerNotification (RObjectListener::MetaChanged, object, 0, 0, 0);
+		sendListenerNotification (RObjectListener::MetaChanged, object, 0, 0, nullptr);
 
 		QModelIndex object_index = indexFor (object);
 		Q_EMIT dataChanged(object_index, object_index);
diff --git a/rkward/dialogs/CMakeLists.txt b/rkward/dialogs/CMakeLists.txt
index 0801b5748..017be1b4f 100644
--- a/rkward/dialogs/CMakeLists.txt
+++ b/rkward/dialogs/CMakeLists.txt
@@ -17,4 +17,4 @@ SET(dialogs_STAT_SRCS
 
 ADD_DEFINITIONS(-DLIBEXECDIR="${CMAKE_INSTALL_FULL_LIBEXECDIR}")
 ADD_LIBRARY(dialogs STATIC ${dialogs_STAT_SRCS})
-TARGET_LINK_LIBRARIES(dialogs Qt6::Widgets KF6::Parts KF6::ConfigWidgets KF6::TextEditor)
+TARGET_LINK_LIBRARIES(dialogs Qt6::Widgets KF6::Parts KF6::ConfigWidgets KF6::TextEditor KF6::I18n)
diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index 54e475552..0113b0518 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -6,16 +6,14 @@ SPDX-License-Identifier: GPL-2.0-or-later
 */
 #include "rkloadlibsdialog.h"
 
-#include <qwidget.h>
-#include <qlayout.h>
+#include <QLayout>
 #include <QTreeWidget>
-#include <qlabel.h>
-#include <qpushbutton.h>
+#include <QLabel>
+#include <QPushButton>
 #include <qcheckbox.h>
-#include <qdir.h>
-#include <qregexp.h>
-#include <qtimer.h>
-#include <qtextstream.h>
+#include <QDir>
+#include <QTimer>
+#include <QTextStream>
 #include <QCloseEvent>
 #include <QSortFilterProxyModel>
 #include <QApplication>
diff --git a/rkward/misc/CMakeLists.txt b/rkward/misc/CMakeLists.txt
index 6d6ed6f0b..e50026b4e 100644
--- a/rkward/misc/CMakeLists.txt
+++ b/rkward/misc/CMakeLists.txt
@@ -38,4 +38,4 @@ SET(misc_STAT_SRCS
    )
 
 ADD_LIBRARY(misc STATIC ${misc_STAT_SRCS})
-TARGET_LINK_LIBRARIES(misc Qt6::Widgets KF6::WidgetsAddons KF6::KIOWidgets Qt6::Xml KF6::ConfigCore KF6::Parts KF6::WindowSystem KF6::TextEditor KF6::Archive)
+TARGET_LINK_LIBRARIES(misc Qt6::Widgets KF6::WidgetsAddons KF6::KIOWidgets Qt6::Xml KF6::ConfigCore KF6::Parts KF6::WindowSystem KF6::TextEditor KF6::Archive KF6::I18n)
diff --git a/rkward/misc/rkdynamicsearchline.cpp b/rkward/misc/rkdynamicsearchline.cpp
index 391588e14..ed5a8bf4c 100644
--- a/rkward/misc/rkdynamicsearchline.cpp
+++ b/rkward/misc/rkdynamicsearchline.cpp
@@ -58,8 +58,8 @@ void RKDynamicSearchLine::delayedSearch () {
 		}
 	}
 
-	QRegExp filter (term, Qt::CaseInsensitive, allnum ? QRegExp::FixedString : QRegExp::RegExp2);
-	if (model) model->setFilterRegExp (filter);
+	QRegularExpression filter (allnum ? QRegularExpression::escape(term) : term, QRegularExpression::CaseInsensitiveOption);
+	if (model) model->setFilterRegularExpression (filter);
 	removeAction (working_indicator);
 	Q_EMIT searchChanged(filter);
 }
diff --git a/rkward/misc/rkdynamicsearchline.h b/rkward/misc/rkdynamicsearchline.h
index ef876d726..bfd0f81db 100644
--- a/rkward/misc/rkdynamicsearchline.h
+++ b/rkward/misc/rkdynamicsearchline.h
@@ -9,6 +9,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #define RKDYNAMICSEARCHLINE_H
 
 #include <QLineEdit>
+#include <QRegularExpression>
 
 #include <QTimer>
 
@@ -27,7 +28,7 @@ public:
 	void setModelToFilter (QSortFilterProxyModel* _model) { model = _model; };
 	QString regexpTip () const;
 Q_SIGNALS:
-	void searchChanged (const QRegExp& search);
+	void searchChanged (const QRegularExpression& search);
 private Q_SLOTS:
 	void textChanged ();
 	void delayedSearch ();
diff --git a/rkward/plugin/rkcomponent.cpp b/rkward/plugin/rkcomponent.cpp
index a28f26c9c..43042bd20 100644
--- a/rkward/plugin/rkcomponent.cpp
+++ b/rkward/plugin/rkcomponent.cpp
@@ -40,12 +40,12 @@ RKComponentPropertyBase* RKComponentBase::lookupProperty (const QString &identif
 	if (p && p->isProperty ()) {
 		if (!remainder && !p_remainder->isEmpty ()) {
 			if (warn) RK_DEBUG (PLUGIN, DL_ERROR, "Modifier is not allowed, here, while looking up property: %s. (Remainder was %s)", qPrintable (identifier), qPrintable (*p_remainder));
-			return 0;
+			return nullptr;
 		}
 		return static_cast<RKComponentPropertyBase*> (p);
 	}
 	if (warn) RK_DEBUG (PLUGIN, DL_ERROR, "No such property: %s. Remainder was %s", qPrintable (identifier), qPrintable (*p_remainder));
-	return 0;
+	return nullptr;
 }
 
 void RKComponentBase::addChild (const QString &id, RKComponentBase *child) {
@@ -57,7 +57,7 @@ void RKComponentBase::addChild (const QString &id, RKComponentBase *child) {
 void RKComponentBase::fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level, const QString &prefix, bool include_inactive_elements) const {
 	RK_TRACE (PLUGIN);
 
-	for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
+	for (auto it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
 		if (it.key () == "#noid#") continue;
 		if (it.value ()->isInternal ()) continue;
 
@@ -212,9 +212,9 @@ QVariant RKComponentBase::fetchValue (const QString &id, const int hint) {
 			if (!ok) RK_DEBUG (PLUGIN, DL_WARNING, "Could not convert value of %s to boolean", qPrintable (id));
 		} else {
 			if (hint == StringlistValue) {
-				if (val.type () != QVariant::StringList) RK_DEBUG (PLUGIN, DL_WARNING, "Value of %s is not a string list", qPrintable (id));
+				if (val.typeId() != QMetaType::QStringList) RK_DEBUG (PLUGIN, DL_WARNING, "Value of %s is not a string list", qPrintable (id));
 			} else if (hint == NumericValue) {
-				if (!val.canConvert (QVariant::Double)) RK_DEBUG (PLUGIN, DL_WARNING, "Value of %s is not numeric", qPrintable (id));
+				if (!val.canConvert<double>()) RK_DEBUG (PLUGIN, DL_WARNING, "Value of %s is not numeric", qPrintable (id));
 			} else {
 				RK_ASSERT (false);
 			}
@@ -236,7 +236,7 @@ RKComponentBase::ComponentStatus RKComponentBase::recursiveStatus () {
 	bool processing = false;
 	bool children_satisfied = true;
 	// we always need to iterate over all children, since we need to make sure to find any which are dead or processing.
-	for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
+	for (auto it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
 		ComponentStatus s = it.value ()->recursiveStatus ();
 		if (s == Dead) return Dead;
 		if (s == Processing) processing = true;
@@ -314,7 +314,7 @@ void RKComponent::updateEnablednessRecursive (bool parent_enabled) {
 	/* RKComponent hierarchy does not always correspond to QWidget hierarchy (although in _most_ cases, it does. For this reason,
 	 * we need to update enabledness of all child components. */
 	if (changed) {
-		for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
+		for (auto it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
 			if (it.value ()->isComponent()) {
 				static_cast<RKComponent*> (it.value ())->updateEnablednessRecursive (enabled);
 			}
@@ -390,7 +390,7 @@ RKStandardComponent *RKComponent::standardComponent (QString *id_adjust) const {
 		p = p->parentComponent ();
 	}
 	RK_ASSERT (false);
-	return 0;
+	return nullptr;
 }
 
 RKStandardComponent* RKComponent::topmostStandardComponent () {
@@ -401,7 +401,7 @@ RKStandardComponent* RKComponent::topmostStandardComponent () {
 	if (p->type () == RKComponent::ComponentStandard) return static_cast<RKStandardComponent*> (p);
 	// NOTE: currently, *only* standard components can be topmost
 	RK_ASSERT (false);
-	return 0;
+	return nullptr;
 }
 
 XMLHelper* RKComponent::xmlHelper () const {
@@ -418,7 +418,7 @@ void RKComponent::removeFromParent () {
 
 	QString key = getIdInParent ();
 	child_map.remove(key, this);
-	_parent = 0;
+	_parent = nullptr;
 }
 
 QString RKComponent::getIdInParent () const {
diff --git a/rkward/plugin/rkcomponentcontext.cpp b/rkward/plugin/rkcomponentcontext.cpp
index d54564f71..a7b3e857e 100644
--- a/rkward/plugin/rkcomponentcontext.cpp
+++ b/rkward/plugin/rkcomponentcontext.cpp
@@ -55,7 +55,7 @@ void RKContextHandler::componentActionActivated () {
 	RK_TRACE (PLUGIN);
 
 	// find handle that triggered action
-	RKComponentHandle *handle = 0;
+	RKComponentHandle *handle = nullptr;
 	const QAction *action = dynamic_cast<const QAction *> (sender ());
 	if (action_map.contains (action)) handle = action_map[action];
 	if (!handle) {
@@ -71,10 +71,10 @@ void RKContextHandler::invokeComponent (RKComponentHandle *handle) {
 	RK_ASSERT (handle);
 
 	// create component
-	RKComponent *component = handle->invoke (0, 0);
+	RKComponent *component = handle->invoke (nullptr, nullptr);
 
 	// set context values
-	for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
+	for (auto it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
 		if (it.key () != "#noid#") {
 			QString id = it.key ();
 			QString remainder;
diff --git a/rkward/plugin/rkmatrixinput.cpp b/rkward/plugin/rkmatrixinput.cpp
index ff2a3667f..279dcccd8 100644
--- a/rkward/plugin/rkmatrixinput.cpp
+++ b/rkward/plugin/rkmatrixinput.cpp
@@ -120,7 +120,7 @@ QVariant RKMatrixInput::value (const QString& modifier) {
 		return QString ("cbind (\n" + ret.join (",\n") + "\n)");
 	} else if (modifier.startsWith (QLatin1String ("row."))) {
 		bool ok;
-		int row = modifier.midRef(4).toInt(&ok);
+		int row = QStringView(modifier).mid(4).toInt(&ok);
 		if ((row >= 0) && ok) {
 			return (rowStrings (row));
 		}
diff --git a/rkward/plugin/rkstandardcomponent.cpp b/rkward/plugin/rkstandardcomponent.cpp
index 6c4930528..7c9b09384 100644
--- a/rkward/plugin/rkstandardcomponent.cpp
+++ b/rkward/plugin/rkstandardcomponent.cpp
@@ -313,7 +313,7 @@ void RKStandardComponent::discard () {
 	wizard = 0;
 
 	// clear all properties. Not the code property, as the script backend relies on it
-	for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
+	for (auto it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
 		if (it.value () != code) {
 			if (it.value ()->isProperty ()) {
 				static_cast<RKComponentPropertyBase *> (it.value ())->deleteLater ();
@@ -571,7 +571,7 @@ void RKComponentBuilder::buildElement (const QDomElement &element, XMLHelper &xm
 	XMLChildList::const_iterator it;
 	for (it = children.constBegin (); it != children.constEnd (); ++it) {
 		bool add_to_layout = true;
-		RKComponent *widget = 0;
+		RKComponent *widget = nullptr;
 		QDomElement e = *it;		// shorthand
 		QString id = xml.getStringAttribute (e, "id", QString (), DL_INFO);
 
@@ -670,7 +670,7 @@ void RKComponentBuilder::buildElement (const QDomElement &element, XMLHelper &xm
 			RKComponentHandle *handle = RKComponentMap::getComponentHandle (component_id);
 			if (handle) {
 				if (xml.getBoolAttribute (e, "as_button", false, DL_INFO)) {
-					RKStandardComponent* swidget = handle->invoke (component (), 0);
+					RKStandardComponent* swidget = handle->invoke (component (), nullptr);
 					widget = swidget;
 					QString dummy = xml.i18nStringAttribute (e, "label", i18n ("Options"), DL_WARNING);
 					swidget->setCaption (dummy);
diff --git a/rkward/rbackend/rcommandstack.cpp b/rkward/rbackend/rcommandstack.cpp
index 44b5c4b9d..0c923aff7 100644
--- a/rkward/rbackend/rcommandstack.cpp
+++ b/rkward/rbackend/rcommandstack.cpp
@@ -113,7 +113,7 @@ void RCommandStack::listCommandsRecursive (QList<RCommand*> *list, const RComman
 	RK_TRACE (RBACKEND);
 
 	if (chain->is_command) list->append (const_cast<RCommandChain*>(chain)->toCommand ());
-	foreach (const RCommandChain* coc, chain->sub_commands) {
+	for (const RCommandChain* coc : std::as_const(chain->sub_commands)) {
 		listCommandsRecursive (list, coc);
 	}
 }
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index 01dfa9ab9..457eb0593 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -19,15 +19,14 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #endif
 
 // statics
-RKRBackend *RKRBackend::this_pointer = 0;
+RKRBackend *RKRBackend::this_pointer = nullptr;
 RKRBackend::RKReplStatus RKRBackend::repl_status = { QByteArray (), 0, true, 0, 0, RKRBackend::RKReplStatus::NoUserCommand, 0, RKRBackend::RKReplStatus::NotInBrowserContext, false };
-void* RKRBackend::default_global_context = 0;
+void* RKRBackend::default_global_context = nullptr;
 
 #include <qstring.h>
 #include <QStringList>
 #include <QThread>
 #include <QDir>
-#include <qtextcodec.h>
 
 #include "../core/robject.h"
 #include "../version.h"
@@ -140,7 +139,7 @@ void RKRBackend::interruptCommand (int command_id) {
 		}
 	} else {
 		// if the command to cancel is *not* the topmost command, then do not interrupt, yet.
-		foreach (RCommandProxy *candidate, all_current_commands) {
+		for (RCommandProxy *candidate : std::as_const(all_current_commands)) {
 			if (candidate->id == command_id) {
 				if (!current_commands_to_cancel.contains (candidate)) {
 					RK_DEBUG (RBACKEND, DL_DEBUG, "scheduling delayed interrupt for command id %d", command_id);
@@ -918,7 +917,7 @@ void doError (const QString &callstring) {
 			RKRBackend::repl_status.interrupted = false;
 			if (RKRBackend::repl_status.user_command_status != RKRBackend::RKReplStatus::ReplIterationKilled) {	// was interrupted only to step out of the repl iteration
 				QMutexLocker lock (&(RKRBackend::this_pointer->all_current_commands_mutex));
-				foreach (RCommandProxy *command, RKRBackend::this_pointer->all_current_commands) command->status |= RCommand::Canceled;
+				for (RCommandProxy *command : std::as_const(RKRBackend::this_pointer->all_current_commands)) command->status |= RCommand::Canceled;
 				RK_DEBUG (RBACKEND, DL_DEBUG, "interrupted");
 			}
 		}
@@ -1008,15 +1007,9 @@ SEXP doUpdateLocale () {
 	RK_TRACE (RBACKEND);
 
 	RK_DEBUG (RBACKEND, DL_WARNING, "Changing locale");
-	if (RKRBackend::this_pointer->current_locale_encoder) {
-		delete (RKRBackend::this_pointer->current_locale_encoder);
-		delete (RKRBackend::this_pointer->current_locale_decoder);
-		QTextCodec::setCodecForLocale (0);
-	}
-	RK_ASSERT (QTextCodec::codecForLocale ());
-	RKRBackend::this_pointer->current_locale_encoder = QTextCodec::codecForLocale ()->makeEncoder (QTextCodec::DefaultConversion);  // NOTE: shall pass non-representable characters unmodified, rather than stripping them.
-	RKRBackend::this_pointer->current_locale_decoder = QTextCodec::codecForLocale ()->makeDecoder (QTextCodec::DefaultConversion);
-	RK_DEBUG (RBACKEND, DL_WARNING, "New locale codec is %s", QTextCodec::codecForLocale ()->name ().data ());
+	RKRBackend::this_pointer->current_locale_encoder = QStringEncoder(QStringEncoder::System);  // NOTE: shall pass non-representable characters unmodified, rather than stripping them.
+	RKRBackend::this_pointer->current_locale_decoder = QStringDecoder(QStringEncoder::System);
+	RK_DEBUG (RBACKEND, DL_WARNING, "New locale codec is %s", RKRBackend::this_pointer->current_locale_decoder.name());
 
 	return R_NilValue;
 }
@@ -1548,7 +1541,7 @@ void RKRBackend::commandFinished (bool check_object_updates_needed) {
 
 		// This method may look a bit over-complex, but remember that repl_status.user_command_successful_up_to works on an *encoded* buffer
 		QByteArray remainder_encoded = repl_status.user_command_buffer.mid (repl_status.user_command_successful_up_to);
-		QString remainder = RKRBackend::toUtf8 (remainder_encoded);
+		QString remainder = current_locale_decoder(remainder_encoded);
 		current_command->has_been_run_up_to = current_command->command.length () - remainder.length ();
 	}
 
diff --git a/rkward/rbackend/rkrbackend.h b/rkward/rbackend/rkrbackend.h
index e08db5d31..e96858b7b 100644
--- a/rkward/rbackend/rkrbackend.h
+++ b/rkward/rbackend/rkrbackend.h
@@ -12,15 +12,11 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include <QMap>
 #include <QVariant>
-#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
-#	include <QRecursiveMutex>
-#else
-#	include <QMutex>
-#endif
+#include <QRecursiveMutex>
 #include <QStringList>
+#include <QStringEncoder>
+#include <QStringDecoder>
 #include <QEvent>
-#include <QTextEncoder>
-#include <QTextDecoder>
 
 #include "rcommand.h"
 #include "rcommandstack.h"
@@ -134,13 +130,13 @@ handleHistoricalSubstackRequest(). Exactly which requests get handled by which f
 	bool isKilled () { return (killed != NotKilled); };
 
 	static QString toUtf8 (const char *local_coded) {
-		return this_pointer->current_locale_decoder->toUnicode (local_coded);
+		return this_pointer->current_locale_decoder(local_coded);
 	}
 	static QByteArray fromUtf8 (const QString &uni_coded) {
-		return this_pointer->current_locale_encoder->fromUnicode (uni_coded);
+		return this_pointer->current_locale_encoder(uni_coded);
 	}
-	QTextEncoder *current_locale_encoder;
-	QTextDecoder *current_locale_decoder;
+	QStringEncoder current_locale_encoder;
+	QStringDecoder current_locale_decoder;
 
 	struct RKReplStatus {
 		QByteArray user_command_buffer;
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index f05d404ec..849044a14 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -452,7 +452,7 @@ void RInterface::timerEvent (QTimerEvent *) {
 void RInterface::flushOutput (bool forced) {
 // do not trace. called periodically
 //	RK_TRACE (RBACKEND);
-	ROutputList list = RKRBackendProtocolFrontend::instance ()->flushOutput (forced);
+	const ROutputList list = RKRBackendProtocolFrontend::instance ()->flushOutput (forced);
 
 	// this must come _after_ the output has been flushed.
 	if (forced || !list.isEmpty ()) {
@@ -462,7 +462,7 @@ void RInterface::flushOutput (bool forced) {
 		}
 	}
 
-	foreach (ROutput *output, list) {
+	for (ROutput *output, list) {
 		if (all_current_commands.isEmpty ()) {
 			RK_DEBUG (RBACKEND, DL_DEBUG, "output without receiver'%s'", qPrintable (output->output));
 			if (RKConsole::mainConsole()) RKConsole::mainConsole()->insertSpontaneousROutput(output);  // the "if" is to prevent crash, should output arrive during exit
@@ -473,7 +473,7 @@ void RInterface::flushOutput (bool forced) {
 		}
 
 		bool first = true;
-		foreach (RCommand* command, all_current_commands) {
+		for (RCommand* command : std::as_const(all_current_commands)) {
 			ROutput *coutput = output;
 			if (!first) {		// this output belongs to several commands at once. So we need to copy it.
 				coutput = new ROutput;
@@ -536,8 +536,8 @@ void RInterface::closeChain(RCommandChain *chain) {
 void RInterface::cancelAll () {
 	RK_TRACE (RBACKEND);
 
-	QList<RCommand*> all_commands = RCommandStack::regular_stack->allCommands ();
-	foreach (RCommand* command, all_commands) cancelCommand (command);
+	const QList<RCommand*> all_commands = RCommandStack::regular_stack->allCommands ();
+	for (RCommand* command : all_commands) cancelCommand (command);
 }
 
 bool RInterface::softCancelCommand (RCommand* command) {
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
index 26510d152..5d9ff19c6 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
@@ -10,7 +10,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <QHBoxLayout>
 #include <QMouseEvent>
 #include <QDialog>
-#include <QMatrix4x4>
+#include <QTransform>
 #include <QFontMetricsF>
 
 #include <KLocalizedString>
@@ -165,7 +165,7 @@ int RKGraphicsDevice::finalizeTilingPattern(int extend) {
 
 void RKGraphicsDevice::viewKilled () {
 	RK_TRACE (GRAPHICS_DEVICE);
-	view = 0;
+	view = nullptr;
 //	closeDevice(devices.key(this));  // Do not do this, here. Don't mark the device as dead until R thinks so, too, and tells us about it.
 }
 
@@ -473,7 +473,7 @@ void RKGraphicsDevice::text(double x, double y, const QString& text, double rot,
 		QPainterPath sub;
 		QSizeF size = strSize(text, font);
 		sub.addText(-(hadj * size.width()), 0, font, text);
-		QMatrix4x4 trans;
+		QTransform trans;
 		trans.translate(x, y);
 		trans.rotate(-rot);
 		recorded_path.addPath(trans.map(sub));
@@ -503,7 +503,7 @@ void RKGraphicsDevice::metricInfo (const QChar& c, const QFont& font, double* as
 	QRectF rect = fm.boundingRect (c);
 	*ascent = -rect.top ();
 	*descent = rect.bottom ();
-	*width = fm.width (c);
+	*width = fm.horizontalAdvance (c);
 }
 
 void RKGraphicsDevice::polygon (const QPolygonF& pol, const QPen& pen, const QBrush& brush) {
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
index 8ce219004..505f9d7e0 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
@@ -596,7 +596,7 @@ void RKD_EventHelper (pDevDesc dev, int code) {
 		else if (keycode == Qt::Key_Insert) r_key_name = knINS;
 		else if (keycode == Qt::Key_Delete) r_key_name = knDEL;
 
-		Rf_doKeybd (dev, r_key_name, text.toUtf8 ());
+		Rf_doKeybd (dev, r_key_name, text.toUtf8 ().data());
 	} else {    // all others are mouse events
 		Rf_doMouseEvent (dev, event_code == RKDMouseDown ? meMouseDown : (event_code == RKDMouseUp ? meMouseUp : meMouseMove), buttons, x, y);
 	}
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 7079cac13..ed3b5afe1 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -178,8 +178,8 @@ QAction* RKConsole::addProxyAction (const QString& actionName, const QString& la
 	QList<KActionCollection*> acs = view->findChildren<KActionCollection*>();
 	acs.append (view->actionCollection ());
 
-	QAction* found = 0;
-	foreach (KActionCollection* ac, acs) {
+	QAction* found = nullptr;
+	for (KActionCollection* ac : std::as_const(acs)) {
 		found = ac->action (actionName);
 		if (found) break;
 	}
@@ -761,8 +761,8 @@ QString RKConsole::cleanSelection (const QString &origin) {
 
 	QString ret;
 	ret.reserve (origin.length ());
-	QStringList lines = origin.split ('\n');
-	foreach (const QString& line, lines) {
+	cosnt QStringList lines = origin.split ('\n');
+	for (const QString& line : lines) {
 		if (line.startsWith(nprefix)) {
 			ret.append(line.midRef(nprefix.length()));
 		} else if (line.startsWith(iprefix)) {
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 758892b4e..4216ab1b8 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -670,7 +670,7 @@ void RKWardMainWindow::initActions() {
 // debug code: prints out all current actions
 void printActionsRecursive (QAction* action, const QString &prefix) {
 	if (action->menu ()) {
-		foreach (QAction *a, action->menu ()->actions ()) printActionsRecursive (a, prefix + action->text () + "->");
+		for (QAction *a : action->menu ()->actions ()) printActionsRecursive (a, prefix + action->text () + "->");
 	} else {
 		qDebug ("%s", qPrintable (prefix + action->text ()));
 	}
@@ -703,7 +703,8 @@ void RKWardMainWindow::partChanged(KParts::Part *part) {
 	if (gui_rebuild_locked) return;
 	if (!part) return;
 	createGUI(part);
-	foreach (QAction *a, actions()) {
+	const auto actionsList = actions();
+	for (QAction *a : actionsList) {
 		if (a->statusTip().isEmpty()) a->setStatusTip(a->whatsThis());
 	}
 
@@ -741,7 +742,7 @@ void RKWardMainWindow::partChanged(KParts::Part *part) {
 	}
 /*
 	// debug code: prints out all current actions
-	foreach (QAction *action, menuBar ()->actions ()) printActionsRecursive (action, QString ());
+	for (QAction *action : menuBar ()->actions ()) printActionsRecursive (action, QString ());
 */
 }
 
diff --git a/rkward/scriptbackends/qtscriptbackend.cpp b/rkward/scriptbackends/qtscriptbackend.cpp
index 3e77f4591..e613130f2 100644
--- a/rkward/scriptbackends/qtscriptbackend.cpp
+++ b/rkward/scriptbackends/qtscriptbackend.cpp
@@ -136,7 +136,7 @@ void QtScriptBackend::threadError (const QString &message) {
 
 	if (dead) return;	// we are already dead, so we've shown an error before.
 
-	KMessageBox::error (0, i18n ("The QtScript-backend has reported an error:\n%1", message), i18n ("Scripting error"));
+	KMessageBox::error (nullptr, i18n ("The QtScript-backend has reported an error:\n%1", message), i18n ("Scripting error"));
 
 	Q_EMIT haveError();
 	destroy ();
diff --git a/rkward/scriptbackends/qtscriptbackend.h b/rkward/scriptbackends/qtscriptbackend.h
index 17a683dfc..6cead860f 100644
--- a/rkward/scriptbackends/qtscriptbackend.h
+++ b/rkward/scriptbackends/qtscriptbackend.h
@@ -56,11 +56,6 @@ private:
 #include <QMutex>
 #include <QtQml/QJSEngine>
 
-template<typename T> QJSValue rkJSMakeArray(QJSEngine *engine, QVector<T> list) {
-	auto ret = engine->newArray(list.size());
-	for(int i = 0; i < list.size(); ++i) ret.setProperty(i, list.at(i));
-	return ret;
-}
 template<typename T> QJSValue rkJSMakeArray(QJSEngine *engine, QList<T> list) {
 	auto ret = engine->newArray(list.size());
 	for(int i = 0; i < list.size(); ++i) ret.setProperty(i, list.at(i));
diff --git a/rkward/scriptbackends/rkcomponentscripting.cpp b/rkward/scriptbackends/rkcomponentscripting.cpp
index 6956cfa22..f5460d427 100644
--- a/rkward/scriptbackends/rkcomponentscripting.cpp
+++ b/rkward/scriptbackends/rkcomponentscripting.cpp
@@ -265,7 +265,8 @@ QVariantList RKComponentScriptingProxy::getObjectInfo (const QString &name) {
 		QVariantList ret;
 
 		QVariantList dims;
-		foreach (int dim, object->getDimensions ()) {
+		const auto objectDims = object->getDimensions ();
+		for (int dim : objectDims) {
 			dims.append (dim);
 		}
 		ret.append (QVariant (dims));
diff --git a/rkward/settings/rksettingsmoduleconsole.cpp b/rkward/settings/rksettingsmoduleconsole.cpp
index 1fdab236b..dc630b3b6 100644
--- a/rkward/settings/rksettingsmoduleconsole.cpp
+++ b/rkward/settings/rksettingsmoduleconsole.cpp
@@ -62,7 +62,9 @@ RKSettingsModuleConsole::RKSettingsModuleConsole (RKSettings *gui, QWidget *pare
 		{{(int) DontAdd, i18n("Do not add")}, {(int) AddSingleLine, i18n("Add only if single line")}, {(int) AlwaysAdd, i18n("Add all commands")}}
 	), this);
 	add_piped_commands_to_history_box->setEnabled(pipe_user_commands_through_console_box->isChecked());
-	connect(pipe_user_commands_through_console_box, &QCheckBox::stateChanged, add_piped_commands_to_history_box, &QCheckBox::setEnabled);
+	connect(pipe_user_commands_through_console_box, &QCheckBox::stateChanged, add_piped_commands_to_history_box, [add_piped_commands_to_history_box](int state) {
+		add_piped_commands_to_history_box->setEnabled(state);
+	});
 	vbox->addWidget (add_piped_commands_to_history_box);
 
 	vbox->addSpacing (2*RKStyle::spacingHint ());
diff --git a/rkward/settings/rksettingsmoduler.cpp b/rkward/settings/rksettingsmoduler.cpp
index ccb378bcc..53c277f1b 100755
--- a/rkward/settings/rksettingsmoduler.cpp
+++ b/rkward/settings/rksettingsmoduler.cpp
@@ -478,8 +478,8 @@ QString RKSettingsModuleRPackages::libLocsCommand () {
 	if (!liblocs.get().isEmpty()) {
 		bool first = true;
 		command = "local({\naddpaths <- unique (c(";
-		QStringList ll = expandLibLocs(liblocs);
-		foreach (const QString& libloc, ll) {
+		const QStringList ll = expandLibLocs(liblocs);
+		for (const QString& libloc : ll) {
 			if (first) first = false;
 			else command.append (", ");
 			command.append (RObject::rQuote (libloc));
@@ -490,8 +490,8 @@ QString RKSettingsModuleRPackages::libLocsCommand () {
 	// For add library locations set "the R way", try to interfere as little as possible.
 	command.append(".libPaths (unique (c (");
 	bool first = true;
-	QStringList ll = libraryLocations ();
-	foreach (const QString& libloc, ll) {
+	const QStringList ll = libraryLocations ();
+	for (const QString& libloc : ll) {
 		if (first) first = false;
 		else command.append (", ");
 		command.append (RObject::rQuote (libloc));
diff --git a/rkward/windows/CMakeLists.txt b/rkward/windows/CMakeLists.txt
index 6f13d5b02..d165c6f13 100644
--- a/rkward/windows/CMakeLists.txt
+++ b/rkward/windows/CMakeLists.txt
@@ -31,8 +31,4 @@ SET(windows_STAT_SRCS
 )
 
 ADD_LIBRARY(windows STATIC ${windows_STAT_SRCS})
-IF(NO_QT_WEBENGINE)
-TARGET_LINK_LIBRARIES(windows Qt6::Widgets Qt6::Xml Qt6::PrintSupport Qt6::WebKitWidgets KF6::WebKit KF6::TextEditor KF6::Notifications KF6::WindowSystem KF6::KIOFileWidgets)
-ELSE(NO_QT_WEBENGINE)
-TARGET_LINK_LIBRARIES(windows Qt6::Widgets Qt6::Xml Qt6::PrintSupport Qt6::WebEngineWidgets KF6::TextEditor KF6::Notifications KF6::WindowSystem KF6::KIOFileWidgets)
-ENDIF(NO_QT_WEBENGINE)
+TARGET_LINK_LIBRARIES(windows Qt6::Widgets Qt6::Xml Qt6::PrintSupport Qt6::WebEngineWidgets KF6::TextEditor KF6::Notifications KF6::WindowSystem KF6::KIOFileWidgets KF6::I18n)
diff --git a/rkward/windows/detachedwindowcontainer.cpp b/rkward/windows/detachedwindowcontainer.cpp
index 69781a1ea..002b3c90f 100644
--- a/rkward/windows/detachedwindowcontainer.cpp
+++ b/rkward/windows/detachedwindowcontainer.cpp
@@ -46,7 +46,8 @@ DetachedWindowContainer::DetachedWindowContainer (RKMDIWindow *widget_to_capture
 
 // copy main window toolbar settings
 	QMap<QString, Qt::ToolButtonStyle> main_window_toolbar_styles;
-	foreach (KToolBar *bar, RKWardMainWindow::getMain ()->toolBars ()) {
+	const auto toolbars = RKWardMainWindow::getMain ()->toolBars ();
+	for (KToolBar *bar : toolbars) {
 		main_window_toolbar_styles.insert (bar->objectName (), bar->toolButtonStyle ());
 	}
 
@@ -71,7 +72,8 @@ DetachedWindowContainer::DetachedWindowContainer (RKMDIWindow *widget_to_capture
 	captured = widget_to_capture;
 	// Special case for graph windows: We don't want to touch their default size before showing. So tell the toolbars to step back, if needed.
 	if (widget_to_capture->isType(RKMDIWindow::X11Window)) {
-		foreach (KToolBar *bar, toolBars()) {
+		const auto bars = toolBars();
+		for (KToolBar *bar : bars) {
 			bar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
 		}
 	}
@@ -81,7 +83,8 @@ DetachedWindowContainer::DetachedWindowContainer (RKMDIWindow *widget_to_capture
 	connect (guiFactory (), &KXMLGUIFactory::makingChanges, this, &DetachedWindowContainer::hideEmptyMenus);
 
 // sanitize toolbars
-	foreach (KToolBar *bar, toolBars ()) {
+	const auto bars = toolBars();
+	for (KToolBar *bar : bars) {
 		if (main_window_toolbar_styles.contains (bar->objectName ())) {
 			bar->setToolButtonStyle (main_window_toolbar_styles[bar->objectName ()]);
 		} else {
@@ -106,7 +109,7 @@ void DetachedWindowContainer::hideEmptyMenus (bool ignore) {
 	// remove empty menus (we had to define them in detachedwindowcontainer.rc in order to force a sane menu order)
 	QStringList menu_names;
 	menu_names << "file" << "device" << "history" << "edit" << "run" << "view" << "settings";
-	foreach (const QString& name, menu_names) {
+	for (const QString& name : std::as_const(menu_names)) {
 		QMenu* menu = dynamic_cast<QMenu*>(guiFactory ()->container (name, this));
 		if (menu) menu->menuAction ()->setVisible (!menu->isEmpty ());
 	}
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 72ca4daf4..0d3f61a7e 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -282,9 +282,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl &_url,
 		}
 	}
 
-	smart_iface = qobject_cast<KTextEditor::MovingInterface*> (m_doc);
 	initBlocks ();
-	RK_ASSERT (smart_iface);
 
 	connect (&autosave_timer, &QTimer::timeout, this, &RKCommandEditorWindow::doAutoSave);
 	connect (&preview_timer, &QTimer::timeout, this, &RKCommandEditorWindow::doRenderPreview);
@@ -348,7 +346,7 @@ QAction *findAction (KTextEditor::View* view, const QString &actionName) {
 	QList<KActionCollection*> acs = view->findChildren<KActionCollection*>();
 	acs.append (view->actionCollection ());
 
-	foreach (KActionCollection* ac, acs) {
+	for (KActionCollection* ac : std::as_const(acs)) {
 		QAction* found = ac->action (actionName);
 		if (found) return found;
 	}
@@ -436,7 +434,6 @@ void RKCommandEditorWindow::initializeActions (KActionCollection* ac) {
 
 void RKCommandEditorWindow::initBlocks () {
 	RK_TRACE (COMMANDEDITOR);
-	if (!smart_iface) return;	// may happen in KDE => 4.6 if compiled with KDE <= 4.4
 	RK_ASSERT (block_records.isEmpty ());
 
 	KActionCollection* ac = getPart ()->actionCollection ();
@@ -1045,13 +1042,12 @@ void RKCommandEditorWindow::clearUnusedBlocks () {
 
 void RKCommandEditorWindow::addBlock (int index, const KTextEditor::Range& range) {
 	RK_TRACE (COMMANDEDITOR);
-	if (!smart_iface) return;	// may happen in KDE => 4.6 if compiled with KDE <= 4.4
 	RK_ASSERT ((index >= 0) && (index < block_records.size ()));
 
 	clearUnusedBlocks ();
 	removeBlock (index);
 
-	KTextEditor::MovingRange* srange = smart_iface->newMovingRange (range);
+	KTextEditor::MovingRange* srange = doc->newMovingRange (range);
 	srange->setInsertBehaviors (KTextEditor::MovingRange::ExpandRight);
 
 	QString actiontext = i18n ("%1 (Active)", index + 1);
@@ -1067,7 +1063,6 @@ void RKCommandEditorWindow::addBlock (int index, const KTextEditor::Range& range
 
 void RKCommandEditorWindow::removeBlock (int index, bool was_deleted) {
 	RK_TRACE (COMMANDEDITOR);
-	if (!smart_iface) return;	// may happen in KDE => 4.6 if compiled with KDE <= 4.4
 	RK_ASSERT ((index >= 0) && (index < block_records.size ()));
 
 	if (!was_deleted) {
@@ -1196,7 +1191,7 @@ QString RKCommandHighlighter::commandToHTML (const QString &r_command, Highlight
 	for (int i = 0; i < doc->lines (); ++i)
 	{
 		const QString &line = doc->line(i);
-		QList<KTextEditor::AttributeBlock> attribs = view->lineAttributes(i);
+		const QList<KTextEditor::AttributeBlock> attribs = view->lineAttributes(i);
 		int lineStart = 0;
 
 		if (mode == RInteractiveSession) {
@@ -1220,7 +1215,7 @@ QString RKCommandHighlighter::commandToHTML (const QString &r_command, Highlight
 
 		int handledUntil = lineStart;
 		int remainingChars = line.length();
-		foreach ( const KTextEditor::AttributeBlock& block, attribs ) {
+		for ( const KTextEditor::AttributeBlock& block : attribs ) {
 			if ((block.start + block.length) <= handledUntil) continue;
 			int start = qMax(block.start, lineStart);
 			if ( start > handledUntil ) {
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 58f886b48..ad5921d59 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -15,7 +15,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <ktexteditor/view.h>
 #include <ktexteditor/document.h>
 #include <ktexteditor/movingrange.h>
-#include <ktexteditor/movinginterface.h>
 
 #include <QUrl>
 
@@ -165,7 +164,6 @@ private:
 	KTextEditor::Cursor saved_scroll_position;
 	KTextEditor::Document *m_doc;
 	KTextEditor::View *m_view;
-	KTextEditor::MovingInterface *smart_iface;
 
 	void initializeActions (KActionCollection* ac);
 
diff --git a/rkward/windows/rkfilebrowser.cpp b/rkward/windows/rkfilebrowser.cpp
index 9f532fe52..a6256183e 100644
--- a/rkward/windows/rkfilebrowser.cpp
+++ b/rkward/windows/rkfilebrowser.cpp
@@ -185,8 +185,8 @@ void RKFileBrowserWidget::contextMenuHook(const KFileItem& item, QMenu* menu) {
 	// some versions of KDE appear to re-use the actions, others don't, and yet other are just plain broken (see this thread: https://mail.kde.org/pipermail/rkward-devel/2011-March/002770.html)
 	// Therefore, we remove all actions, explicitly, each time the menu is shown, then add them again.
 	QList<QAction*> menu_actions = menu->actions ();
-	QAction *first_sep = 0;
-	foreach (QAction* act, menu_actions) {
+	QAction *first_sep = nullptr;
+	for (QAction* act : std::as_const(menu_actions)) {
 		if (added_service_actions.contains (act)) menu->removeAction (act);
 		if (!first_sep && act->isSeparator ()) first_sep = act;
 	}
@@ -194,16 +194,11 @@ void RKFileBrowserWidget::contextMenuHook(const KFileItem& item, QMenu* menu) {
 	menu_actions = menu->actions ();
 
 	menu->insertAction (first_sep, rename_action);
-#if KIO_VERSION >= QT_VERSION_CHECK(5,82,0)
 	fi_actions->insertOpenWithActionsTo(nullptr, menu, QStringList());
 	fi_actions->addActionsTo(menu);
-#else
-	fi_actions->addOpenWithActionsTo (menu, QString ());
-	fi_actions->addServiceActionsTo (menu);
-#endif
 
-	QList<QAction*> menu_actions_after = menu->actions ();
-	foreach (QAction* act, menu_actions_after) if (!menu_actions.contains (act)) added_service_actions.append (act);
+	const QList<QAction*> menu_actions_after = menu->actions ();
+	for (QAction* act : menu_actions_after) if (!menu_actions.contains (act)) added_service_actions.append (act);
 }
 
 // does not work in d-tor. Apparently it's too late, then
diff --git a/rkward/windows/rktoolwindowbar.cpp b/rkward/windows/rktoolwindowbar.cpp
index 461f3896e..85160c177 100644
--- a/rkward/windows/rktoolwindowbar.cpp
+++ b/rkward/windows/rktoolwindowbar.cpp
@@ -326,7 +326,8 @@ void RKToolWindowBar::contextMenuEvent (QContextMenuEvent* event) {
 	RK_TRACE (APP);
 
 	QMenu menu (this);
-	foreach (const RKToolWindowList::ToolWindowRepresentation& rep, RKToolWindowList::registeredToolWindows ()) {
+	const auto windows = RKToolWindowList::registeredToolWindows ();
+	for (const RKToolWindowList::ToolWindowRepresentation& rep : windows) {
 		QAction *a = menu.addAction (rep.window->windowIcon (), rep.window->shortCaption ());
 		a->setCheckable (true);
 		a->setChecked (rep.window->tool_window_bar == this);
diff --git a/rkward/windows/rktoplevelwindowgui.cpp b/rkward/windows/rktoplevelwindowgui.cpp
index 0be526c4a..32df30964 100644
--- a/rkward/windows/rktoplevelwindowgui.cpp
+++ b/rkward/windows/rktoplevelwindowgui.cpp
@@ -127,7 +127,8 @@ void RKTopLevelWindowGUI::initToolWindowActions () {
 		ref = ref.nextSiblingElement (action_tag);
 	}
 	QAction *action;
-	foreach (const RKToolWindowList::ToolWindowRepresentation& rep, RKToolWindowList::registeredToolWindows ()) {
+	const auto windows = RKToolWindowList::registeredToolWindows ();
+	for (const RKToolWindowList::ToolWindowRepresentation& rep : windows) {
 		QString id = QLatin1String ("window_show_") + rep.id;
 		action = actionCollection ()->addAction (id, this, SLOT (toggleToolView()));
 		action->setText (i18n ("Show/Hide %1", rep.window->shortCaption ()));
@@ -147,7 +148,8 @@ void RKTopLevelWindowGUI::configureShortcuts () {
 	KMessageBox::information (for_window, i18n ("For technical reasons, the following dialog allows you to configure the keyboard shortcuts only for those parts of RKWard that are currently active.\n\nTherefore, if you want to configure keyboard shortcuts e.g. for use inside the script editor, you need to open a script editor window, and activate it."), i18n ("Note"), "configure_shortcuts_kparts");
 
 	KShortcutsDialog dlg (KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, qobject_cast<QWidget*> (parent()));
-	foreach (KXMLGUIClient *client, factory ()->clients ()) {
+	const auto clients = factory ()->clients ();
+	for (KXMLGUIClient *client : clients) {
 		if (client && !client->xmlFile ().isEmpty ()) dlg.addCollection (client->actionCollection());
 	}
 	dlg.addCollection (RKComponentMap::getMap ()->actionCollection (), i18n ("RKWard Plugins"));
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index c65725453..a259e4271 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -314,7 +314,8 @@ void RKWorkplace::addWindow (RKMDIWindow *window, bool attached) {
 void RKWorkplace::placeToolWindows() {
 	RK_TRACE (APP);
 
-	foreach (const RKToolWindowList::ToolWindowRepresentation& rep, RKToolWindowList::registeredToolWindows ()) {
+	const auto windows = RKToolWindowList::registeredToolWindows ();
+	for (const RKToolWindowList::ToolWindowRepresentation& rep : windows) {
 		placeInToolWindowBar (rep.window, rep.default_placement);
 	}
 }
@@ -640,7 +641,8 @@ RKEditor *RKWorkplace::editObject (RObject *object) {
 
 	if (!ed) {
 		unsigned long size = 1;
-		foreach (int dim, iobj->getDimensions ()) {
+		const auto objDims = iobj->getDimensions ();
+		for (int dim, objDims) {
 			size *= dim;
 		}
 		if ((RKSettingsModuleGeneral::warnLargeObjectThreshold () != 0) && (size > RKSettingsModuleGeneral::warnLargeObjectThreshold ())) {
@@ -952,8 +954,8 @@ QStringList RKWorkplace::makeWorkplaceDescription () {
 	if (base_url.isLocalFile () && !base_url.isEmpty ()) workplace_description.append ("base::::" + base_url.url ());
 
 	// window order in the workplace view may have changed with respect to our list. Thus we first generate a properly sorted list
-	RKWorkplaceObjectList list = getObjectList (RKMDIWindow::DocumentWindow, RKMDIWindow::Detached);
-	foreach (RKMDIWindow *win, list) {
+	const RKWorkplaceObjectList list = getObjectList (RKMDIWindow::DocumentWindow, RKMDIWindow::Detached);
+	for (RKMDIWindow *win : list) {
 		QString desc = makeItemDescription (win);
 		if (!desc.isEmpty ()) workplace_description.append (desc);
 	}
@@ -961,8 +963,8 @@ QStringList RKWorkplace::makeWorkplaceDescription () {
 	workplace_description.append (QStringLiteral ("layout::::") + wview->listLayout ());
 	workplace_description.append (wview->listContents ());
 
-	list = getObjectList (RKMDIWindow::ToolWindow, RKMDIWindow::AnyWindowState);
-	foreach (RKMDIWindow *win, list) {
+	const auto objectList = getObjectList (RKMDIWindow::ToolWindow, RKMDIWindow::AnyWindowState);
+	for (RKMDIWindow *win : objectList) {
 		QString desc = makeItemDescription (win);
 		if (!desc.isEmpty ()) workplace_description.append (desc);
 	}



More information about the rkward-tracker mailing list