diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 66d4d947a..960649bfc 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -154,23 +154,23 @@ void Calculator::InitVariables(const VContainer *data) num +=2; } - const QHash *lengthLines = data->DataLengthLines(); - num += lengthLines->size(); + const QMap lengthLines = data->DataLengthLines(); + num += lengthLines.size(); - const QHash *lengthSplines = data->DataLengthSplines(); - num += lengthSplines->size(); + const QMap lengthSplines = data->DataLengthSplines(); + num += lengthSplines.size(); - const QHash *lengthArcs = data->DataLengthArcs(); - num += lengthArcs->size(); + const QMap lengthArcs = data->DataLengthArcs(); + num += lengthArcs.size(); - const QHash *lineAngles = data->DataLineAngles(); - num += lineAngles->size(); + const QMap lineAngles = data->DataLineAngles(); + num += lineAngles.size(); - const QHash *measurements = data->DataMeasurements(); - num += measurements->size(); + const QMap measurements = data->DataMeasurements(); + num += measurements.size(); - const QHash *increments = data->DataIncrements(); - num += increments->size(); + const QMap increments = data->DataIncrements(); + num += increments.size(); vVarVal = new qreal[num]; int j = 0; @@ -187,8 +187,8 @@ void Calculator::InitVariables(const VContainer *data) } { - QHash::const_iterator i = lengthLines->constBegin(); - while (i != lengthLines->constEnd()) + QMap::const_iterator i = lengthLines.constBegin(); + while (i != lengthLines.constEnd()) { vVarVal[j] = i.value(); DefineVar(i.key(), &vVarVal[j]); @@ -198,8 +198,8 @@ void Calculator::InitVariables(const VContainer *data) } { - QHash::const_iterator i = lengthSplines->constBegin(); - while (i != lengthSplines->constEnd()) + QMap::const_iterator i = lengthSplines.constBegin(); + while (i != lengthSplines.constEnd()) { vVarVal[j] = i.value(); DefineVar(i.key(), &vVarVal[j]); @@ -209,8 +209,8 @@ void Calculator::InitVariables(const VContainer *data) } { - QHash::const_iterator i = lengthArcs->constBegin(); - while (i != lengthArcs->constEnd()) + QMap::const_iterator i = lengthArcs.constBegin(); + while (i != lengthArcs.constEnd()) { vVarVal[j] = i.value(); DefineVar(i.key(), &vVarVal[j]); @@ -220,8 +220,8 @@ void Calculator::InitVariables(const VContainer *data) } { - QHash::const_iterator i = lineAngles->constBegin(); - while (i != lineAngles->constEnd()) + QMap::const_iterator i = lineAngles.constBegin(); + while (i != lineAngles.constEnd()) { vVarVal[j] = i.value(); DefineVar(i.key(), &vVarVal[j]); @@ -231,17 +231,15 @@ void Calculator::InitVariables(const VContainer *data) } { - QHash::const_iterator i = measurements->constBegin(); - while (i != measurements->constEnd()) + QMap::const_iterator i = measurements.constBegin(); + while (i != measurements.constEnd()) { + VMeasurement *m = i.value(); if (qApp->patternType() == MeasurementsType::Standard) { - vVarVal[j] = i.value().GetValue(data->size(), data->height()); - } - else - { - vVarVal[j] = i.value().GetValue(); + m->SetValue(data->size(), data->height()); } + vVarVal[j] = *m->GetValue(); DefineVar(i.key(), &vVarVal[j]); ++j; ++i; @@ -249,17 +247,15 @@ void Calculator::InitVariables(const VContainer *data) } { - QHash::const_iterator i = increments->constBegin(); - while (i != increments->constEnd()) + QMap::const_iterator i = increments.constBegin(); + while (i != increments.constEnd()) { + VIncrement *incr = i.value(); if (qApp->patternType() == MeasurementsType::Standard) { - vVarVal[j] = i.value().GetValue(data->size(), data->height()); - } - else - { - vVarVal[j] = i.value().GetValue(); + incr->SetValue(data->size(), data->height()); } + vVarVal[j] = *incr->GetValue(); DefineVar(i.key(), &vVarVal[j]); ++j; ++i; diff --git a/src/app/container/container.pri b/src/app/container/container.pri index 9a4d2b572..fed806e71 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -3,11 +3,22 @@ SOURCES += \ container/calculator.cpp \ container/vmeasurement.cpp \ container/vincrement.cpp \ - container/vvariable.cpp + container/vvariable.cpp \ + container/vinternalvariable.cpp \ + container/vlengthline.cpp \ + container/vlengthspline.cpp \ + container/vlengtharc.cpp \ + container/vlineangle.cpp HEADERS += \ container/vcontainer.h \ container/calculator.h \ container/vmeasurement.h \ container/vincrement.h \ - container/vvariable.h + container/vvariable.h \ + container/vinternalvariable.h \ + container/vlengthline.h \ + container/vlengthspline.h \ + container/vlengtharc.h \ + container/vlineangle.h \ + container/variables.h diff --git a/src/app/container/variables.h b/src/app/container/variables.h new file mode 100644 index 000000000..0dc78df57 --- /dev/null +++ b/src/app/container/variables.h @@ -0,0 +1,40 @@ +/************************************************************************ + ** + ** @file variables.h + ** @author Roman Telezhynskyi + ** @date 28 7, 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 VARIABLES_H +#define VARIABLES_H + +#include "vinternalvariable.h" +#include "vmeasurement.h" +#include "vincrement.h" +#include "vlengtharc.h" +#include "vlengthline.h" +#include "vlengthspline.h" +#include "vlineangle.h" + +#endif // VARIABLES_H diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index ee38703e4..89e42c9ed 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -41,11 +41,11 @@ quint32 VContainer::_id = 0; * @brief VContainer create empty container */ VContainer::VContainer() - :_size(50), sizeName(size_M), _height(176), heightName(height_M), gObjects(QHash()), - measurements(QHash()), increments(QHash()), - lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), - lengthArcs(QHash()), details(QHash()) -{} + :_size(50), sizeName(size_M), _height(176), heightName(height_M), + gObjects(QHash()), variables(QHash ()), + details(QHash()) +{ +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -69,10 +69,9 @@ VContainer &VContainer::operator =(const VContainer &data) * @param data container */ VContainer::VContainer(const VContainer &data) - :_size(50), sizeName(size_M), _height(176), heightName(height_M), gObjects(QHash()), - measurements(QHash()), increments(QHash()), - lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), - lengthArcs(QHash()), details(QHash()) + :_size(50), sizeName(size_M), _height(176), heightName(height_M), + gObjects(QHash()), variables(QHash ()), + details(QHash()) { setData(data); } @@ -80,8 +79,8 @@ VContainer::VContainer(const VContainer &data) //--------------------------------------------------------------------------------------------------------------------- VContainer::~VContainer() { - qDeleteAll(gObjects); - gObjects.clear(); + ClearGObjects(); + ClearVariables(); } //--------------------------------------------------------------------------------------------------------------------- @@ -95,40 +94,71 @@ void VContainer::setData(const VContainer &data) sizeName = data.SizeName(); _height = data.height(); heightName = data.HeightName(); - - qDeleteAll(gObjects); - gObjects.clear(); - const QHash *obj = data.DataGObjects(); - SCASSERT(obj != nullptr); - QHashIterator i(*obj); - while (i.hasNext()) { - i.next(); - switch (i.value()->getType()) + ClearGObjects(); + const QHash *obj = data.DataGObjects(); + SCASSERT(obj != nullptr); + QHashIterator i(*obj); + while (i.hasNext()) { - case (GOType::Arc): - CopyGObject(data, i.key()); - break; - case (GOType::Point): - CopyGObject(data, i.key()); - break; - case (GOType::Spline): - CopyGObject(data, i.key()); - break; - case (GOType::SplinePath): - CopyGObject(data, i.key()); - break; - default: - qDebug()<<"Don't know how copy this type."; - break; + i.next(); + switch (i.value()->getType()) + { + case (GOType::Arc): + CopyGObject(data, i.key()); + break; + case (GOType::Point): + CopyGObject(data, i.key()); + break; + case (GOType::Spline): + CopyGObject(data, i.key()); + break; + case (GOType::SplinePath): + CopyGObject(data, i.key()); + break; + default: + qDebug()<<"Don't know how copy this type."; + break; + } } } - measurements = *data.DataMeasurements(); - increments = *data.DataIncrements(); - lengthLines = *data.DataLengthLines(); - lineAngles = *data.DataLineAngles(); - lengthSplines = *data.DataLengthSplines(); - lengthArcs = *data.DataLengthArcs(); + + { + ClearVariables(); + const QHash *vars = data.DataVariables(); + SCASSERT(vars != nullptr); + QHashIterator i(*vars); + while (i.hasNext()) + { + i.next(); + switch (i.value()->GetType()) + { + case (VarType::Measurement): + CopyVar(data, i.key()); + break; + case (VarType::Increment): + CopyVar(data, i.key()); + break; + case (VarType::LengthLine): + CopyVar(data, i.key()); + break; + case (VarType::LengthSpline): + CopyVar(data, i.key()); + break; + case (VarType::LengthArc): + CopyVar(data, i.key()); + break; + case (VarType::LineAngle): + CopyVar(data, i.key()); + break; + case (VarType::Unknown): + default: + qDebug()<<"Don't know how copy this type."; + break; + } + } + } + details = *data.DataDetails(); } @@ -164,98 +194,6 @@ const val VContainer::GetObject(const QHash &obj, key id) const } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetObject return object from container - * @param obj container - * @param id id of object - * @return Object - */ -template -val VContainer::GetVariable(const QHash &obj, key id) const -{ - if (obj.contains(id)) - { - return obj.value(id); - } - else - { - throw VExceptionBadId(tr("Can't find object"), id); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetMeasurement return measurement by name - * @param name short measurement name - * @return measurement - */ -const VMeasurement VContainer::GetMeasurement(const QString &name) const -{ - SCASSERT(name.isEmpty()==false); - return GetVariable(measurements, name); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetIncrement return increment table row by name - * @param name name of increment table row - * @return increment - */ -const VIncrement VContainer::GetIncrement(const QString& name) const -{ - SCASSERT(name.isEmpty()==false); - return GetVariable(increments, name); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetLine return length of line by name - * @param name name of line - * @return length of line in mm - */ -qreal VContainer::GetLine(const QString &name) const -{ - SCASSERT(name.isEmpty()==false); - return GetVariable(lengthLines, name); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetLengthArc return length of arc by name - * @param name name of arc - * @return length of arc in mm - */ -qreal VContainer::GetLengthArc(const QString &name) const -{ - SCASSERT(name.isEmpty()==false); - return GetVariable(lengthArcs, name); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetLengthSpline return length of spline by name - * @param name name of spline - * @return length of spline in mm - */ -qreal VContainer::GetLengthSpline(const QString &name) const -{ - SCASSERT(name.isEmpty()==false); - return GetVariable(lengthSplines, name); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetLineAngle return angle of line - * @param name name of line angle - * @return angle in degree - */ -qreal VContainer::GetLineAngle(const QString &name) const -{ - SCASSERT(name.isEmpty()==false); - return GetVariable(lineAngles, name); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetDetail return detail by id @@ -264,7 +202,14 @@ qreal VContainer::GetLineAngle(const QString &name) const */ const VDetail VContainer::GetDetail(quint32 id) const { - return GetVariable(details, id); + if (details.contains(id)) + { + return details.value(id); + } + else + { + throw VExceptionBadId(tr("Can't find object"), id); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -291,17 +236,6 @@ quint32 VContainer::AddDetail(VDetail detail) return id; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddIncrement add new increment - * @param name increment name - * @param incr increment - */ -void VContainer::AddIncrement(const QString &name, VIncrement incr) -{ - increments[name] = incr; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief getNextId generate next unique id @@ -348,18 +282,6 @@ void VContainer::UpdateObject(QHash &obj, const quint32 &id, val p UpdateId(id); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddLengthSpline add length of spline to container - * @param name name of spline - * @param value length of spline - */ -void VContainer::AddLengthSpline(const QString &name, const qreal &value) -{ - SCASSERT(name.isEmpty() == false); - lengthSplines[name] = value; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddLengthArc add length of arc to container @@ -368,57 +290,7 @@ void VContainer::AddLengthSpline(const QString &name, const qreal &value) void VContainer::AddLengthArc(const quint32 &id) { const VArc * arc = GeometricObject(id); - lengthArcs[arc->name()] = qApp->fromPixel(arc->GetLength()); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddLineAngle add angle of line to container - * @param name name of line angle - * @param value angle in degree - */ -void VContainer::AddLineAngle(const QString &name, const qreal &value) -{ - SCASSERT(name.isEmpty() == false); - lineAngles[name] = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetValueStandardTableRow return value of measurement by name - * @param name name of measurement - * @return value in measurement units - */ -qreal VContainer::GetValueStandardTableRow(const QString& name) const -{ - const VMeasurement m = GetMeasurement(name); - if (qApp->patternType() == MeasurementsType::Individual) - { - return m.GetValue(); - } - else - { - return m.GetValue(size(), height()); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetValueIncrementTableRow return value of increment table row by name - * @param name name of row - * @return value of row in mm - */ -qreal VContainer::GetValueIncrementTableRow(const QString& name) const -{ - const VIncrement icr = GetIncrement(name); - if (qApp->patternType() == MeasurementsType::Individual) - { - return icr.GetValue(); - } - else - { - return icr.GetValue(size(), height()); - } + AddVariable(arc->name(), new VLengthArc(id, arc)); } //--------------------------------------------------------------------------------------------------------------------- @@ -428,13 +300,9 @@ qreal VContainer::GetValueIncrementTableRow(const QString& name) const void VContainer::Clear() { _id = 0; - measurements.clear(); - increments.clear(); - lengthLines.clear(); - lengthArcs.clear(); - lineAngles.clear(); + details.clear(); - lengthSplines.clear(); + ClearVariables(); ClearGObjects(); } @@ -444,10 +312,7 @@ void VContainer::Clear() */ void VContainer::ClearGObjects() { - if (gObjects.size()>0) - { - qDeleteAll(gObjects); - } + qDeleteAll(gObjects); gObjects.clear(); } @@ -469,6 +334,32 @@ void VContainer::ClearCalculationGObjects() } } +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::ClearVariables(const VarType &type) +{ + if (variables.size()>0) + { + if (type == VarType::Unknown) + { + qDeleteAll(variables); + variables.clear(); + } + else + { + QHashIterator i(variables); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == type) + { + delete i.value(); + variables.remove(i.key()); + } + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddLine add line to container @@ -477,12 +368,14 @@ void VContainer::ClearCalculationGObjects() */ void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPointId) { - QString nameLine = GetNameLine(firstPointId, secondPointId); const VPointF *first = GeometricObject(firstPointId); const VPointF *second = GeometricObject(secondPointId); - AddLengthLine(nameLine, qApp->fromPixel(QLineF(first->toQPointF(), second->toQPointF()).length())); - nameLine = GetNameLineAngle(firstPointId, secondPointId); - AddLineAngle(nameLine, QLineF(first->toQPointF(), second->toQPointF()).angle()); + + VLengthLine *length = new VLengthLine(first, firstPointId, second, secondPointId); + AddVariable(length->GetName(), length); + + VLineAngle *angle = new VLineAngle(first, firstPointId, second, secondPointId); + AddVariable(angle->GetName(), angle); } //--------------------------------------------------------------------------------------------------------------------- @@ -502,36 +395,6 @@ quint32 VContainer::AddObject(QHash &obj, val value) return id; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetNameLine return name of line - * @param firstPoint id of first point of line - * @param secondPoint id of second point of line - * @return name of line - */ -QString VContainer::GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const -{ - const VPointF *first = GeometricObject(firstPoint); - const VPointF *second = GeometricObject(secondPoint); - - return QString(line_+"%1_%2").arg(first->name(), second->name()); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetNameLineAngle return name of line angle - * @param firstPoint id of first point of line - * @param secondPoint id of second point of line - * @return name of angle of line - */ -QString VContainer::GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const -{ - const VPointF *first = GeometricObject(firstPoint); - const VPointF *second = GeometricObject(secondPoint); - - return QString(angleLine_+"%1_%2").arg(first->name(), second->name()); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief UpdateGObject update GObject by id @@ -558,13 +421,122 @@ void VContainer::UpdateDetail(quint32 id, const VDetail &detail) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddLengthLine add length of line to container - * @param name name of line - * @param value length of line - */ -void VContainer::AddLengthLine(const QString &name, const qreal &value) +qreal VContainer::GetTableValue(const QString &name) const { - SCASSERT(name.isEmpty() == false); - lengthLines[name] = value; + VVariable *m = GetVariable(name); + if (qApp->patternType() == MeasurementsType::Standard) + { + m->SetValue(size(), height()); + } + return *m->GetValue(); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief RemoveIncrement remove increment by name from increment table + * @param name name of existing increment + */ +void VContainer::RemoveIncrement(const QString &name) +{ + delete variables.value(name); + variables.remove(name); +} + +//--------------------------------------------------------------------------------------------------------------------- +const QMap VContainer::DataMeasurements() const +{ + return DataTableVar(VarType::Measurement); +} + +//--------------------------------------------------------------------------------------------------------------------- +const QMap VContainer::DataIncrements() const +{ + return DataTableVar(VarType::Increment); +} + +//--------------------------------------------------------------------------------------------------------------------- +const QMap VContainer::DataLengthLines() const +{ + return DataVar(VarType::LengthLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +const QMap VContainer::DataLengthSplines() const +{ + return DataVar(VarType::LengthSpline); +} + +//--------------------------------------------------------------------------------------------------------------------- +const QMap VContainer::DataLengthArcs() const +{ + return DataVar(VarType::LengthArc); +} + +//--------------------------------------------------------------------------------------------------------------------- +const QMap VContainer::DataLineAngles() const +{ + return DataVar(VarType::LineAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief IncrementTableContains check if increment table contains name + * @param name name of row + * @return true if contains + */ +bool VContainer::IncrementExist(const QString &name) +{ + return variables.contains(name); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VContainer::CopyGObject(const VContainer &data, const quint32 &id) +{ + T *obj = new T(*data.GeometricObject(id)); + UpdateGObject(id, obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VContainer::CopyVar(const VContainer &data, const QString &name) +{ + T *var = new T(*data.GetVariable(name)); + AddVariable(name, var); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMap VContainer::DataVar(const VarType &type) const +{ + QHashIterator i(variables); + QMap map; + //Sorting QHash by id + while (i.hasNext()) + { + i.next(); + if(i.value()->GetType() == type) + { + map.insert(qApp->VarToUser(i.key()), *i.value()->GetValue()); + } + } + return map; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +const QMap VContainer::DataTableVar(const VarType &type) const +{ + QHashIterator i(variables); + QMap map; + //Sorting QHash by id + while (i.hasNext()) + { + i.next(); + if(i.value()->GetType() == type) + { + T *var = GetVariable(i.key()); + map.insert(qApp->VarToUser(i.key()), var); + } + } + return map; } diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 8e5ba870f..3d6f94782 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -29,11 +29,11 @@ #ifndef VCONTAINER_H #define VCONTAINER_H -#include "vmeasurement.h" -#include "vincrement.h" +#include "variables.h" #include "../geometry/vdetail.h" #include "../geometry/vgobject.h" #include "../exception/vexceptionbadid.h" + #include #include @@ -48,13 +48,9 @@ public: VContainer &operator=(const VContainer &data); VContainer(const VContainer &data); ~VContainer(); - template - void CopyGObject(const VContainer &data, const quint32 &id) - { - T *obj = new T(*data.GeometricObject(id)); - UpdateGObject(id, obj); - } + void setData(const VContainer &data); + template const T GeometricObject(const quint32 &id) const { @@ -84,43 +80,79 @@ public: } const VGObject *GetGObject(quint32 id) const; - const VMeasurement GetMeasurement(const QString& name) const; - const VIncrement GetIncrement(const QString& name) const; - qreal GetLine(const QString &name) const; - qreal GetLengthArc(const QString &name) const; - qreal GetLengthSpline(const QString &name) const; - qreal GetLineAngle(const QString &name) const; const VDetail GetDetail(quint32 id) const; + qreal GetTableValue(const QString& name) const; + template + /** + * @brief GetVariable return varible by name + * @param name variable's name + * @return variable + */ + T GetVariable(QString name) const + { + SCASSERT(name.isEmpty()==false); + if (variables.contains(name)) + { + try + { + T value = dynamic_cast(variables.value(name)); + SCASSERT(value != nullptr); + return value; + } + catch (const std::bad_alloc &) + { + throw VExceptionBadId(tr("Can't cast object"), name); + return nullptr; + } + } + else + { + throw VExceptionBadId(tr("Can't find object"), name); + return nullptr; + } + } + static quint32 getId(){return _id;} + static quint32 getNextId(); + static void UpdateId(quint32 newId); + quint32 AddGObject(VGObject *obj); quint32 AddDetail(VDetail detail); - void AddMeasurement(const QString& name, const VMeasurement &m); - void AddIncrement(const QString& name, VIncrement incr); - void AddLengthLine(const QString &name, const qreal &value); - void AddLengthSpline(const QString &name, const qreal &value); void AddLengthArc(const quint32 &id); - void AddLineAngle(const QString &name, const qreal &value); void AddLine(const quint32 &firstPointId, const quint32 &secondPointId); - // cppcheck-suppress functionStatic - QString GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const; - // cppcheck-suppress functionStatic - QString GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const; + + template + void AddVariable(const QString& name, T var) + { + if(variables.contains(name)) + { + if(variables.value(name)->GetType() == var->GetType()) + { + T v = dynamic_cast(variables.value(name)); + SCASSERT(v != nullptr); + *v = *var; + delete var; + } + else + { + throw VExceptionBadId(tr("Can't find object. Type mismatch."), name); + } + } + else + { + variables[name] = var; + } + } + void UpdateGObject(quint32 id, VGObject* obj); void UpdateDetail(quint32 id, const VDetail &detail); - void UpdateMeasurement(const QString& name, VMeasurement m); - void UpdateIncrement(const QString& name, VIncrement incr); - qreal GetValueStandardTableRow(const QString& name) const; - qreal GetValueIncrementTableRow(const QString& name) const; + void Clear(); void ClearGObjects(); void ClearCalculationGObjects(); - void ClearIncrementTable(); - void ClearMeasurements(); - void ClearLengthLines(); - void ClearLengthSplines(); - void ClearLengthArcs(); - void ClearLineAngles(); + void ClearVariables(const VarType &type = VarType::Unknown); void ClearDetails(); + void SetSize(qreal size); void SetSizeName(const QString &name); void SetHeight(qreal height); @@ -129,55 +161,41 @@ public: QString SizeName()const; qreal height() const; QString HeightName()const; - bool IncrementTableContains(const QString& name); - static quint32 getNextId(); - void RemoveIncrementTableRow(const QString& name); - static void UpdateId(quint32 newId); - const QHash *DataGObjects() const; - const QHash *DataMeasurements() const; - const QHash *DataIncrements() const; - const QHash *DataLengthLines() const; - const QHash *DataLengthSplines() const; - const QHash *DataLengthArcs() const; - const QHash *DataLineAngles() const; - const QHash *DataDetails() const; + + bool IncrementExist(const QString& name); + + void RemoveIncrement(const QString& name); + + const QHash *DataGObjects() const; + const QHash *DataDetails() const; + const QHash *DataVariables() const; + + const QMap DataMeasurements() const; + const QMap DataIncrements() const; + const QMap DataLengthLines() const; + const QMap DataLengthSplines() const; + const QMap DataLengthArcs() const; + const QMap DataLineAngles() const; + + private: /** * @brief _id current id. New object will have value +1. For empty class equal 0. */ - static quint32 _id; - qreal _size; - QString sizeName; - qreal _height; - QString heightName; + static quint32 _id; + qreal _size; + QString sizeName; + qreal _height; + QString heightName; /** * @brief gObjects graphicals objects of pattern. */ QHash gObjects; + /** - * @brief measurements container of measurements. + * @brief variables container for measurements, increments, lines lengths, lines angles, arcs lengths, curve lengths */ - QHash measurements; - /** - * @brief increments - */ - QHash increments; - /** - * @brief lengthLines container of lines lengths - */ - QHash lengthLines; - /** - * @brief lineAngles container of angles of lines - */ - QHash lineAngles; - /** - * @brief lengthSplines container of splines length - */ - QHash lengthSplines; - /** - * @brief lengthArcs container of arcs length - */ - QHash lengthArcs; + QHash variables; /** * @brief details container of details */ @@ -187,101 +205,24 @@ private: // cppcheck-suppress functionStatic const val GetObject(const QHash &obj, key id) const; - template - // cppcheck-suppress functionStatic - val GetVariable(const QHash &obj, key id) const; - template void UpdateObject(QHash &obj, const quint32 &id, val point); template static quint32 AddObject(QHash &obj, val value); + + template + void CopyGObject(const VContainer &data, const quint32 &id); + + template + void CopyVar(const VContainer &data, const QString &name); + + QMap DataVar(const VarType &type) const; + + template + const QMap DataTableVar(const VarType &type) const; }; -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddMeasurement add new measurement - * @param name short measurement name - * @param m measurement - */ -inline void VContainer::AddMeasurement(const QString &name, const VMeasurement &m) -{ - measurements[name] = m; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief UpdateMeasurement update measurement by name - * @param name short measurement name - * @param m measurement - */ -inline void VContainer::UpdateMeasurement(const QString &name, VMeasurement m) -{ - measurements[name] = m; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief UpdateIncrement update increment table row by name - * @param name name of row - * @param incr increment - */ -inline void VContainer::UpdateIncrement(const QString &name, VIncrement incr) -{ - increments[name] = incr; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ClearIncrementTable clear increment table - */ -inline void VContainer::ClearIncrementTable() -{ - increments.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -inline void VContainer::ClearMeasurements() -{ - measurements.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ClearLengthLines clear length lines - */ -inline void VContainer::ClearLengthLines() -{ - lengthLines.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ClearLengthSplines clear length splines - */ -inline void VContainer::ClearLengthSplines() -{ - lengthSplines.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ClearLengthArcs clear length arcs - */ -inline void VContainer::ClearLengthArcs() -{ - lengthArcs.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief ClearLineAngles clear angles of lines - */ -inline void VContainer::ClearLineAngles() -{ - lineAngles.clear(); -} - //--------------------------------------------------------------------------------------------------------------------- inline void VContainer::ClearDetails() { @@ -352,27 +293,6 @@ inline QString VContainer::HeightName() const return heightName; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief IncrementTableContains check if increment table contains name - * @param name name of row - * @return true if contains - */ -inline bool VContainer::IncrementTableContains(const QString &name) -{ - return increments.contains(name); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RemoveIncrementTableRow remove row by name from increment table - * @param name name of existing row - */ -inline void VContainer::RemoveIncrementTableRow(const QString &name) -{ - increments.remove(name); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief data container with datagObjects return container of gObjects @@ -383,66 +303,6 @@ inline const QHash *VContainer::DataGObjects() const return &gObjects; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief DataMeasurements container with measurements. - * @return pointer to measurements. - */ -inline const QHash *VContainer::DataMeasurements() const -{ - return &measurements; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief data container with dataIncrements return container of increment table - * @return pointer on container of increment table - */ -inline const QHash *VContainer::DataIncrements() const -{ - return &increments; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief data container with dataLengthLines return container of lines lengths - * @return pointer on container of lines lengths - */ -inline const QHash *VContainer::DataLengthLines() const -{ - return &lengthLines; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief data container with dataLengthSplines return container of splines lengths - * @return pointer on container of splines lengths - */ -inline const QHash *VContainer::DataLengthSplines() const -{ - return &lengthSplines; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief data container with dataLengthArcs return container of arcs length - * @return pointer on container of arcs length - */ -inline const QHash *VContainer::DataLengthArcs() const -{ - return &lengthArcs; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief data container with dataLineAngles return container of angles of line - * @return pointer on container of angles of line - */ -inline const QHash *VContainer::DataLineAngles() const -{ - return &lineAngles; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief data container with dataDetails return container of details @@ -453,4 +313,10 @@ inline const QHash *VContainer::DataDetails() const return &details; } +//--------------------------------------------------------------------------------------------------------------------- +inline const QHash *VContainer::DataVariables() const +{ + return &variables; +} + #endif // VCONTAINER_H diff --git a/src/app/container/vincrement.cpp b/src/app/container/vincrement.cpp index e0ae5355f..2b65a8406 100644 --- a/src/app/container/vincrement.cpp +++ b/src/app/container/vincrement.cpp @@ -34,20 +34,25 @@ */ VIncrement::VIncrement() :VVariable(), id(0) -{} +{ + type = VarType::Increment; +} //--------------------------------------------------------------------------------------------------------------------- /** * @brief VIncrementTableRow create increment + * @param name increment's name * @param id id * @param base value in base size and height * @param ksize increment in sizes * @param kheight increment in heights * @param description description of increment */ -VIncrement::VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description) - :VVariable(base, ksize, kheight, description), id(id) -{} +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; +} //--------------------------------------------------------------------------------------------------------------------- VIncrement::VIncrement(const VIncrement &incr) diff --git a/src/app/container/vincrement.h b/src/app/container/vincrement.h index b7887043d..654daa982 100644 --- a/src/app/container/vincrement.h +++ b/src/app/container/vincrement.h @@ -30,7 +30,6 @@ #define VINCREMENTTABLEROW_H #include "vvariable.h" -#include /** * @brief The VIncrement class keep data row of increment table @@ -39,7 +38,8 @@ class VIncrement :public VVariable { public: VIncrement(); - VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description = QString()); + VIncrement(const QString &name, quint32 id, qreal base, qreal ksize, qreal kheight, + QString description = QString()); VIncrement(const VIncrement &incr); VIncrement &operator=(const VIncrement &incr); virtual ~VIncrement(); @@ -50,7 +50,7 @@ public: void setKheight(const qreal &value); void setDescription(const QString &value); private: - /** @brief id identificator */ + /** @brief id each increment have unique identificator */ quint32 id; }; diff --git a/src/app/container/vinternalvariable.cpp b/src/app/container/vinternalvariable.cpp new file mode 100644 index 000000000..df24534d4 --- /dev/null +++ b/src/app/container/vinternalvariable.cpp @@ -0,0 +1,63 @@ +/************************************************************************ + ** + ** @file vinternalvariable.cpp + ** @author Roman Telezhynskyi + ** @date 28 7, 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 . + ** + *************************************************************************/ + +#include "vinternalvariable.h" + +//--------------------------------------------------------------------------------------------------------------------- +VInternalVariable::VInternalVariable() + :type(VarType::Unknown), value(0), name(QString()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VInternalVariable::VInternalVariable(const VInternalVariable &var) + :type(var.GetType()), value(var.GetValue()), name(var.GetName()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VInternalVariable &VInternalVariable::operator=(const VInternalVariable &var) +{ + if ( &var == this ) + { + return *this; + } + this->type = var.GetType(); + this->value = var.GetValue(); + this->name = var.GetName(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VInternalVariable::~VInternalVariable() +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VInternalVariable::Filter(quint32 id) +{ + Q_UNUSED(id); + return false; +} diff --git a/src/app/container/vinternalvariable.h b/src/app/container/vinternalvariable.h new file mode 100644 index 000000000..a2d7b04f6 --- /dev/null +++ b/src/app/container/vinternalvariable.h @@ -0,0 +1,83 @@ +/************************************************************************ + ** + ** @file vinternalvariable.h + ** @author Roman Telezhynskyi + ** @date 28 7, 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_H +#define VINTERNALVARIABLE_H + +#include + +enum class VarType : char { Measurement, Increment, LengthLine, LengthSpline, LengthArc, LineAngle, Unknown }; + +class VInternalVariable +{ +public: + VInternalVariable(); + VInternalVariable(const VInternalVariable &var); + VInternalVariable &operator=(const VInternalVariable &var); + virtual ~VInternalVariable(); + + qreal GetValue() const; + qreal* GetValue(); + QString GetName() const; + VarType GetType() const; + + virtual bool Filter(quint32 id); +protected: + VarType type; + + /** @brief value variable's value */ + qreal value; + + QString name; +}; + +//--------------------------------------------------------------------------------------------------------------------- +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/vlengtharc.cpp b/src/app/container/vlengtharc.cpp new file mode 100644 index 000000000..8914bc0ab --- /dev/null +++ b/src/app/container/vlengtharc.cpp @@ -0,0 +1,75 @@ +/************************************************************************ + ** + ** @file vlengtharc.cpp + ** @author Roman Telezhynskyi + ** @date 28 7, 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 . + ** + *************************************************************************/ + +#include "vlengtharc.h" +#include "../geometry/varc.h" +#include "../widgets/vapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +VLengthArc::VLengthArc() + :VInternalVariable(), id(0) +{ + type = VarType::LengthArc; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthArc::VLengthArc(const quint32 &id, const VArc *arc) + :VInternalVariable(), id(id) +{ + type = VarType::LengthArc; + SCASSERT(arc != nullptr); + name = arc->name(); + value = qApp->fromPixel(arc->GetLength()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthArc::VLengthArc(const VLengthArc &var) + :VInternalVariable(var), id(var.GetId()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthArc &VLengthArc::operator=(const VLengthArc &var) +{ + if ( &var == this ) + { + return *this; + } + VInternalVariable::operator=(var); + this->id = var.GetId(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthArc::~VLengthArc() +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VLengthArc::Filter(quint32 id) +{ + return this->id == id; +} diff --git a/src/app/container/vlengtharc.h b/src/app/container/vlengtharc.h new file mode 100644 index 000000000..bf45df4f8 --- /dev/null +++ b/src/app/container/vlengtharc.h @@ -0,0 +1,56 @@ +/************************************************************************ + ** + ** @file vlengtharc.h + ** @author Roman Telezhynskyi + ** @date 28 7, 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 VLENGTHARC_H +#define VLENGTHARC_H + +#include "vinternalvariable.h" + +class VArc; + +class VLengthArc :public VInternalVariable +{ +public: + VLengthArc(); + VLengthArc(const quint32 &id, const VArc * arc); + VLengthArc(const VLengthArc &var); + VLengthArc &operator=(const VLengthArc &var); + virtual ~VLengthArc(); + + virtual bool Filter(quint32 id); + quint32 GetId() const; +private: + quint32 id; +}; + +inline quint32 VLengthArc::GetId() const +{ + return id; +} + +#endif // VLENGTHARC_H diff --git a/src/app/container/vlengthline.cpp b/src/app/container/vlengthline.cpp new file mode 100644 index 000000000..cb36ca80d --- /dev/null +++ b/src/app/container/vlengthline.cpp @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @file vlengthline.cpp + ** @author Roman Telezhynskyi + ** @date 28 7, 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 . + ** + *************************************************************************/ + +#include "vlengthline.h" +#include "../geometry/vpointf.h" +#include "../widgets/vapplication.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VLengthLine::VLengthLine() + :VInternalVariable(), p1Id(0), p2Id(0) +{ + type = VarType::LengthLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthLine::VLengthLine(const VPointF *p1, const quint32 &p1Id, const VPointF *p2, const quint32 &p2Id) + :VInternalVariable(), p1Id(p1Id), p2Id(p2Id) +{ + SCASSERT(p1 != nullptr); + SCASSERT(p2 != nullptr); + + type = VarType::LengthLine; + name = QString(line_+"%1_%2").arg(p1->name(), p2->name()); + SetValue(p1, p2); +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthLine::VLengthLine(const VLengthLine &var) + :VInternalVariable(var), p1Id(var.GetP1Id()), p2Id(var.GetP2Id()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthLine &VLengthLine::operator=(const VLengthLine &var) +{ + if ( &var == this ) + { + return *this; + } + VInternalVariable::operator=(var); + this->p1Id = var.GetP1Id(); + this->p2Id = var.GetP2Id(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthLine::~VLengthLine() +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VLengthLine::Filter(quint32 id) +{ + return id == p1Id || id == p2Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLengthLine::SetValue(const VPointF *p1, const VPointF *p2) +{ + SCASSERT(p1 != nullptr); + SCASSERT(p2 != nullptr); + + value = qApp->fromPixel(QLineF(p1->toQPointF(), p2->toQPointF()).length()); +} diff --git a/src/app/container/vlengthline.h b/src/app/container/vlengthline.h new file mode 100644 index 000000000..f65894442 --- /dev/null +++ b/src/app/container/vlengthline.h @@ -0,0 +1,66 @@ +/************************************************************************ + ** + ** @file vlengthline.h + ** @author Roman Telezhynskyi + ** @date 28 7, 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 VLENGTHLINE_H +#define VLENGTHLINE_H + +#include "vinternalvariable.h" + +class VPointF; + +class VLengthLine :public VInternalVariable +{ +public: + VLengthLine(); + VLengthLine(const VPointF *p1, const quint32 &p1Id, const VPointF *p2, const quint32 &p2Id); + VLengthLine(const VLengthLine &var); + VLengthLine &operator=(const VLengthLine &var); + virtual ~VLengthLine(); + + virtual bool Filter(quint32 id); + void SetValue(const VPointF *p1, const VPointF *p2); + quint32 GetP1Id() const; + quint32 GetP2Id() const; +private: + quint32 p1Id; + quint32 p2Id; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 VLengthLine::GetP1Id() const +{ + return p1Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 VLengthLine::GetP2Id() const +{ + return p2Id; +} + +#endif // VLENGTHLINE_H diff --git a/src/app/container/vlengthspline.cpp b/src/app/container/vlengthspline.cpp new file mode 100644 index 000000000..146ad4b46 --- /dev/null +++ b/src/app/container/vlengthspline.cpp @@ -0,0 +1,82 @@ +/************************************************************************ + ** + ** @file vlengthsplines.cpp + ** @author Roman Telezhynskyi + ** @date 28 7, 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 . + ** + *************************************************************************/ + +#include "vlengthspline.h" +#include "../geometry/vabstractcurve.h" +#include "../widgets/vapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +VLengthSpline::VLengthSpline() + :VInternalVariable(), id(0) +{ + type = VarType::LengthSpline; +} + +VLengthSpline::VLengthSpline(const quint32 &id, const QString &name, const qreal &value) + :VInternalVariable(), id(id) +{ + type = VarType::LengthSpline; + this->name = name; + this->value = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthSpline::VLengthSpline(const quint32 &id, const VAbstractCurve *path) + :VInternalVariable(), id(id) +{ + type = VarType::LengthSpline; + this->name = path->name(); + this->value = qApp->fromPixel(path->GetLength()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthSpline::VLengthSpline(const VLengthSpline &var) + :VInternalVariable(var), id(var.GetId()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthSpline &VLengthSpline::operator=(const VLengthSpline &var) +{ + if ( &var == this ) + { + return *this; + } + VInternalVariable::operator=(var); + this->id = var.GetId(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthSpline::~VLengthSpline() +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VLengthSpline::Filter(quint32 id) +{ + return this->id == id; +} diff --git a/src/app/container/vlengthspline.h b/src/app/container/vlengthspline.h new file mode 100644 index 000000000..127dc8d33 --- /dev/null +++ b/src/app/container/vlengthspline.h @@ -0,0 +1,58 @@ +/************************************************************************ + ** + ** @file vlengthsplines.h + ** @author Roman Telezhynskyi + ** @date 28 7, 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 VLENGTHSPLINES_H +#define VLENGTHSPLINES_H + +#include "vinternalvariable.h" + +class VAbstractCurve; + +class VLengthSpline :public VInternalVariable +{ +public: + VLengthSpline(); + VLengthSpline(const quint32 &id, const QString &name, const qreal &value); + VLengthSpline(const quint32 &id, const VAbstractCurve *path); + VLengthSpline(const VLengthSpline &var); + VLengthSpline &operator=(const VLengthSpline &var); + virtual ~VLengthSpline(); + + virtual bool Filter(quint32 id); + quint32 GetId() const; +private: + quint32 id; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 VLengthSpline::GetId() const +{ + return id; +} + +#endif // VLENGTHSPLINES_H diff --git a/src/app/container/vlineangle.cpp b/src/app/container/vlineangle.cpp new file mode 100644 index 000000000..50b56d833 --- /dev/null +++ b/src/app/container/vlineangle.cpp @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @file vlineangle.cpp + ** @author Roman Telezhynskyi + ** @date 28 7, 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 . + ** + *************************************************************************/ + +#include "vlineangle.h" +#include "../geometry/vpointf.h" +#include "../widgets/vapplication.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VLineAngle::VLineAngle() + :VInternalVariable(), p1Id(0), p2Id(0) +{ + type = VarType::LineAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLineAngle::VLineAngle(const VPointF *p1, const quint32 &p1Id, const VPointF *p2, const quint32 &p2Id) + :VInternalVariable(), p1Id(p1Id), p2Id(p2Id) +{ + type = VarType::LineAngle; + + SCASSERT(p1 != nullptr); + SCASSERT(p2 != nullptr); + + name = QString(angleLine_+"%1_%2").arg(p1->name(), p2->name()); + SetValue(p1, p2); +} + +//--------------------------------------------------------------------------------------------------------------------- +VLineAngle::VLineAngle(const VLineAngle &var) + :VInternalVariable(var), p1Id(var.GetP1Id()), p2Id(var.GetP2Id()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VLineAngle &VLineAngle::operator=(const VLineAngle &var) +{ + if ( &var == this ) + { + return *this; + } + VInternalVariable::operator=(var); + this->p1Id = var.GetP1Id(); + this->p2Id = var.GetP2Id(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLineAngle::~VLineAngle() +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VLineAngle::Filter(quint32 id) +{ + return id == p1Id || id == p2Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLineAngle::SetValue(const VPointF *p1, const VPointF *p2) +{ + SCASSERT(p1 != nullptr); + SCASSERT(p2 != nullptr); + value = QLineF(p1->toQPointF(), p2->toQPointF()).angle(); +} diff --git a/src/app/container/vlineangle.h b/src/app/container/vlineangle.h new file mode 100644 index 000000000..297f16a96 --- /dev/null +++ b/src/app/container/vlineangle.h @@ -0,0 +1,66 @@ +/************************************************************************ + ** + ** @file vlineangle.h + ** @author Roman Telezhynskyi + ** @date 28 7, 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 VLINEANGLE_H +#define VLINEANGLE_H + +#include "vinternalvariable.h" + +class VPointF; + +class VLineAngle :public VInternalVariable +{ +public: + VLineAngle(); + VLineAngle(const VPointF *p1, const quint32 &p1Id, const VPointF *p2, const quint32 &p2Id); + VLineAngle(const VLineAngle &var); + VLineAngle &operator=(const VLineAngle &var); + virtual ~VLineAngle(); + + virtual bool Filter(quint32 id); + void SetValue(const VPointF *p1, const VPointF *p2); + quint32 GetP1Id() const; + quint32 GetP2Id() const; +private: + quint32 p1Id; + quint32 p2Id; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 VLineAngle::GetP1Id() const +{ + return p1Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 VLineAngle::GetP2Id() const +{ + return p2Id; +} + +#endif // VLINEANGLE_H diff --git a/src/app/container/vmeasurement.cpp b/src/app/container/vmeasurement.cpp index d55cbaf14..d8b0ab33c 100644 --- a/src/app/container/vmeasurement.cpp +++ b/src/app/container/vmeasurement.cpp @@ -36,11 +36,14 @@ */ VMeasurement::VMeasurement() :VVariable(), gui_text(QString()), _tagName(QString()) -{} +{ + type = VarType::Measurement; +} //--------------------------------------------------------------------------------------------------------------------- /** * @brief VMeasurement create measurement for standard table + * @param name measurement's name * @param base value in base size and height * @param ksize increment in sizes * @param kheight increment in heights @@ -48,23 +51,28 @@ VMeasurement::VMeasurement() * @param description measurement full description * @param tagName measurement's tag name in file */ -VMeasurement::VMeasurement(const qreal &base, const qreal &ksize, const qreal &kheight, +VMeasurement::VMeasurement(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, const QString &gui_text, const QString &description, const QString &tagName) - :VVariable(base, ksize, kheight, description), gui_text(gui_text), _tagName(tagName) -{} + :VVariable(name, base, ksize, kheight, description), gui_text(gui_text), _tagName(tagName) +{ + type = VarType::Measurement; +} //--------------------------------------------------------------------------------------------------------------------- /** * @brief VMeasurement create measurement for individual table + * @param name measurement's name * @param base value in base size and height * @param gui_text shor tooltip for user * @param description measurement full description * @param tagName measurement's tag name in file */ -VMeasurement::VMeasurement(const qreal &base, const QString &gui_text, const QString &description, +VMeasurement::VMeasurement(const QString &name, const qreal &base, const QString &gui_text, const QString &description, const QString &tagName) - :VVariable(base, description), gui_text(gui_text), _tagName(tagName) -{} + :VVariable(name, base, description), gui_text(gui_text), _tagName(tagName) +{ + type = VarType::Measurement; +} //--------------------------------------------------------------------------------------------------------------------- VMeasurement::VMeasurement(const VMeasurement &m) @@ -91,12 +99,13 @@ VMeasurement::~VMeasurement() //--------------------------------------------------------------------------------------------------------------------- QStringList VMeasurement::ListHeights() { + QStringList list; if (qApp->patternUnit() == Unit::Inch) { qWarning()<<"Standard table doesn't support inches."; + return list; } - QStringList list; // from 92 cm to 188 cm for (int i = 92; i<= 188; i = i+6) { @@ -108,12 +117,13 @@ QStringList VMeasurement::ListHeights() //--------------------------------------------------------------------------------------------------------------------- QStringList VMeasurement::ListSizes() { + QStringList list; if (qApp->patternUnit() == Unit::Inch) { qWarning()<<"Standard table doesn't support inches."; + return list; } - QStringList list; // from 22 cm to 56 cm for (int i = 22; i<= 56; i = i+2) { diff --git a/src/app/container/vmeasurement.h b/src/app/container/vmeasurement.h index 87a5122f1..a5955b09a 100644 --- a/src/app/container/vmeasurement.h +++ b/src/app/container/vmeasurement.h @@ -30,7 +30,8 @@ #define VSTANDARDTABLEROW_H #include "vvariable.h" -#include + +#include /** * @brief The VMeasurement class keep data row of standard table @@ -39,10 +40,10 @@ class VMeasurement :public VVariable { public: VMeasurement(); - VMeasurement(const qreal &base, const qreal &ksize, const qreal &kheight, + VMeasurement(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, const QString &gui_text = QString(), const QString &description = QString(), const QString &TagName = QString()); - VMeasurement(const qreal &base, const QString &gui_text = QString(), + VMeasurement(const QString &name, const qreal &base, const QString &gui_text = QString(), const QString &description = QString(), const QString &TagName = QString()); VMeasurement(const VMeasurement &m); VMeasurement &operator=(const VMeasurement &m); diff --git a/src/app/container/vvariable.cpp b/src/app/container/vvariable.cpp index 55c31000a..dfa30be83 100644 --- a/src/app/container/vvariable.cpp +++ b/src/app/container/vvariable.cpp @@ -32,26 +32,34 @@ //--------------------------------------------------------------------------------------------------------------------- VVariable::VVariable() - :base(0), ksize(0), kheight(0), description(QString()) + :VInternalVariable(), base(0), ksize(0), kheight(0), description(QString()) { Init(); + value = base; } //--------------------------------------------------------------------------------------------------------------------- -VVariable::VVariable(const qreal &base, const qreal &ksize, const qreal &kheight, const QString &description) - :base(base), ksize(ksize), kheight(kheight), description(description) -{} +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) +{ + value = base; + this->name = name; +} //--------------------------------------------------------------------------------------------------------------------- -VVariable::VVariable(const qreal &base, const QString &description) +VVariable::VVariable(const QString &name, const qreal &base, const QString &description) :base(base), ksize(0), kheight(0), description(description) { Init(); + value = base; + this->name = name; } //--------------------------------------------------------------------------------------------------------------------- VVariable::VVariable(const VVariable &var) - :base(var.GetBase()), ksize(var.GetKsize()), kheight(var.GetKheight()), description(var.GetDescription()) + :VInternalVariable(var), base(var.GetBase()), ksize(var.GetKsize()), kheight(var.GetKheight()), + description(var.GetDescription()) {} //--------------------------------------------------------------------------------------------------------------------- @@ -61,6 +69,7 @@ VVariable &VVariable::operator=(const VVariable &var) { return *this; } + VInternalVariable::operator=(var); this->base = var.GetBase(); this->ksize = var.GetKsize(); this->kheight = var.GetKheight(); @@ -73,24 +82,22 @@ VVariable::~VVariable() {} //--------------------------------------------------------------------------------------------------------------------- -qreal VVariable::GetValue(const qreal &size, const qreal &height) const +void VVariable::SetValue(const qreal &size, const qreal &height) { - if (qApp->patternUnit() != Unit::Inch) + if (qApp->patternUnit() == Unit::Inch) { - const qreal baseSize = VAbstractMeasurements::UnitConvertor(50.0, Unit::Cm, qApp->patternUnit()); - const qreal baseHeight = VAbstractMeasurements::UnitConvertor(176.0, Unit::Cm, qApp->patternUnit()); - const qreal sizeIncrement = VAbstractMeasurements::UnitConvertor(2.0, Unit::Cm, qApp->patternUnit()); - const qreal heightIncrement = VAbstractMeasurements::UnitConvertor(6.0, Unit::Cm, qApp->patternUnit()); + qWarning("Gradation doesn't support inches"); + return; + } + const qreal baseSize = VAbstractMeasurements::UnitConvertor(50.0, Unit::Cm, qApp->patternUnit()); + const qreal baseHeight = VAbstractMeasurements::UnitConvertor(176.0, Unit::Cm, qApp->patternUnit()); + const qreal sizeIncrement = VAbstractMeasurements::UnitConvertor(2.0, Unit::Cm, qApp->patternUnit()); + const qreal heightIncrement = VAbstractMeasurements::UnitConvertor(6.0, Unit::Cm, qApp->patternUnit()); - // Formula for calculation gradation - const qreal k_size = ( size - baseSize ) / sizeIncrement; - const qreal k_height = ( height - baseHeight ) / heightIncrement; - return base + k_size * ksize + k_height * kheight; - } - else// Must not be reached!!!! - { - return base; - } + // 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; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/container/vvariable.h b/src/app/container/vvariable.h index 18a850f7a..84b17f95c 100644 --- a/src/app/container/vvariable.h +++ b/src/app/container/vvariable.h @@ -29,14 +29,15 @@ #ifndef VVARIABLE_H #define VVARIABLE_H -#include +#include "vinternalvariable.h" -class VVariable +class VVariable :public VInternalVariable { public: VVariable(); - VVariable(const qreal &base, const qreal &ksize, const qreal &kheight, const QString &description = QString()); - VVariable(const qreal &base, const QString &description = QString()); + VVariable(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, + const QString &description = QString()); + VVariable(const QString &name, const qreal &base, const QString &description = QString()); VVariable(const VVariable &var); VVariable &operator=(const VVariable &var); virtual ~VVariable(); @@ -46,20 +47,19 @@ public: qreal GetKsize() const; qreal GetKheight() const; QString GetDescription() const; - qreal GetValue() const; - qreal GetValue(const qreal &size, const qreal &height) const; + void SetValue(const qreal &size, const qreal &height); protected: /** @brief base value in base size and height */ - qreal base; + qreal base; /** @brief ksize increment in sizes */ - qreal ksize; + qreal ksize; /** @brief kgrowth increment in heights */ - qreal kheight; + qreal kheight; /** @brief description description of increment */ - QString description; + QString description; private: void Init(); }; @@ -106,10 +106,4 @@ inline QString VVariable::GetDescription() const return description; } -//--------------------------------------------------------------------------------------------------------------------- -inline qreal VVariable::GetValue() const -{ - return base; -} - #endif // VVARIABLE_H diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index b4a6c9551..aa38c284c 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -144,28 +144,20 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par */ void DialogIncrements::FillMeasurements() { - const QHash *table = data->DataMeasurements(); - QHashIterator i(*table); - QMap map; - //Sorting QHash by id - while (i.hasNext()) - { - i.next(); - map.insert(qApp->VarToUser(i.key()), i.value()); - } + const QMap table = data->DataMeasurements(); qint32 currentRow = -1; - QMapIterator iMap(map); - ui->tableWidgetMeasurements->setRowCount ( table->size() ); + QMapIterator iMap(table); + ui->tableWidgetMeasurements->setRowCount ( table.size() ); while (iMap.hasNext()) { iMap.next(); - VMeasurement m = iMap.value(); + VMeasurement *m = iMap.value(); currentRow++; QTableWidgetItem *item = new QTableWidgetItem(QString(iMap.key())); item->setTextAlignment(Qt::AlignHCenter); item->setFont(QFont("Times", 12, QFont::Bold)); - item->setToolTip(m.GetGuiText()); + item->setToolTip(m->GetGuiText()); // set the item non-editable (view only), and non-selectable Qt::ItemFlags flags = item->flags(); flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag @@ -175,7 +167,7 @@ void DialogIncrements::FillMeasurements() if (qApp->patternType() == MeasurementsType::Standard) { - QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(data->GetValueStandardTableRow(iMap.key()))); + QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(data->GetTableValue(iMap.key()))); item->setTextAlignment(Qt::AlignHCenter); // set the item non-editable (view only), and non-selectable Qt::ItemFlags flags = item->flags(); @@ -184,13 +176,13 @@ void DialogIncrements::FillMeasurements() ui->tableWidgetMeasurements->setItem(currentRow, 1, item);// calculated value } - item = new QTableWidgetItem(QString().setNum(m.GetBase())); + item = new QTableWidgetItem(QString().setNum(m->GetBase())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetMeasurements->setItem(currentRow, 2, item); if (qApp->patternType() == MeasurementsType::Standard) { - QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(m.GetKsize())); + QTableWidgetItem *item = new QTableWidgetItem(QString().setNum(m->GetKsize())); item->setTextAlignment(Qt::AlignHCenter); // set the item non-editable (view only), and non-selectable Qt::ItemFlags flags = item->flags(); @@ -198,7 +190,7 @@ void DialogIncrements::FillMeasurements() item->setFlags(flags); ui->tableWidgetMeasurements->setItem(currentRow, 3, item);// in sizes - item = new QTableWidgetItem(QString().setNum(m.GetKheight())); + item = new QTableWidgetItem(QString().setNum(m->GetKheight())); item->setTextAlignment(Qt::AlignHCenter); // set the item non-editable (view only), and non-selectable flags = item->flags(); @@ -207,8 +199,8 @@ void DialogIncrements::FillMeasurements() ui->tableWidgetMeasurements->setItem(currentRow, 4, item);// in heights } - item = new QTableWidgetItem(m.GetDescription()); - item->setToolTip(m.GetDescription()); + item = new QTableWidgetItem(m->GetDescription()); + item->setToolTip(m->GetDescription()); item->setTextAlignment(Qt::AlignHCenter); // set the item non-editable (view only), and non-selectable flags = item->flags(); @@ -228,15 +220,15 @@ void DialogIncrements::FillMeasurements() */ void DialogIncrements::FillIncrements() { - const QHash *increments = data->DataIncrements(); - QHashIterator i(*increments); + const QMap increments = data->DataIncrements(); + QMapIterator i(increments); QMap map; //Sorting QHash by id while (i.hasNext()) { i.next(); - VIncrement incr = i.value(); - map.insert(incr.getId(), i.key()); + VIncrement *incr = i.value(); + map.insert(incr->getId(), i.key()); } qint32 currentRow = -1; @@ -244,19 +236,19 @@ void DialogIncrements::FillIncrements() while (iMap.hasNext()) { iMap.next(); - VIncrement incr = increments->value(iMap.value()); + VIncrement *incr = increments.value(iMap.value()); currentRow++; - ui->tableWidgetIncrement->setRowCount ( increments->size() ); + ui->tableWidgetIncrement->setRowCount ( increments.size() ); QTableWidgetItem *item = new QTableWidgetItem(iMap.value()); item->setTextAlignment(Qt::AlignHCenter); item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, incr.getId()); + item->setData(Qt::UserRole, incr->getId()); ui->tableWidgetIncrement->setItem(currentRow, 0, item); if (qApp->patternType() == MeasurementsType::Standard) { - item = new QTableWidgetItem(QString().setNum(data->GetValueIncrementTableRow(iMap.value()))); + item = new QTableWidgetItem(QString().setNum(data->GetTableValue(iMap.value()))); item->setTextAlignment(Qt::AlignHCenter); // set the item non-editable (view only), and non-selectable Qt::ItemFlags flags = item->flags(); @@ -265,23 +257,23 @@ void DialogIncrements::FillIncrements() ui->tableWidgetIncrement->setItem(currentRow, 1, item); } - item = new QTableWidgetItem(QString().setNum(incr.GetBase())); + item = new QTableWidgetItem(QString().setNum(incr->GetBase())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 2, item); if (qApp->patternType() == MeasurementsType::Standard) { - item = new QTableWidgetItem(QString().setNum(incr.GetKsize())); + item = new QTableWidgetItem(QString().setNum(incr->GetKsize())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 3, item); - item = new QTableWidgetItem(QString().setNum(incr.GetKheight())); + item = new QTableWidgetItem(QString().setNum(incr->GetKheight())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 4, item); } - item = new QTableWidgetItem(incr.GetDescription()); - item->setToolTip(incr.GetDescription()); + item = new QTableWidgetItem(incr->GetDescription()); + item->setToolTip(incr->GetDescription()); item->setTextAlignment(Qt::AlignLeft); ui->tableWidgetIncrement->setItem(currentRow, 5, item); } @@ -295,28 +287,18 @@ void DialogIncrements::FillIncrements() } //--------------------------------------------------------------------------------------------------------------------- -void DialogIncrements::FillTable(const QHash *varTable, QTableWidget *table) +void DialogIncrements::FillTable(const QMap varTable, QTableWidget *table) { SCASSERT(table != nullptr); - SCASSERT(varTable != nullptr); - - QHashIterator iHash(*varTable); - QMap map; - //Sorting QHash by name - while (iHash.hasNext()) - { - iHash.next(); - map.insert(qApp->VarToUser(iHash.key()), iHash.value()); - } qint32 currentRow = -1; - QMapIterator i(map); + QMapIterator i(varTable); while (i.hasNext()) { i.next(); qreal length = i.value(); currentRow++; - table->setRowCount ( varTable->size() ); + table->setRowCount ( varTable.size() ); QTableWidgetItem *item = new QTableWidgetItem(i.key()); item->setTextAlignment(Qt::AlignLeft); @@ -485,7 +467,7 @@ void DialogIncrements::OpenTable() } delete m; m = m1; - data->ClearMeasurements(); + data->ClearVariables(VarType::Measurement); m->Measurements(); emit FullUpdateTree(); @@ -517,7 +499,7 @@ void DialogIncrements::OpenTable() } m1->SetSize(); m1->SetHeight(); - data->ClearMeasurements(); + data->ClearVariables(VarType::Measurement); m1->Measurements(); delete m1; emit FullUpdateTree(); @@ -553,12 +535,12 @@ void DialogIncrements::clickedToolButtonAdd() { name = QString(tr("Name_%1")).arg(num); num++; - } while (data->IncrementTableContains(name)); + } while (data->IncrementExist(name)); const quint32 id = data->getNextId(); const QString description(tr("Description")); - VIncrement incr = VIncrement(id, 0, 0, 0, description); - data->AddIncrement(name, incr); + VIncrement *incr = new VIncrement(name, id, 0, 0, 0, description); + data->AddVariable(name, incr); AddIncrementToFile(id, name, 0, 0, 0, description); @@ -610,7 +592,7 @@ void DialogIncrements::clickedToolButtonRemove() QTableWidgetItem *item = ui->tableWidgetIncrement->currentItem(); qint32 row = item->row(); QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0); - data->RemoveIncrementTableRow(itemName->text()); + data->RemoveIncrement(itemName->text()); quint32 id = qvariant_cast(item->data(Qt::UserRole)); QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) @@ -687,7 +669,7 @@ void DialogIncrements::IncrementChanged ( qint32 row, qint32 column ) { case 0: // VPattern::IncrementName doc->SetAttribute(domElement, VPattern::IncrementName, item->text()); - data->ClearIncrementTable(); + data->ClearVariables(VarType::Increment); this->column = 2; emit FullUpdateTree(); break; @@ -709,9 +691,8 @@ void DialogIncrements::IncrementChanged ( qint32 row, qint32 column ) case 5: // VPattern::IncrementDescription { doc->SetAttribute(domElement, VPattern::IncrementDescription, item->text()); - VIncrement incr = data->GetIncrement(itemName->text()); - incr.setDescription(item->text()); - data->UpdateIncrement(itemName->text(), incr); + VIncrement *incr = data->GetVariable(itemName->text()); + incr->setDescription(item->text()); ui->tableWidgetIncrement->resizeColumnsToContents(); ui->tableWidgetIncrement->resizeRowsToContents(); this->column = 0; @@ -734,8 +715,8 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column) const QTableWidgetItem *itemName = ui->tableWidgetMeasurements->item(row, 0);// name column QTableWidgetItem *item = ui->tableWidgetMeasurements->item(row, 2); - VMeasurement measur = data->GetMeasurement(qApp->VarFromUser(itemName->text())); - const QString tag = measur.TagName(); + VMeasurement *measur = data->GetVariable(qApp->VarFromUser(itemName->text())); + const QString tag = measur->TagName(); QDomNodeList list = m->elementsByTagName(tag); QDomElement domElement = list.at(0).toElement(); if (domElement.isElement() == false) @@ -748,13 +729,13 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column) qreal base = item->text().replace(",", ".").toDouble(&ok); if (ok == false) { - measur.SetBase(0); + measur->SetBase(0); item->setText("0"); qDebug()<<"Can't convert toDouble measurement value"<SetBase(base); } // Convert value to measurements table unit @@ -766,7 +747,7 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column) qDebug()<<"Can't save measurement"; } - data->ClearMeasurements(); + data->ClearVariables(); m->Measurements(); emit FullUpdateTree(); diff --git a/src/app/dialogs/app/dialogincrements.h b/src/app/dialogs/app/dialogincrements.h index 3fa523aca..b702b120d 100644 --- a/src/app/dialogs/app/dialogincrements.h +++ b/src/app/dialogs/app/dialogincrements.h @@ -94,7 +94,7 @@ private: void FillMeasurements(); void FillIncrements(); - void FillTable(const QHash *varTable, QTableWidget *table); + void FillTable(const QMap varTable, QTableWidget *table); void FillLengthLines(); void FillLengthSplines(); void FillLengthArcs(); diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 4163bbd20..5213efff6 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -231,8 +231,8 @@ void DialogArc::ValChenged(int row) QListWidgetItem *item = ui->listWidget->item( row ); if (ui->radioButtonLineAngles->isChecked()) { - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLineAngle(item->text())) - .arg(tr("Value of angle of line.")); + qreal angle = *data->GetVariable(item->text())->GetValue(); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(angle).arg(tr("Value of angle of line.")); ui->labelDescription->setText(desc); return; } @@ -357,9 +357,8 @@ void DialogArc::ShowLineAngles() disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); ui->listWidget->clear(); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); - const QHash *lineAnglesTable = data->DataLineAngles(); - SCASSERT(lineAnglesTable != nullptr); - QHashIterator i(*lineAnglesTable); + const QMap lineAnglesTable = data->DataLineAngles(); + QMapIterator i(lineAnglesTable); while (i.hasNext()) { i.next(); diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index f56e87bf3..265ea53da 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -967,30 +967,32 @@ void DialogTool::ValChenged(int row) if (radioButtonStandardTable->isChecked()) { QString name = qApp->VarFromUser(item->text()); - VMeasurement stable = data->GetMeasurement(name); - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandardTableRow(name)) - .arg(stable.GetGuiText()); + VMeasurement *stable = data->GetVariable(name); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetTableValue(name)) + .arg(stable->GetGuiText()); labelDescription->setText(desc); return; } if (radioButtonIncrements->isChecked()) { - VIncrement incr = data->GetIncrement(item->text()); - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) - .arg(incr.GetDescription()); + VIncrement *incr = data->GetVariable(item->text()); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetTableValue(item->text())) + .arg(incr->GetDescription()); labelDescription->setText(desc); return; } if (radioButtonLengthLine->isChecked()) { - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLine(qApp->VarFromUser(item->text()))) + QString desc = QString("%1(%2) - %3").arg(item->text()) + .arg(*data->GetVariable(qApp->VarFromUser(item->text()))->GetValue()) .arg(tr("Line length")); labelDescription->setText(desc); return; } if (radioButtonLengthArc->isChecked()) { - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLengthArc(qApp->VarFromUser(item->text()))) + QString desc = QString("%1(%2) - %3").arg(item->text()) + .arg(*data->GetVariable(qApp->VarFromUser(item->text()))->GetValue()) .arg(tr("Arc length")); labelDescription->setText(desc); return; @@ -998,7 +1000,8 @@ void DialogTool::ValChenged(int row) if (radioButtonLengthCurve->isChecked()) { QString desc = QString("%1(%2) - %3").arg(item->text()) - .arg(data->GetLengthSpline(qApp->VarFromUser(item->text()))).arg(tr("Curve length")); + .arg(*data->GetVariable(qApp->VarFromUser(item->text()))->GetValue()) + .arg(tr("Curve length")); labelDescription->setText(desc); return; } @@ -1049,21 +1052,13 @@ void DialogTool::UpdateList() * @param var container with variables */ template -void DialogTool::ShowVariable(const QHash *var) +void DialogTool::ShowVariable(const QMap var) { SCASSERT(listWidget != nullptr); disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); listWidget->clear(); - QHashIterator i(*var); - QMap map; - while (i.hasNext()) - { - i.next(); - map.insert(qApp->VarToUser(i.key()), i.value()); - } - - QMapIterator iMap(map); + QMapIterator iMap(var); while (iMap.hasNext()) { iMap.next(); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 182ea4dd8..1bb92399d 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -197,7 +197,7 @@ protected: virtual void CheckState(); QString GetTypeLine(const QComboBox *box)const; template - void ShowVariable(const QHash *var); + void ShowVariable(const QMap var); void SetupTypeLine(QComboBox *box, const QString &value); void ChangeCurrentText(QComboBox *box, const QString &value); void ChangeCurrentData(QComboBox *box, const quint32 &value) const; diff --git a/src/app/geometry/vgobject.cpp b/src/app/geometry/vgobject.cpp index 7e0501499..f201b8405 100644 --- a/src/app/geometry/vgobject.cpp +++ b/src/app/geometry/vgobject.cpp @@ -33,7 +33,7 @@ * @brief VGObject default constructor. */ VGObject::VGObject() - :_id(0), type(GOType::Point), idObject(0), _name(QString()), mode(Draw::Calculation) + :_id(0), type(GOType::Unknown), idObject(0), _name(QString()), mode(Draw::Calculation) {} //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/geometry/vgobject.h b/src/app/geometry/vgobject.h index d7993931c..0146af60b 100644 --- a/src/app/geometry/vgobject.h +++ b/src/app/geometry/vgobject.h @@ -33,7 +33,7 @@ #include #include -enum class GOType : char { Point, Arc, Spline, SplinePath }; +enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown }; /** * @brief The VGObject class keep information graphical objects. diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index b29e4dd0a..093229f37 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -136,11 +136,11 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); spl1id = data->AddGObject(spline1); - data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength())); + data->AddVariable(spline1->name(), new VLengthSpline(id, spline1)); VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve()); spl2id = data->AddGObject(spline2); - data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength())); + data->AddVariable(spline2->name(), new VLengthSpline(id, spline2)); } else { @@ -152,11 +152,11 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); data->UpdateGObject(spl1id, spline1); - data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength())); + data->AddVariable(spline1->name(), new VLengthSpline(id, spline1)); VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve()); data->UpdateGObject(spl2id, spline2); - data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength())); + data->AddVariable(spline2->name(), new VLengthSpline(id, spline2)); if (parse != Document::FullParse) { diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 57e79ba62..b898dbf71 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -198,18 +198,18 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt if (typeCreation == Source::FromGui) { splPath1id = data->AddGObject(splPath1); - data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength())); + data->AddVariable(splPath1->name(), new VLengthSpline(splPath1id, splPath1)); splPath2id = data->AddGObject(splPath2); - data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength())); + data->AddVariable(splPath2->name(), new VLengthSpline(splPath2id, splPath2)); } else { data->UpdateGObject(splPath1id, splPath1); - data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength())); + data->AddVariable(splPath1->name(), new VLengthSpline(splPath1id, splPath1)); data->UpdateGObject(splPath2id, splPath2); - data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength())); + data->AddVariable(splPath2->name(), new VLengthSpline(splPath2id, splPath2)); if (parse != Document::FullParse) { diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 5eebdd646..c9157611a 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -154,12 +154,12 @@ void VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4 if (typeCreation == Source::FromGui) { id = data->AddGObject(spline); - data->AddLengthSpline(spline->name(), qApp->fromPixel(spline->GetLength())); + data->AddVariable(spline->name(), new VLengthSpline(id, spline)); } else { data->UpdateGObject(id, spline); - data->AddLengthSpline(spline->name(), qApp->fromPixel(spline->GetLength())); + data->AddVariable(spline->name(), new VLengthSpline(id, spline)); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 1c77865b0..9a2f19803 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -136,12 +136,12 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics if (typeCreation == Source::FromGui) { id = data->AddGObject(path); - data->AddLengthSpline(path->name(), qApp->fromPixel(path->GetLength())); + data->AddVariable(path->name(), new VLengthSpline(id, path)); } else { data->UpdateGObject(id, path); - data->AddLengthSpline(path->name(), qApp->fromPixel(path->GetLength())); + data->AddVariable(path->name(), new VLengthSpline(id, path)); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); diff --git a/src/app/xml/vindividualmeasurements.cpp b/src/app/xml/vindividualmeasurements.cpp index c0cd57b0c..45ea957dd 100644 --- a/src/app/xml/vindividualmeasurements.cpp +++ b/src/app/xml/vindividualmeasurements.cpp @@ -70,7 +70,7 @@ void VIndividualMeasurements::ReadMeasurement(const QDomElement &domElement, con { qreal value = GetParametrDouble(domElement, AttrValue, "0.0"); value = UnitConvertor(value, MUnit(), qApp->patternUnit()); - data->AddMeasurement(tag, VMeasurement(value, qApp->GuiText(tag), qApp->Description(tag), tag)); + data->AddVariable(tag, new VMeasurement(tag, value, qApp->GuiText(tag), qApp->Description(tag), tag)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 82114b904..41483660c 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1753,7 +1753,7 @@ void VPattern::ParseIncrementsElement(const QDomNode &node) const qreal kgrowth = GetParametrDouble(domElement, IncrementKgrowth, "0"); const QString desc = GetParametrString(domElement, IncrementDescription, "Description"); data->UpdateId(id); - data->AddIncrement(name, VIncrement(id, base, ksize, kgrowth, desc)); + data->AddVariable(name, new VIncrement(name, id, base, ksize, kgrowth, desc)); } } } @@ -1835,13 +1835,8 @@ void VPattern::PrepareForParse(const Document &parse) patternPieces.clear(); tools.clear(); cursor = 0; + history.clear(); } - data->ClearLengthLines(); - data->ClearLengthArcs(); - data->ClearLengthSplines(); - data->ClearLineAngles(); - data->ClearDetails(); - history.clear(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/xml/vstandardmeasurements.cpp b/src/app/xml/vstandardmeasurements.cpp index 1528537e0..55d025880 100644 --- a/src/app/xml/vstandardmeasurements.cpp +++ b/src/app/xml/vstandardmeasurements.cpp @@ -75,8 +75,8 @@ void VStandardMeasurements::ReadMeasurement(const QDomElement &domElement, const qWarning()<<"Standard table can't use inch unit."; } - data->AddMeasurement(tag, VMeasurement(value, size_increase, height_increase, qApp->GuiText(tag), - qApp->Description(tag), tag)); + data->AddVariable(tag, new VMeasurement(tag, value, size_increase, height_increase, qApp->GuiText(tag), + qApp->Description(tag), tag)); }