diff --git a/Valentina.pro b/Valentina.pro index c6ba0d871..9c5f07496 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -89,13 +89,13 @@ CONFIG(debug, debug|release){ } } else { *-g++{#Don't use additional GCC keys on Windows system. - QMAKE_CXXFLAGS += -Og -Wall -Wextra -pedantic + QMAKE_CXXFLAGS += -O0 -Wall -Wextra -pedantic } } }else{ # Release *-g++{ - QMAKE_CXXFLAGS += -O1 + QMAKE_CXXFLAGS += -O2 } DEFINES += QT_NO_DEBUG_OUTPUT diff --git a/share/resources/schema/pattern.xsd b/share/resources/schema/pattern.xsd index 78a444e41..cfc6524a5 100644 --- a/share/resources/schema/pattern.xsd +++ b/share/resources/schema/pattern.xsd @@ -4,9 +4,16 @@ - - - + + + + + + + + + + diff --git a/src/dialogs/app/dialogincrements.cpp b/src/dialogs/app/dialogincrements.cpp index 549cc687f..0f44d0e06 100644 --- a/src/dialogs/app/dialogincrements.cpp +++ b/src/dialogs/app/dialogincrements.cpp @@ -91,37 +91,17 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par if (qApp->patternType() == Pattern::Individual) { QString filePath = doc->MPath(); - QFile file(filePath); - if (file.open(QIODevice::ReadOnly)) + try { - try - { - VDomDocument::ValidatePattern("://schema/individual_measurements.xsd", filePath); - } - catch(VException &e) - { - qWarning()<<"Validation file error."<setContent(&file); - } - catch(VException &e) - { - qWarning()<<"Parsing measurements file error."<setContent(filePath); } - else + catch(VException &e) { - qWarning()<setPatternUnit( m.Unit()); - } - catch(VException &e) - { - e.CriticalMessageBox(tr("Parsing pattern file error."), this); - qWarning()<<"Parsing pattern file error."<setPatternUnit( m.Unit()); } - else + catch(VException &e) { - QString message = tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString()); - QMessageBox::warning(this, tr("Cannot read file"), message); - qWarning()<comboBoxLang->addItem(lang, QVariant(fi.absoluteFilePath())); - } - catch(VException &e) - { - qWarning()<<"Parsing pattern file error."<comboBoxLang->addItem(lang, QVariant(fi.absoluteFilePath())); } - else + catch(VException &e) { - qWarning()<lineEditPathExistM->setText(fileName); diff --git a/src/dialogs/app/dialogstandardmeasurements.cpp b/src/dialogs/app/dialogstandardmeasurements.cpp index 36a061279..e6af0ffea 100644 --- a/src/dialogs/app/dialogstandardmeasurements.cpp +++ b/src/dialogs/app/dialogstandardmeasurements.cpp @@ -77,40 +77,18 @@ 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."<setPatternUnit(m.Unit()); - } - catch(VException &e) - { - e.CriticalMessageBox(tr("Parsing pattern file error."), this); - qWarning()<<"Parsing pattern file error."<setPatternUnit(m.Unit()); } - else + catch(VException &e) { - QString message = tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString()); - QMessageBox::warning(this, tr("Cannot read file"), message); - qWarning()<comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath())); - } - catch(VException &e) - { - qWarning()<<"Parsing pattern file error."<comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath())); } - else + catch(VException &e) { - qWarning()< #include @@ -55,7 +56,6 @@ MainWindow::MainWindow(QWidget *parent) { CreateActions(); CreateMenus(); - ToolBarOption(); ToolBarDraws(); sceneDraw = new VMainGraphicsScene(); @@ -542,39 +542,36 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::ToolBarOption() { - QLabel * labelGrowth = new QLabel; - labelGrowth->setText(tr("Height: ")); - ui->toolBarOption->addWidget(labelGrowth); + if (qApp->patternType() == Pattern::Standard) + { + ui->toolBarOption->addWidget(new QLabel(tr("Height: "))); - QStringList list; - list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" - <<"182"<<"188"; - QComboBox *comboBoxGrow = new QComboBox; - comboBoxGrow->clear(); - comboBoxGrow->addItems(list); - comboBoxGrow->setCurrentIndex(14); - ui->toolBarOption->addWidget(comboBoxGrow); - connect(comboBoxGrow, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::ChangedHeight); + QStringList list; + list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" + <<"182"<<"188"; + QComboBox *comboBoxHeight = new QComboBox; + comboBoxHeight->addItems(list); + comboBoxHeight->setCurrentIndex(14);//176 + ui->toolBarOption->addWidget(comboBoxHeight); + connect(comboBoxHeight, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedHeight); - QLabel * labelSize = new QLabel; - labelSize->setText(tr(" Size: ")); - ui->toolBarOption->addWidget(labelSize); + ui->toolBarOption->addWidget(new QLabel(tr(" Size: "))); - list.clear(); - list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"<<"56"; - QComboBox *comboBoxSize = new QComboBox; - comboBoxSize->clear(); - comboBoxSize->addItems(list); - comboBoxSize->setCurrentIndex(14); - ui->toolBarOption->addWidget(comboBoxSize); - connect(comboBoxSize, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::ChangedSize); + list.clear(); + list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54" + <<"56"; + QComboBox *comboBoxSize = new QComboBox; + comboBoxSize->addItems(list); + comboBoxSize->setCurrentIndex(14);//50 + ui->toolBarOption->addWidget(comboBoxSize); + connect(comboBoxSize, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::ChangedSize); - ui->toolBarOption->addSeparator(); + ui->toolBarOption->addSeparator(); + } - mouseCoordinate = new QLabel; - mouseCoordinate ->setText("0, 0"); + mouseCoordinate = new QLabel("0, 0"); ui->toolBarOption->addWidget(mouseCoordinate); } @@ -626,10 +623,12 @@ void MainWindow::currentDrawChanged( int index ) void MainWindow::mouseMove(const QPointF &scenePos) { - QString string = QString("%1, %2") - .arg(static_cast(qApp->fromPixel(scenePos.x()))) - .arg(static_cast(qApp->fromPixel(scenePos.y()))); - mouseCoordinate->setText(string); + QString string = QString("%1, %2").arg(static_cast(qApp->fromPixel(scenePos.x()))) + .arg(static_cast(qApp->fromPixel(scenePos.y()))); + if (mouseCoordinate != nullptr) + { + mouseCoordinate->setText(string); + } } void MainWindow::CancelTool() @@ -953,6 +952,9 @@ void MainWindow::Clear() ui->actionSave->setEnabled(false); ui->actionPattern_properties->setEnabled(false); SetEnableTool(false); + qApp->setPatternUnit(Valentina::Cm); + qApp->setPatternType(Pattern::Individual); + ui->toolBarOption->clear(); #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif @@ -1386,100 +1388,165 @@ MainWindow::~MainWindow() void MainWindow::LoadPattern(const QString &fileName) { - QFile file(fileName); - if (file.open(QIODevice::ReadOnly)) + try { - try + VDomDocument::ValidateXML("://schema/pattern.xsd", fileName); + doc->setContent(fileName); + + qApp->setPatternUnit(doc->MUnit()); + qApp->setPatternType(doc->MType()); + QString path = doc->MPath(); + + path = CheckPathToMeasurements(path, qApp->patternType()); + if(path.isEmpty()) { - VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName); - } - catch(VException &e) - { - e.CriticalMessageBox(tr("Validation file error."), this); - file.close(); Clear(); return; } - try + QString text = tr("Measurements use different units than pattern. This pattern required measurements in %1") + .arg(doc->UnitsToStr(qApp->patternUnit())); + if (qApp->patternType() == Pattern::Standard) { - doc->setContent(&file); - } - catch(VException &e) - { - e.CriticalMessageBox(tr("Parsing pattern file error."), this); - file.close(); - Clear(); - return; - } - - disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - try - { - #ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); - #endif - doc->Parse(Document::FullParse, sceneDraw, sceneDetails); - #ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); - #endif - ui->actionPattern_properties->setEnabled(true); - } - catch (const VExceptionObjectError &e) - { - e.CriticalMessageBox(tr("Error parsing file."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionConversionError &e) - { - e.CriticalMessageBox(tr("Error can't convert value."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionEmptyParameter &e) - { - e.CriticalMessageBox(tr("Error empty parameter."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionWrongId &e) - { - e.CriticalMessageBox(tr("Error wrong id."), this); - file.close(); - Clear(); - return; - } - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - QString nameDraw = doc->GetNameActivDraw(); - qint32 index = comboBoxDraws->findText(nameDraw); - if ( index != -1 ) - { // -1 for not found - comboBoxDraws->setCurrentIndex(index); - } - if (comboBoxDraws->count() > 0) - { - SetEnableTool(true); + VStandardMeasurements m(pattern); + m.setContent(path); + Valentina::Units mUnit = m.Unit(); + if (qApp->patternUnit() != mUnit) + { + QMessageBox::critical(this, tr("Wrong units."), text); + Clear(); + return; + } + m.SetSize(); + m.SetHeight(); + ToolBarOption(); } else { - SetEnableTool(false); + VIndividualMeasurements m(pattern); + m.setContent(path); + Valentina::Units mUnit = m.Unit(); + if (qApp->patternUnit() != mUnit) + { + QMessageBox::critical(this, tr("Wrong units."), text); + Clear(); + return; + } } - SetEnableWidgets(true); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("File error."), this); + Clear(); + return; + } - file.close(); + disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + try + { + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + + doc->Parse(Document::FullParse, sceneDraw, sceneDetails); + + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + ui->actionPattern_properties->setEnabled(true); + } + catch (const VExceptionObjectError &e) + { + e.CriticalMessageBox(tr("Error parsing file."), this); + Clear(); + return; + } + catch (const VExceptionConversionError &e) + { + e.CriticalMessageBox(tr("Error can't convert value."), this); + Clear(); + return; + } + catch (const VExceptionEmptyParameter &e) + { + e.CriticalMessageBox(tr("Error empty parameter."), this); + Clear(); + return; + } + catch (const VExceptionWrongId &e) + { + e.CriticalMessageBox(tr("Error wrong id."), this); + Clear(); + return; + } + connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + QString nameDraw = doc->GetNameActivDraw(); + qint32 index = comboBoxDraws->findText(nameDraw); + if ( index != -1 ) + { // -1 for not found + comboBoxDraws->setCurrentIndex(index); + } + if (comboBoxDraws->count() > 0) + { + SetEnableTool(true); } else { - QMessageBox::warning(this, tr("Valentina"), tr("Cannot read file %1:\n%2.") - .arg(fileName) - .arg(file.errorString())); + SetEnableTool(false); } + SetEnableWidgets(true); + setCurrentFile(fileName); helpLabel->setText(tr("File loaded")); } + +QString MainWindow::CheckPathToMeasurements(const QString &path, const Pattern::Measurements &patternType) +{ + QFile table(path); + if (table.exists() == false) + { + QString text = tr("The measurements file

%1

%3").arg(path) + .arg(tr("could not be found. Do you want to update the file location")); + QMessageBox::StandardButton res = QMessageBox::question(this, "Loading measurements file", text, + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + if(res == QMessageBox::No) + { + return QString(); + } + else + { + QString filter; + if (patternType == Pattern::Standard) + { + filter = tr("Standard measurements (*.vst)"); + } + else + { + filter = tr("Individual measurements (*.vit)"); + } + QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); + + if(mPath.isEmpty()) + { + return mPath; + } + else + { + if (patternType == Pattern::Standard) + { + VDomDocument::ValidateXML("://schema/standard_measurements.xsd", mPath); + } + else + { + VDomDocument::ValidateXML("://schema/individual_measurements.xsd", mPath); + } + doc->SetPath(mPath); + return mPath; + } + } + } + return path; +} diff --git a/src/mainwindow.h b/src/mainwindow.h index c5bcc046e..cc517b6a0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -562,6 +562,7 @@ private: void CreateActions(); void InitAutoSave(); QString PatternPieceName(const QString &text); + QString CheckPathToMeasurements(const QString &path, const Pattern::Measurements &patternType); }; #endif // MAINWINDOW_H diff --git a/src/options.h b/src/options.h index b58858479..00da1e17e 100644 --- a/src/options.h +++ b/src/options.h @@ -92,7 +92,7 @@ namespace Valentina /** * @brief The Unit enum */ - enum Unit { Mm, Cm, In }; + enum Unit { Mm, Cm, Inch }; Q_DECLARE_FLAGS(Units, Unit) } Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Scenes ) diff --git a/src/widgets/vapplication.cpp b/src/widgets/vapplication.cpp index dd2ac8575..c33c7b579 100644 --- a/src/widgets/vapplication.cpp +++ b/src/widgets/vapplication.cpp @@ -99,7 +99,7 @@ double VApplication::toPixel(double unit) const case Valentina::Cm: result = ((unit * 10.0) / 25.4) * PrintDPI; break; - case Valentina::In: + case Valentina::Inch: result = unit * PrintDPI; break; default: @@ -119,7 +119,7 @@ double VApplication::fromPixel(double pix) const case Valentina::Cm: result = ((pix / PrintDPI) * 25.4) / 10.0; break; - case Valentina::In: + case Valentina::Inch: result = pix / PrintDPI; break; default: diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index a6464c53d..f6494543a 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -81,7 +81,7 @@ const QString VDomDocument::AttrId = QStringLiteral("id"); const QString VDomDocument::AttrUnit = QStringLiteral("unit"); const QString VDomDocument::UnitMM = QStringLiteral("mm"); const QString VDomDocument::UnitCM = QStringLiteral("cm"); -const QString VDomDocument::UnitIN = QStringLiteral("in"); +const QString VDomDocument::UnitINCH = QStringLiteral("inch"); VDomDocument::VDomDocument(VContainer *data) : QDomDocument(), data(data), map(QHash()) @@ -250,27 +250,21 @@ QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVa return defVal; } -void VDomDocument::ValidatePattern(const QString &schema, const QString &fileName) +void VDomDocument::ValidateXML(const QString &schema, const QString &fileName) { - QString errorMsg; - qint64 errorLine = -1; - qint64 errorColumn = -1; - QFile pattern(fileName); if (pattern.open(QIODevice::ReadOnly) == false) { - errorMsg = QString(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString())); - VException e(errorMsg); - e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); - throw e; + const QString errorMsg(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString())); + throw VException(errorMsg); } + QFile fileSchema(schema); if (fileSchema.open(QIODevice::ReadOnly) == false) { - errorMsg = QString(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString())); - VException e(errorMsg); - e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); - throw e; + pattern.close(); + const QString errorMsg(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString())); + throw VException(errorMsg); } MessageHandler messageHandler; @@ -294,30 +288,41 @@ void VDomDocument::ValidatePattern(const QString &schema, const QString &fileNam if (errorOccurred) { + pattern.close(); + fileSchema.close(); VException e(messageHandler.statusMessage()); - e.AddMoreInformation(tr("Error in line %1 column %2").arg(messageHandler.line()).arg(messageHandler.column())); + e.AddMoreInformation(tr("Validation error in line %1 column %2").arg(messageHandler.line()).arg(messageHandler.column())); throw e; } - + pattern.close(); + fileSchema.close(); } -void VDomDocument::setContent(QIODevice *dev) +void VDomDocument::setContent(const QString &fileName) { - QString errorMsg; - int errorLine = 0; - int errorColumn = 0; - if (QDomDocument::setContent(dev, &errorMsg, &errorLine, &errorColumn) == false) + QFile file(fileName); + if (file.open(QIODevice::ReadOnly) == false) { - VException e(errorMsg); - e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); - throw e; + const QString errorMsg(tr("Can't open file %1:\n%2.").arg(fileName).arg(file.errorString())); + throw VException(errorMsg); + } + + QString errorMsg; + int errorLine = -1; + int errorColumn = -1; + if (QDomDocument::setContent(&file, &errorMsg, &errorLine, &errorColumn) == false) + { + file.close(); + VException e(errorMsg); + e.AddMoreInformation(tr("Parcing error in line %1 column %2").arg(errorLine).arg(errorColumn)); + throw e; } } -Valentina::Units VDomDocument::Units(const QString &unit) +Valentina::Units VDomDocument::StrToUnits(const QString &unit) { QStringList units; - units << UnitMM << UnitCM << UnitIN; + units << UnitMM << UnitCM << UnitINCH; Valentina::Units result = Valentina::Cm; switch (units.indexOf(unit)) { @@ -327,8 +332,8 @@ Valentina::Units VDomDocument::Units(const QString &unit) case 1:// cm result = Valentina::Cm; break; - case 2:// in - result = Valentina::In; + case 2:// inch + result = Valentina::Inch; break; default: result = Valentina::Cm; @@ -336,3 +341,24 @@ Valentina::Units VDomDocument::Units(const QString &unit) } return result; } + +QString VDomDocument::UnitsToStr(const Valentina::Units &unit) +{ + QString result; + switch(unit) + { + case Valentina::Mm: + result = "mm"; + break; + case Valentina::Cm: + result = "cm"; + break; + case Valentina::Inch: + result = "inch"; + break; + default: + result = "cm"; + break; + } + return result; +} diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index 6692d0760..8c6df8ab7 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -51,7 +51,7 @@ public: static const QString AttrUnit; static const QString UnitMM; static const QString UnitCM; - static const QString UnitIN; + static const QString UnitINCH; /** * @brief VDomDocument constructor. * @param data container with variables. @@ -111,22 +111,24 @@ public: qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; /** - * @brief ValidatePattern validate pattern file by xsd schema. + * @brief ValidateXML validate xml file by xsd schema. * @param schema path to schema file. - * @param fileName name of pattern file. + * @param fileName name of xml file. * @param errorMsg error message. * @param errorLine number error line. * @param errorColumn number error column. * @return true if validation successful. */ - static void ValidatePattern(const QString &schema, const QString &fileName); - void setContent(QIODevice * dev); + static void ValidateXML(const QString &schema, const QString &fileName); + void setContent(const QString &fileName); + static Valentina::Units StrToUnits(const QString &unit); + static QString UnitsToStr(const Valentina::Units &unit); protected: /** * @brief data container with data. */ VContainer *data; - Valentina::Units Units(const QString &unit); + private: Q_DISABLE_COPY(VDomDocument) /** @@ -163,27 +165,6 @@ inline void VDomDocument::SetAttribute(QDomElement &domEl } } -template <> -inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, - const Valentina::Units &value) -{ - switch(value) - { - case Valentina::Mm: - domElement.setAttribute(name, "mm"); - break; - case Valentina::Cm: - domElement.setAttribute(name, "cm"); - break; - case Valentina::In: - domElement.setAttribute(name, "in"); - break; - default: - domElement.setAttribute(name, "cm"); - break; - } -} - #ifdef Q_CC_GNU #pragma GCC diagnostic pop #endif diff --git a/src/xml/vindividualmeasurements.cpp b/src/xml/vindividualmeasurements.cpp index 375e56198..28f870602 100644 --- a/src/xml/vindividualmeasurements.cpp +++ b/src/xml/vindividualmeasurements.cpp @@ -47,7 +47,7 @@ VIndividualMeasurements::VIndividualMeasurements(VContainer *data):VDomDocument( Valentina::Units VIndividualMeasurements::Unit() { const QString unit = UniqueTagText(AttrUnit, UnitCM); - return VDomDocument::Units(unit); + return VDomDocument::StrToUnits(unit); } void VIndividualMeasurements::Measurements() diff --git a/src/xml/vpattern.cpp b/src/xml/vpattern.cpp index 24ed010bb..048357a64 100644 --- a/src/xml/vpattern.cpp +++ b/src/xml/vpattern.cpp @@ -35,6 +35,8 @@ #include "../exception/vexceptionobjecterror.h" #include "../exception/vexceptionwrongid.h" #include "../exception/vexceptionconversionerror.h" +#include "vstandardmeasurements.h" +#include "vindividualmeasurements.h" #include @@ -85,7 +87,7 @@ void VPattern::CreateEmptyFile(const QString &tablePath) patternElement.appendChild(createElement(TagNotes)); QDomElement measurements = createElement(TagMeasurements); - SetAttribute(measurements, AttrUnit, qApp->patternUnit()); + SetAttribute(measurements, AttrUnit, UnitsToStr(qApp->patternUnit())); SetAttribute(measurements, AttrType, qApp->patternType()); SetAttribute(measurements, AttrPath, tablePath); patternElement.appendChild(measurements); @@ -417,7 +419,7 @@ bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element) QString VPattern::MPath() const { - QDomNodeList list = elementsByTagName(VPattern::TagMeasurements); + QDomNodeList list = elementsByTagName(TagMeasurements); QDomElement element = list.at(0).toElement(); if (element.isElement()) { @@ -429,6 +431,20 @@ QString VPattern::MPath() const } } +void VPattern::SetPath(const QString &path) +{ + QDomNodeList list = elementsByTagName(TagMeasurements); + QDomElement element = list.at(0).toElement(); + if (element.isElement()) + { + SetAttribute(element, AttrPath, path); + } + else + { + qWarning()<<"Can't save path to measurements"<Clear(); - emit UpdateMeasurements(); + UpdateMeasurements(); nameActivDraw.clear(); sceneDraw->clear(); sceneDetail->clear(); @@ -1400,3 +1416,20 @@ void VPattern::PrepareForParse(const Document::Documents &parse, VMainGraphicsSc data->ClearDetails(); history.clear(); } + +void VPattern::UpdateMeasurements() +{ + const QString path = MPath(); + if (MType() == Pattern::Standard) + { + VStandardMeasurements m(data); + m.setContent(path); + m.Measurements(); + } + else + { + VIndividualMeasurements m(data); + m.setContent(path); + m.Measurements(); + } +} diff --git a/src/xml/vpattern.h b/src/xml/vpattern.h index f1e559543..f9b7a8cca 100644 --- a/src/xml/vpattern.h +++ b/src/xml/vpattern.h @@ -166,6 +166,7 @@ public: */ bool GetActivNodeElement(const QString& name, QDomElement& element); QString MPath() const; + void SetPath(const QString &path); Valentina::Units MUnit() const; Pattern::Measurements MType() const; static const QString TagPattern; @@ -224,7 +225,6 @@ signals: * @param id tool id. */ void ChangedCursor(quint32 id); - void UpdateMeasurements(); public slots: /** * @brief FullUpdateTree lite parse file. @@ -382,6 +382,7 @@ private: void CollectId(const QDomElement &node, QVector &vector)const; void PrepareForParse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail); + void UpdateMeasurements(); }; inline QString VPattern::GetNameActivDraw() const diff --git a/src/xml/vstandardmeasurements.cpp b/src/xml/vstandardmeasurements.cpp index 204687dfb..49826919a 100644 --- a/src/xml/vstandardmeasurements.cpp +++ b/src/xml/vstandardmeasurements.cpp @@ -47,7 +47,7 @@ VStandardMeasurements::VStandardMeasurements(VContainer *data):VDomDocument(data Valentina::Units VStandardMeasurements::Unit() { const QString unit = UniqueTagText(AttrUnit, UnitCM); - return VDomDocument::Units(unit); + return VDomDocument::StrToUnits(unit); } QString VStandardMeasurements::Description()