[rkward] /: Honor decimal precision setting for displaying data in editor.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Jan 1 17:24:04 UTC 2016


Git commit 11c952da4e21425950eeda8970b6cb637f8caa4e by Thomas Friedrichsmeier.
Committed on 01/01/2016 at 17:21.
Pushed by tfry into branch 'master'.

Honor decimal precision setting for displaying data in editor.

M  +1    -0    ChangeLog
M  +20   -20   rkward/core/rkvariable.cpp
M  +0    -2    rkward/core/rkvariable.h

http://commits.kde.org/rkward/11c952da4e21425950eeda8970b6cb637f8caa4e

diff --git a/ChangeLog b/ChangeLog
index 6ca254a..8fccecd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Fixed: Numerical (display) precision setting was not honored in data editor
 - Fix several window activation quirks in "Focus follows mouse" mode
 - File selectors in "Import XYZ" plugins now filter for standard file extensions, by default
 - Show a warning screen when invoking plugins from the command line (or from clicking an rkward://-link in an external application)
diff --git a/rkward/core/rkvariable.cpp b/rkward/core/rkvariable.cpp
index b65d963..9429b2f 100644
--- a/rkward/core/rkvariable.cpp
+++ b/rkward/core/rkvariable.cpp
@@ -460,21 +460,34 @@ QString RKVariable::getText (int row, bool pretty) const {
 
 	if (data->cell_states[row] & RKVarEditData::NA) return (QString ());
 
-	if (pretty) return (getLabeled (row));
-
+	QString ret;
 	if (getDataType () == DataCharacter) {
 		RK_ASSERT (!data->cell_strings.isEmpty ());
-		return (data->cell_strings[row]);
+		ret = data->cell_strings[row];
 	} else {
 		RK_ASSERT (!data->cell_doubles.isEmpty ());
-		if (pretty && (data->formatting_options.precision_mode != FormattingOptions::PrecisionDefault)) {
+		if (pretty && (data->formatting_options.precision_mode != FormattingOptions::PrecisionDefault) && (getDataType () != DataLogical)) {
 			if (data->formatting_options.precision_mode == FormattingOptions::PrecisionRequired) {
-				return QString::number (data->cell_doubles[row], 'g', MAX_PRECISION);
+				ret = QString::number (data->cell_doubles[row], 'g', MAX_PRECISION);
+			} else {
+				ret = QString::number (data->cell_doubles[row], 'f', data->formatting_options.precision);
+			}
+		} else {
+			ret = QString::number (data->cell_doubles[row], 'g', MAX_PRECISION);
+		}
+	}
+
+	if (pretty) {
+		if (getDataType () == DataLogical) {
+			if (ret == "0") return "FALSE";
+			else if (ret == "1") return "TRUE";
+		} else if (data->value_labels) {
+			if (data->value_labels->contains (ret)) {
+				return (*(data->value_labels))[ret];
 			}
-			return QString::number (data->cell_doubles[row], 'f', data->formatting_options.precision);
 		}
-		return QString::number (data->cell_doubles[row], 'g', MAX_PRECISION);
 	}
+	return ret;
 }
 
 QString RKVariable::getRText (int row) const {
@@ -546,19 +559,6 @@ void RKVariable::setText (int row, const QString &text) {
 	cellsChanged (row, row);
 }
 
-QString RKVariable::getLabeled (int row) const {
-	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 otext;
-}
-
 void RKVariable::setNumericFromR (int from_row, int to_row, const QVector<double> &numdata) {
 	RK_TRACE (OBJECTS);
 	RK_ASSERT (to_row < getLength ());
diff --git a/rkward/core/rkvariable.h b/rkward/core/rkvariable.h
index 38a697f..45da272 100644
--- a/rkward/core/rkvariable.h
+++ b/rkward/core/rkvariable.h
@@ -178,8 +178,6 @@ protected:
 	void writeInvalidFields (QList<int> rows, RCommandChain *chain=0);
 /** writes the values labels to the backend */
 	void writeValueLabels (RCommandChain *chain) const;
-/** tries to match a value-label to the value in the given cell. Returns the label, or - if there is no label - the original value in textual representation */
-	QString getLabeled (int row) const;
 
 /** allocate edit data (cells initialized to NAs) */
 	void allocateEditData ();



More information about the rkward-tracker mailing list