Commit 57454346 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

show import errors which are not related to a particular line

parent 19939b4f
Pipeline #33412 passed with stage
in 26 minutes and 37 seconds
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "Device/InputOutput/DataFormatUtils.h" #include "Device/InputOutput/DataFormatUtils.h"
#include <map> #include <map>
// #migration +++ this works only if separator is space or tab; it does not // #bamigration +++ this works only if separator is space or tab; it does not
// work e.g. with comma or semicolon // work e.g. with comma or semicolon
OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fin) OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fin)
{ {
...@@ -34,11 +34,11 @@ OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fi ...@@ -34,11 +34,11 @@ OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fi
while (std::getline(fin, line)) { while (std::getline(fin, line)) {
line = StringUtils::trim(line); line = StringUtils::trim(line);
try { try {
// #migration +++ this works only if separator is space or tab; it does not // #bamigration +++ this works only if separator is space or tab; it does not
// work e.g. with comma or semicolon // work e.g. with comma or semicolon
std::vector<double> rowVec = DataFormatUtils::parse_doubles(line); std::vector<double> rowVec = DataFormatUtils::parse_doubles(line);
vecVec.push_back(rowVec); vecVec.push_back(rowVec);
} catch (...) { // #migration +++ This eats useful errors away... } catch (...) { // #bamigration +++ This eats useful errors away...
continue; continue;
} }
} }
...@@ -46,10 +46,10 @@ OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fi ...@@ -46,10 +46,10 @@ OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fi
// validate - There is at least one row and at least two columns // validate - There is at least one row and at least two columns
size_t nrows = vecVec.size(); size_t nrows = vecVec.size();
if (nrows < 1) if (nrows < 1)
throw std::runtime_error("Import1dTextData: no numerical values found"); throw std::runtime_error("No numerical values found");
size_t ncols = vecVec[0].size(); size_t ncols = vecVec[0].size();
if (ncols < 2) if (ncols < 2)
throw std::runtime_error("Import1dTextData: Minimum 2 columns required"); throw std::runtime_error("Minimum 2 columns required");
// Assign Q vs R, dR, dQ: // Assign Q vs R, dR, dQ:
for (size_t row = 0; row < nrows; row++) { for (size_t row = 0; row < nrows; row++) {
......
...@@ -42,6 +42,16 @@ int AbstractDataLoader::numErrors() const ...@@ -42,6 +42,16 @@ int AbstractDataLoader::numErrors() const
return 0; return 0;
} }
int AbstractDataLoader::numLineRelatedErrors() const
{
return 0;
}
QStringList AbstractDataLoader::lineUnrelatedErrors() const
{
return {};
}
AbstractDataLoaderResultModel* AbstractDataLoader::createResultModel() const AbstractDataLoaderResultModel* AbstractDataLoader::createResultModel() const
{ {
return nullptr; return nullptr;
......
...@@ -95,6 +95,13 @@ public: ...@@ -95,6 +95,13 @@ public:
//! content can't be used (e.g. only 1 line present). //! content can't be used (e.g. only 1 line present).
virtual int numErrors() const; virtual int numErrors() const;
//! Number of errors related to a specific line. Such an error means that a particular
//! content (line) can't be used or may be suspicious.
virtual int numLineRelatedErrors() const;
//! Errors not related to a particular line.
virtual QStringList lineUnrelatedErrors() const;
//! Create a table model which contains the import information like original file content, raw //! Create a table model which contains the import information like original file content, raw
//! content, processed content //! content, processed content
//! The returned pointer will be owned by the caller. //! The returned pointer will be owned by the caller.
......
...@@ -115,3 +115,11 @@ int AutomaticDataLoader1D::numErrors() const ...@@ -115,3 +115,11 @@ int AutomaticDataLoader1D::numErrors() const
{ {
return m_error.isEmpty() ? 0 : 1; return m_error.isEmpty() ? 0 : 1;
} }
QStringList AutomaticDataLoader1D::lineUnrelatedErrors() const
{
if (!m_error.isEmpty())
return {m_error};
return {};
}
...@@ -31,6 +31,7 @@ public: ...@@ -31,6 +31,7 @@ public:
virtual void processContents() override; virtual void processContents() override;
virtual AbstractDataLoaderResultModel* createResultModel() const override; virtual AbstractDataLoaderResultModel* createResultModel() const override;
virtual int numErrors() const override; virtual int numErrors() const override;
virtual QStringList lineUnrelatedErrors() const override;
private: private:
QByteArray m_fileContent; QByteArray m_fileContent;
......
...@@ -169,7 +169,7 @@ QByteArray QREDataLoader::serialize() const ...@@ -169,7 +169,7 @@ QByteArray QREDataLoader::serialize() const
s << m_importResult.validCalculatedLines; s << m_importResult.validCalculatedLines;
s << m_importResult.maxColumnCount; s << m_importResult.maxColumnCount;
s << m_importResult.calculationErrors; s << m_importResult.calculationErrors;
s << m_importResult.errors; s << m_importResult.error;
s << m_importResult.importSettings; s << m_importResult.importSettings;
return a; return a;
...@@ -201,7 +201,7 @@ void QREDataLoader::deserialize(const QByteArray& data) ...@@ -201,7 +201,7 @@ void QREDataLoader::deserialize(const QByteArray& data)
s >> m_importResult.validCalculatedLines; s >> m_importResult.validCalculatedLines;
s >> m_importResult.maxColumnCount; s >> m_importResult.maxColumnCount;
s >> m_importResult.calculationErrors; s >> m_importResult.calculationErrors;
s >> m_importResult.errors; s >> m_importResult.error;
s >> m_importResult.importSettings; s >> m_importResult.importSettings;
} else } else
throw DeserializationException::tooNew(); throw DeserializationException::tooNew();
...@@ -224,8 +224,7 @@ void QREDataLoader::processContents() ...@@ -224,8 +224,7 @@ void QREDataLoader::processContents()
// Important: If the current options match the ones in m_parsingResult, then nothing should be // Important: If the current options match the ones in m_parsingResult, then nothing should be
// performed. Otherwise e.g. a linked instrument may have to be re-linked // performed. Otherwise e.g. a linked instrument may have to be re-linked
// #baimport o check for binary etc. and return error m_importResult.error.clear();
m_importResult.errors.clear();
ASSERT(m_item != nullptr); ASSERT(m_item != nullptr);
ASSERT(m_item->isSpecularData()); ASSERT(m_item->isSpecularData());
...@@ -255,9 +254,9 @@ void QREDataLoader::processContents() ...@@ -255,9 +254,9 @@ void QREDataLoader::processContents()
// -- make a few checks (mainly for fulfilling PointwiseAxis::sanityCheck()) // -- make a few checks (mainly for fulfilling PointwiseAxis::sanityCheck())
if (m_importResult.validCalculatedLines < 2) if (m_importResult.validCalculatedLines < 2)
m_importResult.errors << "At least two full rows must exist"; m_importResult.error = "At least two full rows must exist";
if (!m_importResult.errors.isEmpty()) { if (!m_importResult.error.isEmpty()) {
invalidateItemData(); invalidateItemData();
return; return;
} }
...@@ -267,7 +266,7 @@ void QREDataLoader::processContents() ...@@ -267,7 +266,7 @@ void QREDataLoader::processContents()
try { try {
createOutputDataFromParsingResult(m_item); createOutputDataFromParsingResult(m_item);
} catch (...) { } catch (...) {
m_importResult.errors << "Import not successful - caught an exception."; m_importResult.error = "Import not successful - caught an exception.";
invalidateItemData(); invalidateItemData();
} }
} }
...@@ -275,7 +274,20 @@ void QREDataLoader::processContents() ...@@ -275,7 +274,20 @@ void QREDataLoader::processContents()
int QREDataLoader::numErrors() const int QREDataLoader::numErrors() const
{ {
return m_importResult.errors.size() + m_importResult.calculationErrors.size(); return (m_importResult.error.isEmpty() ? 0 : 1) + m_importResult.calculationErrors.size();
}
int QREDataLoader::numLineRelatedErrors() const
{
return m_importResult.calculationErrors.size();
}
QStringList QREDataLoader::lineUnrelatedErrors() const
{
if (!m_importResult.error.isEmpty())
return {m_importResult.error};
return {};
} }
AbstractDataLoaderResultModel* QREDataLoader::createResultModel() const AbstractDataLoaderResultModel* QREDataLoader::createResultModel() const
...@@ -617,7 +629,7 @@ void QREDataLoader::ImportResult::clear() ...@@ -617,7 +629,7 @@ void QREDataLoader::ImportResult::clear()
validCalculatedLines = 0; validCalculatedLines = 0;
maxColumnCount = 0; maxColumnCount = 0;
calculationErrors.clear(); calculationErrors.clear();
errors.clear(); error.clear();
importSettings.columnDefinitions.clear(); // sufficient importSettings.columnDefinitions.clear(); // sufficient
} }
......
...@@ -40,6 +40,8 @@ public: ...@@ -40,6 +40,8 @@ public:
virtual void guessSettings() override; virtual void guessSettings() override;
virtual void processContents() override; virtual void processContents() override;
virtual int numErrors() const override; virtual int numErrors() const override;
virtual int numLineRelatedErrors() const override;
virtual QStringList lineUnrelatedErrors() const override;
virtual AbstractDataLoaderResultModel* createResultModel() const override; virtual AbstractDataLoaderResultModel* createResultModel() const override;
private: private:
...@@ -112,7 +114,7 @@ private: ...@@ -112,7 +114,7 @@ private:
int maxColumnCount; //!< max found columns in raw data int maxColumnCount; //!< max found columns in raw data
QMap<int, ErrorDefinition> QMap<int, ErrorDefinition>
calculationErrors; //!< calculation error per line; line is 0-based calculationErrors; //!< calculation error per line; line is 0-based
QStringList errors; //!< errors unrelated to lines QString error; //!< error unrelated to lines
ImportSettings importSettings; //!< Settings used for the import ImportSettings importSettings; //!< Settings used for the import
}; };
mutable ImportResult m_importResult; mutable ImportResult m_importResult;
......
...@@ -36,6 +36,7 @@ public: ...@@ -36,6 +36,7 @@ public:
virtual void guessSettings() override; virtual void guessSettings() override;
virtual void processContents() override; virtual void processContents() override;
// #baUserDefLoaders ++ implement all overloads!
private: private:
QString m_name; QString m_name;
AbstractDataLoader1D* m_wrappedLoader; AbstractDataLoader1D* m_wrappedLoader;
......
...@@ -262,8 +262,12 @@ QVariant RealDataTreeModel::data(const QModelIndex& index, int role) const ...@@ -262,8 +262,12 @@ QVariant RealDataTreeModel::data(const QModelIndex& index, int role) const
const auto numErrors = const auto numErrors =
(item->dataLoader() != nullptr) ? item->dataLoader()->numErrors() : 0; (item->dataLoader() != nullptr) ? item->dataLoader()->numErrors() : 0;
return numErrors == 0 ? item->name() if (numErrors == 0)
: item->name() + QString(" (%1 parser warnings)").arg(numErrors); return item->name();
else if (numErrors == 1)
return item->name() + " (1 parser warning)";
else
return item->name() + QString(" (%1 parser warnings)").arg(numErrors);
} }
if (role == Qt::EditRole) if (role == Qt::EditRole)
......
...@@ -40,6 +40,9 @@ SpecularDataImportWidget::SpecularDataImportWidget(QWidget* parent) ...@@ -40,6 +40,9 @@ SpecularDataImportWidget::SpecularDataImportWidget(QWidget* parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->warningsIcon->setFixedSize(20, 20);
m_ui->warningsIcon->setPixmap(QPixmap(":/images/warning_16x16.png"));
m_ui->linkedInstrumentGroup->hide(); // #baimport - remove from UI if not used in the future m_ui->linkedInstrumentGroup->hide(); // #baimport - remove from UI if not used in the future
// #baUserDefLoaders - remove next line when implementation is complete // #baUserDefLoaders - remove next line when implementation is complete
...@@ -292,6 +295,38 @@ void SpecularDataImportWidget::updatePreview() ...@@ -292,6 +295,38 @@ void SpecularDataImportWidget::updatePreview()
delete oldModel; delete oldModel;
} }
if (m_loader && m_loader->numErrors() > 0) {
m_ui->warningsIcon->show();
m_ui->warningsLabel->show();
m_ui->warningsListWidget->show();
m_ui->warningsListWidget->clear();
auto warnings = m_loader->lineUnrelatedErrors();
const int nLineRelatedWarnings = m_loader->numErrors() - warnings.size();
if (nLineRelatedWarnings == 1)
warnings << "1 line related warning. Please check the data tab on the right for more "
"information.";
else if (nLineRelatedWarnings > 1)
warnings
<< QString(
"%1 line related warnings. Please check the data tab on the right for more "
"information.")
.arg(nLineRelatedWarnings);
if (warnings.size() > 1)
for (auto& w : warnings)
w.prepend("* ");
for (auto& w : warnings)
new QListWidgetItem(w, m_ui->warningsListWidget);
} else {
m_ui->warningsIcon->hide();
m_ui->warningsLabel->hide();
m_ui->warningsListWidget->hide();
}
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
......
...@@ -139,6 +139,62 @@ ...@@ -139,6 +139,62 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing">
<number>5</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="warningsIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>(RT)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="warningsLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>The file import issued warnings:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="warningsListWidget"/>
</item>
</layout>
</item>
<item> <item>
<widget class="QGroupBox" name="linkedInstrumentGroup"> <widget class="QGroupBox" name="linkedInstrumentGroup">
<property name="title"> <property name="title">
...@@ -158,21 +214,17 @@ ...@@ -158,21 +214,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <spacer name="verticalSpacer">
<item> <property name="orientation">
<spacer name="verticalSpacer"> <enum>Qt::Vertical</enum>
<property name="orientation"> </property>
<enum>Qt::Vertical</enum> <property name="sizeHint" stdset="0">
</property> <size>
<property name="sizeHint" stdset="0"> <width>20</width>
<size> <height>40</height>
<width>20</width> </size>
<height>40</height> </property>
</size> </spacer>
</property>
</spacer>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment