valentina/src/libs/vformat/vdimensions.h

275 lines
9.2 KiB
C
Raw Normal View History

2020-09-28 15:38:32 +02:00
/************************************************************************
**
** @file vdimensions.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 9, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VDIMENSIONS_H
#define VDIMENSIONS_H
#include <QCoreApplication>
2020-10-08 12:34:38 +02:00
#include <QMap>
2020-09-28 15:38:32 +02:00
#include "../vmisc/def.h"
enum class MeasurementDimension: qint8
{
2020-10-01 12:32:02 +02:00
X = 0, // height
Y = 1, // size (chest half circumference)
2020-10-20 15:29:11 +02:00
W = 2, // waist half circumference
Z = 3 // hip half circumference
2020-09-28 15:38:32 +02:00
};
2020-10-01 12:32:02 +02:00
class VAbstartMeasurementDimension;
template <class T> class QSharedPointer;
using MeasurementDimension_p = QSharedPointer<VAbstartMeasurementDimension>;
using DimesionLabels = QMap<qreal, QString>;
2020-09-28 15:38:32 +02:00
class VAbstartMeasurementDimension
{
Q_DECLARE_TR_FUNCTIONS(VAbstartMeasurementDimension)
public:
VAbstartMeasurementDimension() =default;
explicit VAbstartMeasurementDimension(Unit units);
VAbstartMeasurementDimension(Unit units, qreal min, qreal max, qreal step);
2020-09-28 15:38:32 +02:00
virtual ~VAbstartMeasurementDimension() =default;
virtual MeasurementDimension Type() const =0;
virtual bool IsValid();
auto MinValue() const -> qreal;
void SetMinValue(qreal minValue);
2020-09-28 15:38:32 +02:00
auto MaxValue() const -> qreal;
void SetMaxValue(qreal maxValue);
2020-09-28 15:38:32 +02:00
auto Step() const -> qreal;
void SetStep(qreal step);
2020-09-28 15:38:32 +02:00
auto BaseValue() const -> qreal;
void SetBaseValue(qreal baseValue);
2020-09-28 15:38:32 +02:00
auto Error() const -> QString;
2020-09-28 15:38:32 +02:00
auto Units() const -> Unit;
2020-09-28 15:38:32 +02:00
virtual auto IsCircumference() const -> bool;
2020-09-28 15:38:32 +02:00
virtual auto RangeMin() const -> int =0;
virtual auto RangeMax() const -> int =0;
2020-09-28 15:38:32 +02:00
auto ValidSteps() const -> QVector<qreal>;
auto ValidBases() const -> QVector<qreal>;
auto ValidBasesList() const -> QStringList;
2020-09-28 15:38:32 +02:00
static auto ValidBases(qreal min, qreal max, qreal step) -> QVector<qreal>;
static auto DimensionName(MeasurementDimension type) -> QString;
static auto DimensionToolTip(MeasurementDimension type, bool circumference, bool fc) -> QString;
auto Labels() const -> DimesionLabels;
void SetLabels(const DimesionLabels &labels);
2020-10-08 12:34:38 +02:00
2020-09-28 15:38:32 +02:00
protected:
2020-10-08 12:34:38 +02:00
Unit m_units{Unit::Cm};
qreal m_minValue{0};
qreal m_maxValue{0};
qreal m_step{-1};
qreal m_baseValue{0};
2020-10-08 12:34:38 +02:00
QString m_error{};
DimesionLabels m_labels{};
2020-09-28 15:38:32 +02:00
auto IsRangeValid() -> bool;
auto IsStepValid() -> bool;
auto IsBaseValid() -> bool;
auto IsUnitsValid() const -> bool;
2020-09-28 15:38:32 +02:00
};
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::MinValue() const -> qreal
2020-09-28 15:38:32 +02:00
{
return m_minValue;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstartMeasurementDimension::SetMinValue(qreal minValue)
2020-09-28 15:38:32 +02:00
{
m_minValue = minValue;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::MaxValue() const -> qreal
2020-09-28 15:38:32 +02:00
{
return m_maxValue;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstartMeasurementDimension::SetMaxValue(qreal maxValue)
2020-09-28 15:38:32 +02:00
{
m_maxValue = maxValue;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::Step() const -> qreal
2020-09-28 15:38:32 +02:00
{
return m_step;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstartMeasurementDimension::SetStep(qreal step)
2020-09-28 15:38:32 +02:00
{
m_step = step;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::BaseValue() const -> qreal
2020-09-28 15:38:32 +02:00
{
return m_baseValue;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstartMeasurementDimension::SetBaseValue(qreal baseValue)
2020-09-28 15:38:32 +02:00
{
m_baseValue = baseValue;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::Error() const -> QString
2020-09-28 15:38:32 +02:00
{
return m_error;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::Units() const -> Unit
2020-09-28 15:38:32 +02:00
{
return m_units;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::IsCircumference() const -> bool
2020-09-28 15:38:32 +02:00
{
return true;
}
2020-10-08 12:34:38 +02:00
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::Labels() const -> DimesionLabels
2020-10-08 12:34:38 +02:00
{
return m_labels;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstartMeasurementDimension::SetLabels(const DimesionLabels &labels)
{
m_labels = labels;
}
2020-09-28 15:38:32 +02:00
// VXMeasurementDimension
//---------------------------------------------------------------------------------------------------------------------
class VXMeasurementDimension : public VAbstartMeasurementDimension
{
public:
VXMeasurementDimension() =default;
explicit VXMeasurementDimension(Unit units);
VXMeasurementDimension(Unit units, qreal min, qreal max, qreal step);
2020-09-28 15:38:32 +02:00
virtual auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
virtual auto RangeMin() const -> int override;
virtual auto RangeMax() const -> int override;
2020-09-28 15:38:32 +02:00
virtual bool IsCircumference() const override;
};
//---------------------------------------------------------------------------------------------------------------------
inline auto VXMeasurementDimension::IsCircumference() const -> bool
2020-09-28 15:38:32 +02:00
{
return false;
}
// VYMeasurementDimension
//---------------------------------------------------------------------------------------------------------------------
class VYMeasurementDimension : public VAbstartMeasurementDimension
{
public:
VYMeasurementDimension() =default;
explicit VYMeasurementDimension(Unit units);
VYMeasurementDimension(Unit units, qreal min, qreal max, qreal step);
2020-09-28 15:38:32 +02:00
virtual auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
virtual auto RangeMin() const -> int override;
virtual auto RangeMax() const -> int override;
2020-09-28 15:38:32 +02:00
virtual auto IsCircumference() const -> bool override;
2020-09-28 15:38:32 +02:00
void SetCircumference(bool circumference);
private:
bool m_circumference{true};
};
//---------------------------------------------------------------------------------------------------------------------
inline bool VYMeasurementDimension::IsCircumference() const
{
return m_circumference;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VYMeasurementDimension::SetCircumference(bool circumference)
{
m_circumference = circumference;
}
// VWMeasurementDimension
//---------------------------------------------------------------------------------------------------------------------
class VWMeasurementDimension : public VAbstartMeasurementDimension
{
public:
VWMeasurementDimension() =default;
explicit VWMeasurementDimension(Unit units);
VWMeasurementDimension(Unit units, qreal min, qreal max, qreal step);
2020-09-28 15:38:32 +02:00
virtual auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
virtual auto RangeMin() const -> int override;
virtual auto RangeMax() const -> int override;
2020-09-28 15:38:32 +02:00
};
// VZMeasurementDimension
//---------------------------------------------------------------------------------------------------------------------
class VZMeasurementDimension : public VAbstartMeasurementDimension
{
public:
VZMeasurementDimension() =default;
explicit VZMeasurementDimension(Unit units);
VZMeasurementDimension(Unit units, qreal min, qreal max, qreal step);
2020-09-28 15:38:32 +02:00
virtual auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
virtual auto RangeMin() const -> int override;
virtual auto RangeMax() const -> int override;
2020-09-28 15:38:32 +02:00
};
#endif // VDIMENSIONS_H