2 changes: 1 addition & 1 deletion src/libkst/datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void DataSource::saveSource(QXmlStreamWriter &s) {
DataPrimitive::saveFilename(name, s);
save(s);

saveNameInfo(s, DATASOURCENUM);
saveNameInfo(s, DATASOURCENUM | SCALARNUM | STRINGNUM);
s.writeEndElement();
}

Expand Down
5 changes: 5 additions & 0 deletions src/libkst/scalarfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ PrimitivePtr VScalarFactory::generatePrimitive(ObjectStore *store, QXmlStreamRea
QXmlStreamAttributes attrs = xml.attributes();
provider = attrs.value("provider").toString();
file = DataPrimitive::readFilename(attrs);

if (!store->override.fileName.isEmpty()) {
file = store->override.fileName;
}

field = attrs.value("field").toString();
f0 = attrs.value("f0").toString().toInt();
if (attrs.value("descriptiveNameIsManual").toString() == "true") {
Expand Down
69 changes: 30 additions & 39 deletions src/libkst/vscalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ const QString VScalar::staticTypeTag = "vscalar";

/** Create a VScalar: a scalar from a single sample of a vector field */
VScalar::VScalar(ObjectStore *store)
: Scalar(store) {
: Scalar(store), DataPrimitive(this) {

_file = 0L;
_field.clear();

setOrphan(true);
}


VScalar::~VScalar() {
_file = 0;
}


Expand All @@ -62,30 +60,31 @@ ScriptInterface* VScalar::createScriptInterface() {
return new ScalarVectorSI(this);
}

void VScalar::change(DataSourcePtr in_file, const QString &in_field, int in_f0) {
void VScalar::change(DataSourcePtr in_datasource, const QString &in_field, int in_f0) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);

_field = in_field;
_file = in_file;
setDataSource(in_datasource);
_f0 = in_f0;
}

void VScalar::changeFile(DataSourcePtr in_file) {
void VScalar::changeFile(DataSourcePtr in_datasource) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);

if (!in_file) {
if (!in_datasource) {
Debug::self()->log(tr("Data file for scalar %1 was not opened.").arg(Name()), Debug::Warning);
}
setDataSource(in_datasource);
}


/** return the name of the file */
QString VScalar::filename() const {
QString rc;
if (_file) {
_file->readLock();
rc = _file->fileName();
_file->unlock();
if (dataSource()) {
dataSource()->readLock();
rc = dataSource()->fileName();
dataSource()->unlock();
}
return rc;
}
Expand All @@ -103,13 +102,9 @@ int VScalar::F0() const {

/** Save data scalar information */
void VScalar::save(QXmlStreamWriter &s) {
if (_file) {
if (dataSource()) {
s.writeStartElement("vscalar");

_file->readLock();
s.writeAttribute("provider", _file->Name());
DataPrimitive::saveFilename(_file->fileName(), s);
_file->unlock();
saveFilename(s);

s.writeAttribute("field", _field);
s.writeAttribute("f0", QString::number(_f0));
Expand All @@ -122,40 +117,40 @@ void VScalar::save(QXmlStreamWriter &s) {

/** Update a data Scalar */
void VScalar::internalUpdate() {
if (_file) {
if (dataSource()) {
int f0;
if (_f0<0) {
f0 = _file->vector().dataInfo(_field).frameCount-1;
f0 = dataSource()->vector().dataInfo(_field).frameCount-1;
} else {
f0 = _f0;
}
_file->writeLock();
dataSource()->writeLock();
DataVector::ReadInfo p = {&_value, f0, -1, -1};
_file->vector().read(_field, p);
_file->unlock();
dataSource()->vector().read(_field, p);
dataSource()->unlock();
}
}

qint64 VScalar::minInputSerial() const {
if (_file) {
return (_file->serial());
if (dataSource()) {
return (dataSource()->serial());
}
return LLONG_MAX;
}

qint64 VScalar::maxInputSerialOfLastChange() const {
if (_file) {
return (_file->serialOfLastChange());
if (dataSource()) {
return (dataSource()->serialOfLastChange());
}
return NoInputs;
}

PrimitivePtr VScalar::_makeDuplicate() const {
PrimitivePtr VScalar::makeDuplicate() const {
Q_ASSERT(store());
VScalarPtr scalar = store()->createObject<VScalar>();

scalar->writeLock();
scalar->change(_file, _field, _f0);
scalar->change(dataSource(), _field, _f0);
if (descriptiveNameIsManual()) {
scalar->setDescriptiveName(descriptiveName());
}
Expand All @@ -167,11 +162,6 @@ PrimitivePtr VScalar::_makeDuplicate() const {
}


DataSourcePtr VScalar::dataSource() const {
return _file;
}


QString VScalar::descriptionTip() const {
QString IDstring;

Expand All @@ -187,17 +177,17 @@ QString VScalar::descriptionTip() const {

/** return true if it has a valid file and field, or false otherwise */
bool VScalar::isValid() const {
if (_file) {
_file->readLock();
bool rc = _file->vector().isValid(_field);
_file->unlock();
if (dataSource()) {
dataSource()->readLock();
bool rc = dataSource()->vector().isValid(_field);
dataSource()->unlock();
return rc;
}
return false;
}


bool VScalar::_checkValidity(const DataSourcePtr ds) const {
bool VScalar::checkValidity(const DataSourcePtr& ds) const {
if (ds) {
ds->readLock();
bool rc = ds->vector().isValid(_field);
Expand All @@ -209,7 +199,8 @@ bool VScalar::_checkValidity(const DataSourcePtr ds) const {


QString VScalar::propertyString() const {
return tr("%2 frame %3 of %1 = %4", "%2 is field name. %3 is frame/index. %1 is the file name. %4 is the value").arg(dataSource()->fileName()).arg(field()).arg(F0()).arg(value());
return tr("%2 frame %3 of %1 = %4",
"%2 is field name. %3 is frame/index. %1 is the file name. %4 is the value").arg(dataSource()->fileName()).arg(field()).arg(F0()).arg(value());
}

}
Expand Down
16 changes: 5 additions & 11 deletions src/libkst/vscalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Kst {
*/

/** A scalar which gets its value from a vector field in a data file. */
class KSTCORE_EXPORT VScalar : public Scalar {
class KSTCORE_EXPORT VScalar : public Scalar, public DataPrimitive {
Q_OBJECT

protected:
Expand Down Expand Up @@ -70,9 +70,6 @@ class KSTCORE_EXPORT VScalar : public Scalar {
/** Save scalar information */
virtual void save(QXmlStreamWriter &s);

/** the data source */
DataSourcePtr dataSource() const;

virtual QString descriptionTip() const;

/** return true if it has a valid file and field, or false otherwise */
Expand All @@ -82,18 +79,15 @@ class KSTCORE_EXPORT VScalar : public Scalar {

virtual ScriptInterface* createScriptInterface();

/** make a copy of the VScalar */
virtual PrimitivePtr makeDuplicate() const;
virtual bool checkValidity(const DataSourcePtr& ds) const;
private:
/** file to read for rvectors */
DataSourcePtr _file;

/** For the scalar field in the data source */
QString _field;
//QString _field;

int _f0;

/** make a copy of the VScalar */
virtual PrimitivePtr _makeDuplicate() const;
virtual bool _checkValidity(const DataSourcePtr ds) const;

};

Expand Down
8 changes: 7 additions & 1 deletion src/libkstapp/changefiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ void ChangeFileDialog::updatePrimitiveList() {
if (dp) {
primitives.append(P);
fileNameList.append(dp->filename());
}
} /*else {
VScalar *vs = qobject_cast<VScalar*>(P);
if (vs) {
primitives.append(P);
fileNameList.append(vs->filename());
}
} */
}

// make sure all items in _changeFilePrimitiveList exist in the store; remove if they don't.
Expand Down
7 changes: 6 additions & 1 deletion src/libkstapp/scalardialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ QString ScalarTab::field() const {


void ScalarTab::setField(const QString &field) {
_current_field = field;
_field->setCurrentIndex(_field->findText(field));
}

Expand All @@ -166,6 +167,7 @@ QString ScalarTab::fieldRV() const {


void ScalarTab::setFieldRV(const QString &field) {
_current_rvfield = field;
_fieldRV->setCurrentIndex(_fieldRV->findText(field));
}

Expand Down Expand Up @@ -198,8 +200,10 @@ void ScalarTab::sourceValid(QString filename, int requestID) {
_dataSource->readLock();

_field->addItems(_dataSource->scalar().list());
setField(_current_field);
_field->setEditable(!_dataSource->scalar().isListComplete());
_fieldRV->addItems(_dataSource->vector().list());
setFieldRV(_current_rvfield);
_fieldRV->setEditable(!_dataSource->vector().isListComplete());
_configure->setEnabled(_dataSource->hasConfigWidget());

Expand Down Expand Up @@ -417,7 +421,8 @@ ObjectPtr ScalarDialog::createNewVScalar() {

_dataObjectName = scalar->Name();

//UpdateServer::self()->requestUpdateSignal();
kstApp->mainWindow()->updateRecentDataFiles(dataSource->fileName());
//dialogDefaults().setValue("vector/datasource", dataSource->fileName());

return scalar;
}
Expand Down
2 changes: 2 additions & 0 deletions src/libkstapp/scalardialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class ScalarTab : public DataTab, Ui::ScalarTab {
ObjectStore *_store;
DataSourcePtr _dataSource;
int _requestID;
QString _current_field;
QString _current_rvfield;
};

class ScalarDialog : public DataDialog {
Expand Down
8 changes: 4 additions & 4 deletions src/libkstapp/scalartab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>631</width>
<height>341</height>
<width>629</width>
<height>339</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
Expand Down Expand Up @@ -209,7 +209,7 @@
</sizepolicy>
</property>
<property name="minimum">
<number>1</number>
<number>0</number>
</property>
<property name="maximum">
<number>1000000000</number>
Expand Down Expand Up @@ -285,7 +285,7 @@
</sizepolicy>
</property>
<property name="text">
<string>V&amp;alue: </string>
<string>Va&amp;lue: </string>
</property>
<property name="wordWrap">
<bool>false</bool>
Expand Down
5 changes: 4 additions & 1 deletion src/libkstapp/stringdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ StringTab::StringTab(ObjectStore *store, QWidget *parent)
connect(_stringValue, SIGNAL(textChanged(QString)), this, SLOT(textChanged()));
connect(_fileName, SIGNAL(changed(QString)), this, SLOT(fileNameChanged(QString)));
connect(_configure, SIGNAL(clicked()), this, SLOT(showConfigWidget()));
connect(_field, SIGNAL(currentIndexChanged(int)), this, SLOT(textChanged()));
}


Expand Down Expand Up @@ -135,6 +136,7 @@ QString StringTab::field() const {


void StringTab::setField(const QString &field) {
_current_field = field;
_field->setCurrentIndex(_field->findText(field));
}

Expand All @@ -161,9 +163,9 @@ void StringTab::sourceValid(QString filename, int requestID) {
_dataSource->readLock();

_field->addItems(_dataSource->string().list());
setField(_current_field);
_field->setEditable(!_dataSource->string().isListComplete());
_configure->setEnabled(_dataSource->hasConfigWidget());

_dataSource->unlock();

_store->cleanUpDataSourceList();
Expand Down Expand Up @@ -244,6 +246,7 @@ void StringDialog::configureTab(ObjectPtr object) {
void StringDialog::updateButtons() {
bool enable = !_stringTab->value().isEmpty()
|| !_stringTab->field().isEmpty();

_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
_buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enable);
}
Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/stringdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class StringTab : public DataTab, Ui::StringTab {
ObjectStore *_store;
DataSourcePtr _dataSource;
int _requestID;
QString _current_field;
};

class StringDialog : public DataDialog {
Expand Down