diff --git a/src/app/container/container.pri b/src/app/container/container.pri index 626222518..c4850fc17 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -14,7 +14,8 @@ SOURCES += \ $$PWD/variables/vlinelength.cpp \ $$PWD/variables/vsplinelength.cpp \ $$PWD/vformula.cpp \ - $$PWD/variables/varcradius.cpp + $$PWD/variables/varcradius.cpp \ + $$PWD/variables/vcurvevariable.cpp HEADERS += \ $$PWD/vcontainer.h \ @@ -32,10 +33,10 @@ HEADERS += \ $$PWD/variables/vinternalvariable_p.h \ $$PWD/variables/vvariable_p.h \ $$PWD/variables/vincrement_p.h \ - $$PWD/variables/vcurvelength_p.h \ $$PWD/variables/vlineangle_p.h \ $$PWD/variables/vlinelength_p.h \ $$PWD/variables/vmeasurement_p.h \ $$PWD/vformula.h \ $$PWD/variables/varcradius.h \ - $$PWD/variables/varcradius_p.h + $$PWD/variables/vcurvevariable.h \ + $$PWD/variables/vcurvevariable_p.h diff --git a/src/app/container/variables/varcradius.cpp b/src/app/container/variables/varcradius.cpp index 6a10b2ac0..3f808669d 100644 --- a/src/app/container/variables/varcradius.cpp +++ b/src/app/container/variables/varcradius.cpp @@ -27,33 +27,30 @@ *************************************************************************/ #include "varcradius.h" -#include "varcradius_p.h" #include "../libs/vgeometry/varc.h" #include "../core/vapplication.h" -#include - //--------------------------------------------------------------------------------------------------------------------- VArcRadius::VArcRadius() - :VInternalVariable(), d(new VArcRadiusData) + :VCurveVariable() { SetType(VarType::ArcRadius); } //--------------------------------------------------------------------------------------------------------------------- -VArcRadius::VArcRadius(const VArc *arc, quint32 arcId) - :VInternalVariable(), d(new VArcRadiusData(arcId)) +VArcRadius::VArcRadius(const quint32 &id, const quint32 &parentId, const VArc *arc) + :VCurveVariable(id, parentId) { SCASSERT(arc != nullptr); SetType(VarType::ArcRadius); SetName(QString(radiusArc_+"%1").arg(arc->name())); - SetValue(arc); + SetValue(qApp->fromPixel(arc->GetRadius())); } //--------------------------------------------------------------------------------------------------------------------- VArcRadius::VArcRadius(const VArcRadius &var) - :VInternalVariable(var), d(var.d) + :VCurveVariable(var) {} //--------------------------------------------------------------------------------------------------------------------- @@ -63,31 +60,10 @@ VArcRadius &VArcRadius::operator=(const VArcRadius &var) { return *this; } - VInternalVariable::operator=(var); - d = var.d; + VCurveVariable::operator=(var); return *this; } //--------------------------------------------------------------------------------------------------------------------- VArcRadius::~VArcRadius() {} - -//--------------------------------------------------------------------------------------------------------------------- -bool VArcRadius::Filter(quint32 id) -{ - return id == d->arcId; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VArcRadius::SetValue(const VArc *arc) -{ - SCASSERT(arc != nullptr); - - VInternalVariable::SetValue(qApp->fromPixel(arc->GetRadius())); -} - -//--------------------------------------------------------------------------------------------------------------------- -quint32 VArcRadius::GetArcId() const -{ - return d->arcId; -} diff --git a/src/app/container/variables/varcradius.h b/src/app/container/variables/varcradius.h index a620c7114..0b32afb21 100644 --- a/src/app/container/variables/varcradius.h +++ b/src/app/container/variables/varcradius.h @@ -29,25 +29,18 @@ #ifndef VARCRADIUS_H #define VARCRADIUS_H -#include "vinternalvariable.h" +#include "vcurvevariable.h" class VArc; -class VArcRadiusData; -class VArcRadius :public VInternalVariable +class VArcRadius :public VCurveVariable { public: VArcRadius(); - VArcRadius(const VArc *arc, quint32 arcId); + VArcRadius(const quint32 &id, const quint32 &parentId, const VArc *arc); VArcRadius(const VArcRadius &var); VArcRadius &operator=(const VArcRadius &var); virtual ~VArcRadius(); - - virtual bool Filter(quint32 id); - void SetValue(const VArc *arc); - quint32 GetArcId() const; -private: - QSharedDataPointer d; }; #endif // VARCRADIUS_H diff --git a/src/app/container/variables/vcurvelength.cpp b/src/app/container/variables/vcurvelength.cpp index fa0afb16d..3382806c9 100644 --- a/src/app/container/variables/vcurvelength.cpp +++ b/src/app/container/variables/vcurvelength.cpp @@ -27,20 +27,19 @@ *************************************************************************/ #include "vcurvelength.h" -#include "vcurvelength_p.h" #include "../core/vapplication.h" #include "../libs/vgeometry/vabstractcurve.h" //--------------------------------------------------------------------------------------------------------------------- VCurveLength::VCurveLength() - :VInternalVariable(), d(new VCurveLengthData) + :VCurveVariable() { SetType(VarType::Unknown); } //--------------------------------------------------------------------------------------------------------------------- VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve) - :VInternalVariable(), d(new VCurveLengthData(id, parentId)) + :VCurveVariable(id, parentId) { SetType(VarType::Unknown); SCASSERT(curve != nullptr); @@ -50,7 +49,7 @@ VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAb //--------------------------------------------------------------------------------------------------------------------- VCurveLength::VCurveLength(const VCurveLength &var) - :VInternalVariable(var), d(var.d) + :VCurveVariable(var) {} //--------------------------------------------------------------------------------------------------------------------- @@ -60,50 +59,10 @@ VCurveLength &VCurveLength::operator=(const VCurveLength &var) { return *this; } - VInternalVariable::operator=(var); - d = var.d; + VCurveVariable::operator=(var); return *this; } //--------------------------------------------------------------------------------------------------------------------- VCurveLength::~VCurveLength() {} - -//--------------------------------------------------------------------------------------------------------------------- -bool VCurveLength::Filter(quint32 id) -{ - if (d->parentId != 0)//Do not check if value zero - {// Not all curves have parents. Only those who was created after cutting the parent curve. - return d->id == id || d->parentId == id; - } - else - { - return d->id == id; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -quint32 VCurveLength::GetId() const -{ - return d->id; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VCurveLength::SetId(const quint32 &id) -{ - d->id = id; -} - -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -quint32 VCurveLength::GetParentId() const -{ - return d->parentId; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VCurveLength::SetParentId(const quint32 &value) -{ - d->parentId = value; -} diff --git a/src/app/container/variables/vcurvelength.h b/src/app/container/variables/vcurvelength.h index 47e566cc3..212331a7c 100644 --- a/src/app/container/variables/vcurvelength.h +++ b/src/app/container/variables/vcurvelength.h @@ -29,12 +29,11 @@ #ifndef VCURVELENGTH_H #define VCURVELENGTH_H -#include "vinternalvariable.h" +#include "vcurvevariable.h" class VAbstractCurve; -class VCurveLengthData; -class VCurveLength : public VInternalVariable +class VCurveLength : public VCurveVariable { public: VCurveLength(); @@ -42,16 +41,6 @@ public: VCurveLength(const VCurveLength &var); VCurveLength &operator=(const VCurveLength &var); virtual ~VCurveLength(); - - virtual bool Filter(quint32 id); - - quint32 GetId() const; - void SetId(const quint32 &id); - - quint32 GetParentId() const; - void SetParentId(const quint32 &value); -private: - QSharedDataPointer d; }; #endif // VCURVELENGTH_H diff --git a/src/app/container/variables/vcurvevariable.cpp b/src/app/container/variables/vcurvevariable.cpp new file mode 100644 index 000000000..0ea24ec04 --- /dev/null +++ b/src/app/container/variables/vcurvevariable.cpp @@ -0,0 +1,106 @@ +/************************************************************************ + ** + ** @file vcurvelength.cpp + ** @author Roman Telezhynskyi + ** @date 15 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) 2013-2015 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 . + ** + *************************************************************************/ + +#include "vcurvevariable.h" +#include "vcurvevariable_p.h" +#include "../core/vapplication.h" +#include "../libs/vgeometry/vabstractcurve.h" + +//--------------------------------------------------------------------------------------------------------------------- +VCurveVariable::VCurveVariable() + :VInternalVariable(), d(new VCurveVariableData) +{ + SetType(VarType::Unknown); +} + +//--------------------------------------------------------------------------------------------------------------------- +VCurveVariable::VCurveVariable(const quint32 &id, const quint32 &parentId) + :VInternalVariable(), d(new VCurveVariableData(id, parentId)) +{ + SetType(VarType::Unknown); +} + +//--------------------------------------------------------------------------------------------------------------------- +VCurveVariable::VCurveVariable(const VCurveVariable &var) + :VInternalVariable(var), d(var.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VCurveVariable &VCurveVariable::operator=(const VCurveVariable &var) +{ + if ( &var == this ) + { + return *this; + } + VInternalVariable::operator=(var); + d = var.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VCurveVariable::~VCurveVariable() +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VCurveVariable::Filter(quint32 id) +{ + if (d->parentId != 0)//Do not check if value zero + {// Not all curves have parents. Only those who was created after cutting the parent curve. + return d->id == id || d->parentId == id; + } + else + { + return d->id == id; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +quint32 VCurveVariable::GetId() const +{ + return d->id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCurveVariable::SetId(const quint32 &id) +{ + d->id = id; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +quint32 VCurveVariable::GetParentId() const +{ + return d->parentId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCurveVariable::SetParentId(const quint32 &value) +{ + d->parentId = value; +} diff --git a/src/app/container/variables/vcurvevariable.h b/src/app/container/variables/vcurvevariable.h new file mode 100644 index 000000000..7e29f9e02 --- /dev/null +++ b/src/app/container/variables/vcurvevariable.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file vcurvelength.h + ** @author Roman Telezhynskyi + ** @date 15 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) 2013-2015 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 VCURVEVARIABLE_H +#define VCURVEVARIABLE_H + +#include "vinternalvariable.h" + +class VAbstractCurve; +class VCurveVariableData; + +class VCurveVariable : public VInternalVariable +{ +public: + VCurveVariable(); + VCurveVariable(const quint32 &id, const quint32 &parentId); + VCurveVariable(const VCurveVariable &var); + VCurveVariable &operator=(const VCurveVariable &var); + virtual ~VCurveVariable(); + + virtual bool Filter(quint32 id); + + quint32 GetId() const; + void SetId(const quint32 &id); + + quint32 GetParentId() const; + void SetParentId(const quint32 &value); +private: + QSharedDataPointer d; +}; + +#endif // VCURVEVARIABLE_H diff --git a/src/app/container/variables/vcurvelength_p.h b/src/app/container/variables/vcurvevariable_p.h similarity index 86% rename from src/app/container/variables/vcurvelength_p.h rename to src/app/container/variables/vcurvevariable_p.h index 4e3b182e0..1da206ec8 100644 --- a/src/app/container/variables/vcurvelength_p.h +++ b/src/app/container/variables/vcurvevariable_p.h @@ -36,29 +36,29 @@ #pragma GCC diagnostic ignored "-Weffc++" #endif -class VCurveLengthData : public QSharedData +class VCurveVariableData : public QSharedData { public: - VCurveLengthData() + VCurveVariableData() :id(NULL_ID), parentId(NULL_ID) {} - VCurveLengthData(const quint32 &id, const quint32 &parentId) + VCurveVariableData(const quint32 &id, const quint32 &parentId) :id(id), parentId(parentId) {} - VCurveLengthData(const VCurveLengthData &var) + VCurveVariableData(const VCurveVariableData &var) :QSharedData(var), id(var.id), parentId(var.parentId) {} - virtual ~VCurveLengthData(); + virtual ~VCurveVariableData(); quint32 id; quint32 parentId; }; -VCurveLengthData::~VCurveLengthData() +VCurveVariableData::~VCurveVariableData() {} #ifdef Q_CC_GNU diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index ede4f8332..589eb5673 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -321,7 +321,7 @@ void VContainer::AddArc(const quint32 &arcId, const quint32 &parentId) AddCurveLength(arcId, parentId); const QSharedPointer arc = GeometricObject(arcId); - VArcRadius *radius = new VArcRadius(arc.data(), arcId); + VArcRadius *radius = new VArcRadius(arcId, parentId, arc.data()); AddVariable(radius->GetName(), radius); }