Fix the layout format conversion.

This commit is contained in:
Roman Telezhynskyi 2022-02-18 16:32:43 +02:00
parent 499ec96691
commit ed910db2c3
11 changed files with 67 additions and 52 deletions

View File

@ -438,17 +438,8 @@ auto VPMainWindow::LoadFile(QString path) -> bool
VLayoutConverter converter(path);
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
path = converter.Convert();
}
catch (VException &e)
{
qCCritical(pWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
lock.reset();
return false;
}
QFile file(path);
QFile file(converter.Convert());
file.open(QIODevice::ReadOnly);
VPLayoutFileReader fileReader;
@ -468,6 +459,14 @@ auto VPMainWindow::LoadFile(QString path) -> bool
}
return false;
}
}
catch (VException &e)
{
qCCritical(pWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
lock.reset();
return false;
}
SetCurrentFile(path);

View File

@ -61,7 +61,6 @@ const QString TagLine = QStringLiteral("line");
const QString TagScale = QStringLiteral("scale");
const QString TagWatermark = QStringLiteral("watermark");
const QString AttrVersion = QStringLiteral("version");
const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition");
const QString AttrWarningOutOfBound = QStringLiteral("warningOutOfBound");
const QString AttrStickyEdges = QStringLiteral("stickyEdges");

View File

@ -66,7 +66,6 @@ extern const QString TagLine;
extern const QString TagScale;
extern const QString TagWatermark;
extern const QString AttrVersion;
extern const QString AttrWarningSuperposition;
extern const QString AttrWarningOutOfBound;
extern const QString AttrStickyEdges;

View File

@ -143,6 +143,7 @@ const QString AttrCurve1Alias1 = QStringLiteral("curve1Alias1");
const QString AttrCurve1Alias2 = QStringLiteral("curve1Alias2");
const QString AttrCurve2Alias1 = QStringLiteral("curve2Alias1");
const QString AttrCurve2Alias2 = QStringLiteral("curve2Alias2");
const QString AttrLayoutVersion = QStringLiteral("version");
const QString TypeLineDefault = QStringLiteral("default");
const QString TypeLineNone = QStringLiteral("none");

View File

@ -162,6 +162,7 @@ extern const QString AttrCurve1Alias1;
extern const QString AttrCurve1Alias2;
extern const QString AttrCurve2Alias1;
extern const QString AttrCurve2Alias2;
extern const QString AttrLayoutVersion;
extern const QString TypeLineDefault;
extern const QString TypeLineNone;

View File

@ -50,7 +50,6 @@
#include <QXmlSchemaValidator>
#include "../exception/vexception.h"
#include "../exception/vexceptionwrongid.h"
#include "vdomdocument.h"
//This class need for validation pattern file using XSD shema
@ -339,17 +338,6 @@ void VAbstractConverter::ValidateInputFile(const QString &currentSchema) const
//---------------------------------------------------------------------------------------------------------------------
void VAbstractConverter::Save()
{
try
{
TestUniqueId();
}
catch (const VExceptionWrongId &e)
{
Q_UNUSED(e)
VException ex(tr("Error no unique id."));
throw ex;
}
m_tmpFile.resize(0);//clear previous content
const int indent = 4;
QTextStream out(&m_tmpFile);
@ -358,8 +346,7 @@ void VAbstractConverter::Save()
if (not m_tmpFile.flush())
{
VException e(m_tmpFile.errorString());
throw e;
throw VException(m_tmpFile.errorString());
}
}

View File

@ -44,7 +44,6 @@ QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
class VAbstractConverter :public VDomDocument
{
Q_DECLARE_TR_FUNCTIONS(VAbstractConverter)
public:
explicit VAbstractConverter(const QString &fileName);
virtual ~VAbstractConverter() Q_DECL_EQ_DEFAULT;
@ -60,8 +59,8 @@ protected:
void ValidateInputFile(const QString &currentSchema) const;
Q_NORETURN void InvalidVersion(unsigned ver) const;
void Save();
void SetVersion(const QString &version);
virtual void Save();
virtual void SetVersion(const QString &version);
virtual unsigned MinVer() const =0;
virtual unsigned MaxVer() const =0;

View File

@ -26,6 +26,8 @@
**
*************************************************************************/
#include "vlayoutconverter.h"
#include "../exception/vexception.h"
#include "ifcdef.h"
/*
* Version rules:
@ -42,18 +44,11 @@ const QString VLayoutConverter::CurrentSchema = QStringLiteral("://schema/layo
//VLayoutConverter::LayoutMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VLayoutConverter::LayoutMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
namespace
{
// The list of all string we use for conversion
// Better to use global variables because repeating QStringLiteral blows up code size
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strVersion, (QLatin1String("version")))
}
//---------------------------------------------------------------------------------------------------------------------
VLayoutConverter::VLayoutConverter(const QString &fileName)
: VAbstractConverter(fileName)
{
m_ver = GetFormatVersion(GetFormatVersionStr());
m_ver = GetFormatVersion(VLayoutConverter::GetFormatVersionStr());
ValidateInputFile(CurrentSchema);
}
@ -66,12 +61,28 @@ auto VLayoutConverter::GetFormatVersionStr() const -> QString
const QDomElement layoutElement = root.toElement();
if (not layoutElement.isNull())
{
return GetParametrString(layoutElement, *strVersion, QStringLiteral("0.0.0"));
return GetParametrString(layoutElement, AttrLayoutVersion, QStringLiteral("0.0.0"));
}
}
return QStringLiteral("0.0.0");
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutConverter::SetVersion(const QString &version)
{
ValidateVersion(version);
QDomElement root = documentElement().toElement();
if (root.isElement() && root.hasAttribute(AttrLayoutVersion))
{
root.setAttribute(AttrLayoutVersion, version);
}
else
{
throw VException(tr("Could not change version."));
}
}
//---------------------------------------------------------------------------------------------------------------------
auto VLayoutConverter::XSDSchema(unsigned ver) const -> QString
{

View File

@ -35,7 +35,6 @@ class QString;
class VLayoutConverter : public VAbstractConverter
{
Q_DECLARE_TR_FUNCTIONS(VLayoutConverter)
public:
explicit VLayoutConverter(const QString &fileName);
virtual ~VLayoutConverter() Q_DECL_EQ_DEFAULT;
@ -48,6 +47,8 @@ public:
static Q_DECL_CONSTEXPR const unsigned LayoutMaxVer = FormatVersion(0, 1, 0);
protected:
void SetVersion(const QString &version) override;
virtual unsigned MinVer() const override;
virtual unsigned MaxVer() const override;

View File

@ -45,9 +45,9 @@
#include "../exception/vexception.h"
#include "../exception/vexceptionemptyparameter.h"
#include "../exception/vexceptionwrongid.h"
#include "../qmuparser/qmutokenparser.h"
#include "../vmisc/def.h"
#include "vabstractconverter.h"
class QDomElement;
@ -179,6 +179,22 @@ VPatternConverter::VPatternConverter(const QString &fileName)
ValidateInputFile(CurrentSchema);
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::Save()
{
try
{
TestUniqueId();
}
catch (const VExceptionWrongId &e)
{
Q_UNUSED(e)
throw VException(tr("Error no unique id."));
}
VAbstractConverter::Save();
}
//---------------------------------------------------------------------------------------------------------------------
auto VPatternConverter::XSDSchema(unsigned ver) const -> QString
{

View File

@ -56,6 +56,8 @@ public:
static Q_DECL_CONSTEXPR const unsigned PatternMaxVer = FormatVersion(0, 9, 0);
protected:
void Save() override;
virtual unsigned MinVer() const override;
virtual unsigned MaxVer() const override;