Fixed issue #325. Check pattern for inverse compatibility.
--HG-- branch : develop
This commit is contained in:
parent
c59efe15d3
commit
be8503664f
|
@ -1,3 +1,6 @@
|
|||
# Version 0.5.0
|
||||
- [#325] Check pattern for inverse compatibility.
|
||||
|
||||
# Version 0.3.3 Released May 20, 2015
|
||||
- [#297] Scaling Error - Print.
|
||||
- [#304] Layout appears different than my pattern.
|
||||
|
|
|
@ -65,7 +65,14 @@ void VAbstractConverter::Convert()
|
|||
|
||||
ReserveFile();
|
||||
|
||||
if (ver <= MaxVer())
|
||||
{
|
||||
ApplyPatches();
|
||||
}
|
||||
else
|
||||
{
|
||||
DowngradeToCurrentMaxVersion();
|
||||
}
|
||||
|
||||
QFile file(backupFileName);
|
||||
file.remove();
|
||||
|
@ -104,25 +111,25 @@ int VAbstractConverter::GetVersion(const QString &version) const
|
|||
{
|
||||
ValidateVersion(version);
|
||||
|
||||
QStringList ver = version.split(".");
|
||||
const QStringList ver = version.split(".");
|
||||
|
||||
bool ok = false;
|
||||
int major = ver.at(0).toInt(&ok);
|
||||
if (ok == false)
|
||||
const int major = ver.at(0).toInt(&ok);
|
||||
if (not ok)
|
||||
{
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
ok = false;
|
||||
int minor = ver.at(1).toInt(&ok);
|
||||
if (ok == false)
|
||||
const int minor = ver.at(1).toInt(&ok);
|
||||
if (not ok)
|
||||
{
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
ok = false;
|
||||
int patch = ver.at(2).toInt(&ok);
|
||||
if (ok == false)
|
||||
const int patch = ver.at(2).toInt(&ok);
|
||||
if (not ok)
|
||||
{
|
||||
return 0x0;
|
||||
}
|
||||
|
@ -133,7 +140,7 @@ int VAbstractConverter::GetVersion(const QString &version) const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::ValidateVersion(const QString &version) const
|
||||
{
|
||||
QRegExp rx(QStringLiteral("^(0|([1-9][0-9]*)).(0|([1-9][0-9]*)).(0|([1-9][0-9]*))$"));
|
||||
const QRegExp rx(QStringLiteral("^(0|([1-9][0-9]*)).(0|([1-9][0-9]*)).(0|([1-9][0-9]*))$"));
|
||||
|
||||
if (rx.exactMatch(version) == false)
|
||||
{
|
||||
|
@ -207,7 +214,7 @@ void VAbstractConverter::BiasTokens(int position, int bias, QMap<int, QString> &
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::CheckVersion(int ver) const
|
||||
Q_NORETURN void VAbstractConverter::InvalidVersion(int ver) const
|
||||
{
|
||||
if (ver < MinVer())
|
||||
{
|
||||
|
@ -220,6 +227,9 @@ void VAbstractConverter::CheckVersion(int ver) const
|
|||
const QString errorMsg(tr("Invalid version. Maximum supported version is %1").arg(MaxVerStr()));
|
||||
throw VException(errorMsg);
|
||||
}
|
||||
|
||||
const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16));
|
||||
throw VException(errorMsg);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -239,6 +249,43 @@ bool VAbstractConverter::SaveDocument(const QString &fileName, QString &error) c
|
|||
return VDomDocument::SaveDocument(fileName, error);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::ValidateInputFile(const QString ¤tSchema) const
|
||||
{
|
||||
QString schema;
|
||||
try
|
||||
{
|
||||
schema = XSDSchema(ver);
|
||||
}
|
||||
catch(const VException &e)
|
||||
{
|
||||
if (ver < MinVer())
|
||||
{ // Version less than minimally supported version. Can't do anything.
|
||||
throw e;
|
||||
}
|
||||
else if (ver > MaxVer())
|
||||
{ // Version bigger than maximum supported version. We still have a chance to open the file.
|
||||
try
|
||||
{ // Try to open like the current version.
|
||||
ValidateXML(currentSchema, fileName);
|
||||
}
|
||||
catch(const VException &exp)
|
||||
{ // Nope, we can't.
|
||||
Q_UNUSED(exp);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Unexpected version. Most time mean that we do not catch all versions between min and max.
|
||||
throw e;
|
||||
}
|
||||
|
||||
return; // All is fine and we can try to convert to current max version.
|
||||
}
|
||||
|
||||
ValidateXML(schema, fileName);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::Save() const
|
||||
{
|
||||
|
@ -253,6 +300,8 @@ void VAbstractConverter::Save() const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::SetVersion(const QString &version)
|
||||
{
|
||||
ValidateVersion(version);
|
||||
|
||||
if (setTagText(TagVersion, version) == false)
|
||||
{
|
||||
VException e(tr("Could not change version."));
|
||||
|
|
|
@ -45,8 +45,9 @@ protected:
|
|||
int ver;
|
||||
QString fileName;
|
||||
|
||||
void ValidateInputFile(const QString ¤tSchema) const;
|
||||
int GetVersion(const QString &version) const;
|
||||
void CheckVersion(int ver) const;
|
||||
Q_NORETURN void InvalidVersion(int ver) const;
|
||||
void Save() const;
|
||||
void SetVersion(const QString &version);
|
||||
|
||||
|
@ -58,6 +59,7 @@ protected:
|
|||
|
||||
virtual QString XSDSchema(int ver) const =0;
|
||||
virtual void ApplyPatches() =0;
|
||||
virtual void DowngradeToCurrentMaxVersion() =0;
|
||||
|
||||
void Replace(QString &formula, const QString &newName, int position, const QString &token, int &bias) const;
|
||||
void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens) const;
|
||||
|
|
|
@ -50,8 +50,7 @@ const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pa
|
|||
VPatternConverter::VPatternConverter(const QString &fileName)
|
||||
:VAbstractConverter(fileName)
|
||||
{
|
||||
const QString schema = XSDSchema(ver);
|
||||
ValidateXML(schema, fileName);
|
||||
ValidateInputFile(CurrentSchema);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -85,8 +84,6 @@ QString VPatternConverter::MaxVerStr() const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VPatternConverter::XSDSchema(int ver) const
|
||||
{
|
||||
CheckVersion(ver);
|
||||
|
||||
switch (ver)
|
||||
{
|
||||
case (0x000100):
|
||||
|
@ -110,10 +107,8 @@ QString VPatternConverter::XSDSchema(int ver) const
|
|||
case (0x000204):
|
||||
return CurrentSchema;
|
||||
default:
|
||||
{
|
||||
const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16));
|
||||
throw VException(errorMsg);
|
||||
}
|
||||
InvalidVersion(ver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,6 +207,13 @@ void VPatternConverter::ApplyPatches()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPatternConverter::DowngradeToCurrentMaxVersion()
|
||||
{
|
||||
SetVersion(PatternMaxVerStr);
|
||||
Save();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPatternConverter::ToV0_1_1()
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ protected:
|
|||
|
||||
QString XSDSchema(int ver) const;
|
||||
virtual void ApplyPatches() Q_DECL_OVERRIDE;
|
||||
virtual void DowngradeToCurrentMaxVersion() Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPatternConverter)
|
||||
|
|
|
@ -47,8 +47,7 @@ const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/in
|
|||
VVITConverter::VVITConverter(const QString &fileName)
|
||||
:VAbstractMConverter(fileName)
|
||||
{
|
||||
const QString schema = XSDSchema(ver);
|
||||
ValidateXML(schema, fileName);
|
||||
ValidateInputFile(CurrentSchema);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -82,8 +81,6 @@ QString VVITConverter::MaxVerStr() const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VVITConverter::XSDSchema(int ver) const
|
||||
{
|
||||
CheckVersion(ver);
|
||||
|
||||
switch (ver)
|
||||
{
|
||||
case (0x000200):
|
||||
|
@ -97,10 +94,8 @@ QString VVITConverter::XSDSchema(int ver) const
|
|||
case (0x000303):
|
||||
return CurrentSchema;
|
||||
default:
|
||||
{
|
||||
const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16));
|
||||
throw VException(errorMsg);
|
||||
}
|
||||
InvalidVersion(ver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,6 +159,13 @@ void VVITConverter::ApplyPatches()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VVITConverter::DowngradeToCurrentMaxVersion()
|
||||
{
|
||||
SetVersion(MeasurementMaxVerStr);
|
||||
Save();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VVITConverter::AddNewTagsForV0_3_0()
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ protected:
|
|||
|
||||
QString XSDSchema(int ver) const;
|
||||
virtual void ApplyPatches() Q_DECL_OVERRIDE;
|
||||
virtual void DowngradeToCurrentMaxVersion() Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VVITConverter)
|
||||
|
|
|
@ -47,8 +47,7 @@ const QString VVSTConverter::CurrentSchema = QStringLiteral("://schema/st
|
|||
VVSTConverter::VVSTConverter(const QString &fileName)
|
||||
:VAbstractMConverter(fileName)
|
||||
{
|
||||
const QString schema = XSDSchema(ver);
|
||||
ValidateXML(schema, fileName);
|
||||
ValidateInputFile(CurrentSchema);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -82,8 +81,6 @@ QString VVSTConverter::MaxVerStr() const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VVSTConverter::XSDSchema(int ver) const
|
||||
{
|
||||
CheckVersion(ver);
|
||||
|
||||
switch (ver)
|
||||
{
|
||||
case (0x000300):
|
||||
|
@ -95,10 +92,8 @@ QString VVSTConverter::XSDSchema(int ver) const
|
|||
case (0x000402):
|
||||
return CurrentSchema;
|
||||
default:
|
||||
{
|
||||
const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16));
|
||||
throw VException(errorMsg);
|
||||
}
|
||||
InvalidVersion(ver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +150,13 @@ void VVSTConverter::ApplyPatches()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VVSTConverter::DowngradeToCurrentMaxVersion()
|
||||
{
|
||||
SetVersion(MeasurementMaxVerStr);
|
||||
Save();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VVSTConverter::AddNewTagsForV0_4_0()
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ protected:
|
|||
|
||||
QString XSDSchema(int ver) const;
|
||||
virtual void ApplyPatches() Q_DECL_OVERRIDE;
|
||||
virtual void DowngradeToCurrentMaxVersion() Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VVSTConverter)
|
||||
|
|
Loading…
Reference in New Issue
Block a user