diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index f3205ad68..0202e62f8 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -30,16 +30,18 @@ #include "ui_dialogpatternproperties.h" #include #include "../xml/vpattern.h" +#include "../vpatterndb/vcontainer.h" #include "../core/vapplication.h" #define MAX_HEIGHTS 18 #define MAX_SIZES 18 //--------------------------------------------------------------------------------------------------------------------- -DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) : - QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), heightsChecked(MAX_HEIGHTS), +DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent) : + QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), pattern(pattern), heightsChecked(MAX_HEIGHTS), sizesChecked(MAX_SIZES), heights (QMap()), sizes(QMap()), - data(QMap()), descriptionChanged(false), gradationChanged(false), isInitialized(false) + data(QMap()), descriptionChanged(false), gradationChanged(false), defaultChanged(false), + isInitialized(false) { ui->setupUi(this); @@ -69,7 +71,7 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) connect(bCansel, &QPushButton::clicked, this, &DialogPatternProperties::close); ui->tabWidget->setCurrentIndex(0); - if (qApp->patternType() == MeasurementsType::Individual) + if (qApp->patternType() != MeasurementsType::Standard) { ui->tabWidget->setTabEnabled(1, false); } @@ -83,7 +85,30 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) SetOptions(heights); SetOptions(sizes); - gradationChanged = false;//Set to default value after initialization + InitComboBox(ui->comboBoxHeight, heights); + InitComboBox(ui->comboBoxSize, sizes); + + const QString height = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomHeight(), + *pattern->GetPatternUnit(), Unit::Cm))); + SetDefaultHeight(height); + + const QString size = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomSize(), + *pattern->GetPatternUnit(), Unit::Cm))); + SetDefaultSize(size); + + connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, &DialogPatternProperties::ToggleComboBox); + connect(ui->radioButtonDefFromP, &QRadioButton::toggled, this, &DialogPatternProperties::DefValueChanged); + + ui->radioButtonDefFromP->setChecked(doc->IsDefCustom()); + + connect(ui->comboBoxHeight, static_cast(&QComboBox::currentIndexChanged), this, + &DialogPatternProperties::DefValueChanged); + connect(ui->comboBoxSize, static_cast(&QComboBox::currentIndexChanged), this, + &DialogPatternProperties::DefValueChanged); + + //Initialization change value. Set to default value after initialization + gradationChanged = false; + defaultChanged = false; } //--------------------------------------------------------------------------------------------------------------------- @@ -100,10 +125,14 @@ void DialogPatternProperties::Apply() case 0: SaveDescription(); descriptionChanged = false; + emit doc->patternChanged(false); break; case 1: SaveGradation(); gradationChanged = false; + SaveDefValues(); + defaultChanged = false; + emit doc->patternChanged(false); break; default: break; @@ -113,6 +142,11 @@ void DialogPatternProperties::Apply() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::Ok() { + if (descriptionChanged || gradationChanged || defaultChanged) + { + emit doc->patternChanged(false); + } + if (descriptionChanged) { SaveDescription(); @@ -125,6 +159,12 @@ void DialogPatternProperties::Ok() gradationChanged = false; } + if (defaultChanged) + { + SaveDefValues(); + defaultChanged = false; + } + close(); } @@ -204,6 +244,8 @@ void DialogPatternProperties::CheckStateHeight(int state) heights.insert(static_cast(data.value(box)), box->isChecked()); } + UpdateDefHeight(); + CheckApplyOk(); gradationChanged = true; } @@ -244,6 +286,8 @@ void DialogPatternProperties::CheckStateSize(int state) sizes.insert(static_cast(data.value(box)), box->isChecked()); } + UpdateDefSize(); + CheckApplyOk(); gradationChanged = true; } @@ -276,6 +320,19 @@ void DialogPatternProperties::showEvent(QShowEvent *event) isInitialized = true;//first show windows are held } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::ToggleComboBox() +{ + ui->comboBoxHeight->setEnabled(ui->radioButtonDefFromP->isChecked()); + ui->comboBoxSize->setEnabled(ui->radioButtonDefFromP->isChecked()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::DefValueChanged() +{ + defaultChanged = true; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SetHeightsChecked(bool enabled) { @@ -396,6 +453,86 @@ void DialogPatternProperties::SaveGradation() emit UpdateGradation(); } +//--------------------------------------------------------------------------------------------------------------------- +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); + } + defaultChanged = false; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SetDefaultHeight(const QString &def) +{ + int index = ui->comboBoxHeight->findText(def); + if (index != -1) + { + ui->comboBoxHeight->setCurrentIndex(index); + defaultChanged = true; + } + else + { + const int height = static_cast(UnitConvertor(pattern->height(), *pattern->GetPatternUnit(), Unit::Cm)); + index = ui->comboBoxHeight->findText(QString().setNum(height)); + if (index != -1) + { + ui->comboBoxHeight->setCurrentIndex(index); + defaultChanged = true; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SetDefaultSize(const QString &def) +{ + int index = ui->comboBoxSize->findText(def); + if (index != -1) + { + ui->comboBoxSize->setCurrentIndex(index); + defaultChanged = true; + } + else + { + const int size = static_cast(UnitConvertor(pattern->size(), *pattern->GetPatternUnit(), Unit::Cm)); + index = ui->comboBoxSize->findText(QString().setNum(size)); + if (index != -1) + { + ui->comboBoxSize->setCurrentIndex(index); + defaultChanged = true; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::UpdateDefHeight() +{ + const QString def = ui->comboBoxHeight->currentText(); + InitComboBox(ui->comboBoxHeight, heights); + SetDefaultHeight(def); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::UpdateDefSize() +{ + const QString def = ui->comboBoxSize->currentText(); + InitComboBox(ui->comboBoxSize, sizes); + SetDefaultSize(def); +} + //--------------------------------------------------------------------------------------------------------------------- template void DialogPatternProperties::Init(QCheckBox *check, int val, Func slot) @@ -425,3 +562,22 @@ void DialogPatternProperties::SetOptions(const QMap &option) } } } + +//--------------------------------------------------------------------------------------------------------------------- +template +void DialogPatternProperties::InitComboBox(QComboBox *box, const QMap &option) +{ + SCASSERT(box != nullptr); + + box->clear(); + + QMapIterator i(option); + while (i.hasNext()) + { + i.next(); + if (i.value() && i.key() != GVal::ALL) + { + box->addItem(QString().setNum(static_cast(i.key()))); + } + } +} diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 9baa9b782..76a3a020e 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -34,6 +34,7 @@ #include class VPattern; +class VContainer; class QCheckBox; namespace Ui @@ -45,7 +46,7 @@ class DialogPatternProperties : public QDialog { Q_OBJECT public: - explicit DialogPatternProperties(VPattern *doc, QWidget *parent = nullptr); + explicit DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent = nullptr); virtual ~DialogPatternProperties() Q_DECL_OVERRIDE; signals: void UpdateGradation(); @@ -58,10 +59,14 @@ public slots: void DescEdited(); protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; +private slots: + void ToggleComboBox(); + void DefValueChanged(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; VPattern *doc; + VContainer *pattern; char heightsChecked; char sizesChecked; QMap heights; @@ -69,6 +74,7 @@ private: QMap data; bool descriptionChanged; bool gradationChanged; + bool defaultChanged; bool isInitialized; void SetHeightsChecked(bool enabled); @@ -79,9 +85,18 @@ private: void Init(QCheckBox *check, int val, Func slot); template void SetOptions(const QMap &option); + template + void InitComboBox(QComboBox *box, const QMap &option); void CheckApplyOk(); void SaveDescription(); void SaveGradation(); + void SaveDefValues(); + + void SetDefaultHeight(const QString &def); + void SetDefaultSize(const QString &def); + + void UpdateDefHeight(); + void UpdateDefSize(); }; #endif // DIALOGPATTERNPROPERTIES_H diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index 88dbf2060..13e78abfe 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -7,7 +7,7 @@ 0 0 657 - 562 + 532 @@ -21,7 +21,7 @@ - 0 + 1 @@ -38,8 +38,7 @@ - - + @@ -82,6 +81,85 @@ Heights and Sizes + + + + Default height and size + + + + + + From standard measurements + + + true + + + buttonGroup + + + + + + + + + Custom + + + false + + + buttonGroup + + + + + + + + + + + Height: + + + + + + + false + + + + + + + + + + + Size: + + + + + + + false + + + + + + + + + + + + @@ -884,4 +962,7 @@ + + + diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index b6887ba6e..53b25e8b4 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1054,7 +1054,7 @@ void MainWindow::OpenRecentFile() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::PatternProperties() { - DialogPatternProperties proper(doc, this); + DialogPatternProperties proper(doc, pattern, this); connect(&proper, &DialogPatternProperties::UpdateGradation, this, &MainWindow::UpdateGradation); proper.exec(); } @@ -1387,17 +1387,7 @@ void MainWindow::ToolBarOption() gradationHeights = SetGradationList(gradationHeightsLabel, listHeights); // set default height - { - const qint32 index = gradationHeights->findText(QString("%1").arg(static_cast(pattern->height()))); - if (index != -1) - { - gradationHeights->setCurrentIndex(index); - } - else - { - pattern->SetHeight(gradationHeights->currentText().toInt()); - } - } + SetDefaultHeight(); connect(gradationHeights.data(), static_cast(&QComboBox::currentIndexChanged), @@ -1407,17 +1397,7 @@ void MainWindow::ToolBarOption() gradationSizes = SetGradationList(gradationSizesLabel, listSizes); // set default size - { - const qint32 index = gradationSizes->findText(QString("%1").arg(static_cast(pattern->size()))); - if (index != -1) - { - gradationSizes->setCurrentIndex(index); - } - else - { - pattern->SetSize(gradationSizes->currentText().toInt()); - } - } + SetDefaultSize(); connect(gradationSizes.data(), static_cast(&QComboBox::currentIndexChanged), @@ -2653,6 +2633,56 @@ void MainWindow::ChangedHeight(const QString &text) } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::SetDefaultHeight() +{ + const QString defHeight = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomHeight(), + *pattern->GetPatternUnit(), Unit::Cm))); + int index = gradationHeights->findText(defHeight); + if (index != -1) + { + gradationHeights->setCurrentIndex(index); + } + else + { + const int height = static_cast(UnitConvertor(pattern->height(), *pattern->GetPatternUnit(), Unit::Cm)); + index = gradationHeights->findText(QString().setNum(height)); + if (index != -1) + { + gradationHeights->setCurrentIndex(index); + } + else + { + pattern->SetHeight(gradationHeights->currentText().toInt()); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::SetDefaultSize() +{ + const QString defSize = QString().setNum(static_cast(UnitConvertor(doc->GetDefCustomSize(), + *pattern->GetPatternUnit(), Unit::Cm))); + int index = gradationSizes->findText(defSize); + if (index != -1) + { + gradationSizes->setCurrentIndex(index); + } + else + { + const int size = static_cast(UnitConvertor(pattern->size(), *pattern->GetPatternUnit(), Unit::Cm)); + index = gradationSizes->findText(QString().setNum(size)); + if (index != -1) + { + gradationSizes->setCurrentIndex(index); + } + else + { + pattern->SetSize(gradationSizes->currentText().toInt()); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ActionTable show table with variables. diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index dcdd60105..c0926bb6f 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -240,6 +240,9 @@ private: VToolOptionsPropertyBrowser *toolOptions; std::shared_ptr> lock; + void SetDefaultHeight(); + void SetDefaultSize(); + void ToolBarOption(); void ToolBarStages(); void ToolBarDraws(); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 2ffd7e561..db80262bd 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2444,6 +2444,152 @@ QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedNa return QString(); } +//--------------------------------------------------------------------------------------------------------------------- +bool VPattern::IsDefCustom() const +{ + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + return false; + } + + const QDomNode domNode = tags.at(0); + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + return GetParametrBool(domElement, AttrCustom, QStringLiteral("false")); + } + else + { + return false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetDefCustom(bool value) +{ + CheckTagExists(TagGradation); + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + qDebug()<<"Can't save attribute "<(GetParametrUInt(domElement, AttrDefHeight, QStringLiteral("0"))); + } + else + { + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetDefCustomHeight(int value) +{ + CheckTagExists(TagGradation); + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + qDebug()<<"Can't save attribute "<(GetParametrUInt(domElement, AttrDefSize, QStringLiteral("0"))); + } + else + { + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetDefCustomSize(int value) +{ + CheckTagExists(TagGradation); + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + qDebug()<<"Can't save attribute "<schema/pattern/v0.1.4.xsd schema/pattern/v0.2.0.xsd schema/pattern/v0.2.1.xsd + schema/pattern/v0.2.2.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.2.2.xsd b/src/libs/ifc/schema/pattern/v0.2.2.xsd new file mode 100644 index 000000000..26c88146f --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.2.2.xsd @@ -0,0 +1,332 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 675e9d3ea..fb3b64188 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -96,6 +96,10 @@ const QString VAbstractPattern::AttrS52 = QStringLiteral("s52"); const QString VAbstractPattern::AttrS54 = QStringLiteral("s54"); const QString VAbstractPattern::AttrS56 = QStringLiteral("s56"); +const QString VAbstractPattern::AttrCustom = QStringLiteral("custom"); +const QString VAbstractPattern::AttrDefHeight = QStringLiteral("defHeight"); +const QString VAbstractPattern::AttrDefSize = QStringLiteral("defSize"); + const QString VAbstractPattern::IncrementName = QStringLiteral("name"); const QString VAbstractPattern::IncrementFormula = QStringLiteral("formula"); const QString VAbstractPattern::IncrementDescription = QStringLiteral("description"); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index d9cf1eb17..947705e6e 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -167,6 +167,10 @@ public: static const QString AttrS54; static const QString AttrS56; + static const QString AttrCustom; + static const QString AttrDefHeight; + static const QString AttrDefSize; + static const QString IncrementName; static const QString IncrementFormula; static const QString IncrementDescription; diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index dce3be75f..87b4cbcca 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -455,7 +455,7 @@ void VDomDocument::ValidateXML(const QString &schema, const QString &fileName) { pattern.close(); fileSchema.close(); - const QString errorMsg(tr("Could not load schema file.").arg(fileSchema.fileName())); + const QString errorMsg(tr("Could not load schema file '%1'.").arg(fileSchema.fileName())); throw VException(errorMsg); } qCDebug(vXML, "Schema loaded."); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 180df4994..2676604b5 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -43,8 +43,8 @@ */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.1"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.1.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.2"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.2.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -102,6 +102,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000200): return QStringLiteral("://schema/pattern/v0.2.0.xsd"); case (0x000201): + return QStringLiteral("://schema/pattern/v0.2.1.xsd"); + case (0x000202): return CurrentSchema; default: { @@ -161,6 +163,13 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH } case (0x000201): + { + ToV0_2_2(); + const QString schema = XSDSchema(0x000202); + ValidateXML(schema, fileName); + V_FALLTHROUGH + } + case (0x000202): break; default: break; @@ -232,6 +241,13 @@ void VPatternConverter::ToV0_2_1() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_2_2() +{ + SetVersion(QStringLiteral("0.2.2")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index b62ef6b5b..7bdb2e9a7 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -61,6 +61,7 @@ private: void ToV0_1_4(); void ToV0_2_0(); void ToV0_2_1(); + void ToV0_2_2(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/test/ValentinaTest/tst_valentina/glimited_vst.val b/src/test/ValentinaTest/tst_valentina/glimited_vst.val index e86a62aa6..944b9db17 100644 --- a/src/test/ValentinaTest/tst_valentina/glimited_vst.val +++ b/src/test/ValentinaTest/tst_valentina/glimited_vst.val @@ -1,12 +1,12 @@ - 0.2.1 + 0.2.2 cm - +