diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 350fb5b1d..5dd5666b3 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -78,6 +78,14 @@ Calculator::Calculator(const QString &formula, bool fromUser) } SetExpr(formula); + try + { + Eval();//Need run for making tokens + } + catch(qmu::QmuParserError &e) + { + return;//Ignore all warnings + } } Calculator::~Calculator() diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 33a79de61..377942edb 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -471,6 +471,12 @@ + + + 0 + 0 + + Size and height @@ -481,6 +487,12 @@ + + + 0 + 0 + + Standard table @@ -488,6 +500,12 @@ + + + 0 + 0 + + Increments @@ -498,6 +516,12 @@ true + + + 0 + 0 + + Length of lines @@ -508,6 +532,12 @@ true + + + 0 + 0 + + Length of arcs @@ -518,6 +548,12 @@ true + + + 0 + 0 + + Length of curves diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index a2a4364e4..e49c4933b 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -671,8 +671,9 @@ void DialogTool::ValChenged(int row) } if (radioButtonStandardTable->isChecked()) { - VMeasurement stable = data->GetMeasurement(item->text()); - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandardTableRow(item->text())) + QString name = qApp->VarFromUser(item->text()); + VMeasurement stable = data->GetMeasurement(name); + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandardTableRow(name)) .arg(stable.GetDescription()); labelDescription->setText(desc); return; @@ -687,22 +688,22 @@ void DialogTool::ValChenged(int row) } if (radioButtonLengthLine->isChecked()) { - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLine(item->text())) + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLine(qApp->VarFromUser(item->text()))) .arg(tr("Line length")); labelDescription->setText(desc); return; } if (radioButtonLengthArc->isChecked()) { - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLengthArc(item->text())) + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLengthArc(qApp->VarFromUser(item->text()))) .arg(tr("Arc length")); labelDescription->setText(desc); return; } if (radioButtonLengthCurve->isChecked()) { - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLengthSpline(item->text())) - .arg(tr("Curve length")); + QString desc = QString("%1(%2) - %3").arg(item->text()) + .arg(data->GetLengthSpline(qApp->VarFromUser(item->text()))).arg(tr("Curve length")); labelDescription->setText(desc); return; } @@ -757,7 +758,7 @@ void DialogTool::ShowVariable(const QHash *var) while (i.hasNext()) { i.next(); - map.insert(i.key(), i.value()); + map.insert(qApp->VarToUser(i.key()), i.value()); } QMapIterator iMap(map); diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index 663fc6452..132fa6835 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -1505,7 +1505,7 @@ void VApplication::InitPostfixOperators() } //--------------------------------------------------------------------------------------------------------------------- -bool VApplication::Measurements(QString &newFormula, int position, const QString &token) +bool VApplication::MeasurementsFromUser(QString &newFormula, int position, const QString &token) const { QMap::const_iterator i = measurements.constBegin(); while (i != measurements.constEnd()) @@ -1521,7 +1521,7 @@ bool VApplication::Measurements(QString &newFormula, int position, const QString } //--------------------------------------------------------------------------------------------------------------------- -bool VApplication::VariablesFromUser(QString &newFormula, int position, const QString &token) +bool VApplication::VariablesFromUser(QString &newFormula, int position, const QString &token) const { QMap::const_iterator i = variables.constBegin(); while (i != variables.constEnd()) @@ -1537,7 +1537,7 @@ bool VApplication::VariablesFromUser(QString &newFormula, int position, const QS } //--------------------------------------------------------------------------------------------------------------------- -bool VApplication::PostfixOperators(QString &newFormula, int position, const QString &token) +bool VApplication::PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token) const { QMap::const_iterator i = postfixOperators.constBegin(); while (i != postfixOperators.constEnd()) @@ -1553,7 +1553,7 @@ bool VApplication::PostfixOperators(QString &newFormula, int position, const QSt } //--------------------------------------------------------------------------------------------------------------------- -bool VApplication::Functions(QString &newFormula, int position, const QString &token) +bool VApplication::FunctionsFromUser(QString &newFormula, int position, const QString &token) const { QMap::const_iterator i = functions.constBegin(); while (i != functions.constEnd()) @@ -1569,14 +1569,14 @@ bool VApplication::Functions(QString &newFormula, int position, const QString &t } //--------------------------------------------------------------------------------------------------------------------- -bool VApplication::VariablesToUser(QString &newFormula, int position, const QString &token) +bool VApplication::VariablesToUser(QString &newFormula, int position, const QString &token) const { QMap::const_iterator i = variables.constBegin(); while (i != variables.constEnd()) { if(token.indexOf( i.key() ) == 0) { - newFormula.replace(position, variables.value(i.key()).translate().length(), i.value().translate()); + newFormula.replace(position, i.key().length(), i.value().translate()); return true; } ++i; @@ -1592,9 +1592,55 @@ void VApplication::setPatternUnit(const Valentina::Units &patternUnit) } //--------------------------------------------------------------------------------------------------------------------- -QString VApplication::Measurement(const QString &measurement) const +QString VApplication::VarToUser(const QString &var) const { - return measurements.value(measurement).translate(); + if (measurements.contains(var)) + { + return measurements.value(var).translate(); + } + + if (functions.contains(var)) + { + return functions.value(var).translate(); + } + + if (postfixOperators.contains(var)) + { + return postfixOperators.value(var).translate(); + } + + QString newVar = var; + if(VariablesToUser(newVar, 0, var)) + { + return newVar; + } + return newVar; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VApplication::VarFromUser(const QString &var) const +{ + QString newVar = var; + if(MeasurementsFromUser(newVar, 0, var)) + { + return newVar; + } + + if(VariablesFromUser(newVar, 0, var)) + { + return newVar; + } + + if(PostfixOperatorsFromUser(newVar, 0, var)) + { + return newVar; + } + + if(FunctionsFromUser(newVar, 0, var)) + { + return newVar; + } + return newVar; } //--------------------------------------------------------------------------------------------------------------------- @@ -1653,7 +1699,7 @@ QString VApplication::FormulaFromUser(const QString &formula) QMap::const_iterator i = tokens.constBegin(); while (i != tokens.constEnd()) { - if(Measurements(newFormula, i.key(), i.value())) + if(MeasurementsFromUser(newFormula, i.key(), i.value())) { ++i; continue; @@ -1665,13 +1711,13 @@ QString VApplication::FormulaFromUser(const QString &formula) continue; } - if(PostfixOperators(newFormula, i.key(), i.value())) + if(PostfixOperatorsFromUser(newFormula, i.key(), i.value())) { ++i; continue; } - if(Functions(newFormula, i.key(), i.value())) + if(FunctionsFromUser(newFormula, i.key(), i.value())) { ++i; continue; diff --git a/src/app/widgets/vapplication.h b/src/app/widgets/vapplication.h index 4df5493d1..944bd25bc 100644 --- a/src/app/widgets/vapplication.h +++ b/src/app/widgets/vapplication.h @@ -72,7 +72,8 @@ public: QString pathToTables() const; qreal widthMainLine() const; qreal widthHairLine() const; - QString Measurement(const QString &measurement) const; + QString VarToUser(const QString &var) const; + QString VarFromUser(const QString &var) const; QString GuiText(const QString &measurement) const; QString Description(const QString &measurement) const; QString Variable(const QString &name) const; @@ -96,11 +97,11 @@ private: void InitVariables(); void InitFunctions(); void InitPostfixOperators(); - bool Measurements(QString &newFormula, int position, const QString &token); - bool VariablesFromUser(QString &newFormula, int position, const QString &token); - bool PostfixOperators(QString &newFormula, int position, const QString &token); - bool Functions(QString &newFormula, int position, const QString &token); - bool VariablesToUser(QString &newFormula, int position, const QString &token); + bool MeasurementsFromUser(QString &newFormula, int position, const QString &token) const; + bool VariablesFromUser(QString &newFormula, int position, const QString &token) const; + bool PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token) const; + bool FunctionsFromUser(QString &newFormula, int position, const QString &token) const; + bool VariablesToUser(QString &newFormula, int position, const QString &token) const; }; inline Valentina::Units VApplication::patternUnit() const