diff --git a/ChangeLog.txt b/ChangeLog.txt index cef80b2bc..2994b7ce2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -14,6 +14,7 @@ - Fix updating dimension labels in Valentina app. - Fix menu on Mac OS X. - Add function's argument template with name in the Formula Wizard. +- Unit type for increments. # Valentina 0.7.51 April 18, 2022 - Z value change for a layout piece. diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index addd3378e..baebe1145 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -4400,7 +4400,7 @@ void TMainWindow::InitMeasurementUnits() units = tr("Centimeters"); break; default: - units = ""; + units = QStringLiteral(""); break; } diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index 920008a73..7afab2d39 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -48,6 +48,11 @@ #define DIALOG_MAX_FORMULA_HEIGHT 64 +namespace +{ +enum class IncrUnits : qint8 {Pattern, Degrees}; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogIncrements create dialog @@ -89,6 +94,20 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par qCDebug(vDialog, "Showing variables."); ShowUnits(); + InitIncrementUnits(ui->comboBoxIncrementUnits); + InitIncrementUnits(ui->comboBoxPreviewCalculationUnits); + + ui->comboBoxIncrementUnits->blockSignals(true); + ui->comboBoxIncrementUnits->setCurrentIndex(-1); + ui->comboBoxIncrementUnits->blockSignals(true); + + ui->comboBoxPreviewCalculationUnits->blockSignals(true); + ui->comboBoxPreviewCalculationUnits->setCurrentIndex(-1); + ui->comboBoxPreviewCalculationUnits->blockSignals(true); + + connect(ui->comboBoxIncrementUnits, QOverload::of(&QComboBox::currentIndexChanged), this, + &DialogIncrements::SaveIncrUnits); + FillIncrements(); FillPreviewCalculations(); FillLengthsLines(); @@ -101,7 +120,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); ui->tabWidget->setCurrentIndex(0); - auto validator = new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^$|")+NameRegExp()), this); + auto *validator = new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^$|")+NameRegExp()), this); ui->lineEditName->setValidator(validator); ui->lineEditNamePC->setValidator(validator); @@ -330,51 +349,57 @@ QString DialogIncrements::ClearIncrementName(const QString &name) const } //--------------------------------------------------------------------------------------------------------------------- -bool DialogIncrements::EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label) +auto DialogIncrements::EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label, + bool special) -> bool { - const QString postfix = - UnitsToStr(VAbstractValApplication::VApp()->patternUnits());//Show unit in dialog lable (cm, mm or inch) + QString postfix; + if (special) + { + postfix = degreeSymbol; + } + else + { + postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits());//Show unit in dialog lable (cm, mm or inch) + } if (formula.isEmpty()) { label->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); label->setToolTip(tr("Empty field")); return false; } - else + + try { - try + QString f; + // Replace line return character with spaces for calc if exist + if (fromUser) { - QString f; - // Replace line return character with spaces for calc if exist - if (fromUser) - { - f = VAbstractApplication::VApp()->TrVars() - ->FormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); - } - else - { - f = formula; - } - QScopedPointer cal(new Calculator()); - const qreal result = cal->EvalFormula(data->DataVariables(), f); - - if (qIsInf(result) || qIsNaN(result)) - { - label->setText(tr("Error") + " (" + postfix + ")."); - label->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your calculations.")); - return false; - } - - label->setText(VAbstractApplication::VApp()->LocaleToString(result) + QChar(QChar::Space) + postfix); - label->setToolTip(tr("Value")); - return true; + f = VAbstractApplication::VApp()->TrVars() + ->FormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); } - catch (qmu::QmuParserError &e) + else { - label->setText(tr("Error") + " (" + postfix + "). " + tr("Parser error: %1").arg(e.GetMsg())); - label->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); + f = formula; + } + QScopedPointer cal(new Calculator()); + const qreal result = cal->EvalFormula(data->DataVariables(), f); + + if (qIsInf(result) || qIsNaN(result)) + { + label->setText(tr("Error") + " (" + postfix + ")."); + label->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your calculations.")); return false; } + + label->setText(VAbstractApplication::VApp()->LocaleToString(result) + QChar(QChar::Space) + postfix); + label->setToolTip(tr("Value")); + return true; + } + catch (qmu::QmuParserError &e) + { + label->setText(tr("Error") + " (" + postfix + "). " + tr("Parser error: %1").arg(e.GetMsg())); + label->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); + return false; } } @@ -499,6 +524,10 @@ void DialogIncrements::EnableDetails(QTableWidget *table, bool enabled) ui->lineEditName->clear(); ui->lineEditName->blockSignals(false); + ui->comboBoxIncrementUnits->blockSignals(true); + ui->comboBoxIncrementUnits->setCurrentIndex(-1); + ui->comboBoxIncrementUnits->blockSignals(false); + ui->plainTextEditDescription->blockSignals(true); ui->plainTextEditDescription->clear(); ui->plainTextEditDescription->blockSignals(false); @@ -517,6 +546,10 @@ void DialogIncrements::EnableDetails(QTableWidget *table, bool enabled) ui->lineEditNamePC->clear(); ui->lineEditNamePC->blockSignals(false); + ui->comboBoxPreviewCalculationUnits->blockSignals(true); + ui->comboBoxPreviewCalculationUnits->setCurrentIndex(-1); + ui->comboBoxPreviewCalculationUnits->blockSignals(false); + ui->plainTextEditDescriptionPC->blockSignals(true); ui->plainTextEditDescriptionPC->clear(); ui->plainTextEditDescriptionPC->blockSignals(false); @@ -536,6 +569,7 @@ void DialogIncrements::EnableDetails(QTableWidget *table, bool enabled) ui->pushButtonGrow->setEnabled(enabled); ui->toolButtonExpr->setEnabled(enabled); ui->lineEditName->setEnabled(enabled); + ui->comboBoxIncrementUnits->setEnabled(enabled); ui->plainTextEditDescription->setEnabled(enabled); ui->plainTextEditFormula->setEnabled(enabled); } @@ -544,6 +578,7 @@ void DialogIncrements::EnableDetails(QTableWidget *table, bool enabled) ui->pushButtonGrowPC->setEnabled(enabled); ui->toolButtonExprPC->setEnabled(enabled); ui->lineEditNamePC->setEnabled(enabled); + ui->comboBoxPreviewCalculationUnits->setEnabled(enabled); ui->plainTextEditDescriptionPC->setEnabled(enabled); ui->plainTextEditFormulaPC->setEnabled(enabled); } @@ -563,6 +598,8 @@ void DialogIncrements::EnableDetails(QTableWidget *table, bool enabled) ui->plainTextEditFormula->setVisible(not isSeparator); ui->pushButtonGrow->setVisible(not isSeparator); ui->toolButtonExpr->setVisible(not isSeparator); + ui->labelIncrementUnits->setVisible(not isSeparator); + ui->comboBoxIncrementUnits->setVisible(not isSeparator); } else if (table == ui->tableWidgetPC) { @@ -572,6 +609,8 @@ void DialogIncrements::EnableDetails(QTableWidget *table, bool enabled) ui->plainTextEditFormulaPC->setVisible(not isSeparator); ui->pushButtonGrowPC->setVisible(not isSeparator); ui->toolButtonExprPC->setVisible(not isSeparator); + ui->labelPreviewCalculationUnits->setVisible(not isSeparator); + ui->comboBoxPreviewCalculationUnits->setVisible(not isSeparator); } } } @@ -652,6 +691,7 @@ void DialogIncrements::ShowTableIncrementDetails(QTableWidget *table) QPlainTextEdit *plainTextEditDescription = nullptr; QPlainTextEdit *plainTextEditFormula = nullptr; QLabel *labelCalculatedValue = nullptr; + QComboBox *comboboxUnits = nullptr; if (table == ui->tableWidgetIncrement) { @@ -659,6 +699,7 @@ void DialogIncrements::ShowTableIncrementDetails(QTableWidget *table) plainTextEditDescription = ui->plainTextEditDescription; plainTextEditFormula = ui->plainTextEditFormula; labelCalculatedValue = ui->labelCalculatedValue; + comboboxUnits = ui->comboBoxIncrementUnits; } else if (table == ui->tableWidgetPC) { @@ -666,6 +707,7 @@ void DialogIncrements::ShowTableIncrementDetails(QTableWidget *table) plainTextEditDescription = ui->plainTextEditDescriptionPC; plainTextEditFormula = ui->plainTextEditFormulaPC; labelCalculatedValue = ui->labelCalculatedValuePC; + comboboxUnits = ui->comboBoxPreviewCalculationUnits; } else { @@ -695,11 +737,16 @@ void DialogIncrements::ShowTableIncrementDetails(QTableWidget *table) lineEditName->setText(ClearIncrementName(incr->GetName())); lineEditName->blockSignals(false); + comboboxUnits->blockSignals(true); + comboboxUnits->setCurrentIndex(comboboxUnits->findData( + static_cast(incr->IsSpecialUnits() ? IncrUnits::Degrees : IncrUnits::Pattern))); + comboboxUnits->blockSignals(false); + plainTextEditDescription->blockSignals(true); plainTextEditDescription->setPlainText(incr->GetDescription()); plainTextEditDescription->blockSignals(false); - EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), labelCalculatedValue); + EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), labelCalculatedValue, incr->IsSpecialUnits()); plainTextEditFormula->blockSignals(true); QString formula = @@ -1124,6 +1171,49 @@ void DialogIncrements::UpdateSearchControlsTooltips() UpdateToolTip(ui->toolButtonFindNextPC); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::InitIncrementUnits(QComboBox *combo) +{ + SCASSERT(combo != nullptr) + + combo->blockSignals(true); + + int current = -1; + if (combo->currentIndex() != -1) + { + current = combo->currentData().toInt(); + } + + QString units; + switch (VAbstractValApplication::VApp()->patternUnits()) + { + case Unit::Mm: + units = tr("Millimeters"); + break; + case Unit::Inch: + units = tr("Inches"); + break; + case Unit::Cm: + units = tr("Centimeters"); + break; + default: + units = QStringLiteral(""); + break; + } + + combo->clear(); + combo->addItem(units, QVariant(static_cast(IncrUnits::Pattern))); + combo->addItem(tr("Degrees"), QVariant(static_cast(IncrUnits::Degrees))); + + int i = combo->findData(current); + if (i != -1) + { + combo->setCurrentIndex(i); + } + + combo->blockSignals(false); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update information in tables form file @@ -1222,9 +1312,13 @@ void DialogIncrements::FillIncrementsTable(QTableWidget *table, if (incr->GetType() == VarType::Increment) { AddCell(table, incr->GetName(), currentRow, 0, Qt::AlignVCenter); // name - AddCell(table, VAbstractApplication::VApp()-> - LocaleToString(*incr->GetValue()), currentRow, 1, Qt::AlignCenter, - incr->IsFormulaOk()); // calculated value + + QString calculatedValue = VAbstractApplication::VApp()->LocaleToString(*incr->GetValue()); + if (incr->IsSpecialUnits()) + { + calculatedValue = calculatedValue + degreeSymbol; + } + AddCell(table, calculatedValue, currentRow, 1, Qt::AlignCenter, incr->IsFormulaOk()); // calculated value QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), @@ -1270,7 +1364,7 @@ void DialogIncrements::AddSeparator() */ void DialogIncrements::RemoveIncrement() { - QToolButton *button = qobject_cast(sender()); + auto *button = qobject_cast(sender()); QTableWidget *table = nullptr; @@ -1469,10 +1563,50 @@ void DialogIncrements::SaveIncrName(const QString &text) table->blockSignals(false); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::SaveIncrUnits() +{ + auto *combo = qobject_cast(sender()); + + QTableWidget *table = nullptr; + + if (combo == ui->comboBoxIncrementUnits) + { + table = ui->tableWidgetIncrement; + } + else if (combo == ui->comboBoxPreviewCalculationUnits) + { + table = ui->tableWidgetPC; + } + else + { + return; + } + + const int row = table->currentRow(); + + if (row == -1) + { + return; + } + + const QTableWidgetItem *nameField = table->item(row, 0); + + const IncrUnits units = static_cast(combo->currentData().toInt()); + doc->SetIncrementSpecialUnits(nameField->text(), units == IncrUnits::Degrees); + LocalUpdateTree(); + + table->blockSignals(true); + table->selectRow(row); + table->blockSignals(false); + + ShowTableIncrementDetails(table); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogIncrements::SaveIncrDescription() { - QPlainTextEdit *textEdit = qobject_cast(sender()); + auto *textEdit = qobject_cast(sender()); QTableWidget *table = nullptr; @@ -1541,32 +1675,46 @@ void DialogIncrements::SaveIncrFormula() const QTableWidgetItem *nameField = table->item(row, 0); QString text = textEdit->toPlainText(); + QSharedPointer incr = data->GetVariable(nameField->text()); QTableWidgetItem *formulaField = table->item(row, 2); if (formulaField->text() == text) { QTableWidgetItem *result = table->item(row, 1); - //Show unit in dialog lable (cm, mm or inch) - const QString postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits()); - labelCalculatedValue->setText(result->text() + QChar(QChar::Space) +postfix); + if (incr->IsSpecialUnits()) + { + labelCalculatedValue->setText(result->text() + QChar(QChar::Space) + degreeSymbol); + } + else + { + //Show unit in dialog lable (cm, mm or inch) + const QString postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits()); + labelCalculatedValue->setText(result->text() + QChar(QChar::Space) +postfix); + } return; } if (text.isEmpty()) { - //Show unit in dialog lable (cm, mm or inch) - const QString postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits()); - labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); + if (incr->IsSpecialUnits()) + { + labelCalculatedValue->setText(tr("Error") + " (" + degreeSymbol + "). " + tr("Empty field.")); + } + else + { + //Show unit in dialog lable (cm, mm or inch) + const QString postfix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits()); + labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); + } return; } - QSharedPointer incr = data->GetVariable(nameField->text()); if (incr->GetIncrementType() == IncrementType::Separator) { return; } - if (not EvalIncrementFormula(text, true, incr->GetData(), labelCalculatedValue)) + if (not EvalIncrementFormula(text, true, incr->GetData(), labelCalculatedValue, incr->IsSpecialUnits())) { return; } diff --git a/src/app/valentina/dialogs/dialogincrements.h b/src/app/valentina/dialogs/dialogincrements.h index 418da6189..c830242a9 100644 --- a/src/app/valentina/dialogs/dialogincrements.h +++ b/src/app/valentina/dialogs/dialogincrements.h @@ -75,6 +75,7 @@ private slots: void MoveUp(); void MoveDown(); void SaveIncrName(const QString &text); + void SaveIncrUnits(); void SaveIncrDescription(); void SaveIncrFormula(); void DeployFormula(); @@ -136,7 +137,7 @@ private: QString GetCustomName() const; QString ClearIncrementName(const QString &name) const; - bool EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label); + bool EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label, bool special); void Controls(QTableWidget *table); void EnableDetails(QTableWidget *table, bool enabled); @@ -158,6 +159,7 @@ private: void SaveIncrementsSearchRequest(); void SavePreviewCalculationsSearchRequest(); void UpdateSearchControlsTooltips(); + void InitIncrementUnits(QComboBox *combo); }; #endif // DIALOGINCREMENTS_H diff --git a/src/app/valentina/dialogs/dialogincrements.ui b/src/app/valentina/dialogs/dialogincrements.ui index 0d67753d3..c7ab349c8 100644 --- a/src/app/valentina/dialogs/dialogincrements.ui +++ b/src/app/valentina/dialogs/dialogincrements.ui @@ -119,7 +119,6 @@ 14 - 75 false true @@ -152,7 +151,6 @@ 14 - 75 true @@ -187,7 +185,6 @@ 14 - 75 true @@ -219,7 +216,6 @@ 14 - 75 true @@ -508,27 +504,34 @@ + + + Units: + + + + Calculated value: - + - + Formula: - + @@ -624,14 +627,14 @@ - + Description: - + false @@ -650,7 +653,7 @@ - + @@ -677,6 +680,16 @@ + + + + false + + + false + + + @@ -761,7 +774,6 @@ 14 - 75 false true @@ -794,7 +806,6 @@ 14 - 75 true @@ -829,7 +840,6 @@ 14 - 75 true @@ -861,7 +871,6 @@ 14 - 75 true @@ -1149,28 +1158,28 @@ - + Calculated value: - + - + Formula: - + @@ -1266,14 +1275,14 @@ - + Description: - + false @@ -1292,7 +1301,7 @@ - + @@ -1319,6 +1328,20 @@ + + + + Units: + + + + + + + false + + + @@ -1585,7 +1608,7 @@ VPlainTextEdit QPlainTextEdit -
vplaintextedit.h
+
vplaintextedit.h
diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 11ed4caef..b894e03d3 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -4038,14 +4038,16 @@ void VPattern::ParseIncrementsElement(const QDomNode &node, const Document &pars strTypeIncrement)); const QString formula = (type == IncrementType::Separator) ? QChar('0') : GetParametrString(domElement, AttrFormula, QChar('0')); + const bool specialUnits = GetParametrBool(domElement, AttrSpecialUnits, falseStr); bool ok = false; const qreal value = EvalFormula(data, formula, &ok); - VIncrement *increment = new VIncrement(data, name, type); + auto *increment = new VIncrement(data, name, type); increment->SetIndex(static_cast(index++)); increment->SetFormula(value, formula, ok); increment->SetDescription(desc); + increment->SetSpecialUnits(specialUnits); increment->SetPreviewCalculation(node.toElement().tagName() == TagPreviewCalculations); data->AddUniqueVariable(increment); } @@ -4150,6 +4152,21 @@ void VPattern::SetIncrementDescription(const QString &name, const QString &text) } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetIncrementSpecialUnits(const QString &name, bool special) +{ + QDomElement node = FindIncrement(name); + if (not node.isNull()) + { + SetAttributeOrRemoveIf(node, AttrSpecialUnits, special, [](bool special) noexcept {return not special;}); + emit patternChanged(false); + } + else + { + qWarning() << tr("Can't find increment '%1'").arg(name); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPattern::ReplaceNameInFormula(QVector &expressions, const QString &name, const QString &newName) { diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 8e598eb2a..f51617030 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -93,6 +93,7 @@ public: void SetIncrementName(const QString &name, const QString &text); void SetIncrementFormula(const QString &name, const QString &text); void SetIncrementDescription(const QString &name, const QString &text); + void SetIncrementSpecialUnits(const QString &name, bool special); void ReplaceNameInFormula(QVector &expressions, const QString &name, const QString &newName); diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 6a33ff30f..df1ac87b4 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -66,6 +66,7 @@ schema/pattern/v0.8.12.xsd schema/pattern/v0.8.13.xsd schema/pattern/v0.9.0.xsd + schema/pattern/v0.9.1.xsd schema/multisize_measurements/v0.3.0.xsd schema/multisize_measurements/v0.4.0.xsd schema/multisize_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.9.1.xsd b/src/libs/ifc/schema/pattern/v0.9.1.xsd new file mode 100644 index 000000000..127de05a0 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.9.1.xsd @@ -0,0 +1,1166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 78c0c70fb..666d62063 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -150,8 +150,9 @@ const QString VAbstractPattern::AttrImageId = QStringLiteral("imageId" const QString VAbstractPattern::AttrContentType = QStringLiteral("contentType"); -const QString VAbstractPattern::AttrFormula = QStringLiteral("formula"); -const QString VAbstractPattern::AttrDescription = QStringLiteral("description"); +const QString VAbstractPattern::AttrFormula = QStringLiteral("formula"); +const QString VAbstractPattern::AttrDescription = QStringLiteral("description"); +const QString VAbstractPattern::AttrSpecialUnits = QStringLiteral("specialUnits"); const QString VAbstractPattern::NodeArc = QStringLiteral("NodeArc"); const QString VAbstractPattern::NodeElArc = QStringLiteral("NodeElArc"); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 59b9e37df..4f1b359b7 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -337,6 +337,7 @@ public: static const QString AttrFormula; static const QString AttrDescription; + static const QString AttrSpecialUnits; static const QString NodeArc; static const QString NodeElArc; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 881c43a54..f54801067 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -60,8 +60,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.4"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.9.0"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.9.0.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.9.1"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.9.1.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -265,7 +265,8 @@ auto VPatternConverter::XSDSchema(unsigned ver) const -> QString std::make_pair(FormatVersion(0, 8, 11), QStringLiteral("://schema/pattern/v0.8.11.xsd")), std::make_pair(FormatVersion(0, 8, 12), QStringLiteral("://schema/pattern/v0.8.12.xsd")), std::make_pair(FormatVersion(0, 8, 13), QStringLiteral("://schema/pattern/v0.8.13.xsd")), - std::make_pair(FormatVersion(0, 9, 0), CurrentSchema) + std::make_pair(FormatVersion(0, 9, 0), QStringLiteral("://schema/pattern/v0.9.0.xsd")), + std::make_pair(FormatVersion(0, 9, 1), CurrentSchema) }; if (schemas.contains(ver)) @@ -367,9 +368,12 @@ void VPatternConverter::ApplyPatches() case (FormatVersion(0, 8, 12)): case (FormatVersion(0, 8, 13)): ToV0_9_0(); - ValidateXML(CurrentSchema); Q_FALLTHROUGH(); case (FormatVersion(0, 9, 0)): + ToV0_9_1(); + ValidateXML(CurrentSchema); + Q_FALLTHROUGH(); + case (FormatVersion(0, 9, 1)): break; default: InvalidVersion(m_ver); @@ -387,7 +391,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FormatVersion(0, 9, 0), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FormatVersion(0, 9, 1), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -546,6 +550,17 @@ void VPatternConverter::ToV0_9_0() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_9_1() +{ + // TODO. Delete if minimal supported version is 0.9.1 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 9, 1), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.9.1")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 71476cb14..f29f9f631 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const unsigned PatternMinVer = FormatVersion(0, 1, 4); - static Q_DECL_CONSTEXPR const unsigned PatternMaxVer = FormatVersion(0, 9, 0); + static Q_DECL_CONSTEXPR const unsigned PatternMaxVer = FormatVersion(0, 9, 1); protected: void Save() override; @@ -85,6 +85,7 @@ private: void ToV0_6_2(); void ToV0_8_8(); void ToV0_9_0(); + void ToV0_9_1(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vpatterndb/variables/vincrement.cpp b/src/libs/vpatterndb/variables/vincrement.cpp index e68a3a7d9..1d3727009 100644 --- a/src/libs/vpatterndb/variables/vincrement.cpp +++ b/src/libs/vpatterndb/variables/vincrement.cpp @@ -149,3 +149,15 @@ void VIncrement::SetPreviewCalculation(bool value) { d->previewCalculation = value; } + +//--------------------------------------------------------------------------------------------------------------------- +bool VIncrement::IsSpecialUnits() const +{ + return d->specialUnits; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VIncrement::SetSpecialUnits(bool special) +{ + d->specialUnits = special; +} diff --git a/src/libs/vpatterndb/variables/vincrement.h b/src/libs/vpatterndb/variables/vincrement.h index 07ba0341b..44d88ac3a 100644 --- a/src/libs/vpatterndb/variables/vincrement.h +++ b/src/libs/vpatterndb/variables/vincrement.h @@ -71,6 +71,9 @@ public: bool IsPreviewCalculation() const; void SetPreviewCalculation(bool value); + bool IsSpecialUnits() const; + void SetSpecialUnits(bool special); + private: QSharedDataPointer d; }; diff --git a/src/libs/vpatterndb/variables/vincrement_p.h b/src/libs/vpatterndb/variables/vincrement_p.h index 71e9cf1d3..f91701594 100644 --- a/src/libs/vpatterndb/variables/vincrement_p.h +++ b/src/libs/vpatterndb/variables/vincrement_p.h @@ -70,7 +70,8 @@ public: formulaOk(incr.formulaOk), previewCalculation(incr.previewCalculation), data(incr.data), - incrType(incr.incrType) + incrType(incr.incrType), + specialUnits(incr.specialUnits) {} virtual ~VIncrementData(); @@ -82,6 +83,7 @@ public: bool previewCalculation{false}; QSharedPointer data; IncrementType incrType{IncrementType::Increment}; + bool specialUnits{false}; private: Q_DISABLE_ASSIGN(VIncrementData) diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp index f56855fad..8741e258f 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp @@ -197,17 +197,10 @@ void DialogEditWrongFormula::ValChanged(int row) const QSharedPointer stable = m_data->GetVariable(name); SetDescription(item->text(), *stable->GetValue(), stable->IsSpecialUnits(), stable->GetGuiText()); } - else if (ui->radioButtonIncrements->isChecked()) + else if (ui->radioButtonIncrements->isChecked() || ui->radioButtonPC->isChecked()) { const QSharedPointer incr = m_data->GetVariable(name); - const bool specialUnits = false; - SetDescription(item->text(), *incr->GetValue(), specialUnits, incr->GetDescription()); - } - else if (ui->radioButtonPC->isChecked()) - { - const QSharedPointer incr = m_data->GetVariable(name); - const bool specialUnits = false; - SetDescription(item->text(), *incr->GetValue(), specialUnits, incr->GetDescription()); + SetDescription(item->text(), *incr->GetValue(), incr->IsSpecialUnits(), incr->GetDescription()); } else if (ui->radioButtonLengthLine->isChecked()) {