[rkward/work/workspace_browser_redesign] rkward: In the object item model, make .GlobalEnv a root level item, sibling to the old RObjectList (which will now 'contain' all other toplevel envs, only).

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Nov 5 19:51:50 UTC 2015


Git commit 9cab353ebf8b64051cffee556b0eeaba52b9680f by Thomas Friedrichsmeier.
Committed on 05/11/2015 at 19:38.
Pushed by tfry into branch 'work/workspace_browser_redesign'.

In the object item model, make .GlobalEnv a root level item, sibling to the old RObjectList (which will now 'contain' all other toplevel envs, only).

M  +5    -4    rkward/core/renvironmentobject.cpp
M  +20   -7    rkward/core/rkmodificationtracker.cpp
M  +5    -1    rkward/core/rkmodificationtracker.h
M  +18   -25   rkward/core/robjectlist.cpp
M  +3    -2    rkward/core/robjectlist.h
M  +9    -11   rkward/misc/rkobjectlistview.cpp

http://commits.kde.org/rkward/9cab353ebf8b64051cffee556b0eeaba52b9680f

diff --git a/rkward/core/renvironmentobject.cpp b/rkward/core/renvironmentobject.cpp
index c292041..ac97171 100644
--- a/rkward/core/renvironmentobject.cpp
+++ b/rkward/core/renvironmentobject.cpp
@@ -2,7 +2,7 @@
                           renvironmentobject  -  description
                              -------------------
     begin                : Wed Sep 27 2006
-    copyright            : (C) 2006, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2006, 2009, 2010, 2011, 2015 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -35,11 +35,12 @@ REnvironmentObject::REnvironmentObject (RContainerObject *parent, const QString
 	type = Environment;
 	if (parent == RObjectList::getObjectList ()) {
 		type |= ToplevelEnv;
-		if (name == ".GlobalEnv") {
-			type |= GlobalEnv;
-		} else if (name.contains (':')) {
+		if (name.contains (':')) {
 			type |= PackageEnv;
 		}
+	} else if (parent == 0) {
+		RK_ASSERT (name == ".GlobalEnv");
+		type |= ToplevelEnv | GlobalEnv;
 	}
 }
 
diff --git a/rkward/core/rkmodificationtracker.cpp b/rkward/core/rkmodificationtracker.cpp
index 7a1e3e6..940696a 100644
--- a/rkward/core/rkmodificationtracker.cpp
+++ b/rkward/core/rkmodificationtracker.cpp
@@ -2,7 +2,7 @@
                           rkmodificationtracker  -  description
                              -------------------
     begin                : Tue Aug 31 2004
-    copyright            : (C) 2004-2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2015 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -24,6 +24,7 @@
 #include "../dataeditor/rkvareditmodel.h"
 #include "rcontainerobject.h"
 #include "robjectlist.h"
+#include "renvironmentobject.h"
 #include "../windows/rkworkplace.h"
 #include "../misc/rkstandardicons.h"
 
@@ -269,9 +270,12 @@ RKObjectListModel::~RKObjectListModel () {
 QModelIndex RKObjectListModel::index (int row, int column, const QModelIndex& parent) const {
 	RK_TRACE (OBJECTS);
 	if (!parent.isValid ()) {
-		RK_ASSERT (row == 0);
+		RK_ASSERT (row < 2);
 		// must cast to RObject, here. Else casting to void* and back will confuse the hell out of GCC 4.2
-		return (createIndex (row, column, static_cast<RObject *> (RObjectList::getObjectList ())));
+		if (row == 0) return (createIndex (0, column, static_cast<RObject *> (RObjectList::getGlobalEnv ())));
+		if (row == 1) return (createIndex (1, column, static_cast<RObject *> (RObjectList::getObjectList ())));
+		RK_ASSERT (false);
+		return QModelIndex ();
 	}
 	RObject* parent_object = static_cast<RObject*> (parent.internalPointer ());
 
@@ -286,6 +290,7 @@ QModelIndex RKObjectListModel::parent (const QModelIndex& index) const {
 	if (!index.isValid ()) return QModelIndex ();
 	RObject* child = static_cast<RObject*> (index.internalPointer ());
 	RK_ASSERT (child);
+	if (child == RObjectList::getGlobalEnv ()) return QModelIndex ();
 	return (indexFor (child->parentObject ()));
 }
 
@@ -294,7 +299,7 @@ int RKObjectListModel::rowCount (const QModelIndex& parent) const {
 
 	RObject* parent_object = 0;
 	if (parent.isValid ()) parent_object = static_cast<RObject*> (parent.internalPointer ());
-	else return 1;		// the root item
+	else return 2;       // the root item
 
 	if (!parent_object) return 0;
 	return (parent_object->numChildrenForObjectModel ());
@@ -312,8 +317,8 @@ QVariant RKObjectListModel::data (const QModelIndex& index, int role) const {
 	int col = index.column ();
 	RObject *object = static_cast<RObject*> (index.internalPointer ());
 
-	if ((!object) || (col >= ColumnCount)) {
-		RK_ASSERT (false);
+	if (!object) {
+		RK_ASSERT (object);
 		return QVariant ();
 	}
 
@@ -337,6 +342,7 @@ QVariant RKObjectListModel::data (const QModelIndex& index, int role) const {
 		return object->getObjectDescription ();
 	}
 
+	RK_ASSERT (col < columnCount ());
 	return QVariant ();
 }
 
@@ -389,7 +395,14 @@ QModelIndex RKObjectListModel::indexFor (RObject *object) const {
 
 	RObject *parent = object->parentObject ();
 	// must cast to RObject, here. Else casting to void* and back will confuse the hell out of GCC 4.2
-	if (!parent) return createIndex (0, 0, static_cast<RObject*> (RObjectList::getObjectList ()));
+	if (!parent) {
+		if (object == RObjectList::getObjectList ()) {
+			return createIndex (1, 0, static_cast<RObject*> (RObjectList::getObjectList ()));
+		} else {
+			RK_ASSERT (object == RObjectList::getGlobalEnv ());
+			return createIndex (0, 0, static_cast<RObject*> (RObjectList::getGlobalEnv ()));
+		}
+	}
 
 	int row = parent->getObjectModelIndexOf (object);
 	if (row < 0) {
diff --git a/rkward/core/rkmodificationtracker.h b/rkward/core/rkmodificationtracker.h
index 0ffa1fc..783c2a5 100644
--- a/rkward/core/rkmodificationtracker.h
+++ b/rkward/core/rkmodificationtracker.h
@@ -71,7 +71,11 @@ private:
 	int num_watched_objects;
 };
 
-/** An item model for the RObjectList . Technically this is the base class for RKModificationTracker. The two could be merged, fully, but this way, it's a little easier to see what belongs where, logically. */
+/** An item model for the RObjectList . Technically this is the base class for RKModificationTracker. The two could be merged, fully, but this way, it's a little easier to see what belongs where, logically.
+
+ The object item model is mostly organized exactly like the tree of R objects rooted at RObjectList::getObjectList(). One small difference is that
+ in the item model .GlobalEnv is one child of the root, and the other loaded environments are contained in a sibling to this.
+*/
 class RKObjectListModel : public QAbstractItemModel {
 public:
 	enum Column {
diff --git a/rkward/core/robjectlist.cpp b/rkward/core/robjectlist.cpp
index 953527b..5b74adb 100644
--- a/rkward/core/robjectlist.cpp
+++ b/rkward/core/robjectlist.cpp
@@ -2,7 +2,7 @@
                           robjectlist  -  description
                              -------------------
     begin                : Wed Aug 18 2004
-    copyright            : (C) 2004-2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2015 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -54,20 +54,20 @@ RObjectList::RObjectList () : RContainerObject (0, QString ()) {
 	
 	update_chain = 0;
 
-	RObject *globalenv = createTopLevelEnvironment (".GlobalEnv");
-	RKGlobals::tracker ()->beginAddObject (globalenv, this, 0);	// 1 == first child after GlobalEnv
-	childmap.insert (0, globalenv);
-	RKGlobals::tracker ()->endAddObject (globalenv, this, 0);
+	globalenv = new REnvironmentObject (0, ".GlobalEnv");
+	globalenv->updateFromR (update_chain);
 
+   // TODO: Do we really need tracker notification at this stage?
 	RKOrphanNamespacesObject *obj = new RKOrphanNamespacesObject (this);
-	RKGlobals::tracker ()->beginAddObject (obj, this, 1);	// 1 == first child after GlobalEnv
+	RKGlobals::tracker ()->beginAddObject (obj, this, 0);      // first child after GlobalEnv
 	orphan_namespaces = obj;
-	RKGlobals::tracker ()->endAddObject (obj, this, 1);
+	RKGlobals::tracker ()->endAddObject (obj, this, 0);
 }
 
 RObjectList::~RObjectList () {
 	RK_TRACE (OBJECTS);
 	delete orphan_namespaces;
+	delete globalenv;
 }
 
 QStringList RObjectList::detachPackages (const QStringList &packages, RCommandChain *chain, RKProgressControl* control) {
@@ -170,7 +170,13 @@ void RObjectList::updateEnvironments (const QStringList &env_names, bool force_g
 	for (int i = 0; i < env_names.count (); ++i) {
 		QString name = env_names[i];
 
-		RObject* obj = findChildByName (name);
+		RObject *obj;
+		if (i == 0) {
+			RK_ASSERT (name == ".GlobalEnv");
+			obj = globalenv;
+		} else {
+			obj = findChildByName (name);
+		}
 		if (obj && (i > 0) && (env_names.lastIndexOf (name, i-1) > -1)) {		// duplicate environment names can happen (e.g. if a data.frame is attached multiple times)
 			obj = 0;	// only copy the old item once
 		}
@@ -247,8 +253,10 @@ RObject *RObjectList::findObjects (const QStringList &path, RObjectSearchMap *ma
 	}
 
 	// no namespace given. Search all environments for matches
+	RObject *found = getGlobalEnv ()->findObjects (path, matches, "$");
+	if (found && !matches) return found;
 	for (int i = 0; i < childmap.size (); ++i) {
-		RObject *found = childmap[i]->findObjects (path, matches, "$");
+		found = childmap[i]->findObjects (path, matches, "$");
 		if (found && !matches) return found;
 	}
 	return 0;
@@ -257,7 +265,7 @@ RObject *RObjectList::findObjects (const QStringList &path, RObjectSearchMap *ma
 REnvironmentObject* RObjectList::findPackage (const QString &namespacename) const {
 	RK_TRACE (OBJECTS);
 
-	for (int i = childmap.size () - 1; i >= 1; --i) {	// NOTE: childmap[0] is the .GlobalEnv
+	for (int i = childmap.size () - 1; i >= 0; --i) {
 		RObject* child = childmap[i];
 		if (!child->isType (PackageEnv)) continue;	// Skip Autoloads
 		REnvironmentObject* env = static_cast<REnvironmentObject *> (child);
@@ -294,20 +302,5 @@ QString RObjectList::removeChildCommand (RObject *object) const {
 	return ("remove (" + object->getFullName () + ')');
 }
 
-//static
-REnvironmentObject *RObjectList::getGlobalEnv () {
-	RK_TRACE (OBJECTS);
-
-	RObjectList *list = getObjectList ();
-	RK_ASSERT (list);
-
-	RK_ASSERT (!list->isEmpty ());
-	REnvironmentObject *envobj = static_cast<REnvironmentObject*> (list->childmap[0]);
-	RK_ASSERT (envobj);
-	RK_ASSERT (envobj->isType (RObject::GlobalEnv));
-
-	return envobj;
-}
-
 #include "robjectlist.moc"
 
diff --git a/rkward/core/robjectlist.h b/rkward/core/robjectlist.h
index 9f3e52d..61fc373 100644
--- a/rkward/core/robjectlist.h
+++ b/rkward/core/robjectlist.h
@@ -2,7 +2,7 @@
                           robjectlist  -  description
                              -------------------
     begin                : Wed Aug 18 2004
-    copyright            : (C) 2004-2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2015 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -60,7 +60,7 @@ public:
 	REnvironmentObject* findPackage (const QString &namespacename) const;
 
 	static RObjectList *getObjectList () { return object_list; };
-	static REnvironmentObject *getGlobalEnv ();
+	static REnvironmentObject *getGlobalEnv () { return object_list->globalenv; };
 
 	/** detach the given list of packages (if the packages are loaded, and safe to remove)
 	@returns a list of error messages (usually empty) */
@@ -98,6 +98,7 @@ private:
 
 	REnvironmentObject *createTopLevelEnvironment (const QString &name);
 
+	REnvironmentObject *globalenv;
 	static RObjectList *object_list;
 };
 
diff --git a/rkward/misc/rkobjectlistview.cpp b/rkward/misc/rkobjectlistview.cpp
index 95d6b76..3dc8b8a 100644
--- a/rkward/misc/rkobjectlistview.cpp
+++ b/rkward/misc/rkobjectlistview.cpp
@@ -2,7 +2,7 @@
                           rkobjectlistview  -  description
                              -------------------
     begin                : Wed Sep 1 2004
-    copyright            : (C) 2004-2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2015 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -66,17 +66,12 @@ void RKObjectListView::setObjectCurrent (RObject *object, bool only_if_none_curr
 void RKObjectListView::setRootObject (RObject *root) {
 	RK_TRACE (APP);
 
-	if (!root) return;
 	root_object = root;
-	if (root == RObjectList::getObjectList () && !settings->getSetting (RKObjectListViewSettings::ShowObjectsAllEnvironments)) root = RObjectList::getGlobalEnv ();
+	if (!root && !settings->getSetting (RKObjectListViewSettings::ShowObjectsAllEnvironments)) root = RObjectList::getGlobalEnv ();
 	QModelIndex index = settings->mapFromSource (RKGlobals::tracker ()->indexFor (root));
-	if (index.isValid ()) {
-		if (index != rootIndex ()) {
-			setRootIndex (index);
-			resizeColumnToContents (0);
-		}
-	} else {
-		RK_ASSERT (false);
+	if (index != rootIndex ()) {
+		setRootIndex (index);
+		settingsChanged ();    // Updates column sizes. Note: Recurses into this function, but with index == rootIndex()
 	}
 }
 
@@ -132,7 +127,6 @@ void RKObjectListView::initialize () {
 	setModel (settings);
 
 	QModelIndex genv = settings->mapFromSource (RKGlobals::tracker ()->indexFor (RObjectList::getGlobalEnv ()));
-	setRootObject (RObjectList::getObjectList ());
 	setExpanded (genv, true);
 	setMinimumHeight (rowHeight (genv) * 5);
 	settingsChanged ();
@@ -161,6 +155,10 @@ void RKObjectListView::settingsChanged () {
 	RK_TRACE (APP);
 
 	setRootObject (root_object);
+	if (!root_object) {
+		setFirstColumnSpanned (0, QModelIndex (), true);
+		setFirstColumnSpanned (1, QModelIndex (), true);
+	}
 	resizeColumnToContents (0);
 }
 



More information about the rkward-tracker mailing list