[rkward-cvs] SF.net SVN: rkward:[4257] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Mon May 21 14:09:00 UTC 2012
Revision: 4257
http://rkward.svn.sourceforge.net/rkward/?rev=4257&view=rev
Author: tfry
Date: 2012-05-21 14:08:59 +0000 (Mon, 21 May 2012)
Log Message:
-----------
First mostly functional (but pointless) example of a 'driven' optionset.
Modified Paths:
--------------
trunk/rkward/rkward/plugin/rkoptionset.cpp
trunk/rkward/rkward/plugin/rkoptionset.h
trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
trunk/rkward/rkward/plugins/under_development.pluginmap
Added Paths:
-----------
trunk/rkward/rkward/plugins/testing/optionset.js
trunk/rkward/rkward/plugins/testing/optionset.xml
Modified: trunk/rkward/rkward/plugin/rkoptionset.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.cpp 2012-05-21 11:14:15 UTC (rev 4256)
+++ trunk/rkward/rkward/plugin/rkoptionset.cpp 2012-05-21 14:08:59 UTC (rev 4257)
@@ -18,7 +18,7 @@
#include "rkoptionset.h"
#include <QVBoxLayout>
-#include <QTableWidget>
+#include <QTreeWidget>
#include <QHeaderView>
#include <klocale.h>
@@ -44,7 +44,7 @@
// create some meta properties
current_row = new RKComponentPropertyInt (this, false, -1);
- row_count->setInternal (true);
+ current_row->setInternal (true);
addChild ("current_row", current_row); // NOTE: read-write
connect (current_row, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (currentRowPropertyChanged(RKComponentPropertyBase*)));
row_count = new RKComponentPropertyInt (this, false, 0);
@@ -68,7 +68,7 @@
// create columns
XMLChildList options = xml->getChildElements (element, "option", DL_WARNING);
- int visible_columns = 0;
+ QStringList visible_column_labels;
for (int i = 0; i < options.size (); ++i) {
const QDomElement &e = options.at (i);
QString id = xml->getStringAttribute (e, "id", QString (), DL_ERROR);
@@ -89,8 +89,9 @@
if (e.hasAttribute ("default")) col_inf.default_value = xml->getStringAttribute (e, "default", QString (), DL_ERROR);
else if (!governor.isEmpty ()) col_inf.default_value = fetchStringValue (governor);
if (!label.isEmpty ()) {
- col_inf.display_index = visible_columns++;
+ col_inf.display_index = visible_column_labels.size ();
col_inf.column_label = label;
+ visible_column_labels.append (label);
} else {
col_inf.display_index = -1;
}
@@ -138,18 +139,11 @@
}
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);
+ display->setColumnCount (visible_column_labels.size ());
+ display->setHeaderLabels (visible_column_labels);
+#warning TODO: implement index
+// display->verticalHeader ()->setVisible (display_show_index);
+ connect (display, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT (currentRowChanged (QTreeWidgetItem*)));
}
}
@@ -157,16 +151,23 @@
RK_TRACE (PLUGIN);
}
-QWidget *RKOptionSet::createDisplay (bool show_index, QWidget *parent) {
+RKComponent *RKOptionSet::createDisplay (bool show_index, QWidget *parent) {
RK_TRACE (PLUGIN);
+ RKComponent* dummy = new RKComponent (this, parent);
+ QVBoxLayout *layout = new QVBoxLayout (dummy);
+ layout->setContentsMargins (0, 0, 0, 0);
+ KHBox *box = new KHBox (dummy);
+ layout->addWidget (box);
+
if (display) {
RK_DO (qDebug ("cannot create more than one optiondisplay per optionset"), PLUGIN, DL_ERROR);
} else {
- display = new QTableWidget (parent);
+ display = new QTreeWidget (box);
display_show_index = show_index;
}
- return (display);
+
+ return (dummy);
}
// This function is called when a property of the current row of the optionset changes
@@ -183,17 +184,20 @@
}
QList<RKComponentPropertyStringList *> cols = columns_to_update.values (property);
+ QTreeWidgetItem *display_item = 0;
+ if (display) display_item = display->topLevelItem (row);
for (int i = 0; i < cols.size (); ++i) {
RKComponentPropertyStringList *target = cols.at (i);
const ColumnInfo &inf = column_map[target];
QString value = property->value (inf.governor_modifier);
target->setValueAt (row, value);
- if (display && (inf.display_index >= 0)) {
- display->setItem (row, inf.display_index, new QTableWidgetItem (value));
+ if (display_item && (inf.display_index >= 0)) {
+ display_item->setText (inf.display_index, value);
}
+
+ if (target == keycolumn) old_keys = keycolumn->values ();
}
- if (keycolumn) old_keys = keycolumn->values ();
updating_from_contents = false;
}
@@ -208,11 +212,20 @@
RK_ASSERT (column_map.contains (target));
const ColumnInfo &inf = column_map[target];
if (display && (inf.display_index >= 0)) {
- display->removeColumn (inf.display_index);
- display->insertColumn (inf.display_index);
QStringList values = target->values ();
+ while (display->topLevelItemCount () != values.size ()) {
+ // row count has changed. Ultimately, this means, all values will be updated, so a crude adjustment
+ // of row count is good enough, here
+ if (values.size () > display->topLevelItemCount ()) {
+ display->addTopLevelItem (new QTreeWidgetItem (QStringList ()));
+ } else {
+ delete (display->takeTopLevelItem (0));
+ }
+ }
for (int row = 0; row < values.size (); ++row) {
- display->setItem (row, inf.display_index, new QTableWidgetItem (values[row]));
+ QTreeWidgetItem *item = display->topLevelItem (row);
+ if (item) item->setText (inf.display_index, values[row]);
+ else RK_ASSERT (false);
}
}
if (inf.restorable) update_timer.start ();
@@ -269,6 +282,7 @@
}
columns_which_have_been_updated_externally.clear ();
+ old_keys = new_keys;
int nrows = new_keys.size ();
row_count->setIntValue (nrows);
@@ -325,6 +339,14 @@
update_timer.start ();
}
+void RKOptionSet::currentRowChanged (QTreeWidgetItem *new_row) {
+ RK_TRACE (PLUGIN);
+
+ RK_ASSERT (display);
+ current_row->setIntValue (display->indexOfTopLevelItem (new_row));
+ update_timer.start ();
+}
+
bool RKOptionSet::isValid () {
if (update_timer.isActive ()) return (false); // actually, this signifies "processing" state
int count = row_count->intValue ();
@@ -333,3 +355,5 @@
if (count > max_rows) return false;
return true;
}
+
+#include "rkoptionset.moc"
Modified: trunk/rkward/rkward/plugin/rkoptionset.h
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.h 2012-05-21 11:14:15 UTC (rev 4256)
+++ trunk/rkward/rkward/plugin/rkoptionset.h 2012-05-21 14:08:59 UTC (rev 4257)
@@ -2,7 +2,7 @@
rkoptionset - description
-------------------
begin : Mon Oct 31 2011
- copyright : (C) 2011 by Thomas Friedrichsmeier
+ copyright : (C) 2011, 2012 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -25,7 +25,8 @@
#include <QTimer>
#include <QSet>
-class QTableWidget;
+class QTreeWidget;
+class QTreeWidgetItem;
/** An RKOptionSet provides a group of options for an arbitrary number of "rows". E.g. different line colors for each of a group of variables.
*@author Thomas Friedrichsmeier
@@ -36,15 +37,16 @@
RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget);
~RKOptionSet ();
int type () { return ComponentOptionSet; };
- QWidget *createDisplay (bool show_index, QWidget *parent);
+ RKComponent *createDisplay (bool show_index, QWidget *parent);
bool isValid ();
private slots:
void governingPropertyChanged (RKComponentPropertyBase *property);
void columnPropertyChanged (RKComponentPropertyBase *property);
void currentRowPropertyChanged (RKComponentPropertyBase *property);
- void addRow ();
- void removeRow (int index);
+// void addRow ();
+// void removeRow (int index);
void updateContents ();
+ void currentRowChanged (QTreeWidgetItem *item);
private:
void initDisplay ();
@@ -65,7 +67,7 @@
};
QMap<RKComponentPropertyStringList *, ColumnInfo> column_map;
RKComponent *contents_container;
- QTableWidget *display;
+ QTreeWidget *display;
bool display_show_index;
RKComponentPropertyInt *current_row;
RKComponentPropertyInt *row_count;
Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.cpp 2012-05-21 11:14:15 UTC (rev 4256)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.cpp 2012-05-21 14:08:59 UTC (rev 4257)
@@ -54,6 +54,7 @@
#include "rktext.h"
#include "rktabpage.h"
#include "rkpluginframe.h"
+#include "rkoptionset.h"
#include "../rkglobals.h"
@@ -656,6 +657,15 @@
} else {
xml->displayError (&e, QString ("Could not embed component '%1'. Not found").arg (component_id), DL_ERROR);
}
+ } else if (e.tagName () == "optionset") {
+ widget = new RKOptionSet (e, component (), parent_widget);
+ } else if (e.tagName () == "optiondisplay") {
+ RKComponent *set = component ()->parentComponent ();
+ if (set->type () == RKComponentBase::ComponentOptionSet) {
+ widget = static_cast<RKOptionSet *> (set)->createDisplay (xml->getBoolAttribute (e, "index", true, DL_INFO), parent_widget);
+ } else {
+ xml->displayError (&e, QString ("optiondisplay element is not allowed outside of an optionset"), DL_ERROR);
+ }
} else if (e.tagName () == "scriptable") {
widget = new RKComponent (component (), parent_widget);
QVBoxLayout *layout = new QVBoxLayout (widget);
Added: trunk/rkward/rkward/plugins/testing/optionset.js
===================================================================
--- trunk/rkward/rkward/plugins/testing/optionset.js (rev 0)
+++ trunk/rkward/rkward/plugins/testing/optionset.js 2012-05-21 14:08:59 UTC (rev 4257)
@@ -0,0 +1 @@
+
Added: trunk/rkward/rkward/plugins/testing/optionset.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/optionset.xml (rev 0)
+++ trunk/rkward/rkward/plugins/testing/optionset.xml 2012-05-21 14:08:59 UTC (rev 4257)
@@ -0,0 +1,42 @@
+<!DOCTYPE rkplugin>
+
+<document>
+ <code file="optionset.js"/>
+
+ <logic>
+ <set id="set.dummyslot.enabled" to="false"/> <!-- TODO: does not work, yet -->
+ <connect governor="x.available" client="set.var" />
+ <connect governor="x.available.shortname" client="set.varname" />
+ </logic>
+
+ <dialog label="Testing Optionset">
+ <text id="text">
+ This plugin is bogus! Do not use!
+ </text>
+ <tabbook>
+ <tab label="Driven set">
+ <row>
+ <column>
+ <varselector id="vars"/>
+ <varslot type="numeric" id="x" source="vars" required="true" label="variables" multi="true"/>
+ </column>
+ <optionset id="set" min_rows="1" keycolumn="var">
+ <content>
+ <frame>
+ <optiondisplay index="true"/>
+ <varslot id="dummyslot"/>
+ <input id="commenta" label="Comment A"/>
+ <input id="commentb" label="Comment B"/>
+ </frame>
+ </content>
+ <option id="var" label="test" connect="dummyslot.available" restorable="true"/>
+ <option id="varname" label="Varname" restorable="false"/>
+ <option id="ca" label="Comment A" connect="commenta.text" restorable="true"/>
+ <option id="cb" connect="commentb.text" restorable="true"/>
+ </optionset>
+ </row>
+ </tab>
+ </tabbook>
+ </dialog>
+
+</document>
Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap 2012-05-21 11:14:15 UTC (rev 4256)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap 2012-05-21 14:08:59 UTC (rev 4257)
@@ -9,6 +9,7 @@
<!-- These are purely for testing: -->
<component type="standard" id="qtscript_test1" file="testing/test1.xml" label="QtScript Test 1" />
<component type="standard" id="qtscript_test2" file="testing/test2.xml" label="QtScript Test 2" />
+ <component type="standard" id="optionset_test" file="testing/optionset.xml" label="Optionset Test" />
<!-- End -->
<component type="standard" id="import_xls" file="00saveload/import/import_xls.xml" label="Import MS EXCEL">
@@ -34,6 +35,7 @@
<menu id="analysis" label="Analysis" index="4">
<entry component="simple_anova" index="9"/>
<entry component="qtscript_test1" index="1"/>
+ <entry component="optionset_test" index="1"/>
</menu>
<menu id="plots" label="Plots" index="5">
<entry component="sieve_plot" />
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