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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Oct 5 17:53:41 UTC 2009


Revision: 2686
          http://rkward.svn.sourceforge.net/rkward/?rev=2686&view=rev
Author:   tfry
Date:     2009-10-05 17:53:41 +0000 (Mon, 05 Oct 2009)

Log Message:
-----------
Changes spinboxes to return their value with at least default_precision digits, and more, only if needed.

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkcomponent.cpp
    trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
    trunk/rkward/rkward/plugin/rkcomponentproperties.h
    trunk/rkward/rkward/plugin/rkpluginspinbox.cpp

Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp	2009-10-05 17:51:34 UTC (rev 2685)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp	2009-10-05 17:53:41 UTC (rev 2686)
@@ -112,6 +112,15 @@
 	UnserializeError error = NoError;
 	for (QMap<QString, QString>::const_iterator it = props.constBegin (); it != props.constEnd (); ++it) {
 		if (fetchStringValue (it.key ()) != it.value ()) {
+			// COMPAT: In RKWard 0.5.1, the formatting of real numbers was different. Hence we compare the numeric values, instead
+			QString dummy;
+			RKComponentBase *prop = lookupComponent (it.key (), &dummy);
+			if (dummy.isEmpty () && prop && prop->type () == PropertyDouble) {
+				if (static_cast<RKComponentPropertyDouble*> (prop)->doubleValue () == it.value ().toDouble ()) {
+					continue;
+				}
+			}
+
 			RK_DO(qDebug ("Tried to apply value %s to property %s, but got %s", qPrintable (it.value ()), qPrintable (it.key ()), qPrintable (fetchStringValue (it.key ()))), PLUGIN, DL_INFO);
 			error = NotAllSettingsApplied;
 		}
@@ -279,6 +288,7 @@
 	// even if we remove a little more than necessary along the way.
 	QString key = getIdInParent ();
 	while (parentComponent ()->child_map.remove (key)) {;}
+	_parent = 0;
 }
 
 QString RKComponent::getIdInParent () const {

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2009-10-05 17:51:34 UTC (rev 2685)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2009-10-05 17:53:41 UTC (rev 2686)
@@ -442,7 +442,7 @@
 
 	validator = new QDoubleValidator (this);		// accepts all ints initially
 	RKComponentPropertyDouble::default_value = default_value;
-	precision = 6;
+	precision = 2;
 	internalSetValue (default_value);
 }
 
@@ -587,7 +587,16 @@
 	RK_TRACE (PLUGIN);
 
 	current_value = new_value;
-	_value = QString::number (current_value, 'f', precision);
+
+	// what we want is AT LEAST *precision digits, more if required. I'm sure there's a nifty algorithm for that, but this hack does the trick:
+	_value = QString::number (current_value, 'f', 9);	// 9 is an arbitrary limit to counter floating point jitter
+	int decimal = _value.indexOf ('.');
+	if (decimal >= 0) {
+		int min_digit = decimal + precision + 1;
+		while ((min_digit < _value.length ()) && _value.endsWith ('0')) _value.chop (1);
+	}
+	if (_value.endsWith ('.')) _value.chop (1);
+
 	is_valid = ((new_value >= validator->bottom ()) && (new_value <= validator->top ()));
 	if (!is_valid) current_value = default_value;
 }

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.h	2009-10-05 17:51:34 UTC (rev 2685)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.h	2009-10-05 17:53:41 UTC (rev 2686)
@@ -176,7 +176,7 @@
 	void setMin (double lower=FLT_MIN);
 /** set upper boundary. Default parameter will effectively remove the boundary. You should call this *before* connecting to any other properties, so limits can be reconciled */
 	void setMax (double upper=FLT_MAX);
-/** set text precision (default = 6) */
+/** set text precision (default = 2) */
 	void setPrecision (int digits) { precision = digits; };
 /** return current min value */
 	double minValue ();

Modified: trunk/rkward/rkward/plugin/rkpluginspinbox.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkpluginspinbox.cpp	2009-10-05 17:51:34 UTC (rev 2685)
+++ trunk/rkward/rkward/plugin/rkpluginspinbox.cpp	2009-10-05 17:53:41 UTC (rev 2686)
@@ -58,7 +58,7 @@
 
 		realvalue->setMin (min);
 		realvalue->setMax (max);
-		realvalue->setPrecision (max_precision);
+		realvalue->setPrecision (default_precision);
 	} else {
 		int min = xml->getIntAttribute (element, "min", INT_MIN, DL_INFO);
 		int max = xml->getIntAttribute (element, "max", INT_MAX, DL_INFO);


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