2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2014-01-15 00:55:41 +01:00
|
|
|
** @file vstandardtablecell.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2014-03-14 15:12:53 +01:00
|
|
|
#include "vmeasurement.h"
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-10-18 21:30:51 +02:00
|
|
|
#include <QMap>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QMessageLogger>
|
2015-10-18 21:30:51 +02:00
|
|
|
#include <QtDebug>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
|
|
|
#include "vvariable.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vmeasurement_p.h"
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-01 09:35:13 +02:00
|
|
|
/**
|
2017-07-12 20:21:48 +02:00
|
|
|
* @brief VMeasurement create measurement for multisize table
|
2014-07-29 13:28:18 +02:00
|
|
|
* @param name measurement's name
|
2014-07-09 14:23:04 +02:00
|
|
|
* @param base value in base size and height
|
2014-06-01 09:35:13 +02:00
|
|
|
* @param ksize increment in sizes
|
|
|
|
* @param kheight increment in heights
|
|
|
|
* @param gui_text shor tooltip for user
|
|
|
|
* @param description measurement full description
|
|
|
|
* @param tagName measurement's tag name in file
|
|
|
|
*/
|
2015-07-25 07:41:04 +02:00
|
|
|
VMeasurement::VMeasurement(quint32 index, const QString &name, qreal baseSize, qreal baseHeight, const qreal &base,
|
|
|
|
const qreal &ksize, const qreal &kheight, const QString &gui_text,
|
|
|
|
const QString &description, const QString &tagName)
|
2017-08-04 19:29:43 +02:00
|
|
|
:VVariable(name, description),
|
|
|
|
d(new VMeasurementData(index, gui_text, tagName, baseSize, baseHeight, base, ksize, kheight))
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-20 17:58:10 +02:00
|
|
|
SetType(VarType::Measurement);
|
2017-08-04 19:29:43 +02:00
|
|
|
VInternalVariable::SetValue(d->base);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
2014-03-14 15:12:53 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-01 09:35:13 +02:00
|
|
|
/**
|
|
|
|
* @brief VMeasurement create measurement for individual table
|
2014-07-29 13:28:18 +02:00
|
|
|
* @param name measurement's name
|
2014-07-09 14:23:04 +02:00
|
|
|
* @param base value in base size and height
|
2014-06-01 09:35:13 +02:00
|
|
|
* @param gui_text shor tooltip for user
|
|
|
|
* @param description measurement full description
|
|
|
|
* @param tagName measurement's tag name in file
|
|
|
|
*/
|
2015-07-24 12:06:39 +02:00
|
|
|
VMeasurement::VMeasurement(VContainer *data, quint32 index, const QString &name, const qreal &base,
|
|
|
|
const QString &formula, bool ok, const QString &gui_text, const QString &description,
|
2014-06-01 09:35:13 +02:00
|
|
|
const QString &tagName)
|
2017-08-04 19:29:43 +02:00
|
|
|
:VVariable(name, description), d(new VMeasurementData(data, index, formula, ok, gui_text, tagName, base))
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-20 17:58:10 +02:00
|
|
|
SetType(VarType::Measurement);
|
2017-08-04 19:29:43 +02:00
|
|
|
VInternalVariable::SetValue(base);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
2014-03-14 15:12:53 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-01 09:35:13 +02:00
|
|
|
VMeasurement::VMeasurement(const VMeasurement &m)
|
2014-08-20 19:43:53 +02:00
|
|
|
:VVariable(m), d(m.d)
|
2014-06-01 09:35:13 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurement &VMeasurement::operator=(const VMeasurement &m)
|
2014-03-14 15:12:53 +01:00
|
|
|
{
|
2014-07-27 14:30:28 +02:00
|
|
|
if ( &m == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2014-07-09 14:23:04 +02:00
|
|
|
VVariable::operator=(m);
|
2014-08-20 19:43:53 +02:00
|
|
|
d = m.d;
|
2014-06-01 09:35:13 +02:00
|
|
|
return *this;
|
2014-03-14 15:12:53 +01:00
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurement &VMeasurement::operator=(VMeasurement &&m) Q_DECL_NOTHROW
|
|
|
|
{
|
|
|
|
Swap(m);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurement::Swap(VMeasurement &m) Q_DECL_NOTHROW
|
|
|
|
{
|
|
|
|
VVariable::Swap(m);
|
|
|
|
std::swap(d, m.d);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-07-09 14:23:04 +02:00
|
|
|
VMeasurement::~VMeasurement()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-05-18 12:51:58 +02:00
|
|
|
QStringList VMeasurement::ListHeights(const QMap<GHeights, bool> &heights, Unit patternUnit)
|
2014-07-09 14:23:04 +02:00
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
QStringList list;
|
2015-06-12 10:55:44 +02:00
|
|
|
if (patternUnit == Unit::Inch)
|
2014-07-09 14:23:04 +02:00
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
qWarning()<<"Multisize table doesn't support inches.";
|
2014-07-29 13:28:18 +02:00
|
|
|
return list;
|
2014-07-09 14:23:04 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 14:03:24 +02:00
|
|
|
QMap<GHeights, bool>::const_iterator i = heights.constBegin();
|
|
|
|
while (i != heights.constEnd())
|
2014-07-09 14:23:04 +02:00
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
if (i.value() && i.key() != GHeights::ALL)
|
2014-08-07 14:03:24 +02:00
|
|
|
{
|
2018-05-18 12:51:58 +02:00
|
|
|
list.append(QString::number(UnitConvertor(static_cast<int>(i.key()), Unit::Cm, patternUnit)));
|
2014-08-07 14:03:24 +02:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list.isEmpty())
|
|
|
|
{
|
2015-07-13 12:48:29 +02:00
|
|
|
list = VMeasurement::WholeListHeights(patternUnit);
|
2014-07-09 14:23:04 +02:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-05-18 12:51:58 +02:00
|
|
|
QStringList VMeasurement::ListSizes(const QMap<GSizes, bool> &sizes, Unit patternUnit)
|
2014-07-09 14:23:04 +02:00
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
QStringList list;
|
2015-06-12 10:55:44 +02:00
|
|
|
if (patternUnit == Unit::Inch)
|
2014-07-09 14:23:04 +02:00
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
qWarning()<<"Multisize table doesn't support inches.";
|
2014-07-29 13:28:18 +02:00
|
|
|
return list;
|
2014-07-09 14:23:04 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 14:03:24 +02:00
|
|
|
QMap<GSizes, bool>::const_iterator i = sizes.constBegin();
|
|
|
|
while (i != sizes.constEnd())
|
|
|
|
{
|
2014-08-08 18:07:44 +02:00
|
|
|
if (i.value() && i.key() != GSizes::ALL)
|
2014-08-07 14:03:24 +02:00
|
|
|
{
|
2018-05-18 12:51:58 +02:00
|
|
|
list.append(QString::number(UnitConvertor(static_cast<int>(i.key()), Unit::Cm, patternUnit)));
|
2014-08-07 14:03:24 +02:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list.isEmpty())
|
2014-07-09 14:23:04 +02:00
|
|
|
{
|
2015-07-13 12:48:29 +02:00
|
|
|
list = VMeasurement::WholeListSizes(patternUnit);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VMeasurement::WholeListHeights(Unit patternUnit)
|
|
|
|
{
|
|
|
|
QStringList list;
|
|
|
|
if (patternUnit == Unit::Inch)
|
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
qWarning()<<"Multisize table doesn't support inches.";
|
2015-07-13 12:48:29 +02:00
|
|
|
return list;
|
|
|
|
}
|
2017-02-22 06:54:42 +01:00
|
|
|
|
2018-05-18 12:51:58 +02:00
|
|
|
list.reserve((static_cast<int>(GHeights::H200) - static_cast<int>(GHeights::H50))/heightStep);
|
2017-03-09 21:41:48 +01:00
|
|
|
for (int i = static_cast<int>(GHeights::H50); i<= static_cast<int>(GHeights::H200); i = i+heightStep)
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2018-05-18 12:51:58 +02:00
|
|
|
list.append(QString::number(UnitConvertor(i, Unit::Cm, patternUnit)));
|
2014-07-09 14:23:04 +02:00
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VMeasurement::WholeListSizes(Unit patternUnit)
|
|
|
|
{
|
|
|
|
QStringList list;
|
|
|
|
if (patternUnit == Unit::Inch)
|
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
qWarning()<<"Multisize table doesn't support inches.";
|
2015-07-13 12:48:29 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:51:58 +02:00
|
|
|
list.reserve((static_cast<int>(GSizes::S72) - static_cast<int>(GSizes::S22))/sizeStep);
|
2017-02-22 06:54:42 +01:00
|
|
|
for (int i = static_cast<int>(GSizes::S22); i<= static_cast<int>(GSizes::S72); i = i+sizeStep)
|
2015-07-13 12:48:29 +02:00
|
|
|
{
|
2018-05-18 12:51:58 +02:00
|
|
|
list.append(QString::number(UnitConvertor(i, Unit::Cm, patternUnit)));
|
2015-07-13 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-09 14:23:04 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2015-10-07 17:28:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurement::IsGradationSizeValid(const QString &size)
|
|
|
|
{
|
|
|
|
if (not size.isEmpty())
|
|
|
|
{
|
|
|
|
const QStringList sizes = VMeasurement::WholeListSizes(Unit::Cm);
|
2017-04-18 10:49:05 +02:00
|
|
|
return sizes.contains(size);
|
2015-10-07 17:28:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurement::IsGradationHeightValid(const QString &height)
|
|
|
|
{
|
|
|
|
if (not height.isEmpty())
|
|
|
|
{
|
|
|
|
const QStringList heights = VMeasurement::WholeListHeights(Unit::Cm);
|
2017-04-18 10:49:05 +02:00
|
|
|
return heights.contains(height);
|
2015-10-07 17:28:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 19:29:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VMeasurement::CalcValue() const
|
|
|
|
{
|
2018-10-12 12:06:03 +02:00
|
|
|
if (d->currentUnit == nullptr || qFuzzyIsNull(d->currentSize) || qFuzzyIsNull(d->currentHeight))
|
2017-08-04 19:29:43 +02:00
|
|
|
{
|
|
|
|
return VInternalVariable::GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*d->currentUnit == Unit::Inch)
|
|
|
|
{
|
|
|
|
qWarning("Gradation doesn't support inches");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const qreal sizeIncrement = UnitConvertor(2.0, Unit::Cm, *d->currentUnit);
|
|
|
|
const qreal heightIncrement = UnitConvertor(6.0, Unit::Cm, *d->currentUnit);
|
|
|
|
|
|
|
|
// Formula for calculation gradation
|
2018-10-12 12:06:03 +02:00
|
|
|
const qreal k_size = ( d->currentSize - d->baseSize ) / sizeIncrement;
|
|
|
|
const qreal k_height = ( d->currentHeight - d->baseHeight ) / heightIncrement;
|
2017-08-04 19:29:43 +02:00
|
|
|
return d->base + k_size * d->ksize + k_height * d->kheight;
|
|
|
|
}
|
|
|
|
|
2014-08-20 19:43:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetGuiText measurement name for tooltip
|
|
|
|
* @return measurement name
|
|
|
|
*/
|
|
|
|
QString VMeasurement::GetGuiText() const
|
|
|
|
{
|
|
|
|
return d->gui_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurement::TagName() const
|
|
|
|
{
|
|
|
|
return d->_tagName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurement::setTagName(const QString &tagName)
|
|
|
|
{
|
|
|
|
d->_tagName = tagName;
|
|
|
|
}
|
2015-07-21 17:28:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurement::GetFormula() const
|
|
|
|
{
|
|
|
|
return d->formula;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurement::IsCustom() const
|
|
|
|
{
|
2017-08-04 19:29:43 +02:00
|
|
|
return GetName().indexOf(CustomMSign) == 0;
|
2015-07-21 17:28:20 +02:00
|
|
|
}
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VMeasurement::Index() const
|
|
|
|
{
|
2015-10-19 15:21:06 +02:00
|
|
|
return static_cast<int>(d->index);
|
2015-07-24 12:06:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurement::IsFormulaOk() const
|
|
|
|
{
|
|
|
|
return d->formulaOk;
|
|
|
|
}
|
|
|
|
|
2017-08-04 19:29:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurement::IsNotUsed() const
|
|
|
|
{
|
|
|
|
return qFuzzyIsNull(d->base) && qFuzzyIsNull(d->ksize) && qFuzzyIsNull(d->kheight);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VMeasurement::GetValue() const
|
|
|
|
{
|
|
|
|
return CalcValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal *VMeasurement::GetValue()
|
|
|
|
{
|
|
|
|
VInternalVariable::SetValue(CalcValue());
|
|
|
|
return VInternalVariable::GetValue();
|
|
|
|
}
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VContainer *VMeasurement::GetData()
|
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
return d->data.data();
|
2017-08-04 19:29:43 +02:00
|
|
|
}
|
|
|
|
|
2018-10-12 12:06:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurement::SetSize(qreal size)
|
|
|
|
{
|
|
|
|
d->currentSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurement::SetHeight(qreal height)
|
|
|
|
{
|
|
|
|
d->currentHeight = height;
|
|
|
|
}
|
|
|
|
|
2017-08-04 19:29:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurement::SetUnit(const Unit *unit)
|
|
|
|
{
|
|
|
|
d->currentUnit = unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetBase return value in base size and height
|
|
|
|
* @return value
|
|
|
|
*/
|
|
|
|
qreal VMeasurement::GetBase() const
|
|
|
|
{
|
|
|
|
return d->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurement::SetBase(const qreal &value)
|
|
|
|
{
|
|
|
|
d->base = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetKsize return increment in sizes
|
|
|
|
* @return increment
|
|
|
|
*/
|
|
|
|
qreal VMeasurement::GetKsize() const
|
|
|
|
{
|
|
|
|
return d->ksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
// cppcheck-suppress unusedFunction
|
|
|
|
void VMeasurement::SetKsize(const qreal &value)
|
|
|
|
{
|
|
|
|
d->ksize = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetKheight return increment in heights
|
|
|
|
* @return increment
|
|
|
|
*/
|
|
|
|
qreal VMeasurement::GetKheight() const
|
|
|
|
{
|
|
|
|
return d->kheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
// cppcheck-suppress unusedFunction
|
|
|
|
void VMeasurement::SetKheight(const qreal &value)
|
|
|
|
{
|
|
|
|
d->kheight = value;
|
|
|
|
}
|