Improve parsing formulas.
Enable subexpressions. Allow user to define local variables. --HG-- branch : develop
This commit is contained in:
parent
9b5b8dde04
commit
54d3ae7561
|
@ -615,12 +615,7 @@ bool TMainWindow::eventFilter(QObject *object, QEvent *event)
|
||||||
if (event->type() == QEvent::KeyPress)
|
if (event->type() == QEvent::KeyPress)
|
||||||
{
|
{
|
||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||||
if ((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return))
|
if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
|
||||||
{
|
|
||||||
// Ignore Enter key
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
|
|
||||||
{
|
{
|
||||||
if (qApp->Settings()->GetOsSeparator())
|
if (qApp->Settings()->GetOsSeparator())
|
||||||
{
|
{
|
||||||
|
@ -1225,8 +1220,7 @@ void TMainWindow::Fx()
|
||||||
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this);
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this);
|
||||||
dialog->setWindowTitle(tr("Edit measurement"));
|
dialog->setWindowTitle(tr("Edit measurement"));
|
||||||
dialog->SetMeasurementsMode();
|
dialog->SetMeasurementsMode();
|
||||||
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "),
|
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText(), true));
|
||||||
true));
|
|
||||||
const QString postfix = UnitsToStr(mUnit, true);//Show unit in dialog lable (cm, mm or inch)
|
const QString postfix = UnitsToStr(mUnit, true);//Show unit in dialog lable (cm, mm or inch)
|
||||||
dialog->setPostfix(postfix);
|
dialog->setPostfix(postfix);
|
||||||
|
|
||||||
|
@ -1650,9 +1644,7 @@ void TMainWindow::SaveMValue()
|
||||||
|
|
||||||
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
||||||
|
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
QString text = ui->plainTextEditFormula->toPlainText();
|
QString text = ui->plainTextEditFormula->toPlainText();
|
||||||
text.replace("\n", " ");
|
|
||||||
|
|
||||||
QTableWidgetItem *formulaField = ui->tableWidget->item(row, ColumnFormula);
|
QTableWidgetItem *formulaField = ui->tableWidget->item(row, ColumnFormula);
|
||||||
if (formulaField->text() == text)
|
if (formulaField->text() == text)
|
||||||
|
@ -2639,7 +2631,6 @@ bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer
|
||||||
{
|
{
|
||||||
f = formula;
|
f = formula;
|
||||||
}
|
}
|
||||||
f.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
qreal result = cal->EvalFormula(data->DataVariables(), f);
|
qreal result = cal->EvalFormula(data->DataVariables(), f);
|
||||||
|
|
||||||
|
|
|
@ -392,7 +392,6 @@ void DialogFinalMeasurements::SaveFormula()
|
||||||
|
|
||||||
// Replace line return character with spaces for calc if exist
|
// Replace line return character with spaces for calc if exist
|
||||||
QString text = ui->plainTextEditFormula->toPlainText();
|
QString text = ui->plainTextEditFormula->toPlainText();
|
||||||
text.replace("\n", " ");
|
|
||||||
|
|
||||||
QTableWidgetItem *formulaField = ui->tableWidget->item(row, 2);
|
QTableWidgetItem *formulaField = ui->tableWidget->item(row, 2);
|
||||||
if (formulaField->text() == text)
|
if (formulaField->text() == text)
|
||||||
|
@ -479,7 +478,7 @@ void DialogFinalMeasurements::Fx()
|
||||||
|
|
||||||
QScopedPointer<DialogEditWrongFormula> dialog(new DialogEditWrongFormula(&m_data, NULL_ID, this));
|
QScopedPointer<DialogEditWrongFormula> dialog(new DialogEditWrongFormula(&m_data, NULL_ID, this));
|
||||||
dialog->setWindowTitle(tr("Edit measurement"));
|
dialog->setWindowTitle(tr("Edit measurement"));
|
||||||
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "),
|
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator()));
|
qApp->Settings()->GetOsSeparator()));
|
||||||
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
|
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
|
||||||
dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch)
|
dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch)
|
||||||
|
@ -600,7 +599,6 @@ bool DialogFinalMeasurements::EvalUserFormula(const QString &formula, bool fromU
|
||||||
{
|
{
|
||||||
f = formula;
|
f = formula;
|
||||||
}
|
}
|
||||||
f.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
const qreal result = cal->EvalFormula(m_data.DataVariables(), f);
|
const qreal result = cal->EvalFormula(m_data.DataVariables(), f);
|
||||||
|
|
||||||
|
@ -719,11 +717,9 @@ qreal DialogFinalMeasurements::EvalFormula(const QString &formula, bool &ok)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QString f = formula;
|
|
||||||
// Replace line return character with spaces for calc if exist
|
// Replace line return character with spaces for calc if exist
|
||||||
f.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
result = cal->EvalFormula(m_data.DataVariables(), f);
|
result = cal->EvalFormula(m_data.DataVariables(), formula);
|
||||||
|
|
||||||
if (qIsInf(result) || qIsNaN(result))
|
if (qIsInf(result) || qIsNaN(result))
|
||||||
{
|
{
|
||||||
|
|
|
@ -357,7 +357,6 @@ bool DialogIncrements::EvalIncrementFormula(const QString &formula, bool fromUse
|
||||||
{
|
{
|
||||||
f = formula;
|
f = formula;
|
||||||
}
|
}
|
||||||
f.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
const qreal result = cal->EvalFormula(data->DataVariables(), f);
|
const qreal result = cal->EvalFormula(data->DataVariables(), f);
|
||||||
|
|
||||||
|
@ -1138,9 +1137,7 @@ void DialogIncrements::SaveIncrFormula()
|
||||||
|
|
||||||
const QTableWidgetItem *nameField = table->item(row, 0);
|
const QTableWidgetItem *nameField = table->item(row, 0);
|
||||||
|
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
QString text = textEdit->toPlainText();
|
QString text = textEdit->toPlainText();
|
||||||
text.replace("\n", " ");
|
|
||||||
|
|
||||||
QTableWidgetItem *formulaField = table->item(row, 2);
|
QTableWidgetItem *formulaField = table->item(row, 2);
|
||||||
if (formulaField->text() == text)
|
if (formulaField->text() == text)
|
||||||
|
@ -1286,7 +1283,7 @@ void DialogIncrements::Fx()
|
||||||
dialog->setWindowTitle(tr("Edit increment"));
|
dialog->setWindowTitle(tr("Edit increment"));
|
||||||
incrementMode ? dialog->SetIncrementsMode() : dialog->SetPreviewCalculationsMode();
|
incrementMode ? dialog->SetIncrementsMode() : dialog->SetPreviewCalculationsMode();
|
||||||
|
|
||||||
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(plainTextEditFormula->toPlainText().replace("\n", " "),
|
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(plainTextEditFormula->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator()));
|
qApp->Settings()->GetOsSeparator()));
|
||||||
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
|
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
|
||||||
dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch)
|
dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch)
|
||||||
|
|
|
@ -1654,11 +1654,8 @@ bool MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, boo
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QString f = m.formula;
|
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
f.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
const qreal result = cal->EvalFormula(completeData.DataVariables(), f);
|
const qreal result = cal->EvalFormula(completeData.DataVariables(), m.formula);
|
||||||
|
|
||||||
csv.setText(i, 1, qApp->LocaleToString(result)); // value
|
csv.setText(i, 1, qApp->LocaleToString(result)); // value
|
||||||
|
|
||||||
|
|
|
@ -3239,11 +3239,8 @@ qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
QString f = formula;
|
|
||||||
f.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
const qreal result = cal->EvalFormula(data->DataVariables(), f);
|
const qreal result = cal->EvalFormula(data->DataVariables(), formula);
|
||||||
|
|
||||||
(qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true;
|
(qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true;
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -2036,6 +2036,11 @@ bool VAbstractPattern::IsVariable(const QString &token) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (token.startsWith('#'))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,11 +66,11 @@ QmuParserBase::QmuParserBase()
|
||||||
m_decimalPoint(QLocale::c().decimalPoint()),
|
m_decimalPoint(QLocale::c().decimalPoint()),
|
||||||
m_thousandsSeparator(QLocale::c().groupSeparator()),
|
m_thousandsSeparator(QLocale::c().groupSeparator()),
|
||||||
m_FunDef(),
|
m_FunDef(),
|
||||||
|
m_pTokenReader(),
|
||||||
m_pParseFormula(&QmuParserBase::ParseString),
|
m_pParseFormula(&QmuParserBase::ParseString),
|
||||||
m_vRPN(),
|
m_vRPN(),
|
||||||
m_vStringBuf(),
|
m_vStringBuf(),
|
||||||
m_vStringVarBuf(),
|
m_vStringVarBuf(),
|
||||||
m_pTokenReader(),
|
|
||||||
m_PostOprtDef(),
|
m_PostOprtDef(),
|
||||||
m_InfixOprtDef(),
|
m_InfixOprtDef(),
|
||||||
m_OprtDef(),
|
m_OprtDef(),
|
||||||
|
@ -102,11 +102,11 @@ QmuParserBase::QmuParserBase(const QmuParserBase &a_Parser)
|
||||||
m_decimalPoint(a_Parser.getDecimalPoint()),
|
m_decimalPoint(a_Parser.getDecimalPoint()),
|
||||||
m_thousandsSeparator(a_Parser.getThousandsSeparator()),
|
m_thousandsSeparator(a_Parser.getThousandsSeparator()),
|
||||||
m_FunDef(),
|
m_FunDef(),
|
||||||
|
m_pTokenReader(),
|
||||||
m_pParseFormula(&QmuParserBase::ParseString),
|
m_pParseFormula(&QmuParserBase::ParseString),
|
||||||
m_vRPN(),
|
m_vRPN(),
|
||||||
m_vStringBuf(),
|
m_vStringBuf(),
|
||||||
m_vStringVarBuf(),
|
m_vStringVarBuf(),
|
||||||
m_pTokenReader(),
|
|
||||||
m_PostOprtDef(),
|
m_PostOprtDef(),
|
||||||
m_InfixOprtDef(),
|
m_InfixOprtDef(),
|
||||||
m_OprtDef(),
|
m_OprtDef(),
|
||||||
|
|
|
@ -134,11 +134,17 @@ public:
|
||||||
void setThousandsSeparator(const QChar &c);
|
void setThousandsSeparator(const QChar &c);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Typedef for the token reader.
|
||||||
|
*/
|
||||||
|
typedef QmuParserTokenReader token_reader_type;
|
||||||
|
|
||||||
static const QStringList c_DefaultOprt;
|
static const QStringList c_DefaultOprt;
|
||||||
QLocale m_locale;///< The locale used by the parser
|
QLocale m_locale;///< The locale used by the parser
|
||||||
QChar m_decimalPoint;
|
QChar m_decimalPoint;
|
||||||
QChar m_thousandsSeparator;
|
QChar m_thousandsSeparator;
|
||||||
funmap_type m_FunDef; ///< Map of function names and pointers.
|
funmap_type m_FunDef; ///< Map of function names and pointers.
|
||||||
|
std::unique_ptr<token_reader_type> m_pTokenReader; ///< Managed pointer to the token reader object.
|
||||||
static bool g_DbgDumpCmdCode;
|
static bool g_DbgDumpCmdCode;
|
||||||
static bool g_DbgDumpStack;
|
static bool g_DbgDumpStack;
|
||||||
void AddCallback(const QString &a_strName, const QmuParserCallback &a_Callback, funmap_type &a_Storage,
|
void AddCallback(const QString &a_strName, const QmuParserCallback &a_Callback, funmap_type &a_Storage,
|
||||||
|
@ -204,11 +210,6 @@ private:
|
||||||
*/
|
*/
|
||||||
typedef QVector<QString> stringbuf_type;
|
typedef QVector<QString> stringbuf_type;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Typedef for the token reader.
|
|
||||||
*/
|
|
||||||
typedef QmuParserTokenReader token_reader_type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type used for parser tokens.
|
* @brief Type used for parser tokens.
|
||||||
*/
|
*/
|
||||||
|
@ -229,8 +230,6 @@ private:
|
||||||
mutable stringbuf_type m_vStringBuf; ///< String buffer, used for storing string function arguments
|
mutable stringbuf_type m_vStringBuf; ///< String buffer, used for storing string function arguments
|
||||||
stringbuf_type m_vStringVarBuf;
|
stringbuf_type m_vStringVarBuf;
|
||||||
|
|
||||||
std::unique_ptr<token_reader_type> m_pTokenReader; ///< Managed pointer to the token reader object.
|
|
||||||
|
|
||||||
funmap_type m_PostOprtDef; ///< Postfix operator callbacks
|
funmap_type m_PostOprtDef; ///< Postfix operator callbacks
|
||||||
funmap_type m_InfixOprtDef; ///< unary infix operator.
|
funmap_type m_InfixOprtDef; ///< unary infix operator.
|
||||||
funmap_type m_OprtDef; ///< Binary operator callbacks
|
funmap_type m_OprtDef; ///< Binary operator callbacks
|
||||||
|
|
|
@ -932,17 +932,25 @@ bool QmuParserTokenReader::IsUndefVarTok ( token_type &a_Tok )
|
||||||
// If a factory is available implicitely create new variables
|
// If a factory is available implicitely create new variables
|
||||||
if ( m_pFactory )
|
if ( m_pFactory )
|
||||||
{
|
{
|
||||||
qreal *fVar = m_pFactory ( strTok, m_pFactoryData );
|
try
|
||||||
a_Tok.SetVar ( fVar, strTok );
|
{
|
||||||
|
qreal *fVar = m_pFactory ( strTok, m_pFactoryData );
|
||||||
|
a_Tok.SetVar ( fVar, strTok );
|
||||||
|
|
||||||
// Do not use m_pParser->DefineVar( strTok, fVar );
|
// Do not use m_pParser->DefineVar( strTok, fVar );
|
||||||
// in order to define the new variable, it will clear the
|
// in order to define the new variable, it will clear the
|
||||||
// m_UsedVar array which will kill previousely defined variables
|
// m_UsedVar array which will kill previousely defined variables
|
||||||
// from the list
|
// from the list
|
||||||
// This is safe because the new variable can never override an existing one
|
// This is safe because the new variable can never override an existing one
|
||||||
// because they are checked first!
|
// because they are checked first!
|
||||||
( *m_pVarDef ) [strTok] = fVar;
|
( *m_pVarDef ) [strTok] = fVar;
|
||||||
m_UsedVar[strTok] = fVar; // Add variable to used-var-list
|
m_UsedVar[strTok] = fVar; // Add variable to used-var-list
|
||||||
|
}
|
||||||
|
catch (const qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(e)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,6 +83,7 @@ QmuTokenParser::QmuTokenParser(const QString &formula, bool osSeparator,
|
||||||
|
|
||||||
SetExpr(formula);
|
SetExpr(formula);
|
||||||
//Need run for making tokens. Don't catch exception here, because we want know if formula has error.
|
//Need run for making tokens. Don't catch exception here, because we want know if formula has error.
|
||||||
|
m_pTokenReader->IgnoreUndefVar(true);
|
||||||
Eval();
|
Eval();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -881,11 +881,8 @@ qreal VMeasurements::EvalFormula(VContainer *data, const QString &formula, bool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
QString f = formula;
|
|
||||||
f.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
const qreal result = cal->EvalFormula(data->DataVariables(), f);
|
const qreal result = cal->EvalFormula(data->DataVariables(), formula);
|
||||||
|
|
||||||
(qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true;
|
(qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true;
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -53,11 +53,15 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Calculator::Calculator()
|
Calculator::Calculator()
|
||||||
:QmuFormulaBase()
|
: QmuFormulaBase(),
|
||||||
|
m_varsValues(),
|
||||||
|
m_vars(nullptr)
|
||||||
{
|
{
|
||||||
InitCharSets();
|
InitCharSets();
|
||||||
setAllowSubexpressions(false);//Only one expression per time
|
|
||||||
|
|
||||||
|
// Parser doesn't know any variable on this stage. So, we just use variable factory that for each unknown variable
|
||||||
|
// set value to 0.
|
||||||
|
SetVarFactory(VarFactory, this);
|
||||||
SetSepForEval();
|
SetSepForEval();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,71 +86,33 @@ qreal Calculator::EvalFormula(const QHash<QString, QSharedPointer<VInternalVaria
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parser doesn't know any variable on this stage. So, we just use variable factory that for each unknown variable
|
|
||||||
// set value to 0.
|
|
||||||
SetVarFactory(AddVariable, this);
|
|
||||||
SetSepForEval();//Reset separators options
|
SetSepForEval();//Reset separators options
|
||||||
|
m_vars = vars;
|
||||||
SetExpr(formula);
|
SetExpr(formula);
|
||||||
|
|
||||||
result = Eval();
|
m_pTokenReader->IgnoreUndefVar(true);
|
||||||
|
|
||||||
QMap<int, QString> tokens = this->GetTokens();
|
|
||||||
|
|
||||||
// Remove "-" from tokens list if exist. If don't do that unary minus operation will broken.
|
|
||||||
RemoveAll(tokens, QStringLiteral("-"));
|
|
||||||
|
|
||||||
for (int i = 0; i < builInFunctions.size(); ++i)
|
|
||||||
{
|
|
||||||
if (tokens.isEmpty())
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
RemoveAll(tokens, builInFunctions.at(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokens.isEmpty())
|
|
||||||
{
|
|
||||||
return result; // We have found only numbers in expression.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add variables to parser because we have deal with expression with variables.
|
|
||||||
InitVariables(vars, tokens, formula);
|
|
||||||
return Eval();
|
return Eval();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
qreal *Calculator::VarFactory(const QString &a_szName, void *a_pUserData)
|
||||||
* @brief Calculator::InitVariables add variables to parser.
|
|
||||||
*
|
|
||||||
* For optimization purpose we try don't add variables that we don't need.
|
|
||||||
*
|
|
||||||
* @param vars list of variables.
|
|
||||||
* @param tokens all tokens (measurements names, variables with lengths) that parser have found in expression.
|
|
||||||
* @param formula expression, need for throwing better error message.
|
|
||||||
*/
|
|
||||||
void Calculator::InitVariables(const QHash<QString, QSharedPointer<VInternalVariable> > *vars,
|
|
||||||
const QMap<int, QString> &tokens, const QString &formula)
|
|
||||||
{
|
{
|
||||||
QMap<int, QString>::const_iterator i = tokens.constBegin();
|
Q_UNUSED(a_szName)
|
||||||
while (i != tokens.constEnd())
|
Calculator *calc = static_cast<Calculator *>(a_pUserData);
|
||||||
|
|
||||||
|
if (calc->m_vars != nullptr && calc->m_vars->contains(a_szName))
|
||||||
{
|
{
|
||||||
bool found = false;
|
QSharedPointer<qreal> val(new qreal(*calc->m_vars->value(a_szName)->GetValue()));
|
||||||
if (vars->contains(i.value()))
|
calc->m_varsValues.append(val);
|
||||||
{
|
return val.data();
|
||||||
DefineVar(i.value(), vars->value(i.value())->GetValue());
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found == false && builInFunctions.contains(i.value()))
|
|
||||||
{// We have found built-in function
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found == false)
|
|
||||||
{
|
|
||||||
throw qmu::QmuParserError (qmu::ecUNASSIGNABLE_TOKEN, i.value(), formula, i.key());
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a_szName.startsWith('#'))
|
||||||
|
{
|
||||||
|
QSharedPointer<qreal> val(new qreal(0));
|
||||||
|
calc->m_varsValues.append(val);
|
||||||
|
return val.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw qmu::QmuParserError (qmu::ecUNASSIGNABLE_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,11 +64,12 @@ public:
|
||||||
virtual ~Calculator() Q_DECL_EQ_DEFAULT;
|
virtual ~Calculator() Q_DECL_EQ_DEFAULT;
|
||||||
|
|
||||||
qreal EvalFormula(const QHash<QString, QSharedPointer<VInternalVariable> > *vars, const QString &formula);
|
qreal EvalFormula(const QHash<QString, QSharedPointer<VInternalVariable> > *vars, const QString &formula);
|
||||||
|
protected:
|
||||||
|
static qreal* VarFactory(const QString &a_szName, void *a_pUserData);
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(Calculator)
|
Q_DISABLE_COPY(Calculator)
|
||||||
|
QVector<QSharedPointer<qreal>> m_varsValues;
|
||||||
void InitVariables(const QHash<QString, QSharedPointer<VInternalVariable> > *vars, const QMap<int, QString> &tokens,
|
const QHash<QString, QSharedPointer<VInternalVariable> > *m_vars;
|
||||||
const QString &formula);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CALCULATOR_H
|
#endif // CALCULATOR_H
|
||||||
|
|
|
@ -65,9 +65,7 @@ VFormula::VFormula(const QString &formula, const VContainer *container)
|
||||||
postfix(QString()),
|
postfix(QString()),
|
||||||
_error(true),
|
_error(true),
|
||||||
dValue(0)
|
dValue(0)
|
||||||
{
|
{}
|
||||||
this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VFormula &VFormula::operator=(const VFormula &formula)
|
VFormula &VFormula::operator=(const VFormula &formula)
|
||||||
|
@ -145,7 +143,6 @@ void VFormula::SetFormula(const QString &value, FormulaType type)
|
||||||
{
|
{
|
||||||
formula = value;
|
formula = value;
|
||||||
}
|
}
|
||||||
formula.replace("\n", " ");// Replace line return with spaces for calc if exist
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,6 @@ qreal EvalFormula(const VContainer *data, QString formula)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
formula.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
const qreal result = cal->EvalFormula(data->DataVariables(), formula);
|
const qreal result = cal->EvalFormula(data->DataVariables(), formula);
|
||||||
|
|
||||||
|
|
|
@ -800,11 +800,8 @@ bool VPiecePath::IsVisible(const QHash<QString, QSharedPointer<VInternalVariable
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QString formula = GetVisibilityTrigger();
|
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
formula.replace("\n", " ");
|
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
const qreal result = cal->EvalFormula(vars, formula);
|
const qreal result = cal->EvalFormula(vars, GetVisibilityTrigger());
|
||||||
|
|
||||||
if (qIsInf(result) || qIsNaN(result))
|
if (qIsInf(result) || qIsNaN(result))
|
||||||
{
|
{
|
||||||
|
|
|
@ -129,7 +129,6 @@ DialogEditWrongFormula::~DialogEditWrongFormula()
|
||||||
void DialogEditWrongFormula::DialogAccepted()
|
void DialogEditWrongFormula::DialogAccepted()
|
||||||
{
|
{
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
emit DialogClosed(QDialog::Accepted);
|
emit DialogClosed(QDialog::Accepted);
|
||||||
accepted();
|
accepted();
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,6 @@ void DialogAlongLine::SaveData()
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
|
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis);
|
VisToolAlongLine *line = qobject_cast<VisToolAlongLine *>(vis);
|
||||||
SCASSERT(line != nullptr)
|
SCASSERT(line != nullptr)
|
||||||
|
|
|
@ -277,11 +277,8 @@ void DialogArc::ShowVisualization()
|
||||||
void DialogArc::SaveData()
|
void DialogArc::SaveData()
|
||||||
{
|
{
|
||||||
radius = ui->plainTextEditFormula->toPlainText();
|
radius = ui->plainTextEditFormula->toPlainText();
|
||||||
radius.replace("\n", " ");
|
|
||||||
f1 = ui->plainTextEditF1->toPlainText();
|
f1 = ui->plainTextEditF1->toPlainText();
|
||||||
f1.replace("\n", " ");
|
|
||||||
f2 = ui->plainTextEditF2->toPlainText();
|
f2 = ui->plainTextEditF2->toPlainText();
|
||||||
f2.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolArc *path = qobject_cast<VisToolArc *>(vis);
|
VisToolArc *path = qobject_cast<VisToolArc *>(vis);
|
||||||
SCASSERT(path != nullptr)
|
SCASSERT(path != nullptr)
|
||||||
|
|
|
@ -354,13 +354,8 @@ void DialogArcWithLength::ShowVisualization()
|
||||||
void DialogArcWithLength::SaveData()
|
void DialogArcWithLength::SaveData()
|
||||||
{
|
{
|
||||||
radius = ui->plainTextEditRadius->toPlainText();
|
radius = ui->plainTextEditRadius->toPlainText();
|
||||||
radius.replace("\n", " ");
|
|
||||||
|
|
||||||
f1 = ui->plainTextEditF1->toPlainText();
|
f1 = ui->plainTextEditF1->toPlainText();
|
||||||
f1.replace("\n", " ");
|
|
||||||
|
|
||||||
length = ui->plainTextEditLength->toPlainText();
|
length = ui->plainTextEditLength->toPlainText();
|
||||||
length.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolArcWithLength *path = qobject_cast<VisToolArcWithLength *>(vis);
|
VisToolArcWithLength *path = qobject_cast<VisToolArcWithLength *>(vis);
|
||||||
SCASSERT(path != nullptr)
|
SCASSERT(path != nullptr)
|
||||||
|
|
|
@ -319,9 +319,7 @@ void DialogBisector::SetLineColor(const QString &value)
|
||||||
void DialogBisector::SaveData()
|
void DialogBisector::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
|
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolBisector *line = qobject_cast<VisToolBisector *>(vis);
|
VisToolBisector *line = qobject_cast<VisToolBisector *>(vis);
|
||||||
SCASSERT(line != nullptr)
|
SCASSERT(line != nullptr)
|
||||||
|
|
|
@ -308,9 +308,7 @@ void DialogCurveIntersectAxis::ShowVisualization()
|
||||||
void DialogCurveIntersectAxis::SaveData()
|
void DialogCurveIntersectAxis::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
|
|
||||||
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
||||||
formulaAngle.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
||||||
SCASSERT(line != nullptr)
|
SCASSERT(line != nullptr)
|
||||||
|
|
|
@ -144,7 +144,6 @@ void DialogCutArc::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
|
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
|
||||||
SCASSERT(path != nullptr)
|
SCASSERT(path != nullptr)
|
||||||
|
|
|
@ -160,7 +160,6 @@ void DialogCutSpline::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
|
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
|
||||||
SCASSERT(path != nullptr)
|
SCASSERT(path != nullptr)
|
||||||
|
|
|
@ -160,7 +160,6 @@ void DialogCutSplinePath::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolCutSplinePath *path = qobject_cast<VisToolCutSplinePath *>(vis);
|
VisToolCutSplinePath *path = qobject_cast<VisToolCutSplinePath *>(vis);
|
||||||
SCASSERT(path != nullptr)
|
SCASSERT(path != nullptr)
|
||||||
|
|
|
@ -612,15 +612,10 @@ void DialogEllipticalArc::ShowVisualization()
|
||||||
void DialogEllipticalArc::SaveData()
|
void DialogEllipticalArc::SaveData()
|
||||||
{
|
{
|
||||||
radius1 = ui->plainTextEditRadius1->toPlainText();
|
radius1 = ui->plainTextEditRadius1->toPlainText();
|
||||||
radius1.replace("\n", " ");
|
|
||||||
radius2 = ui->plainTextEditRadius2->toPlainText();
|
radius2 = ui->plainTextEditRadius2->toPlainText();
|
||||||
radius2.replace("\n", " ");
|
|
||||||
f1 = ui->plainTextEditF1->toPlainText();
|
f1 = ui->plainTextEditF1->toPlainText();
|
||||||
f1.replace("\n", " ");
|
|
||||||
f2 = ui->plainTextEditF2->toPlainText();
|
f2 = ui->plainTextEditF2->toPlainText();
|
||||||
f2.replace("\n", " ");
|
|
||||||
rotationAngle = ui->plainTextEditRotationAngle->toPlainText();
|
rotationAngle = ui->plainTextEditRotationAngle->toPlainText();
|
||||||
rotationAngle.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
|
VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
|
||||||
SCASSERT(path != nullptr)
|
SCASSERT(path != nullptr)
|
||||||
|
|
|
@ -344,12 +344,8 @@ void DialogEndLine::ShowVisualization()
|
||||||
void DialogEndLine::SaveData()
|
void DialogEndLine::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
|
|
||||||
formulaLength = ui->plainTextEditFormula->toPlainText();
|
formulaLength = ui->plainTextEditFormula->toPlainText();
|
||||||
formulaLength.replace("\n", " ");
|
|
||||||
|
|
||||||
formulaAngle = ui->plainTextEditAngle->toPlainText();
|
formulaAngle = ui->plainTextEditAngle->toPlainText();
|
||||||
formulaAngle.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolEndLine *line = qobject_cast<VisToolEndLine *>(vis);
|
VisToolEndLine *line = qobject_cast<VisToolEndLine *>(vis);
|
||||||
SCASSERT(line != nullptr)
|
SCASSERT(line != nullptr)
|
||||||
|
|
|
@ -375,9 +375,7 @@ void DialogLineIntersectAxis::ShowVisualization()
|
||||||
void DialogLineIntersectAxis::SaveData()
|
void DialogLineIntersectAxis::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
|
|
||||||
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
||||||
formulaAngle.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolLineIntersectAxis *line = qobject_cast<VisToolLineIntersectAxis *>(vis);
|
VisToolLineIntersectAxis *line = qobject_cast<VisToolLineIntersectAxis *>(vis);
|
||||||
SCASSERT(line != nullptr)
|
SCASSERT(line != nullptr)
|
||||||
|
|
|
@ -513,15 +513,9 @@ void DialogMove::ShowVisualization()
|
||||||
void DialogMove::SaveData()
|
void DialogMove::SaveData()
|
||||||
{
|
{
|
||||||
m_suffix = ui->lineEditSuffix->text();
|
m_suffix = ui->lineEditSuffix->text();
|
||||||
|
|
||||||
formulaAngle = ui->plainTextEditAngle->toPlainText();
|
formulaAngle = ui->plainTextEditAngle->toPlainText();
|
||||||
formulaAngle.replace("\n", " ");
|
|
||||||
|
|
||||||
formulaRotationAngle = ui->plainTextEditRotationAngle->toPlainText();
|
formulaRotationAngle = ui->plainTextEditRotationAngle->toPlainText();
|
||||||
formulaRotationAngle.replace("\n", " ");
|
|
||||||
|
|
||||||
formulaLength = ui->plainTextEditLength->toPlainText();
|
formulaLength = ui->plainTextEditLength->toPlainText();
|
||||||
formulaLength.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolMove *operation = qobject_cast<VisToolMove *>(vis);
|
VisToolMove *operation = qobject_cast<VisToolMove *>(vis);
|
||||||
SCASSERT(operation != nullptr)
|
SCASSERT(operation != nullptr)
|
||||||
|
|
|
@ -198,7 +198,6 @@ void DialogNormal::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
angle = ui->doubleSpinBoxAngle->value();
|
angle = ui->doubleSpinBoxAngle->value();
|
||||||
|
|
||||||
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
|
VisToolNormal *line = qobject_cast<VisToolNormal *>(vis);
|
||||||
|
|
|
@ -302,15 +302,12 @@ void DialogPointFromCircleAndTangent::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
|
|
||||||
QString radius = ui->plainTextEditRadius->toPlainText();
|
|
||||||
radius.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
||||||
SCASSERT(point != nullptr)
|
SCASSERT(point != nullptr)
|
||||||
|
|
||||||
point->setObject1Id(GetTangentPointId());
|
point->setObject1Id(GetTangentPointId());
|
||||||
point->setObject2Id(GetCircleCenterId());
|
point->setObject2Id(GetCircleCenterId());
|
||||||
point->setCRadius(radius);
|
point->setCRadius(ui->plainTextEditRadius->toPlainText());
|
||||||
point->setCrossPoint(GetCrossCirclesPoint());
|
point->setCrossPoint(GetCrossCirclesPoint());
|
||||||
point->RefreshGeometry();
|
point->RefreshGeometry();
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,6 @@ void DialogPointOfContact::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
radius = ui->plainTextEditFormula->toPlainText();
|
radius = ui->plainTextEditFormula->toPlainText();
|
||||||
radius.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
|
VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
|
||||||
SCASSERT(line != nullptr)
|
SCASSERT(line != nullptr)
|
||||||
|
|
|
@ -389,19 +389,13 @@ void DialogPointOfIntersectionCircles::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
|
|
||||||
QString c1Radius = ui->plainTextEditCircle2Radius->toPlainText();
|
|
||||||
c1Radius.replace("\n", " ");
|
|
||||||
|
|
||||||
QString c2Radius = ui->plainTextEditCircle2Radius->toPlainText();
|
|
||||||
c2Radius.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolPointOfIntersectionCircles *point = qobject_cast<VisToolPointOfIntersectionCircles *>(vis);
|
VisToolPointOfIntersectionCircles *point = qobject_cast<VisToolPointOfIntersectionCircles *>(vis);
|
||||||
SCASSERT(point != nullptr)
|
SCASSERT(point != nullptr)
|
||||||
|
|
||||||
point->setObject1Id(GetFirstCircleCenterId());
|
point->setObject1Id(GetFirstCircleCenterId());
|
||||||
point->setObject2Id(GetSecondCircleCenterId());
|
point->setObject2Id(GetSecondCircleCenterId());
|
||||||
point->setC1Radius(c1Radius);
|
point->setC1Radius(ui->plainTextEditCircle2Radius->toPlainText());
|
||||||
point->setC2Radius(c2Radius);
|
point->setC2Radius(ui->plainTextEditCircle2Radius->toPlainText());
|
||||||
point->setCrossPoint(GetCrossCirclesPoint());
|
point->setCrossPoint(GetCrossCirclesPoint());
|
||||||
point->RefreshGeometry();
|
point->RefreshGeometry();
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,9 +372,7 @@ void DialogRotation::ShowVisualization()
|
||||||
void DialogRotation::SaveData()
|
void DialogRotation::SaveData()
|
||||||
{
|
{
|
||||||
m_suffix = ui->lineEditSuffix->text();
|
m_suffix = ui->lineEditSuffix->text();
|
||||||
|
|
||||||
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
||||||
formulaAngle.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
||||||
SCASSERT(operation != nullptr)
|
SCASSERT(operation != nullptr)
|
||||||
|
|
|
@ -224,7 +224,6 @@ void DialogShoulderPoint::SaveData()
|
||||||
{
|
{
|
||||||
pointName = ui->lineEditNamePoint->text();
|
pointName = ui->lineEditNamePoint->text();
|
||||||
formula = ui->plainTextEditFormula->toPlainText();
|
formula = ui->plainTextEditFormula->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
|
|
||||||
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
|
VisToolShoulderPoint *line = qobject_cast<VisToolShoulderPoint *>(vis);
|
||||||
SCASSERT(line != nullptr)
|
SCASSERT(line != nullptr)
|
||||||
|
|
|
@ -444,16 +444,9 @@ void DialogSpline::EvalLength2()
|
||||||
VSpline DialogSpline::CurrentSpline() const
|
VSpline DialogSpline::CurrentSpline() const
|
||||||
{
|
{
|
||||||
QString angle1F = ui->plainTextEditAngle1F->toPlainText();
|
QString angle1F = ui->plainTextEditAngle1F->toPlainText();
|
||||||
angle1F.replace("\n", " ");
|
|
||||||
|
|
||||||
QString angle2F = ui->plainTextEditAngle2F->toPlainText();
|
QString angle2F = ui->plainTextEditAngle2F->toPlainText();
|
||||||
angle2F.replace("\n", " ");
|
|
||||||
|
|
||||||
QString length1F = ui->plainTextEditLength1F->toPlainText();
|
QString length1F = ui->plainTextEditLength1F->toPlainText();
|
||||||
length1F.replace("\n", " ");
|
|
||||||
|
|
||||||
QString length2F = ui->plainTextEditLength2F->toPlainText();
|
QString length2F = ui->plainTextEditLength2F->toPlainText();
|
||||||
length2F.replace("\n", " ");
|
|
||||||
|
|
||||||
const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables();
|
const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables();
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,7 @@ void DialogSplinePath::Angle1Changed()
|
||||||
SCASSERT(item != nullptr)
|
SCASSERT(item != nullptr)
|
||||||
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
||||||
|
|
||||||
const QString angle1F = ui->plainTextEditAngle1F->toPlainText().replace("\n", " ");
|
const QString angle1F = ui->plainTextEditAngle1F->toPlainText();
|
||||||
const qreal angle1 = Visualization::FindValFromUser(angle1F, data->DataVariables());
|
const qreal angle1 = Visualization::FindValFromUser(angle1F, data->DataVariables());
|
||||||
p.SetAngle1(angle1, VTranslateVars::TryFormulaFromUser(angle1F, qApp->Settings()->GetOsSeparator()));
|
p.SetAngle1(angle1, VTranslateVars::TryFormulaFromUser(angle1F, qApp->Settings()->GetOsSeparator()));
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ void DialogSplinePath::Angle2Changed()
|
||||||
SCASSERT(item != nullptr)
|
SCASSERT(item != nullptr)
|
||||||
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
||||||
|
|
||||||
const QString angle2F = ui->plainTextEditAngle2F->toPlainText().replace("\n", " ");
|
const QString angle2F = ui->plainTextEditAngle2F->toPlainText();
|
||||||
const qreal angle2 = Visualization::FindValFromUser(angle2F, data->DataVariables());
|
const qreal angle2 = Visualization::FindValFromUser(angle2F, data->DataVariables());
|
||||||
p.SetAngle2(angle2, VTranslateVars::TryFormulaFromUser(angle2F, qApp->Settings()->GetOsSeparator()));
|
p.SetAngle2(angle2, VTranslateVars::TryFormulaFromUser(angle2F, qApp->Settings()->GetOsSeparator()));
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@ void DialogSplinePath::Length1Changed()
|
||||||
SCASSERT(item != nullptr)
|
SCASSERT(item != nullptr)
|
||||||
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
||||||
|
|
||||||
const QString length1F = ui->plainTextEditLength1F->toPlainText().replace("\n", " ");
|
const QString length1F = ui->plainTextEditLength1F->toPlainText();
|
||||||
const qreal length1 = Visualization::FindLengthFromUser(length1F, data->DataVariables());
|
const qreal length1 = Visualization::FindLengthFromUser(length1F, data->DataVariables());
|
||||||
p.SetLength1(length1, VTranslateVars::TryFormulaFromUser(length1F, qApp->Settings()->GetOsSeparator()));
|
p.SetLength1(length1, VTranslateVars::TryFormulaFromUser(length1F, qApp->Settings()->GetOsSeparator()));
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ void DialogSplinePath::Length2Changed()
|
||||||
SCASSERT(item != nullptr)
|
SCASSERT(item != nullptr)
|
||||||
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
||||||
|
|
||||||
const QString length2F = ui->plainTextEditLength2F->toPlainText().replace("\n", " ");
|
const QString length2F = ui->plainTextEditLength2F->toPlainText();
|
||||||
const qreal length2 = Visualization::FindLengthFromUser(length2F, data->DataVariables());
|
const qreal length2 = Visualization::FindLengthFromUser(length2F, data->DataVariables());
|
||||||
p.SetLength2(length2, VTranslateVars::TryFormulaFromUser(length2F, qApp->Settings()->GetOsSeparator()));
|
p.SetLength2(length2, VTranslateVars::TryFormulaFromUser(length2F, qApp->Settings()->GetOsSeparator()));
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ 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 = VTranslateVars::TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText().replace("\n", " "),
|
QString angle1F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator());
|
qApp->Settings()->GetOsSeparator());
|
||||||
|
|
||||||
dialog->SetFormula(angle1F);
|
dialog->SetFormula(angle1F);
|
||||||
|
@ -440,7 +440,7 @@ 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 = VTranslateVars::TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText().replace("\n", " "),
|
QString angle2F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator());
|
qApp->Settings()->GetOsSeparator());
|
||||||
|
|
||||||
dialog->SetFormula(angle2F);
|
dialog->SetFormula(angle2F);
|
||||||
|
@ -465,7 +465,7 @@ 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 = VTranslateVars::TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText().replace("\n", " "),
|
QString length1F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator());
|
qApp->Settings()->GetOsSeparator());
|
||||||
|
|
||||||
dialog->SetFormula(length1F);
|
dialog->SetFormula(length1F);
|
||||||
|
@ -490,7 +490,7 @@ 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 = VTranslateVars::TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText().replace("\n", " "),
|
QString length2F = VTranslateVars::TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator());
|
qApp->Settings()->GetOsSeparator());
|
||||||
|
|
||||||
dialog->SetFormula(length2F);
|
dialog->SetFormula(length2F);
|
||||||
|
|
|
@ -77,7 +77,7 @@ template <class T> class QSharedPointer;
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(vDialog, "v.dialog")
|
Q_LOGGING_CATEGORY(vDialog, "v.dialog")
|
||||||
|
|
||||||
#define DIALOG_MAX_FORMULA_HEIGHT 64
|
#define DIALOG_MAX_FORMULA_HEIGHT 80
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -401,12 +401,7 @@ bool DialogTool::eventFilter(QObject *object, QEvent *event)
|
||||||
if (event->type() == QEvent::KeyPress)
|
if (event->type() == QEvent::KeyPress)
|
||||||
{
|
{
|
||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||||
if ((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return))
|
if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
|
||||||
{
|
|
||||||
// Ignore Enter key
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
|
|
||||||
{
|
{
|
||||||
if (qApp->Settings()->GetOsSeparator())
|
if (qApp->Settings()->GetOsSeparator())
|
||||||
{
|
{
|
||||||
|
@ -799,11 +794,8 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Replace line return character with spaces for calc if exist
|
|
||||||
QString formula = text;
|
|
||||||
formula.replace("\n", " ");
|
|
||||||
// Translate to internal look.
|
// Translate to internal look.
|
||||||
formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
QString formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator());
|
||||||
QScopedPointer<Calculator> cal(new Calculator());
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
result = cal->EvalFormula(data->DataVariables(), formula);
|
result = cal->EvalFormula(data->DataVariables(), formula);
|
||||||
|
|
||||||
|
|
|
@ -1201,7 +1201,6 @@ void DialogPiecePath::SetPieceId(quint32 id)
|
||||||
QString DialogPiecePath::GetFormulaSAWidth() const
|
QString DialogPiecePath::GetFormulaSAWidth() const
|
||||||
{
|
{
|
||||||
QString width = ui->plainTextEditFormulaWidth->toPlainText();
|
QString width = ui->plainTextEditFormulaWidth->toPlainText();
|
||||||
width.replace("\n", " ");
|
|
||||||
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1305,7 +1304,6 @@ void DialogPiecePath::NewItem(const VPieceNode &node)
|
||||||
QString DialogPiecePath::GetFormulaSAWidthBefore() const
|
QString DialogPiecePath::GetFormulaSAWidthBefore() const
|
||||||
{
|
{
|
||||||
QString width = ui->plainTextEditFormulaWidthBefore->toPlainText();
|
QString width = ui->plainTextEditFormulaWidthBefore->toPlainText();
|
||||||
width.replace("\n", " ");
|
|
||||||
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1313,7 +1311,6 @@ QString DialogPiecePath::GetFormulaSAWidthBefore() const
|
||||||
QString DialogPiecePath::GetFormulaSAWidthAfter() const
|
QString DialogPiecePath::GetFormulaSAWidthAfter() const
|
||||||
{
|
{
|
||||||
QString width = ui->plainTextEditFormulaWidthAfter->toPlainText();
|
QString width = ui->plainTextEditFormulaWidthAfter->toPlainText();
|
||||||
width.replace("\n", " ");
|
|
||||||
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1321,7 +1318,6 @@ QString DialogPiecePath::GetFormulaSAWidthAfter() const
|
||||||
QString DialogPiecePath::GetFormulaVisible() const
|
QString DialogPiecePath::GetFormulaVisible() const
|
||||||
{
|
{
|
||||||
QString formula = ui->plainTextEditFormulaVisible->toPlainText();
|
QString formula = ui->plainTextEditFormulaVisible->toPlainText();
|
||||||
formula.replace("\n", " ");
|
|
||||||
return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ void DialogPlaceLabel::SetLabelType(PlaceLabelType type)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString DialogPlaceLabel::GetWidth() const
|
QString DialogPlaceLabel::GetWidth() const
|
||||||
{
|
{
|
||||||
return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaWidth->toPlainText().replace("\n", " "),
|
return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaWidth->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator());
|
qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ void DialogPlaceLabel::SetWidth(const QString &value)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString DialogPlaceLabel::GetHeight() const
|
QString DialogPlaceLabel::GetHeight() const
|
||||||
{
|
{
|
||||||
return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaHeight->toPlainText().replace("\n", " "),
|
return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaHeight->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator());
|
qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ void DialogPlaceLabel::SetHeight(const QString &value)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString DialogPlaceLabel::GetAngle() const
|
QString DialogPlaceLabel::GetAngle() const
|
||||||
{
|
{
|
||||||
return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaAngle->toPlainText().replace("\n", " "),
|
return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormulaAngle->toPlainText(),
|
||||||
qApp->Settings()->GetOsSeparator());
|
qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,10 +72,7 @@ void EnableDefButton(QPushButton *defButton, const QString &formula)
|
||||||
QString GetFormulaFromUser(QPlainTextEdit *textEdit)
|
QString GetFormulaFromUser(QPlainTextEdit *textEdit)
|
||||||
{
|
{
|
||||||
SCASSERT(textEdit != nullptr)
|
SCASSERT(textEdit != nullptr)
|
||||||
|
return qApp->TrVars()->TryFormulaFromUser(textEdit->toPlainText(), qApp->Settings()->GetOsSeparator());
|
||||||
QString formula = textEdit->toPlainText();
|
|
||||||
formula.replace("\n", " ");
|
|
||||||
return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1515,7 +1512,6 @@ void DialogSeamAllowance::UpdateGrainlineValues()
|
||||||
QString qsVal;
|
QString qsVal;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
qsFormula.replace("\n", " ");
|
|
||||||
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
||||||
Calculator cal;
|
Calculator cal;
|
||||||
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
|
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
|
||||||
|
@ -1597,7 +1593,7 @@ void DialogSeamAllowance::UpdateDetailLabelValues()
|
||||||
QString qsVal;
|
QString qsVal;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
qsFormula.replace("\n", " ");
|
|
||||||
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
||||||
Calculator cal;
|
Calculator cal;
|
||||||
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
|
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
|
||||||
|
@ -1683,7 +1679,6 @@ void DialogSeamAllowance::UpdatePatternLabelValues()
|
||||||
QString qsVal;
|
QString qsVal;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
qsFormula.replace("\n", " ");
|
|
||||||
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
||||||
Calculator cal;
|
Calculator cal;
|
||||||
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
|
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
|
||||||
|
@ -1814,7 +1809,6 @@ void DialogSeamAllowance::EditGrainlineFormula()
|
||||||
if (dlg.exec() == QDialog::Accepted)
|
if (dlg.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
QString qsFormula = dlg.GetFormula();
|
QString qsFormula = dlg.GetFormula();
|
||||||
qsFormula.replace("\n", " ");
|
|
||||||
|
|
||||||
if (sender() == uiTabGrainline->pushButtonLen)
|
if (sender() == uiTabGrainline->pushButtonLen)
|
||||||
{
|
{
|
||||||
|
@ -1871,7 +1865,6 @@ void DialogSeamAllowance::EditDLFormula()
|
||||||
if (dlg.exec() == QDialog::Accepted)
|
if (dlg.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
QString qsFormula = dlg.GetFormula();
|
QString qsFormula = dlg.GetFormula();
|
||||||
qsFormula.replace("\n", " ");
|
|
||||||
if (sender() == uiTabLabels->pushButtonDLHeight)
|
if (sender() == uiTabLabels->pushButtonDLHeight)
|
||||||
{
|
{
|
||||||
SetDLHeight(qsFormula);
|
SetDLHeight(qsFormula);
|
||||||
|
@ -1931,7 +1924,6 @@ void DialogSeamAllowance::EditPLFormula()
|
||||||
if (dlg.exec() == QDialog::Accepted)
|
if (dlg.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
QString qsFormula = dlg.GetFormula();
|
QString qsFormula = dlg.GetFormula();
|
||||||
qsFormula.replace("\n", " ");
|
|
||||||
if (sender() == uiTabLabels->pushButtonPLHeight)
|
if (sender() == uiTabLabels->pushButtonPLHeight)
|
||||||
{
|
{
|
||||||
SetPLHeight(qsFormula);
|
SetPLHeight(qsFormula);
|
||||||
|
@ -2965,7 +2957,6 @@ void DialogSeamAllowance::InitAllPinComboboxes()
|
||||||
QString DialogSeamAllowance::GetFormulaSAWidth() const
|
QString DialogSeamAllowance::GetFormulaSAWidth() const
|
||||||
{
|
{
|
||||||
QString width = uiTabPaths->plainTextEditFormulaWidth->toPlainText();
|
QString width = uiTabPaths->plainTextEditFormulaWidth->toPlainText();
|
||||||
width.replace("\n", " ");
|
|
||||||
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,6 @@ qreal Visualization::FindValFromUser(const QString &expression,
|
||||||
{
|
{
|
||||||
// Replace line return with spaces for calc if exist
|
// Replace line return with spaces for calc if exist
|
||||||
QString formula = expression;
|
QString formula = expression;
|
||||||
formula.replace("\n", " ");
|
|
||||||
if (fromUser)
|
if (fromUser)
|
||||||
{
|
{
|
||||||
formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user