[rkward-cvs] rkward/rkward/misc rkspinbox.cpp,1.1,1.2 rkspinbox.h,1.1,1.2 xmlhelper.cpp,1.4,1.5 xmlhelper.h,1.3,1.4

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Mar 17 15:18:40 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/misc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19219/misc

Modified Files:
	rkspinbox.cpp rkspinbox.h xmlhelper.cpp xmlhelper.h 
Log Message:
Moved over RKPluginSpinBox

Index: rkspinbox.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkspinbox.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkspinbox.cpp	18 Aug 2004 12:14:24 -0000	1.1
--- rkspinbox.cpp	17 Mar 2006 15:18:38 -0000	1.2
***************
*** 26,29 ****
--- 26,30 ----
  	validator = 0;
  	mode = Integer;
+ 	divisor = 1;
  }
  
***************
*** 32,39 ****
  }
  
  int RKSpinBox::mapTextToValue (bool *ok) {
  	if (mode == Real) {
  		RK_DO (qDebug ("ttv %s -> %d", text ().latin1 (), (int) (divisor * text ().toFloat (ok))), PLUGIN, DL_DEBUG);
! 		return (round (divisor * text ().toFloat (ok)));
  	} else {
  		return QSpinBox::mapTextToValue (ok);
--- 33,44 ----
  }
  
+ void RKSpinBox::setRealValue (double new_value) {
+ 	setValue ((int) round (new_value * divisor));
+ };
+ 
  int RKSpinBox::mapTextToValue (bool *ok) {
  	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)));
  	} else {
  		return QSpinBox::mapTextToValue (ok);
***************
*** 45,49 ****
  		QString dummy;
  		RK_DO (qDebug ("vtt %d", v), PLUGIN, DL_DEBUG);
! 		RK_DO (qDebug (QString ("%1.%2").arg (v / divisor).arg (v % divisor, 2).latin1 ()), PLUGIN, DL_DEBUG);
  		return (QString ().setNum ((double) v / double (divisor)));
  	} else {
--- 50,54 ----
  		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)));
  	} else {
***************
*** 66,76 ****
  	setMaxValue ((int) (max * divisor));
  	setSteps ((int) (pow (10, default_precision)), (int) (pow (10, default_precision + 1)));
! 	setValue (round ((double) initial * divisor));
! 	RK_DO (qDebug ("minint %d maxint %d stepint %d pageint %d initialint %d", minValue (), maxValue (), lineStep (), pageStep (), round (initial * divisor)), PLUGIN, DL_DEBUG);
  }
  
  void RKSpinBox::setIntMode (int min, int max, int initial) {
  	QValidator *new_validator = new QIntValidator (min, max, this);
! 	
  	int range_power = (int) (log10 (max - min));
  	if (range_power <= 0) {
--- 71,81 ----
  	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);
  }
  
  void RKSpinBox::setIntMode (int min, int max, int initial) {
  	QValidator *new_validator = new QIntValidator (min, max, this);
! 
  	int range_power = (int) (log10 (max - min));
  	if (range_power <= 0) {
***************
*** 86,89 ****
--- 91,95 ----
  	validator = new_validator;
  	mode = Integer;
+ 	divisor = 1;
  }
  

Index: xmlhelper.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/xmlhelper.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** xmlhelper.cpp	29 Sep 2005 16:02:51 -0000	1.4
--- xmlhelper.cpp	17 Mar 2006 15:18:38 -0000	1.5
***************
*** 147,150 ****
--- 147,165 ----
  }
  
+ double XMLHelper::getDoubleAttribute (const QDomElement &element, const QString &name, double def, int debug_level) {
+ 	RK_TRACE (XML);
+ 
+ 	QString res = getStringAttribute (element, name, QString::number (def), debug_level);
+ 
+ 	bool valid_number;;
+ 	double ret = res.toDouble (&valid_number);
+ 
+ 	if (!valid_number) {
+ 		displayError (&element, i18n ("Illegal attribute value. Only real numbers are allowed."), debug_level, DL_ERROR);
+ 		return def;
+ 	}
+ 
+ 	return ret;
+ }
  
  bool XMLHelper::getBoolAttribute (const QDomElement &element, const QString &name, bool def, int debug_level) {

Index: rkspinbox.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkspinbox.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkspinbox.h	18 Aug 2004 12:14:24 -0000	1.1
--- rkspinbox.h	17 Mar 2006 15:18:38 -0000	1.2
***************
*** 36,39 ****
--- 36,41 ----
  	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); };
+ 	void setRealValue (double new_value);
  protected:
  	int mapTextToValue (bool *ok);

Index: xmlhelper.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/xmlhelper.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** xmlhelper.h	16 Mar 2006 22:31:08 -0000	1.3
--- xmlhelper.h	17 Mar 2006 15:18:38 -0000	1.4
***************
*** 90,93 ****
--- 90,102 ----
  	int getIntAttribute (const QDomElement &element, const QString &name, int def, int debug_level);
  
+ /** returns the value of a numeric (double) attribute
+ @param element the element whose attributes to search
+ @param name the name of the attribute to read
+ @param def default value to return if no such attribute is given
+ @param debug_level level of debug message to generate in case of failure (i.e. no such attribute was found, or attribute was not an integer. Note that if the given attribute is found, but is not a valid integer, an error-message will be shown regardless of this setting, but highestError () will still use debug_level)
+ @returns the value of the given attribute or the given default */
+ 	double getDoubleAttribute (const QDomElement &element, const QString &name, double def, int debug_level);
+ 
+ 
  /** returns the value of a boolean attribute ("true" or "false")
  @param element the element whose attributes to search





More information about the rkward-tracker mailing list