Fix regression. Incorrect data caching.

This commit is contained in:
Roman Telezhynskyi 2021-05-07 11:19:06 +03:00
parent abdebbbfaa
commit 69da5ba9b7
15 changed files with 275 additions and 183 deletions

View File

@ -9,6 +9,7 @@
- [smart-pattern/valentina#123] Error inside Save layout dialog.
- Improve error handling for the dxf export.
- Fix correct handle a final measurement formula error when exporting a pattern recipe.
- Fix regression. Incorrect data caching.
# Version 0.7.46 Mar 31, 2021
- Fix incorrect calculation of value for multisize measurements in Valentina.

View File

@ -332,7 +332,7 @@ bool TMainWindow::LoadFile(const QString &path)
throw VException(tr("File contains invalid known measurement(s)."));
}
mUnit = m->MUnit();
mUnit = m->Units();
pUnit = mUnit;
currentDimensionA = m->DimensionABase();
@ -2672,7 +2672,7 @@ void TMainWindow::InitMenu()
void TMainWindow::InitDimensionsBaseValue()
{
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
const QString unit = UnitsToStr(m->MUnit(), true);
const QString unit = UnitsToStr(m->Units(), true);
const bool fc = m->IsFullCircumference();
auto DimensionsBaseValue = [this, dimensions, unit, fc](int index, QLabel *name, QLabel *base)
@ -2726,7 +2726,7 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p
SCASSERT(control != nullptr)
const bool fc = m->IsFullCircumference();
const QString unit = UnitsToStr(m->MUnit(), true);
const QString unit = UnitsToStr(m->Units(), true);
qreal current = -1;
if (control->currentIndex() != -1)
@ -2811,7 +2811,7 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p
void TMainWindow::InitDimensionControls()
{
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
const QString unit = UnitsToStr(m->MUnit(), true);
const QString unit = UnitsToStr(m->Units(), true);
auto InitControl = [this, dimensions, unit](int index, QLabel *&name, QComboBox *&control)
{
@ -3574,7 +3574,7 @@ bool TMainWindow::LoadFromExistingFile(const QString &path)
throw VException(tr("File contains invalid known measurement(s)."));
}
mUnit = m->MUnit();
mUnit = m->Units();
pUnit = mUnit;
currentDimensionA = m->DimensionABase();
@ -4358,7 +4358,7 @@ void TMainWindow::InitMeasurementUnits()
}
QString units;
switch (m->MUnit())
switch (m->Units())
{
case Unit::Mm:
units = tr("Millimeters");

View File

@ -2064,7 +2064,7 @@ void MainWindow::CleanWaterkmarkEditors()
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::StoreMultisizeMDimensions()
{
VAbstractValApplication::VApp()->SetMeasurementsUnits(m->MUnit());
VAbstractValApplication::VApp()->SetMeasurementsUnits(m->Units());
QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
@ -2090,7 +2090,7 @@ void MainWindow::StoreMultisizeMDimensions()
labels.value(currentBase, QString::number(fc ? currentBase*2 : currentBase)));
const bool circumference = dimension->IsCircumference();
VAbstractValApplication::VApp()
->SetDimensionSizeUnits(circumference ? m->MUnit() : Unit::LAST_UNIT_DO_NOT_USE);
->SetDimensionSizeUnits(circumference ? m->Units() : Unit::LAST_UNIT_DO_NOT_USE);
break;
}
case MeasurementDimension::W:
@ -5197,7 +5197,7 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
{
doc->SetMPath(RelativeMPath(fileName, customMeasureFile));
}
VAbstractValApplication::VApp()->SetPatternUnits(doc->MUnit());
VAbstractValApplication::VApp()->SetPatternUnits(doc->Units());
QString path = AbsoluteMPath(fileName, doc->MPath());
QString fixedMPath;
@ -5284,7 +5284,7 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile)
{
doc->SetMPath(RelativeMPath(fileName, fixedMPath));
}
VAbstractValApplication::VApp()->SetPatternUnits(doc->MUnit());
VAbstractValApplication::VApp()->SetPatternUnits(doc->Units());
}
}
catch (VException &e)

View File

@ -141,6 +141,9 @@ void VPattern::CreateEmptyFile()
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")),
this->firstChild());
// Cache values
m_units = VAbstractValApplication::VApp()->patternUnits();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -41,6 +41,19 @@ VAbstractMConverter::VAbstractMConverter(const QString &fileName)
{
}
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractMConverter::Units() const -> Unit
{
Unit units = StrToUnits(UniqueTagText(TagUnit, unitCM));
if (units == Unit::Px)
{
units = Unit::Cm;
}
return units;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractMConverter::AddRootComment()
{

View File

@ -43,6 +43,8 @@ public:
explicit VAbstractMConverter(const QString &fileName);
virtual ~VAbstractMConverter() Q_DECL_EQ_DEFAULT;
auto Units() const -> Unit;
protected:
void AddRootComment();
static QMultiMap<QString, QString> OldNamesToNewNames_InV0_3_0();

View File

@ -155,14 +155,6 @@ bool VAbstractPattern::patternLabelWasChanged = false;
namespace
{
// Need to be reinited in setXMLContent as well
Q_GLOBAL_STATIC_WITH_ARGS(QString, patternNumberCached, (unknownCharacter))
Q_GLOBAL_STATIC_WITH_ARGS(QString, labelDateFormatCached, (unknownCharacter))
Q_GLOBAL_STATIC_WITH_ARGS(QString, patternNameCached, (unknownCharacter))
Q_GLOBAL_STATIC_WITH_ARGS(QString, MPathCached, (unknownCharacter))
Q_GLOBAL_STATIC_WITH_ARGS(QString, WatermarkPathCached, (unknownCharacter))
Q_GLOBAL_STATIC_WITH_ARGS(QString, companyNameCached, (unknownCharacter))
void ReadExpressionAttribute(QVector<VFormulaField> &expressions, const QDomElement &element, const QString &attribute)
{
VFormulaField formula;
@ -592,17 +584,26 @@ void VAbstractPattern::setXMLContent(const QString &fileName)
{
Clear();
VDomDocument::setXMLContent(fileName);
m_patternNumber = ReadPatternNumber();
m_labelDateFormat = ReadLabelDateFormat();
m_patternName = ReadPatternName();
m_MPath = ReadMPath();
m_watermarkPath = ReadWatermarkPath();
m_companyName = ReadCompanyName();
m_units = ReadUnits();
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::Clear()
{
clear();
*patternNumberCached = unknownCharacter;
*labelDateFormatCached = unknownCharacter;
*patternNameCached = unknownCharacter;
*MPathCached = unknownCharacter;
*companyNameCached = unknownCharacter;
m_patternNumber.clear();
m_labelDateFormat.clear();
m_patternName.clear();
m_MPath.clear();
m_watermarkPath.clear();
m_companyName.clear();
m_units = Unit::LAST_UNIT_DO_NOT_USE;
}
//---------------------------------------------------------------------------------------------------------------------
@ -820,11 +821,7 @@ QVector<VToolRecord> VAbstractPattern::getLocalHistory() const
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::MPath() const
{
if (*MPathCached == unknownCharacter)
{
*MPathCached = UniqueTagText(TagMeasurements);
}
return *MPathCached;
return m_MPath;
}
//---------------------------------------------------------------------------------------------------------------------
@ -832,9 +829,10 @@ void VAbstractPattern::SetMPath(const QString &path)
{
if (setTagText(TagMeasurements, path))
{
emit patternChanged(false);
m_MPath = path;
patternLabelWasChanged = true;
*MPathCached = path;
modified = true;
emit patternChanged(false);
}
else
{
@ -932,19 +930,15 @@ void VAbstractPattern::SetNotes(const QString &text)
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetPatternName() const
{
if (*patternNameCached == unknownCharacter)
{
*patternNameCached = UniqueTagText(TagPatternName);
}
return *patternNameCached;
return m_patternName;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetPatternName(const QString &qsName)
{
*patternNameCached = qsName;
m_patternName = qsName;
CheckTagExists(TagPatternName);
setTagText(TagPatternName, *patternNameCached);
setTagText(TagPatternName, m_patternName);
patternLabelWasChanged = true;
modified = true;
emit patternChanged(false);
@ -953,19 +947,15 @@ void VAbstractPattern::SetPatternName(const QString &qsName)
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetCompanyName() const
{
if (*companyNameCached == unknownCharacter)
{
*companyNameCached = UniqueTagText(TagCompanyName);
}
return *companyNameCached;
return m_companyName;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetCompanyName(const QString& qsName)
{
*companyNameCached = qsName;
m_companyName = qsName;
CheckTagExists(TagCompanyName);
setTagText(TagCompanyName, *companyNameCached);
setTagText(TagCompanyName, m_companyName);
patternLabelWasChanged = true;
modified = true;
emit patternChanged(false);
@ -974,19 +964,15 @@ void VAbstractPattern::SetCompanyName(const QString& qsName)
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetPatternNumber() const
{
if (*patternNumberCached == unknownCharacter)
{
*patternNumberCached = UniqueTagText(TagPatternNum);
}
return *patternNumberCached;
return m_patternNumber;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetPatternNumber(const QString& qsNum)
{
*patternNumberCached = qsNum;
m_patternNumber = qsNum;
CheckTagExists(TagPatternNum);
setTagText(TagPatternNum, *patternNumberCached);
setTagText(TagPatternNum, m_patternNumber);
patternLabelWasChanged = true;
modified = true;
emit patternChanged(false);
@ -1043,34 +1029,15 @@ void VAbstractPattern::SetCustomerEmail(const QString &email)
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetLabelDateFormat() const
{
if (*labelDateFormatCached == unknownCharacter)
{
const QString globalLabelDateFormat = VAbstractApplication::VApp()->Settings()->GetLabelDateFormat();
const QDomNodeList list = elementsByTagName(TagPatternLabel);
if (list.isEmpty())
{
return globalLabelDateFormat;
}
try
{
*labelDateFormatCached = GetParametrString(list.at(0).toElement(), AttrDateFormat);
}
catch (const VExceptionEmptyParameter &)
{
return globalLabelDateFormat;
}
}
return *labelDateFormatCached;
return m_labelDateFormat;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetLabelDateFormat(const QString &format)
{
*labelDateFormatCached = format;
m_labelDateFormat = format;
QDomElement tag = CheckTagExists(TagPatternLabel);
SetAttribute(tag, AttrDateFormat, *labelDateFormatCached);
SetAttribute(tag, AttrDateFormat, m_labelDateFormat);
patternLabelWasChanged = true;
modified = true;
emit patternChanged(false);
@ -1142,7 +1109,8 @@ bool VAbstractPattern::SetWatermarkPath(const QString &path)
emit patternChanged(false);
patternLabelWasChanged = true;
*WatermarkPathCached = path;
m_watermarkPath = path;
modified = true;
return true;
}
else
@ -1151,7 +1119,8 @@ bool VAbstractPattern::SetWatermarkPath(const QString &path)
{
emit patternChanged(false);
patternLabelWasChanged = true;
*WatermarkPathCached = path;
m_watermarkPath = path;
modified = true;
return true;
}
else
@ -1165,11 +1134,7 @@ bool VAbstractPattern::SetWatermarkPath(const QString &path)
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetWatermarkPath() const
{
if (*WatermarkPathCached == unknownCharacter)
{
*WatermarkPathCached = UniqueTagText(TagWatermark);
}
return *WatermarkPathCached;
return m_watermarkPath;
}
//---------------------------------------------------------------------------------------------------------------------
@ -2277,6 +2242,73 @@ bool VAbstractPattern::GroupHasItem(const QDomElement &groupDomElement, quint32
return result;
}
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractPattern::ReadUnits() const -> Unit
{
Unit units = StrToUnits(UniqueTagText(TagUnit, unitCM));
if (units == Unit::Px)
{
units = Unit::Cm;
}
return units;
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::ReadPatternNumber() const
{
return UniqueTagText(TagPatternNum);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::ReadLabelDateFormat() const
{
const QString globalLabelDateFormat = VAbstractApplication::VApp()->Settings()->GetLabelDateFormat();
const QDomNodeList list = elementsByTagName(TagPatternLabel);
if (list.isEmpty())
{
return globalLabelDateFormat;
}
QString labelDateFormat;
try
{
labelDateFormat = GetParametrString(list.at(0).toElement(), AttrDateFormat);
}
catch (const VExceptionEmptyParameter &)
{
return globalLabelDateFormat;
}
return labelDateFormat;
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::ReadPatternName() const
{
return UniqueTagText(TagPatternName);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::ReadMPath() const
{
return UniqueTagText(TagMeasurements);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::ReadWatermarkPath() const
{
return UniqueTagText(TagWatermark);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::ReadCompanyName() const
{
return UniqueTagText(TagCompanyName);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Adds an item to the given group with the given toolId and objectId
@ -2455,6 +2487,12 @@ VContainer VAbstractPattern::GetCompletePPData(const QString &name) const
return VContainer(nullptr, nullptr, VContainer::UniqueNamespace());
}
//---------------------------------------------------------------------------------------------------------------------
Unit VAbstractPattern::Units() const
{
return m_units;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::FilterGroupTags(const QString &tags)
{

View File

@ -233,6 +233,8 @@ public:
virtual VContainer GetCompleteData() const;
virtual VContainer GetCompletePPData(const QString &name) const;
auto Units() const -> Unit;
static const QString TagPattern;
static const QString TagCalculation;
static const QString TagModeling;
@ -396,6 +398,14 @@ protected:
/** @brief modified keep state of the document for cases that do not cover QUndoStack*/
mutable bool modified;
Unit m_units{Unit::LAST_UNIT_DO_NOT_USE};
QString m_patternNumber{};
QString m_labelDateFormat{};
QString m_patternName{};
QString m_MPath{};
QString m_watermarkPath{};
QString m_companyName{};
/** @brief tools list with pointer on tools. */
static QHash<quint32, VDataTool*> tools;
/** @brief patternLabelLines list to speed up reading a template by many pieces. */
@ -421,6 +431,15 @@ protected:
QVector<VToolRecord> getLocalHistory(const QString &draw) const;
bool GroupHasItem(const QDomElement &groupDomElement, quint32 toolId, quint32 objectId);
auto ReadUnits() const -> Unit;
auto ReadPatternNumber() const ->QString;
auto ReadLabelDateFormat() const ->QString;
auto ReadPatternName() const ->QString;
auto ReadMPath() const ->QString;
auto ReadWatermarkPath() const -> QString;
auto ReadCompanyName() const -> QString;
private:
Q_DISABLE_COPY(VAbstractPattern)

View File

@ -232,8 +232,6 @@ bool LessThen(const QDomNode &element1, const QDomNode &element2)
}
return false;
}
Unit mUnitCached = Unit::LAST_UNIT_DO_NOT_USE;
} // namespace
Q_LOGGING_CATEGORY(vXML, "v.xml")
@ -636,22 +634,6 @@ quint32 VDomDocument::GetParametrId(const QDomElement &domElement)
return id;
}
//---------------------------------------------------------------------------------------------------------------------
Unit VDomDocument::MUnit() const
{
if (mUnitCached == Unit::LAST_UNIT_DO_NOT_USE)
{
mUnitCached = StrToUnits(UniqueTagText(TagUnit, unitCM));
if (mUnitCached == Unit::Px)
{
mUnitCached = Unit::Cm;
}
}
return mUnitCached;
}
//---------------------------------------------------------------------------------------------------------------------
QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVal) const
{

View File

@ -118,8 +118,6 @@ public:
static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue);
static quint32 GetParametrId(const QDomElement& domElement);
Unit MUnit() const;
virtual void setXMLContent(const QString &fileName);
static QString UnitsHelpString();

View File

@ -345,7 +345,7 @@ void VVSTConverter::AddNewTagsForV0_5_0()
return GetParametrInt(baseTag, QStringLiteral("base"), QChar('0'));
};
const Unit units = MUnit();
const Unit units = Units();
{
const int step = static_cast<int>(UnitConvertor(6, Unit::Cm, units));

View File

@ -109,10 +109,7 @@ const QString VMeasurements::DimensionZ = QStringLiteral("z");
namespace
{
using VDimensions = QMap<MeasurementDimension, MeasurementDimension_p>;
Q_GLOBAL_STATIC_WITH_ARGS(const QString, defBirthDate, (QLatin1String("1800-01-01")))
Q_GLOBAL_STATIC(VDimensions, dimensionsCached)
//---------------------------------------------------------------------------------------------------------------------
QString FileComment()
@ -124,8 +121,7 @@ QString FileComment()
//---------------------------------------------------------------------------------------------------------------------
VMeasurements::VMeasurements(VContainer *data)
:VDomDocument(),
data(data),
: data(data),
type(MeasurementsType::Unknown)
{
SCASSERT(data != nullptr)
@ -133,8 +129,7 @@ VMeasurements::VMeasurements(VContainer *data)
//---------------------------------------------------------------------------------------------------------------------
VMeasurements::VMeasurements(Unit unit, VContainer *data)
:VDomDocument(),
data(data),
: data(data),
type(MeasurementsType::Individual)
{
SCASSERT(data != nullptr)
@ -145,8 +140,7 @@ VMeasurements::VMeasurements(Unit unit, VContainer *data)
//---------------------------------------------------------------------------------------------------------------------
VMeasurements::VMeasurements(Unit unit, const QVector<MeasurementDimension_p > &dimensions,
VContainer *data)
:VDomDocument(),
data(data),
: data(data),
type(MeasurementsType::Multisize)
{
SCASSERT(data != nullptr)
@ -159,6 +153,8 @@ void VMeasurements::setXMLContent(const QString &fileName)
{
VDomDocument::setXMLContent(fileName);
type = ReadType();
m_units = ReadUnits();
m_dimensions = ReadDimensions();
}
//---------------------------------------------------------------------------------------------------------------------
@ -277,6 +273,12 @@ void VMeasurements::MoveBottom(const QString &name)
}
}
//---------------------------------------------------------------------------------------------------------------------
auto VMeasurements::Units() const -> Unit
{
return m_units;
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::StoreNames(bool store)
{
@ -327,25 +329,25 @@ void VMeasurements::ReadMeasurements(qreal baseA, qreal baseB, qreal baseC) cons
if (not specialUnits)
{
base = UnitConvertor(base, MUnit(), *data->GetPatternUnit());
shiftA = UnitConvertor(shiftA, MUnit(), *data->GetPatternUnit());
shiftB = UnitConvertor(shiftB, MUnit(), *data->GetPatternUnit());
shiftC = UnitConvertor(shiftC, MUnit(), *data->GetPatternUnit());
base = UnitConvertor(base, Units(), *data->GetPatternUnit());
shiftA = UnitConvertor(shiftA, Units(), *data->GetPatternUnit());
shiftB = UnitConvertor(shiftB, Units(), *data->GetPatternUnit());
shiftC = UnitConvertor(shiftC, Units(), *data->GetPatternUnit());
QMutableMapIterator<QString, qreal> iterator(corrections);
while (iterator.hasNext())
{
iterator.next();
iterator.setValue(UnitConvertor(iterator.value(), MUnit(), *data->GetPatternUnit()));
iterator.setValue(UnitConvertor(iterator.value(), Units(), *data->GetPatternUnit()));
}
convertedBaseA = UnitConvertor(convertedBaseA, MUnit(), *data->GetPatternUnit());
convertedBaseB = UnitConvertor(convertedBaseB, MUnit(), *data->GetPatternUnit());
convertedBaseC = UnitConvertor(convertedBaseC, MUnit(), *data->GetPatternUnit());
convertedBaseA = UnitConvertor(convertedBaseA, Units(), *data->GetPatternUnit());
convertedBaseB = UnitConvertor(convertedBaseB, Units(), *data->GetPatternUnit());
convertedBaseC = UnitConvertor(convertedBaseC, Units(), *data->GetPatternUnit());
convertedStepA = UnitConvertor(convertedStepA, MUnit(), *data->GetPatternUnit());
convertedStepB = UnitConvertor(convertedStepB, MUnit(), *data->GetPatternUnit());
convertedStepC = UnitConvertor(convertedStepC, MUnit(), *data->GetPatternUnit());
convertedStepA = UnitConvertor(convertedStepA, Units(), *data->GetPatternUnit());
convertedStepB = UnitConvertor(convertedStepB, Units(), *data->GetPatternUnit());
convertedStepC = UnitConvertor(convertedStepC, Units(), *data->GetPatternUnit());
}
meash = QSharedPointer<VMeasurement>::create(static_cast<quint32>(i), name,
@ -380,7 +382,7 @@ void VMeasurements::ReadMeasurements(qreal baseA, qreal baseB, qreal baseC) cons
if (not specialUnits)
{
value = UnitConvertor(value, MUnit(), *data->GetPatternUnit());
value = UnitConvertor(value, Units(), *data->GetPatternUnit());
}
meash = QSharedPointer<VMeasurement>::create(data, static_cast<quint32>(i), name, value, formula, ok);
@ -846,61 +848,9 @@ QString VMeasurements::MeasurementForDimension(IMD type) const
}
//---------------------------------------------------------------------------------------------------------------------
auto VMeasurements::Dimensions() const -> QMap<MeasurementDimension, MeasurementDimension_p >
auto VMeasurements::Dimensions() const -> VDimensions
{
if (type != MeasurementsType::Multisize)
{
return QMap<MeasurementDimension, MeasurementDimension_p>();
}
if (dimensionsCached->isEmpty())
{
const Unit units = MUnit();
const QDomNodeList list = elementsByTagName(TagDimension);
for (int i=0; i < list.size(); ++i)
{
const QDomElement dom = list.at(i).toElement();
const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType));
const qreal min = GetParametrDouble(dom, AttrMin, QChar('0'));
const qreal max = GetParametrDouble(dom, AttrMax, QChar('0'));
const qreal step = GetParametrDouble(dom, AttrStep, QStringLiteral("-1"));
const qreal base = GetParametrDouble(dom, AttrBase, QChar('0'));
const DimesionLabels labels = ReadDimensionLabels(dom);
if (type == MeasurementDimension::X)
{
auto dimension = QSharedPointer<VXMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetLabels(labels);
dimensionsCached->insert(type, dimension);
}
else if (type == MeasurementDimension::Y)
{
auto dimension = QSharedPointer<VYMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr));
dimension->SetLabels(labels);
dimensionsCached->insert(type, dimension);
}
else if (type == MeasurementDimension::W)
{
auto dimension = QSharedPointer<VWMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetLabels(labels);
dimensionsCached->insert(type, dimension);
}
else if (type == MeasurementDimension::Z)
{
auto dimension = QSharedPointer<VZMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetLabels(labels);
dimensionsCached->insert(type, dimension);
}
}
}
return *dimensionsCached;
return m_dimensions;
}
//---------------------------------------------------------------------------------------------------------------------
@ -976,7 +926,7 @@ void VMeasurements::SetDimensionLabels(const QMap<MeasurementDimension, Dimesion
}
}
dimensionsCached->clear(); // Invalidate cache
m_dimensions = ReadDimensions(); // Refresh cache
}
//---------------------------------------------------------------------------------------------------------------------
@ -1187,6 +1137,10 @@ void VMeasurements::CreateEmptyMultisizeFile(Unit unit,
this->appendChild(mElement);
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild());
// Cache data
m_units = unit;
m_dimensions = ReadDimensions();
}
//---------------------------------------------------------------------------------------------------------------------
@ -1215,6 +1169,10 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit)
this->appendChild(mElement);
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild());
// Cache data
m_units = unit;
m_dimensions = ReadDimensions();
}
//---------------------------------------------------------------------------------------------------------------------
@ -1246,7 +1204,7 @@ QDomElement VMeasurements::CreateDimensions(const QVector<MeasurementDimension_p
//---------------------------------------------------------------------------------------------------------------------
qreal VMeasurements::UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const
{
const qreal defVal = UnitConvertor(defValue, Unit::Cm, MUnit());
const qreal defVal = UnitConvertor(defValue, Unit::Cm, Units());
const QDomNodeList nodeList = this->elementsByTagName(tag);
if (nodeList.isEmpty())
@ -1332,6 +1290,76 @@ MeasurementsType VMeasurements::ReadType() const
}
}
//---------------------------------------------------------------------------------------------------------------------
auto VMeasurements::ReadUnits() const -> Unit
{
Unit units = StrToUnits(UniqueTagText(TagUnit, unitCM));
if (units == Unit::Px)
{
units = Unit::Cm;
}
return units;
}
//---------------------------------------------------------------------------------------------------------------------
auto VMeasurements::ReadDimensions() const -> VDimensions
{
if (type != MeasurementsType::Multisize)
{
return {};
}
VDimensions dimensions;
const Unit units = Units();
const QDomNodeList list = elementsByTagName(TagDimension);
for (int i=0; i < list.size(); ++i)
{
const QDomElement dom = list.at(i).toElement();
const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType));
const qreal min = GetParametrDouble(dom, AttrMin, QChar('0'));
const qreal max = GetParametrDouble(dom, AttrMax, QChar('0'));
const qreal step = GetParametrDouble(dom, AttrStep, QStringLiteral("-1"));
const qreal base = GetParametrDouble(dom, AttrBase, QChar('0'));
const DimesionLabels labels = ReadDimensionLabels(dom);
if (type == MeasurementDimension::X)
{
auto dimension = QSharedPointer<VXMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetLabels(labels);
dimensions.insert(type, dimension);
}
else if (type == MeasurementDimension::Y)
{
auto dimension = QSharedPointer<VYMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr));
dimension->SetLabels(labels);
dimensions.insert(type, dimension);
}
else if (type == MeasurementDimension::W)
{
auto dimension = QSharedPointer<VWMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetLabels(labels);
dimensions.insert(type, dimension);
}
else if (type == MeasurementDimension::Z)
{
auto dimension = QSharedPointer<VZMeasurementDimension>::create(units, min, max, step);
dimension->SetBaseValue(base);
dimension->SetLabels(labels);
dimensions.insert(type, dimension);
}
}
return dimensions;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VMeasurements::EvalFormula(VContainer *data, const QString &formula, bool *ok) const
{

View File

@ -44,6 +44,8 @@ class VContainer;
enum class GenderType : qint8 { Male, Female, Unknown };
using VDimensions = QMap<MeasurementDimension, MeasurementDimension_p>;
class VMeasurements : public VDomDocument
{
Q_DECLARE_TR_FUNCTIONS(VMeasurements)
@ -65,6 +67,8 @@ public:
void MoveDown(const QString &name);
void MoveBottom(const QString &name);
auto Units() const -> Unit;
void StoreNames(bool store);
void ReadMeasurements(qreal baseA, qreal baseB=0, qreal baseC=0) const;
@ -117,7 +121,7 @@ public:
QString MeasurementForDimension(IMD type) const;
auto Dimensions() const -> QMap<MeasurementDimension, MeasurementDimension_p >;
auto Dimensions() const -> VDimensions;
auto GetRestrictions() const -> QMap<QString, VDimensionRestriction >;
void SetRestrictions(const QMap<QString, VDimensionRestriction > &restrictions);
@ -201,6 +205,10 @@ private:
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};
@ -214,6 +222,8 @@ private:
QDomElement MakeEmpty(const QString &name, const QString &formula);
QDomElement FindM(const QString &name) const;
MeasurementsType ReadType() const;
auto ReadUnits() const -> Unit;
auto ReadDimensions() const -> VDimensions;
qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const;

View File

@ -34,4 +34,3 @@ const QString preferencesOtherIcon = QStringLiteral("preferences-other");
const QString degreeSymbol = QStringLiteral("°");
const QString trueStr = QStringLiteral("true");
const QString falseStr = QStringLiteral("false");
const QString unknownCharacter = QStringLiteral("<EFBFBD>");

View File

@ -40,6 +40,5 @@ extern const QString preferencesOtherIcon;
extern const QString degreeSymbol;
extern const QString trueStr;
extern const QString falseStr;
extern const QString unknownCharacter;
#endif // LITERALS_H