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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Nov 13 10:03:20 UTC 2012


Revision: 4430
          http://rkward.svn.sourceforge.net/rkward/?rev=4430&view=rev
Author:   tfry
Date:     2012-11-13 10:03:20 +0000 (Tue, 13 Nov 2012)
Log Message:
-----------
Make a few basics of the optionset work, again

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
    trunk/rkward/rkward/plugin/rkoptionset.cpp
    trunk/rkward/rkward/plugin/rkoptionset.h
    trunk/rkward/rkward/plugins/testing/optionset.xml

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2012-11-12 18:17:01 UTC (rev 4429)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2012-11-13 10:03:20 UTC (rev 4430)
@@ -762,9 +762,10 @@
 
 	// remove items from the old list that are not in the new list
 	for (int i = 0; i < object_list.size (); ++i) {
-		if (!newlist.contains (object_list[i])) {
+		RObject *object = object_list[i];
+		if (!newlist.contains (object)) {
 			stopListenForObject (object_list.takeAt (i));
-			problems.remove (object_list[i]);
+			problems.remove (object);
 			--i;
 			changes = true;
 		}

Modified: trunk/rkward/rkward/plugin/rkoptionset.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-11-12 18:17:01 UTC (rev 4429)
+++ trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-11-13 10:03:20 UTC (rev 4430)
@@ -65,6 +65,7 @@
 	builder->makeConnections ();
 	addChild ("contents", contents_container);
 	contents_container->fetchPropertyValuesRecursive (&default_row_state);
+	contents_container->enablednessProperty ()->setBoolValue (false);	// no current row; Do this *after* fetching default values, however
 
 	// create columns
 	XMLChildList options = xml->getChildElements (element, "option", DL_WARNING);
@@ -75,7 +76,7 @@
 		QString id = xml->getStringAttribute (e, "id", QString (), DL_ERROR);
 		QString label = xml->getStringAttribute (e, "label", QString (), DL_DEBUG);
 		QString governor = xml->getStringAttribute (e, "connect", QString (), DL_INFO);
-		bool restorable = xml->getBoolAttribute (e, "restorable", true, DL_INFO);
+		bool external = xml->getBoolAttribute (e, "external", false, DL_INFO);
 
 		while (child_map.contains (id) || (id.startsWith ("_row"))) {
 			RK_DO (qDebug ("optionset already contains a property named %s. Renaming to _%s", qPrintable (id), qPrintable (id)), PLUGIN, DL_ERROR);
@@ -84,7 +85,7 @@
 
 		ColumnInfo col_inf;
 		col_inf.column_name = id;
-		col_inf.restorable = restorable;
+		col_inf.external = external;
 		col_inf.governor = governor;
 #warning TODO: Do we have to wait for the parent component to settle before (re-)fetching defaults?
 #warning -------------- TODO ------------- Do not store defaults per column. Use only implicit defaults, instead.
@@ -114,8 +115,8 @@
 		if (!column_map.contains (keycolumn)) {
 			RK_DO (qDebug ("optionset does not contain a column named %s. Falling back to manual insertion mode", qPrintable (keycol)), PLUGIN, DL_ERROR);
 			keycolumn = 0;
-		} else if (!column_map[keycolumn].restorable) {
-			RK_DO (qDebug ("keycolumn (%s) is not marked as restorable. Falling back to manual insertion mode", qPrintable (keycol)), PLUGIN, DL_ERROR);
+		} else if (!column_map[keycolumn].external) {
+			RK_DO (qDebug ("keycolumn (%s) is not marked as external. Falling back to manual insertion mode", qPrintable (keycol)), PLUGIN, DL_ERROR);
 			keycolumn = 0;
 		}
 	}
@@ -129,12 +130,12 @@
 			RKComponentBase *governor = contents_container->lookupComponent (ci.governor, &ci.governor_modifier);
 			if (governor && governor->isProperty ()) {
 				RKComponentPropertyBase *gov_prop = static_cast<RKComponentPropertyBase*> (governor);
-				if (ci.restorable) {
+				if (ci.external) {
 					if (!ci.governor_modifier.isEmpty ()) {
-						RK_DO (qDebug ("Cannot connect restorable column '%s' in optionset to property with modifier (%s). Add an auxiliary non-restorable column, instead.", qPrintable (ci.column_name), qPrintable (ci.governor)), PLUGIN, DL_ERROR);
+						RK_DO (qDebug ("Cannot connect external column '%s' in optionset to property with modifier (%s).", qPrintable (ci.column_name), qPrintable (ci.governor)), PLUGIN, DL_ERROR);
 						continue;
 					} else if (gov_prop->isInternal ()) {
-						RK_DO (qDebug ("Cannot connect restorable column '%s' in optionset to property (%s), which is marked 'internal'. Add an auxiliary non-restorable column, instead.", qPrintable (ci.column_name), qPrintable (ci.governor)), PLUGIN, DL_ERROR);
+						RK_DO (qDebug ("Cannot connect external column '%s' in optionset to property (%s), which is marked 'internal'.", qPrintable (ci.column_name), qPrintable (ci.governor)), PLUGIN, DL_ERROR);
 						continue;
 					}
 				}
@@ -152,9 +153,10 @@
 		display->setRootIsDecorated (false);
 		if (display_show_index) display->resizeColumnToContents (0);
 		else display->setColumnHidden (0, true);
-		model = new RKOptionSetDisplayModel (this);
 		display->setModel (model);
-		connect (display, SIGNAL (rowChanged(int)), this, SLOT (currentRowChanged (int)));
+		display->setSelectionBehavior (QAbstractItemView::SelectRows);
+		display->setSelectionMode (QAbstractItemView::SingleSelection);
+		connect (display->selectionModel (), SIGNAL (selectionChanged(QItemSelection,QItemSelection)), this, SLOT (currentRowChanged()));
 
 		if (keycolumn) display_buttons->setVisible (false);
 		else {
@@ -185,6 +187,7 @@
 	} else {
 		display = new QTreeView (box);
 		display_show_index = show_index;
+		model = new RKOptionSetDisplayModel (this);
 	}
 
 	display_buttons = new KHBox (dummy);
@@ -225,8 +228,12 @@
 	++n_invalid_rows;
 
 	row_count->setIntValue (nrows + 1);
+	storeRowSerialization (active_row);
 	current_row->setIntValue (active_row = row);
+	setContentsForRow (row);
 	if (display) model->endInsertRows ();
+
+	changed ();
 }
 
 void RKOptionSet::removeRow () {
@@ -259,7 +266,10 @@
 	if ((row < 0) && (nrows > 1)) row = 0;
 	row_count->setIntValue (nrows - 1);
 	current_row->setIntValue (active_row = row);
+	setContentsForRow (row);
 	if (display) model->endRemoveRows ();
+
+	changed ();
 }
 
 QString getDefaultValue (const RKOptionSet::ColumnInfo& ci, int row) {
@@ -284,9 +294,10 @@
 void RKOptionSet::changed () {
 	int row = active_row;
 
-	rows[row].full_row_serialization.clear ();
-	ComponentStatus cs = contents_container->recursiveStatus ();
-	setRowState (row, cs != Processing, cs == Satisfied);
+	if (row > 0) {
+		ComponentStatus cs = contents_container->recursiveStatus ();
+		setRowState (row, cs != Processing, cs == Satisfied);
+	}
 
 	ComponentStatus s = recursiveStatus ();
 	if (s != last_known_status) {
@@ -301,15 +312,11 @@
 void RKOptionSet::governingPropertyChanged (RKComponentPropertyBase *property) {
 	RK_TRACE (PLUGIN);
 
+	int row = active_row;
+	if (row < 0) return;
 	if (updating_from_storage) return;
 	updating_from_contents = true;
 
-	int row = active_row;
-	if (row < 0) {
-		RK_ASSERT (false);
-		return;
-	}
-
 	QList<RKComponentPropertyStringList *> cols = columns_to_update.values (property);
 	for (int i = 0; i < cols.size (); ++i) {
 		RKComponentPropertyStringList *target = cols.at (i);
@@ -334,7 +341,7 @@
 	RKComponentPropertyStringList *target = static_cast<RKComponentPropertyStringList *> (property);
 	RK_ASSERT (column_map.contains (target));
 	ColumnInfo& ci = column_map[target];
-	if (!ci.restorable) {
+	if (!ci.external) {
 		RK_ASSERT (false);
 		return;
 	}
@@ -368,7 +375,7 @@
 	for (; it != column_map.end (); ++it) {
 		RKComponentPropertyStringList* col = it.key ();
 		ColumnInfo &column = it.value ();
-		if (column.restorable) continue;
+		if (column.external) continue;
 
 		// Ok, we'll have to adjust this column. We start by copying the old values, and padding to the
 		// new length (if that is greater than the old).
@@ -426,33 +433,43 @@
 	changed ();
 }
 
+void RKOptionSet::applyContentsFromExternalColumn (RKComponentPropertyStringList* column, int row) {
+	RK_TRACE (PLUGIN);
+
+	const ColumnInfo &ci = column_map[column];
+	if (!ci.external) return;
+
+	QString dummy;
+	RKComponentBase *governor = contents_container->lookupComponent (ci.governor, &dummy);
+	if (governor && governor->isProperty ()) {
+		RK_ASSERT (dummy.isEmpty ());
+
+		QString value;
+		if (row >= 0) value = column->valueAt (row);
+		else value = getDefaultValue (ci, row);
+
+		static_cast<RKComponentPropertyBase*> (governor)->setValue (value);
+	} else {
+		RK_DO (qDebug ("Lookup error while trying to restore row %d of optionset: %s. Remainder: %s", row, qPrintable (ci.governor), qPrintable (dummy)), PLUGIN, DL_WARNING);
+		RK_ASSERT (false);
+	}
+}
+
 void RKOptionSet::setContentsForRow (int row) {
 	RK_TRACE (PLUGIN);
 
-#warning ------------ TODO: If needed, initialize serialization to default values, first! ----------------
-#warning ------------ TODO: Then initialize from serialization ----------------
-#warning ------------ then apply column values as below ----------------
+	RK_ASSERT (rows.size () > row);
+	if (row >= 0) {
+		contents_container->setPropertyValues (&(rows[row].full_row_serialization), false);
+	} else {
+		contents_container->setPropertyValues (&default_row_state, false);
+	}
 	QMap<RKComponentPropertyStringList *, ColumnInfo>::const_iterator it = column_map.constBegin ();
 	for (; it != column_map.constEnd (); ++it) {
 		RKComponentPropertyStringList* col = it.key ();
-		const ColumnInfo &ci = it.value ();
-		if (!ci.restorable) continue;
-
-		QString dummy;
-		RKComponentBase *governor = contents_container->lookupComponent (ci.governor, &dummy);
-		if (governor && governor->isProperty ()) {
-			RK_ASSERT (dummy.isEmpty ());
-
-			QString value;
-			if (row >= 0) value = col->valueAt (row);
-			else value = getDefaultValue (ci, row);
-
-			static_cast<RKComponentPropertyBase*> (governor)->setValue (value);
-		} else {
-			RK_DO (qDebug ("Lookup error while trying to restore row %d of optionset: %s. Remainder: %s", row, qPrintable (ci.governor), qPrintable (dummy)), PLUGIN, DL_WARNING);
-			RK_ASSERT (false);
-		}
+		applyContentsFromExternalColumn (col, row);
 	}
+	contents_container->enablednessProperty ()->setBoolValue (row >= 0);
 }
 
 void RKOptionSet::updateVisuals () {
@@ -471,37 +488,52 @@
 	display->header ()->setPalette (palette);
 }
 
-void RKOptionSet::currentRowPropertyChanged (RKComponentPropertyBase *property) {
+void RKOptionSet::storeRowSerialization (int row) {
 	RK_TRACE (PLUGIN);
 
-	RK_ASSERT (property == current_row);
-	int row = current_row->intValue ();
-	if (row != active_row) {	// May or may not be the case. True, e.g. if a row was removed
-		storeRowSerialization (active_row);
-		active_row = row;
-		contents_container->enablednessProperty ()->setBoolValue (active_row >= 0);
-	}
+	if (row < 0) return;	// No row was active
+	RK_ASSERT (rows.size () > row);
+	rows[row].full_row_serialization.clear ();
+	contents_container->fetchPropertyValuesRecursive (&(rows[row].full_row_serialization));
+}
 
-	if (display) {
-		if (row >= 0) display->setCurrentIndex (model->index (1, row));
+int getCurrentRowFromDisplay (QTreeView* display) {
+	QModelIndexList l = display->selectionModel ()->selectedRows ();
+	if (l.isEmpty ()) return -1;
+	return (l[0].row ());
+}
+
+void setCurrentRowInDisplay (QTreeView* display, int row) {
+	if (row < 0) display->selectionModel ()->clearSelection ();
+	else {
+		display->selectionModel ()->select (display->model ()->index (row, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
 	}
 }
 
-void RKOptionSet::storeRowSerialization (int row) {
+void RKOptionSet::currentRowChanged () {
 	RK_TRACE (PLUGIN);
 
-	if (row < 0) return;	// No row was active
-#warning ---------------- TODO ----------------------
+	RK_ASSERT (display);
+	int r = getCurrentRowFromDisplay (display);
+	if (active_row != r) current_row->setIntValue (r);
+	// --> currentRowPropertyChanged ()
 }
 
-void RKOptionSet::currentRowChanged (int new_row) {
+void RKOptionSet::currentRowPropertyChanged (RKComponentPropertyBase *property) {
 	RK_TRACE (PLUGIN);
 
-	RK_ASSERT (display);
-	current_row->setIntValue (new_row);
-	// --> currentRowPropertyChanged ()
+	RK_ASSERT (property == current_row);
+	int row = current_row->intValue ();
+	if (row != active_row) {	// May or may not be the case. True, e.g. if a row was removed
+		storeRowSerialization (active_row);
+		active_row = row;
+		setContentsForRow (active_row);
+	}
+
+	if (display) setCurrentRowInDisplay (display, row);	// Doing this unconditionally helps fixing up selection problems
 }
 
+
 /** reimplemented from RKComponent */
 RKComponent::ComponentStatus RKOptionSet::recursiveStatus () {
 	RK_TRACE (PLUGIN);
@@ -521,6 +553,9 @@
 	return true;
 }
 
+
+
+
 RKOptionSetDisplayModel::RKOptionSetDisplayModel (RKOptionSet* parent) : QAbstractTableModel (parent) {
 	RK_TRACE (PLUGIN);
 	set = parent;

Modified: trunk/rkward/rkward/plugin/rkoptionset.h
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.h	2012-11-12 18:17:01 UTC (rev 4429)
+++ trunk/rkward/rkward/plugin/rkoptionset.h	2012-11-13 10:03:20 UTC (rev 4430)
@@ -55,13 +55,14 @@
 	void currentRowPropertyChanged (RKComponentPropertyBase *property);
 	void addRow ();
 	void removeRow ();
-	void currentRowChanged (int new_row);
+	void currentRowChanged ();
 private:
 friend class RKOptionSetDisplayModel;
 	void updateVisuals ();
 	int rowCount () const { return row_count->intValue (); };
 	void setRowState (int row, bool finished, bool valid);
 	void storeRowSerialization (int row);
+	void applyContentsFromExternalColumn (RKComponentPropertyStringList* column, int row);
 
 	RKComponentPropertyInt *current_row;
 	RKComponentPropertyInt *row_count;
@@ -80,7 +81,7 @@
 		QString governor_modifier;
 		QString default_value;
 		int display_index;
-		bool restorable;
+		bool external;
 	};
 	/** Map of all columns to their meta info */
 	QMap<RKComponentPropertyStringList *, ColumnInfo> column_map;
@@ -131,7 +132,6 @@
 	int columnCount (const QModelIndex & parent = QModelIndex()) const;
 	QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
 	QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
-	void currentChanged (const QModelIndex& current, const QModelIndex& previous);
 	void triggerReset ();
 	QTimer reset_timer;
 	QStringList column_labels;

Modified: trunk/rkward/rkward/plugins/testing/optionset.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/optionset.xml	2012-11-12 18:17:01 UTC (rev 4429)
+++ trunk/rkward/rkward/plugins/testing/optionset.xml	2012-11-13 10:03:20 UTC (rev 4430)
@@ -9,6 +9,7 @@
 		<connect governor="x.available.shortname" client="set.varname" />
 		<connect governor="mset.object" client="cset.object" />
 		<connect governor="mset.objshort" client="cset.objshort" />
+		<!--		<connect governor="mset.current_row" client="cset.current_row" /> TODO: This causes crashes -->
 	</logic>
 
 	<dialog label="Testing Optionset">
@@ -24,16 +25,16 @@
 							<row>
 								<varselector id="vars"/>
 								<column>
-									<varslot type="numeric" id="x" source="vars" required="true" label="Pick an object"/>	<!-- NOTE: requiredness does not work, correctly, yet -->
-									<input id="summary" label="Enter a summary" size="large"/>
+									<varslot type="numeric" id="mx" source="vars" required="true" label="Pick an object"/>	<!-- NOTE: requiredness does not work, correctly, yet -->
+									<input id="summary" label="Enter a summary" size="large" initial="I am the default"/>
 									<stretch/>
 								</column>
 							</row>
 						</frame>
 					</content>
-					<option id="object" connect="x.available" restorable="true"/>
-					<option id="objshort" label="Object" connect="x.available.shortname" restorable="false"/>
-					<option id="summary" connect="summary.text" restorable="true"/>
+					<option id="object" connect="mx.available"/>
+					<option id="objshort" label="Object" connect="mx.available.shortname"/>
+					<option id="summary" label="Summary" connect="summary.text"/>
 				</optionset>
 			</tab>
 			<tab label="Connected driven set">
@@ -45,9 +46,9 @@
 							<input id="summary" label="Enter another summary" size="large"/>
 						</frame>
 					</content>
-					<option id="object" restorable="false"/>
-					<option id="objshort" label="Object" restorable="false"/>
-					<option id="summary" connect="summary.text" restorable="true"/>
+					<option id="object" external="true"/>
+					<option id="objshort" label="Object" external="true"/>
+					<option id="summary" connect="summary.text"/>
 				</optionset>
 			</tab>
 			<tab label="Driven set">

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