Get measurements units.
--HG-- branch : feature
This commit is contained in:
parent
a950a9f59b
commit
61c4d8df0c
|
@ -34,8 +34,10 @@
|
|||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
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."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
|
||||
return;
|
||||
}
|
||||
|
||||
VIndividualMeasurements m(data);
|
||||
try
|
||||
{
|
||||
m.setContent(&file);
|
||||
patternUnit = m.Unit();
|
||||
}
|
||||
catch(VException &e)
|
||||
{
|
||||
e.CriticalMessageBox(tr("Parsing pattern file error."), this);
|
||||
qWarning()<<"Parsing pattern file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
|
||||
return;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString message = tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString());
|
||||
QMessageBox::warning(this, tr("Cannot read file"), message);
|
||||
qWarning()<<tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString()) << Q_FUNC_INFO;
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
void DialogIndividualMeasurements::DialogRejected()
|
||||
{
|
||||
_name = "";
|
||||
_tablePath = "";
|
||||
_name.clear();
|
||||
_tablePath.clear();
|
||||
reject();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class DialogIndividualMeasurements : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogIndividualMeasurements(VContainer *data, QWidget *parent = nullptr);
|
||||
DialogIndividualMeasurements(VContainer *data, const QString &patternPieceName, QWidget *parent = nullptr);
|
||||
~DialogIndividualMeasurements();
|
||||
QString name() const;
|
||||
QString tablePath() const;
|
||||
|
|
|
@ -31,8 +31,9 @@
|
|||
#include <QDir>
|
||||
#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."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
|
||||
return;
|
||||
}
|
||||
|
||||
VStandardMeasurements m(data);
|
||||
try
|
||||
{
|
||||
m.setContent(&file);
|
||||
patternUnit = m.Unit();
|
||||
}
|
||||
catch(VException &e)
|
||||
{
|
||||
e.CriticalMessageBox(tr("Parsing pattern file error."), this);
|
||||
qWarning()<<"Parsing pattern file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
|
||||
return;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString message = tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString());
|
||||
QMessageBox::warning(this, tr("Cannot read file"), message);
|
||||
qWarning()<<tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString()) << Q_FUNC_INFO;
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
void DialogStandardMeasurements::DialogRejected()
|
||||
{
|
||||
_name = "";
|
||||
_tablePath = "";
|
||||
_name.clear();
|
||||
_tablePath.clear();
|
||||
reject();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class DialogStandardMeasurements : public QDialog
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DialogStandardMeasurements(VContainer *data, QWidget *parent = nullptr);
|
||||
DialogStandardMeasurements(VContainer *data, const QString &patternPieceName, QWidget *parent = nullptr);
|
||||
~DialogStandardMeasurements();
|
||||
QString name() const;
|
||||
QString tablePath() const;
|
||||
|
|
|
@ -99,7 +99,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
pattern = new VContainer();
|
||||
|
||||
doc = new VPattern(pattern, comboBoxDraws, &mode);
|
||||
doc->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()<<tr("Error creating pattern with the name ")<<nameDraw<<".";
|
||||
qWarning()<<tr("Error creating pattern with the name ")<<patternPieceName<<".";
|
||||
return;
|
||||
}
|
||||
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&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);
|
||||
|
|
|
@ -144,6 +144,34 @@ inline void VDomDocument::SetAttribute<QString>(QDomElement &domElement, const Q
|
|||
domElement.setAttribute(name, value);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void VDomDocument::SetAttribute<Pattern::Measurements>(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<Valentina::Units>(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
|
||||
|
|
|
@ -38,24 +38,25 @@
|
|||
|
||||
#include <QMessageBox>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user