diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc
index b585907db..3644ffb8b 100644
--- a/src/libs/ifc/schema.qrc
+++ b/src/libs/ifc/schema.qrc
@@ -45,5 +45,6 @@
schema/individual_measurements/v0.3.1.xsd
schema/individual_measurements/v0.3.2.xsd
schema/individual_measurements/v0.3.3.xsd
+ schema/label_template/v1.0.0.xsd
diff --git a/src/libs/ifc/schema/label_template/v1.0.0.xsd b/src/libs/ifc/schema/label_template/v1.0.0.xsd
new file mode 100644
index 000000000..3890aade3
--- /dev/null
+++ b/src/libs/ifc/schema/label_template/v1.0.0.xsd
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/libs/ifc/xml/vlabeltemplateconverter.cpp b/src/libs/ifc/xml/vlabeltemplateconverter.cpp
new file mode 100644
index 000000000..4b7319828
--- /dev/null
+++ b/src/libs/ifc/xml/vlabeltemplateconverter.cpp
@@ -0,0 +1,109 @@
+/************************************************************************
+ **
+ ** @file
+ ** @author Roman Telezhynskyi
+ ** @date 10 8, 2017
+ **
+ ** @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) 2017 Valentina project
+ ** 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 .
+ **
+ *************************************************************************/
+
+#include "vlabeltemplateconverter.h"
+
+/*
+ * Version rules:
+ * 1. Version have three parts "major.minor.patch";
+ * 2. major part only for stable releases;
+ * 3. minor - 10 or more patch changes, or one big change;
+ * 4. patch - little change.
+ */
+
+const QString VLabelTemplateConverter::LabelTemplateMinVerStr = QStringLiteral("1.0.0");
+const QString VLabelTemplateConverter::LabelTemplateMaxVerStr = QStringLiteral("1.0.0");
+const QString VLabelTemplateConverter::CurrentSchema = QStringLiteral("://schema/label_template/v1.0.0.xsd");
+
+//VLabelTemplateConverter::LabelTemplateMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
+//VLabelTemplateConverter::LabelTemplateMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
+
+//---------------------------------------------------------------------------------------------------------------------
+VLabelTemplateConverter::VLabelTemplateConverter(const QString &fileName)
+ : VAbstractConverter(fileName)
+{
+ ValidateInputFile(CurrentSchema);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+int VLabelTemplateConverter::MinVer() const
+{
+ return LabelTemplateMinVer;
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+int VLabelTemplateConverter::MaxVer() const
+{
+ return LabelTemplateMaxVer;
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+QString VLabelTemplateConverter::MinVerStr() const
+{
+ return LabelTemplateMinVerStr;
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+QString VLabelTemplateConverter::MaxVerStr() const
+{
+ return LabelTemplateMaxVerStr;
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+QString VLabelTemplateConverter::XSDSchema(int ver) const
+{
+ switch (ver)
+ {
+ case (0x010000):
+ return CurrentSchema;
+ default:
+ InvalidVersion(ver);
+ break;
+ }
+ return QString();//unreachable code
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+void VLabelTemplateConverter::ApplyPatches()
+{
+ switch (m_ver)
+ {
+ case (0x010000):
+ break;
+ default:
+ InvalidVersion(m_ver);
+ break;
+ }
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+void VLabelTemplateConverter::DowngradeToCurrentMaxVersion()
+{
+ SetVersion(LabelTemplateMaxVerStr);
+ Save();
+}
diff --git a/src/libs/ifc/xml/vlabeltemplateconverter.h b/src/libs/ifc/xml/vlabeltemplateconverter.h
new file mode 100644
index 000000000..13669199b
--- /dev/null
+++ b/src/libs/ifc/xml/vlabeltemplateconverter.h
@@ -0,0 +1,63 @@
+/************************************************************************
+ **
+ ** @file
+ ** @author Roman Telezhynskyi
+ ** @date 10 8, 2017
+ **
+ ** @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) 2017 Valentina project
+ ** 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 .
+ **
+ *************************************************************************/
+
+#ifndef VLABELTEMPLATECONVERTER_H
+#define VLABELTEMPLATECONVERTER_H
+
+#include "vabstractconverter.h"
+
+class VLabelTemplateConverter : public VAbstractConverter
+{
+public:
+ explicit VLabelTemplateConverter(const QString &fileName);
+ virtual ~VLabelTemplateConverter() Q_DECL_EQ_DEFAULT;
+
+ static const QString LabelTemplateMaxVerStr;
+ static const QString CurrentSchema;
+ static Q_DECL_CONSTEXPR const int LabelTemplateMinVer = CONVERTER_VERSION_CHECK(1, 0, 0);
+ static Q_DECL_CONSTEXPR const int LabelTemplateMaxVer = CONVERTER_VERSION_CHECK(1, 0, 0);
+
+protected:
+ virtual int MinVer() const Q_DECL_OVERRIDE;
+ virtual int MaxVer() const Q_DECL_OVERRIDE;
+
+ virtual QString MinVerStr() const Q_DECL_OVERRIDE;
+ virtual QString MaxVerStr() const Q_DECL_OVERRIDE;
+
+ virtual QString XSDSchema(int ver) const Q_DECL_OVERRIDE;
+ virtual void ApplyPatches() Q_DECL_OVERRIDE;
+ virtual void DowngradeToCurrentMaxVersion() Q_DECL_OVERRIDE;
+
+ virtual bool IsReadOnly() const Q_DECL_OVERRIDE {return false;}
+
+private:
+ Q_DISABLE_COPY(VLabelTemplateConverter)
+ static const QString LabelTemplateMinVerStr;
+};
+
+#endif // VLABELTEMPLATECONVERTER_H
diff --git a/src/libs/ifc/xml/xml.pri b/src/libs/ifc/xml/xml.pri
index 0925a57b0..d5d333e23 100644
--- a/src/libs/ifc/xml/xml.pri
+++ b/src/libs/ifc/xml/xml.pri
@@ -9,7 +9,8 @@ HEADERS += \
$$PWD/vabstractpattern.h \
$$PWD/vvstconverter.h \
$$PWD//vvitconverter.h \
- $$PWD//vabstractmconverter.h
+ $$PWD//vabstractmconverter.h \
+ $$PWD/vlabeltemplateconverter.h
SOURCES += \
$$PWD/vabstractconverter.cpp \
@@ -19,4 +20,5 @@ SOURCES += \
$$PWD/vabstractpattern.cpp \
$$PWD/vvstconverter.cpp \
$$PWD//vvitconverter.cpp \
- $$PWD//vabstractmconverter.cpp
+ $$PWD//vabstractmconverter.cpp \
+ $$PWD/vlabeltemplateconverter.cpp
diff --git a/src/libs/vformat/vlabeltemplate.cpp b/src/libs/vformat/vlabeltemplate.cpp
index b1ba21171..942c88405 100644
--- a/src/libs/vformat/vlabeltemplate.cpp
+++ b/src/libs/vformat/vlabeltemplate.cpp
@@ -27,6 +27,7 @@
*************************************************************************/
#include "vlabeltemplate.h"
+#include "../ifc/xml/vlabeltemplateconverter.h"
const QString VLabelTemplate::TagTemplate = QStringLiteral("template");
const QString VLabelTemplate::TagLines = QStringLiteral("lines");
@@ -49,7 +50,7 @@ void VLabelTemplate::CreateEmptyTemplate()
QDomElement templateElement = this->createElement(TagTemplate);
QDomElement version = createElement(TagVersion);
- QDomText newNodeText = createTextNode("1.0"/*VLabelTemplateConverter::TemplateMaxVerStr*/);
+ QDomText newNodeText = createTextNode(VLabelTemplateConverter::LabelTemplateMaxVerStr);
version.appendChild(newNodeText);
templateElement.appendChild(version);
@@ -84,3 +85,36 @@ void VLabelTemplate::AddLines(const QVector &lines)
}
}
}
+
+//---------------------------------------------------------------------------------------------------------------------
+QVector VLabelTemplate::ReadLines() const
+{
+ QVector lines;
+
+ const QDomNodeList listLines = elementsByTagName(TagLines);
+ if (listLines.size() == 0)
+ {
+ return lines;
+ }
+
+ 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(""));
+ 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;
+}
diff --git a/src/libs/vformat/vlabeltemplate.h b/src/libs/vformat/vlabeltemplate.h
index 294b9a0ef..c79960390 100644
--- a/src/libs/vformat/vlabeltemplate.h
+++ b/src/libs/vformat/vlabeltemplate.h
@@ -62,6 +62,7 @@ public:
void CreateEmptyTemplate();
void AddLines(const QVector &lines);
+ QVector ReadLines() const;
private:
Q_DISABLE_COPY(VLabelTemplate)
};
diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp
index 885ed6e34..b581b02d1 100644
--- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp
+++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp
@@ -30,6 +30,8 @@
#include "ui_dialogeditlabel.h"
#include "../vmisc/vabstractapplication.h"
#include "../vformat/vlabeltemplate.h"
+#include "../ifc/xml/vlabeltemplateconverter.h"
+#include "../ifc/exception/vexception.h"
#include
#include
@@ -55,6 +57,7 @@ DialogEditLabel::DialogEditLabel(QWidget *parent)
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogEditLabel::ShowLineDetails);
connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate);
connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate);
+ connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &DialogEditLabel::ImportTemplate);
}
//---------------------------------------------------------------------------------------------------------------------
@@ -99,7 +102,7 @@ void DialogEditLabel::ShowLineDetails()
ui->toolButtonTextCenter->setChecked(false);
ui->toolButtonTextRight->setChecked(false);
}
- else if (lineAlignment & Qt::AlignCenter)
+ else if (lineAlignment & Qt::AlignHCenter)
{
ui->toolButtonTextLeft->setChecked(false);
ui->toolButtonTextCenter->setChecked(true);
@@ -208,7 +211,7 @@ void DialogEditLabel::SaveTextFormating(bool checked)
{
if (checked)
{
- curLine->setTextAlignment(Qt::AlignCenter);
+ curLine->setTextAlignment(Qt::AlignHCenter);
ui->toolButtonTextLeft->setChecked(false);
ui->toolButtonTextRight->setChecked(false);
@@ -317,13 +320,43 @@ void DialogEditLabel::ExportTemplate()
}
RemoveTempDir();
- return;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::ImportTemplate()
{
+ if (ui->listWidget->count() > 0)
+ {
+ const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Import template"),
+ tr("Import template will overwrite the current, do "
+ "you want to continue?"),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+ if (answer == QMessageBox::No)
+ {
+ return;
+ }
+ }
+ QString filter(tr("Label template") + QLatin1String("(*.xml)"));
+ const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"),
+ qApp->Settings()->GetPathLabelTemplate(), filter, nullptr,
+ QFileDialog::DontUseNativeDialog);
+ if (fileName.isEmpty())
+ {
+ return;
+ }
+
+ try
+ {
+ VLabelTemplate ltemplate;
+ ltemplate.setXMLContent(VLabelTemplateConverter(fileName).Convert());
+ InitLines(ltemplate.ReadLines());
+ }
+ catch (VException &e)
+ {
+ qCritical("%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), qUtf8Printable(e.ErrorMessage()),
+ qUtf8Printable(e.DetailedInformation()));
+ }
}
//---------------------------------------------------------------------------------------------------------------------
@@ -377,3 +410,32 @@ QVector DialogEditLabel::PrepareLines() const
return lines;
}
+
+//---------------------------------------------------------------------------------------------------------------------
+void DialogEditLabel::InitLines(const QVector &lines)
+{
+ ui->listWidget->blockSignals(true);
+ ui->listWidget->clear();
+
+ int row = -1;
+
+ for (int i=0; isetTextAlignment(lines.at(i).alignment);
+
+ QFont font = item->font();
+ font.setBold(lines.at(i).bold);
+ font.setItalic(lines.at(i).italic);
+ item->setFont(font);
+
+ ui->listWidget->insertItem(++row, item);
+ }
+
+ ui->listWidget->blockSignals(false);
+
+ if (ui->listWidget->count() > 0)
+ {
+ ui->listWidget->setCurrentRow(0);
+ }
+}
diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.h b/src/libs/vtools/dialogs/support/dialogeditlabel.h
index 2040fbde2..9025674c9 100644
--- a/src/libs/vtools/dialogs/support/dialogeditlabel.h
+++ b/src/libs/vtools/dialogs/support/dialogeditlabel.h
@@ -64,6 +64,7 @@ private:
void SetupControls();
QVector PrepareLines() const;
+ void InitLines(const QVector &lines);
};
#endif // DIALOGEDITLABEL_H