Skip to content

Commit

Permalink
Merge f1ae1a5 into 569225d
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Nov 23, 2018
2 parents 569225d + f1ae1a5 commit 745a6ae
Show file tree
Hide file tree
Showing 21 changed files with 307 additions and 436 deletions.
Expand Up @@ -40,7 +40,7 @@
</message>
</context>
<context>
<name>OpenCOR::BioSignalMLDataStore::BiosignalmlDataStoreExporter</name>
<name>OpenCOR::BioSignalMLDataStore::BiosignalmlDataStoreExporterWorker</name>
<message>
<source>The data could not be exported to BioSignalML (%1).</source>
<translation>Les données n&apos;ont pas pu être exportées vers BioSignalML (%1).</translation>
Expand Down
Expand Up @@ -44,14 +44,14 @@ namespace BioSignalMLDataStore {

//==============================================================================

BiosignalmlDataStoreExporter::BiosignalmlDataStoreExporter(DataStore::DataStoreData *pDataStoreData) :
DataStore::DataStoreExporter(pDataStoreData)
BiosignalmlDataStoreExporterWorker::BiosignalmlDataStoreExporterWorker(DataStore::DataStoreData *pDataStoreData) :
DataStore::DataStoreExporterWorker(pDataStoreData)
{
}

//==============================================================================

void BiosignalmlDataStoreExporter::execute(QString &pErrorMessage) const
void BiosignalmlDataStoreExporterWorker::run()
{
// Determine the number of steps to export everything

Expand All @@ -69,6 +69,7 @@ void BiosignalmlDataStoreExporter::execute(QString &pErrorMessage) const
// Export the given data store to a BioSignalML file

bsml::HDF5::Recording *recording = nullptr;
QString errorMessage = QString();

try {
// Create and populate a recording
Expand Down Expand Up @@ -161,7 +162,7 @@ void BiosignalmlDataStoreExporter::execute(QString &pErrorMessage) const
// Something went wrong, so retrieve the error message and delete our
// BioSignalML file

pErrorMessage = tr("The data could not be exported to BioSignalML (%1).").arg(exception.what());
errorMessage = tr("The data could not be exported to BioSignalML (%1).").arg(exception.what());

QFile::remove(dataStoreData->fileName());
}
Expand All @@ -173,6 +174,19 @@ void BiosignalmlDataStoreExporter::execute(QString &pErrorMessage) const

delete recording;
}

// Let people know that our XSL transformation has been performed

emit done(errorMessage);
}

//==============================================================================

DataStore::DataStoreExporterWorker * BiosignalmlDataStoreExporter::workerInstance(DataStore::DataStoreData *pDataStoreData)
{
// Return an instance of our worker

return new BiosignalmlDataStoreExporterWorker(pDataStoreData);
}

//==============================================================================
Expand Down
Expand Up @@ -34,14 +34,25 @@ namespace BioSignalMLDataStore {

//==============================================================================

class BiosignalmlDataStoreExporter : public DataStore::DataStoreExporter
class BiosignalmlDataStoreExporterWorker : public DataStore::DataStoreExporterWorker
{
Q_OBJECT

public:
explicit BiosignalmlDataStoreExporter(DataStore::DataStoreData *pDataStoreData);
explicit BiosignalmlDataStoreExporterWorker(DataStore::DataStoreData *pDataStoreData);

public slots:
void run() override;
};

//==============================================================================

class BiosignalmlDataStoreExporter : public DataStore::DataStoreExporter
{
Q_OBJECT

void execute(QString &pErrorMessage) const override;
protected:
DataStore::DataStoreExporterWorker * workerInstance(DataStore::DataStoreData *pDataStoreData) override;
};

//==============================================================================
Expand Down
Expand Up @@ -100,11 +100,14 @@ DataStore::DataStoreData * BioSignalMLDataStorePlugin::getData(const QString &pF

//==============================================================================

DataStore::DataStoreExporter * BioSignalMLDataStorePlugin::dataStoreExporterInstance(DataStore::DataStoreData *pDataStoreData) const
DataStore::DataStoreExporter * BioSignalMLDataStorePlugin::dataStoreExporterInstance() const
{
// Return an instance of our BioSignalML data store exporter
// Return the 'global' instance of our BioSignalML data store exporter

return new BiosignalmlDataStoreExporter(pDataStoreData);
static BiosignalmlDataStoreExporter instance;

return static_cast<BiosignalmlDataStoreExporter *>(Core::globalInstance("OpenCOR::BioSignalMLDataStore::BiosignalmlDataStoreExporter::instance()",
&instance));
}

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dataStore/CSVDataStore/i18n/CSVDataStore_fr.ts
Expand Up @@ -17,7 +17,7 @@
</message>
</context>
<context>
<name>OpenCOR::CSVDataStore::CsvDataStoreExporter</name>
<name>OpenCOR::CSVDataStore::CsvDataStoreExporterWorker</name>
<message>
<source>The data could not be exported to CSV.</source>
<translation>Les données n&apos;ont pas pu être exportées vers CSV.</translation>
Expand Down
24 changes: 19 additions & 5 deletions src/plugins/dataStore/CSVDataStore/src/csvdatastoreexporter.cpp
Expand Up @@ -36,14 +36,14 @@ namespace CSVDataStore {

//==============================================================================

CsvDataStoreExporter::CsvDataStoreExporter(DataStore::DataStoreData *pDataStoreData) :
DataStore::DataStoreExporter(pDataStoreData)
CsvDataStoreExporterWorker::CsvDataStoreExporterWorker(DataStore::DataStoreData *pDataStoreData) :
DataStore::DataStoreExporterWorker(pDataStoreData)
{
}

//==============================================================================

void CsvDataStoreExporter::execute(QString &pErrorMessage) const
void CsvDataStoreExporterWorker::run()
{
// Do the export itself
// Note: we would normally rely on a string to which we would append our
Expand All @@ -55,6 +55,7 @@ void CsvDataStoreExporter::execute(QString &pErrorMessage) const
// first write our header and then our data, one row at a time...

QFile file(Core::temporaryFileName());
QString errorMessage = QString();

if (file.open(QIODevice::WriteOnly)) {
// Determine whether we need to export the VOI and, if so, remove it
Expand Down Expand Up @@ -218,11 +219,24 @@ void CsvDataStoreExporter::execute(QString &pErrorMessage) const
if (!res) {
file.remove();

pErrorMessage = tr("The data could not be exported to CSV.");
errorMessage = tr("The data could not be exported to CSV.");
}
} else {
pErrorMessage = tr("The CSV file could not be created.");
errorMessage = tr("The CSV file could not be created.");
}

// Let people know that our XSL transformation has been performed

emit done(errorMessage);
}

//==============================================================================

DataStore::DataStoreExporterWorker * CsvDataStoreExporter::workerInstance(DataStore::DataStoreData *pDataStoreData)
{
// Return an instance of our worker

return new CsvDataStoreExporterWorker(pDataStoreData);
}

//==============================================================================
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/dataStore/CSVDataStore/src/csvdatastoreexporter.h
Expand Up @@ -34,14 +34,25 @@ namespace CSVDataStore {

//==============================================================================

class CsvDataStoreExporter : public DataStore::DataStoreExporter
class CsvDataStoreExporterWorker : public DataStore::DataStoreExporterWorker
{
Q_OBJECT

public:
explicit CsvDataStoreExporter(DataStore::DataStoreData *pDataStoreData);
explicit CsvDataStoreExporterWorker(DataStore::DataStoreData *pDataStoreData);

public slots:
void run() override;
};

//==============================================================================

class CsvDataStoreExporter : public DataStore::DataStoreExporter
{
Q_OBJECT

void execute(QString &pErrorMessage) const override;
protected:
DataStore::DataStoreExporterWorker * workerInstance(DataStore::DataStoreData *pDataStoreData) override;
};

//==============================================================================
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/dataStore/CSVDataStore/src/csvdatastoreplugin.cpp
Expand Up @@ -96,11 +96,14 @@ DataStore::DataStoreData * CSVDataStorePlugin::getData(const QString &pFileName,

//==============================================================================

DataStore::DataStoreExporter * CSVDataStorePlugin::dataStoreExporterInstance(DataStore::DataStoreData *pDataStoreData) const
DataStore::DataStoreExporter * CSVDataStorePlugin::dataStoreExporterInstance() const
{
// Return an instance of our CSV data store exporter
// Return the 'global' instance of our CSV data store exporter

return new CsvDataStoreExporter(pDataStoreData);
static CsvDataStoreExporter instance;

return static_cast<CsvDataStoreExporter *>(Core::globalInstance("OpenCOR::CSVDataStore::CsvDataStoreExporter::instance()",
&instance));
}

//==============================================================================
Expand Down
65 changes: 24 additions & 41 deletions src/plugins/datastoreinterface.cpp
Expand Up @@ -42,7 +42,7 @@ extern "C" Q_DECL_EXPORT int dataStoreInterfaceVersion()
{
// Version of the data store interface

return 3;
return 4;
}

//==============================================================================
Expand Down Expand Up @@ -551,61 +551,44 @@ void DataStore::addValues(double pVoiValue)

//==============================================================================

DataStoreExporter::DataStoreExporter(DataStoreData *pDataStoreData) :
DataStoreExporterWorker::DataStoreExporterWorker(DataStoreData *pDataStoreData) :
mDataStoreData(pDataStoreData)
{
// Create our thread

mThread = new QThread();

// Move ourselves to our thread

moveToThread(mThread);

// Create a few connections

connect(mThread, &QThread::started,
this, &DataStoreExporter::started);

connect(mThread, &QThread::finished,
mThread, &QThread::deleteLater);
connect(mThread, &QThread::finished,
this, &DataStoreExporter::deleteLater);
}

//==============================================================================

DataStoreExporter::~DataStoreExporter()
void DataStoreExporter::exportData(DataStoreData *pDataStoreData)
{
// Delete some internal objects
// Note: no need to delete mDataStore since it will be automatically
// deleted through our threaded mechanism...
// Create and move our worker to a thread
// Note: we cannot use the new connect() syntax with our worker's signals
// since it's an instance of a derived class located in another
// plugin...

delete mDataStoreData;
}
QThread *thread = new QThread();
DataStoreExporterWorker *worker = workerInstance(pDataStoreData);

//==============================================================================

void DataStoreExporter::start()
{
// Start the export
worker->moveToThread(thread);

mThread->start();
}
connect(thread, &QThread::started,
worker, &DataStoreExporterWorker::run);

//==============================================================================

void DataStoreExporter::started()
{
// Do the export itself
connect(worker, SIGNAL(progress(double)),
this, SIGNAL(progress(double)));

QString errorMessage = QString();
connect(worker, SIGNAL(done(const QString &)),
this, SIGNAL(done(const QString &)));
connect(worker, SIGNAL(done(const QString &)),
thread, SLOT(quit()));
connect(worker, SIGNAL(done(const QString &)),
worker, SLOT(deleteLater()));

execute(errorMessage);
connect(thread, &QThread::finished,
thread, &QThread::deleteLater);

// Let people know that we are done with the export
// Start our worker by starting the thread in which it is

emit done(errorMessage);
thread->start();
}

//==============================================================================
Expand Down

0 comments on commit 745a6ae

Please sign in to comment.