/************************************************************************ ** ** @file vwatermarkconverter.cpp ** @author Roman Telezhynskyi ** @date 26 12, 2019 ** ** @brief ** @copyright ** This source code is part of the Valentina project, a pattern making ** program, whose allow create and modeling patterns of clothing. ** Copyright (C) 2019 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** *************************************************************************/ #include "vwatermarkconverter.h" #include /* * Version rules: * 1. Version have three parts "major.minor.patch"; * 2. major part only for stable releases; * 3. minor - 10 or more patch changes, or one big change; * 4. patch - little change. */ const QString VWatermarkConverter::WatermarkMinVerStr = QStringLiteral("1.0.0"); const QString VWatermarkConverter::WatermarkMaxVerStr = QStringLiteral("1.1.0"); const QString VWatermarkConverter::CurrentSchema = QStringLiteral("://schema/watermark/v1.1.0.xsd"); //VWatermarkConverter::WatermarkMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VWatermarkConverter::WatermarkMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! //--------------------------------------------------------------------------------------------------------------------- VWatermarkConverter::VWatermarkConverter(const QString &fileName) : VAbstractConverter(fileName) { m_ver = GetFormatVersion(GetFormatVersionStr()); ValidateInputFile(CurrentSchema); } //--------------------------------------------------------------------------------------------------------------------- auto VWatermarkConverter::XSDSchemas() -> QHash { static auto schemas = QHash { std::make_pair(FormatVersion(1, 0, 0), QStringLiteral("://schema/watermark/v1.0.0.xsd")), std::make_pair(FormatVersion(1, 1, 0), CurrentSchema) }; return schemas; } //--------------------------------------------------------------------------------------------------------------------- unsigned VWatermarkConverter::MinVer() const { return WatermarkMinVer; } //--------------------------------------------------------------------------------------------------------------------- unsigned VWatermarkConverter::MaxVer() const { return WatermarkMaxVer; } //--------------------------------------------------------------------------------------------------------------------- QString VWatermarkConverter::MinVerStr() const { return WatermarkMinVerStr; } //--------------------------------------------------------------------------------------------------------------------- QString VWatermarkConverter::MaxVerStr() const { return WatermarkMaxVerStr; } //--------------------------------------------------------------------------------------------------------------------- void VWatermarkConverter::ApplyPatches() { switch (m_ver) { case (FormatVersion(1, 0, 0)): ToV1_1_0(); ValidateXML(XSDSchema(FormatVersion(1, 1, 0))); Q_FALLTHROUGH(); case (FormatVersion(1, 1, 0)): break; default: InvalidVersion(m_ver); } } //--------------------------------------------------------------------------------------------------------------------- void VWatermarkConverter::DowngradeToCurrentMaxVersion() { SetVersion(WatermarkMaxVerStr); Save(); } //--------------------------------------------------------------------------------------------------------------------- auto VWatermarkConverter::Schemas() const -> QHash { return XSDSchemas(); } //--------------------------------------------------------------------------------------------------------------------- void VWatermarkConverter::ToV1_1_0() { // TODO. Delete if minimal supported version is 1.1.0 Q_STATIC_ASSERT_X(VWatermarkConverter::WatermarkMinVer < FormatVersion(1, 1, 0), "Time to refactor the code."); SetVersion(QStringLiteral("1.1.0")); Save(); }