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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Feb 1 18:15:18 UTC 2007


Revision: 1280
          http://svn.sourceforge.net/rkward/?rev=1280&view=rev
Author:   tfry
Date:     2007-02-01 10:15:18 -0800 (Thu, 01 Feb 2007)

Log Message:
-----------
Rework RKSpinBox: Now step sizes are adjusted dynamically (depedning on the log of the current value)
In real mode, there is no more mapping to int, making the full double range available

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/TODO
    trunk/rkward/rkward/misc/rkspinbox.cpp
    trunk/rkward/rkward/misc/rkspinbox.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-02-01 16:05:46 UTC (rev 1279)
+++ trunk/rkward/ChangeLog	2007-02-01 18:15:18 UTC (rev 1280)
@@ -1,5 +1,7 @@
-- input elements can be made required 							TODO: don't list this, but document!
+- improvements to spinbox: step size is adjusted dynamically, and no arbitrary limits in real mode
+- input elements and browser elements can be made required 				TODO: don't list this, but document!
 - fixed problem with specifying y axis limits in several plugins
+- simplified CSV import plugin
 - new plugin: import SPSS files								TODO: document
 - new documentation pages: console
 - improvements to distribution plot plugins

Modified: trunk/rkward/TODO
===================================================================
--- trunk/rkward/TODO	2007-02-01 16:05:46 UTC (rev 1279)
+++ trunk/rkward/TODO	2007-02-01 18:15:18 UTC (rev 1280)
@@ -160,37 +160,11 @@
 		- http://de3.php.net/manual/en/function.call-user-func.php seems to be faster than eval
 		- find out why an error in the backend often leads to a subsequent crash
 	- plugins (general)
-		- add import-filter plugins
-			- also export plugins, export x11 plugins, and probably more
-			- maybe this can be generalized as "context sensitive plugins"
-				- this context could also hold additional info such as filename to open, or device number
-			- Plan on context dependent actions:
-				- RKComponentMap additionally has a map of contexts (name -> context class)
-				- The contextclass (RKContextMap) is a map of RKComponentHandle (or id?)->Context parameters (such as filter name filter for import plugins, but may be empty for many others. Maybe a simple QString, for now)
-					- maybe a contextmap really IS an RKComponentMap!
-						- This would provide the benefit of already having a XMLGUI for pluggin into menus/contexts (but do we really need this? Probably only for some contexts such as X11 (where context info is already known) but not in others such as Import (where context info will have to be asked for, somewhere). OTOH, the context includer can decide, whether or not (and where) to merge the context)
-				- or maybe the attributes are a map, as well (attribute-name->attribute-value)
-				- in a pluginmap, the definition may look like:
-				<context id="...">
-					<entry component_id="..." parameters="...::..."/>
-				</context>
-				- components may be placed in multiple contexts, and even both inside and outside a context, if they can deal with all those contexts.
-				- RKComponentHandle will need an additional function invokeWithContext()
-				- RKStandardComponent needs that context as a parameter
-				- The context will simply be a list(Map) of RKComponentProperties, to copy into the RKStandardComponent (should they also be owned, there?)
-					- why not just set some RKComponentProperties directly?
-					- showing RKStandardComponents should be delayed using a 0 timer to call show
-				- An RKContextMap can be asked to provide an RKContextInstance, i.e. a class of actions (given an action collection) that can be plugged into a menu (with a structure?), and the context properties
-				- This context map will also have a single slot to receive the activation signals of all actions.
-					- By investigating QObject::sender (), and looking up the corresponding handle, it will dispatch to the correct RKStandardComponentHandle::invokeWithContext()
 		- ODS filter (try to find someone to implement one in R)
 	- formula-widget:
 		- use smart sorting, esp. of generated string
 		- add labels, add "up to level" option
 		- add constant term option
-	- create a spinbox, that can really deal with real numbers
-		- whenever the value changes (user entered text, or clicked up/down), the value will be translated into an integer number, and an integer exponent (in mapTextToValue(), and mapValueToText ()?)
-		- step size will be auto-adjusted logarithmically (e.g. always third most significant digit)
 	- multi-object option group:
 		- provide the set of enclosed options for each of the selected variables
 		- will provide dynamic properties based on which variables are selected in the source

Modified: trunk/rkward/rkward/misc/rkspinbox.cpp
===================================================================
--- trunk/rkward/rkward/misc/rkspinbox.cpp	2007-02-01 16:05:46 UTC (rev 1279)
+++ trunk/rkward/rkward/misc/rkspinbox.cpp	2007-02-01 18:15:18 UTC (rev 1280)
@@ -2,7 +2,7 @@
                           rkspinbox  -  description
                              -------------------
     begin                : Wed Aug 11 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -17,6 +17,7 @@
 #include "rkspinbox.h"
 
 #include <qvalidator.h>
+#include <qlineedit.h>
 
 #include <math.h>
 
@@ -25,7 +26,8 @@
 RKSpinBox::RKSpinBox (QWidget *parent) : QSpinBox (parent) {
 	validator = 0;
 	mode = Integer;
-	divisor = 1;
+	updating = updating_b = false;
+	real_value = 0;
 }
 
 RKSpinBox::~RKSpinBox () {
@@ -33,76 +35,94 @@
 }
 
 void RKSpinBox::setRealValue (double new_value) {
-	setValue ((int) round (new_value * divisor));
+	real_value = new_value;
+	setValue (0);
 };
 
-int RKSpinBox::mapTextToValue (bool *ok) {
+void RKSpinBox::interpretText () {
+	if (updating) return;
+	updating = true;
+
 	if (mode == Real) {
-		RK_DO (qDebug ("ttv %s -> %d", text ().latin1 (), (int) (divisor * text ().toFloat (ok))), PLUGIN, DL_DEBUG);
-		return ((int) round (divisor * text ().toFloat (ok)));
+		bool ok;
+		double new_value = text ().toFloat (&ok);
+		if (ok) real_value = new_value;
+		valueChange ();
 	} else {
-		return QSpinBox::mapTextToValue (ok);
+		QSpinBox::interpretText ();
 	}
+
+	updating = false;
 }
 
-QString RKSpinBox::mapValueToText (int v) {
+void RKSpinBox::updateDisplay () {
+	if (updating_b) return;
+	updating_b = true;
+
 	if (mode == Real) {
-		QString dummy;
-		RK_DO (qDebug ("vtt %d", v), PLUGIN, DL_DEBUG);
-		RK_DO (qDebug ("%s", QString ("%1.%2").arg (v / divisor).arg (v % divisor, 2).latin1 ()), PLUGIN, DL_DEBUG);
-		return (QString ().setNum ((double) v / double (divisor)));
+		if (value () != 0) {
+			int change = value ();
+			setValue (0);
+
+			int power = (int) log10 (real_value) - default_precision;
+			if (power < (-default_precision)) power = -default_precision;
+			if (power > 10) power = 10;
+			double step = pow (10, power);
+
+			real_value += change * step;
+			if (real_value > real_max) real_value = real_max;
+			if (real_value < real_min) real_value = real_min;
+		}
+		setUpdatesEnabled (false);
+		QSpinBox::updateDisplay ();	// need this to enable/disable the button correctly
+		editor ()->setText (QString ().setNum (real_value));
+		setUpdatesEnabled (true);
 	} else {
-		return QSpinBox::mapValueToText (v);
+		QSpinBox::updateDisplay ();
+
+		int power = (int) log10 (value ());
+		int step = (int) pow (10, power-1);
+		if (step < 1) step = 1;
+		setSteps (step, 10*step);
 	}
+
+	updating_b = false;
 }
 
 void RKSpinBox::setRealMode (double min, double max, double initial, int default_precision, int max_precision) {
-	RK_ASSERT ((max_precision >= default_precision) && (max_precision <= 6) && (default_precision >= 0));
-	RK_DO (qDebug ("min %f max %f initial %f defp %d maxp %d", min, max, initial, default_precision, max_precision), PLUGIN, DL_DEBUG);
+	RK_ASSERT ((max_precision >= default_precision) && (max_precision <= 8));
 
-	divisor = (int) (pow (10, max_precision));
-
-	double max_max = (double) INT_MAX / (double) divisor;
-	double min_min = (double) (-(INT_MAX-1)) / (double) divisor;
-	if (max > max_max) max = max_max;
-	if (max < min_min) max = min_min;
-	if (min < min_min) min = min_min;
-	if (min > max_max) min = max_max;
-
 	mode = Real;
 	QValidator *new_validator = new QDoubleValidator (min, max, max_precision, this);
 	setValidator (new_validator);
 	delete validator;
 	validator = new_validator;
 
-	setMinValue ((int) (min * divisor));
-	setMaxValue ((int) (max * divisor));
-	setSteps ((int) (pow (10, default_precision)), (int) (pow (10, default_precision + 1)));
-	setValue ((int) round ((double) initial * divisor));
-	RK_DO (qDebug ("minint %d maxint %d stepint %d pageint %d initialint %d", minValue (), maxValue (), lineStep (), pageStep (), (int) round (initial * divisor)), PLUGIN, DL_DEBUG);
+	setMinValue (-1000);
+	setMaxValue (1000);
+	setSteps (1, 10);
+
+	real_value = initial;
+	real_min = min;
+	real_max = max;
+	RKSpinBox::default_precision = default_precision;
+
+	setValue (0);
 }
 
 void RKSpinBox::setIntMode (int min, int max, int initial) {
 	QValidator *new_validator = new QIntValidator (min, max, this);
 
-	int range_power = (int) (log10 (max - min));
-	int range_power_limit = (int) (log10 (initial)) + 2;
-	if (range_power > range_power_limit) {
-		range_power = range_power_limit;
-	}
-	if (range_power <= 0) {
-		range_power = 1;
-	}
 	setMinValue (min);
 	setMaxValue (max);
-	setSteps ((int) (pow (10, range_power-1)), (int) (pow (10, range_power)));
 	setValue (initial);
 
 	setValidator (new_validator);
 	delete validator;
 	validator = new_validator;
 	mode = Integer;
-	divisor = 1;
+
+	updateDisplay ();
 }
 
 #include "rkspinbox.moc"

Modified: trunk/rkward/rkward/misc/rkspinbox.h
===================================================================
--- trunk/rkward/rkward/misc/rkspinbox.h	2007-02-01 16:05:46 UTC (rev 1279)
+++ trunk/rkward/rkward/misc/rkspinbox.h	2007-02-01 18:15:18 UTC (rev 1280)
@@ -2,7 +2,7 @@
                           rkspinbox  -  description
                              -------------------
     begin                : Wed Aug 11 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -25,25 +25,28 @@
 /** After constructing use one of setRealMode or setIntMode to initialize the Spinbox.
 @author Thomas Friedrichsmeier
 */
-class RKSpinBox : public QSpinBox
-{
-Q_OBJECT
+class RKSpinBox : public QSpinBox {
+	Q_OBJECT
 public:
-    RKSpinBox(QWidget *parent = 0);
-
-    ~RKSpinBox();
+	RKSpinBox (QWidget *parent = 0);
+	~RKSpinBox ();
 	
 	void setRealMode (double min, double max, double initial, int default_precision, int max_precision);
 	void setIntMode (int min, int max, int initial);
-	double realValue () { return ((double) value () / (double) divisor); };
+	double realValue () { return real_value; };
 	void setRealValue (double new_value);
 protected:
-	int mapTextToValue (bool *ok);
-	QString mapValueToText (int v);
+	void updateDisplay ();
+	void interpretText ();
 private:
 	enum Mode { Integer=0, Real=1 };
 	Mode mode;
-	int divisor;
+	bool updating;
+	bool updating_b;
+	double real_value;
+	double real_min;
+	double real_max;
+	int default_precision;
 	QValidator *validator;
 };
 


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