Refactoring.
This commit is contained in:
parent
4dd7b93aab
commit
7ae794e0b7
|
@ -48,7 +48,6 @@
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VTranslateVars::VTranslateVars()
|
||||
:VTranslateMeasurements()
|
||||
{
|
||||
InitPatternMakingSystems();
|
||||
InitVariables();
|
||||
|
@ -545,8 +544,8 @@ void VTranslateVars::InitFunctions()
|
|||
|
||||
functions.insert(csrInch_F, translate("VTranslateVars", "csrInch", "cut, split and rotate modeling operation. Takes"
|
||||
" inch units."));
|
||||
functionsDescriptions.insert(csrInch_F, translate("VTranslateVars", "cut, split and rotate modeling operation. Takes"
|
||||
" inch units.", "function csrInch"));
|
||||
functionsDescriptions.insert(csrInch_F, translate("VTranslateVars", "cut, split and rotate modeling operation. "
|
||||
"Takes inch units.", "function csrInch"));
|
||||
functionsArguments.insert(csrInch_F, threeArguments);
|
||||
|
||||
functions.insert(abs_F, translate("VTranslateVars", "abs", "absolute value"));
|
||||
|
@ -622,7 +621,7 @@ void VTranslateVars::InitSystem(const QString &code, const qmu::QmuTranslation &
|
|||
* @param numbers all numbers
|
||||
*/
|
||||
void VTranslateVars::CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens,
|
||||
QMap<int, QString> &numbers) const
|
||||
QMap<int, QString> &numbers)
|
||||
{
|
||||
if (bias == 0)
|
||||
{
|
||||
|
@ -633,6 +632,188 @@ void VTranslateVars::CorrectionsPositions(int position, int bias, QMap<int, QStr
|
|||
BiasTokens(position, bias, numbers);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTranslateVars::TranslateVarsFromUser(QString &newFormula, QMap<int, QString> &tokens,
|
||||
QMap<int, QString> &numbers) const
|
||||
{
|
||||
QList<int> tKeys = tokens.keys();// Take all tokens positions
|
||||
QList<QString> tValues = tokens.values();
|
||||
for (int i = 0; i < tKeys.size(); ++i)
|
||||
{
|
||||
int bias = 0;
|
||||
if (MeasurementsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position of next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (VariablesFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position of next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FunctionsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position of next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tValues.at(i) == QLocale().negativeSign())
|
||||
{// unary minus
|
||||
newFormula.replace(tKeys.at(i), 1, '-');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTranslateVars::TranslateNumbersFromUser(QString &newFormula, QMap<int, QString> &tokens,
|
||||
QMap<int, QString> &numbers, bool osSeparator)
|
||||
{
|
||||
QLocale loc = QLocale(); // User locale
|
||||
if (loc != QLocale::c() && osSeparator)
|
||||
{// User want use Os separator
|
||||
QList<int> nKeys = numbers.keys();// Positions for all numbers in expression
|
||||
QList<QString> nValues = numbers.values();
|
||||
for (int i = 0; i < nKeys.size(); ++i)
|
||||
{
|
||||
loc = QLocale();// From system locale
|
||||
bool ok = false;
|
||||
const qreal d = loc.toDouble(nValues.at(i), &ok);
|
||||
if (not ok)
|
||||
{
|
||||
qDebug()<<"Can't convert to double token"<<nValues.at(i);
|
||||
continue;//Leave with out translation
|
||||
}
|
||||
|
||||
loc = QLocale::c();// To internal locale
|
||||
const QString dStr = loc.toString(d);// Internal look for number
|
||||
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
|
||||
const int bias = nValues.at(i).length() - dStr.length();
|
||||
if (bias != 0)
|
||||
{// Translated number has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
|
||||
nKeys = numbers.keys();
|
||||
nValues = numbers.values();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTranslateVars::TranslateVarsToUser(QString &newFormula, QMap<int, QString> &tokens,
|
||||
QMap<int, QString> &numbers) const
|
||||
{
|
||||
QList<int> tKeys = tokens.keys();
|
||||
QList<QString> tValues = tokens.values();
|
||||
for (int i = 0; i < tKeys.size(); ++i)
|
||||
{
|
||||
if (measurements.contains(tValues.at(i)))
|
||||
{
|
||||
newFormula.replace(tKeys.at(i), tValues.at(i).length(),
|
||||
measurements.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
||||
int bias = tValues.at(i).length() -
|
||||
measurements.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()).length();
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (functions.contains(tValues.at(i)))
|
||||
{
|
||||
newFormula.replace(tKeys.at(i), tValues.at(i).length(),
|
||||
functions.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
||||
int bias = tValues.at(i).length() -
|
||||
functions.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()).length();
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int bias = 0;
|
||||
if (VariablesToUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tValues.at(i) == QChar('-'))
|
||||
{// unary minus
|
||||
newFormula.replace(tKeys.at(i), 1, QLocale().negativeSign());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTranslateVars::TranslateNumbersToUser(QString &newFormula, QMap<int, QString> &tokens,
|
||||
QMap<int, QString> &numbers, bool osSeparator)
|
||||
{
|
||||
QLocale loc = QLocale();// User locale
|
||||
if (loc != QLocale::C && osSeparator)
|
||||
{// User want use Os separator
|
||||
QList<int> nKeys = numbers.keys();// Positions for all numbers in expression
|
||||
QList<QString> nValues = numbers.values();
|
||||
for (int i = 0; i < nKeys.size(); ++i)
|
||||
{
|
||||
loc = QLocale::c();// From pattern locale
|
||||
bool ok = false;
|
||||
const qreal d = loc.toDouble(nValues.at(i), &ok);
|
||||
if (not ok)
|
||||
{
|
||||
qDebug()<<"Can't convert to double token"<<nValues.at(i);
|
||||
continue;//Leave with out translation
|
||||
}
|
||||
|
||||
loc = QLocale();// To user locale
|
||||
QString dStr = loc.toString(d);// Number string in user locale
|
||||
if (loc.groupSeparator().isSpace())
|
||||
{
|
||||
dStr.replace(loc.groupSeparator(), QString());
|
||||
}
|
||||
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
|
||||
const int bias = nValues.at(i).length() - dStr.length();
|
||||
if (bias != 0)
|
||||
{// Translated number has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
|
||||
nKeys = numbers.keys();
|
||||
nValues = numbers.values();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief BiasTokens change position for each token that have position more then "position".
|
||||
|
@ -670,7 +851,7 @@ void VTranslateVars::BiasTokens(int position, int bias, QMap<int, QString> &toke
|
|||
* @param bias hold change of length between translated and origin token string
|
||||
* @return true if was found variable with same name.
|
||||
*/
|
||||
bool VTranslateVars::VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const
|
||||
auto VTranslateVars::VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const -> bool
|
||||
{
|
||||
const QString currentLengthTr =
|
||||
variables.value(currentLength).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
||||
|
@ -711,7 +892,7 @@ bool VTranslateVars::VariablesFromUser(QString &newFormula, int position, const
|
|||
* @param bias hold change of length between translated and origin token string
|
||||
* @return true if was found function with same name.
|
||||
*/
|
||||
bool VTranslateVars::FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
|
||||
auto VTranslateVars::FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const -> bool
|
||||
{
|
||||
QMap<QString, qmu::QmuTranslation>::const_iterator i = functions.constBegin();
|
||||
while (i != functions.constEnd())
|
||||
|
@ -736,7 +917,7 @@ bool VTranslateVars::FunctionsFromUser(QString &newFormula, int position, const
|
|||
* @param bias hold change of length between translated and origin token string
|
||||
* @return true if was found variable with same name.
|
||||
*/
|
||||
bool VTranslateVars::VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const
|
||||
auto VTranslateVars::VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const -> bool
|
||||
{
|
||||
QMap<QString, qmu::QmuTranslation>::const_iterator i = variables.constBegin();
|
||||
while (i != variables.constEnd())
|
||||
|
@ -764,7 +945,7 @@ bool VTranslateVars::VariablesToUser(QString &newFormula, int position, const QS
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::InternalVarToUser(const QString &var) const
|
||||
auto VTranslateVars::InternalVarToUser(const QString &var) const -> QString
|
||||
{
|
||||
QString newVar = var;
|
||||
int bias = 0;
|
||||
|
@ -772,14 +953,12 @@ QString VTranslateVars::InternalVarToUser(const QString &var) const
|
|||
{
|
||||
return newVar;
|
||||
}
|
||||
else
|
||||
{
|
||||
return var;
|
||||
}
|
||||
|
||||
return var;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::VarToUser(const QString &var) const
|
||||
auto VTranslateVars::VarToUser(const QString &var) const -> QString
|
||||
{
|
||||
if (VAbstractApplication::VApp()->Settings()->GetLocale() == QStringLiteral("zh_CN"))
|
||||
{
|
||||
|
@ -800,7 +979,7 @@ QString VTranslateVars::VarToUser(const QString &var) const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::VarFromUser(const QString &var) const
|
||||
auto VTranslateVars::VarFromUser(const QString &var) const -> QString
|
||||
{
|
||||
if (VAbstractApplication::VApp()->Settings()->GetLocale() == QStringLiteral("zh_CN"))
|
||||
{
|
||||
|
@ -827,19 +1006,19 @@ QString VTranslateVars::VarFromUser(const QString &var) const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::PMSystemName(const QString &code) const
|
||||
auto VTranslateVars::PMSystemName(const QString &code) const -> QString
|
||||
{
|
||||
return PMSystemNames.value(code).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::PMSystemAuthor(const QString &code) const
|
||||
auto VTranslateVars::PMSystemAuthor(const QString &code) const -> QString
|
||||
{
|
||||
return PMSystemAuthors.value(code).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::PMSystemBook(const QString &code) const
|
||||
auto VTranslateVars::PMSystemBook(const QString &code) const -> QString
|
||||
{
|
||||
return PMSystemBooks.value(code).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
||||
}
|
||||
|
@ -852,98 +1031,30 @@ QString VTranslateVars::PMSystemBook(const QString &code) const
|
|||
* @throw qmu::QmuParserError in case of a wrong expression
|
||||
* @return translated expression
|
||||
*/
|
||||
QString VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator) const
|
||||
auto VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator) const -> QString
|
||||
{
|
||||
if (formula.isEmpty())
|
||||
{
|
||||
return formula;
|
||||
}
|
||||
QString newFormula = formula;// Local copy for making changes
|
||||
|
||||
// Eval formula
|
||||
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula, osSeparator, true, GetTranslatedFunctions()));
|
||||
QScopedPointer<qmu::QmuTokenParser> cal(
|
||||
new qmu::QmuTokenParser(formula, osSeparator, true, GetTranslatedFunctions()));
|
||||
QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
|
||||
QMap<int, QString> numbers = cal->GetNumbers();// All numbers in expression for changing decimal separator
|
||||
delete cal.take();
|
||||
|
||||
QList<int> tKeys = tokens.keys();// Take all tokens positions
|
||||
QList<QString> tValues = tokens.values();
|
||||
for (int i = 0; i < tKeys.size(); ++i)
|
||||
{
|
||||
int bias = 0;
|
||||
if (MeasurementsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
QString newFormula = formula;// Local copy for making changes
|
||||
|
||||
if (VariablesFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FunctionsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tValues.at(i) == QLocale().negativeSign())
|
||||
{// unary minus
|
||||
newFormula.replace(tKeys.at(i), 1, '-');
|
||||
}
|
||||
}
|
||||
|
||||
QLocale loc = QLocale(); // User locale
|
||||
if (loc != QLocale::c() && osSeparator)
|
||||
{// User want use Os separator
|
||||
QList<int> nKeys = numbers.keys();// Positions for all numbers in expression
|
||||
QList<QString> nValues = numbers.values();
|
||||
for (int i = 0; i < nKeys.size(); ++i)
|
||||
{
|
||||
loc = QLocale();// From system locale
|
||||
bool ok = false;
|
||||
const qreal d = loc.toDouble(nValues.at(i), &ok);
|
||||
if (ok == false)
|
||||
{
|
||||
qDebug()<<"Can't convert to double token"<<nValues.at(i);
|
||||
continue;//Leave with out translation
|
||||
}
|
||||
|
||||
loc = QLocale::c();// To internal locale
|
||||
const QString dStr = loc.toString(d);// Internal look for number
|
||||
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
|
||||
const int bias = nValues.at(i).length() - dStr.length();
|
||||
if (bias != 0)
|
||||
{// Translated number has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
|
||||
nKeys = numbers.keys();
|
||||
nValues = numbers.values();
|
||||
}
|
||||
}
|
||||
}
|
||||
TranslateVarsFromUser(newFormula, tokens, numbers);
|
||||
TranslateNumbersFromUser(newFormula, tokens, numbers, osSeparator);
|
||||
|
||||
return newFormula;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSeparator)
|
||||
auto VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSeparator) -> QString
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -964,7 +1075,7 @@ QString VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSepara
|
|||
* @param formula expression that need translate
|
||||
* @return translated expression
|
||||
*/
|
||||
QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator) const
|
||||
auto VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator) const -> QString
|
||||
{
|
||||
if (formula.isEmpty())
|
||||
{
|
||||
|
@ -991,98 +1102,14 @@ QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator)
|
|||
return newFormula;
|
||||
}
|
||||
|
||||
QList<int> tKeys = tokens.keys();
|
||||
QList<QString> tValues = tokens.values();
|
||||
for (int i = 0; i < tKeys.size(); ++i)
|
||||
{
|
||||
if (measurements.contains(tValues.at(i)))
|
||||
{
|
||||
newFormula.replace(tKeys.at(i), tValues.at(i).length(),
|
||||
measurements.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
||||
int bias = tValues.at(i).length() - measurements.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()).length();
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (functions.contains(tValues.at(i)))
|
||||
{
|
||||
newFormula.replace(tKeys.at(i), tValues.at(i).length(),
|
||||
functions.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
||||
int bias = tValues.at(i).length() - functions.value(tValues.at(i))
|
||||
.translate(VAbstractApplication::VApp()->Settings()->GetLocale()).length();
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int bias = 0;
|
||||
if (VariablesToUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
||||
{
|
||||
if (bias != 0)
|
||||
{// Translated token has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
||||
tKeys = tokens.keys();
|
||||
tValues = tokens.values();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tValues.at(i) == QChar('-'))
|
||||
{// unary minus
|
||||
newFormula.replace(tKeys.at(i), 1, QLocale().negativeSign());
|
||||
}
|
||||
}
|
||||
|
||||
QLocale loc = QLocale();// User locale
|
||||
if (loc != QLocale::C && osSeparator)
|
||||
{// User want use Os separator
|
||||
QList<int> nKeys = numbers.keys();// Positions for all numbers in expression
|
||||
QList<QString> nValues = numbers.values();
|
||||
for (int i = 0; i < nKeys.size(); ++i)
|
||||
{
|
||||
loc = QLocale::c();// From pattern locale
|
||||
bool ok = false;
|
||||
const qreal d = loc.toDouble(nValues.at(i), &ok);
|
||||
if (ok == false)
|
||||
{
|
||||
qDebug()<<"Can't convert to double token"<<nValues.at(i);
|
||||
continue;//Leave with out translation
|
||||
}
|
||||
|
||||
loc = QLocale();// To user locale
|
||||
QString dStr = loc.toString(d);// Number string in user locale
|
||||
if (loc.groupSeparator().isSpace())
|
||||
{
|
||||
dStr.replace(loc.groupSeparator(), QString());
|
||||
}
|
||||
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
|
||||
const int bias = nValues.at(i).length() - dStr.length();
|
||||
if (bias != 0)
|
||||
{// Translated number has different length than original. Position next tokens need to be corrected.
|
||||
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
|
||||
nKeys = numbers.keys();
|
||||
nValues = numbers.values();
|
||||
}
|
||||
}
|
||||
}
|
||||
TranslateVarsToUser(newFormula, tokens, numbers);
|
||||
TranslateNumbersToUser(newFormula, tokens, numbers, osSeparator);
|
||||
|
||||
return newFormula;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::TryFormulaToUser(const QString &formula, bool osSeparator)
|
||||
auto VTranslateVars::TryFormulaToUser(const QString &formula, bool osSeparator) -> QString
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1116,25 +1143,25 @@ void VTranslateVars::Retranslate()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<QString, QString> VTranslateVars::GetTranslatedFunctions() const
|
||||
auto VTranslateVars::GetTranslatedFunctions() const -> QMap<QString, QString>
|
||||
{
|
||||
return translatedFunctions;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<QString, qmu::QmuTranslation> VTranslateVars::GetFunctions() const
|
||||
auto VTranslateVars::GetFunctions() const -> QMap<QString, qmu::QmuTranslation>
|
||||
{
|
||||
return functions;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<QString, qmu::QmuTranslation> VTranslateVars::GetFunctionsDescriptions() const
|
||||
auto VTranslateVars::GetFunctionsDescriptions() const -> QMap<QString, qmu::QmuTranslation>
|
||||
{
|
||||
return functionsDescriptions;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<QString, QString> VTranslateVars::GetFunctionsArguments() const
|
||||
auto VTranslateVars::GetFunctionsArguments() const -> QMap<QString, QString>
|
||||
{
|
||||
return functionsArguments;
|
||||
}
|
||||
|
|
|
@ -33,43 +33,44 @@
|
|||
#include <QtGlobal>
|
||||
|
||||
#include "vtranslatemeasurements.h"
|
||||
#include "../vmisc/defglobal.h"
|
||||
|
||||
class VTranslateVars : public VTranslateMeasurements
|
||||
{
|
||||
public:
|
||||
explicit VTranslateVars();
|
||||
virtual ~VTranslateVars() = default;
|
||||
~VTranslateVars() override = default;
|
||||
|
||||
bool VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
|
||||
bool FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
|
||||
bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const;
|
||||
auto VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const -> bool;
|
||||
auto FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const -> bool;
|
||||
auto VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const -> bool;
|
||||
|
||||
QString InternalVarToUser(const QString &var) const;
|
||||
auto InternalVarToUser(const QString &var) const -> QString;
|
||||
|
||||
QString VarToUser(const QString &var) const;
|
||||
QString VarFromUser(const QString &var) const;
|
||||
auto VarToUser(const QString &var) const -> QString;
|
||||
auto VarFromUser(const QString &var) const -> QString;
|
||||
|
||||
QString PMSystemName(const QString &code) const;
|
||||
QString PMSystemAuthor(const QString &code) const;
|
||||
QString PMSystemBook(const QString &code) const;
|
||||
auto PMSystemName(const QString &code) const -> QString;
|
||||
auto PMSystemAuthor(const QString &code) const -> QString;
|
||||
auto PMSystemBook(const QString &code) const -> QString;
|
||||
|
||||
QString FormulaFromUser(const QString &formula, bool osSeparator) const;
|
||||
static QString TryFormulaFromUser(const QString &formula, bool osSeparator);
|
||||
auto FormulaFromUser(const QString &formula, bool osSeparator) const -> QString;
|
||||
static auto TryFormulaFromUser(const QString &formula, bool osSeparator) -> QString;
|
||||
|
||||
QString FormulaToUser(const QString &formula, bool osSeparator) const;
|
||||
static QString TryFormulaToUser(const QString &formula, bool osSeparator);
|
||||
auto FormulaToUser(const QString &formula, bool osSeparator) const -> QString;
|
||||
static auto TryFormulaToUser(const QString &formula, bool osSeparator) -> QString;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
void Retranslate() override;
|
||||
|
||||
QMap<QString, QString> GetTranslatedFunctions() const;
|
||||
QMap<QString, qmu::QmuTranslation> GetFunctions() const;
|
||||
QMap<QString, qmu::QmuTranslation> GetFunctionsDescriptions() const;
|
||||
QMap<QString, QString> GetFunctionsArguments() const;
|
||||
auto GetTranslatedFunctions() const -> QMap<QString, QString>;
|
||||
auto GetFunctions() const -> QMap<QString, qmu::QmuTranslation>;
|
||||
auto GetFunctionsDescriptions() const -> QMap<QString, qmu::QmuTranslation>;
|
||||
auto GetFunctionsArguments() const -> QMap<QString, QString>;
|
||||
|
||||
static void BiasTokens(int position, int bias, QMap<int, QString> &tokens);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VTranslateVars)
|
||||
Q_DISABLE_COPY_MOVE(VTranslateVars) //NOLINT
|
||||
QMap<QString, qmu::QmuTranslation> PMSystemNames{};
|
||||
QMap<QString, qmu::QmuTranslation> PMSystemAuthors{};
|
||||
QMap<QString, qmu::QmuTranslation> PMSystemBooks{};
|
||||
|
@ -89,8 +90,15 @@ private:
|
|||
void InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author,
|
||||
const qmu::QmuTranslation &book);
|
||||
|
||||
void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens, QMap<int, QString> &numbers) const;
|
||||
static void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens, QMap<int, QString> &numbers);
|
||||
|
||||
void TranslateVarsFromUser(QString &newFormula, QMap<int, QString> &tokens, QMap<int, QString> &numbers) const;
|
||||
static void TranslateNumbersFromUser(QString &newFormula, QMap<int, QString> &tokens, QMap<int, QString> &numbers,
|
||||
bool osSeparator);
|
||||
|
||||
void TranslateVarsToUser(QString &newFormula, QMap<int, QString> &tokens, QMap<int, QString> &numbers) const;
|
||||
static void TranslateNumbersToUser(QString &newFormula, QMap<int, QString> &tokens, QMap<int, QString> &numbers,
|
||||
bool osSeparator);
|
||||
};
|
||||
|
||||
#endif // VTRANSLATEVARS_H
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
#include "../vpatterndb/variables/vlineangle.h"
|
||||
#include "../vpatterndb/variables/vlinelength.h"
|
||||
#include "../vpatterndb/variables/vmeasurement.h"
|
||||
#include "../ifc/xml/vdomdocument.h"
|
||||
#include "../vmisc/def.h"
|
||||
#include "../vmisc/vabstractapplication.h"
|
||||
#include "../vmisc/vcommonsettings.h"
|
||||
|
@ -79,14 +78,7 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, quint32 t
|
|||
ui(new Ui::DialogEditWrongFormula),
|
||||
m_data(data),
|
||||
m_toolId(toolId),
|
||||
formula(),
|
||||
formulaBaseHeight(0),
|
||||
checkZero(false),
|
||||
checkLessThanZero(false),
|
||||
postfix(),
|
||||
restoreCursor(false),
|
||||
timerFormula(new QTimer(this)),
|
||||
flagFormula(false)
|
||||
timerFormula(new QTimer(this))
|
||||
{
|
||||
SCASSERT(data != nullptr)
|
||||
|
||||
|
@ -494,10 +486,9 @@ void DialogEditWrongFormula::SetPreviewCalculationsMode()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString DialogEditWrongFormula::GetFormula() const
|
||||
auto DialogEditWrongFormula::GetFormula() const -> QString
|
||||
{
|
||||
return VAbstractApplication::VApp()->TrVars()
|
||||
->TryFormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
||||
return VTranslateVars::TryFormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -554,7 +545,7 @@ void DialogEditWrongFormula::SetDescription(const QString &name, qreal value, bo
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal DialogEditWrongFormula::Eval(const FormulaData &formulaData, bool &flag)
|
||||
auto DialogEditWrongFormula::Eval(const FormulaData &formulaData, bool &flag) -> qreal
|
||||
{
|
||||
const qreal result = EvalToolFormula(this, formulaData, flag);
|
||||
CheckState(); // Disable Ok and Apply buttons if something wrong.
|
||||
|
@ -586,7 +577,7 @@ void DialogEditWrongFormula::ShowVariable(const QMap<key, val> &var)
|
|||
if (iMap.value()->Filter(m_toolId) == false)
|
||||
{// If we create this variable don't show
|
||||
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
|
||||
QTableWidgetItem *item = new QTableWidgetItem(iMap.key());
|
||||
auto *item = new QTableWidgetItem(iMap.key());
|
||||
QFont font = item->font();
|
||||
font.setBold(true);
|
||||
item->setFont(font);
|
||||
|
@ -619,16 +610,16 @@ void DialogEditWrongFormula::ShowMeasurements(const QMap<QString, QSharedPointer
|
|||
{
|
||||
continue; //skip this measurement
|
||||
}
|
||||
if (iMap.value()->Filter(m_toolId) == false)
|
||||
if (not iMap.value()->Filter(m_toolId))
|
||||
{// If we create this variable don't show
|
||||
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
|
||||
QTableWidgetItem *itemName = new QTableWidgetItem(iMap.key());
|
||||
auto *itemName = new QTableWidgetItem(iMap.key());
|
||||
QFont fontName = itemName->font();
|
||||
fontName.setBold(true);
|
||||
itemName->setFont(fontName);
|
||||
itemName->setToolTip(itemName->text());
|
||||
|
||||
QTableWidgetItem *itemFullName = new QTableWidgetItem();
|
||||
auto *itemFullName = new QTableWidgetItem();
|
||||
QFont fontFullName = itemName->font();
|
||||
fontFullName.setBold(true);
|
||||
itemFullName->setFont(fontFullName);
|
||||
|
@ -735,7 +726,7 @@ void DialogEditWrongFormula::FilterVariablesEdited(const QString &filter)
|
|||
|
||||
// show rows with matched filter
|
||||
const QList<QTableWidgetItem*> items = ui->tableWidget->findItems(filter, Qt::MatchContains);
|
||||
for (auto item : items)
|
||||
for (auto *item : items)
|
||||
{
|
||||
// If filter is empty findItems() for unknown reason returns nullptr items.
|
||||
if (item)
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include <QtGlobal>
|
||||
#include <QDialog>
|
||||
|
||||
#include "../vmisc/defglobal.h"
|
||||
|
||||
class VMeasurement;
|
||||
struct FormulaData;
|
||||
class VContainer;
|
||||
|
@ -57,37 +59,38 @@ class DialogEditWrongFormula;
|
|||
*/
|
||||
class DialogEditWrongFormula final : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT //NOLINT
|
||||
public:
|
||||
DialogEditWrongFormula(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
|
||||
virtual ~DialogEditWrongFormula() override;
|
||||
~DialogEditWrongFormula() override;
|
||||
|
||||
QString GetFormula() const;
|
||||
void SetFormula(const QString &value);
|
||||
void setCheckZero(bool value);
|
||||
void setCheckLessThanZero(bool value);
|
||||
void setPostfix(const QString &value);
|
||||
void SetMeasurementsMode();
|
||||
void SetIncrementsMode();
|
||||
void SetPreviewCalculationsMode();
|
||||
auto GetFormula() const -> QString;
|
||||
void SetFormula(const QString &value);
|
||||
void setCheckZero(bool value);
|
||||
void setCheckLessThanZero(bool value);
|
||||
void setPostfix(const QString &value);
|
||||
void SetMeasurementsMode();
|
||||
void SetIncrementsMode();
|
||||
void SetPreviewCalculationsMode();
|
||||
public slots:
|
||||
virtual void DialogAccepted();
|
||||
virtual void DialogRejected();
|
||||
void EvalFormula();
|
||||
void ValChanged(int row);
|
||||
void PutHere();
|
||||
void PutVal(QTableWidgetItem * item);
|
||||
|
||||
void Measurements();
|
||||
void LengthLines();
|
||||
void RadiusArcs();
|
||||
void AnglesCurves();
|
||||
void LengthCurves();
|
||||
void CurvesCLength();
|
||||
void AngleLines();
|
||||
void Increments();
|
||||
void PreviewCalculations();
|
||||
void Functions();
|
||||
void EvalFormula();
|
||||
void ValChanged(int row);
|
||||
void PutHere();
|
||||
void PutVal(QTableWidgetItem * item);
|
||||
|
||||
void Measurements();
|
||||
void LengthLines();
|
||||
void RadiusArcs();
|
||||
void AnglesCurves();
|
||||
void LengthCurves();
|
||||
void CurvesCLength();
|
||||
void AngleLines();
|
||||
void Increments();
|
||||
void PreviewCalculations();
|
||||
void Functions();
|
||||
signals:
|
||||
/**
|
||||
* @brief DialogClosed signal dialog closed
|
||||
|
@ -99,15 +102,15 @@ signals:
|
|||
*/
|
||||
void DialogApplied();
|
||||
protected:
|
||||
virtual bool IsValid() const final;
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
virtual void showEvent( QShowEvent *event ) override;
|
||||
virtual void resizeEvent(QResizeEvent *event) override;
|
||||
virtual auto IsValid() const -> bool final;
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void showEvent( QShowEvent *event ) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
virtual void CheckState();
|
||||
private slots:
|
||||
void FilterVariablesEdited(const QString &filter);
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogEditWrongFormula)
|
||||
Q_DISABLE_COPY_MOVE(DialogEditWrongFormula) //NOLINT
|
||||
Ui::DialogEditWrongFormula *ui;
|
||||
|
||||
const VContainer *m_data;
|
||||
|
@ -115,19 +118,19 @@ private:
|
|||
quint32 m_toolId;
|
||||
|
||||
/** @brief formula string with formula */
|
||||
QString formula;
|
||||
QString formula{};
|
||||
|
||||
/** @brief formulaBaseHeight base height defined by dialogui */
|
||||
int formulaBaseHeight;
|
||||
int formulaBaseHeight{0};
|
||||
|
||||
bool checkZero;
|
||||
bool checkLessThanZero;
|
||||
QString postfix;
|
||||
bool restoreCursor;
|
||||
bool checkZero{false};
|
||||
bool checkLessThanZero{false};
|
||||
QString postfix{};
|
||||
bool restoreCursor{false};
|
||||
|
||||
QTimer *timerFormula;
|
||||
|
||||
bool flagFormula;
|
||||
bool flagFormula{false};
|
||||
|
||||
/** @brief m_isInitialized true if window is initialized */
|
||||
bool m_isInitialized{false};
|
||||
|
@ -142,11 +145,11 @@ private:
|
|||
|
||||
void SetDescription(const QString &name, qreal value, bool specialUnits, const QString &description);
|
||||
|
||||
qreal Eval(const FormulaData &formulaData, bool &flag);
|
||||
auto Eval(const FormulaData &formulaData, bool &flag) -> qreal;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline bool DialogEditWrongFormula::IsValid() const
|
||||
inline auto DialogEditWrongFormula::IsValid() const -> bool
|
||||
{
|
||||
return flagFormula;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user