2015-07-14 19:22:31 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vmeasurements.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 14 7, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vmeasurements.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <qnumeric.h>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QDomNode>
|
|
|
|
#include <QDomNodeList>
|
|
|
|
#include <QDomText>
|
|
|
|
#include <QForeachContainer>
|
|
|
|
#include <QLatin1Char>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QScopedPointer>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
#include "../ifc/exception/vexceptionemptyparameter.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vvitconverter.h"
|
|
|
|
#include "../ifc/xml/vvstconverter.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2015-10-15 14:37:10 +02:00
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../qmuparser/qmuparsererror.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/calculator.h"
|
|
|
|
#include "../vpatterndb/variables/vmeasurement.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2015-07-16 11:38:54 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
class QDate;
|
2015-10-18 21:30:51 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
const QString VMeasurements::TagVST = QStringLiteral("vst");
|
|
|
|
const QString VMeasurements::TagVIT = QStringLiteral("vit");
|
|
|
|
const QString VMeasurements::TagBodyMeasurements = QStringLiteral("body-measurements");
|
|
|
|
const QString VMeasurements::TagUnit = QStringLiteral("unit");
|
|
|
|
const QString VMeasurements::TagNotes = QStringLiteral("notes");
|
|
|
|
const QString VMeasurements::TagSize = QStringLiteral("size");
|
|
|
|
const QString VMeasurements::TagHeight = QStringLiteral("height");
|
|
|
|
const QString VMeasurements::TagPersonal = QStringLiteral("personal");
|
|
|
|
const QString VMeasurements::TagFamilyName = QStringLiteral("family-name");
|
|
|
|
const QString VMeasurements::TagGivenName = QStringLiteral("given-name");
|
|
|
|
const QString VMeasurements::TagBirthDate = QStringLiteral("birth-date");
|
2015-10-13 10:13:43 +02:00
|
|
|
const QString VMeasurements::TagGender = QStringLiteral("gender");
|
2015-10-16 19:26:05 +02:00
|
|
|
const QString VMeasurements::TagPMSystem = QStringLiteral("pm_system");
|
2015-07-16 11:38:54 +02:00
|
|
|
const QString VMeasurements::TagEmail = QStringLiteral("email");
|
2015-07-18 13:08:44 +02:00
|
|
|
const QString VMeasurements::TagReadOnly = QStringLiteral("read-only");
|
2015-07-19 14:28:01 +02:00
|
|
|
const QString VMeasurements::TagMeasurement = QStringLiteral("m");
|
2015-07-16 11:38:54 +02:00
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
const QString VMeasurements::AttrBase = QStringLiteral("base");
|
|
|
|
const QString VMeasurements::AttrValue = QStringLiteral("value");
|
|
|
|
const QString VMeasurements::AttrSizeIncrease = QStringLiteral("size_increase");
|
|
|
|
const QString VMeasurements::AttrHeightIncrease = QStringLiteral("height_increase");
|
|
|
|
const QString VMeasurements::AttrDescription = QStringLiteral("description");
|
|
|
|
const QString VMeasurements::AttrName = QStringLiteral("name");
|
2015-07-25 10:54:39 +02:00
|
|
|
const QString VMeasurements::AttrFullName = QStringLiteral("full_name");
|
2015-07-16 11:38:54 +02:00
|
|
|
|
2015-10-13 10:13:43 +02:00
|
|
|
const QString VMeasurements::GenderMale = QStringLiteral("male");
|
|
|
|
const QString VMeasurements::GenderFemale = QStringLiteral("female");
|
|
|
|
const QString VMeasurements::GenderUnknown = QStringLiteral("unknown");
|
2015-07-14 19:22:31 +02:00
|
|
|
|
2015-12-19 20:26:05 +01:00
|
|
|
const QString defBirthDate = QStringLiteral("1800-01-01");
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurements::VMeasurements(VContainer *data)
|
|
|
|
:VDomDocument(),
|
2015-07-16 11:38:54 +02:00
|
|
|
data(data),
|
2015-07-21 19:26:33 +02:00
|
|
|
type(MeasurementsType::Unknown)
|
2015-07-15 09:16:59 +02:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
}
|
2015-07-14 19:22:31 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurements::VMeasurements(Unit unit, VContainer *data)
|
|
|
|
:VDomDocument(),
|
|
|
|
data(data),
|
2015-07-21 19:26:33 +02:00
|
|
|
type(MeasurementsType::Individual)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(data != nullptr)
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
|
|
CreateEmptyIndividualFile(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurements::VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data)
|
|
|
|
:VDomDocument(),
|
|
|
|
data(data),
|
2015-07-21 19:26:33 +02:00
|
|
|
type(MeasurementsType::Standard)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(data != nullptr)
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
|
|
CreateEmptyStandardFile(unit, baseSize, baseHeight);
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurements::~VMeasurements()
|
2015-07-14 19:22:31 +02:00
|
|
|
{
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::setXMLContent(const QString &fileName)
|
|
|
|
{
|
|
|
|
VDomDocument::setXMLContent(fileName);
|
|
|
|
type = ReadType();
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-01 13:25:05 +02:00
|
|
|
void VMeasurements::AddEmpty(const QString &name, const QString &formula)
|
2015-07-19 14:28:01 +02:00
|
|
|
{
|
2015-08-01 13:25:05 +02:00
|
|
|
const QDomElement element = MakeEmpty(name, formula);
|
2015-07-19 14:28:01 +02:00
|
|
|
|
2015-07-21 19:26:33 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).appendChild(element);
|
|
|
|
}
|
2015-07-19 14:28:01 +02:00
|
|
|
|
2015-07-21 19:26:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-01 13:25:05 +02:00
|
|
|
void VMeasurements::AddEmptyAfter(const QString &after, const QString &name, const QString &formula)
|
2015-07-21 19:26:33 +02:00
|
|
|
{
|
2015-08-01 13:25:05 +02:00
|
|
|
const QDomElement element = MakeEmpty(name, formula);
|
2015-07-21 19:26:33 +02:00
|
|
|
const QDomElement sibling = FindM(after);
|
|
|
|
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
|
|
|
|
if (sibling.isNull())
|
2015-07-19 14:28:01 +02:00
|
|
|
{
|
2015-07-21 19:26:33 +02:00
|
|
|
list.at(0).appendChild(element);
|
2015-07-19 14:28:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-21 19:26:33 +02:00
|
|
|
list.at(0).insertAfter(element, sibling);
|
2015-07-19 14:28:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 08:41:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::Remove(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).removeChild(FindM(name));
|
|
|
|
}
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveTop(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList mList = elementsByTagName(TagMeasurement);
|
|
|
|
if (mList.size() >= 2)
|
|
|
|
{
|
|
|
|
const QDomNode top = mList.at(0);
|
|
|
|
if (not top.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertBefore(node, top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 09:01:34 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveUp(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomElement prSibling = node.previousSiblingElement(TagMeasurement);
|
|
|
|
if (not prSibling.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertBefore(node, prSibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveDown(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomElement nextSibling = node.nextSiblingElement(TagMeasurement);
|
|
|
|
if (not nextSibling.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertAfter(node, nextSibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveBottom(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList mList = elementsByTagName(TagMeasurement);
|
|
|
|
if (mList.size() >= 2)
|
|
|
|
{
|
|
|
|
const QDomNode bottom = mList.at(mList.size()-1);
|
|
|
|
if (not bottom.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertAfter(node, bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::ReadMeasurements() const
|
|
|
|
{
|
2015-08-17 14:36:55 +02:00
|
|
|
// For conversion values we must first calculate all data in measurement file's unit.
|
|
|
|
// That's why we need two containers: one for converted values, second for real data.
|
|
|
|
|
|
|
|
// Container for values in measurement file's unit
|
|
|
|
VContainer *tempData = new VContainer(data->GetTrVars(), data->GetPatternUnit());
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
|
|
|
const QString name = GetParametrString(dom, AttrName);
|
|
|
|
|
|
|
|
QString description;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
description = GetParametrString(dom, AttrDescription);
|
|
|
|
}
|
|
|
|
catch (VExceptionEmptyParameter &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
}
|
|
|
|
|
2015-07-25 10:54:39 +02:00
|
|
|
QString fullName;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fullName = GetParametrString(dom, AttrFullName);
|
|
|
|
}
|
|
|
|
catch (VExceptionEmptyParameter &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
VMeasurement *meash;
|
2015-08-17 14:36:55 +02:00
|
|
|
VMeasurement *tempMeash;
|
2015-07-24 12:06:39 +02:00
|
|
|
if (type == MeasurementsType::Standard)
|
|
|
|
{
|
2015-08-17 14:36:55 +02:00
|
|
|
qreal base = GetParametrDouble(dom, AttrBase, "0");
|
|
|
|
qreal ksize = GetParametrDouble(dom, AttrSizeIncrease, "0");
|
|
|
|
qreal kheight = GetParametrDouble(dom, AttrHeightIncrease, "0");
|
|
|
|
|
2015-10-26 09:36:07 +01:00
|
|
|
tempMeash = new VMeasurement(static_cast<quint32>(i), name, BaseSize(), BaseHeight(), base, ksize,
|
2015-10-19 15:21:06 +02:00
|
|
|
kheight);
|
2015-08-17 14:36:55 +02:00
|
|
|
|
|
|
|
base = UnitConvertor(base, MUnit(), *data->GetPatternUnit());
|
|
|
|
ksize = UnitConvertor(ksize, MUnit(), *data->GetPatternUnit());
|
|
|
|
kheight = UnitConvertor(kheight, MUnit(), *data->GetPatternUnit());
|
2015-07-24 12:06:39 +02:00
|
|
|
|
2015-08-17 14:36:55 +02:00
|
|
|
const qreal baseSize = UnitConvertor(BaseSize(), MUnit(), *data->GetPatternUnit());
|
|
|
|
const qreal baseHeight = UnitConvertor(BaseHeight(), MUnit(), *data->GetPatternUnit());
|
|
|
|
|
2015-10-26 09:36:07 +01:00
|
|
|
meash = new VMeasurement(static_cast<quint32>(i), name, baseSize, baseHeight, base, ksize, kheight,
|
2015-10-19 15:21:06 +02:00
|
|
|
fullName, description);
|
2015-07-24 12:06:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-17 14:36:55 +02:00
|
|
|
const QString formula = GetParametrString(dom, AttrValue, "0");
|
2015-07-24 12:06:39 +02:00
|
|
|
bool ok = false;
|
2015-08-17 14:36:55 +02:00
|
|
|
qreal value = EvalFormula(tempData, formula, &ok);
|
|
|
|
|
2015-10-26 09:36:07 +01:00
|
|
|
tempMeash = new VMeasurement(tempData, static_cast<quint32>(i), name, value, formula, ok);
|
2015-08-17 14:36:55 +02:00
|
|
|
|
|
|
|
value = UnitConvertor(value, MUnit(), *data->GetPatternUnit());
|
2015-10-26 09:36:07 +01:00
|
|
|
meash = new VMeasurement(data, static_cast<quint32>(i), name, value, formula, ok, fullName,
|
2015-10-19 15:21:06 +02:00
|
|
|
description);
|
2015-07-24 12:06:39 +02:00
|
|
|
}
|
2015-08-17 14:36:55 +02:00
|
|
|
tempData->AddVariable(name, tempMeash);
|
2015-07-24 12:06:39 +02:00
|
|
|
data->AddVariable(name, meash);
|
|
|
|
}
|
2015-08-17 14:36:55 +02:00
|
|
|
|
|
|
|
delete tempData;
|
2015-07-24 12:06:39 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 14:37:10 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::ClearForExport()
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
if (qmu::QmuTokenParser::IsSingle(domElement.attribute(AttrValue)))
|
|
|
|
{
|
|
|
|
SetAttribute(domElement, AttrValue, QString("0"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
MeasurementsType VMeasurements::Type() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Unit VMeasurements::MUnit() const
|
|
|
|
{
|
|
|
|
const QString unit = UniqueTagText(TagUnit, UnitCM);
|
|
|
|
return VDomDocument::StrToUnits(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VMeasurements::BaseSize() const
|
|
|
|
{
|
|
|
|
if (type == MeasurementsType::Standard)
|
|
|
|
{
|
|
|
|
return static_cast<int>(UniqueTagAttr(TagSize, AttrBase, 50));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VMeasurements::BaseHeight() const
|
|
|
|
{
|
|
|
|
if (type == MeasurementsType::Standard)
|
|
|
|
{
|
|
|
|
return static_cast<int>(UniqueTagAttr(TagHeight, AttrBase, 176));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::Notes() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagNotes, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetNotes(const QString &text)
|
|
|
|
{
|
2015-07-18 15:25:56 +02:00
|
|
|
if (not ReadOnly())
|
|
|
|
{
|
|
|
|
setTagText(TagNotes, text);
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::FamilyName() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagFamilyName, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetFamilyName(const QString &text)
|
|
|
|
{
|
2015-07-18 15:25:56 +02:00
|
|
|
if (not ReadOnly())
|
|
|
|
{
|
|
|
|
setTagText(TagFamilyName, text);
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::GivenName() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagGivenName, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetGivenName(const QString &text)
|
|
|
|
{
|
2015-07-18 15:25:56 +02:00
|
|
|
if (not ReadOnly())
|
|
|
|
{
|
|
|
|
setTagText(TagGivenName, text);
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDate VMeasurements::BirthDate() const
|
|
|
|
{
|
2015-12-19 20:26:05 +01:00
|
|
|
return QDate::fromString(UniqueTagText(TagBirthDate, defBirthDate), "yyyy-MM-dd");
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetBirthDate(const QDate &date)
|
|
|
|
{
|
2015-07-18 15:25:56 +02:00
|
|
|
if (not ReadOnly())
|
|
|
|
{
|
|
|
|
setTagText(TagBirthDate, date.toString("yyyy-MM-dd"));
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
GenderType VMeasurements::Gender() const
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
return StrToGender(UniqueTagText(TagGender, GenderUnknown));
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
void VMeasurements::SetGender(const GenderType &gender)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2015-07-18 15:25:56 +02:00
|
|
|
if (not ReadOnly())
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
setTagText(TagGender, GenderToStr(gender));
|
2015-07-18 15:25:56 +02:00
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::PMSystem() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagPMSystem, ClearPMCode(p998_S));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetPMSystem(const QString &system)
|
|
|
|
{
|
|
|
|
if (not ReadOnly())
|
|
|
|
{
|
|
|
|
setTagText(TagPMSystem, ClearPMCode(system));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::Email() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagEmail, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetEmail(const QString &text)
|
|
|
|
{
|
2015-07-18 15:25:56 +02:00
|
|
|
if (not ReadOnly())
|
|
|
|
{
|
|
|
|
setTagText(TagEmail, text);
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurements::ReadOnly() const
|
|
|
|
{
|
|
|
|
if (UniqueTagText(TagReadOnly, "false") == "true")
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetReadOnly(bool ro)
|
|
|
|
{
|
|
|
|
if (ro)
|
|
|
|
{
|
|
|
|
setTagText(TagReadOnly, "true");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setTagText(TagReadOnly, "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMName(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrName, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMValue(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrValue, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
void VMeasurements::SetMBaseValue(const QString &name, double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
2015-07-25 07:41:04 +02:00
|
|
|
SetAttribute(node, AttrBase, value);
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
void VMeasurements::SetMSizeIncrease(const QString &name, double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrSizeIncrease, value);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
void VMeasurements::SetMHeightIncrease(const QString &name, double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrHeightIncrease, value);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMDescription(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrDescription, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
2015-07-25 10:54:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMFullName(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrFullName, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-25 10:54:39 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
QString VMeasurements::GenderToStr(const GenderType &sex)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
|
|
|
switch (sex)
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
case GenderType::Male:
|
|
|
|
return GenderMale;
|
|
|
|
case GenderType::Female:
|
|
|
|
return GenderFemale;
|
|
|
|
case GenderType::Unknown:
|
2015-07-16 11:38:54 +02:00
|
|
|
default:
|
2015-10-13 10:13:43 +02:00
|
|
|
return GenderUnknown;
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
GenderType VMeasurements::StrToGender(const QString &sex)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
const QStringList genders = QStringList() << GenderMale << GenderFemale << GenderUnknown;
|
2015-07-16 11:38:54 +02:00
|
|
|
switch (genders.indexOf(sex))
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
case 0: // GenderMale
|
|
|
|
return GenderType::Male;
|
|
|
|
case 1: // GenderFemale
|
|
|
|
return GenderType::Female;
|
|
|
|
case 2: // GenderUnknown
|
2015-07-16 11:38:54 +02:00
|
|
|
default:
|
2015-10-13 10:13:43 +02:00
|
|
|
return GenderType::Unknown;
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:01:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VMeasurements::ListAll() const
|
|
|
|
{
|
|
|
|
QStringList listNames;
|
|
|
|
const QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
listNames.append(domElement.attribute(AttrName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return listNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VMeasurements::ListKnown() const
|
|
|
|
{
|
|
|
|
QStringList listNames;
|
|
|
|
const QStringList list = ListAll();
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
if (list.at(i).indexOf(CustomMSign) != 0)
|
2015-07-26 09:01:26 +02:00
|
|
|
{
|
|
|
|
listNames.append(list.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return listNames;
|
|
|
|
}
|
|
|
|
|
2015-09-22 16:41:05 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurements::IsDefinedKnownNamesValid() const
|
|
|
|
{
|
|
|
|
QStringList names = AllGroupNames();
|
2015-10-27 07:11:41 +01:00
|
|
|
|
2015-09-22 16:41:05 +02:00
|
|
|
QSet<QString> set;
|
|
|
|
foreach (const QString &var, names)
|
|
|
|
{
|
|
|
|
set.insert(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
names = ListKnown();
|
|
|
|
foreach (const QString &var, names)
|
|
|
|
{
|
|
|
|
if (not set.contains(var))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-18 09:24:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetDataSize()
|
|
|
|
{
|
|
|
|
data->SetSize(UnitConvertor(BaseSize(), MUnit(), *data->GetPatternUnit()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetDataHeight()
|
|
|
|
{
|
|
|
|
data->SetHeight(UnitConvertor(BaseHeight(), MUnit(), *data->GetPatternUnit()));
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::CreateEmptyStandardFile(Unit unit, int baseSize, int baseHeight)
|
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
QDomElement mElement = this->createElement(TagVST);
|
|
|
|
|
|
|
|
mElement.appendChild(createComment("Measurements created with Valentina (http://www.valentina-project.org/)."));
|
|
|
|
|
|
|
|
QDomElement version = createElement(TagVersion);
|
|
|
|
const QDomText newNodeText = createTextNode(VVSTConverter::MeasurementMaxVerStr);
|
|
|
|
version.appendChild(newNodeText);
|
|
|
|
mElement.appendChild(version);
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
QDomElement ro = createElement(TagReadOnly);
|
2015-07-18 14:39:33 +02:00
|
|
|
const QDomText roNodeText = createTextNode("false");
|
2015-07-18 13:08:44 +02:00
|
|
|
ro.appendChild(roNodeText);
|
|
|
|
mElement.appendChild(ro);
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
mElement.appendChild(createElement(TagNotes));
|
|
|
|
|
|
|
|
QDomElement mUnit = createElement(TagUnit);
|
|
|
|
const QDomText unitText = createTextNode(UnitsToStr(unit));
|
|
|
|
mUnit.appendChild(unitText);
|
|
|
|
mElement.appendChild(mUnit);
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
QDomElement system = createElement(TagPMSystem);
|
|
|
|
system.appendChild(createTextNode(ClearPMCode(p998_S)));
|
|
|
|
mElement.appendChild(system);
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
QDomElement size = createElement(TagSize);
|
|
|
|
SetAttribute(size, AttrBase, QString().setNum(baseSize));
|
|
|
|
mElement.appendChild(size);
|
|
|
|
|
|
|
|
QDomElement height = createElement(TagHeight);
|
|
|
|
SetAttribute(height, AttrBase, QString().setNum(baseHeight));
|
|
|
|
mElement.appendChild(height);
|
|
|
|
|
|
|
|
mElement.appendChild(createElement(TagBodyMeasurements));
|
|
|
|
|
|
|
|
this->appendChild(mElement);
|
|
|
|
insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::CreateEmptyIndividualFile(Unit unit)
|
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
QDomElement mElement = this->createElement(TagVIT);
|
|
|
|
|
|
|
|
mElement.appendChild(createComment("Measurements created with Valentina (http://www.valentina-project.org/)."));
|
|
|
|
|
|
|
|
QDomElement version = createElement(TagVersion);
|
|
|
|
const QDomText newNodeText = createTextNode(VVITConverter::MeasurementMaxVerStr);
|
|
|
|
version.appendChild(newNodeText);
|
|
|
|
mElement.appendChild(version);
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
QDomElement ro = createElement(TagReadOnly);
|
2015-07-18 14:39:33 +02:00
|
|
|
const QDomText roNodeText = createTextNode("false");
|
2015-07-18 13:08:44 +02:00
|
|
|
ro.appendChild(roNodeText);
|
|
|
|
mElement.appendChild(ro);
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
mElement.appendChild(createElement(TagNotes));
|
|
|
|
|
|
|
|
QDomElement mUnit = createElement(TagUnit);
|
|
|
|
mUnit.appendChild(createTextNode(UnitsToStr(unit)));
|
|
|
|
mElement.appendChild(mUnit);
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
QDomElement system = createElement(TagPMSystem);
|
|
|
|
system.appendChild(createTextNode(ClearPMCode(p998_S)));
|
|
|
|
mElement.appendChild(system);
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
QDomElement personal = createElement(TagPersonal);
|
2015-07-25 17:18:01 +02:00
|
|
|
personal.appendChild(createElement(TagFamilyName));
|
2015-09-07 13:51:21 +02:00
|
|
|
personal.appendChild(createElement(TagGivenName));
|
2015-10-15 07:04:23 +02:00
|
|
|
|
|
|
|
QDomElement date = createElement(TagBirthDate);
|
2015-12-19 20:26:05 +01:00
|
|
|
date.appendChild(createTextNode(defBirthDate));
|
2015-10-15 07:04:23 +02:00
|
|
|
personal.appendChild(date);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
2015-10-13 10:13:43 +02:00
|
|
|
QDomElement gender = createElement(TagGender);
|
|
|
|
gender.appendChild(createTextNode(GenderToStr(GenderType::Unknown)));
|
|
|
|
personal.appendChild(gender);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
personal.appendChild(createElement(TagEmail));
|
|
|
|
mElement.appendChild(personal);
|
|
|
|
|
|
|
|
mElement.appendChild(createElement(TagBodyMeasurements));
|
|
|
|
|
|
|
|
this->appendChild(mElement);
|
|
|
|
insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VMeasurements::UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const
|
|
|
|
{
|
|
|
|
const qreal defVal = UnitConvertor(defValue, Unit::Cm, MUnit());
|
|
|
|
|
|
|
|
const QDomNodeList nodeList = this->elementsByTagName(tag);
|
|
|
|
if (nodeList.isEmpty())
|
|
|
|
{
|
|
|
|
return defVal;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QDomNode domNode = nodeList.at(0);
|
|
|
|
if (domNode.isNull() == false && domNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
return GetParametrDouble(domElement, attr, QString("%1").arg(defVal));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defVal;
|
|
|
|
}
|
2015-07-21 19:26:33 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-01 13:25:05 +02:00
|
|
|
QDomElement VMeasurements::MakeEmpty(const QString &name, const QString &formula)
|
2015-07-21 19:26:33 +02:00
|
|
|
{
|
|
|
|
QDomElement element = createElement(TagMeasurement);
|
|
|
|
|
|
|
|
SetAttribute(element, AttrName, name);
|
|
|
|
|
|
|
|
if (type == MeasurementsType::Standard)
|
|
|
|
{
|
2015-07-22 11:44:31 +02:00
|
|
|
SetAttribute(element, AttrBase, QString("0"));
|
2015-07-21 19:26:33 +02:00
|
|
|
SetAttribute(element, AttrSizeIncrease, QString("0"));
|
|
|
|
SetAttribute(element, AttrHeightIncrease, QString("0"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-01 13:25:05 +02:00
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
SetAttribute(element, AttrValue, QString("0"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetAttribute(element, AttrValue, formula);
|
|
|
|
}
|
2015-07-21 19:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomElement VMeasurements::FindM(const QString &name) const
|
|
|
|
{
|
2015-10-03 00:49:15 +02:00
|
|
|
if (name.isEmpty())
|
|
|
|
{
|
|
|
|
qWarning() << tr("The measurement name is empty!");
|
|
|
|
return QDomElement();
|
|
|
|
}
|
|
|
|
|
2015-07-21 19:26:33 +02:00
|
|
|
QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
const QString parameter = domElement.attribute(AttrName);
|
|
|
|
if (parameter == name)
|
|
|
|
{
|
|
|
|
return domElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QDomElement();
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementsType VMeasurements::ReadType() const
|
|
|
|
{
|
|
|
|
QDomElement root = documentElement();
|
|
|
|
if (root.tagName() == TagVST)
|
|
|
|
{
|
|
|
|
return MeasurementsType::Standard;
|
|
|
|
}
|
|
|
|
else if (root.tagName() == TagVIT)
|
|
|
|
{
|
|
|
|
return MeasurementsType::Individual;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return MeasurementsType::Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VMeasurements::EvalFormula(VContainer *data, const QString &formula, bool *ok) const
|
|
|
|
{
|
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
*ok = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Replace line return character with spaces for calc if exist
|
|
|
|
QString f = formula;
|
|
|
|
f.replace("\n", " ");
|
2016-05-24 14:25:58 +02:00
|
|
|
QScopedPointer<Calculator> cal(new Calculator());
|
2015-10-15 12:07:43 +02:00
|
|
|
const qreal result = cal->EvalFormula(data->PlainVariables(), f);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
2016-05-24 14:06:35 +02:00
|
|
|
(qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true;
|
2015-07-24 12:06:39 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
2015-10-19 15:21:06 +02:00
|
|
|
Q_UNUSED(e)
|
2015-07-24 12:06:39 +02:00
|
|
|
*ok = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-16 19:26:05 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::ClearPMCode(const QString &code) const
|
|
|
|
{
|
|
|
|
QString clear = code;
|
|
|
|
const int index = clear.indexOf(QLatin1Char('p'));
|
|
|
|
if (index == 0)
|
|
|
|
{
|
|
|
|
clear.remove(0, 1);
|
|
|
|
}
|
|
|
|
return clear;
|
|
|
|
}
|