Check if all defined known measurements in a file are valid.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-09-22 17:41:05 +03:00
parent c01bc165db
commit d90d24ca61
8 changed files with 76 additions and 35 deletions

View File

@ -194,11 +194,17 @@ void TMainWindow::LoadFile(const QString &path)
m = new VMeasurements(data);
m->setXMLContent(path);
if (not m->IsDefinedKnownNamesValid())
{
VException e(tr("File contains invalid known measurement(s)."));
throw e;
}
mType = m->Type();
if (mType == MeasurementsType::Unknown)
{
VException e("File has unknown format.");
VException e(tr("File has unknown format."));
throw e;
}

View File

@ -245,9 +245,15 @@ bool MainWindow::LoadMeasurements(const QString &path)
m = new VMeasurements(pattern);
m->setXMLContent(path);
if (not m->IsDefinedKnownNamesValid())
{
VException e(tr("Measurement file contains invalid known measurement(s)."));
throw e;
}
if (m->Type() == MeasurementsType::Unknown)
{
VException e("Measurement file has unknown format.");
VException e(tr("Measurement file has unknown format."));
throw e;
}
@ -274,9 +280,8 @@ bool MainWindow::LoadMeasurements(const QString &path)
const QSet<QString> match = pList.toSet().subtract(mList.toSet());
if (not match.isEmpty())
{
VException e("Measurement file doesn't include all required measurements.");
e.AddMoreInformation(QString("Please, additionaly provide: %1")
.arg(QStringList(match.toList()).join(", ")));
VException e(tr("Measurement file doesn't include all required measurements."));
e.AddMoreInformation(tr("Please, additionaly provide: %1").arg(QStringList(match.toList()).join(", ")));
throw e;
}
@ -3430,11 +3435,17 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
VMeasurements *m = new VMeasurements(pattern);
m->setXMLContent(mPath);
if (not m->IsDefinedKnownNamesValid())
{
VException e(tr("Measurement file contains invalid known measurement(s)."));
throw e;
}
patternType = m->Type();
if (patternType == MeasurementsType::Unknown)
{
VException e("Measurement file has unknown format.");
VException e(tr("Measurement file has unknown format."));
throw e;
}
@ -3463,8 +3474,8 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
const QSet<QString> match = pList.toSet().subtract(mList.toSet());
if (not match.isEmpty())
{
VException e("Measurement file doesn't include all required measurements.");
e.AddMoreInformation(QString("Please, additionaly provide: %1")
VException e(tr("Measurement file doesn't include all required measurements."));
e.AddMoreInformation(tr("Please, additionaly provide: %1")
.arg(QStringList(match.toList()).join(", ")));
throw e;
}

View File

@ -533,6 +533,28 @@ QStringList VMeasurements::ListKnown() const
return listNames;
}
//---------------------------------------------------------------------------------------------------------------------
bool VMeasurements::IsDefinedKnownNamesValid() const
{
QStringList names = AllGroupNames();
QSet<QString> set;
foreach (const QString &var, names)
{
set.insert(var);
}
names = ListKnown();
foreach (const QString &var, names)
{
if (not set.contains(var))
{
return false;
}
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::SetDataSize()
{

View File

@ -121,6 +121,8 @@ public:
QStringList ListAll() const;
QStringList ListKnown() const;
bool IsDefinedKnownNamesValid() const;
void SetDataSize();
void SetDataHeight();

View File

@ -935,3 +935,27 @@ QStringList SupportedLocales()
return locales;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList AllGroupNames()
{
const QStringList originalNames = QStringList() << ListGroupA()
<< ListGroupB()
<< ListGroupC()
<< ListGroupD()
<< ListGroupE()
<< ListGroupF()
<< ListGroupG()
<< ListGroupH()
<< ListGroupI()
<< ListGroupJ()
<< ListGroupK()
<< ListGroupL()
<< ListGroupM()
<< ListGroupN()
<< ListGroupO()
<< ListGroupP()
<< ListGroupQ();
return originalNames;
}

View File

@ -577,5 +577,6 @@ qreal UnitConvertor(qreal value, const Unit &from, const Unit &to);
void CheckFactor(qreal &oldFactor, const qreal &Newfactor);
QStringList SupportedLocales();
QStringList AllGroupNames();
#endif // DEF_H

View File

@ -55,7 +55,7 @@ TST_MeasurementRegExp::~TST_MeasurementRegExp()
// cppcheck-suppress unusedFunction
void TST_MeasurementRegExp::TestOriginalMeasurementNamesRegExp()
{
const QStringList originalNames = OriginalNames();
const QStringList originalNames = AllGroupNames();
const QRegularExpression re(NameRegExp());
foreach(const QString &str, originalNames)
@ -454,7 +454,7 @@ void TST_MeasurementRegExp::InitTrMs()
//---------------------------------------------------------------------------------------------------------------------
void TST_MeasurementRegExp::CheckNames() const
{
const QStringList originalNames = OriginalNames();
const QStringList originalNames = AllGroupNames();
const QRegularExpression re(NameRegExp());
foreach(const QString &str, originalNames)
@ -463,27 +463,3 @@ void TST_MeasurementRegExp::CheckNames() const
QCOMPARE(re.match(translated).hasMatch(), true);
}
}
//---------------------------------------------------------------------------------------------------------------------
QStringList TST_MeasurementRegExp::OriginalNames() const
{
const QStringList originalNames = QStringList() << ListGroupA()
<< ListGroupB()
<< ListGroupC()
<< ListGroupD()
<< ListGroupE()
<< ListGroupF()
<< ListGroupG()
<< ListGroupH()
<< ListGroupI()
<< ListGroupJ()
<< ListGroupK()
<< ListGroupL()
<< ListGroupM()
<< ListGroupN()
<< ListGroupO()
<< ListGroupP()
<< ListGroupQ();
return originalNames;
}

View File

@ -57,7 +57,6 @@ private:
int LoadTranslation(const QString &checkedSystem, const QString &checkedLocale);
void InitTrMs();
void CheckNames() const;
QStringList OriginalNames() const;
};
#endif // TST_MEASUREMENTREGEXP_H