From 327705da4418ccda1559ba82033c3c5d659dee50 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 20 Aug 2014 19:21:42 +0300 Subject: [PATCH] Implicit Sharing for class VVariable. --HG-- branch : develop --- src/app/container/container.pri | 3 +- src/app/container/vincrement.h | 33 --------- src/app/container/vvariable.cpp | 87 ++++++++++++++++++++---- src/app/container/vvariable.h | 66 +++--------------- src/app/container/vvariable_p.h | 70 +++++++++++++++++++ src/app/dialogs/app/dialogincrements.cpp | 2 +- 6 files changed, 157 insertions(+), 104 deletions(-) create mode 100644 src/app/container/vvariable_p.h diff --git a/src/app/container/container.pri b/src/app/container/container.pri index 2aca23641..8438d1a65 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -24,4 +24,5 @@ HEADERS += \ container/varclength.h \ container/vlinelength.h \ container/vsplinelength.h \ - container/vinternalvariable_p.h + container/vinternalvariable_p.h \ + container/vvariable_p.h diff --git a/src/app/container/vincrement.h b/src/app/container/vincrement.h index 654daa982..866462ef5 100644 --- a/src/app/container/vincrement.h +++ b/src/app/container/vincrement.h @@ -46,9 +46,6 @@ public: quint32 getId() const; void setId(const quint32 &value); - void setKsize(const qreal &value); - void setKheight(const qreal &value); - void setDescription(const QString &value); private: /** @brief id each increment have unique identificator */ quint32 id; @@ -74,34 +71,4 @@ inline void VIncrement::setId(const quint32 &value) id = value; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setKsize set increment in sizes - * @param value value of increment - */ -inline void VIncrement::setKsize(const qreal &value) -{ - ksize = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setKheight set increment in growths - * @param value value of increment - */ -inline void VIncrement::setKheight(const qreal &value) -{ - kheight = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setDescription set description for row - * @param value description - */ -inline void VIncrement::setDescription(const QString &value) -{ - description = value; -} - #endif // VINCREMENTTABLEROW_H diff --git a/src/app/container/vvariable.cpp b/src/app/container/vvariable.cpp index 2e322fcf9..ee9282cb4 100644 --- a/src/app/container/vvariable.cpp +++ b/src/app/container/vvariable.cpp @@ -27,29 +27,30 @@ *************************************************************************/ #include "vvariable.h" +#include "vvariable_p.h" #include "../widgets/vapplication.h" #include "../xml/vabstractmeasurements.h" //--------------------------------------------------------------------------------------------------------------------- VVariable::VVariable() - :VInternalVariable(), base(0), ksize(0), kheight(0), description(QString()) + :VInternalVariable(), d(new VVariableData) { Init(); - VInternalVariable::SetValue(base); + VInternalVariable::SetValue(d->base); } //--------------------------------------------------------------------------------------------------------------------- VVariable::VVariable(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, const QString &description) - :VInternalVariable(), base(base), ksize(ksize), kheight(kheight), description(description) + :VInternalVariable(), d(new VVariableData(base, ksize, kheight, description)) { - VInternalVariable::SetValue(base); + VInternalVariable::SetValue(d->base); SetName(name); } //--------------------------------------------------------------------------------------------------------------------- VVariable::VVariable(const QString &name, const qreal &base, const QString &description) - :base(base), ksize(0), kheight(0), description(description) + :d(new VVariableData(base, description)) { Init(); VInternalVariable::SetValue(base); @@ -58,8 +59,7 @@ VVariable::VVariable(const QString &name, const qreal &base, const QString &desc //--------------------------------------------------------------------------------------------------------------------- VVariable::VVariable(const VVariable &var) - :VInternalVariable(var), base(var.GetBase()), ksize(var.GetKsize()), kheight(var.GetKheight()), - description(var.GetDescription()) + :VInternalVariable(var), d(var.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -70,10 +70,7 @@ VVariable &VVariable::operator=(const VVariable &var) return *this; } VInternalVariable::operator=(var); - this->base = var.GetBase(); - this->ksize = var.GetKsize(); - this->kheight = var.GetKheight(); - this->description = var.GetDescription(); + d = var.d; return *this; } @@ -97,7 +94,7 @@ void VVariable::SetValue(const qreal &size, const qreal &height) // Formula for calculation gradation const qreal k_size = ( size - baseSize ) / sizeIncrement; const qreal k_height = ( height - baseHeight ) / heightIncrement; - VInternalVariable::SetValue(base + k_size * ksize + k_height * kheight); + VInternalVariable::SetValue(d->base + k_size * d->ksize + k_height * d->kheight); } //--------------------------------------------------------------------------------------------------------------------- @@ -105,7 +102,69 @@ void VVariable::Init() { if (qApp->patternUnit() != Unit::Inch) { - ksize = VAbstractMeasurements::UnitConvertor(50.0, Unit::Cm, qApp->patternUnit()); - kheight = VAbstractMeasurements::UnitConvertor(176.0, Unit::Cm, qApp->patternUnit()); + d->ksize = VAbstractMeasurements::UnitConvertor(50.0, Unit::Cm, qApp->patternUnit()); + d->kheight = VAbstractMeasurements::UnitConvertor(176.0, Unit::Cm, qApp->patternUnit()); } } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetBase return value in base size and height + * @return value + */ +qreal VVariable::GetBase() const +{ + return d->base; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVariable::SetBase(const qreal &value) +{ + d->base = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetKsize return increment in sizes + * @return increment + */ +qreal VVariable::GetKsize() const +{ + return d->ksize; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVariable::SetKsize(const qreal &value) +{ + d->ksize = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetKheight return increment in heights + * @return increment + */ +qreal VVariable::GetKheight() const +{ + return d->kheight; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VVariable::SetKheight(const qreal &value) +{ + d->kheight = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VVariable::GetDescription() const +{ + return d->description; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VVariable::SetDescription(const QString &desc) +{ + d->description = desc; +} diff --git a/src/app/container/vvariable.h b/src/app/container/vvariable.h index 84b17f95c..ea3e3297f 100644 --- a/src/app/container/vvariable.h +++ b/src/app/container/vvariable.h @@ -31,11 +31,13 @@ #include "vinternalvariable.h" +class VVariableData; + class VVariable :public VInternalVariable { public: VVariable(); - VVariable(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, + VVariable(const QString &name, const qreal &base, const qreal &ksize = 0, const qreal &kheight = 0, const QString &description = QString()); VVariable(const QString &name, const qreal &base, const QString &description = QString()); VVariable(const VVariable &var); @@ -44,66 +46,20 @@ public: qreal GetBase() const; void SetBase(const qreal &value); + qreal GetKsize() const; + void SetKsize(const qreal &value); + qreal GetKheight() const; + void SetKheight(const qreal &value); + QString GetDescription() const; + void SetDescription(const QString &desc); + void SetValue(const qreal &size, const qreal &height); -protected: - /** @brief base value in base size and height */ - qreal base; - - /** @brief ksize increment in sizes */ - qreal ksize; - - /** @brief kgrowth increment in heights */ - qreal kheight; - - /** @brief description description of increment */ - QString description; private: + QSharedDataPointer d; void Init(); }; -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetBase return value in base size and height - * @return value - */ -inline qreal VVariable::GetBase() const -{ - return base; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline void VVariable::SetBase(const qreal &value) -{ - base = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetKsize return increment in sizes - * @return increment - */ -inline qreal VVariable::GetKsize() const -{ - return ksize; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetKheight return increment in heights - * @return increment - */ -inline qreal VVariable::GetKheight() const -{ - return kheight; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline QString VVariable::GetDescription() const -{ - return description; -} - #endif // VVARIABLE_H diff --git a/src/app/container/vvariable_p.h b/src/app/container/vvariable_p.h new file mode 100644 index 000000000..66c7d5e67 --- /dev/null +++ b/src/app/container/vvariable_p.h @@ -0,0 +1,70 @@ +/************************************************************************ + ** + ** @file vvariable_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 VVARIABLE_P_H +#define VVARIABLE_P_H + +#include +#include "../options.h" + +class VVariableData : public QSharedData +{ +public: + + VVariableData() + :base(0), ksize(0), kheight(0), description(QString()) + {} + + VVariableData(const qreal &base, const qreal &ksize, const qreal &kheight, const QString &description) + :base(base), ksize(ksize), kheight(kheight), description(description) + {} + + VVariableData(const qreal &base, const QString &description) + :base(base), ksize(0), kheight(0), description(description) + {} + + VVariableData(const VVariableData &var) + :QSharedData(var), base(var.base), ksize(var.ksize), kheight(var.kheight), description(var.description) + {} + + virtual ~VVariableData() {} + + /** @brief base value in base size and height */ + qreal base; + + /** @brief ksize increment in sizes */ + qreal ksize; + + /** @brief kgrowth increment in heights */ + qreal kheight; + + /** @brief description description of increment */ + QString description; +}; + +#endif // VVARIABLE_P_H diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index 3a43c85c1..494195f02 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -695,7 +695,7 @@ void DialogIncrements::IncrementChanged ( qint32 row, qint32 column ) { doc->SetAttribute(domElement, VPattern::IncrementDescription, item->text()); VIncrement *incr = data->GetVariable(itemName->text()); - incr->setDescription(item->text()); + incr->SetDescription(item->text()); ui->tableWidgetIncrement->resizeColumnsToContents(); ui->tableWidgetIncrement->resizeRowsToContents(); this->column = 0;