[rkward-cvs] SF.net SVN: rkward:[2871] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Jun 2 15:45:27 UTC 2010


Revision: 2871
          http://rkward.svn.sourceforge.net/rkward/?rev=2871&view=rev
Author:   tfry
Date:     2010-06-02 15:45:27 +0000 (Wed, 02 Jun 2010)

Log Message:
-----------
Start adding support for row names to the data editor. Read-only support should work, already.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/core/CMakeLists.txt
    trunk/rkward/rkward/core/rcontainerobject.cpp
    trunk/rkward/rkward/core/rcontainerobject.h
    trunk/rkward/rkward/core/rkmodificationtracker.cpp
    trunk/rkward/rkward/core/robject.cpp
    trunk/rkward/rkward/core/robject.h
    trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
    trunk/rkward/rkward/dataeditor/rkvareditmodel.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/ChangeLog	2010-06-02 15:45:27 UTC (rev 2871)
@@ -1,5 +1,6 @@
 TODO: Do not use SmartInterface for KDE 4.5 and above
 
+- Fixed: Would crash when trying to configure toolbars under certain circumstances (workaround for bug in kdelibs)
 - Fixed: Crash while analysing some objects returned by XML::xmlParseTree() for invalid XML
 - Fixed: Error while installing packages with R 2.11.0, when archiving packages in a non-existing directory
 - Add option to autosave script files (enabled by default)

Modified: trunk/rkward/rkward/core/CMakeLists.txt
===================================================================
--- trunk/rkward/rkward/core/CMakeLists.txt	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/core/CMakeLists.txt	2010-06-02 15:45:27 UTC (rev 2871)
@@ -11,6 +11,7 @@
    rkmodificationtracker.cpp
    rfunctionobject.cpp
    renvironmentobject.cpp
+   rkrownames.cpp
    )
 
 QT4_AUTOMOC(${core_STAT_SRCS})

Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp	2010-06-02 15:45:27 UTC (rev 2871)
@@ -2,7 +2,7 @@
                           rcontainerobject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004, 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -23,6 +23,7 @@
 #include "rkvariable.h"
 #include "rfunctionobject.h"
 #include "renvironmentobject.h"
+#include "rkrownames.h"
 
 #include "../rkglobals.h"
 #include "rkmodificationtracker.h"
@@ -32,6 +33,7 @@
 RContainerObject::RContainerObject (RContainerObject *parent, const QString &name) : RObject (parent, name) {
 	RK_TRACE (OBJECTS);
 	type = Container;
+	rownames_object = 0;
 }
 
 RContainerObject::~RContainerObject () {
@@ -41,6 +43,7 @@
 	for (int i = childmap.size () - 1; i >= 0; --i) {
 		delete childmap[i];
 	}
+	delete rownames_object;
 }
 
 RObject *RContainerObject::updateChildStructure (RObject *child, RData *new_data, bool just_created) {
@@ -87,6 +90,7 @@
 		RData *children_sub = new_data->getStructureVector ()[5];
 		RK_ASSERT (children_sub->getDataType () == RData::StructureVector);
 		updateChildren (children_sub);
+		updateRowNamesObject ();
 	} else {
 		RK_ASSERT (false);
 	}
@@ -235,6 +239,30 @@
 	return 0;
 }
 
+RKRowNames* RContainerObject::rowNames () {
+	RK_TRACE (OBJECTS);
+
+	if (!rownames_object) {
+		rownames_object = new RKRowNames (this);
+		updateRowNamesObject ();
+	}
+	return rownames_object;
+}
+
+void RContainerObject::updateRowNamesObject () {
+	RK_TRACE (OBJECTS);
+
+	if (!rownames_object) return;
+
+	int childlen = 0;
+	if (!childmap.isEmpty ()) childlen = childmap[0]->getLength ();
+	rownames_object->dimensions[0] = childlen;
+
+	if (rownames_object->isType (NeedDataUpdate)) {
+		rownames_object->updateDataFromR (0);
+	}
+}
+
 int RContainerObject::getIndexOf (RObject *child) const {
 	RK_TRACE (OBJECTS);
 

Modified: trunk/rkward/rkward/core/rcontainerobject.h
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.h	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/core/rcontainerobject.h	2010-06-02 15:45:27 UTC (rev 2871)
@@ -2,7 +2,7 @@
                           rcontainerobject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -21,6 +21,7 @@
 
 class RCommand;
 class RKEditor;
+class RKRowNames;
 
 /**
 Internal representation of objects in the R-workspace that contain other objects
@@ -78,9 +79,15 @@
 	void beginEdit () {};
 	/** see beginEdit() */
 	void endEdit () {};
+	/** return an RKVariable representing the row-names object for this container */
+	RKRowNames* rowNames ();
+private:
+	/** usually, we do not update the structure of the row.names() from R, as it is always the same. However, we may need to adjust the length, and this hack does that. */
+	void updateRowNamesObject ();
 protected:
 	void updateChildren (RData *new_children);
 	RObjectMap childmap;
+	RKRowNames *rownames_object;
 	// why do I need this to make it compile?!
 	friend class RObjectList;
 	friend class RObject;

Modified: trunk/rkward/rkward/core/rkmodificationtracker.cpp
===================================================================
--- trunk/rkward/rkward/core/rkmodificationtracker.cpp	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/core/rkmodificationtracker.cpp	2010-06-02 15:45:27 UTC (rev 2871)
@@ -2,7 +2,7 @@
                           rkmodificationtracker  -  description
                              -------------------
     begin                : Tue Aug 31 2004
-    copyright            : (C) 2004, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -341,6 +341,7 @@
 	RK_TRACE (OBJECTS);
 
 	if (!object) return QModelIndex ();
+	if (object->isType (RObject::NonVisibleObject)) return QModelIndex ();
 
 	RContainerObject *parent = object->getContainer ();
 	// must cast to RObject, here. Else casting to void* and back will confuse the hell out of GCC 4.2

Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/core/robject.cpp	2010-06-02 15:45:27 UTC (rev 2871)
@@ -2,7 +2,7 @@
                           robject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004, 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -29,6 +29,7 @@
 #include "renvironmentobject.h"
 #include "rfunctionobject.h"
 #include "rkmodificationtracker.h"
+#include "rkrownames.h"
 
 #include "../debug.h"
 
@@ -314,7 +315,6 @@
 	type -= (type & NeedDataUpdate);
 }
 
-#warning probably we do not really need this. Rather we should always call updateDataFromR recursively, and that will take care of things. (make sure not to overwrite pending changes, though)
 void RObject::markDataDirty () {
 	RK_TRACE (OBJECTS);
 
@@ -324,6 +324,7 @@
 		for (int i = children.size () - 1; i >= 0; --i) {
 			children[i]->markDataDirty ();
 		}
+		static_cast<RContainerObject*> (this)->rownames_object->markDataDirty ();
 	}
 }
 

Modified: trunk/rkward/rkward/core/robject.h
===================================================================
--- trunk/rkward/rkward/core/robject.h	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/core/robject.h	2010-06-02 15:45:27 UTC (rev 2871)
@@ -2,7 +2,7 @@
                           robject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004, 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -45,25 +45,26 @@
 /** types of objects, RKWard knows about */
 	enum RObjectType {
 		DataFrame=1,
-		Matrix=2,
-		Array=4,
-		List=8,
-		Container=16,
-		Variable=32,
-		Workspace=64,
-		Function=128,
-		Environment=256,
-		GlobalEnv=512,
-		ToplevelEnv=1024,
-		PackageEnv=2048,
-		HasMetaObject=4096,
-		Misplaced=8192,		/** < the object is not in the namespace where it would be expected */
+		Matrix=1 << 1,
+		Array=1 << 2,
+		List=1 << 3,
+		Container=1 << 4,
+		Variable=1 << 5,
+		Workspace=1 << 6,
+		Function=1 << 7,
+		Environment=1 << 8,
+		GlobalEnv=1 << 9,
+		ToplevelEnv=1 << 10,
+		PackageEnv=1 << 11,
+		HasMetaObject=1 << 12,
+		Misplaced=1 << 13,		/** < the object is not in the namespace where it would be expected */
 		Numeric=1 << 14,
 		Factor=2 << 14,
 		Character=3 << 14,
 		Logical=4 << 14,
 		DataTypeMask=Numeric | Factor | Character | Logical,
-		NeedDataUpdate=1 << 30,	/** < the object's data should be (re-) fetched from R */
+		NonVisibleObject=1 << 29,	/** < the object is not listed in the object list. Currently, this is only the case for row.names()-objects */
+		NeedDataUpdate=1 << 30,	/** < the object's data should be (re-) fetched from R. The main purpose of this flag is to make sure the data is synced *after* the structure has been synced */
 		Pending=1 << 31		/** < the object is pending, i.e. it has been created in the object list, but we have not seen it in R, yet. This is used by data editors to create the illusion that a new object was added immediately, while in fact it takes some time to create it in the backend. */
 	};
 

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-02 15:45:27 UTC (rev 2871)
@@ -23,6 +23,7 @@
 
 #include "../core/rcontainerobject.h"
 #include "../core/rkmodificationtracker.h"
+#include "../core/rkrownames.h"
 #include "../rbackend/rinterface.h"
 #include "../rkglobals.h"
 
@@ -99,6 +100,12 @@
 void RKVarEditModel::objectDataChanged (RObject* object, const RObject::ChangeSet *changes) {
 	RK_TRACE (EDITOR);
 
+	if (object == rownames) {
+		RK_ASSERT (changes);
+		emit (headerDataChanged (Qt::Vertical, changes->from_index, changes->to_index));
+		return;
+	}
+
 	int cindex = objects.indexOf (static_cast<RKVariable*> (object));	// no check for isVariable needed. we only need to look up, if we have this object, and where.
 	if (cindex < 0) return;	// none of our buisiness
 
@@ -137,6 +144,7 @@
 // TODO: this does not emit any data change notifications to other editors
 		objects[i]->insertRows (row, count);
 	}
+	rownames->insertRows (row, count);
 	doInsertRowsInBackend (row, count);
 	endInsertRows ();
 
@@ -300,7 +308,10 @@
 		return objects[section]->getShortName ();
 	}
 
-	return QString::number (section + 1);
+	if (section < rownames->getLength ()) {
+		return rownames->getText (section);
+	}
+	return QVariant ();
 }
 
 RKTextMatrix RKVarEditModel::getTextMatrix (const QItemSelectionRange& range) const {
@@ -719,12 +730,15 @@
 		RK_ASSERT (obj->isVariable ());
 		addObject (i, static_cast<RKVariable*> (obj));
 	}
+	rownames = dataframe->rowNames ();
+	listenForObject (rownames);
 }
 
 RKVarEditDataFrameModel::~RKVarEditDataFrameModel () {
 	RK_TRACE (EDITOR);
 
 	if (dataframe) stopListenForObject (dataframe);
+	if (rownames) stopListenForObject (rownames);
 }
 
 bool RKVarEditDataFrameModel::insertColumns (int column, int count, const QModelIndex& parent) {

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.h	2010-06-02 15:44:07 UTC (rev 2870)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.h	2010-06-02 15:45:27 UTC (rev 2871)
@@ -2,7 +2,7 @@
                           rkvareditmodel  -  description
                              -------------------
     begin                : Mon Nov 05 2007
-    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    copyright            : (C) 2007, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -29,6 +29,7 @@
 class RKVarEditMetaModel;
 class RCommandChain;
 class RKEditor;
+class RKRowNames;
 
 /** Base class for RKVarEditModel and RKVarEditMetaModel. Defines a common interface for copy and paste operations. Models might reimplement these functions for more efficiency.
 @author Thomas Friedrichsmeier */
@@ -92,6 +93,7 @@
 protected:
 friend class RKVarEditMetaModel;
 	QList<RKVariable*> objects;
+	RKRowNames *rownames;
 
 	/** very simple convenience function to return the number of true cols + trailing cols */
 	int apparentCols () const { return (trueCols () + trailing_cols); };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list