[education/rkward] rkward: Modernize loops

Thomas Friedrichsmeier null at kde.org
Sun Sep 8 20:42:17 BST 2024


Git commit 1a62c6ffe517cb2029ff9bd356f29bdff1ff365a by Thomas Friedrichsmeier.
Committed on 03/09/2024 at 14:28.
Pushed by tfry into branch 'master'.

Modernize loops

M  +2    -2    rkward/autotests/core_test.cpp
M  +12   -12   rkward/misc/rkrapimenu.cpp

https://invent.kde.org/education/rkward/-/commit/1a62c6ffe517cb2029ff9bd356f29bdff1ff365a

diff --git a/rkward/autotests/core_test.cpp b/rkward/autotests/core_test.cpp
index 645a40394..f634dc51a 100644
--- a/rkward/autotests/core_test.cpp
+++ b/rkward/autotests/core_test.cpp
@@ -534,8 +534,8 @@ private Q_SLOTS:
 	void rkMenuTest() {
 		const QStringList actionpath {"analysis", "myaction"};
 		RInterface::issueCommand(new RCommand("a <- rk.menu()", RCommand::App));
-		for (int i = 0; i < actionpath.size(); ++i) {
-			RInterface::issueCommand(new RCommand("a <- a$item(" + RObject::rQuote(actionpath[i]) + ")", RCommand::App));
+		for (const auto &segment : actionpath) {
+			RInterface::issueCommand(new RCommand("a <- a$item(" + RObject::rQuote(segment) + ")", RCommand::App));
 		}
 		RInterface::issueCommand(new RCommand("a$define('My Label', function() assign('x', 'actionval', envir=globalenv()))", RCommand::User));
 		waitForAllFinished();
diff --git a/rkward/misc/rkrapimenu.cpp b/rkward/misc/rkrapimenu.cpp
index 169100a71..704ff6f80 100644
--- a/rkward/misc/rkrapimenu.cpp
+++ b/rkward/misc/rkrapimenu.cpp
@@ -92,8 +92,8 @@ void RKRApiMenu::makeXML(QDomElement e, const QVariantList &l, const QString &pa
 			t.appendChild(s.ownerDocument().createTextNode(label));
 		}
 		const auto children = getChildlist(l);
-		for (auto it = children.constBegin(); it != children.constEnd(); ++it) {
-			makeXML(s, (*it).toList(), full_id, actionlist);
+		for (const auto &child : children) {
+			makeXML(s, child.toList(), full_id, actionlist);
 		}
 	}
 }
@@ -107,16 +107,16 @@ void RKRApiMenu::commit() {
 	auto r = addChildElement(doc, QStringLiteral("kpartgui"), QStringLiteral("rapi_menu"));
 	auto mb = addChildElement(r,  QStringLiteral("MenuBar"), QString());
 	const auto menus = getChildlist(rep);
-	for (auto it = menus.constBegin(); it != menus.constEnd(); ++it) {
-		auto menu = (*it).toList();
-		if (getId((*it).toList()) == "toolbar") {
+	for (const auto &menu : menus) {
+		const auto menuList = menu.toList();
+		if (getId(menuList) == "toolbar") {
 			auto tb = addChildElement(r, QStringLiteral("ToolBar"), QStringLiteral("mainToolBar"));
-			const auto tb_children = getChildlist(menu);
-			for (auto tbit : tb_children) {
+			const auto tb_children = getChildlist(menuList);
+			for (const auto &tbit : tb_children) {
 				makeXML(tb, tbit.toList(), QStringLiteral("toolbar"), &actionlist);
 			}
 		} else {
-			makeXML(mb, menu, QString(), &actionlist);
+			makeXML(mb, menuList, QString(), &actionlist);
 		}
 	}
 
@@ -126,10 +126,10 @@ void RKRApiMenu::commit() {
 	setXMLGUIBuildDocument(doc);
 
 	// delete any actions that are no longer around
-	auto all_actions = actionCollection()->actions();
-	for (int i = 0; i < all_actions.size(); ++i) {
-		if (!actionlist.contains(all_actions[i]->objectName())) {
-			delete (actionCollection()->takeAction(all_actions[i]));
+	const auto actions = actionCollection()->actions();
+	for (const auto &action : actions) {
+		if (!actionlist.contains(action->objectName())) {
+			delete actionCollection()->takeAction(action);
 		}
 	}
 



More information about the rkward-tracker mailing list