From b4c0651de4b6e681de5a7b856f18d85a158cd603 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 10 Aug 2017 17:14:39 +0300 Subject: [PATCH] Added export the template. --HG-- branch : feature --- src/libs/vformat/vformat.pri | 6 +- src/libs/vformat/vlabeltemplate.cpp | 86 +++++++++++++++++++ src/libs/vformat/vlabeltemplate.h | 69 +++++++++++++++ .../dialogs/support/dialogeditlabel.cpp | 54 +++++++++--- .../vtools/dialogs/support/dialogeditlabel.h | 4 + 5 files changed, 205 insertions(+), 14 deletions(-) create mode 100644 src/libs/vformat/vlabeltemplate.cpp create mode 100644 src/libs/vformat/vlabeltemplate.h diff --git a/src/libs/vformat/vformat.pri b/src/libs/vformat/vformat.pri index 5afe5834a..2d8f8f3ad 100644 --- a/src/libs/vformat/vformat.pri +++ b/src/libs/vformat/vformat.pri @@ -2,10 +2,12 @@ # This need for corect working file translations.pro SOURCES += \ - $$PWD/vmeasurements.cpp + $$PWD/vmeasurements.cpp \ + $$PWD/vlabeltemplate.cpp *msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ $$PWD/vmeasurements.h \ - $$PWD/stable.h + $$PWD/stable.h \ + $$PWD/vlabeltemplate.h diff --git a/src/libs/vformat/vlabeltemplate.cpp b/src/libs/vformat/vlabeltemplate.cpp new file mode 100644 index 000000000..b1ba21171 --- /dev/null +++ b/src/libs/vformat/vlabeltemplate.cpp @@ -0,0 +1,86 @@ +/************************************************************************ + ** + ** @file vlabeltemplate.cpp + ** @author Roman Telezhynskyi + ** @date 10 8, 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 + ** 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 "vlabeltemplate.h" + +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() + : VDomDocument() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VLabelTemplate::CreateEmptyTemplate() +{ + clear(); + QDomElement templateElement = this->createElement(TagTemplate); + + QDomElement version = createElement(TagVersion); + QDomText newNodeText = createTextNode("1.0"/*VLabelTemplateConverter::TemplateMaxVerStr*/); + version.appendChild(newNodeText); + templateElement.appendChild(version); + + templateElement.appendChild(createElement(TagLines)); + + this->appendChild(templateElement); + insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLabelTemplate::AddLines(const QVector &lines) +{ + const QDomNodeList listLines = elementsByTagName(TagLines); + if (listLines.size() == 0) + { + 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); + } + } +} diff --git a/src/libs/vformat/vlabeltemplate.h b/src/libs/vformat/vlabeltemplate.h new file mode 100644 index 000000000..294b9a0ef --- /dev/null +++ b/src/libs/vformat/vlabeltemplate.h @@ -0,0 +1,69 @@ +/************************************************************************ + ** + ** @file vlabeltemplate.h + ** @author Roman Telezhynskyi + ** @date 10 8, 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 + ** 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 VLABELTEMPLATE_H +#define VLABELTEMPLATE_H + +#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: + VLabelTemplate(); + virtual ~VLabelTemplate() Q_DECL_EQ_DEFAULT; + + 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(); + + void AddLines(const QVector &lines); +private: + Q_DISABLE_COPY(VLabelTemplate) +}; + +#endif // VLABELTEMPLATE_H diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 74b60697f..885ed6e34 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -29,6 +29,7 @@ #include "dialogeditlabel.h" #include "ui_dialogeditlabel.h" #include "../vmisc/vabstractapplication.h" +#include "../vformat/vlabeltemplate.h" #include #include @@ -298,18 +299,22 @@ void DialogEditLabel::ExportTemplate() fileName += QLatin1String(".xml"); } -// QString error; -// const bool result = doc->SaveDocument(fileName, error); -// if (result == false) -// { -// QMessageBox messageBox(this); -// messageBox.setIcon(QMessageBox::Warning); -// messageBox.setInformativeText(tr("Could not save file")); -// messageBox.setDefaultButton(QMessageBox::Ok); -// messageBox.setDetailedText(error); -// messageBox.setStandardButtons(QMessageBox::Ok); -// messageBox.exec(); -// } + VLabelTemplate ltemplate; + ltemplate.CreateEmptyTemplate(); + ltemplate.AddLines(PrepareLines()); + + QString error; + const bool result = ltemplate.SaveDocument(fileName, error); + if (result == false) + { + QMessageBox messageBox(this); + messageBox.setIcon(QMessageBox::Warning); + messageBox.setInformativeText(tr("Could not save file")); + messageBox.setDefaultButton(QMessageBox::Ok); + messageBox.setDetailedText(error); + messageBox.setStandardButtons(QMessageBox::Ok); + messageBox.exec(); + } RemoveTempDir(); return; @@ -347,3 +352,28 @@ void DialogEditLabel::SetupControls() ui->toolButtonExportLabel->setEnabled(enabled); ui->lineEditLine->setEnabled(enabled); } + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogEditLabel::PrepareLines() const +{ + QVector lines; + + for (int i=0; ilistWidget->count(); ++i) + { + const QListWidgetItem *lineItem = ui->listWidget->item(i); + if (lineItem) + { + VLabelTemplateLine line; + line.line = lineItem->text(); + line.alignment = lineItem->textAlignment(); + + const QFont font = lineItem->font(); + line.bold = font.bold(); + line.italic = font.italic(); + + lines.append(line); + } + } + + return lines; +} diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.h b/src/libs/vtools/dialogs/support/dialogeditlabel.h index 1c29af271..2040fbde2 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.h +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.h @@ -36,6 +36,8 @@ namespace Ui class DialogEditLabel; } +class VLabelTemplateLine; + class DialogEditLabel : public QDialog { Q_OBJECT @@ -60,6 +62,8 @@ private: Ui::DialogEditLabel *ui; void SetupControls(); + + QVector PrepareLines() const; }; #endif // DIALOGEDITLABEL_H