[education/rkward] rkward: Fix display order of factor levels

Thomas Friedrichsmeier null at kde.org
Fri Sep 19 15:45:27 BST 2025


Git commit 50c4bd23b932b70db1b087235ae794ec689d301e by Thomas Friedrichsmeier.
Committed on 19/09/2025 at 14:44.
Pushed by tfry into branch 'master'.

Fix display order of factor levels

BUG: 400755

M  +1    -0    rkward/core/robject.h
M  +5    -5    rkward/misc/celleditor.cpp

https://invent.kde.org/education/rkward/-/commit/50c4bd23b932b70db1b087235ae794ec689d301e

diff --git a/rkward/core/robject.h b/rkward/core/robject.h
index b7cfa16d6..f0e2f0ecf 100644
--- a/rkward/core/robject.h
+++ b/rkward/core/robject.h
@@ -178,6 +178,7 @@ class RObject {
 	/** A QList of RObjects. Internally the same as RObjectMap, but can be considered "public" */
 	typedef QList<RObject *> ObjectList;
 
+	// TODO: review whether we actually need string->string mapping at all, rather than just ordered (integer-indexed) list
 	/** A map of values to labels. This is used both in regular objects, in which it just represents a map of named values, if any. The more important use is in factors, where it represents the factor levels. Here, the key is always a string representation of a positive integer. */
 	typedef QMap<QString, QString> ValueLabels;
 
diff --git a/rkward/misc/celleditor.cpp b/rkward/misc/celleditor.cpp
index 5e018276b..c3d2b3d3d 100644
--- a/rkward/misc/celleditor.cpp
+++ b/rkward/misc/celleditor.cpp
@@ -42,11 +42,11 @@ void CellEditor::setValueLabels(const RObject::ValueLabels &labels) {
 	const int limit = 64;
 	int i = 0;
 	for (RObject::ValueLabels::const_iterator it = labels.constBegin(); it != labels.constEnd(); ++it) {
-		if (++i >= limit) break;
-		value_list->addAction(it.key() + u": "_s + it.value())->setData(it.key());
-	}
-	if (i >= limit) {
-		value_list->addAction(i18n("[Omitted %1 more factor levels]", labels.size() - limit))->setEnabled(false);
+		if (++i >= limit) {
+			value_list->addAction(i18n("[Omitted %1 more factor levels]", labels.size() - limit))->setEnabled(false);
+			break;
+		}
+		value_list->addAction(it.key().rightJustified(2) + u": "_s + it.value())->setData(it.key());
 	}
 	connect(value_list, &QMenu::triggered, this, &CellEditor::selectedFromList);
 


More information about the rkward-tracker mailing list