[education/rkward] rkward: De-pointerize ROutput

Thomas Friedrichsmeier null at kde.org
Sun Aug 31 13:51:37 BST 2025


Git commit e1b2df8faf4782ede1a6f77e6a9e7079df4d7e86 by Thomas Friedrichsmeier.
Committed on 30/08/2025 at 10:24.
Pushed by tfry into branch 'master'.

De-pointerize ROutput

M  +1    -1    rkward/autotests/core_test.cpp
M  +11   -13   rkward/misc/rkprogresscontrol.cpp
M  +2    -2    rkward/misc/rkprogresscontrol.h
M  +15   -29   rkward/rbackend/rcommand.cpp
M  +7    -6    rkward/rbackend/rcommand.h
M  +2    -4    rkward/rbackend/rkfrontendtransmitter.cpp
M  +16   -21   rkward/rbackend/rkrbackendprotocol_shared.cpp
M  +14   -27   rkward/rbackend/rkrinterface.cpp
M  +5    -5    rkward/rbackend/rktransmitter.cpp
M  +4    -4    rkward/rkconsole.cpp
M  +2    -2    rkward/rkconsole.h
M  +10   -13   rkward/windows/rkcommandlog.cpp
M  +2    -2    rkward/windows/rkcommandlog.h

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

diff --git a/rkward/autotests/core_test.cpp b/rkward/autotests/core_test.cpp
index 405ab1331..7d42e20da 100644
--- a/rkward/autotests/core_test.cpp
+++ b/rkward/autotests/core_test.cpp
@@ -418,7 +418,7 @@ class RKWardCoreTest : public QObject {
 		//       reasonably be done on the CI...
 		for (int i = 0; i < 10; ++i) {
 			bool priority_command_done = false;
-			runCommandAsync(new RCommand(QStringLiteral("%1cat(\"sleeping\\n\");%1Sys.sleep(5)").arg(QString().fill(u'\n', i%5)), RCommand::User), nullptr, [&priority_command_done](RCommand *command) {
+			runCommandAsync(new RCommand(QStringLiteral("%1cat(\"sleeping\\n\");%1Sys.sleep(5)").arg(QString().fill(u'\n', i % 5)), RCommand::User), nullptr, [&priority_command_done](RCommand *command) {
 				QVERIFY(priority_command_done);
 				QVERIFY(command->failed());
 				QVERIFY(command->wasCanceled());
diff --git a/rkward/misc/rkprogresscontrol.cpp b/rkward/misc/rkprogresscontrol.cpp
index 7ba8f9c98..4d5296a6f 100644
--- a/rkward/misc/rkprogresscontrol.cpp
+++ b/rkward/misc/rkprogresscontrol.cpp
@@ -34,7 +34,7 @@ class RKProgressControlDialog : public QDialog {
 	~RKProgressControlDialog();
 
   public:
-	void addOutput(const ROutput *output);
+	void addOutput(const ROutput &output);
 	void finished();
 	void indicateError();
 
@@ -165,16 +165,14 @@ void RKProgressControl::createDialog() {
 	connect(dialog, &QObject::destroyed, this, &RKProgressControl::dialogDestroyed);
 	if (is_done) done();
 	for (int i = 0; i < output_log.count(); ++i) {
-		dialog->addOutput(&(output_log[i]));
+		dialog->addOutput(output_log[i]);
 	}
 }
 
-void RKProgressControl::newOutput(RCommand *, const ROutput *output) {
+void RKProgressControl::newOutput(RCommand *, const ROutput &output) {
 	RK_TRACE(MISC);
-	RK_ASSERT(output);
 
-	const ROutput outputc(*output);
-	output_log.append(outputc);
+	output_log.append(output);
 	if (mode & RaiseOnOutput) {
 		if (!dialog) createDialog();
 		dialog->raise();
@@ -269,7 +267,7 @@ void RKProgressControlDialog::indicateError() {
 	error_indicator->show();
 }
 
-void RKProgressControlDialog::addOutput(const ROutput *output) {
+void RKProgressControlDialog::addOutput(const ROutput &output) {
 	RK_TRACE(MISC);
 
 	// scrolled all the way to the bottom?
@@ -279,11 +277,11 @@ void RKProgressControlDialog::addOutput(const ROutput *output) {
 		if (bar && (bar->value() < bar->maximum())) at_end = false;
 	}
 
-	if (output->type != last_output_type) {
-		last_output_type = output->type;
+	if (output.type != last_output_type) {
+		last_output_type = output.type;
 		output_text->insertPlainText(QStringLiteral("\n"));
 
-		if (output->type == ROutput::Output) {
+		if (output.type == ROutput::Output) {
 			output_text->setTextColor(RKStyle::viewScheme()->foreground(KColorScheme::NormalText).color());
 		} else {
 			output_text->setTextColor(RKStyle::viewScheme()->foreground(KColorScheme::NegativeText).color());
@@ -291,7 +289,7 @@ void RKProgressControlDialog::addOutput(const ROutput *output) {
 		}
 	}
 
-	output_text->insertPlainText(output->output);
+	output_text->insertPlainText(output.output);
 
 	// if previously at end, auto-scroll
 	if (at_end && output_text->isVisible()) scrollDown();
@@ -431,8 +429,8 @@ void RKInlineProgressControl::addRCommand(RCommand *command) {
 			done();
 		}
 	});
-	connect(command->notifier(), &RCommandNotifier::commandOutput, this, [this](RCommand *, const ROutput *o) {
-		addOutput(o->output, o->type != ROutput::Output);
+	connect(command->notifier(), &RCommandNotifier::commandOutput, this, [this](RCommand *, const ROutput &o) {
+		addOutput(o.output, o.type != ROutput::Output);
 	});
 }
 
diff --git a/rkward/misc/rkprogresscontrol.h b/rkward/misc/rkprogresscontrol.h
index cfba5ec9e..c72ff3ed2 100644
--- a/rkward/misc/rkprogresscontrol.h
+++ b/rkward/misc/rkprogresscontrol.h
@@ -79,7 +79,7 @@ class RKProgressControl : public QObject {
 	void createDialog();
 
 	RKProgressControlDialog *dialog;
-	QList<ROutput> output_log;
+	ROutputList output_log;
 	QList<RCommand *> outstanding_commands;
 
 	bool autodelete;
@@ -90,7 +90,7 @@ class RKProgressControl : public QObject {
 	QString caption;
 
   protected:
-	void newOutput(RCommand *, const ROutput *output);
+	void newOutput(RCommand *, const ROutput &output);
 };
 
 class KMessageWidget;
diff --git a/rkward/rbackend/rcommand.cpp b/rkward/rbackend/rcommand.cpp
index 5213b5e67..734ad7f8e 100644
--- a/rkward/rbackend/rcommand.cpp
+++ b/rkward/rbackend/rcommand.cpp
@@ -1,6 +1,6 @@
 /*
 rcommand.cpp - This file is part of RKWard (https://rkward.kde.org). Created: Mon Nov 11 2002
-SPDX-FileCopyrightText: 2002-2007 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2002-2025 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -47,11 +47,6 @@ RCommand::RCommand(const QString &command, int type, const QString &rk_equiv) :
 RCommand::~RCommand() {
 	RK_TRACE(RBACKEND);
 
-	for (QList<ROutput *>::const_iterator it = output_list.constBegin(); it != output_list.constEnd(); ++it) {
-		delete (*it);
-	}
-	// The output_list itself is cleared automatically
-
 	if (_notifier) delete _notifier;
 }
 
@@ -71,7 +66,7 @@ void RCommand::finished() {
 	if (_notifier) _notifier->emitFinished(this);
 }
 
-void RCommand::newOutput(ROutput *output) {
+void RCommand::newOutput(const ROutput &output) {
 	RK_TRACE(RBACKEND);
 
 	RKCommandLog::getLog()->newOutput(this, output);
@@ -84,48 +79,39 @@ void RCommand::commandLineIn() {
 	if (_notifier) _notifier->emitLineIn(this);
 }
 
-QString RCommand::error() const {
-	RK_TRACE(RBACKEND);
-
+static QString extractFromOutputList(const ROutputList &list, ROutput::ROutputType type) {
 	QString ret;
-	for (ROutputList::const_iterator it = output_list.begin(); it != output_list.end(); ++it) {
-		if ((*it)->type == ROutput::Error) {
-			ret.append((*it)->output);
+	for (const auto &out : list) {
+		if (out.type == type) {
+			ret.append(out.output);
 		}
 	}
 	return ret;
 }
 
+QString RCommand::error() const {
+	RK_TRACE(RBACKEND);
+	return extractFromOutputList(output_list, ROutput::Error);
+}
+
 QString RCommand::output() const {
 	RK_TRACE(RBACKEND);
 
-	QString ret;
-	for (ROutputList::const_iterator it = output_list.begin(); it != output_list.end(); ++it) {
-		if ((*it)->type == ROutput::Output) {
-			ret.append((*it)->output);
-		}
-	}
-	return ret;
+	return extractFromOutputList(output_list, ROutput::Output);
 }
 
 QString RCommand::warnings() const {
 	RK_TRACE(RBACKEND);
 
-	QString ret;
-	for (ROutputList::const_iterator it = output_list.begin(); it != output_list.end(); ++it) {
-		if ((*it)->type == ROutput::Warning) {
-			ret.append((*it)->output);
-		}
-	}
-	return ret;
+	return extractFromOutputList(output_list, ROutput::Warning);
 }
 
 QString RCommand::fullOutput() const {
 	RK_TRACE(RBACKEND);
 
 	QString ret;
-	for (ROutputList::const_iterator it = output_list.begin(); it != output_list.end(); ++it) {
-		ret.append((*it)->output);
+	for (const auto &out : std::as_const(output_list)) {
+		ret.append(out.output);
 	}
 	return ret;
 }
diff --git a/rkward/rbackend/rcommand.h b/rkward/rbackend/rcommand.h
index e509d059b..8184b9c07 100644
--- a/rkward/rbackend/rcommand.h
+++ b/rkward/rbackend/rcommand.h
@@ -1,6 +1,6 @@
 /*
 rcommand.h - This file is part of the RKWard project. Created: Mon Nov 11 2002
-SPDX-FileCopyrightText: 2002-2020 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2002-2025 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -47,18 +47,19 @@ class RCommandChain {
 /** this struct is used to store the R output to an RCommand. The RCommand basically keeps a list of ROutputString (s). The difference to a normal
 QString is, that additionally we store information on whether the output was "normal", "warning", or an "error". */
 struct ROutput {
-	ROutput() : type(NoOutput) {};
 	enum ROutputType {
 		NoOutput, /**< No output. Rarely used. */
 		Output,   /**< normal output */
 		Warning,  /**< R warning */
 		Error     /**< R error */
 	};
+	ROutput() : type(NoOutput) {};
+	ROutput(ROutputType type, const QString &output) : type(type), output(output) {};
 	ROutputType type;
 	QString output;
 };
 
-typedef QList<ROutput *> ROutputList;
+typedef QList<ROutput> ROutputList;
 
 /** Supplies signals for RCommands.
  * Obtain an instance of this using RCommand::notifier ();
@@ -70,7 +71,7 @@ class RCommandNotifier : public QObject {
 	/** given command has finished (not necessarily successfully) */
 	void commandFinished(RCommand *command);
 	/** new output for the given command */
-	void commandOutput(RCommand *command, const ROutput *output);
+	void commandOutput(RCommand *command, const ROutput &output);
 	/** a new line of the command has started being evaluate. Only emitted to RCommand::User-type commands */
 	void commandLineIn(RCommand *command);
 
@@ -79,7 +80,7 @@ class RCommandNotifier : public QObject {
 	RCommandNotifier();
 	~RCommandNotifier();
 	void emitFinished(RCommand *command) { Q_EMIT commandFinished(command); };
-	void emitOutput(RCommand *command, const ROutput *output) { Q_EMIT commandOutput(command, output); };
+	void emitOutput(RCommand *command, const ROutput &output) { Q_EMIT commandOutput(command, output); };
 	void emitLineIn(RCommand *command) { Q_EMIT commandLineIn(command); };
 };
 
@@ -211,7 +212,7 @@ class RCommand : public RData, public RCommandChain {
 	/** internal function will be called by the backend, as the command gets passed through. Takes care of sending this command (back) to its receiver(s) */
 	void finished();
 	/** new output was generated. Pass on to receiver(s) */
-	void newOutput(ROutput *output);
+	void newOutput(const ROutput &output);
 	/** next line of command has been transmitted. Pass on to receiver(s). Only called for RCommand::User type commands */
 	void commandLineIn();
 	ROutputList output_list;
diff --git a/rkward/rbackend/rkfrontendtransmitter.cpp b/rkward/rbackend/rkfrontendtransmitter.cpp
index 0dcea281f..ba0936428 100644
--- a/rkward/rbackend/rkfrontendtransmitter.cpp
+++ b/rkward/rbackend/rkfrontendtransmitter.cpp
@@ -390,14 +390,12 @@ void RKFrontendTransmitter::requestReceived(RBackendRequest *request) {
 	if (request->type == RBackendRequest::Output) {
 		ROutputList *list = request->output;
 		for (int i = 0; i < list->size(); ++i) {
-			ROutput *out = (*list)[i];
+			const auto &out = (*list)[i];
 
-			if (handleOutput(out->output, out->output.length(), out->type)) {
+			if (handleOutput(out.output, out.output.length(), out.type)) {
 				RKRBackendEvent *event = new RKRBackendEvent(new RBackendRequest(false, RBackendRequest::OutputStartedNotification));
 				qApp->postEvent(frontend, event);
 			}
-
-			delete (out);
 		}
 		delete list;
 		request->output = nullptr;
diff --git a/rkward/rbackend/rkrbackendprotocol_shared.cpp b/rkward/rbackend/rkrbackendprotocol_shared.cpp
index 7c4d7501c..009370682 100644
--- a/rkward/rbackend/rkrbackendprotocol_shared.cpp
+++ b/rkward/rbackend/rkrbackendprotocol_shared.cpp
@@ -115,24 +115,24 @@ QString RKROutputBuffer::popOutputCapture(bool highlighted) {
 	QString ret;
 	ROutput::ROutputType previous_type = ROutput::NoOutput;
 	for (int i = 0; i < capture.recorded.length(); ++i) {
-		const ROutput *output = capture.recorded[i];
-		if (output->output.isEmpty()) continue;
+		const auto output = capture.recorded[i];
+		if (output.output.isEmpty()) continue;
 
-		if (output->type != ROutput::Error) { // NOTE: skip error output. It has already been written as a warning.
-			if (highlighted && (output->type != previous_type)) {
+		if (output.type != ROutput::Error) { // NOTE: skip error output. It has already been written as a warning.
+			if (highlighted && (output.type != previous_type)) {
 				if (!ret.isEmpty()) ret.append(u"</pre>\n"_s);
 
-				if (output->type == ROutput::Output) ret.append(u"<pre class=\"output_normal\">"_s);
-				else if (output->type == ROutput::Warning) ret.append(u"<pre class=\"output_warning\">"_s);
+				if (output.type == ROutput::Output) ret.append(u"<pre class=\"output_normal\">"_s);
+				else if (output.type == ROutput::Warning) ret.append(u"<pre class=\"output_warning\">"_s);
 				else {
 					RK_ASSERT(false);
 					ret.append(u"<pre>"_s);
 				}
 			}
-			if (highlighted) ret.append(output->output.toHtmlEscaped());
-			else ret.append(output->output);
+			if (highlighted) ret.append(output.output.toHtmlEscaped());
+			else ret.append(output.output);
 
-			previous_type = output->type;
+			previous_type = output.type;
 		}
 	}
 	if (highlighted && !ret.isEmpty()) ret.append(u"</pre>\n"_s);
@@ -141,19 +141,14 @@ QString RKROutputBuffer::popOutputCapture(bool highlighted) {
 
 void appendToOutputList(ROutputList *list, const QString &output, ROutput::ROutputType output_type) {
 	// No trace
-	ROutput *current_output = nullptr;
-	if (!list->isEmpty()) {
-		// Merge with previous output fragment, if of the same type
-		current_output = list->last();
-		if (current_output->type != output_type) current_output = nullptr;
-	}
-	if (!current_output) {
-		current_output = new ROutput;
-		current_output->type = output_type;
-		current_output->output.reserve(OUTPUT_STRING_RESERVE);
-		list->append(current_output);
+	// Merge with previous output fragment, if of the same type
+	if (!list->isEmpty() && list->last().type == output_type) {
+		list->last().output.append(output);
+	} else {
+		QString spaced = output;
+		spaced.reserve(OUTPUT_STRING_RESERVE);
+		list->append(ROutput(output_type, spaced));
 	}
-	current_output->output.append(output);
 }
 
 bool RKROutputBuffer::handleOutput(const QString &output, int buf_length, ROutput::ROutputType output_type, bool allow_blocking) {
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index ad0945071..69ab2217b 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -253,9 +253,7 @@ void RInterface::handleCommandOut(RCommand *command) {
 
 	if (command->status & RCommand::Canceled) {
 		command->status |= RCommand::HasError;
-		ROutput *out = new ROutput;
-		out->type = ROutput::Error;
-		out->output = u"--- interrupted ---"_s;
+		auto out = ROutput(ROutput::Error, u"--- interrupted ---"_s);
 		command->output_list.append(out);
 		command->newOutput(out);
 	}
@@ -472,44 +470,33 @@ void RInterface::flushOutput(bool forced) {
 	//	RK_TRACE (RBACKEND);
 	const ROutputList list = backendprotocol->flushOutput(forced);
 
-	for (ROutput *output : list) {
+	for (const ROutput &output : list) {
 		if (all_current_commands.isEmpty()) {
-			RK_DEBUG(RBACKEND, DL_DEBUG, "output without receiver'%s'", qPrintable(output->output));
+			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
-			delete output;
-			continue; // to delete the other output pointers, too
+			continue;
 		} else {
-			RK_DEBUG(RBACKEND, DL_DEBUG, "output '%s'", qPrintable(output->output));
+			RK_DEBUG(RBACKEND, DL_DEBUG, "output '%s'", qPrintable(output.output));
 		}
 
-		bool first = true;
 		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;
-				coutput->type = output->type;
-				coutput->output = output->output;
-			}
-			first = false;
-
-			if (coutput->type == ROutput::Output) {
+			if (output.type == ROutput::Output) {
 				command->status |= RCommand::HasOutput;
-				command->output_list.append(coutput);
-			} else if (coutput->type == ROutput::Warning) {
+				command->output_list.append(output);
+			} else if (output.type == ROutput::Warning) {
 				command->status |= RCommand::HasWarnings;
-				command->output_list.append(coutput);
-			} else if (coutput->type == ROutput::Error) {
+				command->output_list.append(output);
+			} else if (output.type == ROutput::Error) {
 				command->status |= RCommand::HasError;
 				// An error output is typically just the copy of the previous output, so merge if possible
 				if (command->output_list.isEmpty()) {
-					command->output_list.append(coutput);
-				}
-				if (command->output_list.last()->output == coutput->output) {
-					command->output_list.last()->type = ROutput::Error;
+					command->output_list.append(output);
+				} else if (command->output_list.last().output == output.output) {
+					command->output_list.last().type = ROutput::Error;
 					continue; // don't call command->newOutput(), again!
 				}
 			}
-			command->newOutput(coutput);
+			command->newOutput(output);
 		}
 	}
 }
diff --git a/rkward/rbackend/rktransmitter.cpp b/rkward/rbackend/rktransmitter.cpp
index 70546758a..43c0ae81a 100644
--- a/rkward/rbackend/rktransmitter.cpp
+++ b/rkward/rbackend/rktransmitter.cpp
@@ -70,8 +70,8 @@ void RKRBackendSerializer::serializeOutput(const ROutputList &list, QDataStream
 
 	stream << (qint32)list.size();
 	for (qint32 i = 0; i < list.size(); ++i) {
-		stream << (qint8)list[i]->type;
-		stream << list[i]->output;
+		stream << (qint8)list[i].type;
+		stream << list[i].output;
 	}
 }
 
@@ -84,11 +84,11 @@ ROutputList *RKRBackendSerializer::unserializeOutput(QDataStream &stream) {
 	ret->reserve(len);
 
 	for (qint32 i = 0; i < len; ++i) {
-		ROutput *out = new ROutput;
+		ROutput out;
 		qint8 dummy8;
 		stream >> dummy8;
-		out->type = (ROutput::ROutputType)dummy8;
-		stream >> out->output;
+		out.type = (ROutput::ROutputType)dummy8;
+		stream >> out.output;
 		ret->append(out);
 	}
 
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 80875bca7..15692bf70 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -517,7 +517,7 @@ void RKConsole::rawWriteLine(const QString &line, QChar line_end) {
 	}
 }
 
-void RKConsole::newOutput(RCommand *command, const ROutput *output) {
+void RKConsole::newOutput(RCommand *command, const ROutput &output) {
 	RK_TRACE(APP);
 
 	if (!command) {
@@ -528,7 +528,7 @@ void RKConsole::newOutput(RCommand *command, const ROutput *output) {
 	int first_line = output_cursor.line();
 	;
 	// split by and handle carriage returns (important for progress bars)
-	const QString out = output->output;
+	const QString out = output.output;
 	int string_pos = -1;
 	int start_pos = 0;
 	int end_pos = out.length();
@@ -542,7 +542,7 @@ void RKConsole::newOutput(RCommand *command, const ROutput *output) {
 	if (start_pos < end_pos) rawWriteLine(out.mid(start_pos, string_pos - start_pos + 1), u' ');
 
 	int end_line = output_cursor.line();
-	if (output->type != ROutput::Output || (!command)) {
+	if (output.type != ROutput::Output || (!command)) {
 		for (int line = first_line; line < end_line; ++line) {
 			doc->addMark(line, command ? KTextEditor::Document::BreakpointActive : KTextEditor::Document::BreakpointDisabled);
 		}
@@ -887,7 +887,7 @@ void RKConsole::pipeCommandThroughConsoleLocal(const QString &command_string) {
 	previous_chunk_was_piped = true;
 }
 
-void RKConsole::insertSpontaneousROutput(ROutput *output) {
+void RKConsole::insertSpontaneousROutput(const ROutput &output) {
 	RK_TRACE(APP);
 	RK_ASSERT(!current_command);
 	newOutput(nullptr, output);
diff --git a/rkward/rkconsole.h b/rkward/rkconsole.h
index 96ff39901..4c6635484 100644
--- a/rkward/rkconsole.h
+++ b/rkward/rkconsole.h
@@ -61,14 +61,14 @@ class RKConsole : public RKMDIWindow, public RKScriptContextProvider {
 	void setCommandHistory(const QStringList &new_history, bool append);
 	QStringList commandHistory() const { return commands_history.getHistory(); };
 	void addCommandToHistory(const QString &text) { commands_history.append(text); };
-	void insertSpontaneousROutput(ROutput *output);
+	void insertSpontaneousROutput(const ROutput &output);
 
   protected:
 	/** Handle keystrokes before they reach the kate-part. Return TRUE if we want the kate-part to ignore it
 	\param e the QKeyEvent */
 	bool handleKeyPress(QKeyEvent *e);
 	/** handle output of console commands */
-	void newOutput(RCommand *command, const ROutput *output);
+	void newOutput(RCommand *command, const ROutput &output);
 	/** display the next line of the command for multi-line commands */
 	void userCommandLineIn(RCommand *command);
 	/** reimplemented from QWidget to show the context menu */
diff --git a/rkward/windows/rkcommandlog.cpp b/rkward/windows/rkcommandlog.cpp
index 93951c8a3..207e32d7c 100644
--- a/rkward/windows/rkcommandlog.cpp
+++ b/rkward/windows/rkcommandlog.cpp
@@ -124,7 +124,7 @@ void RKCommandLog::addInputNoCheck(RCommand *command) {
 	command_input_shown.append(command);
 }
 
-void RKCommandLog::addOutputNoCheck(RCommand *command, ROutput *output) {
+void RKCommandLog::addOutputNoCheck(RCommand *command, const ROutput &output) {
 	RK_TRACE(APP);
 
 	if (command->type() & RCommand::User) {
@@ -135,15 +135,15 @@ void RKCommandLog::addOutputNoCheck(RCommand *command, ROutput *output) {
 		log_view->setTextColor(Qt::blue);
 	}
 	log_view->setFontWeight(QFont::Bold);
-	if (output->type != ROutput::Output) {
+	if (output.type != ROutput::Output) {
 		QTextBlockFormat f;
 		f.setBackground(QBrush(QColor(255, 200, 200)));
 		log_view->textCursor().mergeBlockFormat(f);
 	}
 
-	log_view->insertPlainText(output->output);
+	log_view->insertPlainText(output.output);
 
-	if (output->type != ROutput::Output) {
+	if (output.type != ROutput::Output) {
 		QTextBlockFormat f;
 		f.setBackground(QBrush(QColor(255, 255, 255)));
 		log_view->textCursor().mergeBlockFormat(f);
@@ -165,7 +165,7 @@ void RKCommandLog::checkRaiseWindow(RCommand *command) {
 	activate(false);
 }
 
-void RKCommandLog::newOutput(RCommand *command, ROutput *output_fragment) {
+void RKCommandLog::newOutput(RCommand *command, const ROutput &output_fragment) {
 	RK_TRACE(APP);
 
 	if (!RKSettingsModuleWatch::shouldShowOutput(command)) return;
@@ -189,21 +189,18 @@ void RKCommandLog::rCommandDone(RCommand *command) {
 			if (!RKSettingsModuleWatch::shouldShowInput(command)) addInputNoCheck(command);
 			if (!RKSettingsModuleWatch::shouldShowOutput(command)) {
 				ROutputList out_list = command->getOutput();
-				for (ROutputList::const_iterator it = out_list.constBegin(); it != out_list.constEnd(); ++it) {
-					addOutputNoCheck(command, *it);
+				for (const auto &out : std::as_const(out_list)) {
+					addOutputNoCheck(command, out);
 				}
 			}
 			if (command->failed() && command->error().isEmpty()) {
-				ROutput dummy_output;
-				dummy_output.type = ROutput::Error;
 				if (command->errorIncomplete()) {
-					dummy_output.output = i18n("Incomplete statement.\n");
+					addOutputNoCheck(command, ROutput(ROutput::Error, i18n("Incomplete statement.\n")));
 				} else if (command->errorSyntax()) {
-					dummy_output.output = i18n("Syntax error.\n");
+					addOutputNoCheck(command, ROutput(ROutput::Error, i18n("Syntax error.\n")));
 				} else {
-					dummy_output.output = i18n("An unspecified error occurred while running the command.\n");
+					addOutputNoCheck(command, ROutput(ROutput::Error, i18n("An unspecified error occurred while running the command.\n")));
 				}
-				addOutputNoCheck(command, &dummy_output);
 			}
 		}
 	}
diff --git a/rkward/windows/rkcommandlog.h b/rkward/windows/rkcommandlog.h
index 2bdd5ee50..ca3fdaf87 100644
--- a/rkward/windows/rkcommandlog.h
+++ b/rkward/windows/rkcommandlog.h
@@ -28,7 +28,7 @@ class RKCommandLog : public RKMDIWindow {
 	/** Adds input to the log_view-window (i.e. commands issued) */
 	void addInput(RCommand *command);
 	/** Adds output to the log_view-window (i.e. replies received) */
-	void newOutput(RCommand *command, ROutput *output_fragment);
+	void newOutput(RCommand *command, const ROutput &output_fragment);
 	/** Adds output not originating from R. Note: Currently used from kate plugins, only, see katepluginintegration.cpp */
 	void addOtherMessage(const QString &message, const QIcon &icon, ROutput::ROutputType severity);
 
@@ -52,7 +52,7 @@ class RKCommandLog : public RKMDIWindow {
 
   private:
 	void addInputNoCheck(RCommand *command);
-	void addOutputNoCheck(RCommand *command, ROutput *output);
+	void addOutputNoCheck(RCommand *command, const ROutput &output);
 	void checkRaiseWindow(RCommand *command);
 	/** internal helper function, called whenever a line/lines have been added. Check whether log is longer than maximum setting. Scroll to the bottom */
 	void linesAdded();



More information about the rkward-tracker mailing list