From 2557cb1133f08ddb33f352f457995d113a450e2b Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 20 Aug 2014 20:33:13 +0300 Subject: [PATCH] Implicit Sharing for class VLengthLine. --HG-- branch : develop --- src/app/container/container.pri | 3 +- src/app/container/vlinelength.cpp | 24 +++++++++---- src/app/container/vlinelength.h | 16 ++------- src/app/container/vlinelength_p.h | 58 +++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 src/app/container/vlinelength_p.h diff --git a/src/app/container/container.pri b/src/app/container/container.pri index ca4244197..b60b99618 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -28,4 +28,5 @@ HEADERS += \ container/vvariable_p.h \ container/vincrement_p.h \ container/vcurvelength_p.h \ - container/vlineangle_p.h + container/vlineangle_p.h \ + container/vlinelength_p.h diff --git a/src/app/container/vlinelength.cpp b/src/app/container/vlinelength.cpp index 7ba87a8b3..cc9b9ea14 100644 --- a/src/app/container/vlinelength.cpp +++ b/src/app/container/vlinelength.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "vlinelength.h" +#include "vlinelength_p.h" #include "../geometry/vpointf.h" #include "../widgets/vapplication.h" @@ -34,14 +35,14 @@ //--------------------------------------------------------------------------------------------------------------------- VLengthLine::VLengthLine() - :VInternalVariable(), p1Id(NULL_ID), p2Id(NULL_ID) + :VInternalVariable(), d(new VLengthLineData) { SetType(VarType::LineLength); } //--------------------------------------------------------------------------------------------------------------------- VLengthLine::VLengthLine(const VPointF *p1, const quint32 &p1Id, const VPointF *p2, const quint32 &p2Id) - :VInternalVariable(), p1Id(p1Id), p2Id(p2Id) + :VInternalVariable(), d(new VLengthLineData(p1Id, p2Id)) { SCASSERT(p1 != nullptr); SCASSERT(p2 != nullptr); @@ -53,7 +54,7 @@ VLengthLine::VLengthLine(const VPointF *p1, const quint32 &p1Id, const VPointF * //--------------------------------------------------------------------------------------------------------------------- VLengthLine::VLengthLine(const VLengthLine &var) - :VInternalVariable(var), p1Id(var.GetP1Id()), p2Id(var.GetP2Id()) + :VInternalVariable(var), d(var.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -64,8 +65,7 @@ VLengthLine &VLengthLine::operator=(const VLengthLine &var) return *this; } VInternalVariable::operator=(var); - this->p1Id = var.GetP1Id(); - this->p2Id = var.GetP2Id(); + d = var.d; return *this; } @@ -76,7 +76,7 @@ VLengthLine::~VLengthLine() //--------------------------------------------------------------------------------------------------------------------- bool VLengthLine::Filter(quint32 id) { - return id == p1Id || id == p2Id; + return id == d->p1Id || id == d->p2Id; } //--------------------------------------------------------------------------------------------------------------------- @@ -87,3 +87,15 @@ void VLengthLine::SetValue(const VPointF *p1, const VPointF *p2) VInternalVariable::SetValue(qApp->fromPixel(QLineF(p1->toQPointF(), p2->toQPointF()).length())); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VLengthLine::GetP1Id() const +{ + return d->p1Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VLengthLine::GetP2Id() const +{ + return d->p2Id; +} diff --git a/src/app/container/vlinelength.h b/src/app/container/vlinelength.h index c698a273c..77311283c 100644 --- a/src/app/container/vlinelength.h +++ b/src/app/container/vlinelength.h @@ -32,6 +32,7 @@ #include "vinternalvariable.h" class VPointF; +class VLengthLineData; class VLengthLine :public VInternalVariable { @@ -47,20 +48,7 @@ public: quint32 GetP1Id() const; quint32 GetP2Id() const; private: - quint32 p1Id; - quint32 p2Id; + QSharedDataPointer d; }; -//--------------------------------------------------------------------------------------------------------------------- -inline quint32 VLengthLine::GetP1Id() const -{ - return p1Id; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline quint32 VLengthLine::GetP2Id() const -{ - return p2Id; -} - #endif // VLINELENGTH_H diff --git a/src/app/container/vlinelength_p.h b/src/app/container/vlinelength_p.h new file mode 100644 index 000000000..8388b2ba5 --- /dev/null +++ b/src/app/container/vlinelength_p.h @@ -0,0 +1,58 @@ +/************************************************************************ + ** + ** @file vlinelength_p.h + ** @author Roman Telezhynskyi + ** @date 20 8, 2014 + ** + ** @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) 2014 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 VLINELENGTH_P_H +#define VLINELENGTH_P_H + +#include +#include "../options.h" + +class VLengthLineData : public QSharedData +{ +public: + + VLengthLineData() + :p1Id(NULL_ID), p2Id(NULL_ID) + {} + + VLengthLineData(const quint32 &p1Id, const quint32 &p2Id) + :p1Id(p1Id), p2Id(p2Id) + {} + + VLengthLineData(const VLengthLineData &var) + :QSharedData(var), p1Id(var.p1Id), p2Id(var.p2Id) + {} + + virtual ~VLengthLineData() {} + + quint32 p1Id; + quint32 p2Id; +}; + + +#endif // VLINELENGTH_P_H