[Kst] branches/work/kst/1.6/kst/src/extensions/js
Andrew Walker
arwalker at sumusltd.com
Thu Nov 15 01:06:54 CET 2007
SVN commit 736846 by arwalker:
add functionality to legend through javaScript
M +1 -1 README
M +80 -3 bind_legend.cpp
M +24 -2 bind_legend.h
--- branches/work/kst/1.6/kst/src/extensions/js/README #736845:736846
@@ -25,7 +25,7 @@
Window DONE (needs more functions/properties)
PlotLabel DONE
-PlotLegend DONE (needs more functions/properties)
+PlotLegend DONE
ViewObject DONE
Plot DONE
Box DONE
--- branches/work/kst/1.6/kst/src/extensions/js/bind_legend.cpp #736845:736846
@@ -19,6 +19,7 @@
#include "bind_curvecollection.h"
#include <kst.h>
+#include <kstbasecurve.h>
#include <kstviewwindow.h>
#include <kdebug.h>
@@ -109,6 +110,8 @@
static LegendBindings legendBindings[] = {
+ { "addCurve", &KstBindLegend::addCurve },
+ { "removeCurve", &KstBindLegend::removeCurve },
{ 0L, 0L }
};
@@ -119,6 +122,7 @@
{ "textColor", &KstBindLegend::setTextColor, &KstBindLegend::textColor },
{ "vertical", &KstBindLegend::setVertical, &KstBindLegend::vertical },
{ "curves", 0L, &KstBindLegend::curves },
+ { "title", &KstBindLegend::setTitle, &KstBindLegend::title },
{ 0L, 0L, 0L }
};
@@ -191,7 +195,7 @@
return (this->*legendProperties[i].get)(exec);
}
}
-
+
return KstBindBorderedViewObject::get(exec, propertyName);
}
@@ -231,6 +235,56 @@
#define makeLegend(X) dynamic_cast<KstViewLegend*>(const_cast<KstObject*>(X.data()))
+KJS::Value KstBindLegend::addCurve(KJS::ExecState *exec, const KJS::List& args) {
+ if (args.size() != 1) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument.");
+ exec->setException(eobj);
+ return KJS::Undefined();
+ }
+
+ KstBaseCurvePtr curve;
+ curve = extractVCurve(exec, args[0], false);
+ if (curve) {
+ KstViewLegendPtr d = makeLegend(_d);
+ if (d) {
+ KstWriteLocker wl(d);
+ d->addCurve(curve);
+ KstApp::inst()->paintAll(KstPainter::P_PAINT);
+ }
+ } else {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+ exec->setException(eobj);
+ }
+
+ return KJS::Undefined();
+}
+
+
+KJS::Value KstBindLegend::removeCurve(KJS::ExecState *exec, const KJS::List& args) {
+ if (args.size() != 1) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument.");
+ exec->setException(eobj);
+ return KJS::Undefined();
+ }
+
+ KstBaseCurvePtr curve;
+ curve = extractVCurve(exec, args[0], false);
+ if (curve) {
+ KstViewLegendPtr d = makeLegend(_d);
+ if (d) {
+ KstWriteLocker wl(d);
+ d->removeCurve(curve);
+ KstApp::inst()->paintAll(KstPainter::P_PAINT);
+ }
+ } else {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+ exec->setException(eobj);
+ }
+
+ return KJS::Undefined();
+}
+
+
void KstBindLegend::setFont(KJS::ExecState *exec, const KJS::Value& value) {
if (value.type() != KJS::StringType) {
KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
@@ -346,6 +400,29 @@
}
+void KstBindLegend::setTitle(KJS::ExecState *exec, const KJS::Value& value) {
+ if (value.type() != KJS::StringType) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+ exec->setException(eobj);
+ return;
+ }
+ KstViewLegendPtr d = makeLegend(_d);
+ if (d) {
+ KstWriteLocker wl(d);
+ d->setTitle(value.toString(exec).qstring());
+ KstApp::inst()->paintAll(KstPainter::P_PAINT);
+ }
+}
+
+
+KJS::Value KstBindLegend::title(KJS::ExecState *exec) const {
+ Q_UNUSED(exec)
+ KstViewLegendPtr d = makeLegend(_d);
+ if (d) {
+ KstReadLocker rl(d);
+ return KJS::String(d->title());
+ }
+ return KJS::Undefined();
+}
+
#undef makeLegend
-
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_legend.h #736845:736846
@@ -57,39 +57,61 @@
int methodCount() const;
int propertyCount() const;
+ /* @method addCurve
+ @description Adds the curve to the legend.
+ @arg string curve The curve to be added. This can be either the name of the curve or a reference to the curve.
+ @exception GeneralError Throws this exception if the curve could not be found.
+ */
+ KJS::Value addCurve(KJS::ExecState *exec, const KJS::List& args);
+
+ /* @method removeCurve
+ @description Removes the curve from the legend.
+ @arg string curve The curve to be removed. This can be either the name of the curve or a reference to the curve.
+ @exception GeneralError Throws this exception if the curve could not be found.
+ */
+ KJS::Value removeCurve(KJS::ExecState *exec, const KJS::List& args);
+
/* @property string font
@description Used to set or get the current font used for the legend.
*/
void setFont(KJS::ExecState *exec, const KJS::Value& value);
KJS::Value font(KJS::ExecState *exec) const;
+
/* @property number fontSize
@description Contains the size of the font used to draw the legend.
*/
void setFontSize(KJS::ExecState *exec, const KJS::Value& value);
KJS::Value fontSize(KJS::ExecState *exec) const;
+
/* @property string textColor
@description Contains the color of the text used to draw the legend.
*/
void setTextColor(KJS::ExecState *exec, const KJS::Value& value);
KJS::Value textColor(KJS::ExecState *exec) const;
+
/* @property boolean vertical
@description True if the legend entries are stacked vertically.
*/
void setVertical(KJS::ExecState *exec, const KJS::Value& value);
KJS::Value vertical(KJS::ExecState *exec) const;
+
/* @property CurveCollection curves
@description The list of curves shown in the legend.
@readonly
*/
KJS::Value curves(KJS::ExecState *exec) const;
+ /* @property string title
+ @description The title of the legend.
+ */
+ void setTitle(KJS::ExecState *exec, const KJS::Value& value);
+ KJS::Value title(KJS::ExecState *exec) const;
+
protected:
KstBindLegend(int id, const char *name = 0L);
void addBindings(KJS::ExecState *exec, KJS::Object& obj);
static KstBindViewObject *bindFactory(KJS::ExecState *exec, KstViewObjectPtr obj);
};
-
#endif
-// vim: ts=2 sw=2 et
More information about the Kst
mailing list