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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon May 21 11:14:16 UTC 2012


Revision: 4256
          http://rkward.svn.sourceforge.net/rkward/?rev=4256&view=rev
Author:   tfry
Date:     2012-05-21 11:14:15 +0000 (Mon, 21 May 2012)
Log Message:
-----------
Intial version of optionset compiles, but is still entirely untested / unused

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

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2012-05-19 10:52:01 UTC (rev 4255)
+++ trunk/rkward/ChangeLog	2012-05-21 11:14:15 UTC (rev 4256)
@@ -1,3 +1,4 @@
+- Fixed: "Next"-button in wizards would remain enabled while settings are missing on a page
 - Fixed: Dynamic pages in a wizard would cause a layout bug on the first page
 - Do not offer to restore individual removed columns of a data.frame opened for editing
 - Fixed: Plot history and graphical menus broken in some cases with R 2.15.0		TODO: backport? (r4182)

Modified: trunk/rkward/rkward/plugin/CMakeLists.txt
===================================================================
--- trunk/rkward/rkward/plugin/CMakeLists.txt	2012-05-19 10:52:01 UTC (rev 4255)
+++ trunk/rkward/rkward/plugin/CMakeLists.txt	2012-05-21 11:14:15 UTC (rev 4256)
@@ -25,6 +25,7 @@
    rkpluginsaveobject.cpp
    rkabstractoptionselector.cpp
    rkpluginframe.cpp
+   rkoptionset.cpp
    )
 
 QT4_AUTOMOC(${plugin_STAT_SRCS})

Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h	2012-05-19 10:52:01 UTC (rev 4255)
+++ trunk/rkward/rkward/plugin/rkcomponent.h	2012-05-21 11:14:15 UTC (rev 4256)
@@ -116,6 +116,7 @@
 	void setInternal (bool internal) { is_internal = internal; };
 	bool isInternal () const { return is_internal; };
 protected:
+	friend class RKOptionSet;
 	QHash<QString, RKComponentBase*> child_map;
 	bool required;
 /** 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 ());

Modified: trunk/rkward/rkward/plugin/rkoptionset.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-05-19 10:52:01 UTC (rev 4255)
+++ trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-05-21 11:14:15 UTC (rev 4256)
@@ -19,6 +19,7 @@
 
 #include <QVBoxLayout>
 #include <QTableWidget>
+#include <QHeaderView>
 
 #include <klocale.h>
 #include <kvbox.h>
@@ -28,18 +29,18 @@
 
 #include "../debug.h"
 
-RKOptionSet::RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget, RKStandardComponentBuilder *builder) : RKComponent (parent_component, parent_widget) {
+RKOptionSet::RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
 	RK_TRACE (PLUGIN);
 
 	XMLHelper *xml = XMLHelper::getStaticHelper ();
 	updating_from_contents = updating_from_storage = false;
 	connect (&update_timer, SIGNAL (timeout()), this, SLOT (updateContents()));
-	update_timer->setSingleShot (true);
-	update_timer->setTimeout (0);
+	update_timer.setSingleShot (true);
+	update_timer.setInterval (0);
 
-	min_rows = xml->getIntAttribute (e, "min_rows", 0, DL_INFO);
-	min_rows_if_any = xml->getIntAttribute (e, "min_rows_if_any", 0, DL_INFO);
-	max_rows = xml->getIntAttribute (e, "max", INT_MAX, DL_INFO);
+	min_rows = xml->getIntAttribute (element, "min_rows", 0, DL_INFO);
+	min_rows_if_any = xml->getIntAttribute (element, "min_rows_if_any", 1, DL_INFO);
+	max_rows = xml->getIntAttribute (element, "max", INT_MAX, DL_INFO);
 
 	// create some meta properties
 	current_row = new RKComponentPropertyInt (this, false, -1);
@@ -75,7 +76,7 @@
 		QString governor = xml->getStringAttribute (e, "connect", QString (), DL_WARNING);
 		bool restorable = xml->getBoolAttribute (e, "restorable", true, DL_INFO);
 
-		while (columns_to_governors.contains (id) || child_map.contains (id)) {
+		while (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;
 		}
@@ -103,15 +104,15 @@
 	keycolumn = 0;
 	QString keycol = xml->getStringAttribute (element, "keycolumn", QString (), DL_DEBUG);
 	if (!keycol.isEmpty ()) {
-		if (!columns_to_governors.contains (keycol)) {
+		keycolumn = static_cast<RKComponentPropertyStringList*> (child_map.value (keycol));
+		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);
-		} else {
-			keycolumn = static_cast<RKComponentPropertyStringList*> (child_map[keycol]);
+			keycolumn = 0;
 		}
 	}
 
-	QMap<RKComponentPropertyStringList *, ColumnInfo>::const_iterator it = column_map.constBegin ();
-	for (; it != column_map.constEnd (); ++it) {
+	QMap<RKComponentPropertyStringList *, ColumnInfo>::iterator it = column_map.begin ();
+	for (; it != column_map.end (); ++it) {
 		ColumnInfo &ci = it.value ();
 		if (!ci.governor.isEmpty ()) {		// there *can* be columns without governor. This allows to connect two option-sets, e.g. on different pages of a tabbook, manually
 			// Establish connections between columns and their respective governors. Since the format differs, the connection is done indirectly, through this component.
@@ -120,7 +121,7 @@
 			if (governor && governor->isProperty ()) {
 				RKComponentPropertyBase *gov_prop = static_cast<RKComponentPropertyBase*> (governor);
 				if (ci.restorable) {
-					if (!modifier.isEmpty ()) {
+					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);
 						continue;
 					} else if (gov_prop->isInternal ()) {
@@ -209,7 +210,7 @@
 	if (display && (inf.display_index >= 0)) {
 		display->removeColumn (inf.display_index);
 		display->insertColumn (inf.display_index);
-		QStringList values = property->values ();
+		QStringList values = target->values ();
 		for (int row = 0; row < values.size (); ++row) {
 			display->setItem (row, inf.display_index, new QTableWidgetItem (values[row]));
 		}
@@ -217,7 +218,7 @@
 	if (inf.restorable) update_timer.start ();
 
 	if (target == keycolumn) {
-		QStringList new_keys = property->values ();;
+		QStringList new_keys = target->values ();;
 		QMap<int, int> position_changes;
 
 		for (int new_pos = 0; new_pos < new_keys.size (); ++new_pos) {
@@ -236,7 +237,7 @@
 		QMap<RKComponentPropertyStringList *, ColumnInfo>::const_iterator it = column_map.constBegin ();
 		for (; it != column_map.constEnd (); ++it) {
 			RKComponentPropertyStringList* col = it.key ();
-			ColumnInfo &column = it.value ();
+			const ColumnInfo &column = it.value ();
 			if (columns_which_have_been_updated_externally.contains (col) || col == keycolumn) {
 				continue;
 			}
@@ -256,13 +257,13 @@
 						new_values[pos] = column.default_value;
 #warning TODO: should also allow scripted defaults
 					} else {	// old key changed position
-						new_values[pos] = old_values (old_pos);
+						new_values[pos] = old_values[old_pos];
 					}
 				}
 			}
 
 			// strip excess length (if any), and apply
-			new_values = new_values.left (new_keys.size ());
+			new_values = new_values.mid (0, new_keys.size ());
 			col->setValues (new_values);
 			// NOTE: this will recurse into the current function, triggering an update of display and contents
 		}
@@ -290,23 +291,29 @@
 	RK_ASSERT (!updating_from_storage);
 	updating_from_storage = true;
 
+	int count = -1;
 	int row = current_row->intValue ();
 	if (row < 0) {
-		contents_container->setPropertyValuesRecursive (defaults);
+		contents_container->setPropertyValues (&content_defaults);
 	} else {
 		QMap<RKComponentPropertyStringList *, ColumnInfo>::const_iterator it = column_map.constBegin ();
 		for (; it != column_map.constEnd (); ++it) {
 			RKComponentPropertyStringList* col = it.key ();
-			ColumnInfo &ci = it.value ();
+			const ColumnInfo &ci = it.value ();
+			if (it == column_map.constBegin ()) count = col->values ().size ();
 			if (!ci.restorable) continue;
-			RKComponentBase *governor = contents_container->lookupComponent (ci.governor);
-			if (governor) {
-				governor->setValue (col->valueAt (row));
+			QString dummy;
+			RKComponentBase *governor = contents_container->lookupComponent (ci.governor, &dummy);
+			if (governor && governor->isProperty ()) {
+				RK_ASSERT (dummy.isEmpty ());
+				static_cast<RKComponentPropertyBase*> (governor)->setValue (col->valueAt (row));
 			} else {
 				RK_ASSERT (false);
 			}
 		}
 	}
+	row_count->setIntValue (count);
+ 	changed ();	// needed, for the unlikely case that no change notification was triggered above, since isValid() returns false while updating
 
 	updating_from_storage = false;
 }
@@ -317,3 +324,12 @@
 	RK_ASSERT (property == current_row);
 	update_timer.start ();
 }
+
+bool RKOptionSet::isValid () {
+	if (update_timer.isActive ()) return (false);	// actually, this signifies "processing" state
+	int count = row_count->intValue ();
+	if (count < min_rows) return false;
+	if ((count > 0) && (count < min_rows_if_any)) return false;
+	if (count > max_rows) return false;
+	return true;
+}

Modified: trunk/rkward/rkward/plugin/rkoptionset.h
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.h	2012-05-19 10:52:01 UTC (rev 4255)
+++ trunk/rkward/rkward/plugin/rkoptionset.h	2012-05-21 11:14:15 UTC (rev 4256)
@@ -21,6 +21,9 @@
 #include <rkcomponent.h>
 
 #include <qmap.h>
+#include <QDomElement>
+#include <QTimer>
+#include <QSet>
 
 class QTableWidget;
 
@@ -30,10 +33,11 @@
 class RKOptionSet : public RKComponent {
 	Q_OBJECT
 public:
-	RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget, RKStandardComponentBuilder *builder);
+	RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget);
 	~RKOptionSet ();
 	int type () { return ComponentOptionSet; };
 	QWidget *createDisplay (bool show_index, QWidget *parent);
+	bool isValid ();
 private slots:
 	void governingPropertyChanged (RKComponentPropertyBase *property);
 	void columnPropertyChanged (RKComponentPropertyBase *property);
@@ -72,7 +76,7 @@
 	int max_rows;
 
 	bool updating_from_contents;
-	bool udpating_from_storage;
+	bool updating_from_storage;
 	QSet<RKComponentPropertyStringList *> columns_which_have_been_updated_externally;
 };
 

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