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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Nov 25 11:46:13 UTC 2011


Revision: 4051
          http://rkward.svn.sourceforge.net/rkward/?rev=4051&view=rev
Author:   tfry
Date:     2011-11-25 11:46:12 +0000 (Fri, 25 Nov 2011)
Log Message:
-----------
A bit more on optionsets. Still incomplete, and does not get compiled, yet.

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

Modified: trunk/rkward/rkward/plugin/rkoptionset.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.cpp	2011-11-24 18:54:27 UTC (rev 4050)
+++ trunk/rkward/rkward/plugin/rkoptionset.cpp	2011-11-25 11:46:12 UTC (rev 4051)
@@ -18,6 +18,7 @@
 #include "rkoptionset.h"
 
 #include <QVBoxLayout>
+#include <QTableWidget>
 
 #include <klocale.h>
 #include <kvbox.h>
@@ -31,6 +32,7 @@
 	RK_TRACE (PLUGIN);
 
 	XMLHelper *xml = XMLHelper::getStaticHelper ();
+	updating_from_contents = changing_row = false;
 
 	// create some meta properties
 	current_row = new RKComponentPropertyInt (this, false, -1);
@@ -57,37 +59,48 @@
 	XMLChildList options = xml->getChildElements (element, "option", DL_WARNING);
 
 	int visible_columns = 0;
-	QQStringList column_labels;
-	QMap<QString, QString> columns_to_governors;
+	QMap<RKComponentPropertyStringList *, QString> columns_to_governors;
 	for (int i = 0; i < options.size (); ++i) {
-		QString id = xml->getStringAttribute (options.at (i), "id", QString (), DL_ERROR);
-		QString label = xml->getStringAttribute (options.at (i), "label", QString (), DL_DEBUG);
-		QString governor = xml->getStringAttribute (options.at (i), "governor", QString (), DL_WARNING);
+		const QDomElement &e = options.at (i);
+		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_WARNING);
+		QString display_modifier = xml->getStringAttribute (e, "display_modifier", QString (), DL_WARNING);
 
 		while (columns_to_governors.contains (id) || child_map.contains (id)) {
 			RK_DO (qDebug ("optionset already contains a property named %s. Renaming to _%s", qPrintable (id), qPrintable (id)), PLUGIN, DL_ERROR);
 			id = "_" + id;
 		}
-		columns_to_governors.insert (id, governor);
+
+		ColumnInfo col_inf;
+		col_inf.column_name = id;
 		if (!label.isEmpty ()) {
-			column_labels.append (label);
-			column_to_display_index_map.insert (id, visible_columns++);
+			col_inf.display_index = visible_columns++;
+			col_inf.column_label = label;
+			col_inf.display_modifier = display_modifier;
+		} else {
+			col_inf.display_index = -1;
 		}
+
+		RKComponentPropertyStringList *column_property = new RKComponentPropertyStringList (this, false);
+		addChild (id, column_property);
+		connect (column_property, SIGNAL (valueChanged(RKComponentPropertyBase *)), this, SLOT (columnPropertyChanged(RKComponentPropertyBase *)));
+		columns_to_governors.insert (column_property, governor);
+		column_map.insert (column_property, col_inf);
 	}
 
-	keycolumn = xml->getStringAttribute (element, "keycolumn", QString (), DL_DEBUG);
-	if (!columns_to_governors.contains (keycolumn)) {
-		RK_DO (qDebug ("optionset does not contain a column named %s. Falling back to manual insertion mode", qPrintable (keycolumn)), PLUGIN, DL_ERROR);
-		keycolumn.clear ();
+	keycolumn = 0;
+	QString keycol = xml->getStringAttribute (element, "keycolumn", QString (), DL_DEBUG);
+	if (!keycol.isEmpty ()) {
+		if (!columns_to_governors.contains (keycol)) {
+			RK_DO (qDebug ("optionset does not contain a column named %s. Falling back to manual insertion mode", qPrintable (keycol)), PLUGIN, DL_ERROR);
+		} else {
+			keycolumn = static_cast<RKComponentPropertyStringList*> (child_map[keycol]);
+		}
 	}
 
-	QMap<QString, QString>::const_iterator it = columns_to_governors.constBegin ();
+	QMap<RKComponentPropertyStringList *, QString>::const_iterator it = columns_to_governors.constBegin ();
 	for (; it != columns_to_governors.constEnd (); ++it) {
-		// add columns
-		RKComponentPropertyStringList *column_property = new RKComponentPropertyStringList (this, false);
-		addChild (it.key (), column_property);
-		connect (column_property, SIGNAL (valueChanged(RKComponentPropertyBase *)), this, SLOT (columnPropertyChanged(RKComponentPropertyBase *)));
-
 		if (!it ().value ().isEmpty ()) {		// there *can* be columns without governor. This allows to connect two option-sets, e.g. on different pages of a tabbook.
 			// Establish connections between columns and their respective governors. Since the format differs, the connection is done indirectly, through this component.
 			// So, here, we set up a map of properties to columns, and connect to the change signals.
@@ -95,15 +108,92 @@
 			RKComponentBase *governor = container->lookupComponent (it.value (), &modifier);
 			if (governor && governor->isProperty ()) {
 				RKComponentPropertyBase *gov_prop = static_cast<RKComponentPropertyBase*> (governor);
-				ModifierAndColumn mac;
-				mac.modifier = modifier;
-				mac.column_name = it.key ();
-				property_to_column_map.insertMulti (gov_prop, mac);
-				connect (gov_prop, SIGNAL (valueChanged(RKComponentPropertyBase *)), this, SLOT (governingPropertyChanged(RKComponentPropertyBase *)));
+				if (!modifier.isEmpty ()) {
+					RK_DO (qDebug ("Cannot connect column in optionset to property with modifier (%s). Use display_modifier, instead.", qPrintable (it.value ()), qPrintable (it.key ())), PLUGIN, DL_ERROR);
+				} else if (gov_prop->isInternal ()) {
+					RK_DO (qDebug ("Cannot connect column in optionset to property (%s), which is marked 'internal'.", qPrintable (it.value ())), PLUGIN, DL_ERROR);
+				} else {
+					columns_to_update.insertMulti (gov_prop, it.key ());
+					connect (gov_prop, SIGNAL (valueChanged(RKComponentPropertyBase *)), this, SLOT (governingPropertyChanged(RKComponentPropertyBase *)));
+				}
 			} else {
 				RK_DO (qDebug ("did not find governing property %s for column %s of optionset", qPrintable (it.value ()), qPrintable (it.key ())), PLUGIN, DL_ERROR);
 			}
 		}
 	}
+
+	if (display) {		// may or may not have been created
+		QVector<QString> headers (visible_columns, QString ());
+		QMap<RKComponentPropertyStringList *, ColumnInfo>::const_iterator it = column_map.constBegin ();
+		for (; it != column_map.constEnd (); ++it) {
+			const ColumnInfo &inf = it.value ();
+			if (inf.display_index >= 0) {
+				RK_ASSERT (headers.size () >= inf.display_index);
+				headers[inf.display_index] = inf.column_label;
+			}
+		}
+		display->setColumnCount (headers.size ());
+		display->setHorizontalHeaderLabels (QStringList (headers.toList ()));
+		display->verticalHeader ()->setVisible (display_show_index);
+	}
 }
 
+RKOptionSet::~RKOptionSet () {
+	RK_TRACE (PLUGIN);
+}
+
+QWidget *RKOptionSet::createDisplay (bool show_index, QWidget *parent) {
+	RK_TRACE (PLUGIN);
+
+	if (display) {
+		RK_DO (qDebug ("cannot create more than one optiondisplay per optionset"), PLUGIN, DL_ERROR);
+	} else {
+		display = new QTableWidget (parent);
+		display_show_index = show_index;
+	}
+	return (display);
+}
+
+void RKOptionSet::governingPropertyChanged (RKComponentPropertyBase *property) {
+	RK_TRACE (PLUGIN);
+
+	if (changing_row) return;
+	updating_from_contents = true;
+
+	int row = current_row->intValue ();
+	if (row < 0) {
+		RK_ASSERT (false);
+		return;
+	}
+
+	QList<RKComponentPropertyStringList *> cols = columns_to_update.values (property);
+	for (int i = 0; i < cols.size (); ++i) {
+		const ColumnInfo &inf = cols.at (i);
+		RKComponentPropertyBase *t = child_map.value (inf.column_name);
+		if ((!t) || (t->type () != RKComponent::PropertyStringList)) {
+			RK_ASSERT (false);
+			continue;
+		}
+
+		RKComponentPropertyStringList *target = static_cast<RKComponentPropertyStringList *> (t);
+		target->setValueAt (row, property->value ());
+
+		if (!display) continue;
+		const ColumnInfo &inf = column_map[target];
+		if (inf.display_index >= 0) {
+			QString value = property->value (inf.display_modifier);
+			display->setItem (row, inf.display_index, new QTableWidgetItem (value));
+		}
+	}
+
+	updating_from_contents = false;
+}
+
+void RKOptionSet::columnPropertyChanged (RKComponentPropertyBase *property) {
+	RK_TRACE (PLUGIN);
+
+	if (updating_from_contents) return;
+#error TODO
+}
+
+void RKOptionSet::currentRowPropertyChanged (RKComponentPropertyBase *property);

Modified: trunk/rkward/rkward/plugin/rkoptionset.h
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.h	2011-11-24 18:54:27 UTC (rev 4050)
+++ trunk/rkward/rkward/plugin/rkoptionset.h	2011-11-25 11:46:12 UTC (rev 4051)
@@ -33,7 +33,7 @@
 	RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget, RKStandardComponentBuilder *builder);
 	~RKOptionSet ();
 	int type () { return ComponentOptionSet; };
-	QWidget *createDisplay (bool show_index);
+	QWidget *createDisplay (bool show_index, QWidget *parent);
 private slots:
 	void governingPropertyChanged (RKComponentPropertyBase *property);
 	void columnPropertyChanged (RKComponentPropertyBase *property);
@@ -41,16 +41,20 @@
 	void addRow ();
 	void removeRow (int index);
 private:
+	void initDisplay ();
+
 	QMap<QString, QString> defaults;
 /** for option sets which are "driven" (i.e. the user cannot simply add / remove rows, directly), this holds the key column, controlling addition / removal of rows in the set.
   * if this length (or order) is changed in this row, it will also be changed in the other rows. */
 	QString keycolumn;
-	struct ModifierAndColumn {
-		QString modifier;
+	QMultiMap<RKComponentPropertyBase *, RKComponentPropertyStringList *> columns_to_update;
+	struct ColumnInfo {
 		QString column_name;
+		QString column_label;
+		int display_index;
+		QString display_modifier;
 	};
-	QMultiMap<RKComponentPropertyBase *, ModifierAndColumn> property_to_column_map;
-	QMap<RKComponentPropertyStringList *, int> column_to_display_index_map;
+	QMap<RKComponentPropertyStringList *, ColumnInfo> column_map;
 	RKComponent *container;
 	QTableWidget *display;
 	bool display_show_index;
@@ -60,6 +64,10 @@
 	int min_rows;
 	int min_rows_if_any;
 	int max_rows;
+
+	bool updating_from_contents;
+	bool changing_row;
+	QStringList columns_which_have_been_updated_externally;
 };
 
 #endif

Modified: trunk/rkward/rkward/plugins/testing/scatterplot2.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/scatterplot2.xml	2011-11-24 18:54:27 UTC (rev 4050)
+++ trunk/rkward/rkward/plugins/testing/scatterplot2.xml	2011-11-25 11:46:12 UTC (rev 4051)
@@ -9,10 +9,10 @@
 				<row>
 					<varselector id="selector" />
 					<optionset id="vars">  <!-- for auto-mode: keycolumn="..." -->
-						<option id="xvar" label="X" governor="xsel.available"/>
-						<option id="yvar" label="Y" governor="ysel.available"/>
-						<option id="custom_color" governor="colorframe.checked"/> <!-- unlabeled columns will not be shown in the optiondisplay -->
-						<option id="color" governor="color.color.string"/>
+						<option id="xvar" label="X" connect="xsel.available" display_modifier="shortname"/>
+						<option id="yvar" label="Y" connect="ysel.available" display_modifier="shortname"/>
+						<option id="custom_color" connect="colorframe.checked"/> <!-- unlabeled columns will not be shown in the optiondisplay -->
+						<option id="color" connect="color.color.string"/>
 						<content>
 							<optiondisplay show_index="true"/>
 							<varslot source="selector" id="xsel" label="X Variable" required="true"/>

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