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);
QString formula;
try
{
formula = qApp->TrVars()->FormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = meash->GetFormula();
}
QString formula = VTranslateVars::TryFormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
ui->plainTextEditFormula->setPlainText(formula);
ui->plainTextEditFormula->blockSignals(false);
@ -2416,16 +2407,7 @@ void TMainWindow::RefreshTable(bool freshCall)
AddCell(locale().toString(value), currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter,
meash->IsFormulaOk()); // calculated value
QString formula;
try
{
formula = qApp->TrVars()->FormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = meash->GetFormula();
}
QString formula = VTranslateVars::TryFormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator());
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,
Qt::AlignHCenter | Qt::AlignVCenter, incr->IsFormulaOk()); // calculated value
QString formula;
try
{
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = incr->GetFormula();
}
QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
AddCell(table, formula, currentRow, 2, Qt::AlignVCenter); // formula
}
@ -1394,16 +1385,7 @@ void DialogIncrements::ShowIncrementDetails()
EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), labelCalculatedValue);
plainTextEditFormula->blockSignals(true);
QString formula;
try
{
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = incr->GetFormula();
}
QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
plainTextEditFormula->setPlainText(formula);
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, 1, qApp->LocaleToString(*incr->GetValue())); // calculated value
QString formula;
try
{
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = incr->GetFormula();
}
QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
csv.setText(currentRow, 2, formula); // formula
}

View File

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

View File

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