[education/rkward] rkward: Address several (random) cppcheck warnings
Thomas Friedrichsmeier
null at kde.org
Sat Jan 31 08:17:04 GMT 2026
Git commit f6d6b1e268a97fa8b25dc9e26fd0937dd3b03c99 by Thomas Friedrichsmeier.
Committed on 31/01/2026 at 08:16.
Pushed by tfry into branch 'master'.
Address several (random) cppcheck warnings
M +2 -2 rkward/autotests/core_test.cpp
M +1 -1 rkward/core/rkmodificationtracker.cpp
M +5 -5 rkward/core/rkvariable.cpp
M +2 -2 rkward/core/rkvariable.h
M +4 -6 rkward/core/robject.cpp
M +2 -2 rkward/core/robject.h
M +2 -2 rkward/core/robjectlist.cpp
M +1 -1 rkward/core/robjectlist.h
M +0 -1 rkward/dataeditor/rkeditordataframe.cpp
M +1 -1 rkward/dialogs/rkloadlibsdialog.cpp
M +4 -4 rkward/misc/rkaccordiontable.cpp
M +1 -2 rkward/misc/rkparsedscript.h
M +1 -1 rkward/rkconsole.cpp
M +1 -1 rkward/robjectviewer.cpp
https://invent.kde.org/education/rkward/-/commit/f6d6b1e268a97fa8b25dc9e26fd0937dd3b03c99
diff --git a/rkward/autotests/core_test.cpp b/rkward/autotests/core_test.cpp
index a4f6f644c..cec53ed37 100644
--- a/rkward/autotests/core_test.cpp
+++ b/rkward/autotests/core_test.cpp
@@ -605,7 +605,7 @@ class RKWardCoreTest : public QObject {
void RKConsoleHistoryTest() {
QTemporaryFile oldhist;
QTemporaryFile emptyhist;
- emptyhist.open();
+ QVERIFY(emptyhist.open());
emptyhist.close();
RInterface::issueCommand(new RCommand(u"savehistory("_s + RObject::rQuote(oldhist.fileName()) + u"); loadhistory("_s + RObject::rQuote(emptyhist.fileName()) + u")"_s, RCommand::App));
waitForAllFinished();
@@ -676,7 +676,7 @@ class RKWardCoreTest : public QObject {
// pretty basic check: don't crash or assert on opening script window
QTemporaryFile f;
- f.open();
+ QVERIFY(f.open());
f.write("plot(1,1)\n"); // Using a plot(), here is interesting in that it a) allows a plot preview b) a plot will also be generated, and
// immediately discarded for R console previews, which used to be prone to crashing
f.close();
diff --git a/rkward/core/rkmodificationtracker.cpp b/rkward/core/rkmodificationtracker.cpp
index 9e559d375..eff32c7ad 100644
--- a/rkward/core/rkmodificationtracker.cpp
+++ b/rkward/core/rkmodificationtracker.cpp
@@ -334,7 +334,7 @@ QVariant RKObjectListModel::data(const QModelIndex &index, int role) const {
} else if (role == Qt::DecorationRole) {
if (col == NameColumn) return RKStandardIcons::iconForObject(object);
} else if (role == Qt::ToolTipRole) {
- QString ret = u"<i>"_s + object->getShortName().replace(u'<', u"<"_s) + u"</i><br>"_s + object->getObjectDescription();
+ QString ret = u"<i>"_s + object->getShortName().toHtmlEscaped() + u"</i><br>"_s + object->getObjectDescription();
return ret;
}
diff --git a/rkward/core/rkvariable.cpp b/rkward/core/rkvariable.cpp
index 538c5fda5..4ef25cecb 100644
--- a/rkward/core/rkvariable.cpp
+++ b/rkward/core/rkvariable.cpp
@@ -205,7 +205,7 @@ void RKVariable::updateDataFromR(RCommandChain *chain) {
if (!data) return;
RCommand *c = new RCommand(u".rk.get.vector.data ("_s + getFullName() + u')', RCommand::App | RCommand::Sync | RCommand::GetStructuredData);
- whenCommandFinished(c, [this](RCommand *command) {
+ whenCommandFinished(c, [this](const RCommand *command) {
if (!data) return; // this can happen, if the editor is closed while a data update is still queued.
// prevent resyncing of data
@@ -215,9 +215,9 @@ void RKVariable::updateDataFromR(RCommandChain *chain) {
RK_ASSERT(command->getDataLength() == 3);
RData::RDataStorage top = command->structureVector();
- RData *cdata = top.at(0);
- RData *levels = top.at(1);
- RData *invalids = top.at(2);
+ const RData *cdata = top.at(0);
+ const RData *levels = top.at(1);
+ const RData *invalids = top.at(2);
// set factor levels first
RK_ASSERT(levels->getDataType() == RData::StringVector);
@@ -323,7 +323,7 @@ void RKVariable::restore(RCommandChain *chain) {
writeMetaData(chain);
}
-void RKVariable::writeInvalidFields(QList<int> rows, RCommandChain *chain) {
+void RKVariable::writeInvalidFields(const QList<int> &rows, RCommandChain *chain) {
RK_TRACE(OBJECTS);
if (rows.isEmpty()) return;
diff --git a/rkward/core/rkvariable.h b/rkward/core/rkvariable.h
index eae165a44..f0c73f127 100644
--- a/rkward/core/rkvariable.h
+++ b/rkward/core/rkvariable.h
@@ -28,7 +28,7 @@ class RKVariable : public RObject {
/** constructs a new RKVariable as a child of the given parent and with the given name. Do not call directly, but let RContainerObject / RObjectList handle creation of new variables. */
RKVariable(RContainerObject *parent, const QString &name);
- ~RKVariable();
+ ~RKVariable() override;
/** set the VarType. If sync, the change will be communicated to the backend immediately. See RObject::RDataType */
void setVarType(RObject::RDataType, bool sync = true);
@@ -173,7 +173,7 @@ class RKVariable : public RObject {
void cellsChanged(int from_row, int to_row);
/** writes the given range of cells to the backend (regardless of whether syncing should be immediate) */
virtual void writeData(int from_row, int to_row, RCommandChain *chain = nullptr);
- void writeInvalidFields(QList<int> rows, RCommandChain *chain = nullptr);
+ void writeInvalidFields(const QList<int> &rows, RCommandChain *chain = nullptr);
/** writes the values labels to the backend */
void writeValueLabels(RCommandChain *chain) const;
diff --git a/rkward/core/robject.cpp b/rkward/core/robject.cpp
index 85732fc6e..0f08e1bb5 100644
--- a/rkward/core/robject.cpp
+++ b/rkward/core/robject.cpp
@@ -156,16 +156,14 @@ QString RObject::getDescription() const {
QString RObject::getObjectDescription() const {
RK_TRACE(OBJECTS);
-#define ESCS replace(u'<', u"<"_s)
-
- QString ret = u"<b>"_s + i18n("Full location:") + u" </b>"_s + getFullName().ESCS;
+ QString ret = u"<b>"_s + i18n("Full location:") + u" </b>"_s + getFullName().toHtmlEscaped();
QString lab = getLabel();
- if (!lab.isEmpty()) ret.append(u"<br><b>"_s + i18n("Label:") + u" </b>"_s + lab.ESCS);
+ if (!lab.isEmpty()) ret.append(u"<br><b>"_s + i18n("Label:") + u" </b>"_s + lab.toHtmlEscaped());
ret.append(u"<br><b>"_s + i18n("Type:") + u" </b>"_s);
if (isType(Function)) {
ret.append(i18n("Function"));
- ret.append(u"<br><b>"_s + i18n("Usage: ") + u" </b>"_s + getShortName().ESCS + u'(' + static_cast<const RFunctionObject *>(this)->printArgs().ESCS + u')');
+ ret.append(u"<br><b>"_s + i18n("Usage: ") + u" </b>"_s + getShortName().toHtmlEscaped() + u'(' + static_cast<const RFunctionObject *>(this)->printArgs().toHtmlEscaped() + u')');
} else if (isType(DataFrame)) {
ret.append(i18n("Data frame"));
} else if (isType(Array)) {
@@ -192,7 +190,7 @@ QString RObject::getObjectDescription() const {
}
}
- if (!isType(Function)) ret.append(u"<br><b>"_s + i18n("Class(es):") + u" </b>"_s + makeClassString(u","_s).ESCS);
+ if (!isType(Function)) ret.append(u"<br><b>"_s + i18n("Class(es):") + u" </b>"_s + makeClassString(u","_s).toHtmlEscaped());
return ret;
}
diff --git a/rkward/core/robject.h b/rkward/core/robject.h
index 81d53f065..b1e9a45c8 100644
--- a/rkward/core/robject.h
+++ b/rkward/core/robject.h
@@ -104,7 +104,7 @@ class RObject {
/** @returns false if an object of the given old type cannot represent an object of the given new type (e.g. (new_type & RObjectType::Variable), but (old_type & RObjectType::Container)). */
static bool isMatchingType(int old_type, int new_type) { return ((old_type & ROBJECT_TYPE_INTERNAL_MASK) == (new_type & ROBJECT_TYPE_INTERNAL_MASK)); };
- QString getShortName() const { return name; };
+ const QString &getShortName() const { return name; };
enum ObjectNameOptions {
DollarExpansion = 1, /**< Return list members as list$member, instead of list[["member"]] */
IncludeEnvirIfNotGlobalEnv = 2, /**< Include package name for objects on the search path */
@@ -223,7 +223,7 @@ class RObject {
/** Representation of changes to an edited object (currently for vector data, only) */
struct ChangeSet {
- ChangeSet(int from = -1, int to = -1, bool reset = false) : from_index(from), to_index(to), full_reset(reset) {};
+ explicit ChangeSet(int from = -1, int to = -1, bool reset = false) : from_index(from), to_index(to), full_reset(reset) {};
int from_index; /**< first changed index */
int to_index; /**< last changed index */
bool full_reset; /**< Model should do a full reset (e.g. dimensions may have changed) */
diff --git a/rkward/core/robjectlist.cpp b/rkward/core/robjectlist.cpp
index f1074345e..e29affd36 100644
--- a/rkward/core/robjectlist.cpp
+++ b/rkward/core/robjectlist.cpp
@@ -60,7 +60,7 @@ void RObjectList::init() {
if (!object_list) {
new RObjectList();
} else {
- auto *globalenv = object_list->globalenv; // easier typing
+ const auto *globalenv = object_list->globalenv; // easier typing
for (int i = globalenv->numChildren() - 1; i >= 0; --i) {
auto obj = globalenv->findChildByIndex(i);
RK_ASSERT(obj->editors().isEmpty());
@@ -155,7 +155,7 @@ void RObjectList::updateFromR(RCommandChain *chain, const QStringList ¤t_s
void RObjectList::makeUpdateCompleteCallback() {
RK_TRACE(OBJECTS);
RCommand *command = new RCommand(QString(), RCommand::App | RCommand::Sync | RCommand::EmptyCommand);
- whenCommandFinished(command, [this](RCommand *) {
+ whenCommandFinished(command, [this](const RCommand *) {
RK_ASSERT(update_chain);
RInterface::closeChain(update_chain);
update_chain = nullptr;
diff --git a/rkward/core/robjectlist.h b/rkward/core/robjectlist.h
index 63990197f..ffc0b80e0 100644
--- a/rkward/core/robjectlist.h
+++ b/rkward/core/robjectlist.h
@@ -35,7 +35,7 @@ class RObjectList : public QObject, public RContainerObject {
Q_OBJECT
public:
RObjectList();
- ~RObjectList();
+ ~RObjectList() override;
void updateFromR(RCommandChain *chain) override;
/** like updateFromR, but only adjusts to new / missing environments, but does not update the .GlobalEnv. Designed to be used from the backend, when packages were loaded/unloaded . */
diff --git a/rkward/dataeditor/rkeditordataframe.cpp b/rkward/dataeditor/rkeditordataframe.cpp
index 4c409df78..ec9f10bae 100644
--- a/rkward/dataeditor/rkeditordataframe.cpp
+++ b/rkward/dataeditor/rkeditordataframe.cpp
@@ -28,7 +28,6 @@ RKEditorDataFrame::RKEditorDataFrame(RContainerObject *object, QWidget *parent)
commonInit();
RK_ASSERT(!object->isPending());
- RKEditor::object = object;
RK_ASSERT(object->isDataFrame());
setGlobalContextProperty(QStringLiteral("current_object"), object->getFullName());
setGlobalContextProperty(QStringLiteral("current_dataframe"), object->getFullName());
diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index 53de8b58d..3e494e814 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -595,7 +595,7 @@ class InstallPackagesDelegate : public QStyledItemDelegate {
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override {
if ((!index.parent().isValid()) && (index.data(Qt::UserRole) == RKRPackageInstallationStatus::UpdateablePackages)) {
if ((event->type() == QEvent::MouseButtonRelease) || (event->type() == QEvent::MouseButtonPress)) {
- QMouseEvent *e = (QMouseEvent *)event;
+ QMouseEvent *e = static_cast<QMouseEvent *>(event);
QRect r = option.rect; // rect of the entire cell
r.setLeft(r.left() + r.width() / 2);
if (r.contains(e->pos())) {
diff --git a/rkward/misc/rkaccordiontable.cpp b/rkward/misc/rkaccordiontable.cpp
index 0da24785c..fac0a176d 100644
--- a/rkward/misc/rkaccordiontable.cpp
+++ b/rkward/misc/rkaccordiontable.cpp
@@ -215,8 +215,9 @@ class RKWidgetGuard : public QWidget {
/** Responsible for drawing expand / collapse indicators in first column */
class RKAccordionDelegate : public QStyledItemDelegate {
public:
- explicit RKAccordionDelegate(RKAccordionTable *parent) : QStyledItemDelegate(parent) {
- table = parent;
+ explicit RKAccordionDelegate(RKAccordionTable *parent, RKAccordionDummyModel *pmodel) : QStyledItemDelegate(parent),
+ table(parent),
+ pmodel(pmodel) {
expanded = RKStandardIcons::getIcon(RKStandardIcons::ActionCollapseUp);
collapsed = RKStandardIcons::getIcon(RKStandardIcons::ActionExpandDown);
}
@@ -264,8 +265,7 @@ RKAccordionTable::RKAccordionTable(QWidget *parent) : QTreeView(parent) {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
pmodel = new RKAccordionDummyModel(this);
- RKAccordionDelegate *delegate = new RKAccordionDelegate(this);
- delegate->pmodel = pmodel;
+ RKAccordionDelegate *delegate = new RKAccordionDelegate(this, pmodel);
setItemDelegateForColumn(0, delegate);
connect(this, &QTreeView::expanded, this, &RKAccordionTable::rowExpanded);
diff --git a/rkward/misc/rkparsedscript.h b/rkward/misc/rkparsedscript.h
index d4d0cb2a0..2912d3fa1 100644
--- a/rkward/misc/rkparsedscript.h
+++ b/rkward/misc/rkparsedscript.h
@@ -47,8 +47,7 @@ class RKParsedScript {
};
struct Context {
- Context(ContextType type, int start) : type(type), start(start) {};
- Context(ContextType type, int start, int end) : type(type), start(start), end(end) {};
+ Context(ContextType type, int start, int end = -1) : type(type), start(start), end(end) {};
bool maybeNesting() const { return (type == Parenthesis || type == Brace || type == Bracket || type == Top); };
ContextType type;
int start;
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 24613e0ce..9134e5e21 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -456,7 +456,7 @@ void RKConsole::submitCommand() {
current_command = new RCommand(command, RCommand::User | RCommand::Console);
connect(current_command->notifier(), &RCommandNotifier::commandOutput, this, &RKConsole::newOutput);
connect(current_command->notifier(), &RCommandNotifier::commandLineIn, this, &RKConsole::userCommandLineIn);
- current_command->whenFinished(this, [this](RCommand *command) {
+ current_command->whenFinished(this, [this](const RCommand *command) {
RK_TRACE(APP);
current_command = nullptr;
diff --git a/rkward/robjectviewer.cpp b/rkward/robjectviewer.cpp
index 436778140..a462a351d 100644
--- a/rkward/robjectviewer.cpp
+++ b/rkward/robjectviewer.cpp
@@ -121,7 +121,7 @@ void RObjectViewer::initDescription(bool notify) {
setCaption(i18n("Object Viewer: %1", _object->getShortName()));
// make the description use less height. Trying to specify <nobr>s, here, is no good idea (see http://sourceforge.net/p/rkward/bugs/55/)
- description_label->setText(u"<i>"_s + _object->getShortName().replace(u'<', u"<"_s) + u"</i> "_s +
+ description_label->setText(u"<i>"_s + _object->getShortName().toHtmlEscaped() + u"</i> "_s +
_object->getObjectDescription().replace(u"<br>"_s, u" "_s));
if (notify) {
QString reason = i18n("The object was changed. You may want to click \"Update\"");
More information about the rkward-tracker
mailing list