]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Try to read all ChemStation files instead of failing on the first
authorMichal Malý <madcatxster@devoid-pointer.net>
Fri, 11 Jul 2014 20:34:52 +0000 (22:34 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Fri, 11 Jul 2014 20:34:52 +0000 (22:34 +0200)
unreadable file. Inform the user which files failed to load and why.

Anyanka.pro
datafilesloader.cpp
datafilesloader.h
datamanager.cpp
gui/failedfilesdialog.cpp [new file with mode: 0644]
gui/failedfilesdialog.h [new file with mode: 0644]
gui/failedfilesdialog.ui [new file with mode: 0644]

index 74448cd917eff0fe081a3baf95cc1af67919657c..3c9ee5d3499b32c0eeb7951fcfc53316b55749c8 100644 (file)
@@ -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
index 0d1f1b8ae35869dbad46dfab6d30b8ed354e6b69..b907b9989b9dc66247e5930fc7bafabe102776e9 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "datafilesloader.h"
 #include "logger.h"
-#include <QtWidgets/QMessageBox>
+#include "gui/failedfilesdialog.h"
 #include <QDebug>
 
 const QString DataFilesLoader::ME_SENDER_STR("DataFilesLoader");
@@ -37,6 +37,7 @@ DataFilesLoader::DataFilesLoader(QObject *parent) :
 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();
@@ -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");
 
index 512f378dcacc813c7ab714597fa52e6e42b35fbf..19261a1e2656f3bff14e78a5a11c0ef0583f4126 100644 (file)
@@ -35,7 +35,6 @@ public:
   enum class ReturnCode {
     SUCCESS,
     E_NO_FILES,
-    E_READ_ERROR,
     E_FATAL
   };
 
index 4d45116cd5c44d582fc39a036a65efc32d76328d..4aa16184afc576cc5e9b54cdbe320668c3b5591b 100644 (file)
@@ -323,14 +323,14 @@ std::shared_ptr<SingleRunData> 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<SingleRunData> 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<SingleRunData> 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 (file)
index 0000000..9b01f28
--- /dev/null
@@ -0,0 +1,35 @@
+#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;
+}
diff --git a/gui/failedfilesdialog.h b/gui/failedfilesdialog.h
new file mode 100644 (file)
index 0000000..0e89848
--- /dev/null
@@ -0,0 +1,29 @@
+#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
diff --git a/gui/failedfilesdialog.ui b/gui/failedfilesdialog.ui
new file mode 100644 (file)
index 0000000..87a12c6
--- /dev/null
@@ -0,0 +1,118 @@
+<?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>