Imported file must not contain the same name twice. ref #804.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-02-07 11:00:25 +02:00
parent 3f79c0f057
commit 543042004a
2 changed files with 15 additions and 4 deletions

View file

@ -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<QString> &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<IndividualMeasurement> measurements;
QSet<QString> 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<MultisizeMeasurement> measurements;
QSet<QString> 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."));

View file

@ -216,7 +216,7 @@ private:
template <class T>
void HackWidget(T **widget);
QString CheckMName(const QString &name) const;
QString CheckMName(const QString &name, const QSet<QString> &importedNames) const;
void ShowError(const QString &text);
void RefreshDataAfterImport();