Show language independent formula in dialog.

--HG--
branch : feature
This commit is contained in:
dismine 2014-05-26 16:18:48 +03:00
parent 6170aea8b6
commit 51a420bbdd
5 changed files with 116 additions and 24 deletions

View File

@ -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()

View File

@ -471,6 +471,12 @@
</item>
<item>
<widget class="QRadioButton" name="radioButtonSizeGrowth">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Size and height</string>
</property>
@ -481,6 +487,12 @@
</item>
<item>
<widget class="QRadioButton" name="radioButtonStandardTable">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Standard table</string>
</property>
@ -488,6 +500,12 @@
</item>
<item>
<widget class="QRadioButton" name="radioButtonIncrements">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Increments</string>
</property>
@ -498,6 +516,12 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Length of lines</string>
</property>
@ -508,6 +532,12 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Length of arcs</string>
</property>
@ -518,6 +548,12 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Length of curves</string>
</property>

View File

@ -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<key, val> *var)
while (i.hasNext())
{
i.next();
map.insert(i.key(), i.value());
map.insert(qApp->VarToUser(i.key()), i.value());
}
QMapIterator<key, val> iMap(map);

View File

@ -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<QString, VTranslation>::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<QString, VTranslation>::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<QString, VTranslation>::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<QString, VTranslation>::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<QString, VTranslation>::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<int, QString>::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;

View File

@ -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