[rkward-cvs] rkward/rkward/plugin rkcomponentproperties.cpp,1.1,1.2 rkcomponentproperties.h,1.1,1.2

Thomas Friedrichsmeier tfry at users.sourceforge.net
Sun Nov 27 16:09:31 UTC 2005


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

Modified Files:
	rkcomponentproperties.cpp rkcomponentproperties.h 
Log Message:
Implementation of first property classes

Index: rkcomponentproperties.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentproperties.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkcomponentproperties.cpp	25 Nov 2005 14:58:48 -0000	1.1
--- rkcomponentproperties.cpp	27 Nov 2005 16:09:29 -0000	1.2
***************
*** 46,48 ****
--- 46,191 ----
  #include "rkcomponentproperties.h"
  
+ #include "../debug.h"
+ 
+ ///////////////////////////////////////////// Base //////////////////////////////////////////
+ 
+ RKComponentPropertyBase::RKComponentPropertyBase (QObject *parent, bool required) : QObject (parent) {
+ 	RK_TRACE (PLUGIN);
+ 	RKComponentPropertyBase::required = required;
+ }
+ 
+ RKComponentPropertyBase::~RKComponentPropertyBase () {
+ 	RK_TRACE (PLUGIN);
+ }
+ 
+ QString RKComponentPropertyBase::value (const QString &modifier) {
+ 	RK_TRACE (PLUGIN);
+ 	if (!modifier.isEmpty ()) {
+ 		warnModifierNotRecognized (modifier);
+ 		return QString::null;
+ 	}
+ 	return _value;
+ }
+ 
+ bool RKComponentPropertyBase::setValue (const QString &string) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	_value = string;
+ 	emit (valueChanged (this));
+ 	return true;
+ }
+ 
+ void RKComponentPropertyBase::connectToGovernor (RKComponentPropertyBase *governor, const QString &modifier, bool) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	RK_ASSERT (governor);
+ 	connect (governor, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (governorValueChanged (RKComponentPropertyBase *)));
+ 	governor_modifier = modifier;
+ 	// no need to reconcile any requirements, and the RKComponentPropertyBase does not have any requirements
+ 
+ 	// fetch current value
+ 	setValue (governor->value (modifier));
+ }
+ 
+ void RKComponentPropertyBase::governorValueChanged (RKComponentPropertyBase *property) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	setValue (property->value (governor_modifier));
+ }
+ 
+ bool RKComponentPropertyBase::isSatisfied () {
+ 	RK_TRACE (PLUGIN);
+ 	if (!required) return true;
+ 	if (isValid ()) return true;
+ 	return false;		// never happens in RKComponentPropertyBase, but might in subclasses
+ }
+ 
+ void RKComponentPropertyBase::warnModifierNotRecognized (const QString &modifier) {
+ 	RK_TRACE (PLUGIN);
+ 	RK_DO (qDebug ("Modifier '%s' not recongnized.", modifier.latin1 ()), PLUGIN, DL_ERROR);
+ }
+ 
+ ///////////////////////////////////////////// Bool //////////////////////////////////////////
+ 
+ RKComponentPropertyBool::RKComponentPropertyBool (QObject *parent, bool required, const QString &value_true, const QString &value_false, bool default_state) : RKComponentPropertyBase (parent, required) {
+ 	RK_TRACE (PLUGIN);
+ 	RKComponentPropertyBool::value_true = value_true;
+ 	RKComponentPropertyBool::value_false = value_false;
+ 	default_value = default_state;
+ 	internalSetValue (default_state);
+ }
+ 
+ RKComponentPropertyBool::~RKComponentPropertyBool () {
+ 	RK_TRACE (PLUGIN);
+ }
+ 
+ void RKComponentPropertyBool::internalSetValue (bool new_value) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	current_value = new_value;
+ 	if (new_value) {
+ 		_value = value_true;
+ 	} else {
+ 		_value = value_false;
+ 	}
+ 	is_valid = true;
+ }
+ 
+ void RKComponentPropertyBool::internalSetValue (QString new_value) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	_value = new_value;
+ 
+ // try to convert to bool
+ 	is_valid = true;
+ 	if (new_value == value_true) {
+ 		current_value = true;
+ 	} else if (new_value == value_false) {
+ 		current_value = false;
+ 	} else {
+ 		is_valid = false;
+ 	}
+ }
+ 
+ void RKComponentPropertyBool::setValue (bool new_value) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	internalSetValue (new_value);
+ 	emit (valueChanged (this));
+ }
+ 
+ bool RKComponentPropertyBool::boolValue () {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	return current_value;
+ }
+ 
+ QString RKComponentPropertyBool::value (const QString &modifier) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	if (modifier.isEmpty ()) return _value;
+ 	if (modifier == "true") return value_true;
+ 	if (modifier == "false") return value_false;
+ 
+ 	warnModifierNotRecognized (modifier);
+ 	return QString::null;
+ }
+ 
+ bool RKComponentPropertyBool::setValue (const QString &string) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	internalSetValue (string);
+ 	emit (valueChanged (this));
+ 	return isValid ();
+ }
+ 
+ bool RKComponentPropertyBool::isStringValid (const QString &string) {
+ 	RK_TRACE (PLUGIN);
+ 
+ 	if ((string == value_true) || (string == value_false)) {
+ 		return true;
+ 	}
+ 	return false;
+ }
+ 
  #include "rkcomponentproperties.moc"

Index: rkcomponentproperties.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentproperties.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkcomponentproperties.h	25 Nov 2005 14:58:48 -0000	1.1
--- rkcomponentproperties.h	27 Nov 2005 16:09:29 -0000	1.2
***************
*** 29,33 ****
  public:
  /** constructor. Pass a valid QObject as parent so the property will be auto-destructed when no longer needed */
! 	RKComponentPropertyBase (QObject *parent);
  /** destructor */
  	virtual ~RKComponentPropertyBase ();
--- 29,33 ----
  public:
  /** constructor. Pass a valid QObject as parent so the property will be auto-destructed when no longer needed */
! 	RKComponentPropertyBase (QObject *parent, bool required);
  /** destructor */
  	virtual ~RKComponentPropertyBase ();
***************
*** 49,59 ****
  	virtual bool setValue (const QString &string);
  /** do not set the value, only check, whether it is legal */
! 	virtual bool isValid (const QString &string);
  /** current setting valid? */
! 	virtual bool isValid () { return true; };
  /** set to required: will only be satisfied if it holds a valid value. Else: satisfied if valid *or empty* */
  	void setRequired (bool require)  { required = require; };
  /** see setRequired () */
! 	virtual bool isSatisfied () { return true; };
  /** for RTTI. see RKComponentPropertyTypes */
  	virtual int type () { return PropertyBase; };
--- 49,59 ----
  	virtual bool setValue (const QString &string);
  /** do not set the value, only check, whether it is legal */
! 	virtual bool isStringValid (const QString &) { return true; };
  /** current setting valid? */
! 	virtual bool isValid () { return is_valid; };
  /** set to required: will only be satisfied if it holds a valid value. Else: satisfied if valid *or empty* */
  	void setRequired (bool require)  { required = require; };
  /** see setRequired () */
! 	virtual bool isSatisfied ();
  /** for RTTI. see RKComponentPropertyTypes */
  	virtual int type () { return PropertyBase; };
***************
*** 70,78 ****
--- 70,85 ----
  	virtual void governorValueChanged (RKComponentPropertyBase *property);
  protected:
+ 	void warnModifierNotRecognized (const QString &modifier);
  	bool required;
+ 	bool is_valid;
+ 	QString _value;
  /** if we're only interested in a specific sub-information of the governor-property, we need to remember the corresponding modifier */
  	QString governor_modifier;
  };
  
+ 
+ 
+ ///////////////////////////////////////////////// Bool ////////////////////////////////////////////////////////
+ 
  /** special type of RKComponentProperty, that is based on a bool setting */
  class RKComponentPropertyBool : public RKComponentPropertyBase {
***************
*** 81,87 ****
  param value_false string value if false/off
  param default value to use, if invalid string value was set */
! 	RKComponentPropertyBool (const QString &value_true, const QString &value_false, bool default_state);
  /** sets the bool value. Also takes care of notifying dependent components */
! 	void setValue (bool value);
  /** current value as bool */
  	bool boolValue ();
--- 88,96 ----
  param value_false string value if false/off
  param default value to use, if invalid string value was set */
! 	RKComponentPropertyBool (QObject *parent, bool required, const QString &value_true, const QString &value_false, bool default_state);
! /** destructor */
! 	~RKComponentPropertyBool ();
  /** sets the bool value. Also takes care of notifying dependent components */
! 	void setValue (bool new_value);
  /** current value as bool */
  	bool boolValue ();
***************
*** 89,100 ****
  	QString value (const QString &modifier=QString::null);
  /** reimplemented from RKComponentPropertyBase to convert to bool value according to current settings */
! 	bool setValue (const QString &value);
  /** reimplemented from RKComponentPropertyBase to test whether conversion to bool value is possible according to current settings */
! 	bool isValid (const QString &value);
  };
  
  class RKComponentPropertyInt;		// min, max
  class RKComponentPropertyDouble;		// min, max
  
  class RObject;
  
--- 98,121 ----
  	QString value (const QString &modifier=QString::null);
  /** reimplemented from RKComponentPropertyBase to convert to bool value according to current settings */
! 	bool setValue (const QString &string);
  /** reimplemented from RKComponentPropertyBase to test whether conversion to bool value is possible according to current settings */
! 	bool isStringValid (const QString &string);
! private:
! /** helper function. Sets the value without emitting change signal */
! 	void internalSetValue (bool new_value);
! /** helper function. Sets the value without emitting change signal */
! 	void internalSetValue (QString new_value);
! 	bool default_value;
! 	bool current_value;
! 	QString value_true;
! 	QString value_false;
  };
  
+ ///////////////////////////////////////////////// Int ////////////////////////////////////////////////////////
  class RKComponentPropertyInt;		// min, max
+ ///////////////////////////////////////////////// Double ////////////////////////////////////////////////////////
  class RKComponentPropertyDouble;		// min, max
  
+ ///////////////////////////////////////////////// RObject ////////////////////////////////////////////////////////
  class RObject;
  
***************
*** 107,111 ****
  	void setDimensionFilter (int dimensionality, int min_length=-1, int max_length=-1);
  	bool setValue (RObject *object);
! 	bool isValid (RObject *object);
  	RObject *objectValue ();
  /** reimplemented from RKComponentPropertyBase. Modifier "label" returns label. Modifier "shortname" returns short name. Modifier QString::null returns full name. */
--- 128,132 ----
  	void setDimensionFilter (int dimensionality, int min_length=-1, int max_length=-1);
  	bool setValue (RObject *object);
! 	bool isObjectValid (RObject *object);
  	RObject *objectValue ();
  /** reimplemented from RKComponentPropertyBase. Modifier "label" returns label. Modifier "shortname" returns short name. Modifier QString::null returns full name. */
***************
*** 117,120 ****
--- 138,143 ----
  };
  
+ ///////////////////////////////////////////////// RObjectList ////////////////////////////////////////////////////////
+ 
  #include <qvaluelist.h>
  
***************
*** 125,129 ****
  	bool addValue (RObject *object);
  	void removeValue (RObject *object);
! 	bool isValid (RObject *object);
  /** reimplemented from RKComponentPropertyBase to return the first RObject in the list */
  	RObject *objectValue ();
--- 148,152 ----
  	bool addValue (RObject *object);
  	void removeValue (RObject *object);
! 	bool isObjectValid (RObject *object);
  /** reimplemented from RKComponentPropertyBase to return the first RObject in the list */
  	RObject *objectValue ();
***************
*** 137,140 ****
--- 160,165 ----
  };
  
+ ///////////////////////////////////////////////// Code ////////////////////////////////////////////////////////
+ 
  /** special type of RKComponentProperty used to contain R code. All stand-alone RKComponents have this. The great thing about this, is that code can be made available to embedding RKComponents by just fetching the component.code.preprocess (or .calculate, .printout, .cleanup) value */
  class RKComponentPropertyCode : public RKComponentPropertyBase {





More information about the rkward-tracker mailing list