[Kst] branches/work/kst/portto4/kst
Barth Netterfield
netterfield at astro.utoronto.ca
Wed Sep 15 18:27:00 CEST 2010
SVN commit 1175708 by netterfield:
Deleting a primitive in the data manager also deletes all dependents.
Matrixes have an automatic vector which is the values as an array.
Fix bug in matrix dialog (field not set properly).
M +1 -1 run-kst
M +51 -38 src/libkst/matrix.cpp
M +5 -1 src/libkst/matrix.h
M +13 -0 src/libkst/object.cpp
M +2 -0 src/libkst/object.h
M +2 -0 src/libkst/objectstore.h
M +9 -0 src/libkst/vector.cpp
M +2 -0 src/libkst/vector.h
M +5 -1 src/libkstapp/matrixdialog.cpp
M +1 -0 src/libkstapp/matrixdialog.h
--- branches/work/kst/portto4/kst/run-kst #1175707:1175708
@@ -3,6 +3,6 @@
cd `dirname $0`
export SCRIPTDIR=$PWD
-export BUILDDIR=$PWD/build/build
+export BUILDDIR=$PWD/build
$BUILDDIR/bin/kst2 "$@"
--- branches/work/kst/portto4/kst/src/libkst/matrix.cpp #1175707:1175708
@@ -52,6 +52,7 @@
Matrix::~Matrix() {
if (_z) {
+ _vectors["z"]->setV(0L, 0);
free(_z);
_z = 0L;
}
@@ -66,10 +67,14 @@
void Matrix::deleteDependents() {
- for (QHash<QString, ScalarPtr>::Iterator it = _statScalars.begin(); it != _statScalars.end(); ++it) {
+ for (QHash<QString, ScalarPtr>::Iterator it = _scalars.begin(); it != _scalars.end(); ++it) {
_store->removeObject(it.value());
}
+ for (QHash<QString, VectorPtr>::Iterator it = _vectors.begin(); it != _vectors.end(); ++it) {
+ _store->removeObject(it.value());
}
+ Object::deleteDependents();
+}
const QString& Matrix::typeString() const {
@@ -141,12 +146,12 @@
}
double Matrix::minValue() const {
- return _statScalars["min"]->value();
+ return _scalars["min"]->value();
}
double Matrix::maxValue() const {
- return _statScalars["max"]->value();
+ return _scalars["max"]->value();
}
double Matrix::minValueNoSpike() const {
@@ -262,11 +267,11 @@
}
double Matrix::meanValue() const {
- return _statScalars["mean"]->value();
+ return _scalars["mean"]->value();
}
double Matrix::minValuePositive() const {
- return _statScalars["minpos"]->value();
+ return _scalars["minpos"]->value();
}
int Matrix::numNew() const {
@@ -302,7 +307,7 @@
int Matrix::getUsage() const {
int scalarUsage = 0;
- for (QHash<QString, ScalarPtr>::ConstIterator it = _statScalars.begin(); it != _statScalars.end(); ++it) {
+ for (QHash<QString, ScalarPtr>::ConstIterator it = _scalars.begin(); it != _scalars.end(); ++it) {
scalarUsage += it.value()->getUsage() - 1;
}
return Object::getUsage() + scalarUsage;
@@ -347,11 +352,11 @@
}
}
}
- _statScalars["sum"]->setValue(sum);
- _statScalars["sumsquared"]->setValue(sumsquared);
- _statScalars["max"]->setValue(max);
- _statScalars["min"]->setValue(min);
- _statScalars["minpos"]->setValue(minpos);
+ _scalars["sum"]->setValue(sum);
+ _scalars["sumsquared"]->setValue(sumsquared);
+ _scalars["max"]->setValue(max);
+ _scalars["min"]->setValue(min);
+ _scalars["minpos"]->setValue(minpos);
updateScalars();
}
@@ -359,7 +364,7 @@
const QHash<QString, ScalarPtr>& Matrix::scalars() const {
- return _statScalars;
+ return _scalars;
}
@@ -401,57 +406,62 @@
void Matrix::createScalars(ObjectStore *store) {
Q_ASSERT(store);
ScalarPtr sp;
+ VectorPtr vp;
- _statScalars.insert("max", sp=store->createObject<Scalar>());
+ _scalars.insert("max", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Max");
- sp->_KShared_ref();
- _statScalars.insert("min", sp=store->createObject<Scalar>());
+
+ _scalars.insert("min", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Min");
- sp->_KShared_ref();
- _statScalars.insert("mean", sp=store->createObject<Scalar>());
+
+ _scalars.insert("mean", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Mean");
- sp->_KShared_ref();
- _statScalars.insert("sigma", sp=store->createObject<Scalar>());
+
+ _scalars.insert("sigma", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Sigma");
- sp->_KShared_ref();
- _statScalars.insert("rms", sp=store->createObject<Scalar>());
+
+ _scalars.insert("rms", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Rms");
- sp->_KShared_ref();
- _statScalars.insert("ns", sp=store->createObject<Scalar>());
+
+ _scalars.insert("ns", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("NS");
- sp->_KShared_ref();
- _statScalars.insert("sum", sp=store->createObject<Scalar>());
+
+ _scalars.insert("sum", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("Sum");
- sp->_KShared_ref();
- _statScalars.insert("sumsquared", sp=store->createObject<Scalar>());
+
+ _scalars.insert("sumsquared", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("SumSquared");
- sp->_KShared_ref();
- _statScalars.insert("minpos", sp=store->createObject<Scalar>());
+
+ _scalars.insert("minpos", sp=store->createObject<Scalar>());
sp->setProvider(this);
sp->setSlaveName("MinPos");
- sp->_KShared_ref();
+
+ _vectors.insert("z", vp = store->createObject<Vector>());
+ vp->setProvider(this);
+ vp->setSlaveName("Z");
+
}
void Matrix::updateScalars() {
- _statScalars["ns"]->setValue(_NS);
+ _scalars["ns"]->setValue(_NS);
if (_NRealS >= 2) {
- _statScalars["mean"]->setValue(_statScalars["sum"]->value()/double(_NRealS));
- _statScalars["sigma"]->setValue( sqrt(
- (_statScalars["sumsquared"]->value() - _statScalars["sum"]->value()*_statScalars["sum"]->value()/double(_NRealS))/ double(_NRealS-1) ) );
- _statScalars["rms"]->setValue(sqrt(_statScalars["sumsquared"]->value()/double(_NRealS)));
+ _scalars["mean"]->setValue(_scalars["sum"]->value()/double(_NRealS));
+ _scalars["sigma"]->setValue( sqrt(
+ (_scalars["sumsquared"]->value() - _scalars["sum"]->value()*_scalars["sum"]->value()/double(_NRealS))/ double(_NRealS-1) ) );
+ _scalars["rms"]->setValue(sqrt(_scalars["sumsquared"]->value()/double(_NRealS)));
} else {
- _statScalars["sigma"]->setValue(_statScalars["max"]->value() - _statScalars["min"]->value());
- _statScalars["rms"]->setValue(sqrt(_statScalars["sumsquared"]->value()));
- _statScalars["mean"]->setValue(0);
+ _scalars["sigma"]->setValue(_scalars["max"]->value() - _scalars["min"]->value());
+ _scalars["rms"]->setValue(sqrt(_scalars["sumsquared"]->value()));
+ _scalars["mean"]->setValue(0);
}
}
@@ -460,6 +470,7 @@
// qDebug() << "resizing to: " << sz << endl;
if (sz >= 1) {
_z = static_cast<double*>(Kst::realloc(_z, sz*sizeof(double)));
+ _vectors["z"]->setV(_z, sz);
if (!_z) {
return false;
}
@@ -517,6 +528,7 @@
if (sz > _zSize) {
// array is getting bigger, so resize before moving
_z = static_cast<double*>(Kst::realloc(_z, sz*sizeof(double)));
+ _vectors["z"]->setV(_z, sz);
if (!_z) {
qCritical() << "Matrix resize failed";
return false;
@@ -541,6 +553,7 @@
if (sz < _zSize) {
// array is getting smaller, so resize after moving
_z = static_cast<double*>(Kst::realloc(_z, sz*sizeof(double)));
+ _vectors["z"]->setV(_z, sz);
if (!_z) {
qCritical() << "Matrix resize failed";
return false;
--- branches/work/kst/portto4/kst/src/libkst/matrix.h #1175707:1175708
@@ -24,6 +24,7 @@
#include <QHash>
#include "scalar.h"
+#include "vector.h"
#include "primitive.h"
class QXmlStreamWriter;
@@ -161,7 +162,10 @@
bool _invertYHint;
int _numNew; // number of new samples
- QHash<QString, ScalarPtr> _statScalars; // statistics scalars
+
+ ScalarMap _scalars;
+ VectorMap _vectors;
+
bool _editable : 1;
bool _saveable : 1;
--- branches/work/kst/portto4/kst/src/libkst/object.cpp #1175707:1175708
@@ -56,9 +56,22 @@
void Object::deleteDependents() {
+ QList<ObjectPtr> Objects = _store->objectList();
+ foreach (ObjectPtr object, Objects) {
+ if (object->uses(this)) {
+ _store->removeObject(object);
}
+ }
+}
+bool Object::uses(ObjectPtr p) const {
+ Q_UNUSED(p)
+
+ return false;
+}
+
+
ObjectStore* Object::store() const {
return _store;
}
--- branches/work/kst/portto4/kst/src/libkst/object.h #1175707:1175708
@@ -74,6 +74,8 @@
virtual bool used() const {return _used;}
void setUsed(bool used_in) {_used = used_in;}
+ virtual bool uses(ObjectPtr p) const;
+
protected:
Object();
virtual ~Object();
--- branches/work/kst/portto4/kst/src/libkst/objectstore.h #1175707:1175708
@@ -78,6 +78,8 @@
* used flags are set properly. It is not done here! */
bool deleteUnsetUsedFlags();
+// void deleteDependentObjects(const Primitive &p);
+
private:
Q_DISABLE_COPY(ObjectStore)
--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #1175707:1175708
@@ -87,12 +87,14 @@
void Vector::deleteDependents() {
+
for (QHash<QString, ScalarPtr>::Iterator it = _scalars.begin(); it != _scalars.end(); ++it) {
_store->removeObject(it.value());
}
for (QHash<QString, StringPtr>::Iterator it = _strings.begin(); it != _strings.end(); ++it) {
_store->removeObject(it.value());
}
+ Object::deleteDependents();
}
@@ -339,6 +341,13 @@
}
+void Vector::setV(double *memptr, int newSize) {
+ _v = memptr;
+ NumNew = newSize;
+ _size = newSize;
+}
+
+
void Vector::zero() {
_ns_min = _ns_max = 0.0;
memset(_v, 0, sizeof(double)*_size);
--- branches/work/kst/portto4/kst/src/libkst/vector.h #1175707:1175708
@@ -212,7 +212,9 @@
QString _descriptiveLabel;
friend class DataObject;
+ friend class Matrix;
virtual double* realloced(double *memptr, int newSize);
+ virtual void setV(double *memptr, int newSize);
};
--- branches/work/kst/portto4/kst/src/libkstapp/matrixdialog.cpp #1175707:1175708
@@ -33,7 +33,7 @@
namespace Kst {
MatrixTab::MatrixTab(ObjectStore *store, QWidget *parent)
- : DataTab(parent), _mode(DataMatrix), _store(store), _requestID(0) {
+ : DataTab(parent), _mode(DataMatrix), _store(store), _initField(QString()), _requestID(0) {
setupUi(this);
setTabTitle(tr("Matrix"));
@@ -164,6 +164,7 @@
void MatrixTab::setField(const QString &field) {
+ _initField = field; // for delayed index setting
_field->setCurrentIndex(_field->findText(field));
}
@@ -501,6 +502,9 @@
_dataSource->readLock();
_field->addItems(_dataSource->matrix().list());
+ if (!_initField.isEmpty()) {
+ setField(_initField);
+ }
_field->setEditable(!_dataSource->matrix().isListComplete() && !_dataSource->matrix().list().empty());
_configure->setEnabled(_dataSource->hasConfigWidget());
--- branches/work/kst/portto4/kst/src/libkstapp/matrixdialog.h #1175707:1175708
@@ -153,6 +153,7 @@
MatrixMode _mode;
DataSourcePtr _dataSource;
ObjectStore *_store;
+ QString _initField;
int _requestID;
};
More information about the Kst
mailing list