[education/rkward] rkward: Various const-ness fixes

Thomas Friedrichsmeier null at kde.org
Sat Jan 31 08:17:04 GMT 2026


Git commit c5f7733548359d24611f02f8b152e6d0708f9f65 by Thomas Friedrichsmeier.
Committed on 31/01/2026 at 08:16.
Pushed by tfry into branch 'master'.

Various const-ness fixes

M  +1    -1    rkward/agents/rkloadagent.cpp
M  +10   -10   rkward/core/rcontainerobject.cpp
M  +4    -4    rkward/core/rcontainerobject.h
M  +4    -4    rkward/core/renvironmentobject.cpp
M  +2    -2    rkward/core/renvironmentobject.h
M  +3    -3    rkward/core/rfunctionobject.cpp
M  +2    -2    rkward/core/rfunctionobject.h
M  +11   -13   rkward/core/rkmodificationtracker.cpp
M  +6    -7    rkward/core/rkvariable.cpp
M  +1    -1    rkward/core/rkvariable.h
M  +21   -21   rkward/core/robject.cpp
M  +10   -10   rkward/core/robject.h
M  +3    -3    rkward/core/robjectlist.cpp
M  +1    -1    rkward/core/robjectlist.h
M  +5    -5    rkward/dialogs/rkloadlibsdialog.cpp
M  +2    -2    rkward/rbackend/rdata.cpp
M  +5    -4    rkward/rbackend/rdata.h
M  +1    -1    rkward/rbackend/rkrbackend.cpp
M  +1    -1    rkward/rbackend/rktransmitter.cpp
M  +1    -1    rkward/scriptbackends/rkcomponentscripting.cpp

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

diff --git a/rkward/agents/rkloadagent.cpp b/rkward/agents/rkloadagent.cpp
index e18acde18..12092684f 100644
--- a/rkward/agents/rkloadagent.cpp
+++ b/rkward/agents/rkloadagent.cpp
@@ -57,7 +57,7 @@ RKLoadAgent::RKLoadAgent(const QUrl &url, bool merge) {
 	}
 
 	command = new RCommand(u"load (\""_s + filename + u"\")"_s, RCommand::App | RCommand::ObjectListUpdate);
-	command->whenFinished(this, [this](RCommand *command) {
+	command->whenFinished(this, [this](const RCommand *command) {
 		if (command->failed()) {
 			KMessageBox::error(nullptr, i18n("There has been an error opening file '%1':\n%2", RKWorkplace::mainWorkplace()->workspaceURL().path(), command->warnings() + command->error()), i18n("Error loading workspace"));
 			RKWorkplace::mainWorkplace()->setWorkspaceURL(QUrl());
diff --git a/rkward/core/rcontainerobject.cpp b/rkward/core/rcontainerobject.cpp
index 7ced783b0..b658d1fec 100644
--- a/rkward/core/rcontainerobject.cpp
+++ b/rkward/core/rcontainerobject.cpp
@@ -33,7 +33,7 @@ RContainerObject::~RContainerObject() {
 	}
 }
 
-RObject *RContainerObject::updateChildStructure(RObject *child, RData *new_data, bool just_created) {
+RObject *RContainerObject::updateChildStructure(RObject *child, const RData *new_data, bool just_created) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(child);
 	RK_ASSERT(new_data);
@@ -50,7 +50,7 @@ RObject *RContainerObject::updateChildStructure(RObject *child, RData *new_data,
 			int child_index = childmap.indexOf(child);
 			RK_ASSERT(child_index >= 0);
 			if (RKModificationTracker::instance()->removeObject(child, nullptr, true)) {
-				RData *child_name_data = new_data->structureVector().at(StoragePositionName);
+				const RData *child_name_data = new_data->structureVector().at(StoragePositionName);
 				RK_ASSERT(child_name_data->getDataType() == RData::StringVector);
 				RK_ASSERT(child_name_data->getDataLength() >= 1);
 				QString child_name = child_name_data->stringVector().at(0);
@@ -63,7 +63,7 @@ RObject *RContainerObject::updateChildStructure(RObject *child, RData *new_data,
 	}
 }
 
-bool RContainerObject::updateStructure(RData *new_data) {
+bool RContainerObject::updateStructure(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	unsigned int data_length = new_data->getDataLength();
 	RK_ASSERT(data_length >= StorageSizeBasicInfo);
@@ -74,7 +74,7 @@ bool RContainerObject::updateStructure(RData *new_data) {
 	if (data_length > StorageSizeBasicInfo) {
 		RK_ASSERT(data_length == (StorageSizeBasicInfo + 1));
 
-		RData *children_sub = new_data->structureVector().at(StoragePositionChildren);
+		const RData *children_sub = new_data->structureVector().at(StoragePositionChildren);
 		RK_ASSERT(children_sub->getDataType() == RData::StructureVector);
 		updateChildren(children_sub);
 		updateRowNamesObject();
@@ -85,12 +85,12 @@ bool RContainerObject::updateStructure(RData *new_data) {
 	return true;
 }
 
-RObject *RContainerObject::createChildFromStructure(RData *child_data, const QString &child_name, int position) {
+RObject *RContainerObject::createChildFromStructure(const RData *child_data, const QString &child_name, int position) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(child_data->getDataType() == RData::StructureVector);
 	RK_ASSERT(child_data->getDataLength() >= (StoragePositionType + 1)); // need to see at least the type at this point
 
-	RData *type_data = child_data->structureVector().at(StoragePositionType);
+	const RData *type_data = child_data->structureVector().at(StoragePositionType);
 	RK_ASSERT(type_data->getDataType() == RData::IntVector);
 	RK_ASSERT(type_data->getDataLength() == 1);
 
@@ -124,7 +124,7 @@ RObject *RContainerObject::createChildFromStructure(RData *child_data, const QSt
 	return child_object;
 }
 
-void RContainerObject::updateChildren(RData *new_children) {
+void RContainerObject::updateChildren(const RData *new_children) {
 	RK_TRACE(OBJECTS);
 
 	RK_ASSERT(new_children->getDataType() == RData::StructureVector);
@@ -133,12 +133,12 @@ void RContainerObject::updateChildren(RData *new_children) {
 	// first find out, which children are now available, copy the old ones, create the new ones
 	RObjectMap new_childmap, old_childmap;
 	old_childmap = childmap;
-	RData::RDataStorage nc_data = new_children->structureVector();
+	const auto &nc_data = new_children->structureVector();
 	for (unsigned int i = 0; i < new_child_count; ++i) {
-		RData *child_data = nc_data.at(i);
+		const RData *child_data = nc_data.at(i);
 		RK_ASSERT(child_data->getDataType() == RData::StructureVector);
 		RK_ASSERT(child_data->getDataLength() >= (StoragePositionName + 1));
-		RData *child_name_data = child_data->structureVector().at(StoragePositionName);
+		const RData *child_name_data = child_data->structureVector().at(StoragePositionName);
 		RK_ASSERT(child_name_data->getDataType() == RData::StringVector);
 		RK_ASSERT(child_name_data->getDataLength() >= 1);
 		QString child_name = child_name_data->stringVector().at(0);
diff --git a/rkward/core/rcontainerobject.h b/rkward/core/rcontainerobject.h
index d77dcd673..d8ddc405f 100644
--- a/rkward/core/rcontainerobject.h
+++ b/rkward/core/rcontainerobject.h
@@ -25,11 +25,11 @@ class RContainerObject : public RObject {
 	~RContainerObject() override;
 
 	/** update the given child with the given data. Since the child may be mismatching, and may need to be recreated, returns a pointer to the child (old or new) */
-	RObject *updateChildStructure(RObject *child, RData *new_data, bool just_created = false);
-	RObject *createChildFromStructure(RData *child_data, const QString &child_name, int position);
+	RObject *updateChildStructure(RObject *child, const RData *new_data, bool just_created = false);
+	RObject *createChildFromStructure(const RData *child_data, const QString &child_name, int position);
 
 	/** reimplemented from RObject to also update children */
-	bool updateStructure(RData *new_data) override;
+	bool updateStructure(const RData *new_data) override;
 
 	int numChildren() const;
 	/** returns true, if there are no children in this container. Note: of course the object list may not be up to date! */
@@ -65,7 +65,7 @@ class RContainerObject : public RObject {
 	/** reimplemented from RObject to actually search for matching objects among the children */
 	RObject::ObjectList findObjects(const QStringList &path, bool partial, const QString &op) override;
 
-	void updateChildren(RData *new_children);
+	void updateChildren(const RData *new_children);
 	RObjectMap childmap;
 	// why do I need this to make it compile?!
 	friend class RObjectList;
diff --git a/rkward/core/renvironmentobject.cpp b/rkward/core/renvironmentobject.cpp
index 97cf1fe71..104dccdf0 100644
--- a/rkward/core/renvironmentobject.cpp
+++ b/rkward/core/renvironmentobject.cpp
@@ -113,7 +113,7 @@ void REnvironmentObject::updateFromR(RCommandChain *chain, const QStringList &ad
 	}
 }
 
-bool REnvironmentObject::updateStructure(RData *new_data) {
+bool REnvironmentObject::updateStructure(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataType() == RData::StructureVector);
 	RK_ASSERT(new_data->getDataLength() >= StorageSizeBasicInfo);
@@ -122,9 +122,9 @@ bool REnvironmentObject::updateStructure(RData *new_data) {
 		if (!RContainerObject::updateStructure(new_data)) return false;
 	}
 
-	RData::RDataStorage new_data_data = new_data->structureVector();
+	const auto &new_data_data = new_data->structureVector();
 	if (new_data->getDataLength() > StorageSizeBasicInfo) {
-		RData *children_sub = new_data_data.at(StoragePositionChildren);
+		const RData *children_sub = new_data_data.at(StoragePositionChildren);
 		RK_ASSERT(children_sub->getDataType() == RData::StructureVector);
 		updateChildren(children_sub);
 
@@ -139,7 +139,7 @@ bool REnvironmentObject::updateStructure(RData *new_data) {
 	return true;
 }
 
-void REnvironmentObject::updateNamespace(RData *new_data) {
+void REnvironmentObject::updateNamespace(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 
 	if (!new_data) {
diff --git a/rkward/core/renvironmentobject.h b/rkward/core/renvironmentobject.h
index da425b80e..da2d76f16 100644
--- a/rkward/core/renvironmentobject.h
+++ b/rkward/core/renvironmentobject.h
@@ -34,13 +34,13 @@ class REnvironmentObject : public RContainerObject {
 	QString getObjectDescription() const override;
 
   protected:
-	bool updateStructure(RData *new_data) override;
+	bool updateStructure(const RData *new_data) override;
 	/// reimplemented from RContainerObject to call "remove (objectname)" instead of "objectname <- NULL"
 	QString removeChildCommand(RObject *object) const override;
 	/// reimplemented from RContainerObject to call "remove (objectname)" instead of "objectname <- NULL"
 	QString renameChildCommand(RObject *object, const QString &new_name) const override;
 	friend class RObject;
-	void updateNamespace(RData *new_data);
+	void updateNamespace(const RData *new_data);
 };
 
 #endif
diff --git a/rkward/core/rfunctionobject.cpp b/rkward/core/rfunctionobject.cpp
index ba82a08cc..193c0ac6c 100644
--- a/rkward/core/rfunctionobject.cpp
+++ b/rkward/core/rfunctionobject.cpp
@@ -36,7 +36,7 @@ QString RFunctionObject::printArgs() const {
 	return ret;
 }
 
-bool RFunctionObject::updateStructure(RData *new_data) {
+bool RFunctionObject::updateStructure(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() >= StorageSizeBasicInfo);
 	RK_ASSERT(new_data->getDataType() == RData::StructureVector);
@@ -48,12 +48,12 @@ bool RFunctionObject::updateStructure(RData *new_data) {
 	return true;
 }
 
-bool RFunctionObject::updateArguments(RData *new_data) {
+bool RFunctionObject::updateArguments(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() == (StoragePositionFunValues + 1));
 	RK_ASSERT(new_data->getDataType() == RData::StructureVector);
 
-	RData::RDataStorage new_data_data = new_data->structureVector();
+	const auto &new_data_data = new_data->structureVector();
 	QStringList new_argnames = new_data_data.at(StoragePositionFunArgs)->stringVector();
 	QStringList new_argvalues = new_data_data.at(StoragePositionFunValues)->stringVector();
 	RK_ASSERT(new_argnames.size() == new_argvalues.size());
diff --git a/rkward/core/rfunctionobject.h b/rkward/core/rfunctionobject.h
index bb2074878..30533a905 100644
--- a/rkward/core/rfunctionobject.h
+++ b/rkward/core/rfunctionobject.h
@@ -23,7 +23,7 @@ class RFunctionObject : public RObject {
 	~RFunctionObject() override;
 
 	/** reimplemented from RObject to handle function arguments */
-	bool updateStructure(RData *new_data) override;
+	bool updateStructure(const RData *new_data) override;
 	QString printArgs() const;
 	QStringList argumentNames() const { return argnames; }
 	QStringList argumentDefaults() const { return argvalues; }
@@ -31,7 +31,7 @@ class RFunctionObject : public RObject {
   protected:
 	QStringList argnames;
 	QStringList argvalues;
-	bool updateArguments(RData *new_data);
+	bool updateArguments(const RData *new_data);
 };
 
 #endif
diff --git a/rkward/core/rkmodificationtracker.cpp b/rkward/core/rkmodificationtracker.cpp
index eff32c7ad..112ff9685 100644
--- a/rkward/core/rkmodificationtracker.cpp
+++ b/rkward/core/rkmodificationtracker.cpp
@@ -228,7 +228,7 @@ void RKModificationTracker::sendListenerNotification(RObjectListener::Notificati
 	// for child objects will know the object is gone.
 	if (type == RObjectListener::ObjectRemoved) {
 		if (o->isContainer()) {
-			RContainerObject *c = static_cast<RContainerObject *>(o);
+			const auto *c = static_cast<RContainerObject *>(o);
 			for (int i = c->numChildren() - 1; i >= 0; --i) {
 				sendListenerNotification(RObjectListener::ObjectRemoved, c->findChildByIndex(i), 0, 0, nullptr);
 			}
@@ -272,7 +272,7 @@ QModelIndex RKObjectListModel::index(int row, int column, const QModelIndex &par
 		RK_ASSERT(false);
 		return QModelIndex();
 	}
-	RObject *parent_object = static_cast<RObject *>(parent.internalPointer());
+	const RObject *parent_object = static_cast<RObject *>(parent.internalPointer());
 
 	RK_ASSERT(row < parent_object->numChildrenForObjectModel());
 
@@ -292,10 +292,9 @@ QModelIndex RKObjectListModel::parent(const QModelIndex &index) const {
 int RKObjectListModel::rowCount(const QModelIndex &parent) const {
 	RK_TRACE(OBJECTS);
 
-	RObject *parent_object = nullptr;
-	if (parent.isValid()) parent_object = static_cast<RObject *>(parent.internalPointer());
-	else return 2; // the root item
+	if (!parent.isValid()) return 2; // the root item
 
+	const RObject *parent_object = static_cast<RObject *>(parent.internalPointer());
 	if (!parent_object) return 0;
 	return (parent_object->numChildrenForObjectModel());
 }
@@ -310,7 +309,7 @@ QVariant RKObjectListModel::data(const QModelIndex &index, int role) const {
 	RK_TRACE(OBJECTS);
 
 	int col = index.column();
-	RObject *object = static_cast<RObject *>(index.internalPointer());
+	const RObject *object = static_cast<RObject *>(index.internalPointer());
 
 	if (!object) {
 		RK_ASSERT(object);
@@ -360,10 +359,9 @@ QVariant RKObjectListModel::headerData(int section, Qt::Orientation orientation,
 bool RKObjectListModel::hasChildren(const QModelIndex &parent) const {
 	RK_TRACE(OBJECTS);
 
-	RObject *parent_object = nullptr;
-	if (parent.isValid()) parent_object = static_cast<RObject *>(parent.internalPointer());
-	else return true; // the root item
+	if (!parent.isValid()) return true; // the root item
 
+	const RObject *parent_object = static_cast<RObject *>(parent.internalPointer());
 	if (!parent_object) return false;
 	return (parent_object->isType(RObject::Incomplete) || parent_object->numChildrenForObjectModel());
 }
@@ -371,7 +369,7 @@ bool RKObjectListModel::hasChildren(const QModelIndex &parent) const {
 bool RKObjectListModel::canFetchMore(const QModelIndex &parent) const {
 	RK_TRACE(OBJECTS);
 
-	RObject *object = static_cast<RObject *>(parent.internalPointer());
+	const RObject *object = static_cast<RObject *>(parent.internalPointer());
 	return (object && object->isType(RObject::Incomplete));
 }
 
@@ -389,9 +387,9 @@ QModelIndex RKObjectListModel::indexFor(RObject *object) const {
 	if (!object) return QModelIndex();
 	if (object->isType(RObject::NonVisibleObject)) return QModelIndex();
 
-	RObject *parent = object->parentObject();
+	const RObject *parent_object = object->parentObject();
 	// must cast to RObject, here. Else casting to void* and back will confuse the hell out of GCC 4.2
-	if (!parent) {
+	if (!parent_object) {
 		if (object == RObjectList::getObjectList()) {
 			return createIndex(1, 0, static_cast<RObject *>(RObjectList::getObjectList()));
 		} else {
@@ -400,7 +398,7 @@ QModelIndex RKObjectListModel::indexFor(RObject *object) const {
 		}
 	}
 
-	int row = parent->getObjectModelIndexOf(object);
+	int row = parent_object->getObjectModelIndexOf(object);
 	if (row < 0) {
 		RK_ASSERT(false);
 		return QModelIndex();
diff --git a/rkward/core/rkvariable.cpp b/rkward/core/rkvariable.cpp
index 4ef25cecb..0bf6f59c4 100644
--- a/rkward/core/rkvariable.cpp
+++ b/rkward/core/rkvariable.cpp
@@ -116,7 +116,7 @@ void RKVariable::setLength(int len) {
 	dimensions[0] = len;
 }
 
-bool RKVariable::updateType(RData *new_data) {
+bool RKVariable::updateType(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 
 	if (data) {
@@ -214,7 +214,7 @@ void RKVariable::updateDataFromR(RCommandChain *chain) {
 		RK_ASSERT(command->getDataType() == RData::StructureVector);
 		RK_ASSERT(command->getDataLength() == 3);
 
-		RData::RDataStorage top = command->structureVector();
+		const auto top = command->structureVector();
 		const RData *cdata = top.at(0);
 		const RData *levels = top.at(1);
 		const RData *invalids = top.at(2);
@@ -859,11 +859,10 @@ RKVariable::FormattingOptions RKVariable::parseFormattingOptionsString(const QSt
 	formatting_options.precision_mode = FormattingOptions::PrecisionDefault;
 	formatting_options.precision = 0;
 
-	QStringList list = string.split(u'#', Qt::SkipEmptyParts);
-	QString option, parameter;
-	for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it) {
-		option = (*it).section(u':', 0, 0);
-		parameter = (*it).section(u':', 1, 1);
+	const QStringList list = string.split(u'#', Qt::SkipEmptyParts);
+	for (const auto &part : list) {
+		const auto option = part.section(u':', 0, 0);
+		const auto parameter = part.section(u':', 1, 1);
 
 		if (parameter.isEmpty()) continue;
 
diff --git a/rkward/core/rkvariable.h b/rkward/core/rkvariable.h
index f0c73f127..8f9ff44b1 100644
--- a/rkward/core/rkvariable.h
+++ b/rkward/core/rkvariable.h
@@ -133,7 +133,7 @@ class RKVariable : public RObject {
 	/** set numeric values in the given range. Assumes you provide enough values for the range. If internalStorage is String, all values will be converted to strings, so you should use this function only, if you know you are dealing with a numeric object. Code may assume that all data comes directly from R, is entirely valid in R. */
 	void setNumericFromR(int from_row, int to_row, const QVector<double> &data);
 	/** reimplemented from RObject to change the internal data storage mode, if the var is being edited */
-	bool updateType(RData *new_data) override;
+	bool updateType(const RData *new_data) override;
 	/** Extended from RObject::EditData to actually contain data. */
 	struct RKVarEditData {
 		QStringList cell_strings;
diff --git a/rkward/core/robject.cpp b/rkward/core/robject.cpp
index 0f08e1bb5..7c2b100ed 100644
--- a/rkward/core/robject.cpp
+++ b/rkward/core/robject.cpp
@@ -269,7 +269,7 @@ void RObject::updateFromR(RCommandChain *chain) {
 		// .rk.get.structure should be reworked to simply not need the value-argument in any case.
 		commandstring = u".rk.get.structure.global ("_s + rQuote(getShortName()) + u')';
 	} else if (isType(Environment)) {
-		REnvironmentObject *env = static_cast<REnvironmentObject *>(this);
+		const auto *env = static_cast<REnvironmentObject *>(this);
 		if (isType(PackageEnv) && RKSettingsModuleObjectBrowser::isPackageBlacklisted(env->packageName())) {
 			KMessageBox::information(
 			    nullptr,
@@ -328,7 +328,7 @@ void RObject::fetchMoreIfNeeded(int levels) {
 	}
 }
 
-bool RObject::updateStructure(RData *new_data) {
+bool RObject::updateStructure(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	if (new_data->getDataLength() == 0) { // can happen, if the object no longer exists
 		return false;
@@ -343,7 +343,7 @@ bool RObject::updateStructure(RData *new_data) {
 
 	bool properties_change = false;
 
-	RData::RDataStorage new_data_data = new_data->structureVector();
+	const auto &new_data_data = new_data->structureVector();
 	properties_change = updateName(new_data_data.at(StoragePositionName));
 	properties_change |= updateType(new_data_data.at(StoragePositionType));
 	properties_change |= updateClasses(new_data_data.at(StoragePositionClass));
@@ -385,18 +385,18 @@ void RObject::markDataDirty() {
 	}
 }
 
-bool RObject::canAccommodateStructure(RData *new_data) {
+bool RObject::canAccommodateStructure(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() >= StorageSizeBasicInfo);
 	RK_ASSERT(new_data->getDataType() == RData::StructureVector);
 
-	RData::RDataStorage new_data_data = new_data->structureVector();
+	const auto &new_data_data = new_data->structureVector();
 	if (!isValidName(new_data_data.at(StoragePositionName))) return false;
 	if (!isValidType(new_data_data.at(StoragePositionType))) return false;
 	return true;
 }
 
-bool RObject::isValidName(RData *new_data) {
+bool RObject::isValidName(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() == 1);
 	RK_ASSERT(new_data->getDataType() == RData::StringVector);
@@ -410,7 +410,7 @@ bool RObject::isValidName(RData *new_data) {
 	return true;
 }
 
-bool RObject::updateName(RData *new_data) {
+bool RObject::updateName(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() == 1);
 	RK_ASSERT(new_data->getDataType() == RData::StringVector);
@@ -425,7 +425,7 @@ bool RObject::updateName(RData *new_data) {
 	return changed;
 }
 
-bool RObject::isValidType(RData *new_data) const {
+bool RObject::isValidType(const RData *new_data) const {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() == 1);
 	RK_ASSERT(new_data->getDataType() == RData::IntVector);
@@ -436,7 +436,7 @@ bool RObject::isValidType(RData *new_data) const {
 	return true;
 }
 
-bool RObject::updateType(RData *new_data) {
+bool RObject::updateType(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() == 1);
 	RK_ASSERT(new_data->getDataType() == RData::IntVector);
@@ -453,7 +453,7 @@ bool RObject::updateType(RData *new_data) {
 	return changed;
 }
 
-bool RObject::updateClasses(RData *new_data) {
+bool RObject::updateClasses(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() >= 1); // or can there be classless objects in R?
 	RK_ASSERT(new_data->getDataType() == RData::StringVector);
@@ -469,12 +469,12 @@ bool RObject::updateClasses(RData *new_data) {
 	return change;
 }
 
-bool RObject::updateMeta(RData *new_data) {
+bool RObject::updateMeta(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 
 	RK_ASSERT(new_data->getDataType() == RData::StringVector);
 
-	QStringList data = new_data->stringVector();
+	const QStringList data = new_data->stringVector();
 	int len = data.size();
 	bool change = false;
 	if (len) {
@@ -499,7 +499,7 @@ bool RObject::updateMeta(RData *new_data) {
 	return change;
 }
 
-bool RObject::updateDimensions(RData *new_data) {
+bool RObject::updateDimensions(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 	RK_ASSERT(new_data->getDataLength() >= 1);
 	RK_ASSERT(new_data->getDataType() == RData::IntVector);
@@ -522,7 +522,7 @@ bool RObject::updateDimensions(RData *new_data) {
 	return (false);
 }
 
-bool RObject::updateSlots(RData *new_data) {
+bool RObject::updateSlots(const RData *new_data) {
 	RK_TRACE(OBJECTS);
 
 	if (new_data->getDataLength()) {
@@ -648,12 +648,12 @@ void RObject::remove(bool removed_in_workspace) {
 
 	if (isPseudoObject()) {
 		RK_ASSERT(removed_in_workspace);
-		PseudoObjectType type = getPseudoObjectType();
-		if (parent->hasPseudoObject(type)) { // not always true for NamespaceObjects, which the RKOrphanNamespacesObject keeps as regular children!
-			if (type == SlotsObject) slots_objects.remove(parent);
-			else if (type == NamespaceObject) namespace_objects.remove(parent);
-			else if (type == RowNamesObject) rownames_objects.remove(parent);
-			parent->contained_objects -= type;
+		PseudoObjectType potype = getPseudoObjectType();
+		if (parent->hasPseudoObject(potype)) { // not always true for NamespaceObjects, which the RKOrphanNamespacesObject keeps as regular children!
+			if (potype == SlotsObject) slots_objects.remove(parent);
+			else if (potype == NamespaceObject) namespace_objects.remove(parent);
+			else if (potype == RowNamesObject) rownames_objects.remove(parent);
+			parent->contained_objects -= potype;
 			delete this;
 			return;
 		}
@@ -854,7 +854,7 @@ RObject *RObject::globalEnvSymbol() const {
 bool RObject::isInGlobalEnv() const {
 	RK_TRACE(OBJECTS);
 
-	RObject *o = toplevelEnvironment();
+	const RObject *o = toplevelEnvironment();
 	if (o->isType(GlobalEnv)) {
 		if (o != this) return true; // the GlobalEnv is not inside the GlobalEnv!
 	}
diff --git a/rkward/core/robject.h b/rkward/core/robject.h
index b1e9a45c8..f31950c28 100644
--- a/rkward/core/robject.h
+++ b/rkward/core/robject.h
@@ -259,39 +259,39 @@ class RObject {
 
 	/** Update object to reflect the structure passed in the new_data argument. If the data is mismatching (i.e. can not be accommodated by this type of object) false is returned (calls canAccommodateStructure () internally). In this case you should delete the object, and create a new one.
 	@returns true if the changes could be done, false if this  */
-	virtual bool updateStructure(RData *new_data);
+	virtual bool updateStructure(const RData *new_data);
 
 	typedef QMap<QString, QString> MetaMap;
 	MetaMap *meta_map;
 
-	virtual bool canAccommodateStructure(RData *new_data);
-	bool isValidName(RData *new_data);
-	bool isValidType(RData *new_data) const;
+	virtual bool canAccommodateStructure(const RData *new_data);
+	bool isValidName(const RData *new_data);
+	bool isValidType(const RData *new_data) const;
 
 	/** handles updating the object name from the given data (common functionality between RContainerObject and RKVariable. This should really never return true, as the name should never change. Hence also raises an assert. Is still useful for it's side effect of detaching and deleting the data from the RData structure after checking it.
 	@param new_data The data. Make sure it really is the classes field of an .rk.get.structure-command to update classes *before* calling this function! WARNING: the new_data object may get changed during this call. Call canAccommodateStructure () before calling this function!
 	@returns whether this caused any changes */
-	bool updateName(RData *new_data);
+	bool updateName(const RData *new_data);
 	/** update type information from the given data.
 	@param new_data The command. Make sure it really is the classification field of an .rk.get.structure-command to update classes *before* calling this function! WARNING: the new_data object may get changed during this call. Call canAccommodateStructure () before calling this function!
 	@returns whether this caused any changes */
-	virtual bool updateType(RData *new_data);
+	virtual bool updateType(const RData *new_data);
 	/** handles updating class names from the given data (common functionality between RContainerObject and RKVariable
 	@param new_data The data. Make sure it really is the classes field of an .rk.get.structure-command to update classes *before* calling this function! WARNING: the new_data object may get changed during this call. Call canAccommodateStructure () before calling this function!
 	@returns whether this caused any changes */
-	bool updateClasses(RData *new_data);
+	bool updateClasses(const RData *new_data);
 	/** handles updating the meta data from the given data (common functionality between RContainerObject and RKVariable. WARNING: the new_data object may get changed during this call. Call canAccommodateStructure () before calling this function!
 	@param new_data The data. Make sure it really is the meta field of an .rk.get.structure-command to update classes *before* calling this function!
 	@returns whether this caused any changes */
-	bool updateMeta(RData *new_data);
+	bool updateMeta(const RData *new_data);
 	/** update dimension information from the given data.
 	@param new_data The command. Make sure it really is the dims field of an .rk.get.structure-command to update classes *before* calling this function! WARNING: the new_data object may get changed during this call. Call canAccommodateStructure () before calling this function!
 	@returns whether this caused any changes */
-	bool updateDimensions(RData *new_data);
+	bool updateDimensions(const RData *new_data);
 	/** update information on slots of this object (if it is an S4 object)
 	@param new_data The command. Make sure it really is the slots field of an .rk.get.structure-command to update classes *before* calling this function! WARNING: the new_data object may get changed during this call. Call canAccommodateStructure () before calling this function!
 	@returns whether this caused any changes */
-	bool updateSlots(RData *new_data);
+	bool updateSlots(const RData *new_data);
 
 	friend class RKModificationTracker;
 	/** Notify the object that some model needs its data. The object should take care of fetching the data from the backend, unless it already has the data. The default implementation does nothing (raises an assert). */
diff --git a/rkward/core/robjectlist.cpp b/rkward/core/robjectlist.cpp
index e29affd36..869e4fbf7 100644
--- a/rkward/core/robjectlist.cpp
+++ b/rkward/core/robjectlist.cpp
@@ -116,9 +116,9 @@ void RObjectList::updateFromR(RCommandChain *chain) {
 	update_chain = RInterface::startChain(chain);
 
 	RCommand *command = new RCommand(QStringLiteral("list (search (), loadedNamespaces ())"), RCommand::App | RCommand::Sync | RCommand::GetStructuredData);
-	whenCommandFinished(command, [this](RCommand *command) {
+	whenCommandFinished(command, [this](const RCommand *command) {
 		RK_ASSERT(command->getDataType() == RData::StructureVector);
-		const RData::RDataStorage &data = command->structureVector();
+		const auto &data = command->structureVector();
 		RK_ASSERT(data.size() == 2);
 
 		QStringList new_environments = data[0]->stringVector();
@@ -303,7 +303,7 @@ REnvironmentObject *RObjectList::findPackage(const QString &namespacename) const
 	return nullptr;
 }
 
-bool RObjectList::updateStructure(RData *) {
+bool RObjectList::updateStructure(const RData *) {
 	RK_TRACE(OBJECTS);
 
 	RK_ASSERT(false);
diff --git a/rkward/core/robjectlist.h b/rkward/core/robjectlist.h
index ffc0b80e0..e2eb1794f 100644
--- a/rkward/core/robjectlist.h
+++ b/rkward/core/robjectlist.h
@@ -74,7 +74,7 @@ class RObjectList : public QObject, public RContainerObject {
 	QString renameChildCommand(RObject *object, const QString &new_name) const override;
 	/// reimplemented from RContainerObject to Q_EMIT a change signal
 	void objectsChanged();
-	bool updateStructure(RData *new_data) override;
+	bool updateStructure(const RData *new_data) override;
 	void updateEnvironments(const QStringList &env_names, bool force_globalenv_update);
 	void updateNamespaces(const QStringList &namespace_names);
 
diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index 3e494e814..7e0bdb43e 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -407,7 +407,7 @@ void LoadUnloadWidget::updateInstalledPackages() {
 		if (command->failed()) return;
 		RK_ASSERT(command->getDataLength() == 5);
 
-		RData::RDataStorage data = command->structureVector();
+		const auto data = command->structureVector();
 		QStringList package = data.at(0)->stringVector();
 		QStringList title = data.at(1)->stringVector();
 		QStringList version = data.at(2)->stringVector();
@@ -918,15 +918,15 @@ void RKRPackageInstallationStatus::statusCommandFinished(RCommand *command) {
 	RK_ASSERT(command->getDataType() == RCommand::StructureVector);
 	RK_ASSERT(command->getDataLength() == 5);
 
-	RData::RDataStorage top = command->structureVector();
-	RData::RDataStorage available = top[0]->structureVector();
+	const auto top = command->structureVector();
+	const auto available = top[0]->structureVector();
 	available_packages = available[0]->stringVector();
 	available_titles = available[1]->stringVector();
 	available_versions = available[2]->stringVector();
 	available_repos = available[3]->stringVector();
 	enhance_rk_in_available = available[4]->intVector();
 
-	RData::RDataStorage installed = top[1]->structureVector();
+	const auto installed = top[1]->structureVector();
 	installed_packages = installed[0]->stringVector();
 	installed_titles = installed[1]->stringVector();
 	installed_versions = installed[2]->stringVector();
@@ -935,7 +935,7 @@ void RKRPackageInstallationStatus::statusCommandFinished(RCommand *command) {
 	installed_has_update.fill(false, installed_packages.count());
 
 	new_packages_in_available = top[2]->intVector();
-	RData::RDataStorage updateable = top[3]->structureVector();
+	const auto updateable = top[3]->structureVector();
 	updateable_packages_in_installed = updateable[0]->intVector();
 	updateable_packages_in_available = updateable[1]->intVector();
 
diff --git a/rkward/rbackend/rdata.cpp b/rkward/rbackend/rdata.cpp
index 80b4af8e2..29ed14f37 100644
--- a/rkward/rbackend/rdata.cpp
+++ b/rkward/rbackend/rdata.cpp
@@ -86,7 +86,7 @@ void RData::setData(const StringStorage &from) {
 	datatype = RData::StringVector;
 }
 
-void RData::printStructure(const QString &prefix) {
+void RData::printStructure(const QString &prefix) const {
 	if (datatype == NoData) {
 		qDebug("%s: NoData, length %d", prefix.toLatin1().data(), getDataLength());
 	} else if (datatype == IntVector) {
@@ -109,7 +109,7 @@ void RData::printStructure(const QString &prefix) {
 		}
 	} else if (datatype == StructureVector) {
 		qDebug("%s: StructureVector, length %d", prefix.toLatin1().data(), getDataLength());
-		RDataStorage data = structureVector();
+		RDataStorageConst data = structureVector();
 		for (int i = 0; i < data.size(); ++i) {
 			QString sub_prefix = prefix + QString::number(i);
 			data.at(i)->printStructure(sub_prefix);
diff --git a/rkward/rbackend/rdata.h b/rkward/rbackend/rdata.h
index ceb8e49c7..9adb32a86 100644
--- a/rkward/rbackend/rdata.h
+++ b/rkward/rbackend/rdata.h
@@ -27,6 +27,7 @@ class RData {
 	typedef QVector<qint32> IntStorage;
 	typedef QVector<double> RealStorage;
 	typedef QVector<RData *> RDataStorage;
+	typedef QVector<const RData *> RDataStorageConst;
 	typedef QStringList StringStorage;
 	/** returns the type of data contained */
 	RDataType getDataType() const { return datatype; };
@@ -57,16 +58,16 @@ class RData {
 		return StringStorage();
 	}
 	/** returns a vector of RData*, if that is the type of data contained (else, an assert is raised, and an empty vector is returned). Can be used safely on a null RData pointer (but raises an assert in this case). @see RCommand::GetStructureVector @see RData::getDataType () */
-	const RDataStorage structureVector() const {
+	const RDataStorageConst structureVector() const {
 		if (datatype == StructureVector) {
-			return (*static_cast<RDataStorage *>(data));
+			return (*static_cast<RDataStorageConst *>(data));
 		}
 		doAssert(StructureVector);
-		return RDataStorage();
+		return RDataStorageConst();
 	}
 	void discardData();
 	/** purely for debugging! */
-	void printStructure(const QString &prefix);
+	void printStructure(const QString &prefix) const;
 
 	void setData(const RDataStorage &from);
 	void setData(const IntStorage &from);
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index 805d2d381..6600fe48b 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -371,7 +371,7 @@ int RReadConsole(const char *prompt, unsigned char *buf, int buflen, int hist) {
 
 			request_type = RBackendRequest::Debugger;
 			if ((dummy->getDataType() == RData::StructureVector) && (dummy->getDataLength() >= 4)) {
-				RData::RDataStorage dummy_data = dummy->structureVector();
+				const auto &dummy_data = dummy->structureVector();
 				params[QStringLiteral("calls")] = QVariant(dummy_data.at(0)->stringVector());
 				params[QStringLiteral("funs")] = QVariant(dummy_data.at(1)->stringVector());
 				params[QStringLiteral("envs")] = QVariant(dummy_data.at(2)->stringVector());
diff --git a/rkward/rbackend/rktransmitter.cpp b/rkward/rbackend/rktransmitter.cpp
index 78dd3d1e6..65dcd3622 100644
--- a/rkward/rbackend/rktransmitter.cpp
+++ b/rkward/rbackend/rktransmitter.cpp
@@ -99,7 +99,7 @@ void RKRBackendSerializer::serializeData(const RData &data, QDataStream &stream)
 	else if (type == RData::StringVector) stream << data.stringVector();
 	else if (type == RData::RealVector) stream << data.realVector();
 	else if (type == RData::StructureVector) {
-		RData::RDataStorage list = data.structureVector();
+		const auto list = data.structureVector();
 		qint32 len = list.size();
 		stream << len;
 		for (qint32 i = 0; i < list.size(); ++i) {
diff --git a/rkward/scriptbackends/rkcomponentscripting.cpp b/rkward/scriptbackends/rkcomponentscripting.cpp
index 00ed06a8f..90916f931 100644
--- a/rkward/scriptbackends/rkcomponentscripting.cpp
+++ b/rkward/scriptbackends/rkcomponentscripting.cpp
@@ -156,7 +156,7 @@ static QJSValue marshall(QJSEngine *engine, const RData *data) {
 	} else if (data->getDataType() == RData::RealVector) {
 		return (rkJSMakeArray(engine, data->realVector()));
 	} else if (data->getDataType() == RData::StructureVector) {
-		const RData::RDataStorage &rs = data->structureVector();
+		const auto &rs = data->structureVector();
 		QJSValue ret = engine->newArray(rs.size());
 		for (int i = 0; i < rs.size(); ++i) {
 			ret.setProperty(i, marshall(engine, rs[i]));



More information about the rkward-tracker mailing list