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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Mar 7 12:39:51 UTC 2007


Revision: 1544
          http://svn.sourceforge.net/rkward/?rev=1544&view=rev
Author:   tfry
Date:     2007-03-07 04:39:51 -0800 (Wed, 07 Mar 2007)

Log Message:
-----------
Fix changing variable types from editor

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/TODO
    trunk/rkward/rkward/core/rkvariable.cpp
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-03-06 14:44:05 UTC (rev 1543)
+++ trunk/rkward/ChangeLog	2007-03-07 12:39:51 UTC (rev 1544)
@@ -1,3 +1,4 @@
+- fixed: changing the type of a column in the data editor was broken
 - fixed: quitting while a plugin was still active would sometimes crash rkward
 - new shortcuts for window navigations: next/previous window, activate console, activate command log, etc.
 - new functions rk.describe.alternative () and rk.print.literal () for use in plugins

Modified: trunk/rkward/TODO
===================================================================
--- trunk/rkward/TODO	2007-03-06 14:44:05 UTC (rev 1543)
+++ trunk/rkward/TODO	2007-03-07 12:39:51 UTC (rev 1544)
@@ -22,12 +22,6 @@
 			- seems to happen more often with larger data frames
 			- more precisely: seems to happen after scrolling
 			- no idea, why this happens
-		- converting objects to a different type is broken (works in the editor, but the type remains unchanged in the backend)
-			- maybe we could do the change in the backend, and then sync
-				- function rk.change.vector.mode() to change the mode, keeping attributes, and adding invalid values where needed
-				- sync using updateFromR(), updateDataFromR()
-				- this would be done from TwinTableMetaMember::setText()
-				- we should find a way to disable the var (set it to gray color group, do not allow editing) during this operation
 	- Quitting via q() in the R console will often lead to a segfault during shutdown
 
 Compilation / technical
@@ -54,6 +48,7 @@
 			- default alignment (per var type)
 			- default precision
 			- display of factor level labels (global and per variable)
+				- might default to "only for factors"
 			- delay of factor-level popup
 		- highlighting of value ranges
 	- Create an editor for single vectors/factors, or rework RKEditorDataFrame to handle those as well

Modified: trunk/rkward/rkward/core/rkvariable.cpp
===================================================================
--- trunk/rkward/rkward/core/rkvariable.cpp	2007-03-06 14:44:05 UTC (rev 1543)
+++ trunk/rkward/rkward/core/rkvariable.cpp	2007-03-07 12:39:51 UTC (rev 1544)
@@ -66,11 +66,24 @@
 			delete myData ()->changes;
 			myData ()->changes = 0;
 		}
+
+		// store what we want to keep of the edit data
 		RKEditor *editor = myData ()->editor;
+		ValueLabels *value_labels = myData ()->value_labels;
+		myData ()->value_labels = 0;	// prevent destruction
+		FormattingOptions *formatting_options = myData ()->formatting_options;
+		myData ()->formatting_options = 0;	// prevent destruction
+
+		// destroy and re-allocate edit data
 		discardEditData ();
 		setDataType (new_type);
 		allocateEditData (editor);
 
+		// re-set presistent aspects of the edit data
+		myData ()->value_labels = value_labels;
+		myData ()->formatting_options = formatting_options;
+
+		// re-set all data
 		setSyncing (false);
 		int i = 0;
 		for (QStringList::const_iterator it = list.constBegin (); it != list.constEnd (); ++it) {
@@ -78,6 +91,14 @@
 			i++;
 		}
 		if (sync) {
+			QString command = ".rk.set.vector.mode(" + getFullName () + ", ";
+			if (new_type == RObject::DataCharacter) command += "as.character";
+			else if (new_type == RObject::DataNumeric) command += "as.numeric";
+			else if (new_type == RObject::DataLogical) command += "as.logical";
+			else if (new_type == RObject::DataFactor) command += "as.factor";
+			command += ")";
+			RKGlobals::rInterface ()->issueCommand (command, RCommand::App | RCommand::Sync, QString::null);
+
 			syncDataToR ();
 		}
 		setSyncing (internal_sync);

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2007-03-06 14:44:05 UTC (rev 1543)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2007-03-07 12:39:51 UTC (rev 1544)
@@ -227,6 +227,25 @@
 	ret
 }
 
+# Change storage type of x to mode newmode.
+# Most attributes will be kept, but the data is erased!
+".rk.set.vector.mode" <- function (x, fun, envir=parent.frame ()) {
+	old_attr <- attributes (x)
+	old_attr$class <- NULL
+	old_attr[[".rk.invalid.fields"]] <- list ()	# will be reset, anyway!
+
+	y <- fun (rep (NA, length.out=length (x)))
+
+	# merge old attributes with new ones
+	newattrs <- attributes (y)
+	for (nattr in names (newattrs)) {
+		old_attr[[nattr]] <- newattrs[[nattr]]
+	}
+
+	attributes (y) <- old_attr
+	eval (substitute (x <- y), envir=envir)
+}
+
 ".rk.get.structure" <- function (x, name, envlevel=0, namespacename=NULL, misplaced=FALSE) {
 	fun <- FALSE
 	cont <- FALSE


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