From 543042004a046b92474ce323614aeb8002ab7e29 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 7 Feb 2018 11:00:25 +0200 Subject: [PATCH] Imported file must not contain the same name twice. ref #804. --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 17 ++++++++++++++--- src/app/tape/tmainwindow.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 2a684d327..1eb03301d 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -3067,13 +3067,18 @@ bool TMainWindow::IgnoreLocking(int error, const QString &path) } //--------------------------------------------------------------------------------------------------------------------- -QString TMainWindow::CheckMName(const QString &name) const +QString TMainWindow::CheckMName(const QString &name, const QSet &importedNames) const { if (name.isEmpty()) { throw VException(tr("Measurement name in is empty.")); } + if (importedNames.contains(name)) + { + throw VException(tr("Imported file must not contain the same name twice.")); + } + if (name.indexOf(CustomMSign) == 0) { QRegularExpression rx(NameRegExp()); @@ -3155,6 +3160,7 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv) }; QVector measurements; + QSet importedNames; for(int i=0; i < rows; ++i) { @@ -3168,7 +3174,9 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv) } IndividualMeasurement measurement; - measurement.name = CheckMName(qApp->TrVars()->MFromUser(name)); + const QString mName = CheckMName(qApp->TrVars()->MFromUser(name), importedNames); + importedNames.insert(mName); + measurement.name = mName; measurement.value = VTranslateVars::TryFormulaFromUser(csv.text(i, 1), qApp->Settings()->GetOsSeparator()); const bool custom = csv.text(i, 0).simplified().startsWith(CustomMSign); @@ -3254,6 +3262,7 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) }; QVector measurements; + QSet importedNames; for(int i=0; i < rows; ++i) { @@ -3267,7 +3276,9 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv) } MultisizeMeasurement measurement; - measurement.name = CheckMName(qApp->TrVars()->MFromUser(name)); + const QString mName = CheckMName(qApp->TrVars()->MFromUser(name), importedNames); + importedNames.insert(mName); + measurement.name = mName; measurement.base = ConverToDouble(csv.text(i, 1), tr("Cannot convert base size value to double in column 2.")); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 1fde6c3c2..a6139a259 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -216,7 +216,7 @@ private: template void HackWidget(T **widget); - QString CheckMName(const QString &name) const; + QString CheckMName(const QString &name, const QSet &importedNames) const; void ShowError(const QString &text); void RefreshDataAfterImport();