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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Feb 4 12:25:57 UTC 2011


Revision: 3414
          http://rkward.svn.sourceforge.net/rkward/?rev=3414&view=rev
Author:   tfry
Date:     2011-02-04 12:25:57 +0000 (Fri, 04 Feb 2011)

Log Message:
-----------
Display logical values as TRUE/FALSE, and support T/TRUE/F/FALSE in additon to 0/1 while editing.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/core/rkvariable.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2011-02-03 15:15:13 UTC (rev 3413)
+++ trunk/rkward/ChangeLog	2011-02-04 12:25:57 UTC (rev 3414)
@@ -1,3 +1,4 @@
+- Display logical values as "TRUE" and "FALSE" in data editor, and accept "T"/"TRUE"/"F"/"FALSE" in addition to "0"/"1" while editing
 - Add support for R functions loadhistory(), savehistory(), history(), and timestamp ()
 - Do not load .RData file from current directory by default (configurable)
 - Fixed: On Windows, a wrong locale for LC_NUMERIC would be applied, resulting in malfunction of pdf() and postscript()

Modified: trunk/rkward/rkward/core/rkvariable.cpp
===================================================================
--- trunk/rkward/rkward/core/rkvariable.cpp	2011-02-03 15:15:13 UTC (rev 3413)
+++ trunk/rkward/rkward/core/rkvariable.cpp	2011-02-04 12:25:57 UTC (rev 3414)
@@ -415,12 +415,7 @@
 		return (*na_char);
 	}
 
-	if (pretty && (data->value_labels)) {
-		QString otext = getText (row);
-		if (data->value_labels->contains (otext)) {
-			return (*(data->value_labels))[otext];
-		}
-	}
+	if (pretty) return (getLabeled (row));
 
 	if (getDataType () == DataCharacter) {
 		RK_ASSERT (!data->cell_strings.isEmpty ());
@@ -445,7 +440,7 @@
 	if ((cell_state == ValueUnused) || (cell_state == ValueInvalid)) {
 		return ("NA");
 	} else if (getDataType () == DataFactor) {
-		return (rQuote (getLabeled (row)));
+		return (rQuote (getText (row, true)));
 	} else if (getDataType () == DataCharacter) {
 		return (rQuote (getText (row)));
 	} else if (getDataType () == DataLogical) {
@@ -470,48 +465,52 @@
 		data->cell_states[row] = 0;
 	}
 
+	bool valid = true;
 	if (text.isNull ()) {
 		data->cell_states[row] |= RKVarEditData::NA;
+	} else if (text.isEmpty () && getDataType () != DataCharacter) {
+		data->cell_states[row] |= RKVarEditData::NA;
 	} else {
 		if (getDataType () == DataCharacter) {
 			data->cell_strings[row] = text;
-			data->cell_states[row] |= RKVarEditData::Valid;
 		} else if (getDataType () == DataFactor) {
-			if (text.isEmpty ()) {
-				data->cell_states[row] |= RKVarEditData::NA;
-			} else if (data->value_labels && data->value_labels->contains (text)) {
+			if (data->value_labels && data->value_labels->contains (text)) {
 				data->cell_doubles[row] = text.toInt ();
-				data->cell_states[row] |= RKVarEditData::Valid;
 			} else {
-				data->invalid_fields.insert (row, text);
-				data->cell_states[row] |= RKVarEditData::Invalid | RKVarEditData::UnsyncedInvalidState;
+				valid = false;
 			}
+		} else if (getDataType () == DataLogical) {
+			if (text == "0" || text == "F" || text == "FALSE") data->cell_doubles[row] = 0;
+			else if (text == "1" || text == "T" || text == "TRUE") data->cell_doubles[row] = 1;
+			else valid = false;
 		} else {
 			bool ok;
-			if (text.isEmpty ()) {
-				data->cell_states[row] |= RKVarEditData::NA;
-			} else {
-				data->cell_doubles[row] = text.toDouble (&ok);
-				if (ok) {
-					data->cell_states[row] |= RKVarEditData::Valid;
-				} else {
-					data->invalid_fields.insert (row, text);
-					data->cell_states[row] |= RKVarEditData::Invalid | RKVarEditData::UnsyncedInvalidState;
-				}
-			}
+			data->cell_doubles[row] = text.toDouble (&ok);
+			if (!ok) valid = false;
 		}
 	}
+
+	if (valid) {
+		if (!(data->cell_states[row] & RKVarEditData::NA)) data->cell_states[row] |= RKVarEditData::Valid;
+	} else {
+		data->invalid_fields.insert (row, text);
+		data->cell_states[row] |= RKVarEditData::Invalid | RKVarEditData::UnsyncedInvalidState;
+	}
+
 	cellsChanged (row, row);
 }
 
 QString RKVariable::getLabeled (int row) const {
-	if (data->value_labels) {
-		QString otext = getText (row);
+	QString otext = getText (row);
+	if (getDataType () == DataLogical) {
+		if (otext == "0") return "FALSE";
+		else if (otext == "1") return "TRUE";
+	} else if (data->value_labels) {
 		if (data->value_labels->contains (otext)) {
 			return (*(data->value_labels))[otext];
 		}
 	}
-	return getText (row);
+	return otext;
 }
 
 void RKVariable::setNumericFromR (int from_row, int to_row, const QVector<double> &numdata) {


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