[Kst] extragear/graphics/kst/kst/extensions/js
George Staikos
staikos at kde.org
Mon Dec 19 08:09:07 CET 2005
SVN commit 489581 by staikos:
implement several of the FIXMEs:
- extract basecurve list
- fix colorsequence constructor
- make an additional scalar constructor
- disable unused property in legend
M +3 -5 bind_colorsequence.cpp
M +1 -0 bind_curvecollection.h
M +4 -0 bind_legend.cpp
M +2 -0 bind_legend.h
M +19 -2 bind_scalar.cpp
M +4 -0 bind_scalar.h
M +48 -0 kstbinding.cpp
M +1 -0 kstbinding.h
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_colorsequence.cpp #489580:489581
@@ -167,21 +167,19 @@
rc = KstColorSequence::next(prev.toColor());
}
break;
-#if 0
case 2:
{
- KstBaseCurveList bcl;
+ KstBaseCurveList bcl = KstBinding::extractCurveList(exec, args[1]);
+ // check for an error code?
QVariant prev = KJSEmbed::convertToVariant(exec, args[0]);
- // FIXME: extract bcl from args[1]
if (!prev.canCast(QVariant::Color)) {
KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
exec->setException(eobj);
return KJS::Undefined();
}
- rc = KstColorSequence::next(bcl, prev.toColor());
+ rc = KstColorSequence::next(kstObjectSubList<KstBaseCurve, KstVCurve>(bcl), prev.toColor());
}
break;
-#endif
default:
KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError);
exec->setException(eobj);
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_curvecollection.h #489580:489581
@@ -48,6 +48,7 @@
virtual KJS::Value extract(KJS::ExecState *exec, unsigned item) const;
protected:
+ friend class KstBinding;
QStringList _curves;
QString _plot;
QGuardedPtr<KstViewLegend> _legend;
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_legend.cpp #489580:489581
@@ -116,7 +116,9 @@
static LegendProperties legendProperties[] = {
{ "font", &KstBindLegend::setFont, &KstBindLegend::font },
{ "fontSize", &KstBindLegend::setFontSize, &KstBindLegend::fontSize },
+#if 0
{ "textColor", &KstBindLegend::setTextColor, &KstBindLegend::textColor },
+#endif
{ "vertical", &KstBindLegend::setVertical, &KstBindLegend::vertical },
{ "curves", 0L, &KstBindLegend::curves },
{ 0L, 0L, 0L }
@@ -284,6 +286,7 @@
}
+#if 0
void KstBindLegend::setTextColor(KJS::ExecState *exec, const KJS::Value& value) {
QVariant cv = KJSEmbed::convertToVariant(exec, value);
if (!cv.canCast(QVariant::Color)) {
@@ -308,6 +311,7 @@
}
return KJSEmbed::convertToValue(exec, QColor());
}
+#endif
void KstBindLegend::setVertical(KJS::ExecState *exec, const KJS::Value& value) {
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_legend.h #489580:489581
@@ -67,11 +67,13 @@
*/
void setFontSize(KJS::ExecState *exec, const KJS::Value& value);
KJS::Value fontSize(KJS::ExecState *exec) const;
+#if 0
/* @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;
+#endif
/* @property boolean vertical
@description True if the legend entries are stacked vertically.
*/
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_scalar.cpp #489580:489581
@@ -49,8 +49,25 @@
KJS::Object KstBindScalar::construct(KJS::ExecState *exec, const KJS::List& args) {
Q_UNUSED(args)
- // FIXME: make a better constructor (but keep the default one)
- return KJS::Object(new KstBindScalar(exec));
+ if (args.size() == 0) {
+ return KJS::Object(new KstBindScalar(exec));
+ }
+
+ if (args.size() > 1) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError);
+ exec->setException(eobj);
+ return KJS::Object();
+ }
+
+ if (args[0].type() != KJS::NumberType) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+ exec->setException(eobj);
+ return KJS::Object();
+ }
+
+ KstScalarPtr s = new KstScalar;
+ s->setValue(args[0].toNumber(exec));
+ return KJS::Object(new KstBindScalar(exec, s));
}
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_scalar.h #489580:489581
@@ -35,6 +35,10 @@
/* @constructor
@description Default constructor. Creates a new scalar with value 0.0.
*/
+ /* @constructor
+ @arg Number value
+ @description Creates a new scalar with the specified value.
+ */
KstBindScalar(KJS::ExecState *exec, KstScalarPtr s);
KstBindScalar(KJS::ExecState *exec, KJS::Object *globalObject = 0L);
~KstBindScalar();
--- trunk/extragear/graphics/kst/kst/extensions/js/kstbinding.cpp #489580:489581
@@ -18,6 +18,7 @@
#include "kstbinding.h"
#include "bind_curve.h"
+#include "bind_curvecollection.h"
#include "bind_datasource.h"
#include "bind_datavector.h"
#include "bind_object.h"
@@ -323,6 +324,53 @@
}
+KstBaseCurveList KstBinding::extractCurveList(KJS::ExecState *exec, const KJS::Value& value, bool doThrow) {
+ KstBaseCurveList rc;
+ switch (value.type()) {
+ case KJS::ObjectType:
+ {
+ KstBindCurveCollection *imp = dynamic_cast<KstBindCurveCollection*>(value.toObject(exec).imp());
+ if (!imp) {
+ if (doThrow) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+ exec->setException(eobj);
+ }
+ return rc;
+ }
+ if (imp->_isPlot) {
+ Kst2DPlotPtr p = *Kst2DPlot::globalPlotList().findTag(imp->_plot);
+ if (p) {
+ for (KstBaseCurveList::ConstIterator i = p->Curves.begin(); i != p->Curves.end(); ++i) {
+ rc += *i;
+ }
+ }
+ } else if (imp->_legend) {
+ for (KstBaseCurveList::ConstIterator i = imp->_legend->curves().begin(); i != imp->_legend->curves().end(); ++i) {
+ rc += *i;
+ }
+ } else {
+ KstBaseCurveList cl = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList);
+ for (KstBaseCurveList::ConstIterator i = cl.begin(); i != cl.end(); ++i) {
+ (*i)->readLock();
+ if (imp->_curves.contains((*i)->tagName())) {
+ rc += *i;
+ }
+ (*i)->readUnlock();
+ }
+ }
+ return rc;
+ }
+ // fall through and throw
+ default:
+ if (doThrow) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+ exec->setException(eobj);
+ }
+ }
+ return rc;
+}
+
+
int KstBinding::methodCount() const {
return 0;
}
--- trunk/extragear/graphics/kst/kst/extensions/js/kstbinding.h #489580:489581
@@ -55,6 +55,7 @@
static KstViewWindow *extractWindow(KJS::ExecState*, const KJS::Value&, bool doThrow = true);
static Kst2DPlotPtr extractPlot(KJS::ExecState*, const KJS::Value&, bool doThrow = true);
static KstViewObjectPtr extractViewObject(KJS::ExecState*, const KJS::Value&, bool doThrow = true);
+ static KstBaseCurveList extractCurveList(KJS::ExecState*, const KJS::Value&, bool doThrow = true);
protected:
KstBinding(const QString& name, int id);
More information about the Kst
mailing list