2016-06-26 13:36:12 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2016-11-09 14:53:22 +01:00
|
|
|
** @file
|
2016-06-26 13:36:12 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2016-11-09 14:53:22 +01:00
|
|
|
** @date 9 11, 2016
|
2016-06-26 13:36:12 +02:00
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-06-26 13:36:12 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-06-26 13:36:12 +02:00
|
|
|
**
|
|
|
|
** 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 <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
#ifndef VABSTRACTPIECE_P_H
|
|
|
|
#define VABSTRACTPIECE_P_H
|
2016-06-26 13:36:12 +02:00
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
#include <QSharedData>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QString>
|
2016-11-29 13:18:23 +01:00
|
|
|
#include <QCoreApplication>
|
2020-04-22 13:32:25 +02:00
|
|
|
#include <QUuid>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2022-08-22 10:34:02 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
2016-11-09 14:53:22 +01:00
|
|
|
#include "../vmisc/diagnostic.h"
|
2022-08-22 10:34:02 +02:00
|
|
|
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
2023-05-11 15:23:57 +02:00
|
|
|
|
2020-01-07 13:21:47 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
2020-01-07 08:45:26 +01:00
|
|
|
# include "../vmisc/vdatastreamenum.h"
|
|
|
|
#endif
|
2023-05-11 15:23:57 +02:00
|
|
|
|
2019-07-01 10:33:29 +02:00
|
|
|
#include "../vmisc/defglobal.h"
|
2019-07-01 11:26:08 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
2016-06-26 13:36:12 +02:00
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
2017-05-30 17:44:16 +02:00
|
|
|
QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
class VAbstractPieceData : public QSharedData
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(VAbstractPieceData) // NOLINT
|
2016-06-26 13:36:12 +02:00
|
|
|
public:
|
2022-11-04 15:12:58 +01:00
|
|
|
VAbstractPieceData() = default;
|
|
|
|
|
|
|
|
VAbstractPieceData(const VAbstractPieceData &piece) = default;
|
2016-11-09 14:53:22 +01:00
|
|
|
|
2022-08-22 15:36:01 +02:00
|
|
|
~VAbstractPieceData() = default;
|
2016-06-26 13:36:12 +02:00
|
|
|
|
2022-11-04 15:12:58 +01:00
|
|
|
friend auto operator<<(QDataStream& dataStream, const VAbstractPieceData& piece) -> QDataStream&;
|
|
|
|
friend auto operator>>(QDataStream& dataStream, VAbstractPieceData& piece) -> QDataStream&;
|
2019-07-01 11:26:08 +02:00
|
|
|
|
2022-11-04 15:12:58 +01:00
|
|
|
QString m_name{tr("Detail")}; // NOLINT (misc-non-private-member-variables-in-classes)
|
2016-11-10 10:56:40 +01:00
|
|
|
/** @brief forbidFlipping forbid piece be mirrored in a layout. */
|
2022-11-04 15:12:58 +01:00
|
|
|
bool m_forbidFlipping{false}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
bool m_forceFlipping{false}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
bool m_seamAllowance{false}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
bool m_seamAllowanceBuiltIn{false}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
bool m_hideMainPath{false}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
qreal m_width{0}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
qreal m_mx{0}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
qreal m_my{0}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
uint m_priority{0}; // NOLINT (misc-non-private-member-variables-in-classes)
|
|
|
|
QUuid m_uuid{QUuid::createUuid()}; // NOLINT (misc-non-private-member-variables-in-classes)
|
2022-11-04 16:16:50 +01:00
|
|
|
bool m_onDrawing{false}; // NOLINT (misc-non-private-member-variables-in-classes)
|
2016-11-09 14:53:22 +01:00
|
|
|
|
|
|
|
private:
|
2022-11-04 15:12:58 +01:00
|
|
|
Q_DISABLE_ASSIGN_MOVE(VAbstractPieceData) // NOLINT
|
2019-07-01 11:26:08 +02:00
|
|
|
|
2022-11-04 15:12:58 +01:00
|
|
|
static constexpr quint32 streamHeader = 0x05CDD73A; // CRC-32Q string "VAbstractPieceData"
|
2022-11-04 16:16:50 +01:00
|
|
|
static constexpr quint16 classVersion = 4;
|
2016-06-26 13:36:12 +02:00
|
|
|
};
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2022-11-21 07:55:32 +01:00
|
|
|
// See https://stackoverflow.com/a/46719572/3045403
|
|
|
|
#if __cplusplus < 201703L // C++17
|
|
|
|
constexpr quint32 VAbstractPieceData::streamHeader; // NOLINT(readability-redundant-declaration)
|
2022-11-22 07:20:22 +01:00
|
|
|
constexpr quint16 VAbstractPieceData::classVersion; // NOLINT(readability-redundant-declaration)
|
2022-11-21 07:55:32 +01:00
|
|
|
#endif
|
|
|
|
|
2019-07-01 11:26:08 +02:00
|
|
|
// Friend functions
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-11-04 15:12:58 +01:00
|
|
|
inline auto operator<<(QDataStream &dataStream, const VAbstractPieceData &piece) -> QDataStream &
|
2019-07-01 11:26:08 +02:00
|
|
|
{
|
|
|
|
dataStream << VAbstractPieceData::streamHeader << VAbstractPieceData::classVersion;
|
|
|
|
|
|
|
|
// Added in classVersion = 1
|
|
|
|
dataStream << piece.m_name;
|
|
|
|
dataStream << piece.m_forbidFlipping;
|
|
|
|
dataStream << piece.m_forceFlipping;
|
|
|
|
dataStream << piece.m_seamAllowance;
|
|
|
|
dataStream << piece.m_seamAllowanceBuiltIn;
|
|
|
|
dataStream << piece.m_hideMainPath;
|
|
|
|
dataStream << piece.m_width;
|
|
|
|
dataStream << piece.m_mx;
|
|
|
|
dataStream << piece.m_my;
|
|
|
|
|
|
|
|
// Added in classVersion = 2
|
2019-07-19 09:45:57 +02:00
|
|
|
dataStream << piece.m_priority;
|
2019-07-01 11:26:08 +02:00
|
|
|
|
2020-04-22 13:32:25 +02:00
|
|
|
// Added in classVersion = 3
|
|
|
|
dataStream << piece.m_uuid;
|
|
|
|
|
2022-11-04 16:16:50 +01:00
|
|
|
// Added in classVersion = 4
|
|
|
|
dataStream << piece.m_onDrawing;
|
|
|
|
|
2019-07-01 11:26:08 +02:00
|
|
|
return dataStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-11-04 15:12:58 +01:00
|
|
|
inline auto operator>>(QDataStream &dataStream, VAbstractPieceData &piece) -> QDataStream &
|
2019-07-01 11:26:08 +02:00
|
|
|
{
|
|
|
|
quint32 actualStreamHeader = 0;
|
|
|
|
dataStream >> actualStreamHeader;
|
|
|
|
|
|
|
|
if (actualStreamHeader != VAbstractPieceData::streamHeader)
|
|
|
|
{
|
|
|
|
QString message = QCoreApplication::tr("VAbstractPieceData prefix mismatch error: actualStreamHeader = 0x%1 "
|
|
|
|
"and streamHeader = 0x%2")
|
|
|
|
.arg(actualStreamHeader, 8, 0x10, QChar('0'))
|
|
|
|
.arg(VAbstractPieceData::streamHeader, 8, 0x10, QChar('0'));
|
|
|
|
throw VException(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
quint16 actualClassVersion = 0;
|
|
|
|
dataStream >> actualClassVersion;
|
|
|
|
|
|
|
|
if (actualClassVersion > VAbstractPieceData::classVersion)
|
|
|
|
{
|
|
|
|
QString message = QCoreApplication::tr("VAbstractPieceData compatibility error: actualClassVersion = %1 and "
|
|
|
|
"classVersion = %2")
|
|
|
|
.arg(actualClassVersion).arg(VAbstractPieceData::classVersion);
|
|
|
|
throw VException(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
dataStream >> piece.m_name;
|
|
|
|
dataStream >> piece.m_forbidFlipping;
|
|
|
|
dataStream >> piece.m_forceFlipping;
|
|
|
|
dataStream >> piece.m_seamAllowance;
|
|
|
|
dataStream >> piece.m_seamAllowanceBuiltIn;
|
|
|
|
dataStream >> piece.m_hideMainPath;
|
|
|
|
dataStream >> piece.m_width;
|
|
|
|
dataStream >> piece.m_mx;
|
|
|
|
dataStream >> piece.m_my;
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
if (actualClassVersion >= 2)
|
|
|
|
{
|
|
|
|
dataStream >> piece.m_priority;
|
|
|
|
}
|
2019-07-01 11:26:08 +02:00
|
|
|
|
2020-04-22 13:32:25 +02:00
|
|
|
if (actualClassVersion >= 3)
|
|
|
|
{
|
|
|
|
dataStream >> piece.m_uuid;
|
|
|
|
}
|
|
|
|
|
2022-11-04 16:16:50 +01:00
|
|
|
if (actualClassVersion >= 4)
|
|
|
|
{
|
|
|
|
dataStream >> piece.m_onDrawing;
|
|
|
|
}
|
|
|
|
|
2019-07-01 11:26:08 +02:00
|
|
|
return dataStream;
|
|
|
|
}
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
#endif // VABSTRACTPIECE_P_H
|
|
|
|
|