Get measurements units.

--HG--
branch : feature
This commit is contained in:
dismine 2014-03-16 08:32:52 +02:00
parent a950a9f59b
commit 61c4d8df0c
8 changed files with 169 additions and 41 deletions

View File

@ -34,8 +34,10 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, QWidget *parent) : DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, const QString &patternPieceName,
QDialog(parent), ui(new Ui::DialogIndividualMeasurements), _name(QString()), _tablePath(QString()), data(data) QWidget *parent) :
QDialog(parent), ui(new Ui::DialogIndividualMeasurements), _name(patternPieceName), _tablePath(QString()),
data(data)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -50,6 +52,8 @@ DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, QWi
connect(bCansel, &QPushButton::clicked, this, &DialogIndividualMeasurements::DialogRejected); connect(bCansel, &QPushButton::clicked, this, &DialogIndividualMeasurements::DialogRejected);
} }
ui->lineEditName->setText(_name);
LoadIndividualTables(); LoadIndividualTables();
CheckState(); CheckState();
@ -90,13 +94,50 @@ void DialogIndividualMeasurements::DialogAccepted()
return; 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(); accept();
} }
void DialogIndividualMeasurements::DialogRejected() void DialogIndividualMeasurements::DialogRejected()
{ {
_name = ""; _name.clear();
_tablePath = ""; _tablePath.clear();
reject(); reject();
} }

View File

@ -42,7 +42,7 @@ class DialogIndividualMeasurements : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit DialogIndividualMeasurements(VContainer *data, QWidget *parent = nullptr); DialogIndividualMeasurements(VContainer *data, const QString &patternPieceName, QWidget *parent = nullptr);
~DialogIndividualMeasurements(); ~DialogIndividualMeasurements();
QString name() const; QString name() const;
QString tablePath() const; QString tablePath() const;

View File

@ -31,8 +31,9 @@
#include <QDir> #include <QDir>
#include "../../xml/vstandardmeasurements.h" #include "../../xml/vstandardmeasurements.h"
DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, QWidget *parent) : DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, const QString &patternPieceName,
QDialog(parent), ui(new Ui::DialogStandardMeasurements), data(data), _name(QString()), _tablePath(QString()) QWidget *parent) :
QDialog(parent), ui(new Ui::DialogStandardMeasurements), data(data), _name(patternPieceName), _tablePath(QString())
{ {
ui->setupUi(this); ui->setupUi(this);
@ -47,6 +48,8 @@ DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, QWidget
connect(bCansel, &QPushButton::clicked, this, &DialogStandardMeasurements::DialogRejected); connect(bCansel, &QPushButton::clicked, this, &DialogStandardMeasurements::DialogRejected);
} }
ui->lineEditName->setText(_name);
LoadStandardTables(); LoadStandardTables();
CheckState(); CheckState();
@ -73,13 +76,50 @@ void DialogStandardMeasurements::DialogAccepted()
_name = ui->lineEditName->text(); _name = ui->lineEditName->text();
const qint32 index = ui->comboBoxTables->currentIndex(); const qint32 index = ui->comboBoxTables->currentIndex();
_tablePath = ui->comboBoxTables->itemData(index).toString(); _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(); accept();
} }
void DialogStandardMeasurements::DialogRejected() void DialogStandardMeasurements::DialogRejected()
{ {
_name = ""; _name.clear();
_tablePath = ""; _tablePath.clear();
reject(); reject();
} }

View File

@ -41,7 +41,7 @@ class DialogStandardMeasurements : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogStandardMeasurements(VContainer *data, QWidget *parent = nullptr); DialogStandardMeasurements(VContainer *data, const QString &patternPieceName, QWidget *parent = nullptr);
~DialogStandardMeasurements(); ~DialogStandardMeasurements();
QString name() const; QString name() const;
QString tablePath() const; QString tablePath() const;

View File

@ -99,7 +99,6 @@ MainWindow::MainWindow(QWidget *parent)
pattern = new VContainer(); pattern = new VContainer();
doc = new VPattern(pattern, comboBoxDraws, &mode); doc = new VPattern(pattern, comboBoxDraws, &mode);
doc->CreateEmptyFile();
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified);
InitAutoSave(); InitAutoSave();
@ -113,17 +112,20 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::ActionNewDraw() void MainWindow::ActionNewDraw()
{ {
QString nameDraw; QString patternPieceName = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1);
if (comboBoxDraws->count() == 0) if (comboBoxDraws->count() == 0)
{ {
QString path;
DialogMeasurements measurements(this); DialogMeasurements measurements(this);
measurements.exec(); measurements.exec();
if (measurements.type() == Measurements::Standard) if (measurements.type() == Measurements::Standard)
{ {
DialogStandardMeasurements stMeasurements(pattern, this); patternType == Pattern::Standard;
DialogStandardMeasurements stMeasurements(pattern, patternPieceName, this);
if (stMeasurements.exec() == QDialog::Accepted) if (stMeasurements.exec() == QDialog::Accepted)
{ {
nameDraw = stMeasurements.name(); patternPieceName = stMeasurements.name();
path = stMeasurements.tablePath();
} }
else else
{ {
@ -132,33 +134,36 @@ void MainWindow::ActionNewDraw()
} }
else else
{ {
DialogIndividualMeasurements indMeasurements(pattern, this); patternType == Pattern::Individual;
DialogIndividualMeasurements indMeasurements(pattern, patternPieceName, this);
if (indMeasurements.exec() == QDialog::Accepted) if (indMeasurements.exec() == QDialog::Accepted)
{ {
nameDraw = indMeasurements.name(); patternPieceName = indMeasurements.name();
path = indMeasurements.tablePath();
} }
else else
{ {
return; return;
} }
} }
doc->CreateEmptyFile(path);
} }
else else
{ {
nameDraw = PatternPieceName(QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1)); patternPieceName = PatternPieceName(patternPieceName);
if (nameDraw.isEmpty()) if (patternPieceName.isEmpty())
{ {
return; 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; return;
} }
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
comboBoxDraws->addItem(nameDraw); comboBoxDraws->addItem(patternPieceName);
pattern->ClearGObjects(); pattern->ClearGObjects();
//Create single point //Create single point
@ -175,7 +180,7 @@ void MainWindow::ActionNewDraw()
SetEnableTool(true); SetEnableTool(true);
SetEnableWidgets(true); SetEnableWidgets(true);
const qint32 index = comboBoxDraws->findText(nameDraw); const qint32 index = comboBoxDraws->findText(patternPieceName);
if ( index != -1 ) if ( index != -1 )
{ // -1 for not found { // -1 for not found
comboBoxDraws->setCurrentIndex(index); comboBoxDraws->setCurrentIndex(index);

View File

@ -144,6 +144,34 @@ inline void VDomDocument::SetAttribute<QString>(QDomElement &domElement, const Q
domElement.setAttribute(name, value); 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 #ifdef Q_CC_GNU
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif

View File

@ -38,24 +38,25 @@
#include <QMessageBox> #include <QMessageBox>
const QString VPattern::TagPattern = QStringLiteral("pattern"); const QString VPattern::TagPattern = QStringLiteral("pattern");
const QString VPattern::TagCalculation = QStringLiteral("calculation"); const QString VPattern::TagCalculation = QStringLiteral("calculation");
const QString VPattern::TagModeling = QStringLiteral("modeling"); const QString VPattern::TagModeling = QStringLiteral("modeling");
const QString VPattern::TagDetails = QStringLiteral("details"); const QString VPattern::TagDetails = QStringLiteral("details");
const QString VPattern::TagAuthor = QStringLiteral("author"); const QString VPattern::TagAuthor = QStringLiteral("author");
const QString VPattern::TagDescription = QStringLiteral("description"); const QString VPattern::TagDescription = QStringLiteral("description");
const QString VPattern::TagNotes = QStringLiteral("notes"); const QString VPattern::TagNotes = QStringLiteral("notes");
const QString VPattern::TagIncrements = QStringLiteral("increments"); const QString VPattern::TagMeasurements = QStringLiteral("measurements");
const QString VPattern::TagIncrement = QStringLiteral("increment"); const QString VPattern::TagIncrements = QStringLiteral("increments");
const QString VPattern::TagDraw = QStringLiteral("draw"); const QString VPattern::TagIncrement = QStringLiteral("increment");
const QString VPattern::TagPoint = QStringLiteral("point"); const QString VPattern::TagDraw = QStringLiteral("draw");
const QString VPattern::TagLine = QStringLiteral("line"); const QString VPattern::TagPoint = QStringLiteral("point");
const QString VPattern::TagSpline = QStringLiteral("spline"); const QString VPattern::TagLine = QStringLiteral("line");
const QString VPattern::TagArc = QStringLiteral("arc"); const QString VPattern::TagSpline = QStringLiteral("spline");
const QString VPattern::TagTools = QStringLiteral("tools"); const QString VPattern::TagArc = QStringLiteral("arc");
const QString VPattern::TagTools = QStringLiteral("tools");
const QString VPattern::AttrName = QStringLiteral("name"); const QString VPattern::AttrName = QStringLiteral("name");
const QString VPattern::AttrType = QStringLiteral("type"); const QString VPattern::AttrType = QStringLiteral("type");
const QString VPattern::IncrementName = QStringLiteral("name"); const QString VPattern::IncrementName = QStringLiteral("name");
const QString VPattern::IncrementBase = QStringLiteral("base"); 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); QDomElement patternElement = this->createElement(TagPattern);
patternElement.appendChild(createComment("Valentina pattern format.")); patternElement.appendChild(createComment("Valentina pattern format."));
patternElement.appendChild(createElement(TagAuthor)); patternElement.appendChild(createElement(TagAuthor));
patternElement.appendChild(createElement(TagDescription)); patternElement.appendChild(createElement(TagDescription));
patternElement.appendChild(createElement(TagNotes)); 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)); patternElement.appendChild(createElement(TagIncrements));
this->appendChild(patternElement); this->appendChild(patternElement);

View File

@ -55,8 +55,9 @@ public:
VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent = nullptr); VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent = nullptr);
/** /**
* @brief CreateEmptyFile create minimal empty file. * @brief CreateEmptyFile create minimal empty file.
* @param tablePath
*/ */
void CreateEmptyFile(); void CreateEmptyFile(const QString &tablePath);
/** /**
* @brief ChangeActivDraw set new pattern peace name. * @brief ChangeActivDraw set new pattern peace name.
* @param name new name. * @param name new name.
@ -171,6 +172,7 @@ public:
static const QString TagAuthor; static const QString TagAuthor;
static const QString TagDescription; static const QString TagDescription;
static const QString TagNotes; static const QString TagNotes;
static const QString TagMeasurements;
static const QString TagIncrements; static const QString TagIncrements;
static const QString TagIncrement; static const QString TagIncrement;
static const QString TagDraw; static const QString TagDraw;