From 61c4d8df0cb6a8850b4da6b819cda19e7df1040c Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 16 Mar 2014 08:32:52 +0200 Subject: [PATCH] Get measurements units. --HG-- branch : feature --- .../app/dialogindividualmeasurements.cpp | 49 +++++++++++++++++-- .../app/dialogindividualmeasurements.h | 2 +- .../app/dialogstandardmeasurements.cpp | 48 ++++++++++++++++-- src/dialogs/app/dialogstandardmeasurements.h | 2 +- src/mainwindow.cpp | 29 ++++++----- src/xml/vdomdocument.h | 28 +++++++++++ src/xml/vpattern.cpp | 48 +++++++++++------- src/xml/vpattern.h | 4 +- 8 files changed, 169 insertions(+), 41 deletions(-) diff --git a/src/dialogs/app/dialogindividualmeasurements.cpp b/src/dialogs/app/dialogindividualmeasurements.cpp index 68720b6eb..8da793595 100644 --- a/src/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/dialogs/app/dialogindividualmeasurements.cpp @@ -34,8 +34,10 @@ #include #include -DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogIndividualMeasurements), _name(QString()), _tablePath(QString()), data(data) +DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, const QString &patternPieceName, + QWidget *parent) : + QDialog(parent), ui(new Ui::DialogIndividualMeasurements), _name(patternPieceName), _tablePath(QString()), + data(data) { ui->setupUi(this); @@ -50,6 +52,8 @@ DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, QWi connect(bCansel, &QPushButton::clicked, this, &DialogIndividualMeasurements::DialogRejected); } + ui->lineEditName->setText(_name); + LoadIndividualTables(); CheckState(); @@ -90,13 +94,50 @@ void DialogIndividualMeasurements::DialogAccepted() return; } } + QFile file(_tablePath); + if (file.open(QIODevice::ReadOnly)) + { + try + { + VDomDocument::ValidatePattern("://schema/standard_measurements.xsd", _tablePath); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("Validation file error."), this); + qWarning()<<"Validation file error."< #include "../../xml/vstandardmeasurements.h" -DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogStandardMeasurements), data(data), _name(QString()), _tablePath(QString()) +DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, const QString &patternPieceName, + QWidget *parent) : + QDialog(parent), ui(new Ui::DialogStandardMeasurements), data(data), _name(patternPieceName), _tablePath(QString()) { ui->setupUi(this); @@ -47,6 +48,8 @@ DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, QWidget connect(bCansel, &QPushButton::clicked, this, &DialogStandardMeasurements::DialogRejected); } + ui->lineEditName->setText(_name); + LoadStandardTables(); CheckState(); @@ -73,13 +76,50 @@ void DialogStandardMeasurements::DialogAccepted() _name = ui->lineEditName->text(); const qint32 index = ui->comboBoxTables->currentIndex(); _tablePath = ui->comboBoxTables->itemData(index).toString(); + QFile file(_tablePath); + if (file.open(QIODevice::ReadOnly)) + { + try + { + VDomDocument::ValidatePattern("://schema/standard_measurements.xsd", _tablePath); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("Validation file error."), this); + qWarning()<<"Validation file error."<CreateEmptyFile(); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); InitAutoSave(); @@ -113,17 +112,20 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::ActionNewDraw() { - QString nameDraw; + QString patternPieceName = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1); if (comboBoxDraws->count() == 0) { + QString path; DialogMeasurements measurements(this); measurements.exec(); if (measurements.type() == Measurements::Standard) { - DialogStandardMeasurements stMeasurements(pattern, this); + patternType == Pattern::Standard; + DialogStandardMeasurements stMeasurements(pattern, patternPieceName, this); if (stMeasurements.exec() == QDialog::Accepted) { - nameDraw = stMeasurements.name(); + patternPieceName = stMeasurements.name(); + path = stMeasurements.tablePath(); } else { @@ -132,33 +134,36 @@ void MainWindow::ActionNewDraw() } else { - DialogIndividualMeasurements indMeasurements(pattern, this); + patternType == Pattern::Individual; + DialogIndividualMeasurements indMeasurements(pattern, patternPieceName, this); if (indMeasurements.exec() == QDialog::Accepted) { - nameDraw = indMeasurements.name(); + patternPieceName = indMeasurements.name(); + path = indMeasurements.tablePath(); } else { return; } } + doc->CreateEmptyFile(path); } else { - nameDraw = PatternPieceName(QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1)); - if (nameDraw.isEmpty()) + patternPieceName = PatternPieceName(patternPieceName); + if (patternPieceName.isEmpty()) { return; } } - if (doc->appendDraw(nameDraw) == false) + if (doc->appendDraw(patternPieceName) == false) { - qWarning()<(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); - comboBoxDraws->addItem(nameDraw); + comboBoxDraws->addItem(patternPieceName); pattern->ClearGObjects(); //Create single point @@ -175,7 +180,7 @@ void MainWindow::ActionNewDraw() SetEnableTool(true); SetEnableWidgets(true); - const qint32 index = comboBoxDraws->findText(nameDraw); + const qint32 index = comboBoxDraws->findText(patternPieceName); if ( index != -1 ) { // -1 for not found comboBoxDraws->setCurrentIndex(index); diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index e4d645dee..bfe95376c 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -144,6 +144,34 @@ inline void VDomDocument::SetAttribute(QDomElement &domElement, const Q domElement.setAttribute(name, value); } +template <> +inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, + const Pattern::Measurements &value) +{ + if (value == Pattern::Standard) + { + domElement.setAttribute(name, "standard"); + } + else + { + domElement.setAttribute(name, "individual"); + } +} + +template <> +inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, + const Valentina::Units &value) +{ + if (value == Valentina::Cm || value == Valentina::Mm) + { + domElement.setAttribute(name, "cm"); + } + else + { + domElement.setAttribute(name, "in"); + } +} + #ifdef Q_CC_GNU #pragma GCC diagnostic pop #endif diff --git a/src/xml/vpattern.cpp b/src/xml/vpattern.cpp index b3f763291..5305c8ce0 100644 --- a/src/xml/vpattern.cpp +++ b/src/xml/vpattern.cpp @@ -38,24 +38,25 @@ #include -const QString VPattern::TagPattern = QStringLiteral("pattern"); -const QString VPattern::TagCalculation = QStringLiteral("calculation"); -const QString VPattern::TagModeling = QStringLiteral("modeling"); -const QString VPattern::TagDetails = QStringLiteral("details"); -const QString VPattern::TagAuthor = QStringLiteral("author"); -const QString VPattern::TagDescription = QStringLiteral("description"); -const QString VPattern::TagNotes = QStringLiteral("notes"); -const QString VPattern::TagIncrements = QStringLiteral("increments"); -const QString VPattern::TagIncrement = QStringLiteral("increment"); -const QString VPattern::TagDraw = QStringLiteral("draw"); -const QString VPattern::TagPoint = QStringLiteral("point"); -const QString VPattern::TagLine = QStringLiteral("line"); -const QString VPattern::TagSpline = QStringLiteral("spline"); -const QString VPattern::TagArc = QStringLiteral("arc"); -const QString VPattern::TagTools = QStringLiteral("tools"); +const QString VPattern::TagPattern = QStringLiteral("pattern"); +const QString VPattern::TagCalculation = QStringLiteral("calculation"); +const QString VPattern::TagModeling = QStringLiteral("modeling"); +const QString VPattern::TagDetails = QStringLiteral("details"); +const QString VPattern::TagAuthor = QStringLiteral("author"); +const QString VPattern::TagDescription = QStringLiteral("description"); +const QString VPattern::TagNotes = QStringLiteral("notes"); +const QString VPattern::TagMeasurements = QStringLiteral("measurements"); +const QString VPattern::TagIncrements = QStringLiteral("increments"); +const QString VPattern::TagIncrement = QStringLiteral("increment"); +const QString VPattern::TagDraw = QStringLiteral("draw"); +const QString VPattern::TagPoint = QStringLiteral("point"); +const QString VPattern::TagLine = QStringLiteral("line"); +const QString VPattern::TagSpline = QStringLiteral("spline"); +const QString VPattern::TagArc = QStringLiteral("arc"); +const QString VPattern::TagTools = QStringLiteral("tools"); -const QString VPattern::AttrName = QStringLiteral("name"); -const QString VPattern::AttrType = QStringLiteral("type"); +const QString VPattern::AttrName = QStringLiteral("name"); +const QString VPattern::AttrType = QStringLiteral("type"); const QString VPattern::IncrementName = QStringLiteral("name"); const QString VPattern::IncrementBase = QStringLiteral("base"); @@ -69,14 +70,25 @@ VPattern::VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws { } -void VPattern::CreateEmptyFile() +void VPattern::CreateEmptyFile(const QString &tablePath) { + if (tablePath.isEmpty()) + { + throw VException("Path to measurement table empty."); + } QDomElement patternElement = this->createElement(TagPattern); patternElement.appendChild(createComment("Valentina pattern format.")); patternElement.appendChild(createElement(TagAuthor)); patternElement.appendChild(createElement(TagDescription)); patternElement.appendChild(createElement(TagNotes)); + + QDomElement measurements = createElement(TagMeasurements); + SetAttribute(measurements, "unit", patternUnit); + SetAttribute(measurements, "type", patternType); + SetAttribute(measurements, "path", tablePath); + patternElement.appendChild(measurements); + patternElement.appendChild(createElement(TagIncrements)); this->appendChild(patternElement); diff --git a/src/xml/vpattern.h b/src/xml/vpattern.h index 102e53c0a..d51f6cd16 100644 --- a/src/xml/vpattern.h +++ b/src/xml/vpattern.h @@ -55,8 +55,9 @@ public: VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent = nullptr); /** * @brief CreateEmptyFile create minimal empty file. + * @param tablePath */ - void CreateEmptyFile(); + void CreateEmptyFile(const QString &tablePath); /** * @brief ChangeActivDraw set new pattern peace name. * @param name new name. @@ -171,6 +172,7 @@ public: static const QString TagAuthor; static const QString TagDescription; static const QString TagNotes; + static const QString TagMeasurements; static const QString TagIncrements; static const QString TagIncrement; static const QString TagDraw;