[rkward-cvs] SF.net SVN: rkward:[4464] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Wed Nov 28 09:28:42 UTC 2012
Revision: 4464
http://rkward.svn.sourceforge.net/rkward/?rev=4464&view=rev
Author: tfry
Date: 2012-11-28 09:28:42 +0000 (Wed, 28 Nov 2012)
Log Message:
-----------
Make the new type-safe getters available for UI scripting, too.
Modified Paths:
--------------
trunk/rkward/rkward/plugin/rkcomponent.cpp
trunk/rkward/rkward/plugin/rkcomponent.h
trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
trunk/rkward/rkward/plugin/rkstandardcomponent.h
trunk/rkward/rkward/plugins/analysis/crosstab.js
trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp
trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h
trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js
Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp 2012-11-28 09:28:42 UTC (rev 4464)
@@ -170,6 +170,35 @@
return fetchStringValue (prop, mod);
}
+QVariant RKComponentBase::fetchValue (const QString &id, const int hint) {
+ if (hint == StringValue) {
+ return (fetchStringValue (id));
+ } else if (hint == TraditionalValue) {
+ QString val = fetchStringValue (id);
+ // return "0" as numeric constant. Many plugins rely on this form PHP times.
+ if (val == "0") return (QVariant (0.0));
+ else return (QVariant (val));
+ } else {
+ QString mod;
+ RKComponentBase *prop = lookupComponent (id, &mod);
+ QVariant val = prop->value (mod);
+ if (hint == BooleanValue) {
+ bool ok;
+ return (RKComponentPropertyBool::variantToBool (val, &ok));
+ if (!ok) RK_DO (qDebug ("Could not convert value of %s to boolean", qPrintable (id)), PLUGIN, DL_WARNING);
+ } else {
+ if (hint == StringlistValue) {
+ if (val.type () != QVariant::StringList) RK_DO (qDebug ("Value of %s is not a string list", qPrintable (id)), PLUGIN, DL_WARNING);
+ } else if (hint == NumericValue) {
+ if (!val.canConvert (QVariant::Double)) RK_DO (qDebug ("Value of %s is not numeric", qPrintable (id)), PLUGIN, DL_WARNING);
+ } else {
+ RK_ASSERT (false);
+ }
+ return (val);
+ }
+ }
+}
+
QVariant RKComponentBase::value (const QString &modifier) {
RK_TRACE (PLUGIN);
Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/plugin/rkcomponent.h 2012-11-28 09:28:42 UTC (rev 4464)
@@ -90,6 +90,14 @@
static QString fetchStringValue (RKComponentBase* prop, const QString &modifier=QString ());
/** returns the "value" of this component or property. Properties generally return their value, components typically return the value of their "most important" property. Default implementation returns QString::null, and writes a debug message */
virtual QVariant value (const QString &modifier=QString ());
+ enum ValueTypeHint {
+ TraditionalValue,
+ BooleanValue,
+ StringValue,
+ StringlistValue,
+ NumericValue
+ };
+ QVariant fetchValue (const QString &identifier, const int type_hint);
/** returns true, if this is a property */
bool isProperty () { return (type () <= PropertyEnd); };
bool isComponent () { return (type () >= ComponentBase); };
Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.cpp 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.cpp 2012-11-28 09:28:42 UTC (rev 4464)
@@ -423,32 +423,7 @@
RK_TRACE (PLUGIN);
RK_ASSERT (backend);
- if (hint == StringValue) {
- backend->writeData (fetchStringValue (id));
- } else if (hint == TraditionalValue) {
- QString val = fetchStringValue (id);
- // return "0" as numeric constant. Many plugins rely on this form PHP times.
- if (val == "0") backend->writeData (QVariant (0.0));
- else backend->writeData (QVariant (val));
- } else {
- QString mod;
- RKComponentBase *prop = lookupComponent (id, &mod);
- QVariant val = prop->value (mod);
- if (hint == BooleanValue) {
- bool ok;
- backend->writeData (RKComponentPropertyBool::variantToBool (val, &ok));
- if (!ok) RK_DO (qDebug ("Could not convert value of %s to boolean", qPrintable (id)), PLUGIN, DL_WARNING);
- } else {
- if (hint == StringlistValue) {
- if (val.type () != QVariant::StringList) RK_DO (qDebug ("Value of %s is not a string list", qPrintable (id)), PLUGIN, DL_WARNING);
- } else if (hint == NumericValue) {
- if (!val.canConvert (QVariant::Double)) RK_DO (qDebug ("Value of %s is not numeric", qPrintable (id)), PLUGIN, DL_WARNING);
- } else {
- RK_ASSERT (false);
- }
- backend->writeData (val);
- }
- }
+ backend->writeData (fetchValue (id, hint));
}
bool RKStandardComponent::isWizardish () {
Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.h 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.h 2012-11-28 09:28:42 UTC (rev 4464)
@@ -81,14 +81,6 @@
/** Return the GUI-scripting handler (creating it, if needed) */
RKComponentScriptingProxy* scriptingProxy ();
-
- enum ValueTypeHint {
- TraditionalValue,
- BooleanValue,
- StringValue,
- StringlistValue,
- NumericValue
- };
signals:
void standardInitializationComplete ();
public slots:
Modified: trunk/rkward/rkward/plugins/analysis/crosstab.js
===================================================================
--- trunk/rkward/rkward/plugins/analysis/crosstab.js 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/plugins/analysis/crosstab.js 2012-11-28 09:28:42 UTC (rev 4464)
@@ -21,7 +21,7 @@
function calculate () {
var x = getValue ("x") ;
- var y = trim (getValue ("y")).split (/\n/).join (', ');
+ var y = getList ("y").join (', ');
var margins = (getValue ("margins") == "TRUE");
echo ('x <- rk.list (' + x + ')\n');
Modified: trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp 2012-11-28 09:28:42 UTC (rev 4464)
@@ -146,12 +146,26 @@
evaluate (command.toUtf8());
}
-QString RKComponentScriptingProxy::getValue (const QString &id) const {
+QVariant RKComponentScriptingProxy::getValue (const QString &id) const {
RK_TRACE (PHP);
+ return (component->fetchValue (id, RKComponent::TraditionalValue));
+}
- return component->fetchStringValue (id);
+QVariant RKComponentScriptingProxy::getString (const QString &id) const {
+ RK_TRACE (PHP);
+ return (component->fetchValue (id, RKComponent::StringValue));
}
+QVariant RKComponentScriptingProxy::getBoolean (const QString &id) const {
+ RK_TRACE (PHP);
+ return (component->fetchValue (id, RKComponent::BooleanValue));
+}
+
+QVariant RKComponentScriptingProxy::getList (const QString &id) const {
+ RK_TRACE (PHP);
+ return (component->fetchValue (id, RKComponent::StringlistValue));
+}
+
void RKComponentScriptingProxy::setValue (const QString &value, const QString &id) {
RK_TRACE (PHP);
Modified: trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h
===================================================================
--- trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h 2012-11-28 09:28:42 UTC (rev 4464)
@@ -49,7 +49,10 @@
void include (const QString& filename);
void addChangeCommand (const QString& changed_id, const QString& command);
- QString getValue (const QString &id) const;
+ QVariant getValue (const QString &id) const;
+ QVariant getString (const QString &id) const;
+ QVariant getBoolean (const QString &id) const;
+ QVariant getList (const QString &id) const;
void setValue (const QString &value, const QString &id);
QVariantList getObjectInfo (const QString &name);
Modified: trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js
===================================================================
--- trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js 2012-11-27 21:00:44 UTC (rev 4463)
+++ trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js 2012-11-28 09:28:42 UTC (rev 4464)
@@ -28,11 +28,21 @@
}
this.getValue = function (id) {
- var ret = _rkward.getValue (this.absoluteId (id));
- if (ret == "0") return (false);
- return (ret);
+ return (_rkward.getValue (this.absoluteId (id)));
}
+ this.getString = function (id) {
+ return (_rkward.getString (this.absoluteId (id)));
+ }
+
+ this.getBoolean = function (id) {
+ return (_rkward.getBoolean (this.absoluteId (id)));
+ }
+
+ this.getList = function (id) {
+ return (_rkward.getList (this.absoluteId (id)));
+ }
+
this.setValue = function (id, value) {
return (_rkward.setValue (value, this.absoluteId (id)));
}
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