From 5562e467908a5e3b3f309ea3d8e3a28cf43bc9c5 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 6 Oct 2016 23:39:57 +0200 Subject: [PATCH] Fixed the Grainline tab in detail dialog and also length/rotation formulas checking --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 126 ++++--- src/libs/vtools/dialogs/tools/dialogdetail.h | 4 +- src/libs/vtools/dialogs/tools/dialogdetail.ui | 308 ++++++++++++++---- 3 files changed, 324 insertions(+), 114 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index d6cc233ce..e82f2e704 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -159,8 +159,8 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.checkBoxGrainline, &QCheckBox::toggled, this, &DialogDetail::EnableGrainlineRotation); connect(ui.pushButtonRot, &QPushButton::clicked, this, &DialogDetail::EditFormula); connect(ui.pushButtonLen, &QPushButton::clicked, this, &DialogDetail::EditFormula); - connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); - connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); + connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues); + connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues); connect(ui.pushButtonShowRot, &QPushButton::clicked, this, &DialogDetail::DeployRotation); connect(ui.pushButtonShowLen, &QPushButton::clicked, this, &DialogDetail::DeployLength); @@ -484,11 +484,8 @@ VDetail DialogDetail::CreateDetail() const detail.GetGrainlineGeometry() = m_oldGrainline; detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked()); - if (ui.checkBoxGrainline->isChecked() == true) - { - detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText()); - detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText()); - } + detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText()); + detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText()); return detail; } @@ -835,58 +832,80 @@ void DialogDetail::ClearFields() } //--------------------------------------------------------------------------------------------------------------------- -void DialogDetail::SetValue(QObject *pobjSender) +void DialogDetail::UpdateValues() { - QPlainTextEdit* pleSender = qobject_cast(pobjSender); - SCASSERT(pleSender != 0); + QPlainTextEdit* apleSender[2]; + apleSender[0] = ui.lineEditRotFormula; + apleSender[1] = ui.lineEditLenFormula; + bool bFormulasOK = true; - QString qsFormula = pleSender->toPlainText().simplified(); - Calculator cal; - QString qsVal; - try + for (int i = 0; i < 2; ++i) { - qsFormula.replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); - qreal dVal; - dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); - if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + QLabel* plbVal; + QLabel* plbText; + QString qsUnit; + if (i == 0) { - qsVal.clear(); + plbVal = ui.labelRot; + plbText = ui.labelEditRot; + QChar ch(0x00b0); + qsUnit = ch; } else { - qsVal.setNum(dVal, 'f', 5); + plbVal = ui.labelLen; + plbText = ui.labelEditLen; + qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit()); } - } - catch (...) - { - qsVal.clear(); + + QString qsFormula = apleSender[i]->toPlainText().simplified(); + Calculator cal; + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + qreal dVal; + dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + throw qmu::QmuParserError(tr("Infinite/undefined result")); + } + else if (i == 1 && dVal <= 0.0) + { + throw qmu::QmuParserError(tr("Length should be positive")); + } + else + { + qsVal.setNum(dVal, 'f', 2); + ChangeColor(plbText, okColor); + } + } + catch (...) + { + qsVal.clear(); + ChangeColor(plbText, Qt::red); + bFormulasOK = false; + } + + if (qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + plbVal->setText(qsVal); } - QLabel* plbVal; - QString qsUnit; - if (pobjSender == ui.lineEditLenFormula) + bOk->setEnabled(bFormulasOK); + if (bFormulasOK == false) { - plbVal = ui.labelLen; - qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit()); - } - else if (pobjSender == ui.lineEditRotFormula) - { - plbVal = ui.labelRot; - QChar ch(0x00b0); - qsUnit = ch; + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui.tabWidget->setTabIcon(2, icon); } else { - // should not get here - return; + QIcon icon; + ui.tabWidget->setTabIcon(2, icon); } - - if (qsVal.isEmpty() == false) - { - qsVal += qsUnit; - } - plbVal->setText(qsVal); } //--------------------------------------------------------------------------------------------------------------------- @@ -945,6 +964,17 @@ void DialogDetail::EnableGrainlineRotation() ui.pushButtonLen->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonShowLen->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonShowRot->setEnabled(ui.checkBoxGrainline->isChecked()); + + if (ui.checkBoxGrainline->isChecked() == true) + { + UpdateValues(); + } + else + { + ChangeColor(ui.labelEditLen, okColor); + ChangeColor(ui.labelEditRot, okColor); + bOk->setEnabled(true); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -977,16 +1007,10 @@ void DialogDetail::EditFormula() QString qsFormula = dlg.GetFormula(); qsFormula.replace("\n", " "); pleFormula->setPlainText(qsFormula); - SetValue(pleFormula); + UpdateValues(); } } -//--------------------------------------------------------------------------------------------------------------------- -void DialogDetail::UpdateValue() -{ - SetValue(sender()); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::DeployRotation() { diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index b96263334..c40cb37a6 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -127,14 +127,12 @@ private: quint32 RowId(int i) const; - void SetValue(QObject* pobjSender); - private slots: + void UpdateValues(); void SetAddMode(); void SetEditMode(); void EnableGrainlineRotation(); void EditFormula(); - void UpdateValue(); void DeployRotation(); void DeployLength(); }; diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index ef696c8e6..2e81a4f14 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -538,9 +538,9 @@ - 20 - 20 - 351 + 10 + 10 + 541 41 @@ -554,32 +554,68 @@ - + - 20 - 70 - 351 + 10 + 60 + 541 41 - - - - - - 11 - 75 - true - + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + - Rotation + Rotation: - + Qt::Horizontal @@ -591,10 +627,13 @@ - - + + + + Formula wizard + - + ... @@ -608,8 +647,8 @@ - - + + @@ -618,79 +657,171 @@ - + + + + 0 + 0 + + 87 0 + + + 0 + 0 + + + + Value + - + _ - + - 20 - 120 - 351 + 10 + 110 + 541 41 - + + + + 0 + 0 + + 16777215 28 + + Calculation + + + true + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + - + - + + + + + + + 16 + 16 + + + + true - + - 20 - 180 - 351 + 10 + 160 + 541 41 - - - - - - 11 - 75 - true - + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + - Length + Length: - + Qt::Horizontal @@ -702,10 +833,13 @@ - - + + + + Formula wizard + - + ... @@ -719,8 +853,8 @@ - - + + @@ -729,51 +863,105 @@ - + + + + 0 + 0 + + 87 0 + + + 0 + 0 + + + + Value + - + _ - + - 20 - 230 - 351 + 10 + 210 + 541 41 - + + + + 0 + 0 + + 16777215 28 + + Calculation + + + true + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + - + + + + 16 + 16 + + + + true +