Added export the template.
--HG-- branch : feature
This commit is contained in:
parent
209a281cdc
commit
b4c0651de4
|
@ -2,10 +2,12 @@
|
||||||
# This need for corect working file translations.pro
|
# This need for corect working file translations.pro
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/vmeasurements.cpp
|
$$PWD/vmeasurements.cpp \
|
||||||
|
$$PWD/vlabeltemplate.cpp
|
||||||
|
|
||||||
*msvc*:SOURCES += $$PWD/stable.cpp
|
*msvc*:SOURCES += $$PWD/stable.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/vmeasurements.h \
|
$$PWD/vmeasurements.h \
|
||||||
$$PWD/stable.h
|
$$PWD/stable.h \
|
||||||
|
$$PWD/vlabeltemplate.h
|
||||||
|
|
86
src/libs/vformat/vlabeltemplate.cpp
Normal file
86
src/libs/vformat/vlabeltemplate.cpp
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vlabeltemplate.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @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
|
||||||
|
** <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 "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<VLabelTemplateLine> &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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
69
src/libs/vformat/vlabeltemplate.h
Normal file
69
src/libs/vformat/vlabeltemplate.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vlabeltemplate.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @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
|
||||||
|
** <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 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<VLabelTemplateLine> &lines);
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(VLabelTemplate)
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VLABELTEMPLATE_H
|
|
@ -29,6 +29,7 @@
|
||||||
#include "dialogeditlabel.h"
|
#include "dialogeditlabel.h"
|
||||||
#include "ui_dialogeditlabel.h"
|
#include "ui_dialogeditlabel.h"
|
||||||
#include "../vmisc/vabstractapplication.h"
|
#include "../vmisc/vabstractapplication.h"
|
||||||
|
#include "../vformat/vlabeltemplate.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
@ -298,18 +299,22 @@ void DialogEditLabel::ExportTemplate()
|
||||||
fileName += QLatin1String(".xml");
|
fileName += QLatin1String(".xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
// QString error;
|
VLabelTemplate ltemplate;
|
||||||
// const bool result = doc->SaveDocument(fileName, error);
|
ltemplate.CreateEmptyTemplate();
|
||||||
// if (result == false)
|
ltemplate.AddLines(PrepareLines());
|
||||||
// {
|
|
||||||
// QMessageBox messageBox(this);
|
QString error;
|
||||||
// messageBox.setIcon(QMessageBox::Warning);
|
const bool result = ltemplate.SaveDocument(fileName, error);
|
||||||
// messageBox.setInformativeText(tr("Could not save file"));
|
if (result == false)
|
||||||
// messageBox.setDefaultButton(QMessageBox::Ok);
|
{
|
||||||
// messageBox.setDetailedText(error);
|
QMessageBox messageBox(this);
|
||||||
// messageBox.setStandardButtons(QMessageBox::Ok);
|
messageBox.setIcon(QMessageBox::Warning);
|
||||||
// messageBox.exec();
|
messageBox.setInformativeText(tr("Could not save file"));
|
||||||
// }
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
||||||
|
messageBox.setDetailedText(error);
|
||||||
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
messageBox.exec();
|
||||||
|
}
|
||||||
|
|
||||||
RemoveTempDir();
|
RemoveTempDir();
|
||||||
return;
|
return;
|
||||||
|
@ -347,3 +352,28 @@ void DialogEditLabel::SetupControls()
|
||||||
ui->toolButtonExportLabel->setEnabled(enabled);
|
ui->toolButtonExportLabel->setEnabled(enabled);
|
||||||
ui->lineEditLine->setEnabled(enabled);
|
ui->lineEditLine->setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<VLabelTemplateLine> DialogEditLabel::PrepareLines() const
|
||||||
|
{
|
||||||
|
QVector<VLabelTemplateLine> lines;
|
||||||
|
|
||||||
|
for (int i=0; i<ui->listWidget->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;
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ namespace Ui
|
||||||
class DialogEditLabel;
|
class DialogEditLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class VLabelTemplateLine;
|
||||||
|
|
||||||
class DialogEditLabel : public QDialog
|
class DialogEditLabel : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -60,6 +62,8 @@ private:
|
||||||
Ui::DialogEditLabel *ui;
|
Ui::DialogEditLabel *ui;
|
||||||
|
|
||||||
void SetupControls();
|
void SetupControls();
|
||||||
|
|
||||||
|
QVector<VLabelTemplateLine> PrepareLines() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIALOGEDITLABEL_H
|
#endif // DIALOGEDITLABEL_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user