valentina/src/libs/vformat/vdimensions.h

405 lines
13 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>
#include <QSet>
2020-09-28 15:38:32 +02:00
#include "../vmisc/def.h"
2022-02-14 12:26:24 +01:00
#include "qglobal.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
#include "../vmisc/defglobal.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
2020-09-28 15:38:32 +02:00
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
{
2022-02-14 12:26:24 +01:00
Q_DECLARE_TR_FUNCTIONS(VAbstartMeasurementDimension) // NOLINT
2020-09-28 15:38:32 +02:00
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;
2022-02-14 12:26:24 +01:00
virtual auto Type() const -> MeasurementDimension =0;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto IsValid() -> bool;
2020-09-28 15:38:32 +02:00
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
2022-02-17 15:22:11 +01:00
auto Units() const -> Unit; // cppcheck-suppress functionStatic
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto IsCircumference() const -> bool;
void SetCircumference(bool circumference);
auto RangeMin() const -> int;
auto RangeMax() const -> int;
virtual auto Axis() const -> QChar =0;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Name() const -> QString;
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, const QSet<qreal> &exclude) -> QVector<qreal>;
static auto DimensionName(MeasurementDimension type) -> QString;
2022-02-14 12:26:24 +01:00
static auto DimensionToolTip(const MeasurementDimension_p &dimension, bool fc) -> QString;
auto Labels() const -> DimesionLabels;
void SetLabels(const DimesionLabels &labels);
2020-10-08 12:34:38 +02:00
2022-02-14 12:26:24 +01:00
auto CustomName() const -> const QString &;
void SetCustomName(const QString &newCustomName);
2020-09-28 15:38:32 +02:00
protected:
2022-02-14 12:26:24 +01:00
auto IsRangeValid() -> bool;
auto IsStepValid() -> bool;
auto IsBaseValid() -> bool;
2022-02-17 15:22:11 +01:00
auto IsUnitsValid() const -> bool; // cppcheck-suppress functionStatic
2022-02-14 12:26:24 +01:00
private:
Q_DISABLE_COPY_MOVE(VAbstartMeasurementDimension) // NOLINT
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{};
2022-02-14 12:26:24 +01:00
bool m_circumference{true};
QString m_customName{};
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
{
2022-02-14 12:26:24 +01:00
return m_circumference;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstartMeasurementDimension::SetCircumference(bool circumference)
{
m_circumference = circumference;
2020-09-28 15:38:32 +02:00
}
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;
}
2022-02-14 12:26:24 +01:00
//---------------------------------------------------------------------------------------------------------------------
inline auto VAbstartMeasurementDimension::CustomName() const -> const QString &
{
return m_customName;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VAbstartMeasurementDimension::SetCustomName(const QString &newCustomName)
{
m_customName = newCustomName;
}
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);
2022-02-14 12:26:24 +01:00
~VXMeasurementDimension() override =default;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Axis() const -> QChar override;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
private:
Q_DISABLE_COPY_MOVE(VXMeasurementDimension) // NOLINT
2020-09-28 15:38:32 +02:00
};
//---------------------------------------------------------------------------------------------------------------------
2022-02-14 12:26:24 +01:00
inline auto VXMeasurementDimension::Type() const -> MeasurementDimension
{
return MeasurementDimension::X;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VXMeasurementDimension::Axis() const -> QChar
2020-09-28 15:38:32 +02:00
{
2022-02-14 12:26:24 +01:00
return QChar('X');
2020-09-28 15:38:32 +02:00
}
// VYMeasurementDimension
//---------------------------------------------------------------------------------------------------------------------
class VYMeasurementDimension : public VAbstartMeasurementDimension
{
public:
VYMeasurementDimension() =default;
explicit VYMeasurementDimension(Unit units);
VYMeasurementDimension(Unit units, qreal min, qreal max, qreal step);
2022-02-14 12:26:24 +01:00
~VYMeasurementDimension() override =default;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Axis() const -> QChar override;
2020-09-28 15:38:32 +02:00
private:
2022-02-14 12:26:24 +01:00
Q_DISABLE_COPY_MOVE(VYMeasurementDimension) // NOLINT
2020-09-28 15:38:32 +02:00
};
//---------------------------------------------------------------------------------------------------------------------
2022-02-14 12:26:24 +01:00
inline auto VYMeasurementDimension::Type() const -> MeasurementDimension
2020-09-28 15:38:32 +02:00
{
2022-02-14 12:26:24 +01:00
return MeasurementDimension::Y;
2020-09-28 15:38:32 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2022-02-14 12:26:24 +01:00
inline auto VYMeasurementDimension::Axis() const -> QChar
2020-09-28 15:38:32 +02:00
{
2022-02-14 12:26:24 +01:00
return QChar('Y');
2020-09-28 15:38:32 +02:00
}
// VWMeasurementDimension
//---------------------------------------------------------------------------------------------------------------------
class VWMeasurementDimension : public VAbstartMeasurementDimension
{
public:
VWMeasurementDimension() =default;
explicit VWMeasurementDimension(Unit units);
VWMeasurementDimension(Unit units, qreal min, qreal max, qreal step);
2022-02-14 12:26:24 +01:00
~VWMeasurementDimension() override =default;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Axis() const -> QChar override;
private:
Q_DISABLE_COPY_MOVE(VWMeasurementDimension) // NOLINT
2020-09-28 15:38:32 +02:00
};
2022-02-14 12:26:24 +01:00
//---------------------------------------------------------------------------------------------------------------------
inline auto VWMeasurementDimension::Type() const -> MeasurementDimension
{
return MeasurementDimension::W;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VWMeasurementDimension::Axis() const -> QChar
{
return QChar('W');
}
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);
2022-02-14 12:26:24 +01:00
~VZMeasurementDimension() override =default;
auto Type() const -> MeasurementDimension override;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
auto Axis() const -> QChar override;
2020-09-28 15:38:32 +02:00
2022-02-14 12:26:24 +01:00
private:
Q_DISABLE_COPY_MOVE(VZMeasurementDimension) // NOLINT
2020-09-28 15:38:32 +02:00
};
2022-02-14 12:26:24 +01:00
//---------------------------------------------------------------------------------------------------------------------
inline auto VZMeasurementDimension::Type() const -> MeasurementDimension
{
return MeasurementDimension::Z;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VZMeasurementDimension::Axis() const -> QChar
{
return QChar('Z');
}
class VDimensionRestriction
{
public:
2022-02-14 12:26:24 +01:00
VDimensionRestriction() = default;
VDimensionRestriction(qreal min, qreal max, const QString &exclude = QString());
void SetMin(qreal min);
auto GetMin() const -> qreal;
void SetMax(qreal max);
auto GetMax() const -> qreal;
void SetExcludeString(const QString &exclude);
auto GetExcludeString() const -> QString;
void SetExcludeValues(const QSet<qreal> &exclude);
auto GetExcludeValues() const -> QSet<qreal>;
private:
qreal m_min{0};
qreal m_max{0};
QSet<qreal> m_exclude{};
};
//---------------------------------------------------------------------------------------------------------------------
inline void VDimensionRestriction::SetMin(qreal min)
{
m_min = min;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VDimensionRestriction::GetMin() const -> qreal
{
return m_min;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VDimensionRestriction::SetMax(qreal max)
{
m_max = max;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VDimensionRestriction::GetMax() const -> qreal
{
return m_max;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VDimensionRestriction::SetExcludeValues(const QSet<qreal> &exclude)
{
m_exclude = exclude;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VDimensionRestriction::GetExcludeValues() const -> QSet<qreal>
{
return m_exclude;
}
2020-09-28 15:38:32 +02:00
#endif // VDIMENSIONS_H