From 65bf17fcf947da77439340fdfe542a5635001860 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 3 Jan 2016 15:21:30 +0200 Subject: [PATCH] Fixed broken feature 'Default height and size'. --HG-- branch : develop --- .../dialogs/dialogpatternproperties.cpp | 23 ++-- src/app/valentina/mainwindow.cpp | 16 +-- src/app/valentina/xml/vpattern.cpp | 11 +- src/libs/ifc/xml/vabstractpattern.cpp | 130 +++++++++++++----- 4 files changed, 114 insertions(+), 66 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 07d04d709..3115183b7 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -88,12 +88,10 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat InitComboBox(ui->comboBoxHeight, heights); InitComboBox(ui->comboBoxSize, sizes); - const QString height = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomHeight(), - *pattern->GetPatternUnit(), Unit::Cm))); + const QString height = QString().setNum(doc->GetDefCustomHeight()); SetDefaultHeight(height); - const QString size = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomSize(), - *pattern->GetPatternUnit(), Unit::Cm))); + const QString size = QString().setNum(doc->GetDefCustomSize()); SetDefaultSize(size); connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, &DialogPatternProperties::ToggleComboBox); @@ -454,18 +452,12 @@ void DialogPatternProperties::SaveDefValues() if (ui->radioButtonDefFromM->isChecked()) { doc->SetDefCustom(false); - doc->SetDefCustomHeight(0); - doc->SetDefCustomSize(0); } else { doc->SetDefCustom(true); - const int height = static_cast(UnitConvertor(ui->comboBoxHeight->currentText().toInt(), - Unit::Cm, *pattern->GetPatternUnit())); - doc->SetDefCustomHeight(height); - const int size = static_cast(UnitConvertor(ui->comboBoxSize->currentText().toInt(), - Unit::Cm, *pattern->GetPatternUnit())); - doc->SetDefCustomSize(size); + doc->SetDefCustomHeight(ui->comboBoxHeight->currentText().toInt()); + doc->SetDefCustomSize(ui->comboBoxSize->currentText().toInt()); } defaultChanged = false; } @@ -481,7 +473,7 @@ void DialogPatternProperties::SetDefaultHeight(const QString &def) } else { - const int height = static_cast(UnitConvertor(pattern->height(), *pattern->GetPatternUnit(), Unit::Cm)); + const int height = static_cast(pattern->height()); index = ui->comboBoxHeight->findText(QString().setNum(height)); if (index != -1) { @@ -502,7 +494,7 @@ void DialogPatternProperties::SetDefaultSize(const QString &def) } else { - const int size = static_cast(UnitConvertor(pattern->size(), *pattern->GetPatternUnit(), Unit::Cm)); + const int size = static_cast(pattern->size()); index = ui->comboBoxSize->findText(QString().setNum(size)); if (index != -1) { @@ -572,7 +564,8 @@ void DialogPatternProperties::InitComboBox(QComboBox *box, const QMapaddItem(QString().setNum(static_cast(i.key()))); + box->addItem(QString().setNum(static_cast(UnitConvertor(static_cast(i.key()), Unit::Cm, + *pattern->GetPatternUnit())))); } } } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index b96f10dae..76fe05e13 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -2693,8 +2693,7 @@ void MainWindow::ChangedHeight(const QString &text) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::SetDefaultHeight() { - const QString defHeight = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomHeight(), - *pattern->GetPatternUnit(), Unit::Cm))); + const QString defHeight = QString().setNum(doc->GetDefCustomHeight()); int index = gradationHeights->findText(defHeight); if (index != -1) { @@ -2707,18 +2706,14 @@ void MainWindow::SetDefaultHeight() { gradationHeights->setCurrentIndex(index); } - else - { - pattern->SetHeight(gradationHeights->currentText().toInt()); - } } + pattern->SetHeight(gradationHeights->currentText().toInt()); } //--------------------------------------------------------------------------------------------------------------------- void MainWindow::SetDefaultSize() { - const QString defSize = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomSize(), - *pattern->GetPatternUnit(), Unit::Cm))); + const QString defSize = QString().setNum(doc->GetDefCustomSize()); int index = gradationSizes->findText(defSize); if (index != -1) { @@ -2731,11 +2726,8 @@ void MainWindow::SetDefaultSize() { gradationSizes->setCurrentIndex(index); } - else - { - pattern->SetSize(gradationSizes->currentText().toInt()); - } } + pattern->SetSize(gradationSizes->currentText().toInt()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index df67b2774..dc9aab7fc 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2547,7 +2547,16 @@ void VPattern::SetDefCustom(bool value) QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - SetAttribute(domElement, AttrCustom, value); + if (value == false) + { + domElement.removeAttribute(AttrDefHeight); + SetDefCustomHeight(0); + SetDefCustomSize(0); + } + else + { + SetAttribute(domElement, AttrCustom, value); + } modified = true; } else diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 3bf856682..dcdf98303 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -654,24 +654,48 @@ void VAbstractPattern::SetGradationHeights(const QMap &options) { case 0: // TagHeights SetAttribute(domElement, AttrAll, options.value(GHeights::ALL)); - SetAttribute(domElement, AttrH92, options.value(GHeights::H92)); - SetAttribute(domElement, AttrH98, options.value(GHeights::H98)); - SetAttribute(domElement, AttrH104, options.value(GHeights::H104)); - SetAttribute(domElement, AttrH110, options.value(GHeights::H110)); - SetAttribute(domElement, AttrH116, options.value(GHeights::H116)); - SetAttribute(domElement, AttrH122, options.value(GHeights::H122)); - SetAttribute(domElement, AttrH128, options.value(GHeights::H128)); - SetAttribute(domElement, AttrH134, options.value(GHeights::H134)); - SetAttribute(domElement, AttrH140, options.value(GHeights::H140)); - SetAttribute(domElement, AttrH146, options.value(GHeights::H146)); - SetAttribute(domElement, AttrH152, options.value(GHeights::H152)); - SetAttribute(domElement, AttrH158, options.value(GHeights::H158)); - SetAttribute(domElement, AttrH164, options.value(GHeights::H164)); - SetAttribute(domElement, AttrH170, options.value(GHeights::H170)); - SetAttribute(domElement, AttrH176, options.value(GHeights::H176)); - SetAttribute(domElement, AttrH182, options.value(GHeights::H182)); - SetAttribute(domElement, AttrH188, options.value(GHeights::H188)); - SetAttribute(domElement, AttrH194, options.value(GHeights::H194)); + if (options.value(GHeights::ALL)) + { + domElement.removeAttribute(AttrH92); + domElement.removeAttribute(AttrH98); + domElement.removeAttribute(AttrH104); + domElement.removeAttribute(AttrH110); + domElement.removeAttribute(AttrH116); + domElement.removeAttribute(AttrH122); + domElement.removeAttribute(AttrH128); + domElement.removeAttribute(AttrH134); + domElement.removeAttribute(AttrH140); + domElement.removeAttribute(AttrH146); + domElement.removeAttribute(AttrH152); + domElement.removeAttribute(AttrH158); + domElement.removeAttribute(AttrH164); + domElement.removeAttribute(AttrH170); + domElement.removeAttribute(AttrH176); + domElement.removeAttribute(AttrH182); + domElement.removeAttribute(AttrH188); + domElement.removeAttribute(AttrH194); + } + else + { + SetAttribute(domElement, AttrH92, options.value(GHeights::H92)); + SetAttribute(domElement, AttrH98, options.value(GHeights::H98)); + SetAttribute(domElement, AttrH104, options.value(GHeights::H104)); + SetAttribute(domElement, AttrH110, options.value(GHeights::H110)); + SetAttribute(domElement, AttrH116, options.value(GHeights::H116)); + SetAttribute(domElement, AttrH122, options.value(GHeights::H122)); + SetAttribute(domElement, AttrH128, options.value(GHeights::H128)); + SetAttribute(domElement, AttrH134, options.value(GHeights::H134)); + SetAttribute(domElement, AttrH140, options.value(GHeights::H140)); + SetAttribute(domElement, AttrH146, options.value(GHeights::H146)); + SetAttribute(domElement, AttrH152, options.value(GHeights::H152)); + SetAttribute(domElement, AttrH158, options.value(GHeights::H158)); + SetAttribute(domElement, AttrH164, options.value(GHeights::H164)); + SetAttribute(domElement, AttrH170, options.value(GHeights::H170)); + SetAttribute(domElement, AttrH176, options.value(GHeights::H176)); + SetAttribute(domElement, AttrH182, options.value(GHeights::H182)); + SetAttribute(domElement, AttrH188, options.value(GHeights::H188)); + SetAttribute(domElement, AttrH194, options.value(GHeights::H194)); + } modified = true; emit patternChanged(false); @@ -798,24 +822,48 @@ void VAbstractPattern::SetGradationSizes(const QMap &options) break; case 1: // TagSizes SetAttribute(domElement, AttrAll, options.value(GSizes::ALL)); - SetAttribute(domElement, AttrS22, options.value(GSizes::S22)); - SetAttribute(domElement, AttrS24, options.value(GSizes::S24)); - SetAttribute(domElement, AttrS26, options.value(GSizes::S26)); - SetAttribute(domElement, AttrS28, options.value(GSizes::S28)); - SetAttribute(domElement, AttrS30, options.value(GSizes::S30)); - SetAttribute(domElement, AttrS32, options.value(GSizes::S32)); - SetAttribute(domElement, AttrS34, options.value(GSizes::S34)); - SetAttribute(domElement, AttrS36, options.value(GSizes::S36)); - SetAttribute(domElement, AttrS38, options.value(GSizes::S38)); - SetAttribute(domElement, AttrS40, options.value(GSizes::S40)); - SetAttribute(domElement, AttrS42, options.value(GSizes::S42)); - SetAttribute(domElement, AttrS44, options.value(GSizes::S44)); - SetAttribute(domElement, AttrS46, options.value(GSizes::S46)); - SetAttribute(domElement, AttrS48, options.value(GSizes::S48)); - SetAttribute(domElement, AttrS50, options.value(GSizes::S50)); - SetAttribute(domElement, AttrS52, options.value(GSizes::S52)); - SetAttribute(domElement, AttrS54, options.value(GSizes::S54)); - SetAttribute(domElement, AttrS56, options.value(GSizes::S56)); + if (options.value(GSizes::ALL)) + { + domElement.removeAttribute(AttrS22); + domElement.removeAttribute(AttrS24); + domElement.removeAttribute(AttrS26); + domElement.removeAttribute(AttrS28); + domElement.removeAttribute(AttrS30); + domElement.removeAttribute(AttrS32); + domElement.removeAttribute(AttrS34); + domElement.removeAttribute(AttrS36); + domElement.removeAttribute(AttrS38); + domElement.removeAttribute(AttrS40); + domElement.removeAttribute(AttrS42); + domElement.removeAttribute(AttrS44); + domElement.removeAttribute(AttrS46); + domElement.removeAttribute(AttrS48); + domElement.removeAttribute(AttrS50); + domElement.removeAttribute(AttrS52); + domElement.removeAttribute(AttrS54); + domElement.removeAttribute(AttrS56); + } + else + { + SetAttribute(domElement, AttrS22, options.value(GSizes::S22)); + SetAttribute(domElement, AttrS24, options.value(GSizes::S24)); + SetAttribute(domElement, AttrS26, options.value(GSizes::S26)); + SetAttribute(domElement, AttrS28, options.value(GSizes::S28)); + SetAttribute(domElement, AttrS30, options.value(GSizes::S30)); + SetAttribute(domElement, AttrS32, options.value(GSizes::S32)); + SetAttribute(domElement, AttrS34, options.value(GSizes::S34)); + SetAttribute(domElement, AttrS36, options.value(GSizes::S36)); + SetAttribute(domElement, AttrS38, options.value(GSizes::S38)); + SetAttribute(domElement, AttrS40, options.value(GSizes::S40)); + SetAttribute(domElement, AttrS42, options.value(GSizes::S42)); + SetAttribute(domElement, AttrS44, options.value(GSizes::S44)); + SetAttribute(domElement, AttrS46, options.value(GSizes::S46)); + SetAttribute(domElement, AttrS48, options.value(GSizes::S48)); + SetAttribute(domElement, AttrS50, options.value(GSizes::S50)); + SetAttribute(domElement, AttrS52, options.value(GSizes::S52)); + SetAttribute(domElement, AttrS54, options.value(GSizes::S54)); + SetAttribute(domElement, AttrS56, options.value(GSizes::S56)); + } modified = true; emit patternChanged(false); @@ -973,8 +1021,14 @@ void VAbstractPattern::CheckTagExists(const QString &tag) case 4: //TagGradation { QDomElement gradation = createElement(TagGradation); - gradation.appendChild(createElement(TagHeights)); - gradation.appendChild(createElement(TagSizes)); + + QDomElement heights = createElement(TagHeights); + heights.setAttribute(AttrAll, QLatin1Literal("true")); + gradation.appendChild(heights); + + QDomElement sizes = createElement(TagSizes); + sizes.setAttribute(AttrAll, QLatin1Literal("true")); + gradation.appendChild(sizes); for (int i = tags.indexOf(tag)-1; i >= 0; --i) {