[Kst] branches/work/kst/portto4/kst
Mike Fenton
mike at staikos.net
Wed Nov 7 20:02:01 CET 2007
SVN commit 733965 by fenton:
Add Save/Restore for Image.
Fix creation of Image.
Update Palette usage in Image.
Fix crash in ImageDialog.
M +1 -0 devel-docs/Kst2Specs/kstfile.txt
M +1 -3 src/libkstapp/csddialog.cpp
M +7 -2 src/libkstapp/imagedialog.cpp
M +2 -0 src/libkstapp/imagedialog.h
M +2 -0 src/libkstmath/builtinrelations.cpp
M +45 -62 src/libkstmath/image.cpp
M +9 -9 src/libkstmath/image.h
A src/libkstmath/imagefactory.cpp [License: GPL (v2+)]
A src/libkstmath/imagefactory.h [License: GPL (v2+)]
M +2 -0 src/libkstmath/libkstmath.pro
--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/kstfile.txt #733964:733965
@@ -34,6 +34,7 @@
</objects>
<relations>
<curve tag="" xvector="" yvector="" legend="" errorxvector="" erroryvector="" errorxminusvector="" erroryminusvector="" color="" haslines="" linewidth="" linestyle="" haspoints="" pointtype="" pointdensity="" hasbars="" barstyle="" ignoreautoscale=""></curve>
+ <image tag="" matrix="" legend="" palettename="" hascolormap="" lowerthreshold="" upperthreshold="" hascontourmap="" numcontourlines="" contourweight="" contourcolor="" autothreshold=""></image>
</relations>
<graphics>
<view name="">
--- branches/work/kst/portto4/kst/src/libkstapp/csddialog.cpp #733964:733965
@@ -121,11 +121,9 @@
csd->update(0);
csd->unlock();
- Palette* newPalette = new Palette(_CSDTab->colorPalette()->selectedPalette());
-
tag = _document->objectStore()->suggestObjectTag<Image>(csd->tag().tagString(), ObjectTag::globalTagContext);
ImagePtr image = _document->objectStore()->createObject<Image>(tag);
- image->changeToColorOnly(csd->outputMatrix(), 0, 1, true, newPalette->paletteData());
+ image->changeToColorOnly(csd->outputMatrix(), 0, 1, true, _CSDTab->colorPalette()->selectedPalette());
image->writeLock();
image->update(0);
--- branches/work/kst/portto4/kst/src/libkstapp/imagedialog.cpp #733964:733965
@@ -122,6 +122,11 @@
}
+void ImageTab::setObjectStore(ObjectStore *store) {
+ _matrix->setObjectStore(store);
+}
+
+
ImageDialog::ImageDialog(ObjectPtr dataObject, QWidget *parent)
: DataDialog(dataObject, parent) {
@@ -157,7 +162,7 @@
_imageTab->lowerZ(),
_imageTab->upperZ(),
_imageTab->realTimeAutoThreshold(),
- Palette(_imageTab->colorPalette()->selectedPalette()).paletteData());
+ _imageTab->colorPalette()->selectedPalette());
} else if (_imageTab->contourOnly()) {
image->changeToContourOnly(_imageTab->matrix(),
_imageTab->numberOfContourLines(),
@@ -168,7 +173,7 @@
_imageTab->lowerZ(),
_imageTab->upperZ(),
_imageTab->realTimeAutoThreshold(),
- Palette(_imageTab->colorPalette()->selectedPalette()).paletteData(),
+ _imageTab->colorPalette()->selectedPalette(),
_imageTab->numberOfContourLines(),
_imageTab->contourColor(),
_imageTab->contourWeight());
--- branches/work/kst/portto4/kst/src/libkstapp/imagedialog.h #733964:733965
@@ -34,6 +34,8 @@
CurvePlacement* curvePlacement() const;
ColorPalette* colorPalette() const;
+ void setObjectStore(ObjectStore *store);
+
bool realTimeAutoThreshold() const;
bool colorOnly() const;
bool contourOnly() const;
--- branches/work/kst/portto4/kst/src/libkstmath/builtinrelations.cpp #733964:733965
@@ -11,11 +11,13 @@
#include "builtinrelations.h"
#include "curvefactory.h"
+#include "imagefactory.h"
namespace Kst {
namespace Builtins {
void initRelations() {
new CurveFactory;
+ new ImageFactory;
}
}
}
--- branches/work/kst/portto4/kst/src/libkstmath/image.cpp #733964:733965
@@ -21,13 +21,14 @@
#include <QImage>
#include <QPainter>
-#include <QTextDocument>
+#include <QXmlStreamWriter>
#include <math.h>
namespace Kst {
const QString Image::staticTypeString = I18N_NOOP("Image");
+const QString Image::staticTypeTag = I18N_NOOP("image");
static const QLatin1String& THEMATRIX = QLatin1String("THEMATRIX");
@@ -91,13 +92,7 @@
_zUpper = in_zUpper;
if (_hasColorMap) {
- PaletteData in_pal;
- //maybe the palette doesn't exist anymore. Generate a grayscale palette then.
- for (int i = 0; i < 256; i++) {
- in_pal.insert(i, QColor(i,i,i));
- }
- Debug::self()->log(i18n("Unable to find PaletteData %1. Using a 256 color grayscale palette instead.").arg(in_paletteName), Debug::Warning);
- _pal = in_pal;
+ _pal = Palette(in_paletteName);
}
if (!_hasColorMap) {
@@ -110,14 +105,14 @@
//constructor for colormap only
-Image::Image(ObjectStore *store, const ObjectTag &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal) : Relation(store, in_tag) {
+Image::Image(ObjectStore *store, const ObjectTag &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName) : Relation(store, in_tag) {
_inputMatrices[THEMATRIX] = in_matrix;
_typeString = staticTypeString;
_type = "Image";
_zLower = lowerZ;
_zUpper = upperZ;
_autoThreshold = autoThreshold;
- _pal = pal;
+ _pal = Palette(paletteName);
_hasContourMap = false;
_hasColorMap = true;
@@ -149,7 +144,7 @@
double lowerZ,
double upperZ,
bool autoThreshold,
- const PaletteData &pal,
+ const QString &paletteName,
int numContours,
const QColor& contourColor,
int contourWeight) :
@@ -165,7 +160,7 @@
_zLower = lowerZ;
_zUpper = upperZ;
_autoThreshold = autoThreshold;
- _pal = pal;
+ _pal = Palette(paletteName);
setDirty();
}
@@ -174,31 +169,28 @@
}
-void Image::save(QTextStream &ts, const QString& indent) {
- QString l2 = indent + " ";
- ts << indent << "<image>" << endl;
- ts << l2 << "<tag>" << Qt::escape(tag().tagString()) << "</tag>" << endl;
+void Image::save(QXmlStreamWriter &s) {
+ s.writeStartElement(staticTypeTag);
+ s.writeAttribute("tag", tag().tagString());
if (_inputMatrices.contains(THEMATRIX)) {
- ts << l2 << "<matrixtag>" << Qt::escape(_inputMatrices[THEMATRIX]->tag().tagString()) << "</matrixtag>" << endl;
+ s.writeAttribute("matrix", _inputMatrices[THEMATRIX]->tag().tagString());
}
- ts << l2 << "<legend>" << Qt::escape(legendText()) << "</legend>" << endl;
- ts << l2 << "<hascolormap>" << _hasColorMap << "</hascolormap>" <<endl;
+ s.writeAttribute("legend", legendText());
-//FIXME!!
-#if 0
- if (!_pal.isEmpty()) {
- ts << l2 << "<palettename>" << Qt::escape(_pal->name()) << "</palettename>" << endl;
+ if (!_pal.paletteData().isEmpty()) {
+ s.writeAttribute("palettename", _pal.paletteName());
}
-#endif
- ts << l2 << "<lowerthreshold>" << _zLower << "</lowerthreshold>" << endl;
- ts << l2 << "<upperthreshold>" << _zUpper << "</upperthreshold>" << endl;
- ts << l2 << "<hascontourmap>" << _hasContourMap << "</hascontourmap>" << endl;
- ts << l2 << "<numcontourlines>" << _numContourLines << "</numcontourlines>" << endl;
- ts << l2 << "<contourweight>" << _contourWeight << "</contourweight>" << endl;
- ts << l2 << "<contourcolor>" << Qt::escape(_contourColor.name()) << "</contourcolor>" << endl;
- ts << l2 << "<autothreshold>" << _autoThreshold << "</autothreshold>" << endl;
- ts << indent << "</image>" << endl;
+ s.writeAttribute("hascolormap", QVariant(_hasColorMap).toString());
+ s.writeAttribute("lowerthreshold", QString::number(_zLower));
+ s.writeAttribute("upperthreshold", QString::number(_zUpper));
+
+ s.writeAttribute("hascontourmap", QVariant(_hasContourMap).toString());
+ s.writeAttribute("numcontourlines", QString::number(_numContourLines));
+ s.writeAttribute("contourweight", QString::number(_contourWeight));
+ s.writeAttribute("contourcolor", _contourColor.name());
+
+ s.writeAttribute("autothreshold", QVariant(_autoThreshold).toString());
}
@@ -282,22 +274,22 @@
int index;
if (_zUpper - _zLower != 0) {
if (z > _zUpper) {
- index = _pal.count() - 1;
+ index = _pal.paletteData().count() - 1;
} else if (z < _zLower) {
index = 0;
} else {
- index = (int)floor(((z - _zLower) * (_pal.count() - 1)) / (_zUpper - _zLower));
+ index = (int)floor(((z - _zLower) * (_pal.paletteData().count() - 1)) / (_zUpper - _zLower));
}
} else {
index = 0;
}
- return _pal.value(index);
+ return _pal.paletteData().value(index);
}
return QColor();
}
-void Image::setPalette(const PaletteData &pal) {
+void Image::setPalette(const Palette &pal) {
_pal = pal;
}
@@ -338,15 +330,15 @@
void Image::changeToColorOnly(MatrixPtr in_matrix, double lowerZ,
- double upperZ, bool autoThreshold, const PaletteData &pal) {
- if (_inputMatrices.contains(THEMATRIX)) {
- _inputMatrices[THEMATRIX] = in_matrix;
- }
+ double upperZ, bool autoThreshold, const QString &paletteName) {
+
+ _inputMatrices[THEMATRIX] = in_matrix;
+
_zLower = lowerZ;
_zUpper = upperZ;
_autoThreshold = autoThreshold;
- if (_pal != pal) {
- _pal = pal;
+ if (_pal.paletteName() != paletteName) {
+ _pal = Palette(paletteName);
}
_hasColorMap = true;
_hasContourMap = false;
@@ -356,37 +348,28 @@
void Image::changeToContourOnly(MatrixPtr in_matrix, int numContours,
const QColor& contourColor, int contourWeight) {
- if (_inputMatrices.contains(THEMATRIX)) {
- _inputMatrices[THEMATRIX] = in_matrix;
- }
+ _inputMatrices[THEMATRIX] = in_matrix;
_numContourLines = numContours;
_contourWeight = contourWeight;
_contourColor = contourColor;
_hasColorMap = false;
_hasContourMap = true;
-//FIXME
-#if 0
- if (_pal) {
- _lastPaletteName = _pal->name();
- }
-#endif
-
setDirty();
}
void Image::changeToColorAndContour(MatrixPtr in_matrix,
- double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal,
+ double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName,
int numContours, const QColor& contourColor, int contourWeight) {
- if (_inputMatrices.contains(THEMATRIX)) {
- _inputMatrices[THEMATRIX] = in_matrix;
- }
+
+ _inputMatrices[THEMATRIX] = in_matrix;
+
_zLower = lowerZ;
_zUpper = upperZ;
_autoThreshold = autoThreshold;
- if (_pal != pal) {
- _pal = pal;
+ if (_pal.paletteName() != paletteName) {
+ _pal = Palette(paletteName);
}
_numContourLines = numContours;
_contourWeight = contourWeight;
@@ -442,7 +425,7 @@
QString Image::paletteName() const {
- return _lastPaletteName;
+ return _pal.paletteName();
}
@@ -826,12 +809,12 @@
void Image::paintLegendSymbol(Painter *p, const QRect& bound) {
- if (hasColorMap() && !_pal.isEmpty()) {
+ if (hasColorMap() && !_pal.paletteData().isEmpty()) {
int l = bound.left(), r = bound.right(), t = bound.top(), b = bound.bottom();
// draw the color palette
for (int i = l; i <= r; i++) {
- int index = (int)floor(static_cast<double>(((i - l) * (_pal.count() - 1))) / (r - l));
- QColor sliceColor = _pal.value(index).rgb();
+ int index = (int)floor(static_cast<double>(((i - l) * (_pal.paletteData().count() - 1))) / (r - l));
+ QColor sliceColor = _pal.paletteData().value(index).rgb();
p->setPen(QPen(sliceColor, 0));
p->drawLine(i, t, i, b);
}
--- branches/work/kst/portto4/kst/src/libkstmath/image.h #733964:733965
@@ -33,10 +33,11 @@
public:
static const QString staticTypeString;
const QString& typeString() const { return staticTypeString; }
+ static const QString staticTypeTag;
virtual void showNewDialog();
virtual void showEditDialog();
- virtual void save(QTextStream &ts, const QString& indent = QString::null);
+ virtual void save(QXmlStreamWriter &s);
virtual UpdateType update(int update_counter = -1);
virtual QString propertyString() const;
@@ -44,7 +45,7 @@
virtual bool getNearestZ(double x, double y, double& z);
virtual QColor getMappedColor(double x, double y);
- virtual void setPalette(const PaletteData &pal);
+ virtual void setPalette(const Palette &pal);
virtual void setUpperThreshold(double z);
virtual void setLowerThreshold(double z);
virtual void setAutoThreshold(bool yes);
@@ -58,16 +59,16 @@
virtual QString matrixTag() const;
virtual MatrixPtr matrix() const;
virtual QString paletteName() const;
- virtual const PaletteData &palette() const { return _pal; }
+ virtual const Palette &palette() const { return _pal; }
virtual void matrixDimensions(double &x, double &y, double &width, double &height);
virtual void changeToColorOnly(MatrixPtr in_matrix,
- double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal);
+ double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName);
virtual void changeToContourOnly(MatrixPtr in_matrix,
int numContours, const QColor& contourColor, int contourWeight);
virtual void changeToColorAndContour(MatrixPtr in_matrix,
- double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal,
+ double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName,
int numContours, const QColor& contourColor, int contourWeight);
//contour lines
@@ -110,7 +111,7 @@
protected:
Image(ObjectStore *store, const ObjectTag &in_tag);
//constructor for colormap only
- Image(ObjectStore *store, const ObjectTag &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal);
+ Image(ObjectStore *store, const ObjectTag &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName);
//constructor for contour map only
Image(ObjectStore *store, const ObjectTag &in_tag, MatrixPtr in_matrix, int numContours, const QColor& contourColor, int contourWeight);
//constructor for both colormap and contour map
@@ -119,7 +120,7 @@
double lowerZ,
double upperZ,
bool autoThreshold,
- const PaletteData &pal,
+ const QString &paletteName,
int numContours,
const QColor& contourColor,
int contourWeight);
@@ -133,7 +134,7 @@
//use these to set defaults when either is not used.
void setColorDefaults();
void setContourDefaults();
- PaletteData _pal;
+ Palette _pal;
//upper and lower thresholds
double _zUpper;
double _zLower;
@@ -146,7 +147,6 @@
QList<double> _contourLines;
QColor _contourColor;
int _contourWeight; //_contourWeight = -1 means variable weight
- QString _lastPaletteName;
};
--- branches/work/kst/portto4/kst/src/libkstmath/libkstmath.pro #733964:733965
@@ -50,6 +50,7 @@
histogram.cpp \
histogramfactory.cpp \
image.cpp \
+ imagefactory.cpp \
labelparser.cpp \
linestyle.cpp \
objectdefaults.cpp \
@@ -90,6 +91,7 @@
histogram.h \
histogramfactory.h \
image.h \
+ imagefactory.h \
labelparser.h \
linestyle.h \
objectdefaults.h \
More information about the Kst
mailing list