57 #include <QDomNodeList>
59 #include <QLatin1Char>
60 #include <QMessageLogger>
61 #include <QScopedPointer>
63 #include <QStaticStringData>
64 #include <QStringData>
65 #include <QStringDataPtr>
68 #include "../ifc/exception/vexceptionemptyparameter.h"
69 #include "../ifc/xml/vvitconverter.h"
70 #include "../ifc/xml/vvstconverter.h"
71 #include "../ifc/ifcdef.h"
72 #include "../qmuparser/qmutokenparser.h"
73 #include "../qmuparser/qmuparsererror.h"
74 #include "../vpatterndb/calculator.h"
75 #include "../vpatterndb/variables/vmeasurement.h"
76 #include "../vpatterndb/vcontainer.h"
77 #include "../vpatterndb/measurements.h"
78 #include "../vpatterndb/pmsystems.h"
79 #include "../vmisc/projectversion.h"
116 return QString(
"Measurements created with Seamly2D v%1 (http://seamly.net/).").arg(
APP_VERSION_STR);
125 m_currentSize(nullptr),
126 m_currentHeight(nullptr)
136 m_currentSize(nullptr),
137 m_currentHeight(nullptr)
149 m_currentSize(nullptr),
150 m_currentHeight(nullptr)
168 QDomNode commentNode = documentElement().firstChild();
169 if (commentNode.isComment())
171 QDomComment comment = commentNode.toComment();
181 const QDomElement element =
MakeEmpty(name, formula);
184 list.at(0).appendChild(element);
190 const QDomElement element =
MakeEmpty(name, formula);
191 const QDomElement sibling =
FindM(after);
195 if (sibling.isNull())
197 list.at(0).appendChild(element);
201 list.at(0).insertAfter(element, sibling);
209 list.at(0).removeChild(
FindM(name));
215 const QDomElement node =
FindM(name);
216 if (not node.isNull())
219 if (mList.size() >= 2)
221 const QDomNode top = mList.at(0);
222 if (not top.isNull())
225 list.at(0).insertBefore(node, top);
234 const QDomElement node =
FindM(name);
235 if (not node.isNull())
237 const QDomElement prSibling = node.previousSiblingElement(
TagMeasurement);
238 if (not prSibling.isNull())
241 list.at(0).insertBefore(node, prSibling);
249 const QDomElement node =
FindM(name);
250 if (not node.isNull())
252 const QDomElement nextSibling = node.nextSiblingElement(
TagMeasurement);
253 if (not nextSibling.isNull())
256 list.at(0).insertAfter(node, nextSibling);
264 const QDomElement node =
FindM(name);
265 if (not node.isNull())
268 if (mList.size() >= 2)
270 const QDomNode bottom = mList.at(mList.size()-1);
271 if (not bottom.isNull())
274 list.at(0).insertAfter(node, bottom);
290 for (
int i=0; i < list.size(); ++i)
292 const QDomElement dom = list.at(i).toElement();
338 base, ksize, kheight, fullName, description));
347 qreal value =
EvalFormula(tempData.data(), formula, &ok);
350 value, formula, ok));
354 ok, fullName, description));
356 tempData->AddVariable(name, tempMeash);
366 for (
int i=0; i < list.size(); ++i)
368 QDomElement domElement = list.at(i).toElement();
369 if (domElement.isNull() ==
false)
550 QDomElement node =
FindM(name);
551 if (not node.isNull())
557 qWarning() << tr(
"Can't find measurement '%1'").arg(name);
564 QDomElement node =
FindM(name);
565 if (not node.isNull())
571 qWarning() << tr(
"Can't find measurement '%1'").arg(name);
578 QDomElement node =
FindM(name);
579 if (not node.isNull())
585 qWarning() << tr(
"Can't find measurement '%1'").arg(name);
592 QDomElement node =
FindM(name);
593 if (not node.isNull())
599 qWarning() << tr(
"Can't find measurement '%1'").arg(name);
606 QDomElement node =
FindM(name);
607 if (not node.isNull())
613 qWarning() << tr(
"Can't find measurement '%1'").arg(name);
620 QDomElement node =
FindM(name);
621 if (not node.isNull())
627 qWarning() << tr(
"Can't find measurement '%1'").arg(name);
634 QDomElement node =
FindM(name);
635 if (not node.isNull())
641 qWarning() << tr(
"Can't find measurement '%1'").arg(name);
664 switch (genders.indexOf(sex))
679 QStringList listNames;
682 for (
int i=0; i < list.size(); ++i)
684 const QDomElement domElement = list.at(i).toElement();
685 if (domElement.isNull() ==
false)
687 listNames.append(domElement.attribute(
AttrName));
697 QStringList listNames;
698 const QStringList list =
ListAll();
699 for (
int i=0; i < list.size(); ++i)
703 listNames.append(list.at(i));
716 foreach (
const QString &var, names)
722 foreach (
const QString &var, names)
724 if (not set.contains(var))
743 QDomElement mElement = this->createElement(
TagVST);
745 mElement.appendChild(createComment(
FileComment()));
747 QDomElement version = createElement(
TagVersion);
749 version.appendChild(newNodeText);
750 mElement.appendChild(version);
753 const QDomText roNodeText = createTextNode(
"false");
754 ro.appendChild(roNodeText);
755 mElement.appendChild(ro);
757 mElement.appendChild(createElement(
TagNotes));
759 QDomElement mUnit = createElement(
TagUnit);
760 const QDomText unitText = createTextNode(
UnitsToStr(unit));
761 mUnit.appendChild(unitText);
762 mElement.appendChild(mUnit);
766 mElement.appendChild(system);
768 QDomElement size = createElement(
TagSize);
770 mElement.appendChild(size);
772 QDomElement height = createElement(
TagHeight);
774 mElement.appendChild(height);
778 this->appendChild(mElement);
779 insertBefore(createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
786 QDomElement mElement = this->createElement(
TagVIT);
788 mElement.appendChild(createComment(
FileComment()));
790 QDomElement version = createElement(
TagVersion);
792 version.appendChild(newNodeText);
793 mElement.appendChild(version);
796 const QDomText roNodeText = createTextNode(
"false");
797 ro.appendChild(roNodeText);
798 mElement.appendChild(ro);
800 mElement.appendChild(createElement(
TagNotes));
802 QDomElement mUnit = createElement(
TagUnit);
803 mUnit.appendChild(createTextNode(
UnitsToStr(unit)));
804 mElement.appendChild(mUnit);
808 mElement.appendChild(system);
816 personal.appendChild(date);
818 QDomElement gender = createElement(
TagGender);
820 personal.appendChild(gender);
822 personal.appendChild(createElement(
TagEmail));
823 mElement.appendChild(personal);
827 this->appendChild(mElement);
828 insertBefore(createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
836 const QDomNodeList nodeList = this->elementsByTagName(tag);
837 if (nodeList.isEmpty())
843 const QDomNode domNode = nodeList.at(0);
844 if (domNode.isNull() ==
false && domNode.isElement())
846 const QDomElement domElement = domNode.toElement();
847 if (domElement.isNull() ==
false)
871 if (formula.isEmpty())
889 qWarning() << tr(
"The measurement name is empty!");
890 return QDomElement();
895 for (
int i=0; i < list.size(); ++i)
897 const QDomElement domElement = list.at(i).toElement();
898 if (domElement.isNull() ==
false)
900 const QString parameter = domElement.attribute(
AttrName);
901 if (parameter == name)
908 return QDomElement();
914 QDomElement root = documentElement();
915 if (root.tagName() ==
TagVST)
919 else if (root.tagName() ==
TagVIT)
932 if (formula.isEmpty())
943 f.replace(
"\n",
" ");
944 QScopedPointer<Calculator> cal(
new Calculator());
947 (qIsInf(result) || qIsNaN(result)) ? *ok =
false : *ok =
true;
962 QString clear = code;
963 const int index = clear.indexOf(QLatin1Char(
'p'));
The Calculator class for calculation formula.
The VContainer class container of all variables.
void AddVariable(const QString &name, T *var)
const VTranslateVars * GetTrVars() const
const QHash< QString, QSharedPointer< VInternalVariable > > * DataVariables() const
const Unit * GetPatternUnit() const
The VDomDocument class represents a Seamly2D document (.val file).
static QString GetParametrString(const QDomElement &domElement, const QString &name, const QString &defValue=QString())
Returns the string value of the given attribute. RENAME: see above.
bool setTagText(const QString &tag, const QString &text)
static qreal GetParametrDouble(const QDomElement &domElement, const QString &name, const QString &defValue)
Returns the double value of the given attribute.
static const QString TagVersion
static const QString TagUnit
QString UniqueTagText(const QString &tagName, const QString &defVal=QString()) const
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
virtual void setXMLContent(const QString &fileName)
virtual bool SaveDocument(const QString &fileName, QString &error)
The VExceptionEmptyParameter class for exception empty parameter.
The VMeasurement class keep data row of multisize table.
void MoveUp(const QString &name)
MeasurementsType ReadType() const
void MoveTop(const QString &name)
static const QString TagSize
void SetMDescription(const QString &name, const QString &text)
void MoveDown(const QString &name)
static const QString AttrValue
static const QString TagNotes
qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const
static const QString AttrSizeIncrease
static const QString TagPMSystem
void addEmpty(const QString &name, const QString &formula=QString())
static GenderType StrToGender(const QString &sex)
static const QString TagGender
VMeasurements(VContainer *data)
void SetGender(const GenderType &gender)
void SetNotes(const QString &text)
static const QString AttrFullName
void SetMBaseValue(const QString &name, double value)
static const QString GenderFemale
void SetEmail(const QString &text)
QStringList ListAll() const
QStringList listKnown() const
static const QString TagBirthDate
static QString GenderToStr(const GenderType &sex)
static const QString AttrBase
static const QString AttrName
QString ClearPMCode(const QString &code) const
void CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHeight)
void SetFamilyName(const QString &text)
static const QString TagHeight
void ReadMeasurements() const
static const QString TagReadOnly
static const QString TagFamilyName
qreal UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const
static const QString TagPersonal
void SetSize(qreal *size)
void SetPMSystem(const QString &system)
QDomElement MakeEmpty(const QString &name, const QString &formula)
void Remove(const QString &name)
VContainer * GetData() const
static const QString AttrDescription
void SetReadOnly(bool ro)
void SetMFullName(const QString &name, const QString &text)
QDomElement FindM(const QString &name) const
static const QString TagBodyMeasurements
void SetHeight(qreal *height)
void SetMValue(const QString &name, const QString &text)
MeasurementsType Type() const
void SetMSizeIncrease(const QString &name, double value)
void MoveBottom(const QString &name)
static const QString TagVIT
static const QString TagMeasurement
void CreateEmptyIndividualFile(Unit unit)
static const QString TagGivenName
VContainer * data
data container with data.
void AddEmptyAfter(const QString &after, const QString &name, const QString &formula=QString())
static const QString GenderMale
static const QString TagVST
void SetGivenName(const QString &text)
void SetMHeightIncrease(const QString &name, double value)
QString FamilyName() const
virtual void setXMLContent(const QString &fileName) Q_DECL_OVERRIDE
static const QString GenderUnknown
GenderType Gender() const
static const QString TagEmail
virtual bool SaveDocument(const QString &fileName, QString &error) Q_DECL_OVERRIDE
static const QString AttrHeightIncrease
QString GivenName() const
bool IsDefinedKnownNamesValid() const
void SetMName(const QString &name, const QString &text)
void SetBirthDate(const QDate &date)
static const QString MeasurementMaxVerStr
static const QString MeasurementMaxVerStr
Error class of the parser.
static bool IsSingle(const QString &formula)
IsSingle test formula and return true if it contain only one number.
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
const QString CustomMSign
QStringList AllGroupNames()
const QString APP_VERSION_STR
const QString defBirthDate