[education/rkward] rkward: Clear object model when restarting backend
Thomas Friedrichsmeier
null at kde.org
Sat Jun 4 20:55:53 BST 2022
Git commit be89b0ac05e08afd9bcb4245c8bfe123c97608a2 by Thomas Friedrichsmeier.
Committed on 04/06/2022 at 16:48.
Pushed by tfry into branch 'master'.
Clear object model when restarting backend
M +25 -15 rkward/core/robjectlist.cpp
M +2 -3 rkward/core/robjectlist.h
M +4 -6 rkward/misc/rkobjectlistview.cpp
M +5 -2 rkward/rkward.cpp
https://invent.kde.org/education/rkward/commit/be89b0ac05e08afd9bcb4245c8bfe123c97608a2
diff --git a/rkward/core/robjectlist.cpp b/rkward/core/robjectlist.cpp
index 0e879e70..11c16d0c 100644
--- a/rkward/core/robjectlist.cpp
+++ b/rkward/core/robjectlist.cpp
@@ -1,6 +1,6 @@
/*
robjectlist - This file is part of RKWard (https://rkward.kde.org). Created: Wed Aug 18 2004
-SPDX-FileCopyrightText: 2004-2019 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2004-2022 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
*/
@@ -26,25 +26,23 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include "../debug.h"
// static
-RObjectList *RObjectList::object_list = 0;
+RObjectList *RObjectList::object_list = nullptr;
RObjectList::RObjectList () : RContainerObject (0, QString ()) {
RK_TRACE (OBJECTS);
+ RK_ASSERT(!object_list);
object_list = this;
update_timer = new QTimer (this);
update_timer->setSingleShot (true);
- connect (update_timer, &QTimer::timeout, this, &RObjectList::timeout);
-
- //update_timer->start (AUTO_UPDATE_INTERVAL, true);
-
+ connect(update_timer, &QTimer::timeout, this, [this]() { updateFromR(0); });
+ update_chain = 0;
+
type = RObject::Workspace;
name = "search()";
-
- update_chain = 0;
globalenv = new REnvironmentObject (0, ".GlobalEnv");
- globalenv->updateFromR (update_chain);
+ globalenv->updateFromR(nullptr);
// TODO: Do we really need tracker notification at this stage?
RKOrphanNamespacesObject *obj = new RKOrphanNamespacesObject (this);
@@ -59,6 +57,24 @@ RObjectList::~RObjectList () {
delete globalenv;
}
+// static
+void RObjectList::init() {
+ RK_TRACE(OBJECTS);
+ if (!object_list) {
+ new RObjectList();
+ } else {
+ auto *globalenv = object_list->globalenv; // easier typing
+ for (int i = globalenv->numChildren() - 1; i >= 0; --i) {
+ globalenv->removeChild(globalenv->findChildByIndex(i), true);
+ }
+ object_list->updateEnvironments(QStringList() << ".GlobalEnv", false);
+ object_list->updateNamespaces(QStringList());
+ // TODO: For unkonwn reasons, a ghost object remains inside globalenv in the QSortFilterProxyModel (qt 5.12.8). Get rid of it with a model reset
+ RKModificationTracker::instance()->beginResetModel();
+ RKModificationTracker::instance()->endResetModel();
+ }
+}
+
QString RObjectList::getObjectDescription () const {
return i18n ("This section contains environments that are not part of <i>.GlobalEnv</i> / your \"workspace\". Most importantly, this includes loaded packages, but also objects added to R's <i>search()<i>-path using <i>attach()</i>.");
}
@@ -299,12 +315,6 @@ bool RObjectList::updateStructure (RData *) {
return true;
}
-void RObjectList::timeout () {
- RK_TRACE (OBJECTS);
-
- updateFromR (0);
-}
-
QString RObjectList::renameChildCommand (RObject *object, const QString &new_name) const {
RK_TRACE (OBJECTS);
diff --git a/rkward/core/robjectlist.h b/rkward/core/robjectlist.h
index 6e7ddc0a..24253af0 100644
--- a/rkward/core/robjectlist.h
+++ b/rkward/core/robjectlist.h
@@ -1,6 +1,6 @@
/*
robjectlist - This file is part of the RKWard project. Created: Wed Aug 18 2004
-SPDX-FileCopyrightText: 2004-2019 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2004-2022 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
*/
@@ -50,6 +50,7 @@ public:
static RObjectList *getObjectList () { return object_list; };
static REnvironmentObject *getGlobalEnv () { return object_list->globalenv; };
+ static void init();
/** detach the given list of packages (if the packages are loaded, and safe to remove)
@returns a list of error messages (usually empty) */
@@ -57,8 +58,6 @@ public:
/** A pseudo object containing as children all loaded namespaces which do not belong to a package on the search path */
RKOrphanNamespacesObject* orphanNamespacesObject () const { return orphan_namespaces; };
QString getObjectDescription () const override;
-public slots:
- void timeout ();
signals:
/// emitted when the list of objects is about to be updated // TODO: remove me
void updateStarted ();
diff --git a/rkward/misc/rkobjectlistview.cpp b/rkward/misc/rkobjectlistview.cpp
index 32719db6..1d623abc 100644
--- a/rkward/misc/rkobjectlistview.cpp
+++ b/rkward/misc/rkobjectlistview.cpp
@@ -193,12 +193,10 @@ void RKObjectListView::settingsChanged () {
RK_TRACE (APP);
setRootObject (root_object);
- if (!root_object) {
- setFirstColumnSpanned (0, QModelIndex (), true);
- setItemDelegateForRow (0, rkdelegate);
- setFirstColumnSpanned (1, QModelIndex (), true);
- setItemDelegateForRow (1, rkdelegate);
- }
+ setFirstColumnSpanned (0, QModelIndex (), true);
+ setItemDelegateForRow (0, rkdelegate);
+ setFirstColumnSpanned (1, QModelIndex (), true);
+ setItemDelegateForRow (1, rkdelegate);
resizeColumnToContents (0);
}
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 4d6ef19d..d2a7b870 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -386,7 +386,7 @@ void RKWardMainWindow::startR () {
RInterface::create();
connect(RInterface::instance(), &RInterface::backendStatusChanged, this, &RKWardMainWindow::setRStatus);
- new RObjectList ();
+ RObjectList::init();
RObjectBrowser::mainBrowser ()->unlock ();
}
@@ -615,7 +615,10 @@ void RKWardMainWindow::initActions() {
auto restart_r = actionCollection()->addAction("restart_r");
restart_r->setText(i18n("Restart R Backend"));
connect(restart_r, &QAction::triggered, this, [this]() {
- if (RInterface::instance()->backendIsDead()) startR();
+ if (RInterface::instance()->backendIsDead()) {
+ delete RInterface::instance();
+ startR();
+ }
});
}
More information about the rkward-tracker
mailing list