Removed unused postfix operator.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-12-04 14:32:17 +02:00
parent d1ec8e90dd
commit debc37d78a
6 changed files with 2 additions and 120 deletions

View File

@ -274,7 +274,7 @@ QStringList VAbstractPattern::ListMeasurements() const
continue;
}
if (IsVariable(tValues.at(j)) || IsPostfixOperator(tValues.at(j)) || IsFunction(tValues.at(j)))
if (IsVariable(tValues.at(j)) || IsFunction(tValues.at(j)))
{
others.insert(tValues.at(j));
}
@ -2049,20 +2049,6 @@ bool VAbstractPattern::IsVariable(const QString &token) const
return false;
}
//---------------------------------------------------------------------------------------------------------------------
bool VAbstractPattern::IsPostfixOperator(const QString &token) const
{
for (int i = 0; i < builInPostfixOperators.size(); ++i)
{
if (token.indexOf( builInPostfixOperators.at(i) ) == 0)
{
return true;
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
bool VAbstractPattern::IsFunction(const QString &token) const
{

View File

@ -450,7 +450,6 @@ private:
QVector<VFormulaField> ListFinalMeasurementsExpressions() const;
bool IsVariable(const QString& token) const;
bool IsPostfixOperator(const QString& token) const;
bool IsFunction(const QString& token) const;
QPair<bool, QMap<quint32, quint32> > ParseItemElement(const QDomElement &domElement);

View File

@ -137,15 +137,6 @@ const QStringList builInFunctions = QStringList() << degTorad_F
<< avg_F
<< fmod_F;
// Postfix operators
const QString cm_Oprt = QStringLiteral("cm");
const QString mm_Oprt = QStringLiteral("mm");
const QString in_Oprt = QStringLiteral("in");
const QStringList builInPostfixOperators = QStringList() << cm_Oprt
<< mm_Oprt
<< in_Oprt;
const QString pl_size = QStringLiteral("size");
const QString pl_height = QStringLiteral("height");
const QString pl_date = QStringLiteral("date");

View File

@ -358,13 +358,6 @@ extern const QString fmod_F;
extern const QStringList builInFunctions;
// Postfix operators
extern const QString cm_Oprt;
extern const QString mm_Oprt;
extern const QString in_Oprt;
extern const QStringList builInPostfixOperators;
// Placeholders
extern const QString pl_size;
extern const QString pl_height;

View File

@ -53,7 +53,6 @@ VTranslateVars::VTranslateVars()
PMSystemBooks(QMap<QString, qmu::QmuTranslation>()),
variables(QMap<QString, qmu::QmuTranslation>()),
functions(QMap<QString, qmu::QmuTranslation>()),
postfixOperators(QMap<QString, qmu::QmuTranslation>()),
placeholders(QMap<QString, qmu::QmuTranslation>()),
stDescriptions(QMap<QString, qmu::QmuTranslation>()),
translatedFunctions(QMap<QString, QString>())
@ -61,16 +60,11 @@ VTranslateVars::VTranslateVars()
InitPatternMakingSystems();
InitVariables();
InitFunctions();
InitPostfixOperators();
InitPlaceholder();
PrepareFunctionTranslations();
}
//---------------------------------------------------------------------------------------------------------------------
VTranslateVars::~VTranslateVars()
{}
#define translate(context, source, disambiguation) qmu::QmuTranslation::translate((context), (source), (disambiguation))
//---------------------------------------------------------------------------------------------------------------------
@ -454,14 +448,6 @@ void VTranslateVars::InitFunctions()
"Returns the floating-point remainder of numer/denom (rounded towards zero)"));
}
//---------------------------------------------------------------------------------------------------------------------
void VTranslateVars::InitPostfixOperators()
{
postfixOperators.insert(cm_Oprt, translate("VTranslateVars", "cm", "centimeter"));
postfixOperators.insert(mm_Oprt, translate("VTranslateVars", "mm", "millimeter"));
postfixOperators.insert(in_Oprt, translate("VTranslateVars", "in", "inch"));
}
//---------------------------------------------------------------------------------------------------------------------
void VTranslateVars::InitPlaceholder()
{
@ -612,31 +598,6 @@ bool VTranslateVars::VariablesFromUser(QString &newFormula, int position, const
return false;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief PostfixOperatorsFromUser translate postfix operator to internal look.
* @param newFormula [in|out] expression to translate
* @param position token position
* @param token token to translate
* @param bias hold change of length between translated and origin token string
* @return true if was found postfix operator with same name.
*/
bool VTranslateVars::PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
{
QMap<QString, qmu::QmuTranslation>::const_iterator i = postfixOperators.constBegin();
while (i != postfixOperators.constEnd())
{
if (token == i.value().translate())
{
newFormula.replace(position, token.length(), i.key());
bias = token.length() - i.key().length();
return true;
}
++i;
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FunctionsFromUser translate function name to internal look.
@ -780,11 +741,6 @@ QString VTranslateVars::VarToUser(const QString &var) const
return functions.value(var).translate();
}
if (postfixOperators.contains(var))
{
return postfixOperators.value(var).translate();
}
return InternalVarToUser(var);
}
@ -803,11 +759,6 @@ QString VTranslateVars::VarFromUser(const QString &var) const
return newVar;
}
if (PostfixOperatorsFromUser(newVar, 0, var, bias))
{
return newVar;
}
if (FunctionsFromUser(newVar, 0, var, bias))
{
return newVar;
@ -833,13 +784,6 @@ QString VTranslateVars::PMSystemBook(const QString &code) const
return PMSystemBooks.value(code).translate();
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
QString VTranslateVars::PostfixOperator(const QString &name) const
{
return postfixOperators.value(name).translate();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FormulaFromUser replace all known tokens in formula to internal look. Also change decimal
@ -890,17 +834,6 @@ QString VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator
continue;
}
if (PostfixOperatorsFromUser(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)
@ -1029,19 +962,6 @@ QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator)
continue;
}
if (postfixOperators.contains(tValues.at(i)))
{
newFormula.replace(tKeys.at(i), tValues.at(i).length(), postfixOperators.value(tValues.at(i)).translate());
int bias = tValues.at(i).length() - postfixOperators.value(tValues.at(i)).translate().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))
{
@ -1120,13 +1040,11 @@ void VTranslateVars::Retranslate()
PMSystemBooks.clear();
variables.clear();
functions.clear();
postfixOperators.clear();
stDescriptions.clear();
InitPatternMakingSystems();
InitVariables();
InitFunctions();
InitPostfixOperators();
InitPlaceholder();
PrepareFunctionTranslations();

View File

@ -38,10 +38,9 @@ class VTranslateVars : public VTranslateMeasurements
{
public:
explicit VTranslateVars();
virtual ~VTranslateVars() Q_DECL_OVERRIDE;
virtual ~VTranslateVars() = default;
bool VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
bool PostfixOperatorsFromUser(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;
@ -58,8 +57,6 @@ public:
QString PMSystemAuthor(const QString &code) const;
QString PMSystemBook(const QString &code) const;
QString PostfixOperator(const QString &name) const;
QString FormulaFromUser(const QString &formula, bool osSeparator) const;
static QString TryFormulaFromUser(const QString &formula, bool osSeparator);
@ -80,7 +77,6 @@ private:
QMap<QString, qmu::QmuTranslation> PMSystemBooks;
QMap<QString, qmu::QmuTranslation> variables;
QMap<QString, qmu::QmuTranslation> functions;
QMap<QString, qmu::QmuTranslation> postfixOperators;
QMap<QString, qmu::QmuTranslation> placeholders;
QMap<QString, qmu::QmuTranslation> stDescriptions;
QMap<QString, QString> translatedFunctions;
@ -88,7 +84,6 @@ private:
void InitPatternMakingSystems();
void InitVariables();
void InitFunctions();
void InitPostfixOperators();
void InitPlaceholder();
void PrepareFunctionTranslations();