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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Apr 18 22:47:51 UTC 2007


Revision: 1829
          http://svn.sourceforge.net/rkward/?rev=1829&view=rev
Author:   tfry
Date:     2007-04-18 15:47:51 -0700 (Wed, 18 Apr 2007)

Log Message:
-----------
Make boolean modifier not return a boolean sub-property

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

Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp	2007-04-18 19:18:17 UTC (rev 1828)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp	2007-04-18 22:47:51 UTC (rev 1829)
@@ -23,13 +23,14 @@
 
 RKComponentBase* RKComponentBase::lookupComponent (const QString &identifier, QString *remainder) {
 	RK_TRACE (PLUGIN);
+	RK_ASSERT (remainder);
 
 	if (identifier.isEmpty ()) return this;
 	RK_DO (qDebug ("looking up '%s'", identifier.latin1 ()), PLUGIN, DL_DEBUG);
 
 	RKComponentBase *child = child_map.find (identifier.section (".", 0, 0));
 	if (!child) {	// if we do not have such a child, return 0 unless this is a property
-		if (remainder) *remainder = identifier;
+		*remainder = identifier;
 		return this;
 	} else {	// else do recursive lookup
 		return child->lookupComponent (identifier.section (".", 1), remainder);

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2007-04-18 19:18:17 UTC (rev 1828)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2007-04-18 22:47:51 UTC (rev 1829)
@@ -161,11 +161,32 @@
 	RK_TRACE (PLUGIN);
 }
 
+RKComponentBase* RKComponentPropertyBool::lookupComponent (const QString &identifier, QString *remainder) {
+	RK_TRACE (PLUGIN);
+
+	RKComponentBase *dummy = RKComponentPropertyBase::lookupComponent (identifier, remainder);
+	if (dummy != this) return dummy;
+
+	QString next = identifier.section (".", 0, 0);
+	if (next == "not") {
+		RKComponentPropertyBool *negated = new RKComponentPropertyBool (this, false, false, value_true, value_false);
+		negated->setInverted (true);
+		negated->connectToGovernor (this);
+		*remainder = identifier.section (".", 1);
+		addChild ("not", negated);		// so subsequent lookups will not recreate the negated property
+		return (negated);
+	}
+
+	return (this);
+}
+
 void RKComponentPropertyBool::internalSetValue (bool new_value) {
 	RK_TRACE (PLUGIN);
 
-	current_value = new_value;
-	if (new_value) {
+	if (inverted) current_value = !new_value;
+	else current_value = new_value;
+
+	if (current_value) {
 		_value = value_true;
 	} else {
 		_value = value_false;
@@ -176,14 +197,11 @@
 void RKComponentPropertyBool::internalSetValue (const 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;
+		internalSetValue (true);
 	} else if (new_value == value_false) {
-		current_value = false;
+		internalSetValue (false);
 	} else {
 		is_valid = false;
 	}
@@ -208,10 +226,6 @@
 	if (modifier.isEmpty ()) return _value;
 	if (modifier == "true") return value_true;
 	if (modifier == "false") return value_false;
-	if (modifier == "not") {
-		if (current_value) return value_false;
-		else return value_true;
-	}
 	if (modifier == "numeric") {
 		if (current_value) return "1";
 		else return "0";

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.h	2007-04-18 19:18:17 UTC (rev 1828)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.h	2007-04-18 22:47:51 UTC (rev 1829)
@@ -79,6 +79,8 @@
 	RKComponentPropertyBool (QObject *parent, bool required, bool default_state=true, const QString &value_true="true", const QString &value_false="false");
 /** destructor */
 	~RKComponentPropertyBool ();
+/** Set this property to the inverted, i.e. true if set to false and vice-versa. Used for the "not" sub-property. */
+	void setInverted (bool invert) { inverted = invert; };
 /** sets the bool value. Also takes care of notifying dependent components */
 	void setBoolValue (bool new_value);
 /** current value as bool */
@@ -93,6 +95,8 @@
 	void governorValueChanged (RKComponentPropertyBase *property);
 /** RTTI */
 	int type () { return PropertyBool; };
+/** reimplemented to return a new negated boolean property if the identifier is "not" */
+	RKComponentBase* lookupComponent (const QString &identifier, QString *remainder);
 private:
 /** helper function. Sets the value without emitting change signal */
 	void internalSetValue (bool new_value);
@@ -100,6 +104,7 @@
 	void internalSetValue (const QString &new_value);
 	bool default_value;
 	bool current_value;
+	bool inverted;
 	QString value_true;
 	QString value_false;
 };


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