[rkward-cvs] SF.net SVN: rkward:[4260] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Tue May 22 10:08:24 UTC 2012
Revision: 4260
http://rkward.svn.sourceforge.net/rkward/?rev=4260&view=rev
Author: tfry
Date: 2012-05-22 10:08:23 +0000 (Tue, 22 May 2012)
Log Message:
-----------
More fixes and some cleanups to the Optionset.
Modified Paths:
--------------
trunk/rkward/rkward/plugin/rkcomponent.h
trunk/rkward/rkward/plugin/rkoptionset.cpp
trunk/rkward/rkward/plugin/rkoptionset.h
trunk/rkward/rkward/plugins/testing/optionset.xml
Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h 2012-05-22 07:44:11 UTC (rev 4259)
+++ trunk/rkward/rkward/plugin/rkcomponent.h 2012-05-22 10:08:23 UTC (rev 4260)
@@ -116,7 +116,6 @@
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-22 07:44:11 UTC (rev 4259)
+++ trunk/rkward/rkward/plugin/rkoptionset.cpp 2012-05-22 10:08:23 UTC (rev 4260)
@@ -26,6 +26,7 @@
#include <kvbox.h>
#include "rkstandardcomponent.h"
+#include "../misc/rkcommonfunctions.h"
#include "../misc/rkstandardicons.h"
#include "../misc/xmlhelper.h"
@@ -63,10 +64,6 @@
RKComponentBuilder *builder = new RKComponentBuilder (contents_container, QDomElement ());
builder->buildElement (xml->getChildElement (element, "content", DL_ERROR), contents_box, false); // NOTE that parent widget != parent component, here, by intention. The point is that the display should not be disabled along with the contents
builder->makeConnections ();
-#warning TOOD: do we need this? or is the per-column default good enough?
-#warning TOOD: should we wait until the (top level) plugin initial state has settled, before fetching the defaults?
- // take a snapshot of the default state of the contents
- contents_container->fetchPropertyValuesRecursive (&content_defaults);
addChild ("contents", contents_container);
// create columns
@@ -91,7 +88,7 @@
col_inf.governor = governor;
#warning TODO: Do we have to wait for the parent component to settle before (re-)fetching defaults?
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);
+ else if (!governor.isEmpty ()) col_inf.default_value = contents_container->fetchStringValue (governor);
if (!label.isEmpty ()) {
col_inf.display_index = visible_column_labels.size ();
col_inf.column_label = label;
@@ -184,7 +181,9 @@
display_buttons = new KHBox (dummy);
layout->addWidget (display_buttons);
add_button = new QPushButton (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertRow), QString (), display_buttons);
+ RKCommonFunctions::setTips (i18n ("Add a row / element"), add_button);
remove_button = new QPushButton (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteRow), QString (), display_buttons);
+ RKCommonFunctions::setTips (i18n ("Remove a row / element"), remove_button);
return (dummy);
}
@@ -200,8 +199,7 @@
RKComponentPropertyStringList* col = it.key ();
const ColumnInfo &column = it.value ();
QStringList values = col->values ();
-#warning TODO: scriptable defaults?
- values.insert (row, column.default_value);
+ values.insert (row, getDefaultValue (column, row));
col->setValues (values);
}
@@ -231,6 +229,13 @@
current_row->setIntValue (row);
}
+QString getDefaultValue (const RKOptionSet::ColumnInfo& ci, int row) {
+ // let's not trace this simple helper fun
+ Q_UNUSED (row);
+#warning TODO: should also allow scripted defaults
+ return ci.default_value;
+}
+
// This function is called when a property of the current row of the optionset changes
void RKOptionSet::governingPropertyChanged (RKComponentPropertyBase *property) {
RK_TRACE (PLUGIN);
@@ -268,6 +273,7 @@
RK_TRACE (PLUGIN);
if (updating_from_contents) return;
+ int activate_row = current_row->intValue ();
RKComponentPropertyStringList *target = static_cast<RKComponentPropertyStringList *> (property);
RK_ASSERT (column_map.contains (target));
@@ -279,8 +285,10 @@
// of row count is good enough, here
if (values.size () > display->topLevelItemCount ()) {
display->addTopLevelItem (new QTreeWidgetItem (QStringList ()));
+ activate_row = values.size () - 1;
} else {
delete (display->takeTopLevelItem (0));
+ activate_row = qMax (values.size (), activate_row);
}
}
for (int row = 0; row < values.size (); ++row) {
@@ -328,8 +336,8 @@
if (pit != position_changes.constEnd ()) { // some change
int old_pos = pit.value ();
if (old_pos < 0) { // a new key
- new_values[pos] = column.default_value;
-#warning TODO: should also allow scripted defaults
+ new_values[pos] = getDefaultValue (column, pos);
+ activate_row = pos;
} else { // old key changed position
new_values[pos] = old_values[old_pos];
}
@@ -347,15 +355,14 @@
int nrows = new_keys.size ();
row_count->setIntValue (nrows);
- int crow = current_row->intValue ();
- if ((crow < 0) && nrows) current_row->setIntValue (0);
- else if (crow >= nrows) current_row->setIntValue (nrows - 1);
} else {
if (!columns_which_have_been_updated_externally.isEmpty ()) { // add clearing timer for the first entry, only
update_timer.start (); // NOTE: only has an effect, if column is neither restorable nor shown in the display. Otherwise, an update has already been triggered
}
columns_which_have_been_updated_externally.insert (target);
}
+
+ current_row->setIntValue (activate_row);
}
void RKOptionSet::updateContents () {
@@ -370,28 +377,28 @@
int row = current_row->intValue ();
QMap<RKComponentPropertyStringList *, ColumnInfo>::const_iterator it = column_map.constBegin ();
if (it != column_map.constEnd ()) count = it.key ()->values ().size ();
- if (row < 0) {
- contents_container->setPropertyValues (&content_defaults);
- } else {
- 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 ());
- static_cast<RKComponentPropertyBase*> (governor)->setValue (col->valueAt (row));
- } else {
- RK_ASSERT (false);
- }
+ 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 with trying to restore row %d of optionset: %s. Remainder: %s", row, qPrintable (ci.governor), qPrintable (dummy)), PLUGIN, DL_WARNING);
+ RK_ASSERT (false);
}
}
row_count->setIntValue (count);
-#warning TODO: why doesn't this have an effect?
contents_container->enablednessProperty ()->setBoolValue (row >= 0);
-// contents_container->setEnabled (false);
updateVisuals ();
changed (); // needed, for the unlikely case that no change notification was triggered above, since isValid() returns false while updating
@@ -432,6 +439,7 @@
if (row >= 0) item = display->topLevelItem (row);
if (item != display->currentItem ()) display->setCurrentItem (item);
}
+#warning: What if the current row is invalid. Should we refuse to switch? Or simply keep track of the fact? What if it is still processing?
update_timer.start ();
}
Modified: trunk/rkward/rkward/plugin/rkoptionset.h
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.h 2012-05-22 07:44:11 UTC (rev 4259)
+++ trunk/rkward/rkward/plugin/rkoptionset.h 2012-05-22 10:08:23 UTC (rev 4260)
@@ -52,7 +52,6 @@
void initDisplay ();
void updateVisuals ();
- QMap<QString, QString> content_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. */
RKComponentPropertyStringList *keycolumn;
@@ -85,6 +84,8 @@
bool updating_from_contents;
bool updating_from_storage;
QSet<RKComponentPropertyStringList *> columns_which_have_been_updated_externally;
+
+ friend QString getDefaultValue (const ColumnInfo& ci, int row);
};
#endif
Modified: trunk/rkward/rkward/plugins/testing/optionset.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/optionset.xml 2012-05-22 07:44:11 UTC (rev 4259)
+++ trunk/rkward/rkward/plugins/testing/optionset.xml 2012-05-22 10:08:23 UTC (rev 4260)
@@ -4,7 +4,7 @@
<code file="optionset.js"/>
<logic>
- <set id="set.contents.dummyslot.enabled" to="false"/>
+ <set id="set.contents.dummybox.enabled" to="false"/>
<connect governor="x.available" client="set.var" />
<connect governor="x.available.shortname" client="set.varname" />
<connect governor="mset.object" client="cset.object" />
@@ -62,19 +62,18 @@
<content>
<frame>
<optiondisplay index="false"/>
- <varslot id="dummyslot"/>
+ <checkbox id="dummybox" label="This dummy option is always disabled"/>
<input id="commenta" label="Comment A"/>
<input id="commentb" label="Comment B"/>
</frame>
</content>
- <option id="var" label="test" restorable="true"/>
+ <option id="var" label="test" restorable="false"/>
<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"/>
+ <option id="cb" connect="commentb.text" restorable="true" default="This is a default entry. Change it, if you like."/>
</optionset>
</row>
</tab>
</tabbook>
</dialog>
-
</document>
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