Added import the template.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-10 19:32:05 +03:00
parent bc96184617
commit c989cdf048
9 changed files with 316 additions and 6 deletions

View File

@ -45,5 +45,6 @@
<file>schema/individual_measurements/v0.3.1.xsd</file> <file>schema/individual_measurements/v0.3.1.xsd</file>
<file>schema/individual_measurements/v0.3.2.xsd</file> <file>schema/individual_measurements/v0.3.2.xsd</file>
<file>schema/individual_measurements/v0.3.3.xsd</file> <file>schema/individual_measurements/v0.3.3.xsd</file>
<file>schema/label_template/v1.0.0.xsd</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="template">
<xs:complexType>
<xs:sequence>
<xs:element name="version" type="formatVersion"/>
<xs:element name="lines">
<xs:complexType>
<xs:sequence>
<xs:element name="line" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="text" type="xs:string" use="required"/>
<xs:attribute name="bold" type="xs:boolean"/>
<xs:attribute name="italic" type="xs:boolean"/>
<xs:attribute name="alignment" type="alignmentType"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="formatVersion">
<xs:restriction base="xs:string">
<xs:pattern value="^(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))$"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="alignmentType">
<xs:restriction base="xs:unsignedInt">
<xs:enumeration value="0"/><!--default (no aligns)-->
<xs:enumeration value="1"/><!--aligns with the left edge-->
<xs:enumeration value="2"/><!--aligns with the right edge-->
<xs:enumeration value="4"/><!--Centers horizontally in the available space-->
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -0,0 +1,109 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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 "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();
}

View File

@ -0,0 +1,63 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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/>.
**
*************************************************************************/
#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

View File

@ -9,7 +9,8 @@ HEADERS += \
$$PWD/vabstractpattern.h \ $$PWD/vabstractpattern.h \
$$PWD/vvstconverter.h \ $$PWD/vvstconverter.h \
$$PWD//vvitconverter.h \ $$PWD//vvitconverter.h \
$$PWD//vabstractmconverter.h $$PWD//vabstractmconverter.h \
$$PWD/vlabeltemplateconverter.h
SOURCES += \ SOURCES += \
$$PWD/vabstractconverter.cpp \ $$PWD/vabstractconverter.cpp \
@ -19,4 +20,5 @@ SOURCES += \
$$PWD/vabstractpattern.cpp \ $$PWD/vabstractpattern.cpp \
$$PWD/vvstconverter.cpp \ $$PWD/vvstconverter.cpp \
$$PWD//vvitconverter.cpp \ $$PWD//vvitconverter.cpp \
$$PWD//vabstractmconverter.cpp $$PWD//vabstractmconverter.cpp \
$$PWD/vlabeltemplateconverter.cpp

View File

@ -27,6 +27,7 @@
*************************************************************************/ *************************************************************************/
#include "vlabeltemplate.h" #include "vlabeltemplate.h"
#include "../ifc/xml/vlabeltemplateconverter.h"
const QString VLabelTemplate::TagTemplate = QStringLiteral("template"); const QString VLabelTemplate::TagTemplate = QStringLiteral("template");
const QString VLabelTemplate::TagLines = QStringLiteral("lines"); const QString VLabelTemplate::TagLines = QStringLiteral("lines");
@ -49,7 +50,7 @@ void VLabelTemplate::CreateEmptyTemplate()
QDomElement templateElement = this->createElement(TagTemplate); QDomElement templateElement = this->createElement(TagTemplate);
QDomElement version = createElement(TagVersion); QDomElement version = createElement(TagVersion);
QDomText newNodeText = createTextNode("1.0"/*VLabelTemplateConverter::TemplateMaxVerStr*/); QDomText newNodeText = createTextNode(VLabelTemplateConverter::LabelTemplateMaxVerStr);
version.appendChild(newNodeText); version.appendChild(newNodeText);
templateElement.appendChild(version); templateElement.appendChild(version);
@ -84,3 +85,36 @@ void VLabelTemplate::AddLines(const QVector<VLabelTemplateLine> &lines)
} }
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<VLabelTemplateLine> VLabelTemplate::ReadLines() const
{
QVector<VLabelTemplateLine> 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("<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;
}

View File

@ -62,6 +62,7 @@ public:
void CreateEmptyTemplate(); void CreateEmptyTemplate();
void AddLines(const QVector<VLabelTemplateLine> &lines); void AddLines(const QVector<VLabelTemplateLine> &lines);
QVector<VLabelTemplateLine> ReadLines() const;
private: private:
Q_DISABLE_COPY(VLabelTemplate) Q_DISABLE_COPY(VLabelTemplate)
}; };

View File

@ -30,6 +30,8 @@
#include "ui_dialogeditlabel.h" #include "ui_dialogeditlabel.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vformat/vlabeltemplate.h" #include "../vformat/vlabeltemplate.h"
#include "../ifc/xml/vlabeltemplateconverter.h"
#include "../ifc/exception/vexception.h"
#include <QDir> #include <QDir>
#include <QMessageBox> #include <QMessageBox>
@ -55,6 +57,7 @@ DialogEditLabel::DialogEditLabel(QWidget *parent)
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogEditLabel::ShowLineDetails); connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogEditLabel::ShowLineDetails);
connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate); connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate);
connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate); 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->toolButtonTextCenter->setChecked(false);
ui->toolButtonTextRight->setChecked(false); ui->toolButtonTextRight->setChecked(false);
} }
else if (lineAlignment & Qt::AlignCenter) else if (lineAlignment & Qt::AlignHCenter)
{ {
ui->toolButtonTextLeft->setChecked(false); ui->toolButtonTextLeft->setChecked(false);
ui->toolButtonTextCenter->setChecked(true); ui->toolButtonTextCenter->setChecked(true);
@ -208,7 +211,7 @@ void DialogEditLabel::SaveTextFormating(bool checked)
{ {
if (checked) if (checked)
{ {
curLine->setTextAlignment(Qt::AlignCenter); curLine->setTextAlignment(Qt::AlignHCenter);
ui->toolButtonTextLeft->setChecked(false); ui->toolButtonTextLeft->setChecked(false);
ui->toolButtonTextRight->setChecked(false); ui->toolButtonTextRight->setChecked(false);
@ -317,13 +320,43 @@ void DialogEditLabel::ExportTemplate()
} }
RemoveTempDir(); RemoveTempDir();
return;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::ImportTemplate() 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<VLabelTemplateLine> DialogEditLabel::PrepareLines() const
return lines; return lines;
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::InitLines(const QVector<VLabelTemplateLine> &lines)
{
ui->listWidget->blockSignals(true);
ui->listWidget->clear();
int row = -1;
for (int i=0; i<lines.size(); ++i)
{
QListWidgetItem *item = new QListWidgetItem(lines.at(i).line);
item->setTextAlignment(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);
}
}

View File

@ -64,6 +64,7 @@ private:
void SetupControls(); void SetupControls();
QVector<VLabelTemplateLine> PrepareLines() const; QVector<VLabelTemplateLine> PrepareLines() const;
void InitLines(const QVector<VLabelTemplateLine> &lines);
}; };
#endif // DIALOGEDITLABEL_H #endif // DIALOGEDITLABEL_H