diff --git a/ChangeLog.txt b/ChangeLog.txt index 48b2244e0..ae34fbf7c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -31,6 +31,7 @@ - Fix locking file after double save as. - Key --ignoremargins still required margins. - [#978] Don't show errors in History dialog. +- Fixed translation numbers in scientific notation. # Version 0.6.1 October 23, 2018 - [#885] Regression. Broken support for multi size measurements. diff --git a/src/libs/qmuparser/qmuformulabase.cpp b/src/libs/qmuparser/qmuformulabase.cpp index e50c2b694..d9cf3daba 100644 --- a/src/libs/qmuparser/qmuformulabase.cpp +++ b/src/libs/qmuparser/qmuformulabase.cpp @@ -118,6 +118,7 @@ void QmuFormulaBase::SetSepForTr(bool osSeparator, bool fromUser) const QLocale loc = QLocale(); setLocale(loc); SetArgSep(';'); + setCNumbers(not osSeparator); if (osSeparator) { setDecimalPoint(loc.decimalPoint()); diff --git a/src/libs/qmuparser/qmuparser.cpp b/src/libs/qmuparser/qmuparser.cpp index a675e274e..f8ee6c27b 100644 --- a/src/libs/qmuparser/qmuparser.cpp +++ b/src/libs/qmuparser/qmuparser.cpp @@ -383,12 +383,12 @@ qreal QmuParser::Max(const qreal *a_afArg, int a_iArgc) * @param [out] a_fVal Pointer where the value should be stored in case one is found. * @return 1 if a value was found 0 otherwise. */ -int QmuParser::IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, const QChar &decimal, - const QChar &thousand) +int QmuParser::IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, bool cNumbers, + const QChar &decimal, const QChar &thousand) { qreal fVal(0); - const int pos = ReadVal(a_szExpr, fVal, locale, decimal, thousand); + int pos = ReadVal(a_szExpr, fVal, locale != QLocale::c() && cNumbers ? QLocale::c() : locale, decimal, thousand); if (pos == -1) { @@ -495,8 +495,8 @@ void QmuParser::InitFun() */ void QmuParser::InitConst() { - DefineConst("_pi", static_cast(M_PI)); - DefineConst("_e", static_cast(M_E)); + DefineConst(QStringLiteral("_pi"), static_cast(M_PI)); + DefineConst(QStringLiteral("_e"), static_cast(M_E)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/qmuparser/qmuparser.h b/src/libs/qmuparser/qmuparser.h index d06abe518..9c71e1ff4 100644 --- a/src/libs/qmuparser/qmuparser.h +++ b/src/libs/qmuparser/qmuparser.h @@ -58,7 +58,7 @@ namespace qmu virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) override; qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon = 0) const; protected: - static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, + static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, bool cNumbers, const QChar &decimal, const QChar &thousand); // hyperbolic functions static qreal Sinh(qreal); diff --git a/src/libs/qmuparser/qmuparser.pro b/src/libs/qmuparser/qmuparser.pro index 275fcd871..5ddfec138 100644 --- a/src/libs/qmuparser/qmuparser.pro +++ b/src/libs/qmuparser/qmuparser.pro @@ -55,7 +55,7 @@ OBJECTS_DIR = obj include(qmuparser.pri) -VERSION = 2.6.0 +VERSION = 2.7.0 # Allow MAC OS X to find library inside a bundle macx:QMAKE_SONAME_PREFIX = @rpath diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index 4e2596c57..5fdab6b19 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -205,6 +205,7 @@ void QmuParserBase::ResetLocale() setLocale(QLocale::c()); m_decimalPoint = m_locale.decimalPoint(); m_thousandsSeparator = m_locale.groupSeparator(); + m_cNumbers = false; SetArgSep(';'); } @@ -278,6 +279,18 @@ void QmuParserBase::setThousandsSeparator(const QChar &c) m_thousandsSeparator = c; } +//--------------------------------------------------------------------------------------------------------------------- +bool QmuParserBase::getCNumbers() const +{ + return m_cNumbers; +} + +//--------------------------------------------------------------------------------------------------------------------- +void QmuParserBase::setCNumbers(bool cNumbers) +{ + m_cNumbers = cNumbers; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Returns the version of muparser. @@ -1355,7 +1368,7 @@ void QmuParserBase::CreateRPN() const for (;;) { - opt = m_pTokenReader->ReadNextToken(m_locale, m_decimalPoint, m_thousandsSeparator); + opt = m_pTokenReader->ReadNextToken(m_locale, m_cNumbers, m_decimalPoint, m_thousandsSeparator); switch (opt.GetCode()) { diff --git a/src/libs/qmuparser/qmuparserbase.h b/src/libs/qmuparser/qmuparserbase.h index 5332b909a..9f0282890 100644 --- a/src/libs/qmuparser/qmuparserbase.h +++ b/src/libs/qmuparser/qmuparserbase.h @@ -133,6 +133,9 @@ public: QChar getThousandsSeparator() const; void setThousandsSeparator(const QChar &c); + bool getCNumbers() const; + void setCNumbers(bool cNumbers); + protected: /** * @brief Typedef for the token reader. @@ -143,6 +146,7 @@ protected: QLocale m_locale;///< The locale used by the parser QChar m_decimalPoint; QChar m_thousandsSeparator; + bool m_cNumbers{false}; ///< Search numbers in c locale funmap_type m_FunDef; ///< Map of function names and pointers. std::unique_ptr m_pTokenReader; ///< Managed pointer to the token reader object. static bool g_DbgDumpCmdCode; diff --git a/src/libs/qmuparser/qmuparserdef.h b/src/libs/qmuparser/qmuparserdef.h index 68bef7a74..0a46cd780 100644 --- a/src/libs/qmuparser/qmuparserdef.h +++ b/src/libs/qmuparser/qmuparserdef.h @@ -36,8 +36,8 @@ @brief This file contains standard definitions used by the parser. */ -#define QMUP_VERSION "2.6.0" -#define QMUP_VERSION_DATE "20180121; GC" +#define QMUP_VERSION "2.7.0" +#define QMUP_VERSION_DATE "20191030; GC" // Detect whether the compiler supports C++11 noexcept exception specifications. # if defined(__clang__) @@ -301,7 +301,7 @@ typedef qreal ( *strfun_type2 ) ( const QString &, qreal ); typedef qreal ( *strfun_type3 ) ( const QString &, qreal, qreal ); /** @brief Callback used for functions that identify values in a string. */ -typedef int ( *identfun_type ) ( const QString &sExpr, int *nPos, qreal *fVal, const QLocale &locale, +typedef int ( *identfun_type ) ( const QString &sExpr, int *nPos, qreal *fVal, const QLocale &locale, bool cNumbers, const QChar &decimal, const QChar &thousand ); /** @brief Callback used for variable creation factory functions. */ diff --git a/src/libs/qmuparser/qmuparsertest.cpp b/src/libs/qmuparser/qmuparsertest.cpp index fd22a71c9..afa05001d 100644 --- a/src/libs/qmuparser/qmuparsertest.cpp +++ b/src/libs/qmuparser/qmuparsertest.cpp @@ -75,11 +75,13 @@ QmuParserTester::QmuParserTester(QObject *parent) //--------------------------------------------------------------------------------------------------------------------- int QmuParserTester::IsHexVal ( const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, - const QChar &decimal, const QChar &thousand ) + bool cNumbers, const QChar &decimal, const QChar &thousand ) { Q_UNUSED(locale) Q_UNUSED(decimal) Q_UNUSED(thousand) + Q_UNUSED(cNumbers) + if ( a_szExpr.size() <= 2 || ( a_szExpr.at(0) != '0' || a_szExpr.at(1) != 'x' ) ) { return 0; diff --git a/src/libs/qmuparser/qmuparsertest.h b/src/libs/qmuparser/qmuparsertest.h index 3b2d61017..af7e1e751 100644 --- a/src/libs/qmuparser/qmuparsertest.h +++ b/src/libs/qmuparser/qmuparsertest.h @@ -307,7 +307,7 @@ private: } // Custom value recognition - static int IsHexVal (const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, + static int IsHexVal (const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, bool cNumbers, const QChar &decimal, const QChar &thousand); // cppcheck-suppress functionStatic diff --git a/src/libs/qmuparser/qmuparsertokenreader.cpp b/src/libs/qmuparser/qmuparsertokenreader.cpp index b690c8278..fbea37619 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.cpp +++ b/src/libs/qmuparser/qmuparsertokenreader.cpp @@ -213,7 +213,8 @@ void QmuParserTokenReader::ReInit() /** * @brief Read the next token from the string. */ -QmuParserTokenReader::token_type QmuParserTokenReader::ReadNextToken(const QLocale &locale, const QChar &decimal, +QmuParserTokenReader::token_type QmuParserTokenReader::ReadNextToken(const QLocale &locale, bool cNumbers, + const QChar &decimal, const QChar &thousand) { assert ( m_pParser ); @@ -246,7 +247,7 @@ QmuParserTokenReader::token_type QmuParserTokenReader::ReadNextToken(const QLoca { return SaveBeforeReturn ( tok ); // Check for function argument separators } - if ( IsValTok ( tok, locale, decimal, thousand ) ) + if ( IsValTok ( tok, locale, cNumbers, decimal, thousand ) ) { return SaveBeforeReturn ( tok ); // Check for values / constant tokens } @@ -757,7 +758,7 @@ bool QmuParserTokenReader::IsPostOpTok ( token_type &a_Tok ) * @param a_Tok [out] If a value token is found it will be placed here. * @return true if a value token has been found. */ -bool QmuParserTokenReader::IsValTok ( token_type &a_Tok, const QLocale &locale, const QChar &decimal, +bool QmuParserTokenReader::IsValTok ( token_type &a_Tok, const QLocale &locale, bool cNumbers, const QChar &decimal, const QChar &thousand ) { assert ( m_pConstDef ); @@ -794,7 +795,7 @@ bool QmuParserTokenReader::IsValTok ( token_type &a_Tok, const QLocale &locale, for ( item = m_vIdentFun.begin(); item != m_vIdentFun.end(); ++item ) { int iStart = m_iPos; - if ( ( *item ) ( m_strFormula.mid ( m_iPos ), &m_iPos, &fVal, locale, decimal, thousand ) == 1 ) + if ( ( *item ) ( m_strFormula.mid ( m_iPos ), &m_iPos, &fVal, locale, cNumbers, decimal, thousand ) == 1 ) { // 2013-11-27 Issue 2: https://code.google.com/p/muparser/issues/detail?id=2 strTok = m_strFormula.mid ( iStart, m_iPos-iStart ); diff --git a/src/libs/qmuparser/qmuparsertokenreader.h b/src/libs/qmuparser/qmuparsertokenreader.h index b023e6b63..3a4766af3 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.h +++ b/src/libs/qmuparser/qmuparsertokenreader.h @@ -66,7 +66,7 @@ public: QChar GetArgSep() const; void IgnoreUndefVar(bool bIgnore); void ReInit(); - token_type ReadNextToken(const QLocale &locale, const QChar &decimal, const QChar &thousand); + token_type ReadNextToken(const QLocale &locale, bool cNumbers, const QChar &decimal, const QChar &thousand); private: /** @@ -111,7 +111,8 @@ private: bool IsFunTok(token_type &a_Tok); bool IsPostOpTok(token_type &a_Tok); bool IsOprt(token_type &a_Tok); - bool IsValTok(token_type &a_Tok, const QLocale &locale, const QChar &decimal, const QChar &thousand); + bool IsValTok(token_type &a_Tok, const QLocale &locale, bool cNumbers, const QChar &decimal, + const QChar &thousand); bool IsVarTok(token_type &a_Tok); bool IsStrVarTok(token_type &a_Tok); bool IsUndefVarTok(token_type &a_Tok);