From f36a4d66210defd1f1711090934a2fe07c59bda2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 23 Feb 2017 14:04:49 +0200 Subject: [PATCH] Copy-on-write for class VGrainlineData. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 3 +- src/libs/vlayout/vlayoutpiece.cpp | 4 +- .../vpatterndb/floatItemData/floatitemdef.h | 41 +++++++++ .../floatItemData/vgrainlinedata.cpp | 52 +++++++----- .../vpatterndb/floatItemData/vgrainlinedata.h | 28 ++---- .../floatItemData/vgrainlinedata_p.h | 85 +++++++++++++++++++ src/libs/vpatterndb/vpatterndb.pri | 4 +- .../dialogs/tools/dialogseamallowance.cpp | 2 +- src/libs/vwidgets/vgrainlineitem.cpp | 9 +- src/libs/vwidgets/vgrainlineitem.h | 5 +- 10 files changed, 180 insertions(+), 53 deletions(-) create mode 100644 src/libs/vpatterndb/floatItemData/floatitemdef.h create mode 100644 src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index deb68b924..15a349c66 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -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(GetParametrUInt(domElement, AttrArrows, "0")); detail.GetGrainlineGeometry().SetArrowType(eAT); } diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 30a4063a1..3102eaabb 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -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; diff --git a/src/libs/vpatterndb/floatItemData/floatitemdef.h b/src/libs/vpatterndb/floatItemData/floatitemdef.h new file mode 100644 index 000000000..415d3d633 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/floatitemdef.h @@ -0,0 +1,41 @@ +/************************************************************************ + ** + ** @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 FLOATITEMDEF_H +#define FLOATITEMDEF_H + +// denotes the type of arrow for the grainline +enum class ArrowType : char +{ + atBoth, + atFront, + atRear +}; + +#endif // FLOATITEMDEF_H + diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp index 4650cae7e..de189c075 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp @@ -29,18 +29,32 @@ #include #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; } diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h index 01218c1c5..dc259bf0e 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata.h +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h @@ -33,6 +33,9 @@ #include #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 d; }; #endif // VGRAINLINEGEOMETRY_H diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h new file mode 100644 index 000000000..cb85be652 --- /dev/null +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h @@ -0,0 +1,85 @@ +/************************************************************************ + ** + ** @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 VGRAINLINEDATA_P_H +#define VGRAINLINEDATA_P_H + +#include +#include + +#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 + diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index a73ab5504..ffed4e24e 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -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 diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 2f860f7d1..99bd96674 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -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(ui->comboBoxArrow->currentIndex())); return piece; } diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index c0c8f90d8..d1e92f9b9 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -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; diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index a7b9ea89e..4a0c445b2 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -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