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 @@
#include "Device/InputOutput/DataFormatUtils.h"
#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
OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fin)
{
......@@ -34,11 +34,11 @@ OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fi
while (std::getline(fin, line)) {
line = StringUtils::trim(line);
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
std::vector<double> rowVec = DataFormatUtils::parse_doubles(line);
vecVec.push_back(rowVec);
} catch (...) { // #migration +++ This eats useful errors away...
} catch (...) { // #bamigration +++ This eats useful errors away...
continue;
}
}
......@@ -46,10 +46,10 @@ OutputData<double>* OutputDataReadReflectometry::readOutputData(std::istream& fi
// validate - There is at least one row and at least two columns
size_t nrows = vecVec.size();
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();
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:
for (size_t row = 0; row < nrows; row++) {
......
......@@ -42,6 +42,16 @@ int AbstractDataLoader::numErrors() const
return 0;
}
int AbstractDataLoader::numLineRelatedErrors() const
{
return 0;
}
QStringList AbstractDataLoader::lineUnrelatedErrors() const
{
return {};
}
AbstractDataLoaderResultModel* AbstractDataLoader::createResultModel() const
{
return nullptr;
......
......@@ -95,6 +95,13 @@ public:
//! content can't be used (e.g. only 1 line present).
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
//! content, processed content
//! The returned pointer will be owned by the caller.
......
......@@ -115,3 +115,11 @@ int AutomaticDataLoader1D::numErrors() const
{
return m_error.isEmpty() ? 0 : 1;
}
QStringList AutomaticDataLoader1D::lineUnrelatedErrors() const
{
if (!m_error.isEmpty())
return {m_error};
return {};
}
......@@ -31,6 +31,7 @@ public:
virtual void processContents() override;
virtual AbstractDataLoaderResultModel* createResultModel() const override;
virtual int numErrors() const override;
virtual QStringList lineUnrelatedErrors() const override;
private:
QByteArray m_fileContent;
......
......@@ -169,7 +169,7 @@ QByteArray QREDataLoader::serialize() const
s << m_importResult.validCalculatedLines;
s << m_importResult.maxColumnCount;
s << m_importResult.calculationErrors;
s << m_importResult.errors;
s << m_importResult.error;
s << m_importResult.importSettings;
return a;
......@@ -201,7 +201,7 @@ void QREDataLoader::deserialize(const QByteArray& data)
s >> m_importResult.validCalculatedLines;
s >> m_importResult.maxColumnCount;
s >> m_importResult.calculationErrors;
s >> m_importResult.errors;
s >> m_importResult.error;
s >> m_importResult.importSettings;
} else
throw DeserializationException::tooNew();
......@@ -224,8 +224,7 @@ void QREDataLoader::processContents()
// 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
// #baimport o check for binary etc. and return error
m_importResult.errors.clear();
m_importResult.error.clear();
ASSERT(m_item != nullptr);
ASSERT(m_item->isSpecularData());
......@@ -255,9 +254,9 @@ void QREDataLoader::processContents()
// -- make a few checks (mainly for fulfilling PointwiseAxis::sanityCheck())
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();
return;
}
......@@ -267,7 +266,7 @@ void QREDataLoader::processContents()
try {
createOutputDataFromParsingResult(m_item);
} catch (...) {
m_importResult.errors << "Import not successful - caught an exception.";
m_importResult.error = "Import not successful - caught an exception.";
invalidateItemData();
}
}
......@@ -275,7 +274,20 @@ void QREDataLoader::processContents()
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
......@@ -617,7 +629,7 @@ void QREDataLoader::ImportResult::clear()
validCalculatedLines = 0;
maxColumnCount = 0;
calculationErrors.clear();
errors.clear();
error.clear();
importSettings.columnDefinitions.clear(); // sufficient
}
......
......@@ -40,6 +40,8 @@ public:
virtual void guessSettings() override;
virtual void processContents() override;
virtual int numErrors() const override;
virtual int numLineRelatedErrors() const override;
virtual QStringList lineUnrelatedErrors() const override;
virtual AbstractDataLoaderResultModel* createResultModel() const override;
private:
......@@ -112,7 +114,7 @@ private:
int maxColumnCount; //!< max found columns in raw data
QMap<int, ErrorDefinition>
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
};
mutable ImportResult m_importResult;
......
......@@ -36,6 +36,7 @@ public:
virtual void guessSettings() override;
virtual void processContents() override;
// #baUserDefLoaders ++ implement all overloads!
private:
QString m_name;
AbstractDataLoader1D* m_wrappedLoader;
......
......@@ -262,8 +262,12 @@ QVariant RealDataTreeModel::data(const QModelIndex& index, int role) const
const auto numErrors =
(item->dataLoader() != nullptr) ? item->dataLoader()->numErrors() : 0;
return numErrors == 0 ? item->name()
: item->name() + QString(" (%1 parser warnings)").arg(numErrors);
if (numErrors == 0)
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)
......
......@@ -40,6 +40,9 @@ SpecularDataImportWidget::SpecularDataImportWidget(QWidget* parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
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
// #baUserDefLoaders - remove next line when implementation is complete
......@@ -292,6 +295,38 @@ void SpecularDataImportWidget::updatePreview()
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();
}
......
......@@ -139,6 +139,62 @@
</layout>
</widget>
</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>
<widget class="QGroupBox" name="linkedInstrumentGroup">
<property name="title">
......@@ -158,21 +214,17 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</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