Skip to content
Snippets Groups Projects
Commit 94a4a429 authored by Yurov, Dmitry's avatar Yurov, Dmitry
Browse files

Made DataItem derived from SaveLoadInterface

Redmine: #2177
parent 5e8cf35f
Branches
Tags
No related merge requests found
...@@ -37,10 +37,9 @@ void DataItem::setRawDataVector(std::vector<double> data) ...@@ -37,10 +37,9 @@ void DataItem::setRawDataVector(std::vector<double> data)
emitDataChanged(); emitDataChanged();
} }
QString DataItem::fileName(const QString& projectDir) const QString DataItem::fileName() const
{ {
QString filename = getItemValue(DataItem::P_FILE_NAME).toString(); return getItemValue(DataItem::P_FILE_NAME).toString();
return projectDir.isEmpty() ? filename : projectDir + QStringLiteral("/") + filename;
} }
QDateTime DataItem::lastModified() const QDateTime DataItem::lastModified() const
...@@ -48,6 +47,33 @@ QDateTime DataItem::lastModified() const ...@@ -48,6 +47,33 @@ QDateTime DataItem::lastModified() const
return m_last_modified; return m_last_modified;
} }
bool DataItem::containsNonXMLData() const
{
return static_cast<bool>(m_data);
}
bool DataItem::load(const QString &projectDir)
{
QString filename = fileName(projectDir);
auto data = IntensityDataIOFactory::readOutputData(filename.toStdString());
if (!data)
return false;
setOutputData(data);
return true;
}
bool DataItem::save(const QString& projectDir)
{
if (!containsNonXMLData())
return false;
std::unique_lock<std::mutex> lock(m_update_data_mutex);
std::unique_ptr<OutputData<double>> clone(getOutputData()->clone());
lock.unlock();
IntensityDataIOFactory::writeOutputData(*clone, fileName(projectDir).toStdString());
return true;
}
void DataItem::setLastModified(const QDateTime& dtime) void DataItem::setLastModified(const QDateTime& dtime)
{ {
m_last_modified = dtime; m_last_modified = dtime;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#ifndef DATAITEM_H #ifndef DATAITEM_H
#define DATAITEM_H #define DATAITEM_H
#include "SaveLoadInterface.h"
#include "SessionItem.h" #include "SessionItem.h"
#include "OutputData.h" #include "OutputData.h"
#include <QDateTime> #include <QDateTime>
...@@ -24,7 +25,7 @@ class InstrumentItem; ...@@ -24,7 +25,7 @@ class InstrumentItem;
//! Provides common functionality for IntensityDataItem and SpecularDataItem //! Provides common functionality for IntensityDataItem and SpecularDataItem
class BA_CORE_API_ DataItem : public SessionItem class BA_CORE_API_ DataItem : public SessionItem, public SaveLoadInterface
{ {
public: public:
static const QString P_FILE_NAME; static const QString P_FILE_NAME;
...@@ -39,9 +40,13 @@ public: ...@@ -39,9 +40,13 @@ public:
//! no dimension checks are applied. //! no dimension checks are applied.
void setRawDataVector(std::vector<double> data); void setRawDataVector(std::vector<double> data);
QString fileName(const QString& projectDir = QString()) const; using SaveLoadInterface::fileName;
QString fileName() const override;
QDateTime lastModified() const override;
bool containsNonXMLData() const override;
bool load(const QString& projectDir) override;
bool save(const QString& projectDir) override;
QDateTime lastModified() const;
void setLastModified(const QDateTime& dtime); void setLastModified(const QDateTime& dtime);
QString selectedAxesUnits() const; QString selectedAxesUnits() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment