unreadable file. Inform the user which files failed to load and why.
imagedrawer.cpp \
signaldrawer.cpp \
jsonserializable.cpp \
- libHPCS/libhpcs.c
+ libHPCS/libhpcs.c \
+ gui/failedfilesdialog.cpp
HEADERS += \
datafilesloader.h \
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
#include "datafilesloader.h"
#include "logger.h"
-#include <QtWidgets/QMessageBox>
+#include "gui/failedfilesdialog.h"
#include <QDebug>
const QString DataFilesLoader::ME_SENDER_STR("DataFilesLoader");
DataFilesLoader::ReturnCode DataFilesLoader::loadSingleRun(const QDir& path, std::vector<struct HPCS_MeasuredData*>& loadedData)
{
ReturnCode ret = ReturnCode::SUCCESS;
+ std::vector<CQStringPair> failedFiles;
for (const QString& s : path.entryList(m_supportedFileTypes, QDir::Files | QDir::NoDotAndDotDot)) {
struct HPCS_MeasuredData* mdata = hpcs_alloc();
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");
enum class ReturnCode {
SUCCESS,
E_NO_FILES,
- E_READ_ERROR,
E_FATAL
};
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;
}
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;
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) {
--- /dev/null
+#include "failedfilesdialog.h"
+#include "ui_failedfilesdialog.h"
+#include <QIcon>
+
+void FailedFilesDialog::exec(const std::vector<CQStringPair>& failedFiles)
+{
+ FailedFilesDialog dlg(failedFiles);
+ static_cast<QDialog*>(&dlg)->exec();
+}
+
+FailedFilesDialog::FailedFilesDialog(const std::vector<CQStringPair>& 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;
+}
--- /dev/null
+#ifndef FAILEDFILESDIALOG_H
+#define FAILEDFILESDIALOG_H
+
+#include <QDialog>
+
+typedef std::pair<const QString, const QString> CQStringPair;
+
+namespace Ui {
+class FailedFilesDialog;
+}
+
+class FailedFilesDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ static void exec(const std::vector<CQStringPair>& failedFiles);
+
+ explicit FailedFilesDialog(const std::vector<CQStringPair>& failedFiles, QWidget* parent = nullptr);
+ ~FailedFilesDialog();
+
+private:
+ Ui::FailedFilesDialog *ui;
+
+private slots:
+ void onOk();
+};
+
+#endif // FAILEDFILESDIALOG_H
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FailedFilesDialog</class>
+ <widget class="QDialog" name="FailedFilesDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>433</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="qlIcon">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>32</width>
+ <height>32</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>128</width>
+ <height>128</height>
+ </size>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="qlCaption">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="text">
+ <string>Following files could not have been loaded</string>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
+ </property>
+ <property name="buddy">
+ <cstring>qlIcon</cstring>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="qteFailedFiles">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="qpbOk">
+ <property name="text">
+ <string>OK</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>