Read/Write pattern label.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-15 10:44:00 +03:00
parent b9bd1b60e4
commit 8466e84eef
8 changed files with 113 additions and 78 deletions

View File

@ -602,9 +602,9 @@ void DialogPatternProperties::SaveTemplateData()
{
if (templateDataChanged)
{
//doc->SetTemplate(templateLines);
doc->SetPatternLabelTemplate(templateLines);
templateDataChanged = false;
//emit doc->patternChanged(false);
emit doc->patternChanged(false);
}
}
@ -884,14 +884,7 @@ void DialogPatternProperties::EditLabel()
DialogEditLabel editor(doc);
// if (templateDataChanged)
// {
// editor.SetTemplate(templateLines);
// }
// else
// {
// editor.SetTemplate(doc->GetTemplate());
// }
templateDataChanged ? editor.SetTemplate(templateLines) : editor.SetTemplate(doc->GetPatternLabelTemplate());
if (QDialog::Accepted == editor.exec())
{

View File

@ -213,4 +213,17 @@ extern const QString currentSeamAllowance;
extern const QStringList builInVariables;
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")
struct VLabelTemplateLine
{
QString line;
bool bold;
bool italic;
int alignment;
};
QT_WARNING_POP
#endif // IFCDEF_H

View File

@ -87,6 +87,7 @@ const QString VAbstractPattern::TagPatternName = QStringLiteral("patternNam
const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber");
const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer");
const QString VAbstractPattern::TagCompanyName = QStringLiteral("company");
const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel");
const QString VAbstractPattern::TagSize = QStringLiteral("size");
const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate");
const QString VAbstractPattern::TagShowMeasurements = QStringLiteral("showMeasurements");
@ -1374,6 +1375,25 @@ void VAbstractPattern::SetMesurementsVisible(bool bVisible)
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetPatternLabelTemplate(const QVector<VLabelTemplateLine> &lines)
{
QDomElement tag = CheckTagExists(TagPatternLabel);
RemoveAllChildren(tag);
SetLabelTemplate(tag, lines);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VLabelTemplateLine> VAbstractPattern::GetPatternLabelTemplate() const
{
const QDomNodeList list = elementsByTagName(TagPatternLabel);
if (list.isEmpty())
{
return QVector<VLabelTemplateLine>();
}
return GetLabelTemplate(list.at(0).toElement());
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetImage() const
{
@ -1516,7 +1536,8 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
{
const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes
<< TagGradation << TagPatternName << TagPatternNum << TagCompanyName
<< TagCustomerName << TagSize << TagShowDate << TagShowMeasurements;
<< TagCustomerName << TagPatternLabel << TagSize << TagShowDate
<< TagShowMeasurements;
switch (tags.indexOf(tag))
{
case 1: //TagImage
@ -1556,13 +1577,16 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
case 9: // TagCustomerName
element = createElement(TagCustomerName);
break;
case 10: // TagSize
case 10: // TagPatternLabel
element = createElement(TagPatternLabel);
break;
case 11: // TagSize
element = createElement(TagSize);
break;
case 11: // TagShowDate
case 12: // TagShowDate
element = createElement(TagShowDate);
break;
case 12: // TagShowMeasurements
case 13: // TagShowMeasurements
element = createElement(TagShowMeasurements);
break;
case 0: //TagUnit (Mandatory tag)

View File

@ -154,6 +154,9 @@ public:
bool IsMeasurementsVisible() const;
void SetMesurementsVisible(bool bVisible);
void SetPatternLabelTemplate(const QVector<VLabelTemplateLine> &lines);
QVector<VLabelTemplateLine> GetPatternLabelTemplate() const;
QString GetImage() const;
QString GetImageExtension() const;
void SetImage(const QString &text, const QString &extension);
@ -209,6 +212,7 @@ public:
static const QString TagPatternNum;
static const QString TagCompanyName;
static const QString TagCustomerName;
static const QString TagPatternLabel;
static const QString TagSize;
static const QString TagShowDate;
static const QString TagShowMeasurements;

View File

@ -179,8 +179,14 @@ void MessageHandler::handleMessage(QtMsgType type, const QString &description, c
Q_LOGGING_CATEGORY(vXML, "v.xml")
const QString VDomDocument::AttrId = QStringLiteral("id");
const QString VDomDocument::AttrText = QStringLiteral("text");
const QString VDomDocument::AttrBold = QStringLiteral("bold");
const QString VDomDocument::AttrItalic = QStringLiteral("italic");
const QString VDomDocument::AttrAlignment = QStringLiteral("alignment");
const QString VDomDocument::TagVersion = QStringLiteral("version");
const QString VDomDocument::TagUnit = QStringLiteral("unit");
const QString VDomDocument::TagLine = QStringLiteral("line");
//---------------------------------------------------------------------------------------------------------------------
VDomDocument::VDomDocument()
@ -899,3 +905,48 @@ bool VDomDocument::SafeCopy(const QString &source, const QString &destination, Q
return result;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VLabelTemplateLine> VDomDocument::GetLabelTemplate(const QDomElement &element) const
{
QVector<VLabelTemplateLine> lines;
if (not element.isNull())
{
QDomElement tagLine = element.firstChildElement();
while (tagLine.isNull() == false)
{
if (tagLine.tagName() == TagLine)
{
VLabelTemplateLine line;
line.line = GetParametrString(tagLine, AttrText, tr("<empty>"));
line.bold = GetParametrBool(tagLine, AttrBold, falseStr);
line.italic = GetParametrBool(tagLine, AttrItalic, falseStr);
line.alignment = GetParametrUInt(tagLine, AttrAlignment, "0");
lines.append(line);
}
tagLine = tagLine.nextSiblingElement(TagLine);
}
}
return lines;
}
//---------------------------------------------------------------------------------------------------------------------
void VDomDocument::SetLabelTemplate(QDomElement &element, const QVector<VLabelTemplateLine> &lines)
{
if (not element.isNull())
{
for (int i=0; i < lines.size(); ++i)
{
QDomElement tagLine = createElement(TagLine);
SetAttribute(tagLine, AttrText, lines.at(i).line);
SetAttribute(tagLine, AttrBold, lines.at(i).bold);
SetAttribute(tagLine, AttrItalic, lines.at(i).italic);
SetAttribute(tagLine, AttrAlignment, lines.at(i).alignment);
element.appendChild(tagLine);
}
}
}

View File

@ -83,8 +83,14 @@ class VDomDocument : public QDomDocument
Q_DECLARE_TR_FUNCTIONS(VDomDocument)
public:
static const QString AttrId;
static const QString AttrText;
static const QString AttrBold;
static const QString AttrItalic;
static const QString AttrAlignment;
static const QString TagVersion;
static const QString TagUnit;
static const QString TagLine;
VDomDocument();
virtual ~VDomDocument() Q_DECL_EQ_DEFAULT;
@ -130,6 +136,9 @@ protected:
void TestUniqueId() const;
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
QVector<VLabelTemplateLine> GetLabelTemplate(const QDomElement &element) const;
void SetLabelTemplate(QDomElement &element, const QVector<VLabelTemplateLine> &lines);
private:
Q_DISABLE_COPY(VDomDocument)
/** @brief Map used for finding element by id. */

View File

@ -31,12 +31,6 @@
const QString VLabelTemplate::TagTemplate = QStringLiteral("template");
const QString VLabelTemplate::TagLines = QStringLiteral("lines");
const QString VLabelTemplate::TagLine = QStringLiteral("line");
const QString VLabelTemplate::AttrText = QStringLiteral("text");
const QString VLabelTemplate::AttrBold = QStringLiteral("bold");
const QString VLabelTemplate::AttrItalic = QStringLiteral("italic");
const QString VLabelTemplate::AttrAlignment = QStringLiteral("alignment");
//---------------------------------------------------------------------------------------------------------------------
VLabelTemplate::VLabelTemplate()
@ -69,52 +63,18 @@ void VLabelTemplate::AddLines(const QVector<VLabelTemplateLine> &lines)
return;
}
QDomElement tagLines = listLines.at(0).toElement();
if (not tagLines.isNull())
{
for (int i=0; i < lines.size(); ++i)
{
QDomElement tagLine = createElement(TagLine);
SetAttribute(tagLine, AttrText, lines.at(i).line);
SetAttribute(tagLine, AttrBold, lines.at(i).bold);
SetAttribute(tagLine, AttrItalic, lines.at(i).italic);
SetAttribute(tagLine, AttrAlignment, lines.at(i).alignment);
tagLines.appendChild(tagLine);
}
}
QDomElement tag = listLines.at(0).toElement();
VDomDocument::SetLabelTemplate(tag, lines);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VLabelTemplateLine> VLabelTemplate::ReadLines() const
{
QVector<VLabelTemplateLine> lines;
const QDomNodeList listLines = elementsByTagName(TagLines);
if (listLines.size() == 0)
{
return lines;
return QVector<VLabelTemplateLine>();
}
QDomElement tagLines = listLines.at(0).toElement();
if (not tagLines.isNull())
{
QDomElement tagLine = tagLines.firstChildElement();
while (tagLine.isNull() == false)
{
if (tagLine.tagName() == TagLine)
{
VLabelTemplateLine line;
line.line = GetParametrString(tagLine, AttrText, tr("<empty>"));
line.bold = GetParametrBool(tagLine, AttrBold, falseStr);
line.italic = GetParametrBool(tagLine, AttrItalic, falseStr);
line.alignment = GetParametrUInt(tagLine, AttrAlignment, "0");
lines.append(line);
}
tagLine = tagLine.nextSiblingElement(TagLine);
}
}
return lines;
return VDomDocument::GetLabelTemplate(listLines.at(0).toElement());
}

View File

@ -31,19 +31,6 @@
#include "../ifc/xml/vdomdocument.h"
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")
struct VLabelTemplateLine
{
QString line;
bool bold;
bool italic;
int alignment;
};
QT_WARNING_POP
class VLabelTemplate : public VDomDocument
{
public:
@ -52,12 +39,6 @@ public:
static const QString TagTemplate;
static const QString TagLines;
static const QString TagLine;
static const QString AttrText;
static const QString AttrBold;
static const QString AttrItalic;
static const QString AttrAlignment;
void CreateEmptyTemplate();