From 67a12ef86c081b07ba9110e44b171c64bf542a95 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 23 Feb 2017 14:46:53 +0200 Subject: [PATCH] Copy-on-write for class VPieceLabelData. --HG-- branch : feature --- .../vpatterndb/floatItemData/floatitemdef.h | 38 ++++++++++ .../floatItemData/vpatternlabeldata.h | 2 +- .../floatItemData/vpiecelabeldata.cpp | 48 ++++++++----- .../floatItemData/vpiecelabeldata.h | 39 ++-------- .../floatItemData/vpiecelabeldata_p.h | 72 +++++++++++++++++++ src/libs/vpatterndb/vpatterndb.pri | 3 +- 6 files changed, 147 insertions(+), 55 deletions(-) create mode 100644 src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h diff --git a/src/libs/vpatterndb/floatItemData/floatitemdef.h b/src/libs/vpatterndb/floatItemData/floatitemdef.h index 415d3d633..6807a3379 100644 --- a/src/libs/vpatterndb/floatItemData/floatitemdef.h +++ b/src/libs/vpatterndb/floatItemData/floatitemdef.h @@ -29,6 +29,9 @@ #ifndef FLOATITEMDEF_H #define FLOATITEMDEF_H +#include +#include + // denotes the type of arrow for the grainline enum class ArrowType : char { @@ -37,5 +40,40 @@ enum class ArrowType : char atRear }; +enum class MaterialType : char +{ + mtFabric = 0, + mtLining = 1, + mtInterfacing = 2, + mtInterlining = 3, + mtUserDefined = 4 +}; + +enum class PlacementType : char +{ + ptNone = 0, + ptCutOnFold = 1 +}; + +/** + * @brief The MaterialCutPlacement struct used to hold a material, cut number and placement 3-tuple + */ +struct MaterialCutPlacement +{ + MaterialType m_eMaterial; + QString m_qsMaterialUserDef; + int m_iCutNumber; + PlacementType m_ePlacement; + + MaterialCutPlacement() + : m_eMaterial(MaterialType::mtFabric), + m_qsMaterialUserDef(), + m_iCutNumber(0), + m_ePlacement(PlacementType::ptNone) + {} +}; + +typedef QList MCPContainer; + #endif // FLOATITEMDEF_H diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h index 21381f6f7..29cdeffc3 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h @@ -65,7 +65,7 @@ public: quint32 BottomRightPin() const; void SetBottomRightPin(const quint32 &bottomRightPin); -protected: +private: QSharedDataPointer d; }; diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp index ecfafc6c0..06d641933 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp @@ -27,24 +27,34 @@ *************************************************************************/ #include "vpiecelabeldata.h" +#include "vpiecelabeldata_p.h" #include //--------------------------------------------------------------------------------------------------------------------- -MaterialCutPlacement::MaterialCutPlacement() - : m_eMaterial(MaterialType::mtFabric), - m_qsMaterialUserDef(), - m_iCutNumber(0), - m_ePlacement(PlacementType::ptNone) +VPieceLabelData::VPieceLabelData() + : VPatternLabelData(), + d(new VPieceLabelDataPrivate()) {} //--------------------------------------------------------------------------------------------------------------------- -VPieceLabelData::VPieceLabelData() - : VPatternLabelData(), - m_qsLetter(), - m_conMCP() +VPieceLabelData::VPieceLabelData(const VPieceLabelData &data) + : VPatternLabelData(data), + d (data.d) {} +//--------------------------------------------------------------------------------------------------------------------- +VPieceLabelData &VPieceLabelData::operator=(const VPieceLabelData &data) +{ + if ( &data == this ) + { + return *this; + } + VPatternLabelData::operator=(data); + d = data.d; + return *this; +} + //--------------------------------------------------------------------------------------------------------------------- VPieceLabelData::~VPieceLabelData() {} @@ -52,7 +62,7 @@ VPieceLabelData::~VPieceLabelData() //--------------------------------------------------------------------------------------------------------------------- void VPieceLabelData::Append(const MaterialCutPlacement& rMCP) { - m_conMCP.append(rMCP); + d->m_conMCP.append(rMCP); } //--------------------------------------------------------------------------------------------------------------------- @@ -60,7 +70,7 @@ void VPieceLabelData::Insert(int i, const MaterialCutPlacement& rMCP) { Q_ASSERT(i >= 0); Q_ASSERT(i <= GetMCPCount()); - m_conMCP.insert(i, rMCP); + d->m_conMCP.insert(i, rMCP); } //--------------------------------------------------------------------------------------------------------------------- @@ -68,13 +78,13 @@ void VPieceLabelData::Set(int i, const MaterialCutPlacement& rMCP) { Q_ASSERT(i >= 0); Q_ASSERT(i < GetMCPCount()); - m_conMCP[i] = rMCP; + d->m_conMCP[i] = rMCP; } //--------------------------------------------------------------------------------------------------------------------- int VPieceLabelData::GetMCPCount() const { - return m_conMCP.count(); + return d->m_conMCP.count(); } //--------------------------------------------------------------------------------------------------------------------- @@ -82,7 +92,7 @@ const MaterialCutPlacement& VPieceLabelData::GetMCP(int i) const { Q_ASSERT(i >= 0); Q_ASSERT(i < GetMCPCount()); - return m_conMCP.at(i); + return d->m_conMCP.at(i); } //--------------------------------------------------------------------------------------------------------------------- @@ -90,24 +100,24 @@ void VPieceLabelData::RemoveMCP(int i) { Q_ASSERT(i >= 0); Q_ASSERT(i < GetMCPCount()); - m_conMCP.removeAt(i); + d->m_conMCP.removeAt(i); } //--------------------------------------------------------------------------------------------------------------------- void VPieceLabelData::Clear() { - m_qsLetter.clear(); - m_conMCP.clear(); + d->m_qsLetter.clear(); + d->m_conMCP.clear(); } //--------------------------------------------------------------------------------------------------------------------- const QString& VPieceLabelData::GetLetter() const { - return m_qsLetter; + return d->m_qsLetter; } //--------------------------------------------------------------------------------------------------------------------- void VPieceLabelData::SetLetter(QString qsLetter) { - m_qsLetter = qsLetter.left(3); + d->m_qsLetter = qsLetter.left(3); } diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h index 273df823c..f58bb3efd 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h @@ -29,40 +29,12 @@ #ifndef VPATTERNPIECEDATA_H #define VPATTERNPIECEDATA_H -#include #include #include "vpatternlabeldata.h" +#include "floatitemdef.h" -enum class MaterialType : char -{ - mtFabric = 0, - mtLining = 1, - mtInterfacing = 2, - mtInterlining = 3, - mtUserDefined = 4 -}; - -enum class PlacementType : char -{ - ptNone = 0, - ptCutOnFold = 1 -}; - -/** - * @brief The MaterialCutPlacement struct used to hold a material, cut number and placement 3-tuple - */ -struct MaterialCutPlacement -{ - MaterialType m_eMaterial; - QString m_qsMaterialUserDef; - int m_iCutNumber; - PlacementType m_ePlacement; - - MaterialCutPlacement(); -}; - -typedef QList MCPContainer; +class VPieceLabelDataPrivate; /** * @brief The VPieceLabelData class holds some information about a single @@ -72,6 +44,8 @@ class VPieceLabelData : public VPatternLabelData { public: VPieceLabelData(); + VPieceLabelData(const VPieceLabelData &data); + VPieceLabelData &operator=(const VPieceLabelData &data); virtual ~VPieceLabelData(); // methods, which operate on MaterialCutPlacement container @@ -88,10 +62,7 @@ public: void SetLetter(QString qsLetter); private: - /** @brief m_qsLetter Detail letter (should be no more than 3 characters) */ - QString m_qsLetter; - /** @brief m_conMCP List of material, cut, placement tuples */ - MCPContainer m_conMCP; + QSharedDataPointer d; }; #endif // VPATTERNPIECEDATA_H diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h new file mode 100644 index 000000000..7d02f96b6 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h @@ -0,0 +1,72 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 23 2, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 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 . + ** + *************************************************************************/ + +#ifndef VPIECELABELDATA_P_H +#define VPIECELABELDATA_P_H + +#include +#include + +#include "../vmisc/diagnostic.h" +#include "floatitemdef.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +class VPieceLabelDataPrivate : public QSharedData +{ +public: + VPieceLabelDataPrivate() + : m_qsLetter(), + m_conMCP() + {} + + VPieceLabelDataPrivate(const VPieceLabelDataPrivate &data) + : QSharedData(data), + m_qsLetter(data.m_qsLetter), + m_conMCP(data.m_conMCP) + {} + + ~VPieceLabelDataPrivate(); + + /** @brief m_qsLetter Detail letter (should be no more than 3 characters) */ + QString m_qsLetter; + /** @brief m_conMCP List of material, cut, placement tuples */ + MCPContainer m_conMCP; + +private: + VPieceLabelDataPrivate &operator=(const VPieceLabelDataPrivate &) Q_DECL_EQ_DELETE; +}; + +VPieceLabelDataPrivate::~VPieceLabelDataPrivate() +{} + +QT_WARNING_POP + +#endif // VPIECELABELDATA_P_H + diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index d0006cd91..45c97a250 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -71,4 +71,5 @@ HEADERS += \ $$PWD/floatItemData/vabstractfloatitemdata_p.h \ $$PWD/floatItemData/vgrainlinedata_p.h \ $$PWD/floatItemData/floatitemdef.h \ - $$PWD/floatItemData/vpatternlabeldata_p.h + $$PWD/floatItemData/vpatternlabeldata_p.h \ + $$PWD/floatItemData/vpiecelabeldata_p.h