Refactoring use static methods VTranslateVars::TryFormula*User().

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-09-26 17:46:28 +03:00
parent 0eb6b8b30f
commit 661e71bad0
5 changed files with 19 additions and 119 deletions

View File

@ -1506,16 +1506,7 @@ void TMainWindow::ShowNewMData(bool fresh)
ui->plainTextEditFormula->blockSignals(true); ui->plainTextEditFormula->blockSignals(true);
QString formula; QString formula = VTranslateVars::TryFormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
try
{
formula = qApp->TrVars()->FormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = meash->GetFormula();
}
ui->plainTextEditFormula->setPlainText(formula); ui->plainTextEditFormula->setPlainText(formula);
ui->plainTextEditFormula->blockSignals(false); ui->plainTextEditFormula->blockSignals(false);
@ -2416,16 +2407,7 @@ void TMainWindow::RefreshTable(bool freshCall)
AddCell(locale().toString(value), currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter, AddCell(locale().toString(value), currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter,
meash->IsFormulaOk()); // calculated value meash->IsFormulaOk()); // calculated value
QString formula; QString formula = VTranslateVars::TryFormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
try
{
formula = qApp->TrVars()->FormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = meash->GetFormula();
}
AddCell(formula, currentRow, ColumnFormula, Qt::AlignVCenter); // formula AddCell(formula, currentRow, ColumnFormula, Qt::AlignVCenter); // formula
} }

View File

@ -713,16 +713,7 @@ void DialogIncrements::FillIncrementsTable(QTableWidget *table,
AddCell(table, qApp->LocaleToString(*incr->GetValue()), currentRow, 1, AddCell(table, qApp->LocaleToString(*incr->GetValue()), currentRow, 1,
Qt::AlignHCenter | Qt::AlignVCenter, incr->IsFormulaOk()); // calculated value Qt::AlignHCenter | Qt::AlignVCenter, incr->IsFormulaOk()); // calculated value
QString formula; QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
try
{
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = incr->GetFormula();
}
AddCell(table, formula, currentRow, 2, Qt::AlignVCenter); // formula AddCell(table, formula, currentRow, 2, Qt::AlignVCenter); // formula
} }
@ -1394,16 +1385,7 @@ void DialogIncrements::ShowIncrementDetails()
EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), labelCalculatedValue); EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), labelCalculatedValue);
plainTextEditFormula->blockSignals(true); plainTextEditFormula->blockSignals(true);
QString formula; QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
try
{
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = incr->GetFormula();
}
plainTextEditFormula->setPlainText(formula); plainTextEditFormula->setPlainText(formula);
plainTextEditFormula->blockSignals(false); plainTextEditFormula->blockSignals(false);

View File

@ -1520,17 +1520,7 @@ void MainWindow::ExportToCSVData(const QString &fileName, const DialogExportToCS
csv.setText(currentRow, 0, incr->GetName()); // name csv.setText(currentRow, 0, incr->GetName()); // name
csv.setText(currentRow, 1, qApp->LocaleToString(*incr->GetValue())); // calculated value csv.setText(currentRow, 1, qApp->LocaleToString(*incr->GetValue())); // calculated value
QString formula; QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
try
{
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = incr->GetFormula();
}
csv.setText(currentRow, 2, formula); // formula csv.setText(currentRow, 2, formula); // formula
} }

View File

@ -326,16 +326,7 @@ void DialogSplinePath::Angle1Changed()
const QString angle1F = ui->plainTextEditAngle1F->toPlainText().replace("\n", " "); const QString angle1F = ui->plainTextEditAngle1F->toPlainText().replace("\n", " ");
const qreal angle1 = Visualization::FindVal(angle1F, data->DataVariables()); const qreal angle1 = Visualization::FindVal(angle1F, data->DataVariables());
p.SetAngle1(angle1, VTranslateVars::TryFormulaFromUser(angle1F, qApp->Settings()->GetOsSeparator()));
try
{
p.SetAngle1(angle1, qApp->TrVars()->FormulaFromUser(angle1F, qApp->Settings()->GetOsSeparator()));
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
p.SetAngle1(angle1, angle1F);
}
item->setData(Qt::UserRole, QVariant::fromValue(p)); item->setData(Qt::UserRole, QVariant::fromValue(p));
@ -369,16 +360,7 @@ void DialogSplinePath::Angle2Changed()
const QString angle2F = ui->plainTextEditAngle2F->toPlainText().replace("\n", " "); const QString angle2F = ui->plainTextEditAngle2F->toPlainText().replace("\n", " ");
const qreal angle2 = Visualization::FindVal(angle2F, data->DataVariables()); const qreal angle2 = Visualization::FindVal(angle2F, data->DataVariables());
p.SetAngle2(angle2, VTranslateVars::TryFormulaFromUser(angle2F, qApp->Settings()->GetOsSeparator()));
try
{
p.SetAngle2(angle2, qApp->TrVars()->FormulaFromUser(angle2F, qApp->Settings()->GetOsSeparator()));
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
p.SetAngle2(angle2, angle2F);
}
item->setData(Qt::UserRole, QVariant::fromValue(p)); item->setData(Qt::UserRole, QVariant::fromValue(p));
@ -412,16 +394,7 @@ void DialogSplinePath::Length1Changed()
const QString length1F = ui->plainTextEditLength1F->toPlainText().replace("\n", " "); const QString length1F = ui->plainTextEditLength1F->toPlainText().replace("\n", " ");
const qreal length1 = Visualization::FindLength(length1F, data->DataVariables()); const qreal length1 = Visualization::FindLength(length1F, data->DataVariables());
p.SetLength1(length1, VTranslateVars::TryFormulaFromUser(length1F, qApp->Settings()->GetOsSeparator()));
try
{
p.SetLength1(length1, qApp->TrVars()->FormulaFromUser(length1F, qApp->Settings()->GetOsSeparator()));
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
p.SetLength1(length1, length1F);
}
item->setData(Qt::UserRole, QVariant::fromValue(p)); item->setData(Qt::UserRole, QVariant::fromValue(p));
@ -446,16 +419,7 @@ void DialogSplinePath::Length2Changed()
const QString length2F = ui->plainTextEditLength2F->toPlainText().replace("\n", " "); const QString length2F = ui->plainTextEditLength2F->toPlainText().replace("\n", " ");
const qreal length2 = Visualization::FindLength(length2F, data->DataVariables()); const qreal length2 = Visualization::FindLength(length2F, data->DataVariables());
p.SetLength2(length2, VTranslateVars::TryFormulaFromUser(length2F, qApp->Settings()->GetOsSeparator()));
try
{
p.SetLength2(length2, qApp->TrVars()->FormulaFromUser(length2F, qApp->Settings()->GetOsSeparator()));
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
p.SetLength2(length2, length2F);
}
item->setData(Qt::UserRole, QVariant::fromValue(p)); item->setData(Qt::UserRole, QVariant::fromValue(p));
@ -469,14 +433,14 @@ void DialogSplinePath::FXAngle1()
auto dialog = new DialogEditWrongFormula(data, toolId, this); auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit first control point angle")); dialog->setWindowTitle(tr("Edit first control point angle"));
QString angle1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText().replace("\n", " "), QString angle1F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator()); qApp->Settings()->GetOsSeparator());
dialog->SetFormula(angle1F); dialog->SetFormula(angle1F);
dialog->setPostfix(degreeSymbol); dialog->setPostfix(degreeSymbol);
if (dialog->exec() == QDialog::Accepted) if (dialog->exec() == QDialog::Accepted)
{ {
angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); angle1F = VTranslateVars::TryFormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (angle1F.length() > 80) if (angle1F.length() > 80)
{ {
@ -494,14 +458,14 @@ void DialogSplinePath::FXAngle2()
auto dialog = new DialogEditWrongFormula(data, toolId, this); auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit second control point angle")); dialog->setWindowTitle(tr("Edit second control point angle"));
QString angle2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText().replace("\n", " "), QString angle2F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator()); qApp->Settings()->GetOsSeparator());
dialog->SetFormula(angle2F); dialog->SetFormula(angle2F);
dialog->setPostfix(degreeSymbol); dialog->setPostfix(degreeSymbol);
if (dialog->exec() == QDialog::Accepted) if (dialog->exec() == QDialog::Accepted)
{ {
angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); angle2F = VTranslateVars::TryFormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (angle2F.length() > 80) if (angle2F.length() > 80)
{ {
@ -519,14 +483,14 @@ void DialogSplinePath::FXLength1()
auto dialog = new DialogEditWrongFormula(data, toolId, this); auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit first control point length")); dialog->setWindowTitle(tr("Edit first control point length"));
QString length1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText().replace("\n", " "), QString length1F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator()); qApp->Settings()->GetOsSeparator());
dialog->SetFormula(length1F); dialog->SetFormula(length1F);
dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
if (dialog->exec() == QDialog::Accepted) if (dialog->exec() == QDialog::Accepted)
{ {
length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); length1F = VTranslateVars::TryFormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (length1F.length() > 80) if (length1F.length() > 80)
{ {
@ -544,14 +508,14 @@ void DialogSplinePath::FXLength2()
auto dialog = new DialogEditWrongFormula(data, toolId, this); auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit second control point length")); dialog->setWindowTitle(tr("Edit second control point length"));
QString length2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText().replace("\n", " "), QString length2F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator()); qApp->Settings()->GetOsSeparator());
dialog->SetFormula(length2F); dialog->SetFormula(length2F);
dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true)); dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
if (dialog->exec() == QDialog::Accepted) if (dialog->exec() == QDialog::Accepted)
{ {
length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); length2F = VTranslateVars::TryFormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (length2F.length() > 80) if (length2F.length() > 80)
{ {

View File

@ -72,16 +72,7 @@ void TST_VTranslateVars::TestFormulaFromUser()
QLocale::setDefault(locale); QLocale::setDefault(locale);
QString result; const QString result = VTranslateVars::TryFormulaFromUser(input, true);
try
{
result = m_trMs->FormulaFromUser(input, true);
}
catch (qmu::QmuParserError &e)// In case something bad will happen
{
Q_UNUSED(e)
result = input;
}
QCOMPARE(result, output); QCOMPARE(result, output);
} }
@ -111,16 +102,7 @@ void TST_VTranslateVars::TestFormulaToUser()
QLocale::setDefault(locale); QLocale::setDefault(locale);
QString result; const QString result = VTranslateVars::TryFormulaToUser(input, true);
try
{
result = m_trMs->FormulaToUser(input, true);
}
catch (qmu::QmuParserError &e)// In case something bad will happen
{
Q_UNUSED(e)
result = input;
}
QCOMPARE(result, output); QCOMPARE(result, output);
} }