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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Sep 9 09:55:18 UTC 2011


Revision: 3735
          http://rkward.svn.sourceforge.net/rkward/?rev=3735&view=rev
Author:   tfry
Date:     2011-09-09 09:55:18 +0000 (Fri, 09 Sep 2011)
Log Message:
-----------
Remove some confusion and duplication between isValid() and isSatisfied(). Fix a small bug in RObjects-properties.

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

Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp	2011-09-09 09:15:55 UTC (rev 3734)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp	2011-09-09 09:55:18 UTC (rev 3735)
@@ -145,15 +145,6 @@
 	return QString ();
 }
 
-bool RKComponentBase::isSatisfied () {
-	RK_TRACE (PLUGIN);
-	if (!required) return true;
-	if (isComponent () && static_cast<RKComponent*>(this)->isInactive ()) return true;
-	if (isValid ()) return true;
- 	if (isComponent ()) RK_DO (qDebug ("component not satisfied: %s", qPrintable (static_cast<RKComponent*> (this)->getIdInParent ())), PLUGIN, DL_DEBUG);
-	return false;		// never happens in RKComponentBase, but might in subclasses
-}
-
 RKComponentBase::ComponentStatus RKComponentBase::recursiveStatus () {
 	RK_TRACE (PLUGIN);
 
@@ -170,7 +161,8 @@
 	bool req = required;
 	if (isComponent () && static_cast<RKComponent*>(this)->isInactive ()) req = false;
 	if (!req) return Satisfied;
-	if (children_satisfied && isSatisfied ()) return Satisfied;
+	if (children_satisfied && isValid ()) return Satisfied;
+ 	if (isComponent ()) RK_DO (qDebug ("component not satisfied: %s", qPrintable (static_cast<RKComponent*> (this)->getIdInParent ())), PLUGIN, DL_DEBUG);
 	return Unsatisfied;
 }
 
@@ -254,17 +246,6 @@
 	return false;
 }
 
-bool RKComponent::isValid () {
-	RK_TRACE (PLUGIN);
-
-	// TODO: It's sort of lame to iterate over all children, here, as typically this is called indirectly from recursiveStatus(), and that iterates over the children, too.
-	// However, iterating over the children is required to make isSatisfied() return a sensible answer.
-	for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
-		if (!(it.value ()->isSatisfied ())) return false;
-	}
-	return true;
-}
-
 bool RKComponent::isWizardish () {
 	RK_TRACE (PLUGIN);
 

Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h	2011-09-09 09:15:55 UTC (rev 3734)
+++ trunk/rkward/rkward/plugin/rkcomponent.h	2011-09-09 09:55:18 UTC (rev 3735)
@@ -69,10 +69,10 @@
 		NoSuchComponent
 	};
 	enum ComponentStatus {
-		Dead,
-		Processing,
-		Unsatisfied,
-		Satisfied
+		Dead,		/**< one or more components are dead */
+		Processing,		/**< one or more components are still processing. */
+		Unsatisfied,		/**< the component is required, but it or one of its (required) children are not valid. */
+		Satisfied		/**< the component is not required, or it, and all of its children are satisfied. */
 	};
 /** for RTTI. see RKComponentBase::RKComponentTypes */
 	virtual int type () = 0;
@@ -88,13 +88,17 @@
 /** returns true, if this is a property */
 	bool isProperty () { return (type () <= PropertyEnd); };
 	bool isComponent () { return (type () >= ComponentBase); };
-/** returns satisfaction state. see setRequired () */
-	bool isSatisfied ();
-/** returns somewhat more elaborate state than isSatisfied(). (Effectively identical in the base class). */
+/** shorthand for recursiveStatus () == Satisfied */
+	bool isSatisfied () { return (recursiveStatus () == Satisfied); };
+/** returns state of the component. @see ComponentStatus */
 	virtual ComponentStatus recursiveStatus ();
-/** currently valid (i.e. satisfied, even if required)? default implementation always returns true */
+/** currently valid? default implementation always returns true. @see recursiveStatus()
+  * reimplement this in subclasses, if components may become invalid.
+  * 
+  * @note: A component will be "satisfied" even when invalid, if is is not required. Also, a required component is implictily not satisfied, if any of its children are not statisfied.
+  * In general, use isSatisfied() to query the status of components, not isValid(). */
 	virtual bool isValid () { return true; };
-/** set to required: will only be satisfied if it is valid. Else: always satisfied (but subclasses might override to always be dissatisfied on really bad values. By default RKComponentBase is required at construction */
+/** set to required: will only be satisfied if it is valid (and all it's children). Else: always satisfied (but subclasses might override to always be dissatisfied on really bad values. By default RKComponentBase is required at construction */
 	void setRequired (bool require) { required = require; };
 /** simple convenience function to add a child to the map of children */
 	void addChild (const QString &id, RKComponentBase *child);
@@ -138,8 +142,6 @@
 	int type () { return Component; };
 /** change notification mechanism. Call this, if something in the component changed that could result in a change in code/values/satisfaction state. Default implementation propagates the change upwards to parent components, if any, but does not do anything further. Reimplement, for instance, to regenerate code */
 	virtual void changed ();
-/** reimplemented to only return true, if all children are satisfied */
-	bool isValid ();
 /** The component as a wizardish (multi-page) interface. Default implementation returns false */
 	virtual bool isWizardish ();
 /** If the component isWizardish (), returns true, if it has a next/previous page

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2011-09-09 09:15:55 UTC (rev 3734)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2011-09-09 09:55:18 UTC (rev 3735)
@@ -987,11 +987,11 @@
 	RK_TRACE (PLUGIN);
 
 	is_valid = true;	// innocent until proven guilty
-	if (min_num_objects || max_num_objects || min_num_objects_if_any) {
+	if ((min_num_objects > 0) || (max_num_objects > 0) || (min_num_objects_if_any > 0)) {
 		int len = object_list.count ();
 		if (len < min_num_objects) is_valid = false;
 		if (len && (len < min_num_objects_if_any)) is_valid = false;
-		if (max_num_objects && (len > max_num_objects)) is_valid = false;
+		if ((max_num_objects > 0) && (len > max_num_objects)) is_valid = 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