[rkward-cvs] SF.net SVN: rkward:[2922] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Thu Jul 1 17:57:49 UTC 2010
Revision: 2922
http://rkward.svn.sourceforge.net/rkward/?rev=2922&view=rev
Author: tfry
Date: 2010-07-01 17:57:48 +0000 (Thu, 01 Jul 2010)
Log Message:
-----------
Allow to specify a root object in varselectors, and add a simple sort-plugin to demonstrate the functionality.
Modified Paths:
--------------
trunk/rkward/rkward/misc/rkobjectlistview.cpp
trunk/rkward/rkward/misc/rkobjectlistview.h
trunk/rkward/rkward/plugin/rkvarselector.cpp
trunk/rkward/rkward/plugin/rkvarselector.h
trunk/rkward/rkward/plugins/under_development.pluginmap
Added Paths:
-----------
trunk/rkward/rkward/plugins/data/sort.js
trunk/rkward/rkward/plugins/data/sort.xml
Modified: trunk/rkward/rkward/misc/rkobjectlistview.cpp
===================================================================
--- trunk/rkward/rkward/misc/rkobjectlistview.cpp 2010-06-30 16:06:54 UTC (rev 2921)
+++ trunk/rkward/rkward/misc/rkobjectlistview.cpp 2010-07-01 17:57:48 UTC (rev 2922)
@@ -2,7 +2,7 @@
rkobjectlistview - description
-------------------
begin : Wed Sep 1 2004
- copyright : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
+ copyright : (C) 2004, 2006, 2007, 2010 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -62,6 +62,19 @@
}
}
+void RKObjectListView::setRootObject (RObject *root) {
+ RK_TRACE (APP);
+
+ if (!root) return;
+ QModelIndex index = settings->mapFromSource (RKGlobals::tracker ()->indexFor (root));
+ if (index.isValid ()) {
+ setRootIndex (index);
+ resizeColumnToContents (0);
+ } else {
+ RK_ASSERT (false);
+ }
+}
+
RObject* RKObjectListView::objectAtIndex (const QModelIndex& index) const {
RK_TRACE (APP);
Modified: trunk/rkward/rkward/misc/rkobjectlistview.h
===================================================================
--- trunk/rkward/rkward/misc/rkobjectlistview.h 2010-06-30 16:06:54 UTC (rev 2921)
+++ trunk/rkward/rkward/misc/rkobjectlistview.h 2010-07-01 17:57:48 UTC (rev 2922)
@@ -2,7 +2,7 @@
rkobjectlistview - description
-------------------
begin : Wed Sep 1 2004
- copyright : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
+ copyright : (C) 2004, 2006, 2007, 2010 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -53,6 +53,7 @@
/** Scrolls so that the item representing object becomes visible, and makes it current */
void setObjectCurrent (RObject *object, bool only_if_none_current=false);
+ void setRootObject (RObject *root);
RObject::ObjectList selectedObjects () const;
Modified: trunk/rkward/rkward/plugin/rkvarselector.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkvarselector.cpp 2010-06-30 16:06:54 UTC (rev 2921)
+++ trunk/rkward/rkward/plugin/rkvarselector.cpp 2010-07-01 17:57:48 UTC (rev 2922)
@@ -2,7 +2,7 @@
rkvarselector.cpp - description
-------------------
begin : Thu Nov 7 2002
- copyright : (C) 2002, 2006, 2009 by Thomas Friedrichsmeier
+ copyright : (C) 2002, 2006, 2009, 2010 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -33,6 +33,9 @@
// TODO: read filter settings
addChild ("selected", selected = new RKComponentPropertyRObjects (this, false));
selected->setInternal (true);
+ addChild ("root", root = new RKComponentPropertyRObjects (this, false));
+ connect (root, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (rootChanged()));
+ root->setInternal (true);
QVBoxLayout *vbox = new QVBoxLayout (this);
vbox->setContentsMargins (0, 0, 0, 0);
@@ -47,12 +50,21 @@
vbox->addWidget (list_view);
list_view->getSettings ()->setSetting (RKObjectListViewSettings::ShowObjectsAllEnvironments, false);
list_view->initialize ();
+ rootChanged ();
}
RKVarSelector::~RKVarSelector () {
RK_TRACE (PLUGIN);
}
+void RKVarSelector::rootChanged () {
+ RK_TRACE (PLUGIN);
+
+ RObject* object = root->objectValue ();
+ if (!object) object = RObjectList::getObjectList ();
+ list_view->setRootObject (object);
+}
+
void RKVarSelector::objectSelectionChanged () {
RK_TRACE (PLUGIN);
Modified: trunk/rkward/rkward/plugin/rkvarselector.h
===================================================================
--- trunk/rkward/rkward/plugin/rkvarselector.h 2010-06-30 16:06:54 UTC (rev 2921)
+++ trunk/rkward/rkward/plugin/rkvarselector.h 2010-07-01 17:57:48 UTC (rev 2922)
@@ -2,7 +2,7 @@
rkvarselector.h - description
-------------------
begin : Thu Nov 7 2002
- copyright : (C) 2002, 2006 by Thomas Friedrichsmeier
+ copyright : (C) 2002, 2006, 2010 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -24,27 +24,27 @@
class RKObjectListView;
class QDomElement;
-/** This is an especially important RK-plugin-widget. It provides a list of variables
-(derived from the document's table), that can be selected for statistical analysis.
+/** This is an especially important RK-plugin-widget. It provides a list of variables, that
+can be selected for statistical analysis.
It's major counterpart is the RKVarSlot-class, which "takes" variables selected from
-this list. Most of the time, you'll only have a single VarSelector in a GUI, but
-you can have more than one, e.g. for serving conceptionally different VarSlots.
+this list. Most of the time, you'll only have a single RKVarSelector in a GUI, but
+you can have more than one, e.g. for serving conceptionally different RKVarSlots.
@author Thomas Friedrichsmeier
- */
-
-
+*/
class RKVarSelector : public RKComponent {
Q_OBJECT
public:
RKVarSelector (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget);
~RKVarSelector ();
int type () { return ComponentVarSelector; };
-public slots:
+private slots:
void objectSelectionChanged ();
+ void rootChanged ();
private:
RKObjectListView *list_view;
RKComponentPropertyRObjects *selected;
+ RKComponentPropertyRObjects *root;
};
#endif
Added: trunk/rkward/rkward/plugins/data/sort.js
===================================================================
--- trunk/rkward/rkward/plugins/data/sort.js (rev 0)
+++ trunk/rkward/rkward/plugins/data/sort.js 2010-07-01 17:57:48 UTC (rev 2922)
@@ -0,0 +1,11 @@
+function calculate () {
+ var object = getValue ("object");
+ var is_data_frame = getValue ("sortby_frame.enabled");
+
+ var saveto = object;
+ if (getValue ("saveto_select") == "other") saveto = getValue ("saveto");
+
+ echo (".GlobalEnv$" + saveto + " <- " + object + "[order (" + getValue ("sortby") + getValue ("order") + ")");
+ if (is_data_frame) echo (",");
+ echo ("]\n");
+}
Added: trunk/rkward/rkward/plugins/data/sort.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/sort.xml (rev 0)
+++ trunk/rkward/rkward/plugins/data/sort.xml 2010-07-01 17:57:48 UTC (rev 2922)
@@ -0,0 +1,63 @@
+<!DOCTYPE rkplugin>
+<document>
+ <code file="sort.js"/>
+ <logic>
+ <connect governor="current_object" client="object.available"/>
+ <connect governor="object.available" client="sortby_selector.root"/>
+ <convert id="isok" mode="equals" sources="notice.text" standard="" require_true="true"/>
+
+ <convert id="saveto_other_object" mode="equals" sources="saveto_select.string" standard="other"/>
+ <connect governor="saveto_other_object" client="saveto.enabled"/>
+ <connect governor="saveto_other_object" client="saveto.required"/>
+ <script><![CDATA[
+ // the top-level block is called only once
+ gui.addChangeCommand ("object.available", "objectChanged ()");
+
+ // this function is called on every change of the saveto's parent
+ objectChanged = function () {
+ object = makeRObject (gui.getValue ("object.available"));
+ gui.setValue ("sortby_frame.enabled", object.isDataFrame ());
+ gui.setValue ("sortby.required", object.isDataFrame ());
+
+ if (!(object.dimensions().length == 1 || object.isDataFrame())) {
+ // Not very elegant, but...
+ gui.setValue ("notice.text", "This type of object is not supported in this plugin");
+ } else {
+ gui.setValue ("notice.text", "");
+ }
+ }
+ ]]></script>
+ </logic>
+ <dialog label="Sort data">
+ <frame>
+ <row>
+ <varselector label="Select the object to be sorted" id="selector"/>
+ <column>
+ <varslot id="object" source="selector" required="true"/>
+ <text id="notice" type="warning"></text>
+ <stretch/>
+ </column>
+ </row>
+ </frame>
+ <row>
+ <frame id="sortby_frame">
+ <varselector label="Sort by" id="sortby_selector"/>
+ <varslot source="sortby_selector" id="sortby" required="true"/>
+ </frame>
+ <column>
+ <radio id="order" label="Order">
+ <option label="Ascending" value="" checked="true"/>
+ <option label="Descending" value=", decreasing=TRUE"/>
+ </radio>
+ <stretch/>
+ </column>
+ </row>
+ <row>
+ <radio id="saveto_select" label="Save to">
+ <option label="Same object" value="same" checked="true"/>
+ <option label="Another object" value="other"/>
+ </radio>
+ <saveobject id="saveto" label="Object to save to" initial="sorted"/>
+ </row>
+ </dialog>
+</document>
Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap 2010-06-30 16:06:54 UTC (rev 2921)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap 2010-07-01 17:57:48 UTC (rev 2922)
@@ -5,6 +5,7 @@
<component type="standard" id="simple_anova" file="simple_anova/description.xml" label="Simple Anova" />
<component type="standard" id="sieve_plot" file="plots/sieve_plot.xml" label="Extended Sieve Plot" />
<component type="standard" id="generate_random" file="data/generate_random.xml" label="Generate random data" />
+ <component type="standard" id="sort_data" file="data/sort.xml" label="Sort data" />
<!-- These are purely for testing: -->
<component type="standard" id="qtscript_test1" file="testing/test1.xml" label="QtScript Test 1" />
@@ -22,7 +23,8 @@
</menu>
</menu>
<menu id="data" label="Data" index="3">
- <entry component="generate_random" index="9"/>
+ <entry component="generate_random"/>
+ <entry component="sort_data"/>
</menu>
<menu id="analysis" label="Analysis" index="4">
<entry component="simple_anova" index="9"/>
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