diff --git a/src/app/container/container.pri b/src/app/container/container.pri index a9e5de22f..2aca23641 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -23,4 +23,5 @@ HEADERS += \ container/vcurvelength.h \ container/varclength.h \ container/vlinelength.h \ - container/vsplinelength.h + container/vsplinelength.h \ + container/vinternalvariable_p.h diff --git a/src/app/container/varclength.cpp b/src/app/container/varclength.cpp index f05805c86..cbd815e1d 100644 --- a/src/app/container/varclength.cpp +++ b/src/app/container/varclength.cpp @@ -34,14 +34,14 @@ VArcLength::VArcLength() :VCurveLength() { - type = VarType::ArcLength; + SetType(VarType::ArcLength); } //--------------------------------------------------------------------------------------------------------------------- VArcLength::VArcLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *arc) :VCurveLength(id, parentId, arc) { - type = VarType::ArcLength; + SetType(VarType::ArcLength); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 98ca648b6..94c2f21ae 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -96,12 +96,9 @@ void VContainer::setData(const VContainer &data) heightName = data.HeightName(); { ClearGObjects(); - const QHash *obj = data.DataGObjects(); - SCASSERT(obj != nullptr); - QHashIterator i(*obj); - while (i.hasNext()) + QHash::const_iterator i; + for (i = data.gObjects.constBegin(); i != data.gObjects.constEnd(); ++i) { - i.next(); switch (i.value()->getType()) { case (GOType::Arc): @@ -125,12 +122,9 @@ void VContainer::setData(const VContainer &data) { ClearVariables(); - const QHash *vars = data.DataVariables(); - SCASSERT(vars != nullptr); - QHashIterator i(*vars); - while (i.hasNext()) + QHash::const_iterator i; + for (i = data.variables.constBegin(); i != data.variables.constEnd(); ++i) { - i.next(); switch (i.value()->GetType()) { case (VarType::Measurement): diff --git a/src/app/container/vcurvelength.cpp b/src/app/container/vcurvelength.cpp index a9c0cf389..6d2d62e08 100644 --- a/src/app/container/vcurvelength.cpp +++ b/src/app/container/vcurvelength.cpp @@ -34,17 +34,17 @@ VCurveLength::VCurveLength() :VInternalVariable(), id(NULL_ID), parentId(NULL_ID) { - type = VarType::Unknown; + SetType(VarType::Unknown); } //--------------------------------------------------------------------------------------------------------------------- VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve) :VInternalVariable(), id(id), parentId(parentId) { - type = VarType::Unknown; + SetType(VarType::Unknown); SCASSERT(curve != nullptr); - name = curve->name(); - value = qApp->fromPixel(curve->GetLength()); + SetName(curve->name()); + SetValue(qApp->fromPixel(curve->GetLength())); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/container/vincrement.cpp b/src/app/container/vincrement.cpp index e45888bcd..4bfce0166 100644 --- a/src/app/container/vincrement.cpp +++ b/src/app/container/vincrement.cpp @@ -36,7 +36,7 @@ VIncrement::VIncrement() :VVariable(), id(NULL_ID) { - type = VarType::Increment; + SetType(VarType::Increment); } //--------------------------------------------------------------------------------------------------------------------- @@ -52,7 +52,7 @@ VIncrement::VIncrement() VIncrement::VIncrement(const QString &name, quint32 id, qreal base, qreal ksize, qreal kheight, QString description) :VVariable(name, base, ksize, kheight, description), id(id) { - type = VarType::Increment; + SetType(VarType::Increment); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/container/vinternalvariable.cpp b/src/app/container/vinternalvariable.cpp index df24534d4..cd2244cce 100644 --- a/src/app/container/vinternalvariable.cpp +++ b/src/app/container/vinternalvariable.cpp @@ -27,15 +27,16 @@ *************************************************************************/ #include "vinternalvariable.h" +#include "vinternalvariable_p.h" //--------------------------------------------------------------------------------------------------------------------- VInternalVariable::VInternalVariable() - :type(VarType::Unknown), value(0), name(QString()) + :d(new VInternalVariableData) {} //--------------------------------------------------------------------------------------------------------------------- VInternalVariable::VInternalVariable(const VInternalVariable &var) - :type(var.GetType()), value(var.GetValue()), name(var.GetName()) + :d(var.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -45,9 +46,7 @@ VInternalVariable &VInternalVariable::operator=(const VInternalVariable &var) { return *this; } - this->type = var.GetType(); - this->value = var.GetValue(); - this->name = var.GetName(); + d = var.d; return *this; } @@ -61,3 +60,45 @@ bool VInternalVariable::Filter(quint32 id) Q_UNUSED(id); return false; } + +//--------------------------------------------------------------------------------------------------------------------- +qreal VInternalVariable::GetValue() const +{ + return d->value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal *VInternalVariable::GetValue() +{ + return &d->value; +} + +void VInternalVariable::SetValue(const qreal &value) +{ + d->value = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VInternalVariable::GetName() const +{ + return d->name; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VInternalVariable::SetName(const QString &name) +{ + d->name = name; +} + +//--------------------------------------------------------------------------------------------------------------------- +VarType VInternalVariable::GetType() const +{ + return d->type; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VInternalVariable::SetType(const VarType &type) +{ + d->type = type; +} diff --git a/src/app/container/vinternalvariable.h b/src/app/container/vinternalvariable.h index cc34ff963..939a6d272 100644 --- a/src/app/container/vinternalvariable.h +++ b/src/app/container/vinternalvariable.h @@ -30,8 +30,10 @@ #define VINTERNALVARIABLE_H #include +#include +#include "../options.h" -enum class VarType : char { Measurement, Increment, LineLength, SplineLength, ArcLength, LineAngle, Unknown }; +class VInternalVariableData; class VInternalVariable { @@ -43,41 +45,17 @@ public: qreal GetValue() const; qreal* GetValue(); + void SetValue(const qreal &value); + QString GetName() const; + void SetName(const QString &name); + VarType GetType() const; + void SetType(const VarType &type); virtual bool Filter(quint32 id); -protected: - VarType type; - - /** @brief value variable's value */ - qreal value; - - QString name; +private: + QSharedDataPointer d; }; -//--------------------------------------------------------------------------------------------------------------------- -inline qreal VInternalVariable::GetValue() const -{ - return value; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline qreal *VInternalVariable::GetValue() -{ - return &value; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline QString VInternalVariable::GetName() const -{ - return name; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline VarType VInternalVariable::GetType() const -{ - return type; -} - #endif // VINTERNALVARIABLE_H diff --git a/src/app/container/vinternalvariable_p.h b/src/app/container/vinternalvariable_p.h new file mode 100644 index 000000000..c41c2b4cc --- /dev/null +++ b/src/app/container/vinternalvariable_p.h @@ -0,0 +1,58 @@ +/************************************************************************ + ** + ** @file vinternalvariable_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 VINTERNALVARIABLE_P_H +#define VINTERNALVARIABLE_P_H + +#include +#include "../options.h" + +class VInternalVariableData : public QSharedData +{ +public: + + VInternalVariableData() + :type(VarType::Unknown), value(0), name(QString()) + {} + + VInternalVariableData(const VInternalVariableData &var) + :QSharedData(var), type(var.type), value(var.value), name(var.name) + {} + + virtual ~VInternalVariableData() {} + + VarType type; + + /** @brief value variable's value */ + qreal value; + + QString name; +}; + + +#endif // VINTERNALVARIABLE_P_H diff --git a/src/app/container/vlineangle.cpp b/src/app/container/vlineangle.cpp index 01396d224..c05fcea6d 100644 --- a/src/app/container/vlineangle.cpp +++ b/src/app/container/vlineangle.cpp @@ -36,19 +36,19 @@ VLineAngle::VLineAngle() :VInternalVariable(), p1Id(NULL_ID), p2Id(NULL_ID) { - type = VarType::LineAngle; + SetType(VarType::LineAngle); } //--------------------------------------------------------------------------------------------------------------------- VLineAngle::VLineAngle(const VPointF *p1, const quint32 &p1Id, const VPointF *p2, const quint32 &p2Id) :VInternalVariable(), p1Id(p1Id), p2Id(p2Id) { - type = VarType::LineAngle; + SetType(VarType::LineAngle); SCASSERT(p1 != nullptr); SCASSERT(p2 != nullptr); - name = QString(angleLine_+"%1_%2").arg(p1->name(), p2->name()); + SetName(QString(angleLine_+"%1_%2").arg(p1->name(), p2->name())); SetValue(p1, p2); } @@ -85,5 +85,5 @@ void VLineAngle::SetValue(const VPointF *p1, const VPointF *p2) { SCASSERT(p1 != nullptr); SCASSERT(p2 != nullptr); - value = QLineF(p1->toQPointF(), p2->toQPointF()).angle(); + VInternalVariable::SetValue(QLineF(p1->toQPointF(), p2->toQPointF()).angle()); } diff --git a/src/app/container/vlinelength.cpp b/src/app/container/vlinelength.cpp index 886d63a89..7ba87a8b3 100644 --- a/src/app/container/vlinelength.cpp +++ b/src/app/container/vlinelength.cpp @@ -36,7 +36,7 @@ VLengthLine::VLengthLine() :VInternalVariable(), p1Id(NULL_ID), p2Id(NULL_ID) { - type = VarType::LineLength; + SetType(VarType::LineLength); } //--------------------------------------------------------------------------------------------------------------------- @@ -46,8 +46,8 @@ VLengthLine::VLengthLine(const VPointF *p1, const quint32 &p1Id, const VPointF * SCASSERT(p1 != nullptr); SCASSERT(p2 != nullptr); - type = VarType::LineLength; - name = QString(line_+"%1_%2").arg(p1->name(), p2->name()); + SetType(VarType::LineLength); + SetName(QString(line_+"%1_%2").arg(p1->name(), p2->name())); SetValue(p1, p2); } @@ -85,5 +85,5 @@ void VLengthLine::SetValue(const VPointF *p1, const VPointF *p2) SCASSERT(p1 != nullptr); SCASSERT(p2 != nullptr); - value = qApp->fromPixel(QLineF(p1->toQPointF(), p2->toQPointF()).length()); + VInternalVariable::SetValue(qApp->fromPixel(QLineF(p1->toQPointF(), p2->toQPointF()).length())); } diff --git a/src/app/container/vmeasurement.cpp b/src/app/container/vmeasurement.cpp index a93ef1a41..183876659 100644 --- a/src/app/container/vmeasurement.cpp +++ b/src/app/container/vmeasurement.cpp @@ -37,7 +37,7 @@ VMeasurement::VMeasurement() :VVariable(), gui_text(QString()), _tagName(QString()) { - type = VarType::Measurement; + SetType(VarType::Measurement); } //--------------------------------------------------------------------------------------------------------------------- @@ -55,7 +55,7 @@ VMeasurement::VMeasurement(const QString &name, const qreal &base, const qreal & const QString &gui_text, const QString &description, const QString &tagName) :VVariable(name, base, ksize, kheight, description), gui_text(gui_text), _tagName(tagName) { - type = VarType::Measurement; + SetType(VarType::Measurement); } //--------------------------------------------------------------------------------------------------------------------- @@ -71,7 +71,7 @@ VMeasurement::VMeasurement(const QString &name, const qreal &base, const QString const QString &tagName) :VVariable(name, base, description), gui_text(gui_text), _tagName(tagName) { - type = VarType::Measurement; + SetType(VarType::Measurement); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/container/vsplinelength.cpp b/src/app/container/vsplinelength.cpp index de7af7520..ae92567e7 100644 --- a/src/app/container/vsplinelength.cpp +++ b/src/app/container/vsplinelength.cpp @@ -34,15 +34,15 @@ VSplineLength::VSplineLength() :VCurveLength() { - type = VarType::SplineLength; + SetType(VarType::SplineLength); } VSplineLength::VSplineLength(const quint32 &id, const quint32 &parentId, const QString &name, const qreal &value) :VCurveLength() { - type = VarType::SplineLength; - this->name = name; - this->value = value; + SetType(VarType::SplineLength); + SetName(name); + SetValue(value); this->id = id; this->parentId = parentId; } @@ -51,7 +51,7 @@ VSplineLength::VSplineLength(const quint32 &id, const quint32 &parentId, const Q VSplineLength::VSplineLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *path) :VCurveLength(id, parentId, path) { - type = VarType::SplineLength; + SetType(VarType::SplineLength); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/container/vvariable.cpp b/src/app/container/vvariable.cpp index dfa30be83..2e322fcf9 100644 --- a/src/app/container/vvariable.cpp +++ b/src/app/container/vvariable.cpp @@ -35,7 +35,7 @@ VVariable::VVariable() :VInternalVariable(), base(0), ksize(0), kheight(0), description(QString()) { Init(); - value = base; + VInternalVariable::SetValue(base); } //--------------------------------------------------------------------------------------------------------------------- @@ -43,8 +43,8 @@ VVariable::VVariable(const QString &name, const qreal &base, const qreal &ksize, const QString &description) :VInternalVariable(), base(base), ksize(ksize), kheight(kheight), description(description) { - value = base; - this->name = name; + VInternalVariable::SetValue(base); + SetName(name); } //--------------------------------------------------------------------------------------------------------------------- @@ -52,8 +52,8 @@ VVariable::VVariable(const QString &name, const qreal &base, const QString &desc :base(base), ksize(0), kheight(0), description(description) { Init(); - value = base; - this->name = name; + VInternalVariable::SetValue(base); + SetName(name); } //--------------------------------------------------------------------------------------------------------------------- @@ -97,7 +97,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; - value = base + k_size * ksize + k_height * kheight; + VInternalVariable::SetValue(base + k_size * ksize + k_height * kheight); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/options.h b/src/app/options.h index 7cfebe1f2..2baec9341 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -80,6 +80,7 @@ enum class Contour : char { OpenContour, CloseContour }; enum class EquidistantType : char { OpenEquidistant, CloseEquidistant }; enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown }; enum class SplinePointPosition : char { FirstPoint, LastPoint }; +enum class VarType : char { Measurement, Increment, LineLength, SplineLength, ArcLength, LineAngle, Unknown }; enum class GHeights : unsigned char { ALL, H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134,