[Kst] branches/work/kst/1.6/kst/src
Andrew Walker
arwalker at sumusltd.com
Tue Nov 20 00:33:51 CET 2007
SVN commit 738915 by arwalker:
KstImage access via javaScript complete - but not yet tested
M +22 -4 extensions/js/bind_image.cpp
M +4 -1 extensions/js/bind_image.h
M +0 -4 libkstmath/kstbasecurve.h
M +2 -2 libkstmath/kstdefaultnames.cpp
M +64 -25 libkstmath/kstimage.cpp
M +2 -1 libkstmath/kstimage.h
M +9 -3 libkstmath/kstvcurve.cpp
M +0 -5 libkstmath/kstvcurve.h
--- branches/work/kst/1.6/kst/src/extensions/js/bind_image.cpp #738914:738915
@@ -106,7 +106,7 @@
static ImageProperties imageProperties[] = {
{ "matrix", &KstBindImage::setMatrix, &KstBindImage::matrix },
{ "map", &KstBindImage::setMap, &KstBindImage::map },
-// { "palette", &KstBindImage::setPalette, &KstBindImage::palette },
+ { "palette", &KstBindImage::setPalette, &KstBindImage::palette },
{ "lowerThreshold", &KstBindImage::setLowerThreshold, &KstBindImage::lowerThreshold },
{ "upperThreshold", &KstBindImage::setUpperThreshold, &KstBindImage::upperThreshold },
{ "autoThreshold", &KstBindImage::setAutoThreshold, &KstBindImage::autoThreshold },
@@ -275,7 +275,7 @@
KstImagePtr d = makeImage(_d);
if (d) {
KstWriteLocker wl(d);
-// d->setMatrix(mp);
+ d->setMatrix(mp);
}
}
}
@@ -348,15 +348,33 @@
return KJS::Number(val);
}
-/*
+
void KstBindImage::setPalette(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;
+ }
+ QString pal = value.toString(exec).qstring();
+ KstImagePtr d = makeImage(_d);
+ if (d) {
+ KstWriteLocker wl(d);
+ d->setPalette(pal);
+ }
}
KJS::Value KstBindImage::palette(KJS::ExecState *exec) const {
+ Q_UNUSED(exec)
+ KstImagePtr d = makeImage(_d);
+ if (d) {
+ KstReadLocker rl(d);
+ return KJS::String(d->paletteName());
+ }
+ return KJS::Undefined();
}
-*/
+
void KstBindImage::setLowerThreshold(KJS::ExecState *exec, const KJS::Value& value) {
if (value.type() != KJS::NumberType) {
KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
--- branches/work/kst/1.6/kst/src/extensions/js/bind_image.h #738914:738915
@@ -80,7 +80,10 @@
void setMap(KJS::ExecState *exec, const KJS::Value& value);
KJS::Value map(KJS::ExecState *exec) const;
-// { "palette", &KstBindImage::setPalette, &KstBindImage::palette },
+ /* @property string palette
+ @description The name of the palette associated with the image color map.
+ */ void setPalette(KJS::ExecState *exec, const KJS::Value& value);
+ KJS::Value palette(KJS::ExecState *exec) const;
/* @property number lowerThreshold
@description The lower threshold associated with the map.
--- branches/work/kst/1.6/kst/src/libkstmath/kstbasecurve.h #738914:738915
@@ -26,10 +26,6 @@
#include "kst_export.h"
#include "labelparser.h"
-/**A class for handling curves for kst
- *@author C. Barth Netterfield
- */
-
// context for rendering a curve in a plot
class KstCurveRenderContext {
public:
--- branches/work/kst/1.6/kst/src/libkstmath/kstdefaultnames.cpp #738914:738915
@@ -109,7 +109,7 @@
QString KST::suggestPluginName(const QString& pname, KstObjectTag vname) {
QString tag;
-
+
if (!vname.isValid()) {
tag = pname;
} else {
@@ -126,4 +126,4 @@
i18n("Minimal abbreviation for 'Image'", "I"),
true);
}
-// vim: ts=2 sw=2 et
+
--- branches/work/kst/1.6/kst/src/libkstmath/kstimage.cpp #738914:738915
@@ -19,8 +19,10 @@
#include "dialoglauncher.h"
#include "kstdatacollection.h"
#include "kstdebug.h"
+#include "kstdefaultnames.h"
#include "kstimage.h"
#include "kstmath.h"
+#include "kstsettings.h"
#include <klocale.h>
@@ -35,8 +37,11 @@
KstImage::KstImage(const QDomElement& e) : KstBaseCurve(e){
QString in_matrixName, in_paletteName;
bool in_hasColorMap = false, in_hasContourMap = false;
- double in_zLower = 0, in_zUpper = 0;
+ double in_zLower = 0.0;
+ double in_zUpper = 0.0;
+
_autoThreshold = false;
+ _pal = 0L;
/* parse the DOM tree */
QDomNode n = e.firstChild();
@@ -106,9 +111,13 @@
//constructor for colormap only
KstImage::KstImage(const QString &in_tag, KstMatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, KPalette* pal) : KstBaseCurve(){
-
_inputMatrices[THEMATRIX] = in_matrix;
- setTagName(KstObjectTag(in_tag, KstObjectTag::globalTagContext)); // FIXME: always top-level?
+ if (in_tag == QString::null) {
+ QString tag_name = KST::suggestImageName(KstObjectTag(in_matrix->tagName()));
+ setTagName(KstObjectTag(in_matrix->tagName(), KstObjectTag::globalTagContext));
+ } else {
+ setTagName(KstObjectTag(in_tag, KstObjectTag::globalTagContext));
+ }
_typeString = i18n("Image");
_type = "Image";
_zLower = lowerZ;
@@ -126,7 +135,12 @@
//constructor for contour map only
KstImage::KstImage(const QString &in_tag, KstMatrixPtr in_matrix, int numContours, const QColor& contourColor, int contourWeight) : KstBaseCurve(){
_inputMatrices[THEMATRIX] = in_matrix;
- setTagName(KstObjectTag(in_tag, KstObjectTag::globalTagContext)); // FIXME: always top-level?
+ if (in_tag == QString::null) {
+ QString tag_name = KST::suggestImageName(KstObjectTag(in_matrix->tagName()));
+ setTagName(KstObjectTag(tag_name, KstObjectTag::globalTagContext));
+ } else {
+ setTagName(KstObjectTag(in_tag, KstObjectTag::globalTagContext));
+ }
_typeString = i18n("Image");
_type = "Image";
_contourColor = contourColor;
@@ -137,7 +151,6 @@
setColorDefaults();
setDirty();
-
}
@@ -152,7 +165,12 @@
const QColor& contourColor,
int contourWeight) {
_inputMatrices[THEMATRIX] = in_matrix;
- setTagName(KstObjectTag(in_tag, KstObjectTag::globalTagContext)); // FIXME: always top-level?
+ if (in_tag == QString::null) {
+ QString tag_name = KST::suggestImageName(KstObjectTag(in_matrix->tagName()));
+ setTagName(KstObjectTag(tag_name, KstObjectTag::globalTagContext));
+ } else {
+ setTagName(KstObjectTag(in_tag, KstObjectTag::globalTagContext));
+ }
_typeString = i18n("Image");
_type = "Image";
_contourColor = contourColor;
@@ -269,25 +287,28 @@
QColor KstImage::getMappedColor(double x, double y) {
- bool ok;
- double z;
+ if (_pal) {
+ bool ok;
+ double z;
- z = _inputMatrices[THEMATRIX]->value(x, y, &ok);
- if (ok) {
- int index;
- if (_zUpper - _zLower != 0) {
- if (z > _zUpper) {
- index = _pal->nrColors() - 1;
- } else if (z < _zLower) {
+ z = _inputMatrices[THEMATRIX]->value(x, y, &ok);
+ if (ok) {
+ int index;
+ if (_zUpper - _zLower != 0) {
+ if (z > _zUpper) {
+ index = _pal->nrColors() - 1;
+ } else if (z < _zLower) {
+ index = 0;
+ } else {
+ index = (int)floor(((z - _zLower) * (_pal->nrColors() - 1)) / (_zUpper - _zLower));
+ }
+ } else {
index = 0;
- } else {
- index = (int)floor(((z - _zLower) * (_pal->nrColors() - 1)) / (_zUpper - _zLower));
}
- } else {
- index = 0;
+ return _pal->color(index);
}
- return _pal->color(index);
}
+
return QColor();
}
@@ -295,9 +316,21 @@
void KstImage::setPalette(KPalette* pal) {
delete _pal;
_pal = pal;
+ setDirty();
}
+void KstImage::setPalette(const QString& strPalette) {
+ KPalette* pal = new KPalette(strPalette);
+
+ if (pal) {
+ delete _pal;
+ _pal = pal;
+ setDirty();
+ }
+}
+
+
void KstImage::showNewDialog() {
KstDialogs::self()->showImageDialog();
}
@@ -505,16 +538,22 @@
KstMatrixPtr KstImage::matrix() const {
if (_inputMatrices.contains(THEMATRIX)) {
- return _inputMatrices[THEMATRIX];
+ return _inputMatrices[THEMATRIX];
} else {
return NULL;
}
}
+void KstImage::setMatrix(const KstMatrixPtr& matrix) {
+ _inputMatrices[THEMATRIX] = matrix;
+ setDirty();
+}
+
+
QString KstImage::xLabel() const {
if (_inputMatrices.contains(THEMATRIX)) {
- return _inputMatrices[THEMATRIX]->xLabel();
+ return _inputMatrices[THEMATRIX]->xLabel();
} else {
return QString();
}
@@ -540,7 +579,7 @@
KstCurveType KstImage::curveType() const {
- return KST_IMAGE;
+ return KST_IMAGE;
}
@@ -552,7 +591,7 @@
if (mp) {
mp->readLock();
provider = kst_cast<KstDataObject>(mp->provider());
- mp->unlock();
+ mp->unlock();
}
return provider;
}
@@ -700,7 +739,7 @@
double zTL, zTR, zBL, zBR;
double new_x_small = (i - b_X) / m_X, new_y_small = (j + 1 - b_Y) / m_Y;
double new_x_large = (i + CONTOUR_STEP - b_X) / m_X, new_y_large = (j+1+CONTOUR_STEP - b_Y) / m_Y;
-
+
if (xLog) {
new_x_small = pow(xLogBase, new_x_small);
new_x_large = pow(xLogBase, new_x_large);
--- branches/work/kst/1.6/kst/src/libkstmath/kstimage.h #738914:738915
@@ -55,19 +55,20 @@
virtual bool getNearestZ(double x, double y, double& z);
virtual QColor getMappedColor(double x, double y);
virtual void setPalette(KPalette* pal);
+ virtual void setPalette(const QString& strPalette);
virtual void setUpperThreshold(double z);
virtual void setLowerThreshold(double z);
virtual void setAutoThreshold(bool yes);
virtual void setThresholdToMinMax();
virtual void setThresholdToSpikeInsensitive(double per = 0.005);
-
virtual double upperThreshold() const { return _zUpper; }
virtual double lowerThreshold() const { return _zLower; }
virtual bool autoThreshold() const { return _autoThreshold; }
virtual QString matrixTag() const;
virtual KstMatrixPtr matrix() const;
+ virtual void setMatrix(const KstMatrixPtr& matrix);
virtual QString paletteName() const;
virtual KPalette* palette() const { return _pal; }
--- branches/work/kst/1.6/kst/src/libkstmath/kstvcurve.cpp #738914:738915
@@ -27,6 +27,7 @@
#include "kstcolorsequence.h"
#include "kstdatacollection.h"
#include "kstdebug.h"
+#include "kstdefaultnames.h"
#include "kstlinestyle.h"
#include "kstmath.h"
#include "kstrvector.h"
@@ -70,7 +71,6 @@
setPointStyle(0);
setInterp(InterpY);
- commonConstructor(in_tag, in_color);
if (in_X) {
_inputVectors[COLOR_XVECTOR] = in_X;
}
@@ -95,6 +95,7 @@
_inputVectors[EYMINUSVECTOR] = in_EYMinus;
}
+ commonConstructor(in_tag, in_color);
setDirty();
}
@@ -164,7 +165,7 @@
} else if (e.tagName() == "ignoreAutoScale") {
_ignoreAutoScale = true;
} else if (e.tagName() == "interp") {
- _interp = KstVCurve::InterpType(e.text().toInt());
+ _interp = KstVCurve::InterpType(e.text().toInt());
}
}
n = n.nextSibling();
@@ -198,7 +199,12 @@
_typeString = i18n("Curve");
_type = "Curve";
_color = in_color;
- setTagName(KstObjectTag::fromString(in_tag));
+ if (in_tag == QString::null) {
+ QString tag_name = KST::suggestCurveName(yVTag());
+ setTagName(KstObjectTag::fromString(tag_name));
+ } else {
+ setTagName(KstObjectTag::fromString(in_tag));
+ }
updateParsedLegendTag();
}
--- branches/work/kst/1.6/kst/src/libkstmath/kstvcurve.h #738914:738915
@@ -23,11 +23,6 @@
#include "kstcurvepointsymbol.h"
#include "kst_export.h"
-/**A class for handling curves for kst
- *@author C. Barth Netterfield
- */
-
-
class KST_EXPORT KstVCurve: public KstBaseCurve {
public:
// InterpType order must match the order of entries of _interp in
More information about the Kst
mailing list