Copy-on-write for class VPatternLabelData.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-02-23 14:36:08 +02:00
parent f36a4d6621
commit 2b1cd5c96c
4 changed files with 127 additions and 31 deletions

View File

@ -27,19 +27,33 @@
*************************************************************************/ *************************************************************************/
#include "vpatternlabeldata.h" #include "vpatternlabeldata.h"
#include "vpatternlabeldata_p.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPatternLabelData::VPatternLabelData() VPatternLabelData::VPatternLabelData()
: VAbstractFloatItemData(), : VAbstractFloatItemData(),
m_dLabelWidth(0), d(new VPatternLabelDataPrivate())
m_dLabelHeight(0),
m_iFontSize(0),
m_dRotation(0),
m_topLeftPin(NULL_ID),
m_bottomRightPin(NULL_ID)
{} {}
//---------------------------------------------------------------------------------------------------------------------
VPatternLabelData::VPatternLabelData(const VPatternLabelData &data)
: VAbstractFloatItemData(data),
d (data.d)
{}
//---------------------------------------------------------------------------------------------------------------------
VPatternLabelData &VPatternLabelData::operator=(const VPatternLabelData &data)
{
if ( &data == this )
{
return *this;
}
VAbstractFloatItemData::operator=(data);
d = data.d;
return *this;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPatternLabelData::~VPatternLabelData() VPatternLabelData::~VPatternLabelData()
{} {}
@ -47,71 +61,71 @@ VPatternLabelData::~VPatternLabelData()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPatternLabelData::GetLabelWidth() const qreal VPatternLabelData::GetLabelWidth() const
{ {
return m_dLabelWidth; return d->m_dLabelWidth;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPatternLabelData::SetLabelWidth(qreal dLabelW) void VPatternLabelData::SetLabelWidth(qreal dLabelW)
{ {
m_dLabelWidth = dLabelW; d->m_dLabelWidth = dLabelW;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPatternLabelData::GetLabelHeight() const qreal VPatternLabelData::GetLabelHeight() const
{ {
return m_dLabelHeight; return d->m_dLabelHeight;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPatternLabelData::SetLabelHeight(qreal dLabelH) void VPatternLabelData::SetLabelHeight(qreal dLabelH)
{ {
m_dLabelHeight = dLabelH; d->m_dLabelHeight = dLabelH;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VPatternLabelData::GetFontSize() const int VPatternLabelData::GetFontSize() const
{ {
return m_iFontSize; return d->m_iFontSize;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPatternLabelData::SetFontSize(int iSize) void VPatternLabelData::SetFontSize(int iSize)
{ {
m_iFontSize = iSize; d->m_iFontSize = iSize;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPatternLabelData::GetRotation() const qreal VPatternLabelData::GetRotation() const
{ {
return m_dRotation; return d->m_dRotation;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPatternLabelData::SetRotation(qreal dRot) void VPatternLabelData::SetRotation(qreal dRot)
{ {
m_dRotation = dRot; d->m_dRotation = dRot;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 VPatternLabelData::TopLeftPin() const quint32 VPatternLabelData::TopLeftPin() const
{ {
return m_topLeftPin; return d->m_topLeftPin;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPatternLabelData::SetTopLeftPin(const quint32 &topLeftPin) void VPatternLabelData::SetTopLeftPin(const quint32 &topLeftPin)
{ {
m_topLeftPin = topLeftPin; d->m_topLeftPin = topLeftPin;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 VPatternLabelData::BottomRightPin() const quint32 VPatternLabelData::BottomRightPin() const
{ {
return m_bottomRightPin; return d->m_bottomRightPin;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPatternLabelData::SetBottomRightPin(const quint32 &bottomRightPin) void VPatternLabelData::SetBottomRightPin(const quint32 &bottomRightPin)
{ {
m_bottomRightPin = bottomRightPin; d->m_bottomRightPin = bottomRightPin;
} }

View File

@ -33,6 +33,8 @@
#include "vabstractfloatitemdata.h" #include "vabstractfloatitemdata.h"
class VPatternLabelDataPrivate;
/** /**
* @brief The VPatternLabelData class holds the information about pattern info label geometry * @brief The VPatternLabelData class holds the information about pattern info label geometry
*/ */
@ -40,6 +42,8 @@ class VPatternLabelData : public VAbstractFloatItemData
{ {
public: public:
VPatternLabelData(); VPatternLabelData();
VPatternLabelData(const VPatternLabelData &data);
VPatternLabelData &operator=(const VPatternLabelData &data);
virtual ~VPatternLabelData(); virtual ~VPatternLabelData();
// methods, which set up label parameters // methods, which set up label parameters
@ -62,18 +66,7 @@ public:
void SetBottomRightPin(const quint32 &bottomRightPin); void SetBottomRightPin(const quint32 &bottomRightPin);
protected: protected:
/** @brief m_dLabelWidth label width */ QSharedDataPointer<VPatternLabelDataPrivate> d;
qreal m_dLabelWidth;
/** @brief m_dLabelHeight label height */
qreal m_dLabelHeight;
/** @brief m_iFontSize label text base font size */
int m_iFontSize;
/** @brief m_dRotation label rotation */
qreal m_dRotation;
/** @brief m_topLeftPin top left corner pin id */
quint32 m_topLeftPin;
/** @brief m_bottomRightPin bottom right corner pin id */
quint32 m_bottomRightPin;
}; };
#endif // VPATTERNINFOGEOMETRY_H #endif // VPATTERNINFOGEOMETRY_H

View File

@ -0,0 +1,88 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VPATTERNLABELDATA_P_H
#define VPATTERNLABELDATA_P_H
#include <QPointF>
#include <QSharedData>
#include "../vmisc/diagnostic.h"
#include "../ifc/ifcdef.h"
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")
class VPatternLabelDataPrivate : public QSharedData
{
public:
VPatternLabelDataPrivate()
: m_dLabelWidth(0),
m_dLabelHeight(0),
m_iFontSize(0),
m_dRotation(0),
m_topLeftPin(NULL_ID),
m_bottomRightPin(NULL_ID)
{}
VPatternLabelDataPrivate(const VPatternLabelDataPrivate &data)
: QSharedData(data),
m_dLabelWidth(data.m_dLabelWidth),
m_dLabelHeight(data.m_dLabelHeight),
m_iFontSize(data.m_iFontSize),
m_dRotation(data.m_dRotation),
m_topLeftPin(data.m_topLeftPin),
m_bottomRightPin(data.m_bottomRightPin)
{}
~VPatternLabelDataPrivate();
/** @brief m_dLabelWidth label width */
qreal m_dLabelWidth;
/** @brief m_dLabelHeight label height */
qreal m_dLabelHeight;
/** @brief m_iFontSize label text base font size */
int m_iFontSize;
/** @brief m_dRotation label rotation */
qreal m_dRotation;
/** @brief m_topLeftPin top left corner pin id */
quint32 m_topLeftPin;
/** @brief m_bottomRightPin bottom right corner pin id */
quint32 m_bottomRightPin;
private:
VPatternLabelDataPrivate &operator=(const VPatternLabelDataPrivate &) Q_DECL_EQ_DELETE;
};
VPatternLabelDataPrivate::~VPatternLabelDataPrivate()
{}
QT_WARNING_POP
#endif // VPATTERNLABELDATA_P_H

View File

@ -70,4 +70,5 @@ HEADERS += \
$$PWD/floatItemData/vabstractfloatitemdata.h \ $$PWD/floatItemData/vabstractfloatitemdata.h \
$$PWD/floatItemData/vabstractfloatitemdata_p.h \ $$PWD/floatItemData/vabstractfloatitemdata_p.h \
$$PWD/floatItemData/vgrainlinedata_p.h \ $$PWD/floatItemData/vgrainlinedata_p.h \
$$PWD/floatItemData/floatitemdef.h $$PWD/floatItemData/floatitemdef.h \
$$PWD/floatItemData/vpatternlabeldata_p.h