From: Michal MalĂ˝ Date: Fri, 11 Jul 2014 20:34:52 +0000 (+0200) Subject: Try to read all ChemStation files instead of failing on the first X-Git-Tag: 0.3a~8^2~1 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=0a3db3e75bd53069a0bf068aa20cabbab2d984c3;p=anyanka.git Try to read all ChemStation files instead of failing on the first unreadable file. Inform the user which files failed to load and why. --- diff --git a/Anyanka.pro b/Anyanka.pro index 74448cd..3c9ee5d 100644 --- a/Anyanka.pro +++ b/Anyanka.pro @@ -51,7 +51,8 @@ SOURCES += main.cpp\ imagedrawer.cpp \ signaldrawer.cpp \ jsonserializable.cpp \ - libHPCS/libhpcs.c + libHPCS/libhpcs.c \ + gui/failedfilesdialog.cpp HEADERS += \ datafilesloader.h \ @@ -86,14 +87,16 @@ HEADERS += \ enumflags.h \ jsonserializable.h \ helpers.h \ - libHPCS/libhpcs.h + libHPCS/libhpcs.h \ + gui/failedfilesdialog.h FORMS += \ gui/mainwindow.ui \ gui/signalview.ui \ gui/aboutanyanka.ui \ gui/exportrawdatadialog.ui \ - gui/exportgraphtoimagedialog.ui + gui/exportgraphtoimagedialog.ui \ + gui/failedfilesdialog.ui RESOURCES += \ imgresources.qrc diff --git a/datafilesloader.cpp b/datafilesloader.cpp index 0d1f1b8..b907b99 100644 --- a/datafilesloader.cpp +++ b/datafilesloader.cpp @@ -23,7 +23,7 @@ #include "datafilesloader.h" #include "logger.h" -#include +#include "gui/failedfilesdialog.h" #include const QString DataFilesLoader::ME_SENDER_STR("DataFilesLoader"); @@ -37,6 +37,7 @@ DataFilesLoader::DataFilesLoader(QObject *parent) : DataFilesLoader::ReturnCode DataFilesLoader::loadSingleRun(const QDir& path, std::vector& loadedData) { ReturnCode ret = ReturnCode::SUCCESS; + std::vector failedFiles; for (const QString& s : path.entryList(m_supportedFileTypes, QDir::Files | QDir::NoDotAndDotDot)) { struct HPCS_MeasuredData* mdata = hpcs_alloc(); @@ -54,21 +55,18 @@ DataFilesLoader::ReturnCode DataFilesLoader::loadSingleRun(const QDir& path, std else { QString errDesc = hpcs_error_to_string(iret); Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, "Error reading file '" + s + "'" + errDesc); - QMessageBox::warning(nullptr, "Error reading file '" + s + "'", errDesc); + failedFiles.push_back(CQStringPair(s, errDesc)); hpcs_free(mdata); - ret = ReturnCode::E_READ_ERROR; - break; } } - if (ret != ReturnCode::SUCCESS) { - for (struct HPCS_MeasuredData* md : loadedData) - hpcs_free(md); - } else { - if (loadedData.size() == 0) - return ReturnCode::E_NO_FILES; + if (failedFiles.size() > 0) { + Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, "Failed files count: " + QString::number(failedFiles.size())); + FailedFilesDialog::exec(failedFiles); } + if (loadedData.size() == 0) + return ReturnCode::E_NO_FILES; Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, QString::number(loadedData.size()) + " files were found and successfully parsed"); diff --git a/datafilesloader.h b/datafilesloader.h index 512f378..19261a1 100644 --- a/datafilesloader.h +++ b/datafilesloader.h @@ -35,7 +35,6 @@ public: enum class ReturnCode { SUCCESS, E_NO_FILES, - E_READ_ERROR, E_FATAL }; diff --git a/datamanager.cpp b/datamanager.cpp index 4d45116..4aa1618 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -323,14 +323,14 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) eqp = equipmentFromFiletype(md->file_type); } catch (std::invalid_argument& ia) { llog->log(Logger::ERROR, ME_SENDER_STR, ia.what()); - delete md; + hpcs_free(md); continue; } try { res = resourceFromFiletype(md->file_type); } catch (std::invalid_argument& ia) { llog->log(Logger::ERROR, ME_SENDER_STR, ia.what()); - delete md; + hpcs_free(md); continue; } @@ -338,7 +338,7 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) yu = yunitFromUnitStr(md->y_units); } catch (std::invalid_argument& ia) { llog->log(Logger::ERROR, ME_SENDER_STR, QString("Invalid units ") + ia.what()); - delete md; + hpcs_free(md); continue; } samplingRate = md->sampling_rate; @@ -372,6 +372,14 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) hpcs_free(md); } + /* We must have same number of signals and controllers */ + Q_ASSERT(sigs.size() == ctrls.size()); + /* Check that all we understood the loaded files */ + if (sigs.size() < 1) { + QMessageBox::warning(nullptr, "Error when loading datafiles", "Some datafiles were loaded but Anyanka does not know how to interpret them."); + return nullptr; + } + /* Check that all common run informaton are the same */ for (int i = 1; i < operatorNames.size(); i++) { if (QString::compare(operatorNames.at(i-1), operatorNames.at(i)) != 0) { diff --git a/gui/failedfilesdialog.cpp b/gui/failedfilesdialog.cpp new file mode 100644 index 0000000..9b01f28 --- /dev/null +++ b/gui/failedfilesdialog.cpp @@ -0,0 +1,35 @@ +#include "failedfilesdialog.h" +#include "ui_failedfilesdialog.h" +#include + +void FailedFilesDialog::exec(const std::vector& failedFiles) +{ + FailedFilesDialog dlg(failedFiles); + static_cast(&dlg)->exec(); +} + +FailedFilesDialog::FailedFilesDialog(const std::vector& failedFiles, QWidget* parent) : + QDialog(parent), + ui(new Ui::FailedFilesDialog) +{ + ui->setupUi(this); + + ui->qlIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(32, 32)); + for (const CQStringPair& p : failedFiles) { + QString s = p.first + " - " + p.second; + ui->qteFailedFiles->append(s); + } + this->setWindowTitle("Some files could not have been loaded"); + + connect(ui->qpbOk, SIGNAL(clicked()), this, SLOT(onOk())); +} + +void FailedFilesDialog::onOk() +{ + this->accept(); +} + +FailedFilesDialog::~FailedFilesDialog() +{ + delete ui; +} diff --git a/gui/failedfilesdialog.h b/gui/failedfilesdialog.h new file mode 100644 index 0000000..0e89848 --- /dev/null +++ b/gui/failedfilesdialog.h @@ -0,0 +1,29 @@ +#ifndef FAILEDFILESDIALOG_H +#define FAILEDFILESDIALOG_H + +#include + +typedef std::pair CQStringPair; + +namespace Ui { +class FailedFilesDialog; +} + +class FailedFilesDialog : public QDialog +{ + Q_OBJECT + +public: + static void exec(const std::vector& failedFiles); + + explicit FailedFilesDialog(const std::vector& failedFiles, QWidget* parent = nullptr); + ~FailedFilesDialog(); + +private: + Ui::FailedFilesDialog *ui; + +private slots: + void onOk(); +}; + +#endif // FAILEDFILESDIALOG_H diff --git a/gui/failedfilesdialog.ui b/gui/failedfilesdialog.ui new file mode 100644 index 0000000..87a12c6 --- /dev/null +++ b/gui/failedfilesdialog.ui @@ -0,0 +1,118 @@ + + + FailedFilesDialog + + + + 0 + 0 + 433 + 300 + + + + + 0 + 0 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + 128 + 128 + + + + + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + Following files could not have been loaded + + + false + + + qlIcon + + + + + + + + + true + + + false + + + true + + + false + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + + + +