DataWriterBackend* backend;
if (formatIdx < 0 || formatIdx >= SUPPORTED_FORMATS.length()) {
- QMessageBox::warning(nullptr, "Data export error", "Invalid format selected");
- return ReturnCode::E_TRYAGAIN;
+ return ReturnCode::E_INVAL_FORMAT;
}
if (path.compare("") == 0) {
- QMessageBox::information(nullptr, "Data export error", "No output file specified.");
- return ReturnCode::E_TRYAGAIN;
+ return ReturnCode::E_NO_OUTPUT;
}
if (dir.exists()) {
- QMessageBox::information(nullptr, "Data export error", "Selected path points to a directory. Name of output file is required.");
- return ReturnCode::E_TRYAGAIN;
+ return ReturnCode::E_IS_DIRECTORY;
}
if (file.exists()) {
int ret = QMessageBox::question(nullptr, "Data export", "The selected file already exists. Do you wish to overwrite it?");
if (ret == QMessageBox::No)
- return ReturnCode::E_TRYAGAIN;
+ return ReturnCode::E_WOULD_OVERWRITE;
else
file.remove();
}
return ret;
}
- //for (int idx = 1; idx < header.size(); idx++) {
WriteList::const_iterator cit = list.cbegin();
std::advance(cit, 1);
for (; cit != list.cend(); cit++) {
const char DataManager::UNIT_MILLIVOLTS_TEXT[] = {0x6D, 0x56, 0x00};
const char DataManager::UNIT_WATTS_TEXT[] = {0x57, 0x00};
const QStringList DataManager::DATA_DIR_SUFFIX = QStringList() << "*.D";
+const QString DataManager::S_RES_DATAEXPORT("Error while exporting data to file");
+const QString DataManager::S_RES_IMGEXPORT("Error while exporting graph to image");
DataManager::DataManager(QObject* parent) :
QObject(parent),
DataFileExporter exporter(this);
ExportRawDataDialog dlg(DataFileExporter::SUPPORTED_FORMATS);
DataFileExporter::WriteList writeList;
- DataFileExporter::ReturnCode ret;
std::shared_ptr<SingleRunData> sr = m_activeSequence->selectedRun();
+ int ret = 1;
for (const std::string& s : sr->allKeys())
dlg.addAvailableSignal(QString::fromStdString(s));
do {
int dret = dlg.exec();
if (dret == QDialog::Rejected)
- return;
+ ret = 0;
else if (dret == QDialog::Accepted && !dlg.isSignalSelected()) {
- QMessageBox::information(nullptr, "Data export error", "No signals selected");
- ret = DataFileExporter::ReturnCode::E_TRYAGAIN;
+ QMessageBox::information(nullptr, S_RES_DATAEXPORT, "No signals selected");
} else if (dret == QDialog::Accepted && dlg.isSignalSelected()) {
std::vector<std::string> selKeys = dlg.selectedSignalKeys();
+ DataFileExporter::ReturnCode exRet;
/* Generate data to export */
genfunc(writeList, sr, selKeys);
- ret = exporter.exportData(writeList, dlg.destination(), dlg.format());
+
+ exRet = exporter.exportData(writeList, dlg.destination(), dlg.format());
+ switch (exRet) {
+ case DataFileExporter::ReturnCode::SUCCESS:
+ ret = 0;
+ break;
+ case DataFileExporter::ReturnCode::E_FAILED:
+ QMessageBox::critical(nullptr, S_RES_DATAEXPORT, "Data could not have been exported to file.");
+ break;
+ case DataFileExporter::ReturnCode::E_INVAL_FORMAT:
+ QMessageBox::warning(nullptr, "Data export error", "Invalid format selected");
+ break;
+ case DataFileExporter::ReturnCode::E_IS_DIRECTORY:
+ QMessageBox::information(nullptr, "Data export error", "Selected path points to a directory. Name of output file is required.");
+ break;
+ case DataFileExporter::ReturnCode::E_NO_OUTPUT:
+ QMessageBox::information(nullptr, "Data export error", "No output file specified.");
+ break;
+ default:
+ break;
+ }
}
- } while (ret == DataFileExporter::ReturnCode::E_TRYAGAIN);
+ } while (ret == 1);
}
Signal::Resource DataManager::resourceFromFiletype(AGRE_Filetype filetype)
{
ExportGraphToImageDialog dlg(ImageDrawer::supportedImageFormats());
std::shared_ptr<SingleRunData> sr;
+ int ret = 1;
if (m_activeSequence == nullptr)
return;
dlg.addSignal(p.second->fromXAbs(), p.second->fromYAbs(), p.second->toXAbs(), p.second->toYAbs(), p.first);
}
- if (dlg.exec() == QDialog::Accepted) {
- const std::string key = dlg.selectedSignal().toStdString();
- std::shared_ptr<SignalController> ctrl = sr->controllerAt(key);
- GraphLayers gl = GraphLayers::GRAPH | GraphLayers::SCALE;
-
- if (ctrl == nullptr) {
- Logger::log(Logger::Level::CRITICAL, ME_SENDER_STR, "Invalid key " + QString::fromStdString(key) + " passed to image exporter");
- return;
- }
-
- if (dlg.path().length() == 0) {
- QMessageBox::warning(nullptr, "Error while exporting to image", "Invalid path");
- return;
- }
-
- /*if (data == nullptr) {
- QMessageBox::warning(nullptr, "Error while exporting to image", "Cannot generate data to draw. Some values are probably invalid.");
- return;
- }*/
-
- if (dlg.includePeaks())
- gl |= GraphLayers::INTEGRATION;
-
- ImageDrawer imageDrawer(ctrl);
- if (!imageDrawer.render(dlg.path() + "." + dlg.imageFormat(), dlg.imageFormat().toLatin1(), dlg.imageWidth(), dlg.imageHeight(), gl))
- QMessageBox::critical(nullptr, "Error while exporting to image", "Image could not have been written.");
-
- }
+ do {
+ if (dlg.exec() == QDialog::Accepted) {
+ const std::string key = dlg.selectedSignal().toStdString();
+ std::shared_ptr<SignalController> ctrl = sr->controllerAt(key);
+ GraphLayers gl = GraphLayers::GRAPH | GraphLayers::SCALE;
+ ImageDrawer::ReturnCode drwRet;
+
+ if (ctrl == nullptr) {
+ Logger::log(Logger::Level::CRITICAL, ME_SENDER_STR, "Invalid key " + QString::fromStdString(key) + " passed to image exporter");
+ continue;
+ }
+
+ if (dlg.path().length() == 0) {
+ QMessageBox::warning(nullptr, "Error while exporting to image", "Invalid path");
+ continue;
+ }
+
+ if (dlg.includePeaks())
+ gl |= GraphLayers::INTEGRATION;
+
+ ImageDrawer imageDrawer(ctrl);
+ drwRet = imageDrawer.render(dlg.path() + "." + dlg.imageFormat(), dlg.imageFormat().toLatin1(), dlg.imageWidth(), dlg.imageHeight(), gl);
+ switch (drwRet) {
+ case ImageDrawer::ReturnCode::SUCCESS:
+ ret = 0;
+ break;
+ case ImageDrawer::ReturnCode::E_INVAL_DIMENSIONS:
+ QMessageBox::critical(nullptr, S_RES_IMGEXPORT, "Image width or height is invalid.");
+ break;
+ case ImageDrawer::ReturnCode::E_CANNOT_DRAW:
+ QMessageBox::critical(nullptr, S_RES_IMGEXPORT, "Graph could not have been drawn.");
+ break;
+ case ImageDrawer::ReturnCode::E_CANNOT_WRITE_IMAGE:
+ QMessageBox::critical(nullptr, S_RES_IMGEXPORT, "Cannot write image to disk.");
+ break;
+ default:
+ break;
+ }
+ } else
+ break;
+ } while (ret == 1);
}
void DataManager::onExportPeaks()
#include "imagedrawer.h"
+#include <QtCore/QFile>
+#include <QtWidgets/QMessageBox>
#include <QDebug>
ImageDrawer::ImageDrawer(std::shared_ptr<SignalController> controller) :
m_imageWriter.setCompression(0);
}
-bool ImageDrawer::render(const QString& filename, const QByteArray format, const int width, const int height, const GraphLayers layers)
+ImageDrawer::ReturnCode ImageDrawer::render(const QString& filename, const QByteArray format, const int width, const int height, const GraphLayers layers)
{
QImage image;
+ QFile file(filename);
- setDimensions(width, height);
+ if (!setDimensions(width, height))
+ return ReturnCode::E_INVAL_DIMENSIONS;
if (!draw(SignalController::RELATIVE_MIN, SignalController::RELATIVE_MIN, SignalController::RELATIVE_MAX, SignalController::RELATIVE_MAX, layers))
- return false;
+ return ReturnCode::E_CANNOT_DRAW;
m_imageWriter.setFileName(filename);
m_imageWriter.setFormat(format);
image = m_pixmap->toImage();
+ if (image.isNull())
+ return ReturnCode::E_CANNOT_CREATE_IMAGE;
- return m_imageWriter.write(image);
+ if (file.exists()) {
+ int ret = QMessageBox::question(nullptr, "Data export", "The selected file already exists. Do you wish to overwrite it?");
+ if (ret == QMessageBox::No)
+ return ReturnCode::E_WOULD_OVERWRITE;
+ else
+ file.remove();
+ }
+
+ if (!m_imageWriter.write(image))
+ return ReturnCode::E_CANNOT_WRITE_IMAGE;
+
+ return ReturnCode::SUCCESS;
}
QList<QByteArray> ImageDrawer::supportedImageFormats()