Copy-on-write for class VGrainlineData.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-02-23 14:04:49 +02:00
parent 9714e8cb07
commit f36a4d6621
10 changed files with 180 additions and 53 deletions

View File

@ -874,8 +874,7 @@ void VPattern::ParsePieceGrainline(const QDomElement &domElement, VPiece &detail
detail.GetGrainlineGeometry().SetLength(qsLength);
QString qsRot = GetParametrString(domElement, AttrRotation, "90");
detail.GetGrainlineGeometry().SetRotation(qsRot);
VGrainlineData::ArrowType eAT =
VGrainlineData::ArrowType(GetParametrUInt(domElement, AttrArrows, "0"));
ArrowType eAT = static_cast<ArrowType>(GetParametrUInt(domElement, AttrArrows, "0"));
detail.GetGrainlineGeometry().SetArrowType(eAT);
}

View File

@ -267,7 +267,7 @@ void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer& rP
v << pt1;
if (geom.GetArrowType() != VGrainlineData::atRear) {
if (geom.GetArrowType() != ArrowType::atRear) {
pt.setX(pt1.x() + dArrowLen * qCos(dAng + dArrowAng));
pt.setY(pt1.y() - dArrowLen * qSin(dAng + dArrowAng));
v << pt;
@ -280,7 +280,7 @@ void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer& rP
v << pt2;
if (geom.GetArrowType() != VGrainlineData::atFront)
if (geom.GetArrowType() != ArrowType::atFront)
{
dAng += M_PI;

View File

@ -0,0 +1,41 @@
/************************************************************************
**
** @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 FLOATITEMDEF_H
#define FLOATITEMDEF_H
// denotes the type of arrow for the grainline
enum class ArrowType : char
{
atBoth,
atFront,
atRear
};
#endif // FLOATITEMDEF_H

View File

@ -29,18 +29,32 @@
#include <QPointF>
#include "vgrainlinedata.h"
#include "../ifc/ifcdef.h"
#include "vgrainlinedata_p.h"
//---------------------------------------------------------------------------------------------------------------------
VGrainlineData::VGrainlineData()
: VAbstractFloatItemData(),
m_qsLength(),
m_dRotation(),
m_eArrowType(atBoth),
m_topPin(NULL_ID),
m_bottomPin(NULL_ID)
d(new VGrainlineDataPrivate())
{}
//---------------------------------------------------------------------------------------------------------------------
VGrainlineData::VGrainlineData(const VGrainlineData &data)
: VAbstractFloatItemData(data),
d (data.d)
{}
//---------------------------------------------------------------------------------------------------------------------
VGrainlineData &VGrainlineData::operator=(const VGrainlineData &data)
{
if ( &data == this )
{
return *this;
}
VAbstractFloatItemData::operator=(data);
d = data.d;
return *this;
}
//---------------------------------------------------------------------------------------------------------------------
VGrainlineData::~VGrainlineData()
{}
@ -48,59 +62,59 @@ VGrainlineData::~VGrainlineData()
//---------------------------------------------------------------------------------------------------------------------
QString VGrainlineData::GetLength() const
{
return m_qsLength;
return d->m_qsLength;
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineData::SetLength(const QString& qsLen)
{
m_qsLength = qsLen;
d->m_qsLength = qsLen;
}
//---------------------------------------------------------------------------------------------------------------------
QString VGrainlineData::GetRotation() const
{
return m_dRotation;
return d->m_dRotation;
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineData::SetRotation(const QString& qsRot)
{
m_dRotation = qsRot;
d->m_dRotation = qsRot;
}
//---------------------------------------------------------------------------------------------------------------------
VGrainlineData::ArrowType VGrainlineData::GetArrowType() const
ArrowType VGrainlineData::GetArrowType() const
{
return m_eArrowType;
return d->m_eArrowType;
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineData::SetArrowType(ArrowType eAT)
{
m_eArrowType = eAT;
d->m_eArrowType = eAT;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VGrainlineData::TopPin() const
{
return m_topPin;
return d->m_topPin;
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineData::SetTopPin(const quint32 &topPin)
void VGrainlineData::SetTopPin(quint32 topPin)
{
m_topPin = topPin;
d->m_topPin = topPin;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VGrainlineData::BottomPin() const
{
return m_bottomPin;
return d->m_bottomPin;
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineData::SetBottomPin(const quint32 &bottomPin)
void VGrainlineData::SetBottomPin(quint32 bottomPin)
{
m_bottomPin = bottomPin;
d->m_bottomPin = bottomPin;
}

View File

@ -33,6 +33,9 @@
#include <QPointF>
#include "vabstractfloatitemdata.h"
#include "floatitemdef.h"
class VGrainlineDataPrivate;
/**
* @brief The VGrainlineData class holds information about a grainline like
@ -41,15 +44,9 @@
class VGrainlineData : public VAbstractFloatItemData
{
public:
// denotes the type of arrow for the grainline
enum ArrowType
{
atBoth,
atFront,
atRear
};
VGrainlineData();
VGrainlineData(const VGrainlineData &data);
VGrainlineData &operator=(const VGrainlineData &data);
virtual ~VGrainlineData();
// methods, which set and return values of different parameters
@ -63,22 +60,13 @@ public:
void SetArrowType(ArrowType eAT);
quint32 TopPin() const;
void SetTopPin(const quint32 &topPin);
void SetTopPin(quint32 topPin);
quint32 BottomPin() const;
void SetBottomPin(const quint32 &bottomPin);
void SetBottomPin(quint32 bottomPin);
private:
/** @brief m_dLength formula to calculate the length of grainline */
QString m_qsLength;
/** @brief m_dRotation formula to calculate the rotation of grainline in [degrees] */
QString m_dRotation;
/** @brief m_eArrowType type of arrow on the grainline */
ArrowType m_eArrowType;
/** @brief m_topPin top pin id */
quint32 m_topPin;
/** @brief m_bottomPin bottom pin id */
quint32 m_bottomPin;
QSharedDataPointer<VGrainlineDataPrivate> d;
};
#endif // VGRAINLINEGEOMETRY_H

View File

@ -0,0 +1,85 @@
/************************************************************************
**
** @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 VGRAINLINEDATA_P_H
#define VGRAINLINEDATA_P_H
#include <QPointF>
#include <QSharedData>
#include "../vmisc/diagnostic.h"
#include "floatitemdef.h"
#include "../ifc/ifcdef.h"
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")
class VGrainlineDataPrivate : public QSharedData
{
public:
VGrainlineDataPrivate()
: m_qsLength(),
m_dRotation(),
m_eArrowType(ArrowType::atBoth),
m_topPin(NULL_ID),
m_bottomPin(NULL_ID)
{}
VGrainlineDataPrivate(const VGrainlineDataPrivate &data)
: QSharedData(data),
m_qsLength(data.m_qsLength),
m_dRotation(data.m_dRotation),
m_eArrowType(data.m_eArrowType),
m_topPin(data.m_topPin),
m_bottomPin(data.m_bottomPin)
{}
~VGrainlineDataPrivate();
/** @brief m_dLength formula to calculate the length of grainline */
QString m_qsLength;
/** @brief m_dRotation formula to calculate the rotation of grainline in [degrees] */
QString m_dRotation;
/** @brief m_eArrowType type of arrow on the grainline */
ArrowType m_eArrowType;
/** @brief m_topPin top pin id */
quint32 m_topPin;
/** @brief m_bottomPin bottom pin id */
quint32 m_bottomPin;
private:
VGrainlineDataPrivate &operator=(const VGrainlineDataPrivate &) Q_DECL_EQ_DELETE;
};
VGrainlineDataPrivate::~VGrainlineDataPrivate()
{}
QT_WARNING_POP
#endif // VGRAINLINEDATA_P_H

View File

@ -68,4 +68,6 @@ HEADERS += \
$$PWD/floatItemData/vpatternlabeldata.h \
$$PWD/floatItemData/vgrainlinedata.h \
$$PWD/floatItemData/vabstractfloatitemdata.h \
$$PWD/floatItemData/vabstractfloatitemdata_p.h
$$PWD/floatItemData/vabstractfloatitemdata_p.h \
$$PWD/floatItemData/vgrainlinedata_p.h \
$$PWD/floatItemData/floatitemdef.h

View File

@ -1307,7 +1307,7 @@ VPiece DialogSeamAllowance::CreatePiece() const
piece.GetGrainlineGeometry().SetVisible(ui->checkBoxGrainline->isChecked());
piece.GetGrainlineGeometry().SetRotation(GetFormulaFromUser(ui->lineEditRotFormula));
piece.GetGrainlineGeometry().SetLength(GetFormulaFromUser(ui->lineEditLenFormula));
piece.GetGrainlineGeometry().SetArrowType(VGrainlineData::ArrowType(ui->comboBoxArrow->currentIndex()));
piece.GetGrainlineGeometry().SetArrowType(static_cast<ArrowType>(ui->comboBoxArrow->currentIndex()));
return piece;
}

View File

@ -65,7 +65,7 @@ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent)
m_ptFinish(),
m_ptCenter(),
m_dAngle(0),
m_eArrowType(VGrainlineData::atBoth)
m_eArrowType(ArrowType::atBoth)
{
m_inactiveZ = 5;
Reset();
@ -107,7 +107,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption
QPolygonF poly;
QPointF ptA;
qreal dArrLen = ARROW_LENGTH*m_dScale;
if (m_eArrowType != VGrainlineData::atRear)
if (m_eArrowType != ArrowType::atRear)
{
// first arrow
poly << pt1;
@ -119,7 +119,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption
poly << ptA;
pP->drawPolygon(poly);
}
if (m_eArrowType != VGrainlineData::atFront)
if (m_eArrowType != ArrowType::atFront)
{
// second arrow
poly.clear();
@ -187,8 +187,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption
* @param dRotation rotation of the grainline in [degrees]
* @param dLength length of the grainline in user's units
*/
void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength,
VGrainlineData::ArrowType eAT)
void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, ArrowType eAT)
{
m_dRotation = qDegreesToRadians(dRotation);
m_dLength = dLength;

View File

@ -40,8 +40,7 @@ public:
virtual ~VGrainlineItem();
virtual void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget) Q_DECL_OVERRIDE;
void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength,
VGrainlineData::ArrowType eAT);
void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, ArrowType eAT);
bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const;
void SetScale(qreal dScale);
@ -75,7 +74,7 @@ private:
QPointF m_ptFinish;
QPointF m_ptCenter;
qreal m_dAngle;
VGrainlineData::ArrowType m_eArrowType;
ArrowType m_eArrowType;
};
#endif // VGRAINLINEITEM_H