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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Dec 5 15:16:18 UTC 2012


Revision: 4478
          http://rkward.svn.sourceforge.net/rkward/?rev=4478&view=rev
Author:   tfry
Date:     2012-12-05 15:16:17 +0000 (Wed, 05 Dec 2012)
Log Message:
-----------
Inactive elements must also be initialized when switching rows in optionset.
Also add convenience function lookupProperty().

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

Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp	2012-12-05 12:01:18 UTC (rev 4477)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp	2012-12-05 15:16:17 UTC (rev 4478)
@@ -40,13 +40,30 @@
 	}
 }
 
+RKComponentPropertyBase* RKComponentBase::lookupProperty (const QString &identifier, QString *remainder, bool warn) {
+	QString _remainder;
+	QString* p_remainder = remainder;
+	if (!remainder) p_remainder = &_remainder;
+
+	RKComponentBase* p = lookupComponent (identifier, p_remainder);
+	if (p && p->isProperty ()) {
+		if (!remainder && !p_remainder->isEmpty ()) {
+			if (warn) RK_DEBUG (PLUGIN, DL_ERROR, "Modifier is not allowed, here, while looking up property: %s. (Remainder was %s)", qPrintable (identifier), qPrintable (*p_remainder));
+			return 0;
+		}
+		return static_cast<RKComponentPropertyBase*> (p);
+	}
+	if (warn) RK_DEBUG (PLUGIN, DL_ERROR, "No such property: %s. Remainder was %s", qPrintable (identifier), qPrintable (*p_remainder));
+	return 0;
+}
+
 void RKComponentBase::addChild (const QString &id, RKComponentBase *child) {
 	RK_TRACE (PLUGIN);
 
 	child_map.insertMulti (id, child);		// no overwriting even on duplicate ("#noid#") ids
 }
 
-void RKComponentBase::fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level, const QString &prefix) const {
+void RKComponentBase::fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level, const QString &prefix, bool include_inactive_elements) const {
 	RK_TRACE (PLUGIN);
 
 	for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) {
@@ -59,7 +76,7 @@
 			}
 		} else {
 			RK_ASSERT (it.value ()->isComponent ());
-			if (static_cast<RKComponent *> (it.value ())->isInactive ()) continue;
+			if (static_cast<RKComponent *> (it.value ())->isInactive () && (!include_inactive_elements)) continue;
 			it.value ()->fetchPropertyValuesRecursive (list, true, prefix + it.key () + '.');
 		}
 	}

Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h	2012-12-05 12:01:18 UTC (rev 4477)
+++ trunk/rkward/rkward/plugin/rkcomponent.h	2012-12-05 15:16:17 UTC (rev 4478)
@@ -85,6 +85,9 @@
 @param remainder If a non null pointer to QString is given, this will be set to the value of the remaining modifier
 @returns a pointer to the RKComponentBase, if found, or the nearest parent that could be looked up */
 	virtual RKComponentBase* lookupComponent (const QString &identifier, QString *remainder);
+/** Convenience wrapper around lookupComponent(), which will only return properties or 0, and optionally warn, if no prop could be found
+ at param remainder In contrast to lookupComponent, this can be 0. In this case only exact matches are returned. */
+	RKComponentPropertyBase* lookupProperty (const QString &identifier, QString *remainder=0, bool warn=true);
 /** Locate the component.subcomponent.property.value described by identifier and return its value as a string. Especially useful as a callback in code templates! Recursively walks subcomponents/properties until the requested value is found. @See RKComponentBase::lookupComponent */
 	QString fetchStringValue (const QString &identifier);
 	static QString fetchStringValue (RKComponentBase* prop, const QString &modifier=QString ());
@@ -136,8 +139,9 @@
 /** recursively fetch the current values of all properties present as direct or indirect children of this component. Used to transfer values e.g. when switching interfaces (or to store settings per plugin in the future). Values are placed in the dictionary provided (be sure to create one first!). Internal properties are ignored (@see RKComponentPropertyBase::isInternal ());
 @param list the list to store the object values in
 @param include_top_level include direct properties of the component in the list (or only properties of children)
- at param prefix used during recursion to provide full ids for the added objects */
-	virtual void fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level=false, const QString &prefix=QString ()) const;
+ at param prefix used during recursion to provide full ids for the added objects
+ at param include_inactive_elements by default, disabled / hidden elements are omitted from the value map. */
+	virtual void fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level=false, const QString &prefix=QString (), bool include_inactive_elements=false) const;
 	friend class RKComponentBuilder;
 /** counterpart to fetchPropertyValuesRecursive (). Tries to apply all values from the list to properties of the given names. If some keys can not be found, or do not resolve to properties, they are ignored.
 @param list a list of id->value such as generated by fetchPropertyValuesRecursive () */

Modified: trunk/rkward/rkward/plugin/rkoptionset.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-12-05 12:01:18 UTC (rev 4477)
+++ trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-12-05 15:16:17 UTC (rev 4478)
@@ -204,7 +204,7 @@
 void RKOptionSet::fetchDefaults () {
 	RK_TRACE (PLUGIN);
 	RK_ASSERT (default_row_state.isEmpty ());
-	contents_container->fetchPropertyValuesRecursive (&default_row_state);
+	contents_container->fetchPropertyValuesRecursive (&default_row_state, false, QString (), true);
 	contents_container->enablednessProperty ()->setBoolValue (rowCount () > 0);	// no current row; Do this *after* fetching default values, however. Otherwise most values will *not* be read, as the element is disabled
 }
 
@@ -274,9 +274,10 @@
 	return ret;
 }
 
-void RKOptionSet::fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level, const QString &prefix) const {
+void RKOptionSet::fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level, const QString &prefix, bool include_inactive_elements) const {
 	RK_TRACE (PLUGIN);
 	RK_ASSERT (include_top_level);
+	RK_ASSERT (!include_inactive_elements);
 
 	QString serialization;
 
@@ -709,7 +710,20 @@
 
 	RK_ASSERT (rows.size () > row);
 	if (row >= 0) {
-		contents_container->setPropertyValues (&(rows[row].full_row_map), false);
+		const PropertyValueMap *map = &(rows[row].full_row_map);
+		// If some elements are disabled, these will *not* be contained in the serialization of a row (unless that is still at the default).
+		// They *are* contained in the default_row_state, however, and thus we will apply any properties for which we do not have a value
+		// from the default_row_state, instead.
+		for (PropertyValueMap::const_iterator it = default_row_state.constBegin (); it != default_row_state.constEnd (); ++it) {
+			if (!map->contains (it.key ())) {
+				RKComponentPropertyBase *prop = contents_container->lookupProperty (it.key (), 0, true);
+				if (prop) {		// found a property
+					RK_ASSERT (!prop->isInternal ());
+					prop->setValue (it.value ());
+				}
+			}
+		}
+		contents_container->setPropertyValues (map, false);
 	} else {
 		contents_container->setPropertyValues (&default_row_state, false);
 	}

Modified: trunk/rkward/rkward/plugin/rkoptionset.h
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.h	2012-12-05 12:01:18 UTC (rev 4477)
+++ trunk/rkward/rkward/plugin/rkoptionset.h	2012-12-05 15:16:17 UTC (rev 4478)
@@ -59,7 +59,7 @@
 /** When keys in the key column change, all other columns have to be updated, accordingly. */
 	void handleKeycolumnUpdate ();
 protected:
-	void fetchPropertyValuesRecursive (QMap<QString, QString> *list, bool include_top_level=false, const QString &prefix=QString ()) const;
+	void fetchPropertyValuesRecursive (PropertyValueMap *list, bool include_top_level=false, const QString &prefix=QString (), bool include_inactive_elements=false) const;
 friend class RKOptionSetDisplayModel;
 	int rowCount () const { return row_count->intValue (); };
 	void setRowState (int row, bool finished, bool valid);

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