Refactoring. Use macros FORMAT_VERSION to avoid human mistakes.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-07-26 21:21:08 +03:00
parent 8a29755a36
commit d8f6734451
12 changed files with 285 additions and 285 deletions

View File

@ -930,7 +930,7 @@ void VPattern::ParseDetailInternals(const QDomElement &domElement, VPiece &detai
if (version == 1)
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
const bool closed = GetParametrUInt(domElement, AttrClosed, QChar('1'));
const qreal width = GetParametrDouble(domElement, AttrWidth, "0.0");

View File

@ -200,7 +200,7 @@ private:
void ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
// TODO. Delete if minimal supported version is 0.2.7
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 7),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 2, 7),
"Time to refactor the code.");
void ParseOldToolSpline(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
@ -208,7 +208,7 @@ private:
void ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
// TODO. Delete if minimal supported version is 0.2.7
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 7),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 2, 7),
"Time to refactor the code.");
void ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);

View File

@ -44,7 +44,7 @@
template <class Key, class T> class QMap;
#define CONVERTER_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
#define FORMAT_VERSION(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
class VAbstractConverter :public VDomDocument
{

View File

@ -39,8 +39,8 @@ public:
static const QString LabelTemplateMaxVerStr;
static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int LabelTemplateMinVer = CONVERTER_VERSION_CHECK(1, 0, 0);
static Q_DECL_CONSTEXPR const int LabelTemplateMaxVer = CONVERTER_VERSION_CHECK(1, 0, 0);
static Q_DECL_CONSTEXPR const int LabelTemplateMinVer = FORMAT_VERSION(1, 0, 0);
static Q_DECL_CONSTEXPR const int LabelTemplateMaxVer = FORMAT_VERSION(1, 0, 0);
protected:
virtual int MinVer() const override;

File diff suppressed because it is too large Load Diff

View File

@ -52,8 +52,8 @@ public:
static const QString PatternMaxVerStr;
static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0);
static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 10);
static Q_DECL_CONSTEXPR const int PatternMinVer = FORMAT_VERSION(0, 1, 0);
static Q_DECL_CONSTEXPR const int PatternMaxVer = FORMAT_VERSION(0, 7, 10);
protected:
virtual int MinVer() const override;

View File

@ -146,7 +146,7 @@ void VVITConverter::DowngradeToCurrentMaxVersion()
bool VVITConverter::IsReadOnly() const
{
// Check if attribute read-only was not changed in file format
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMaxVer == CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMaxVer == FORMAT_VERSION(0, 4, 0),
"Check attribute read-only.");
// Possibly in future attribute read-only will change position etc.
@ -160,7 +160,7 @@ bool VVITConverter::IsReadOnly() const
void VVITConverter::AddNewTagsForV0_3_0()
{
// TODO. Delete if minimal supported version is 0.3.0
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 0),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 0),
"Time to refactor the code.");
QDomElement rootElement = this->documentElement();
@ -182,7 +182,7 @@ void VVITConverter::AddNewTagsForV0_3_0()
QString VVITConverter::MUnitV0_2_0()
{
// TODO. Delete if minimal supported version is 0.3.0
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 0),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 0),
"Time to refactor the code.");
return UniqueTagText(QStringLiteral("unit"), QStringLiteral("cm"));
@ -192,7 +192,7 @@ QString VVITConverter::MUnitV0_2_0()
void VVITConverter::ConvertMeasurementsToV0_3_0()
{
// TODO. Delete if minimal supported version is 0.3.0
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 0),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 0),
"Time to refactor the code.");
const QString tagBM = QStringLiteral("body-measurements");
@ -235,7 +235,7 @@ void VVITConverter::ConvertMeasurementsToV0_3_0()
QDomElement VVITConverter::AddMV0_3_0(const QString &name, qreal value)
{
// TODO. Delete if minimal supported version is 0.3.0
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 0),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 0),
"Time to refactor the code.");
QDomElement element = createElement(QStringLiteral("m"));
@ -252,7 +252,7 @@ QDomElement VVITConverter::AddMV0_3_0(const QString &name, qreal value)
void VVITConverter::GenderV0_3_1()
{
// TODO. Delete if minimal supported version is 0.3.1
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 1),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 1),
"Time to refactor the code.");
const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("sex"));
@ -269,7 +269,7 @@ void VVITConverter::GenderV0_3_1()
void VVITConverter::PM_SystemV0_3_2()
{
// TODO. Delete if minimal supported version is 0.3.2
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 2),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 2),
"Time to refactor the code.");
QDomElement pm_system = createElement(QStringLiteral("pm_system"));
@ -286,7 +286,7 @@ void VVITConverter::PM_SystemV0_3_2()
void VVITConverter::ConvertMeasurementsToV0_3_3()
{
// TODO. Delete if minimal supported version is 0.3.3
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 3),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 3),
"Time to refactor the code.");
const QMap<QString, QString> names = OldNamesToNewNames_InV0_3_3();
@ -374,7 +374,7 @@ void VVITConverter::ConverCustomerNameToV0_4_0()
void VVITConverter::ToV0_3_0()
{
// TODO. Delete if minimal supported version is 0.3.0
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 0),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 0),
"Time to refactor the code.");
AddRootComment();
@ -388,7 +388,7 @@ void VVITConverter::ToV0_3_0()
void VVITConverter::ToV0_3_1()
{
// TODO. Delete if minimal supported version is 0.3.1
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 1),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 1),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.3.1"));
@ -400,7 +400,7 @@ void VVITConverter::ToV0_3_1()
void VVITConverter::ToV0_3_2()
{
// TODO. Delete if minimal supported version is 0.3.2
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 2),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 2),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.3.2"));
@ -412,7 +412,7 @@ void VVITConverter::ToV0_3_2()
void VVITConverter::ToV0_3_3()
{
// TODO. Delete if minimal supported version is 0.3.3
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 3, 3),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 3),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.3.3"));
@ -424,7 +424,7 @@ void VVITConverter::ToV0_3_3()
void VVITConverter::ToV0_4_0()
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.4.0"));

View File

@ -48,8 +48,8 @@ public:
static const QString MeasurementMaxVerStr;
static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int MeasurementMinVer = CONVERTER_VERSION_CHECK(0, 2, 0);
static Q_DECL_CONSTEXPR const int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 4, 0);
static Q_DECL_CONSTEXPR const int MeasurementMinVer = FORMAT_VERSION(0, 2, 0);
static Q_DECL_CONSTEXPR const int MeasurementMaxVer = FORMAT_VERSION(0, 4, 0);
protected:
virtual int MinVer() const override;

View File

@ -140,7 +140,7 @@ void VVSTConverter::DowngradeToCurrentMaxVersion()
bool VVSTConverter::IsReadOnly() const
{
// Check if attribute read-only was not changed in file format
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMaxVer == CONVERTER_VERSION_CHECK(0, 4, 4),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMaxVer == FORMAT_VERSION(0, 4, 4),
"Check attribute read-only.");
// Possibly in future attribute read-only will change position etc.
@ -154,7 +154,7 @@ bool VVSTConverter::IsReadOnly() const
void VVSTConverter::AddNewTagsForV0_4_0()
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
QDomElement rootElement = this->documentElement();
@ -179,7 +179,7 @@ void VVSTConverter::AddNewTagsForV0_4_0()
void VVSTConverter::RemoveTagsForV0_4_0()
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
QDomElement rootElement = this->documentElement();
@ -205,7 +205,7 @@ void VVSTConverter::RemoveTagsForV0_4_0()
void VVSTConverter::ConvertMeasurementsToV0_4_0()
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
const QString tagBM = QStringLiteral("body-measurements");
@ -255,7 +255,7 @@ void VVSTConverter::ConvertMeasurementsToV0_4_0()
QDomElement VVSTConverter::AddMV0_4_0(const QString &name, qreal value, qreal sizeIncrease, qreal heightIncrease)
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
QDomElement element = createElement(QStringLiteral("m"));
@ -274,7 +274,7 @@ QDomElement VVSTConverter::AddMV0_4_0(const QString &name, qreal value, qreal si
void VVSTConverter::PM_SystemV0_4_1()
{
// TODO. Delete if minimal supported version is 0.4.1
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 1),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 1),
"Time to refactor the code.");
QDomElement pm_system = createElement(QStringLiteral("pm_system"));
@ -291,7 +291,7 @@ void VVSTConverter::PM_SystemV0_4_1()
void VVSTConverter::ConvertMeasurementsToV0_4_2()
{
// TODO. Delete if minimal supported version is 0.4.2
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 2),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 2),
"Time to refactor the code.");
const QMap<QString, QString> names = OldNamesToNewNames_InV0_3_3();
@ -324,7 +324,7 @@ void VVSTConverter::ConvertMeasurementsToV0_4_2()
void VVSTConverter::ToV0_4_0()
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
AddRootComment();
@ -339,7 +339,7 @@ void VVSTConverter::ToV0_4_0()
void VVSTConverter::ToV0_4_1()
{
// TODO. Delete if minimal supported version is 0.4.1
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 1),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 1),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.4.1"));
@ -351,7 +351,7 @@ void VVSTConverter::ToV0_4_1()
void VVSTConverter::ToV0_4_2()
{
// TODO. Delete if minimal supported version is 0.4.2
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 2),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 2),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.4.2"));
@ -363,7 +363,7 @@ void VVSTConverter::ToV0_4_2()
void VVSTConverter::ToV0_4_3()
{
// TODO. Delete if minimal supported version is 0.4.3
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 3),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 3),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.4.3"));
@ -374,7 +374,7 @@ void VVSTConverter::ToV0_4_3()
void VVSTConverter::ToV0_4_4()
{
// TODO. Delete if minimal supported version is 0.4.4
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 4),
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 4),
"Time to refactor the code.");
SetVersion(QStringLiteral("0.4.4"));

View File

@ -50,11 +50,11 @@ public:
static const QString CurrentSchema;
// GCC 4.6 doesn't allow constexpr and const together
#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406
static Q_DECL_CONSTEXPR int MeasurementMinVer = CONVERTER_VERSION_CHECK(0, 3, 0);
static Q_DECL_CONSTEXPR int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 4, 4);
static Q_DECL_CONSTEXPR int MeasurementMinVer = FORMAT_VERSION(0, 3, 0);
static Q_DECL_CONSTEXPR int MeasurementMaxVer = FORMAT_VERSION(0, 4, 4);
#else
static Q_DECL_CONSTEXPR const int MeasurementMinVer = CONVERTER_VERSION_CHECK(0, 3, 0);
static Q_DECL_CONSTEXPR const int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 4, 4);
static Q_DECL_CONSTEXPR const int MeasurementMinVer = FORMAT_VERSION(0, 3, 0);
static Q_DECL_CONSTEXPR const int MeasurementMaxVer = FORMAT_VERSION(0, 4, 4);
#endif
protected:

View File

@ -991,7 +991,7 @@ void VToolSeamAllowance::RefreshDataInFile()
// Refresh only parts that we possibly need to update
{
// TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 4, 0),
"Time to refactor the code.");
const uint version = doc->GetParametrUInt(domElement, AttrVersion, QChar('1'));

View File

@ -1336,7 +1336,7 @@ void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qrea
{
// This check need for backward compatibility
// Remove check and "else" part if min version is 0.3.2
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 2),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 3, 2),
"Time to refactor the code.");
if (children.size() == countNodeD1 + countNodeD2-1)
{
@ -1393,7 +1393,7 @@ void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qrea
QVector<quint32> FixChildren(QVector<quint32> records, QVector<quint32> children, VContainer *data)
{
// TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 7, 0),
"Time to refactor the code.");
SCASSERT(data != nullptr)
@ -1431,7 +1431,7 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx
if (initData.version == 1)
{
// TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 7, 0),
"Time to refactor the code.");
// Fixing bug in first version of the tool. Mostly for backward compatibility.
children = FixChildren(records, children, initData.data);
@ -1444,7 +1444,7 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx
if (initData.version == 1)
{
// TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0),
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 7, 0),
"Time to refactor the code.");
const quint32 updatedId = TakeNextId(children);