Improve error messages while import CSV data.

Show correct row number.
This commit is contained in:
Roman Telezhynskyi 2022-12-26 15:38:12 +02:00
parent db2b6b865b
commit 376152da8c
3 changed files with 19 additions and 8 deletions

View File

@ -10,6 +10,7 @@
- Export area of piece in Final measurements. - Export area of piece in Final measurements.
- New option Show accuracy radius. - New option Show accuracy radius.
- New option Interactive tools. - New option Interactive tools.
- Improve error messages while import CSV data.
# Valentina 0.7.52 September 12, 2022 # Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru. - Fix crash when default locale is ru.

View File

@ -1112,11 +1112,11 @@ void TMainWindow::ImportDataFromCSV()
if (m_m->Type() == MeasurementsType::Individual) if (m_m->Type() == MeasurementsType::Individual)
{ {
ImportIndividualMeasurements(csv, map); ImportIndividualMeasurements(csv, map, dialog.IsWithHeader());
} }
else else
{ {
ImportMultisizeMeasurements(csv, map); ImportMultisizeMeasurements(csv, map, dialog.IsWithHeader());
} }
} }
} }
@ -3930,7 +3930,7 @@ void TMainWindow::RefreshDataAfterImport()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv, const QVector<int> &map) void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv, const QVector<int> &map, bool withHeader)
{ {
const int columns = csv.columnCount(); const int columns = csv.columnCount();
const int rows = csv.rowCount(); const int rows = csv.rowCount();
@ -3999,7 +3999,12 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv, const QVe
} }
catch (VException &e) catch (VException &e)
{ {
ShowError(tr("Error in row %1.").arg(i) + QLatin1Char(' ') + e.ErrorMessage()); int rowIndex = i+1;
if (withHeader)
{
++rowIndex;
}
ShowError(tr("Error in row %1. %2").arg(rowIndex).arg(e.ErrorMessage()));
return; return;
} }
} }
@ -4023,7 +4028,7 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv, const QVe
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector<int> &map) void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector<int> &map, bool withHeader)
{ {
const int columns = csv.columnCount(); const int columns = csv.columnCount();
@ -4047,7 +4052,12 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVec
} }
catch (VException &e) catch (VException &e)
{ {
ShowError(tr("Error in row %1.").arg(i) + QLatin1Char(' ') + e.ErrorMessage()); int rowIndex = i+1;
if (withHeader)
{
++rowIndex;
}
ShowError(tr("Error in row %1. %2").arg(rowIndex).arg(e.ErrorMessage()));
return; return;
} }
} }

View File

@ -263,8 +263,8 @@ private:
void ShowError(const QString &text); void ShowError(const QString &text);
void RefreshDataAfterImport(); void RefreshDataAfterImport();
void ImportIndividualMeasurements(const QxtCsvModel &csv, const QVector<int> &map); void ImportIndividualMeasurements(const QxtCsvModel &csv, const QVector<int> &map, bool withHeader);
void ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector<int> &map); void ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector<int> &map, bool withHeader);
auto ImportMultisizeMeasurement(const QxtCsvModel &csv, int i, const QVector<int> &map, auto ImportMultisizeMeasurement(const QxtCsvModel &csv, int i, const QVector<int> &map,
int dimensionsCount, QSet<QString> &importedNames) -> MultisizeMeasurement; int dimensionsCount, QSet<QString> &importedNames) -> MultisizeMeasurement;