valentina/src/libs/vformat/vmeasurements.h

246 lines
8.9 KiB
C
Raw Normal View History

/************************************************************************
**
** @file vmeasurements.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 14 7, 2015
**
** @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) 2015 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 VMEASUREMENTS_H
#define VMEASUREMENTS_H
#include <qcompilerdetection.h>
#include <QCoreApplication>
#include <QDomElement>
#include <QString>
#include <QStringList>
#include <QtGlobal>
#include "../ifc/xml/vdomdocument.h"
#include "../vmisc/def.h"
2020-10-01 12:32:02 +02:00
#include "vdimensions.h"
class VContainer;
enum class GenderType : qint8 { Male, Female, Unknown };
using VDimensions = QMap<MeasurementDimension, MeasurementDimension_p>;
class VMeasurements : public VDomDocument
{
2022-08-12 17:50:13 +02:00
Q_DECLARE_TR_FUNCTIONS(VMeasurements) // NOLINT
public:
2015-10-12 13:52:48 +02:00
explicit VMeasurements(VContainer *data);
VMeasurements(Unit unit, VContainer *data);
2020-10-01 12:32:02 +02:00
VMeasurements(Unit unit, const QVector<MeasurementDimension_p > &dimensions,
VContainer *data);
2022-08-22 15:36:01 +02:00
virtual ~VMeasurements() = default;
virtual void setXMLContent(const QString &fileName) override;
2023-05-03 13:07:02 +02:00
virtual auto SaveDocument(const QString &fileName, QString &error) -> bool override;
void AddEmpty(const QString &name, const QString &formula = QString());
void AddEmptyAfter(const QString &after, const QString &name, const QString &formula = QString());
2022-02-05 14:00:22 +01:00
void AddSeparator(const QString &name);
void AddSeparatorAfter(const QString &after, const QString &name);
void Remove(const QString &name);
void MoveTop(const QString &name);
void MoveUp(const QString &name);
void MoveDown(const QString &name);
void MoveBottom(const QString &name);
auto Units() const -> Unit;
void StoreNames(bool store);
2020-10-03 17:52:31 +02:00
void ReadMeasurements(qreal baseA, qreal baseB=0, qreal baseC=0) const;
void ClearForExport();
2023-05-03 13:07:02 +02:00
auto Type() const -> MeasurementsType;
auto DimensionABase() const -> qreal;
auto DimensionBBase() const -> qreal;
auto DimensionCBase() const -> qreal;
2023-05-03 13:07:02 +02:00
auto DimensionAStep() const -> qreal;
auto DimensionBStep() const -> qreal;
auto DimensionCStep() const -> qreal;
2020-10-03 17:52:31 +02:00
2023-05-03 13:07:02 +02:00
auto Notes() const -> QString;
void SetNotes(const QString &text);
2023-05-03 13:07:02 +02:00
auto Customer() const -> QString;
void SetCustomer(const QString &text);
2023-05-03 13:07:02 +02:00
auto BirthDate() const -> QDate;
void SetBirthDate(const QDate &date);
2023-05-03 13:07:02 +02:00
auto Gender() const -> GenderType;
2020-10-15 17:05:21 +02:00
void SetGender(const GenderType &gender);
2023-05-03 13:07:02 +02:00
auto PMSystem() const -> QString;
void SetPMSystem(const QString &system);
2023-05-03 13:07:02 +02:00
auto Email() const -> QString;
void SetEmail(const QString &text);
2023-05-03 13:07:02 +02:00
auto IsReadOnly() const -> bool;
void SetReadOnly(bool ro);
2023-05-03 13:07:02 +02:00
auto IsFullCircumference() const -> bool;
2020-10-01 13:16:21 +02:00
void SetFullCircumference(bool fc);
void SetMName(const QString &name, const QString &text);
void SetMValue(const QString &name, const QString &text);
void SetMBaseValue(const QString &name, double value);
2020-10-03 17:52:31 +02:00
void SetMShiftA(const QString &name, double value);
void SetMShiftB(const QString &name, double value);
void SetMShiftC(const QString &name, double value);
void SetMSpecialUnits(const QString &name, bool special);
void SetMCorrectionValue(const QString &name, qreal baseA, qreal baseB, qreal baseC, double value);
void SetMDescription(const QString &name, const QString &text);
void SetMFullName(const QString &name, const QString &text);
void SetMDimension(const QString &name, IMD type);
2023-05-03 13:07:02 +02:00
auto MeasurementForDimension(IMD type) const -> QString;
auto Dimensions() const -> VDimensions;
2020-10-01 12:32:02 +02:00
auto GetRestrictions() const -> QMap<QString, VDimensionRestriction >;
void SetRestrictions(const QMap<QString, VDimensionRestriction > &restrictions);
auto Restriction(qreal base, qreal base2=0) const -> VDimensionRestriction;
2020-10-03 06:34:25 +02:00
2020-10-08 12:34:38 +02:00
void SetDimensionLabels(const QMap<MeasurementDimension, DimesionLabels> &labels);
2022-02-14 12:26:24 +01:00
void SetDimensionCustomNames(const QMap<MeasurementDimension, QString> &names);
2020-10-08 12:34:38 +02:00
static const QString TagVST;
static const QString TagVIT;
static const QString TagBodyMeasurements;
static const QString TagNotes;
static const QString TagPersonal;
static const QString TagCustomer;
static const QString TagBirthDate;
static const QString TagGender;
static const QString TagPMSystem;
static const QString TagEmail;
static const QString TagReadOnly;
static const QString TagMeasurement;
2020-10-01 12:32:02 +02:00
static const QString TagDimensions;
static const QString TagDimension;
static const QString TagRestrictions;
2020-10-05 14:14:38 +02:00
static const QString TagRestriction;
2020-10-03 17:52:31 +02:00
static const QString TagCorrections;
static const QString TagCorrection;
2020-10-08 12:34:38 +02:00
static const QString TagLabels;
static const QString TagLabel;
static const QString AttrBase;
static const QString AttrValue;
2020-10-03 17:52:31 +02:00
static const QString AttrShiftA;
static const QString AttrShiftB;
static const QString AttrShiftC;
static const QString AttrCorrection;
static const QString AttrCoordinates;
static const QString AttrExclude;
2020-10-03 17:52:31 +02:00
static const QString AttrSpecialUnits;
static const QString AttrDescription;
static const QString AttrName;
static const QString AttrFullName;
2020-10-01 12:32:02 +02:00
static const QString AttrMin;
static const QString AttrMax;
static const QString AttrStep;
static const QString AttrMeasurement;
2020-10-01 13:16:21 +02:00
static const QString AttrFullCircumference;
2020-10-08 12:34:38 +02:00
static const QString AttrLabel;
static const QString AttrDimension;
2022-02-14 12:26:24 +01:00
static const QString AttrCustomName;
static const QString GenderMale;
static const QString GenderFemale;
static const QString GenderUnknown;
static const QString DimensionN;
2020-10-01 12:32:02 +02:00
static const QString DimensionX;
static const QString DimensionY;
static const QString DimensionW;
static const QString DimensionZ;
2023-05-03 13:07:02 +02:00
static auto GenderToStr(const GenderType &sex) -> QString;
static auto StrToGender(const QString &sex) -> GenderType;
2023-05-03 13:07:02 +02:00
static auto DimensionTypeToStr(const MeasurementDimension &type) -> QString;
static auto StrToDimensionType(const QString &type) -> MeasurementDimension;
2020-10-01 12:32:02 +02:00
2023-05-03 13:07:02 +02:00
static auto IMDToStr(const IMD &type) -> QString;
static auto StrToIMD(const QString &type) -> IMD;
2023-05-03 13:07:02 +02:00
static auto IMDName(IMD type) -> QString;
2023-05-03 13:07:02 +02:00
auto ListAll() const -> QStringList;
auto ListKnown() const -> QStringList;
2023-05-03 13:07:02 +02:00
auto IsDefinedKnownNamesValid() const -> bool;
2023-05-03 13:07:02 +02:00
auto GetData() const -> VContainer *;
private:
2022-08-12 17:50:13 +02:00
Q_DISABLE_COPY_MOVE(VMeasurements) // NOLINT
/** @brief data container with data. */
VContainer *data;
MeasurementsType type;
// Cache data to quick access
Unit m_units{Unit::LAST_UNIT_DO_NOT_USE};
VDimensions m_dimensions{};
/** @brief m_keepNames store names in container to check uniqueness. */
bool m_keepNames{true};
2020-10-01 12:32:02 +02:00
void CreateEmptyMultisizeFile(Unit unit, const QVector<MeasurementDimension_p > &dimensions);
void CreateEmptyIndividualFile(Unit unit);
2023-05-03 13:07:02 +02:00
auto CreateDimensions(const QVector<MeasurementDimension_p> &dimensions) -> QDomElement;
2020-10-01 12:32:02 +02:00
2023-05-03 13:07:02 +02:00
auto UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const -> qreal;
2023-05-03 13:07:02 +02:00
auto MakeEmpty(const QString &name, const QString &formula, MeasurementType varType) -> QDomElement;
auto FindM(const QString &name) const -> QDomElement;
auto ReadType() const -> MeasurementsType;
auto ReadUnits() const -> Unit;
auto ReadDimensions() const -> VDimensions;
2023-05-03 13:07:02 +02:00
auto EvalFormula(VContainer *data, const QString &formula, bool *ok) const -> qreal;
2023-05-03 13:07:02 +02:00
auto ClearPMCode(const QString &code) const -> QString;
2020-10-03 17:52:31 +02:00
2023-05-03 13:07:02 +02:00
auto ReadCorrections(const QDomElement &mElement) const -> QMap<QString, qreal>;
2020-10-03 17:52:31 +02:00
void WriteCorrections(QDomElement &mElement, const QMap<QString, qreal> &corrections);
2020-10-08 12:34:38 +02:00
void SaveDimesionLabels(QDomElement &dElement, const DimesionLabels &labels);
2023-05-03 13:07:02 +02:00
auto ReadDimensionLabels(const QDomElement &dElement) const -> DimesionLabels;
void ClearDimension(IMD type);
};
#endif // VMEASUREMENTS_H