[education/rkward] rkward: Small cleanup

Thomas Friedrichsmeier null at kde.org
Fri Oct 3 09:33:05 BST 2025


Git commit 8d1e212d851c24c33e00dd2845603d5b950ea518 by Thomas Friedrichsmeier.
Committed on 03/10/2025 at 08:32.
Pushed by tfry into branch 'master'.

Small cleanup

M  +5    -7    rkward/core/rkvariable.cpp
M  +1    -1    rkward/core/rkvariable.h
M  +2    -1    rkward/dataeditor/rktextmatrix.cpp
M  +3    -4    rkward/dataeditor/rktextmatrix.h
M  +6    -11   rkward/dataeditor/rkvareditmodel.cpp
M  +1    -1    rkward/misc/rkprogresscontrol.cpp

https://invent.kde.org/education/rkward/-/commit/8d1e212d851c24c33e00dd2845603d5b950ea518

diff --git a/rkward/core/rkvariable.cpp b/rkward/core/rkvariable.cpp
index 2c1cd5ed0..94c2612ad 100644
--- a/rkward/core/rkvariable.cpp
+++ b/rkward/core/rkvariable.cpp
@@ -589,20 +589,18 @@ void RKVariable::setNumericFromR(int from_row, int to_row, const QVector<double>
 	cellsChanged(from_row, to_row);
 }
 
-QString *RKVariable::getCharacter(int from_row, int to_row) const {
+QStringList RKVariable::getCharacter(int from_row, int to_row) const {
 	RK_TRACE(OBJECTS);
 	if (to_row >= getLength()) {
 		RK_ASSERT(false);
-		return nullptr;
+		return QStringList();
 	}
 	RK_ASSERT(from_row <= to_row);
 
-	QString *ret = new QString[(to_row - from_row) + 1];
-
-	int i = 0;
+	QStringList ret;
+	ret.reserve((to_row - from_row) + 1);
 	for (int row = from_row; row <= to_row; ++row) {
-		ret[i] = getText(row);
-		i++;
+		ret.append(getText(row));
 	}
 
 	return ret;
diff --git a/rkward/core/rkvariable.h b/rkward/core/rkvariable.h
index a945f3d2d..0159463a4 100644
--- a/rkward/core/rkvariable.h
+++ b/rkward/core/rkvariable.h
@@ -63,7 +63,7 @@ class RKVariable : public RObject {
 	virtual void setText(int row, const QString &text);
 
 	/** get a copy of the text values of rows from from_index to to_index. TODO: This could be made, but currently is not, more efficient than calling getText in a loop. */
-	QString *getCharacter(int from_row, int to_row) const;
+	QStringList getCharacter(int from_row, int to_row) const;
 
 	/** returns the current status of the given cell */
 	Status cellStatus(int row) const;
diff --git a/rkward/dataeditor/rktextmatrix.cpp b/rkward/dataeditor/rktextmatrix.cpp
index 3e32f441e..813fc217f 100644
--- a/rkward/dataeditor/rktextmatrix.cpp
+++ b/rkward/dataeditor/rktextmatrix.cpp
@@ -117,9 +117,10 @@ void RKTextMatrix::setText(int row, int col, const QString &text) {
 	rows[row][col] = text;
 }
 
-void RKTextMatrix::setColumn(int column, const QString *textarray, int length) {
+void RKTextMatrix::setColumn(int column, const QStringList &textarray) {
 	RK_TRACE(EDITOR);
 
+	const int length = textarray.length();
 	upsize(length - 1, column);
 	for (int i = 0; i < length; ++i) {
 		rows[i][column] = textarray[i];
diff --git a/rkward/dataeditor/rktextmatrix.h b/rkward/dataeditor/rktextmatrix.h
index 86bd149f2..538cea2b7 100644
--- a/rkward/dataeditor/rktextmatrix.h
+++ b/rkward/dataeditor/rktextmatrix.h
@@ -27,9 +27,8 @@ class RKTextMatrix {
 	void copyToClipboard() const;
 
 	void setText(int row, int col, const QString &text);
-	/** set an entire column at once. This takes a copy of the data, so you will still have to delete it when done.
-	TODO: convert to using QStringList */
-	void setColumn(int column, const QString *textarray, int length);
+	/** set an entire column at once */
+	void setColumn(int column, const QStringList &textarray);
 	/** set an entire row at once. */
 	void appendRow(const QStringList &row);
 
@@ -54,7 +53,7 @@ class RKTextMatrix {
   private:
 	QList<QStringList> rows;
 
-	inline void upsize(int newmaxrow, int newmaxcol);
+	void upsize(int newmaxrow, int newmaxcol);
 
 	int colcount;
 };
diff --git a/rkward/dataeditor/rkvareditmodel.cpp b/rkward/dataeditor/rkvareditmodel.cpp
index 3cf3395e9..b8f7d00f1 100644
--- a/rkward/dataeditor/rkvareditmodel.cpp
+++ b/rkward/dataeditor/rkvareditmodel.cpp
@@ -371,20 +371,15 @@ RKTextMatrix RKVarEditModel::getTextMatrix(const QItemSelectionRange &range) con
 	if ((!range.isValid()) || objects.isEmpty()) return RKTextMatrix();
 
 	// NOTE: of course, when the range is small, this is terribly inefficient. On the other hand, it doesn't really matter, then, either.
-	QItemSelectionRange erange = range.intersected(QItemSelectionRange(index(0, 0), index(trueRows() - 1, trueCols() - 1)));
-	int top = erange.top();
-	int bottom = erange.bottom();
-	int left = erange.left();
-	int right = erange.right();
+	const QItemSelectionRange erange = range.intersected(QItemSelectionRange(index(0, 0), index(trueRows() - 1, trueCols() - 1)));
+	const int top = erange.top();
+	const int bottom = erange.bottom();
+	const int left = erange.left();
+	const int right = erange.right();
 
 	RKTextMatrix ret;
-	int tcol = 0;
 	for (int col = left; col <= right; ++col) {
-		QString *data = objects[col]->getCharacter(top, bottom);
-		RK_ASSERT(data);
-		ret.setColumn(tcol, data, bottom - top + 1);
-		delete[] data;
-		++tcol;
+		ret.setColumn(col - left, objects[col]->getCharacter(top, bottom));
 	}
 
 	return ret;
diff --git a/rkward/misc/rkprogresscontrol.cpp b/rkward/misc/rkprogresscontrol.cpp
index cf6b8f654..faee21ca8 100644
--- a/rkward/misc/rkprogresscontrol.cpp
+++ b/rkward/misc/rkprogresscontrol.cpp
@@ -181,7 +181,7 @@ static void addOutput(QTextEdit *log, const ROutput &output) {
 		}
 		//log->setTextColor(RKStyle::viewScheme()->foreground(KColorScheme::NormalText).color());
 	} else {
-		// We don't want output from install.packages() (which will always arrive as at "Warning" level
+		// We don't want output from install.packages() (which will always arrive as at "Warning" level)
 		// to look too alarming. Yet we'd like to keep output types differentiated in other cases.
 		auto font = log->font();
 		if (!font.bold()) {


More information about the rkward-tracker mailing list