diff --git a/ChangeLog.txt b/ChangeLog.txt index 8940bb288..671119a0c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -23,6 +23,7 @@ - [#924] Valentina produces wrong passmark for rollback case. - [#930] Valentina doesn't update translation for variables after dynamic language switch. - [#931] Variable translation for Greek and Chinese are broken. +- [#938] Dialog Seam Allowance doesn't block user from saving broken formula. # Version 0.6.1 October 23, 2018 - [#885] Regression. Broken support for multi size measurements. diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 20a42401d..c607a93e5 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -1030,13 +1030,29 @@ VPieceLabelData VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiec ppData.SetOnFold(GetParametrBool(domElement, AttrOnFold, falseStr)); ppData.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, QChar('0')), GetParametrDouble(domElement, AttrMy, QChar('0')))); - ppData.SetLabelWidth(GetParametrString(domElement, AttrWidth, QChar('1'))); - ppData.SetLabelHeight(GetParametrString(domElement, AttrHeight, QChar('1'))); ppData.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, QChar('0')))); ppData.SetRotation(GetParametrString(domElement, AttrRotation, QChar('0'))); - ppData.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); - ppData.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); - ppData.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); + + const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); + const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); + + if (topLeftPin != NULL_ID && bottomRightPin != NULL_ID && topLeftPin != bottomRightPin) + { + ppData.SetTopLeftPin(topLeftPin); + ppData.SetBottomRightPin(bottomRightPin); + ppData.SetCenterPin(NULL_ID); + ppData.SetLabelWidth(QChar('1')); + ppData.SetLabelHeight(QChar('1')); + } + else + { + ppData.SetTopLeftPin(NULL_ID); + ppData.SetBottomRightPin(NULL_ID); + ppData.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); + ppData.SetLabelWidth(GetParametrString(domElement, AttrWidth, QChar('1'))); + ppData.SetLabelHeight(GetParametrString(domElement, AttrHeight, QChar('1'))); + } + ppData.SetLabelTemplate(GetLabelTemplate(domElement)); return ppData; } @@ -1047,13 +1063,29 @@ VPatternLabelData VPattern::ParsePiecePatternInfo(const QDomElement &domElement, patternInfo.SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); patternInfo.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, QChar('0')), GetParametrDouble(domElement, AttrMy, QChar('0')))); - patternInfo.SetLabelWidth(GetParametrString(domElement, AttrWidth, QChar('1'))); - patternInfo.SetLabelHeight(GetParametrString(domElement, AttrHeight, QChar('1'))); patternInfo.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, QChar('0')))); patternInfo.SetRotation(GetParametrString(domElement, AttrRotation, QChar('0'))); - patternInfo.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); - patternInfo.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); - patternInfo.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); + + const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); + const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); + + if (topLeftPin != NULL_ID && bottomRightPin != NULL_ID && topLeftPin != bottomRightPin) + { + patternInfo.SetTopLeftPin(topLeftPin); + patternInfo.SetBottomRightPin(bottomRightPin); + patternInfo.SetCenterPin(NULL_ID); + patternInfo.SetLabelWidth(QChar('1')); + patternInfo.SetLabelHeight(QChar('1')); + } + else + { + patternInfo.SetTopLeftPin(NULL_ID); + patternInfo.SetBottomRightPin(NULL_ID); + patternInfo.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); + patternInfo.SetLabelWidth(GetParametrString(domElement, AttrWidth, QChar('1'))); + patternInfo.SetLabelHeight(GetParametrString(domElement, AttrHeight, QChar('1'))); + } + return patternInfo; } @@ -1063,12 +1095,30 @@ VGrainlineData VPattern::ParsePieceGrainline(const QDomElement &domElement, VGra gGeometry.SetVisible(GetParametrBool(domElement, AttrVisible, falseStr)); gGeometry.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, QChar('0')), GetParametrDouble(domElement, AttrMy, QChar('0')))); - gGeometry.SetLength(GetParametrString(domElement, AttrLength, QChar('1'))); - gGeometry.SetRotation(GetParametrString(domElement, AttrRotation, QStringLiteral("90"))); gGeometry.SetArrowType(static_cast(GetParametrUInt(domElement, AttrArrows, QChar('0')))); - gGeometry.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); - gGeometry.SetTopPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR)); - gGeometry.SetBottomPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomPin, NULL_ID_STR)); + + const quint32 topPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR); + const quint32 bottomPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomPin, NULL_ID_STR); + + if (topPin != NULL_ID && bottomPin != NULL_ID && topPin != bottomPin) + { + gGeometry.SetTopPin(topPin); + gGeometry.SetBottomPin(bottomPin); + + gGeometry.SetLength(QChar('1')); + gGeometry.SetRotation(QString::number(90)); + gGeometry.SetCenterPin(NULL_ID); + } + else + { + gGeometry.SetTopPin(NULL_ID); + gGeometry.SetBottomPin(NULL_ID); + + gGeometry.SetLength(GetParametrString(domElement, AttrLength, QChar('1'))); + gGeometry.SetRotation(GetParametrString(domElement, AttrRotation, QString::number(90))); + gGeometry.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); + } + return gGeometry; } diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index ad852a0b4..9f4f61d99 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -234,8 +234,17 @@ void ReadExpressionAttribute(QVector &expressions, const QDomElem //--------------------------------------------------------------------------------------------------------------------- QList GetTokens(const VFormulaField &formula) { - QScopedPointer cal(new qmu::QmuTokenParser(formula.expression, false, false)); - return cal->GetTokens().values(); + try + { + QScopedPointer cal(new qmu::QmuTokenParser(formula.expression, false, false)); + return cal->GetTokens().values(); + } + catch (const qmu::QmuParserError &e) + { + qWarning() << QObject::tr("Cannot get tokens from formula '%1'. Parser error: %2.") + .arg(formula.expression, e.GetMsg()); + return QList(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index eb613d2a1..460261495 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -1782,7 +1782,6 @@ void DialogSeamAllowance::EnabledGrainline() { if (uiTabGrainline->groupBoxGrainline->isChecked() == true) { - UpdateGrainlineValues(); GrainlinePinPointChanged(); } else @@ -2256,6 +2255,7 @@ void DialogSeamAllowance::GrainlinePinPointChanged() m_ftb->SetTabText(TabOrder::Grainline, tr("Grainline")); } } + EnableGrainlineFormulaControls(not flagGPin); UpdateGrainlineValues(); ChangeColor(uiTabGrainline->labelGrainlineTopPin, color); ChangeColor(uiTabGrainline->labelGrainlineBottomPin, color); @@ -2289,6 +2289,7 @@ void DialogSeamAllowance::DetailPinPointChanged() QIcon(":/icons/win.icon.theme/16x16/status/dialog-warning.png")); uiTabLabels->tabWidget->setTabIcon(uiTabLabels->tabWidget->indexOf(uiTabLabels->tabLabels), icon); } + EnableDetailLabelFormulaControls(not flagDPin); UpdateDetailLabelValues(); ChangeColor(uiTabLabels->labelDLTopLeftPin, color); ChangeColor(uiTabLabels->labelDLBottomRightPin, color); @@ -2322,6 +2323,7 @@ void DialogSeamAllowance::PatternPinPointChanged() QIcon(":/icons/win.icon.theme/16x16/status/dialog-warning.png")); uiTabLabels->tabWidget->setTabIcon(uiTabLabels->tabWidget->indexOf(uiTabLabels->tabLabels), icon); } + EnablePatternLabelFormulaControls(not flagPPin); UpdatePatternLabelValues(); ChangeColor(uiTabLabels->labelPLTopLeftPin, color); ChangeColor(uiTabLabels->labelPLBottomRightPin, color); @@ -2367,29 +2369,65 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.GetPatternPieceData().SetQuantity(uiTabLabels->spinBoxQuantity->value()); piece.GetPatternPieceData().SetOnFold(uiTabLabels->checkBoxFold->isChecked()); piece.GetPatternPieceData().SetLabelTemplate(m_templateLines); - piece.GetPatternPieceData().SetLabelWidth(GetFormulaFromUser(uiTabLabels->lineEditDLWidthFormula)); - piece.GetPatternPieceData().SetLabelHeight(GetFormulaFromUser(uiTabLabels->lineEditDLHeightFormula)); piece.GetPatternPieceData().SetRotation(GetFormulaFromUser(uiTabLabels->lineEditDLAngleFormula)); piece.GetPatternPieceData().SetVisible(uiTabLabels->groupBoxDetailLabel->isChecked()); - piece.GetPatternPieceData().SetCenterPin(getCurrentObjectId(uiTabLabels->comboBoxDLCenterPin)); - piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(uiTabLabels->comboBoxDLTopLeftPin)); - piece.GetPatternPieceData().SetBottomRightPin(getCurrentObjectId(uiTabLabels->comboBoxDLBottomRightPin)); + + if (not flagDPin) + { + piece.GetPatternPieceData().SetLabelWidth(GetFormulaFromUser(uiTabLabels->lineEditDLWidthFormula)); + piece.GetPatternPieceData().SetLabelHeight(GetFormulaFromUser(uiTabLabels->lineEditDLHeightFormula)); + piece.GetPatternPieceData().SetCenterPin(getCurrentObjectId(uiTabLabels->comboBoxDLCenterPin)); + piece.GetPatternPieceData().SetTopLeftPin(NULL_ID); + piece.GetPatternPieceData().SetBottomRightPin(NULL_ID); + } + else + { + piece.GetPatternPieceData().SetLabelWidth(QString::number(1)); + piece.GetPatternPieceData().SetLabelHeight(QString::number(1)); + piece.GetPatternPieceData().SetCenterPin(NULL_ID); + piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(uiTabLabels->comboBoxDLTopLeftPin)); + piece.GetPatternPieceData().SetBottomRightPin(getCurrentObjectId(uiTabLabels->comboBoxDLBottomRightPin)); + } piece.GetPatternInfo().SetVisible(uiTabLabels->groupBoxPatternLabel->isChecked()); - piece.GetPatternInfo().SetCenterPin(getCurrentObjectId(uiTabLabels->comboBoxPLCenterPin)); - piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(uiTabLabels->comboBoxPLTopLeftPin)); - piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(uiTabLabels->comboBoxPLBottomRightPin)); - piece.GetPatternInfo().SetLabelWidth(GetFormulaFromUser(uiTabLabels->lineEditPLWidthFormula)); - piece.GetPatternInfo().SetLabelHeight(GetFormulaFromUser(uiTabLabels->lineEditPLHeightFormula)); piece.GetPatternInfo().SetRotation(GetFormulaFromUser(uiTabLabels->lineEditPLAngleFormula)); + if (not flagPPin) + { + piece.GetPatternInfo().SetCenterPin(getCurrentObjectId(uiTabLabels->comboBoxPLCenterPin)); + piece.GetPatternInfo().SetTopLeftPin(NULL_ID); + piece.GetPatternInfo().SetBottomRightPin(NULL_ID); + piece.GetPatternInfo().SetLabelWidth(GetFormulaFromUser(uiTabLabels->lineEditPLWidthFormula)); + piece.GetPatternInfo().SetLabelHeight(GetFormulaFromUser(uiTabLabels->lineEditPLHeightFormula)); + } + else + { + piece.GetPatternInfo().SetCenterPin(NULL_ID); + piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(uiTabLabels->comboBoxPLTopLeftPin)); + piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(uiTabLabels->comboBoxPLBottomRightPin)); + piece.GetPatternInfo().SetLabelWidth(QString::number(1)); + piece.GetPatternInfo().SetLabelHeight(QString::number(1)); + } + piece.GetGrainlineGeometry().SetVisible(uiTabGrainline->groupBoxGrainline->isChecked()); - piece.GetGrainlineGeometry().SetRotation(GetFormulaFromUser(uiTabGrainline->lineEditRotFormula)); - piece.GetGrainlineGeometry().SetLength(GetFormulaFromUser(uiTabGrainline->lineEditLenFormula)); piece.GetGrainlineGeometry().SetArrowType(static_cast(uiTabGrainline->comboBoxArrow->currentIndex())); - piece.GetGrainlineGeometry().SetCenterPin(getCurrentObjectId(uiTabGrainline->comboBoxGrainlineCenterPin)); - piece.GetGrainlineGeometry().SetTopPin(getCurrentObjectId(uiTabGrainline->comboBoxGrainlineTopPin)); - piece.GetGrainlineGeometry().SetBottomPin(getCurrentObjectId(uiTabGrainline->comboBoxGrainlineBottomPin)); + + if (not flagGPin) + { + piece.GetGrainlineGeometry().SetRotation(GetFormulaFromUser(uiTabGrainline->lineEditRotFormula)); + piece.GetGrainlineGeometry().SetLength(GetFormulaFromUser(uiTabGrainline->lineEditLenFormula)); + piece.GetGrainlineGeometry().SetCenterPin(getCurrentObjectId(uiTabGrainline->comboBoxGrainlineCenterPin)); + piece.GetGrainlineGeometry().SetTopPin(NULL_ID); + piece.GetGrainlineGeometry().SetBottomPin(NULL_ID); + } + else + { + piece.GetGrainlineGeometry().SetRotation(QString::number(90)); + piece.GetGrainlineGeometry().SetLength(QChar('1')); + piece.GetGrainlineGeometry().SetCenterPin(NULL_ID); + piece.GetGrainlineGeometry().SetTopPin(getCurrentObjectId(uiTabGrainline->comboBoxGrainlineTopPin)); + piece.GetGrainlineGeometry().SetBottomPin(getCurrentObjectId(uiTabGrainline->comboBoxGrainlineBottomPin)); + } return piece; } @@ -3344,6 +3382,48 @@ QString DialogSeamAllowance::GetDefaultPieceName() const return name; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EnableGrainlineFormulaControls(bool enable) +{ + uiTabGrainline->pushButtonRot->setEnabled(enable); + uiTabGrainline->lineEditRotFormula->setEnabled(enable); + uiTabGrainline->pushButtonShowRot->setEnabled(enable); + + uiTabGrainline->pushButtonLen->setEnabled(enable); + uiTabGrainline->lineEditLenFormula->setEnabled(enable); + uiTabGrainline->pushButtonShowLen->setEnabled(enable); + + uiTabGrainline->comboBoxGrainlineCenterPin->setEnabled(enable); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EnableDetailLabelFormulaControls(bool enable) +{ + uiTabLabels->pushButtonDLWidth->setEnabled(enable); + uiTabLabels->lineEditDLWidthFormula->setEnabled(enable); + uiTabLabels->pushButtonShowDLWidth->setEnabled(enable); + + uiTabLabels->pushButtonDLHeight->setEnabled(enable); + uiTabLabels->lineEditDLHeightFormula->setEnabled(enable); + uiTabLabels->pushButtonShowDLHeight->setEnabled(enable); + + uiTabLabels->comboBoxDLCenterPin->setEnabled(enable); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EnablePatternLabelFormulaControls(bool enable) +{ + uiTabLabels->pushButtonPLWidth->setEnabled(enable); + uiTabLabels->lineEditPLWidthFormula->setEnabled(enable); + uiTabLabels->pushButtonShowPLWidth->setEnabled(enable); + + uiTabLabels->pushButtonPLHeight->setEnabled(enable); + uiTabLabels->lineEditPLHeightFormula->setEnabled(enable); + uiTabLabels->pushButtonShowPLHeight->setEnabled(enable); + + uiTabLabels->comboBoxPLCenterPin->setEnabled(enable); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::SetMoveControls() { diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h index 7459dc083..bc91471a2 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ ** ** @file dialogseamallowance.h ** @author Roman Telezhynskyi @@ -276,6 +276,10 @@ private: VPlaceLabelItem CurrentPlaceLabel(quint32 id) const; QString GetDefaultPieceName() const; + + void EnableGrainlineFormulaControls(bool enable); + void EnableDetailLabelFormulaControls(bool enable); + void EnablePatternLabelFormulaControls(bool enable); }; #endif // DIALOGSEAMALLOWANCE_H