Implicit Sharing for class VInternalVariable.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-20 18:58:10 +03:00
parent cd03b8a473
commit 3c731d9f35
14 changed files with 151 additions and 78 deletions

View File

@ -23,4 +23,5 @@ HEADERS += \
container/vcurvelength.h \
container/varclength.h \
container/vlinelength.h \
container/vsplinelength.h
container/vsplinelength.h \
container/vinternalvariable_p.h

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -96,12 +96,9 @@ void VContainer::setData(const VContainer &data)
heightName = data.HeightName();
{
ClearGObjects();
const QHash<quint32, VGObject*> *obj = data.DataGObjects();
SCASSERT(obj != nullptr);
QHashIterator<quint32, VGObject*> i(*obj);
while (i.hasNext())
QHash<quint32, VGObject*>::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<QString, VInternalVariable*> *vars = data.DataVariables();
SCASSERT(vars != nullptr);
QHashIterator<QString, VInternalVariable*> i(*vars);
while (i.hasNext())
QHash<QString, VInternalVariable*>::const_iterator i;
for (i = data.variables.constBegin(); i != data.variables.constEnd(); ++i)
{
i.next();
switch (i.value()->GetType())
{
case (VarType::Measurement):

View File

@ -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()));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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;
}

View File

@ -30,8 +30,10 @@
#define VINTERNALVARIABLE_H
#include <QString>
#include <QSharedDataPointer>
#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<VInternalVariableData> 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

View File

@ -0,0 +1,58 @@
/************************************************************************
**
** @file vinternalvariable_p.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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 VINTERNALVARIABLE_P_H
#define VINTERNALVARIABLE_P_H
#include <QSharedData>
#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

View File

@ -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());
}

View File

@ -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()));
}

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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,