QLocale in Qt6 now returns QString instead of QChar.

This commit is contained in:
Roman Telezhynskyi 2023-02-09 15:42:34 +02:00
parent 404f870069
commit 5335fecc98
28 changed files with 645 additions and 82 deletions

View File

@ -44,7 +44,7 @@ template <class T>
auto NumberToString(T number) -> QString
{
const QLocale locale = QLocale::c();
return locale.toString(number, 'g', 12).remove(locale.groupSeparator());
return locale.toString(number, 'g', 12).remove(LocaleGroupSeparator(locale));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -36,8 +36,8 @@
#include <ciso646>
#include "../vmisc/literals.h"
#include "../vmisc/defglobal.h"
#include "../layout/layoutdef.h"
#include "../qmuparser/qmudef.h"
class VPLayout;
class VPSheet;
@ -91,7 +91,7 @@ void VPLayoutFileWriter::SetAttribute(const QString &name, const T &value)
{
// See specification for xs:decimal
const QLocale locale = QLocale::c();
writeAttribute(name, locale.toString(value).remove(locale.groupSeparator()));
writeAttribute(name, locale.toString(value).remove(LocaleGroupSeparator(locale)));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -34,6 +34,7 @@
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vmisc/backport/qoverload.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../qmuparser/qmudef.h"
//---------------------------------------------------------------------------------------------------------------------
TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *parent)
@ -163,7 +164,7 @@ void TapePreferencesConfigurationPage::changeEvent(QEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void TapePreferencesConfigurationPage::RetranslateUi()
{
ui->osOptionCheck->setText(tr("With OS options") + QStringLiteral(" (%1)").arg(QLocale().decimalPoint()));
ui->osOptionCheck->setText(tr("With OS options") + QStringLiteral(" (%1)").arg(LocaleDecimalPoint(QLocale())));
{
const auto code = qvariant_cast<QString>(ui->systemCombo->currentData());

View File

@ -760,11 +760,11 @@ auto TMainWindow::eventFilter(QObject *object, QEvent *event) -> bool
{
if (VAbstractApplication::VApp()->Settings()->GetOsSeparator())
{
plainTextEdit->insertPlainText(QLocale().decimalPoint());
plainTextEdit->insertPlainText(LocaleDecimalPoint(QLocale()));
}
else
{
plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
plainTextEdit->insertPlainText(LocaleDecimalPoint(QLocale::c()));
}
return true;
}
@ -779,11 +779,11 @@ auto TMainWindow::eventFilter(QObject *object, QEvent *event) -> bool
{
if (VAbstractApplication::VApp()->Settings()->GetOsSeparator())
{
textEdit->insert(QLocale().decimalPoint());
textEdit->insert(LocaleDecimalPoint(QLocale()));
}
else
{
textEdit->insert(QLocale::c().decimalPoint());
textEdit->insert(LocaleDecimalPoint(QLocale::c()));
}
return true;
}

View File

@ -35,6 +35,7 @@
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vmisc/backport/qoverload.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../qmuparser/qmudef.h"
#include <QDir>
#include <QDirIterator>
@ -281,7 +282,7 @@ void PreferencesConfigurationPage::InitUnits()
//---------------------------------------------------------------------------------------------------------------------
void PreferencesConfigurationPage::RetranslateUi()
{
ui->osOptionCheck->setText(tr("With OS options") + QStringLiteral(" (%1)").arg(QLocale().decimalPoint()));
ui->osOptionCheck->setText(tr("With OS options") + QStringLiteral(" (%1)").arg(LocaleDecimalPoint(QLocale())));
{
ui->unitCombo->blockSignals(true);

View File

@ -147,11 +147,11 @@ auto DialogFinalMeasurements::eventFilter(QObject *object, QEvent *event) -> boo
{
if (VAbstractApplication::VApp()->Settings()->GetOsSeparator())
{
textEdit->insert(QLocale().decimalPoint());
textEdit->insert(LocaleDecimalPoint(QLocale()));
}
else
{
textEdit->insert(QLocale::c().decimalPoint());
textEdit->insert(LocaleDecimalPoint(QLocale::c()));
}
return true;
}

View File

@ -1933,11 +1933,11 @@ auto DialogIncrements::eventFilter(QObject *object, QEvent *event) -> bool
{
if (VAbstractApplication::VApp()->Settings()->GetOsSeparator())
{
textEdit->insert(QLocale().decimalPoint());
textEdit->insert(LocaleDecimalPoint(QLocale()));
}
else
{
textEdit->insert(QLocale::c().decimalPoint());
textEdit->insert(LocaleDecimalPoint(QLocale::c()));
}
return true;
}

View File

@ -275,7 +275,7 @@ template <class T>
auto NumberToString(T number) -> QString
{
const QLocale locale = QLocale::c();
return locale.toString(number, 'g', 12).remove(locale.groupSeparator());
return locale.toString(number, 'g', 12).remove(LocaleGroupSeparator(locale));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -47,6 +47,7 @@
#include "../vmisc/diagnostic.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/literals.h"
#include "../qmuparser/qmudef.h"
class QDomElement;
class QDomNode;
@ -186,7 +187,7 @@ inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &n
{
// See specification for xs:decimal
const QLocale locale = QLocale::c();
domElement.setAttribute(name, locale.toString(value).remove(locale.groupSeparator()));
domElement.setAttribute(name, locale.toString(value).remove(LocaleGroupSeparator(locale)));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -241,8 +241,8 @@ qmusizetype ReadVal(const QString &formula, qreal &val, const QLocale &locale, c
{
// Convert to C locale
QLocale cLocale(QLocale::C);
const QChar cDecimal = cLocale.decimalPoint();
const QChar cThousand = cLocale.groupSeparator();
const QChar cDecimal = LocaleDecimalPoint(cLocale);
const QChar cThousand = LocaleGroupSeparator(cLocale);
if (locale != cLocale && (cDecimal != decimal || cThousand != thousand))
{
if (decimal == cThousand)
@ -297,24 +297,24 @@ QString NameRegExp()
for(const auto &locale : allLocales)
{
if (not positiveSigns.contains(locale.positiveSign()))
if (not positiveSigns.contains(LocalePositiveSign(locale)))
{
positiveSigns.append(locale.positiveSign());
positiveSigns.append(LocalePositiveSign(locale));
}
if (not negativeSigns.contains(locale.negativeSign()))
if (not negativeSigns.contains(LocaleNegativeSign(locale)))
{
negativeSigns.append(locale.negativeSign());
negativeSigns.append(LocaleNegativeSign(locale));
}
if (not decimalPoints.contains(locale.decimalPoint()))
if (not decimalPoints.contains(LocaleDecimalPoint(locale)))
{
decimalPoints.append(locale.decimalPoint());
decimalPoints.append(LocaleDecimalPoint(locale));
}
if (not groupSeparators.contains(locale.groupSeparator()))
if (not groupSeparators.contains(LocaleGroupSeparator(locale)))
{
groupSeparators.append(locale.groupSeparator());
groupSeparators.append(LocaleGroupSeparator(locale));
}
}
@ -353,3 +353,243 @@ qmusizetype FindFirstNotOf(const QString &string, const QString &chars, qmusizet
return -1;
}
//---------------------------------------------------------------------------------------------------------------------
bool SupportedLocale(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return locale.positiveSign().size() == 1 &&
locale.negativeSign().size() == 1 &&
locale.toString(0).size() == 1 &&
locale.toString(1).size() == 1 &&
locale.toString(2).size() == 1 &&
locale.toString(3).size() == 1 &&
locale.toString(4).size() == 1 &&
locale.toString(5).size() == 1 &&
locale.toString(6).size() == 1 &&
locale.toString(7).size() == 1 &&
locale.toString(8).size() == 1 &&
locale.toString(9).size() == 1 &&
locale.exponential().size() == 1 &&
locale.decimalPoint().size() == 1 &&
locale.groupSeparator().size() == 1;
#else
return true;
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocalePositiveSign(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.positiveSign();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().positiveSign().front();
#else
return locale.positiveSign();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleNegativeSign(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.negativeSign();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().negativeSign().front();
#else
return locale.negativeSign();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign0(const QLocale &locale)
{
const QString sign = locale.toString(0);
if (sign.size() == 1)
{
return sign.front();
}
return {'0'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign1(const QLocale &locale)
{
const QString sign = locale.toString(1);
if (sign.size() == 1)
{
return sign.front();
}
return {'1'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign2(const QLocale &locale)
{
const QString sign = locale.toString(2);
if (sign.size() == 1)
{
return sign.front();
}
return {'2'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign3(const QLocale &locale)
{
const QString sign = locale.toString(3);
if (sign.size() == 1)
{
return sign.front();
}
return {'3'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign4(const QLocale &locale)
{
const QString sign = locale.toString(4);
if (sign.size() == 1)
{
return sign.front();
}
return {'4'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign5(const QLocale &locale)
{
const QString sign = locale.toString(5);
if (sign.size() == 1)
{
return sign.front();
}
return {'5'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign6(const QLocale &locale)
{
const QString sign = locale.toString(6);
if (sign.size() == 1)
{
return sign.front();
}
return {'6'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign7(const QLocale &locale)
{
const QString sign = locale.toString(7);
if (sign.size() == 1)
{
return sign.front();
}
return {'7'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign8(const QLocale &locale)
{
const QString sign = locale.toString(8);
if (sign.size() == 1)
{
return sign.front();
}
return {'8'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleSign9(const QLocale &locale)
{
const QString sign = locale.toString(9);
if (sign.size() == 1)
{
return sign.front();
}
return {'9'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleExpUpper(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.exponential();
if (sign.size() == 1)
{
return sign.front().toUpper();
}
return QLocale::c().exponential().front().toUpper();
#else
return locale.exponential().toUpper();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleExpLower(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.exponential();
if (sign.size() == 1)
{
return sign.front().toLower();
}
return QLocale::c().exponential().front().toLower();
#else
return locale.exponential().toLower();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleDecimalPoint(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.decimalPoint();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().decimalPoint().front();
#else
return locale.decimalPoint();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar LocaleGroupSeparator(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.groupSeparator();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().groupSeparator().front();
#else
return locale.groupSeparator();
#endif
}

View File

@ -105,23 +105,42 @@ class QLocale;
class QChar;
class QString;
QMUPARSERSHARED_EXPORT auto SupportedLocale(const QLocale &locale) -> bool;
QMUPARSERSHARED_EXPORT auto LocalePositiveSign(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleNegativeSign(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign0(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign1(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign2(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign3(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign4(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign5(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign6(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign7(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign8(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleSign9(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleExpUpper(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleExpLower(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleDecimalPoint(const QLocale &locale) -> QChar;
QMUPARSERSHARED_EXPORT auto LocaleGroupSeparator(const QLocale &locale) -> QChar;
#define INIT_LOCALE_VARIABLES(locale) \
const QChar positiveSign = (locale).positiveSign(); \
const QChar negativeSign = (locale).negativeSign(); \
const QChar sign0 = (locale).toString(0).at(0); \
const QChar sign1 = (locale).toString(1).at(0); \
const QChar sign2 = (locale).toString(2).at(0); \
const QChar sign3 = (locale).toString(3).at(0); \
const QChar sign4 = (locale).toString(4).at(0); \
const QChar sign5 = (locale).toString(5).at(0); \
const QChar sign6 = (locale).toString(6).at(0); \
const QChar sign7 = (locale).toString(7).at(0); \
const QChar sign8 = (locale).toString(8).at(0); \
const QChar sign9 = (locale).toString(9).at(0); \
const QChar expUpper = (locale).exponential().toUpper(); \
const QChar expLower = (locale).exponential().toLower(); \
const QChar decimalPoint = (locale).decimalPoint(); \
const QChar groupSeparator = (locale).groupSeparator() \
const QChar positiveSign = LocalePositiveSign((locale)); \
const QChar negativeSign = LocaleNegativeSign((locale)); \
const QChar sign0 = LocaleSign0((locale)); \
const QChar sign1 = LocaleSign1((locale)); \
const QChar sign2 = LocaleSign2((locale)); \
const QChar sign3 = LocaleSign3((locale)); \
const QChar sign4 = LocaleSign4((locale)); \
const QChar sign5 = LocaleSign5((locale)); \
const QChar sign6 = LocaleSign6((locale)); \
const QChar sign7 = LocaleSign7((locale)); \
const QChar sign8 = LocaleSign8((locale)); \
const QChar sign9 = LocaleSign9((locale)); \
const QChar expUpper = LocaleExpUpper((locale)); \
const QChar expLower = LocaleExpLower((locale)); \
const QChar decimalPoint = LocaleDecimalPoint((locale)); \
const QChar groupSeparator = LocaleGroupSeparator((locale));
QMUPARSERSHARED_EXPORT QString NameRegExp();

View File

@ -147,8 +147,8 @@ void QmuFormulaBase::SetSepForTr(bool osSeparator, bool fromUser)
setCNumbers(not osSeparator);
if (osSeparator)
{
setDecimalPoint(loc.decimalPoint());
setThousandsSeparator(loc.groupSeparator());
setDecimalPoint(LocaleDecimalPoint(loc));
setThousandsSeparator(LocaleGroupSeparator(loc));
return;
}
}

View File

@ -507,7 +507,7 @@ void QmuParser::InitConst()
*/
void QmuParser::InitOprt()
{
DefineInfixOprt(m_locale.negativeSign(), UnaryMinus);
DefineInfixOprt(LocaleNegativeSign(m_locale), UnaryMinus);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -64,8 +64,8 @@ const QStringList QmuParserBase::c_DefaultOprt = QStringList()<< "<=" << ">=" <<
*/
QmuParserBase::QmuParserBase()
: m_locale(QLocale::c()),
m_decimalPoint(QLocale::c().decimalPoint()),
m_thousandsSeparator(QLocale::c().groupSeparator()),
m_decimalPoint(LocaleDecimalPoint(QLocale::c())),
m_thousandsSeparator(LocaleGroupSeparator(QLocale::c())),
m_FunDef(),
m_pTokenReader(),
m_pParseFormula(&QmuParserBase::ParseString),
@ -204,8 +204,8 @@ void QmuParserBase::Assign(const QmuParserBase &a_Parser)
void QmuParserBase::ResetLocale()
{
setLocale(QLocale::c());
m_decimalPoint = m_locale.decimalPoint();
m_thousandsSeparator = m_locale.groupSeparator();
m_decimalPoint = LocaleDecimalPoint(m_locale);
m_thousandsSeparator = LocaleGroupSeparator(m_locale);
m_cNumbers = false;
SetArgSep(';');
}

View File

@ -54,7 +54,6 @@ QmuTokenParser::QmuTokenParser()
*/
QmuTokenParser::QmuTokenParser(const QString &formula, bool osSeparator,
bool fromUser, const QMap<QString, QString> &translatedFunctions)
:QmuFormulaBase()
{
InitCharSets();
SetVarFactory(AddVariable, this);

View File

@ -302,4 +302,20 @@ inline auto Insert(QMap<Key, T> &map1, const QMap<Key, T> &map2) -> void
#endif
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VLocaleCharacter(const QString &character) -> QChar
{
Q_ASSERT(character.size() == 1);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
return character.front();
#else
return character.at(0);
#endif
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VLocaleCharacter(const QChar &character) -> QChar
{
return character;
}
#endif // COMPATIBILITY_H

View File

@ -1449,24 +1449,24 @@ auto VPiece::ShortNameRegExp() -> QString
for(const auto &locale : allLocales)
{
if (not positiveSigns.contains(locale.positiveSign()))
if (not positiveSigns.contains(LocalePositiveSign(locale)))
{
positiveSigns.append(locale.positiveSign());
positiveSigns.append(LocalePositiveSign(locale));
}
if (not negativeSigns.contains(locale.negativeSign()))
if (not negativeSigns.contains(LocaleNegativeSign(locale)))
{
negativeSigns.append(locale.negativeSign());
negativeSigns.append(LocaleNegativeSign(locale));
}
if (not decimalPoints.contains(locale.decimalPoint()))
if (not decimalPoints.contains(LocaleDecimalPoint(locale)))
{
decimalPoints.append(locale.decimalPoint());
decimalPoints.append(LocaleDecimalPoint(locale));
}
if (not groupSeparators.contains(locale.groupSeparator()))
if (not groupSeparators.contains(LocaleGroupSeparator(locale)))
{
groupSeparators.append(locale.groupSeparator());
groupSeparators.append(LocaleGroupSeparator(locale));
}
}

View File

@ -39,10 +39,12 @@
#include "../qmuparser/qmuparsererror.h"
#include "../qmuparser/qmutokenparser.h"
#include "../qmuparser/qmutranslation.h"
#include "../qmuparser/qmudef.h"
#include "../vpatterndb/vtranslatevars.h"
#include "../vmisc/def.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/literals.h"
#include "../vmisc/compatibility.h"
#include "vtranslatemeasurements.h"
#include "pmsystems.h"
@ -677,7 +679,7 @@ void VTranslateVars::TranslateVarsFromUser(QString &newFormula, QMap<vsizetype,
continue;
}
if (tValues.at(i) == QLocale().negativeSign())
if (tValues.at(i) == LocaleNegativeSign(QLocale()))
{// unary minus
newFormula.replace(tKeys.at(i), 1, '-');
}
@ -774,7 +776,7 @@ void VTranslateVars::TranslateVarsToUser(QString &newFormula, QMap<vsizetype, QS
if (tValues.at(i) == QChar('-'))
{// unary minus
newFormula.replace(tKeys.at(i), 1, QLocale().negativeSign());
newFormula.replace(tKeys.at(i), 1, LocaleNegativeSign(QLocale()));
}
}
}
@ -801,9 +803,9 @@ void VTranslateVars::TranslateNumbersToUser(QString &newFormula, QMap<vsizetype,
loc = QLocale();// To user locale
QString dStr = loc.toString(d);// Number string in user locale
if (loc.groupSeparator().isSpace())
if (VLocaleCharacter(LocaleGroupSeparator(loc)).isSpace())
{
dStr.replace(loc.groupSeparator(), QString());
dStr.replace(LocaleGroupSeparator(loc), QString());
}
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
const auto bias = nValues.at(i).length() - dStr.length();

View File

@ -172,11 +172,11 @@ bool VPE::VStringProperty::eventFilter(QObject *object, QEvent *event)
{
if (m_osSeparator)
{
textEdit->insert(QLocale().decimalPoint());
textEdit->insert(VPELocaleDecimalPoint(QLocale()));
}
else
{
textEdit->insert(QLocale::c().decimalPoint());
textEdit->insert(VPELocaleDecimalPoint(QLocale::c()));
}
return true;
}

View File

@ -0,0 +1,245 @@
/************************************************************************
**
** @file vpropertydef.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 2, 2023
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2023 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vpropertydef.h"
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocalePositiveSign(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.positiveSign();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().positiveSign().front();
#else
return locale.positiveSign();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleNegativeSign(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.negativeSign();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().negativeSign().front();
#else
return locale.negativeSign();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign0(const QLocale &locale)
{
const QString sign = locale.toString(0);
if (sign.size() == 1)
{
return sign.front();
}
return {'0'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign1(const QLocale &locale)
{
const QString sign = locale.toString(1);
if (sign.size() == 1)
{
return sign.front();
}
return {'1'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign2(const QLocale &locale)
{
const QString sign = locale.toString(2);
if (sign.size() == 1)
{
return sign.front();
}
return {'2'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign3(const QLocale &locale)
{
const QString sign = locale.toString(3);
if (sign.size() == 1)
{
return sign.front();
}
return {'3'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign4(const QLocale &locale)
{
const QString sign = locale.toString(4);
if (sign.size() == 1)
{
return sign.front();
}
return {'4'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign5(const QLocale &locale)
{
const QString sign = locale.toString(5);
if (sign.size() == 1)
{
return sign.front();
}
return {'5'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign6(const QLocale &locale)
{
const QString sign = locale.toString(6);
if (sign.size() == 1)
{
return sign.front();
}
return {'6'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign7(const QLocale &locale)
{
const QString sign = locale.toString(7);
if (sign.size() == 1)
{
return sign.front();
}
return {'7'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign8(const QLocale &locale)
{
const QString sign = locale.toString(8);
if (sign.size() == 1)
{
return sign.front();
}
return {'8'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleSign9(const QLocale &locale)
{
const QString sign = locale.toString(9);
if (sign.size() == 1)
{
return sign.front();
}
return {'9'};
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleExpUpper(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.exponential();
if (sign.size() == 1)
{
return sign.front().toUpper();
}
return QLocale::c().exponential().front().toUpper();
#else
return locale.exponential().toUpper();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleExpLower(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.exponential();
if (sign.size() == 1)
{
return sign.front().toLower();
}
return QLocale::c().exponential().front().toLower();
#else
return locale.exponential().toLower();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleDecimalPoint(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.decimalPoint();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().decimalPoint().front();
#else
return locale.decimalPoint();
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QChar VPELocaleGroupSeparator(const QLocale &locale)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QString sign = locale.groupSeparator();
if (sign.size() == 1)
{
return sign.front();
}
return QLocale::c().groupSeparator().front();
#else
return locale.groupSeparator();
#endif
}

View File

@ -28,6 +28,8 @@
#ifndef VPROPERTYDEF_H
#define VPROPERTYDEF_H
#include "vpropertyexplorer_global.h"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QtGlobal>
using vpesizetype = qsizetype;
@ -35,4 +37,21 @@ using vpesizetype = qsizetype;
using vpesizetype = int;
#endif
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocalePositiveSign(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleNegativeSign(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign0(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign1(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign2(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign3(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign4(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign5(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign6(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign7(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign8(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleSign9(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleExpUpper(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleExpLower(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleDecimalPoint(const QLocale &locale) -> QChar;
VPROPERTYEXPLORERSHARED_EXPORT auto VPELocaleGroupSeparator(const QLocale &locale) -> QChar;
#endif // VPROPERTYDEF_H

View File

@ -4,6 +4,7 @@
SOURCES += \
$$PWD/plugins/vtextproperty.cpp \
$$PWD/vproperty.cpp \
$$PWD/vpropertydef.cpp \
$$PWD/vpropertydelegate.cpp \
$$PWD/vpropertyfactorymanager.cpp \
$$PWD/vpropertyformview.cpp \
@ -56,6 +57,7 @@ HEADERS +=\
$$PWD/vpropertyset.h \
$$PWD/vpropertymodel.h \
$$PWD/vproperty.h \
$$PWD/vpropertydef.h \
$$PWD/plugins/vwidgetproperty.h \
$$PWD/plugins/vcolorproperty.h \
$$PWD/plugins/vboolproperty.h \

View File

@ -7,6 +7,7 @@ VDynamicLib {
version: "1.0.0"
files: [
"vproperty.cpp",
"vpropertydef.cpp",
"vpropertydef.h",
"vpropertydelegate.cpp",
"vpropertyfactorymanager.cpp",

View File

@ -250,11 +250,11 @@ bool FilterObject(QObject *object, QEvent *event)
{
if (VAbstractApplication::VApp()->Settings()->GetOsSeparator())
{
plainTextEdit->insertPlainText(QLocale().decimalPoint());
plainTextEdit->insertPlainText(LocaleDecimalPoint(QLocale()));
}
else
{
plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
plainTextEdit->insertPlainText(LocaleDecimalPoint(QLocale::c()));
}
return true;
}

View File

@ -48,7 +48,7 @@ void TST_NameRegExp::TestNameRegExp_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(auto &locale : allLocales)
for(const auto &locale : allLocales)
{
INIT_LOCALE_VARIABLES(locale);
Q_UNUSED(positiveSign)
@ -56,6 +56,7 @@ void TST_NameRegExp::TestNameRegExp_data()
Q_UNUSED(expLower)
const QString localeName = locale.name();
QString tag = localeName+QLatin1String(". First character can't be ")+sign0;
QTest::newRow(qUtf8Printable(tag)) << sign0+QLatin1String("a") << false;

View File

@ -28,6 +28,7 @@
#include "tst_qmutokenparser.h"
#include "../qmuparser/qmutokenparser.h"
#include "../qmuparser/qmudef.h"
#include <QtTest>
@ -83,8 +84,12 @@ void TST_QmuTokenParser::TokenFromUser_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(auto &locale : allLocales)
for(const auto &locale : allLocales)
{
if (not SupportedLocale(locale))
{
continue;
}
PrepareVal(1000.5, locale);
PrepareVal(-1000.5, locale);
}
@ -153,14 +158,7 @@ bool TST_QmuTokenParser::IsSingleFromUser(const QString &formula)
}
// Remove "-" from tokens list if exist. If don't do that unary minus operation will broken.
qmu::QmuFormulaBase::RemoveAll(tokens, QLocale().negativeSign());
qmu::QmuFormulaBase::RemoveAll(tokens, LocaleNegativeSign(QLocale()));
if (tokens.isEmpty() && numbers.size() == 1)
{
return true;
}
else
{
return false;
}
return tokens.isEmpty() && numbers.size() == 1;
}

View File

@ -28,6 +28,7 @@
#include "tst_readval.h"
#include "../qmuparser/qmudef.h"
#include "../vmisc/compatibility.h"
#include <QtTest>
#include <limits>
@ -49,8 +50,13 @@ void TST_ReadVal::TestReadVal_data()
const QList<QLocale> allLocales =
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(auto &locale : allLocales)
for(const auto &locale : allLocales)
{
if (not SupportedLocale(locale))
{
continue;
}
PrepareVal(1., locale);
PrepareVal(1.0, locale);
PrepareVal(-1.0, locale);
@ -138,7 +144,8 @@ void TST_ReadVal::TestVal()
qreal resVal = 0;
QLocale::setDefault(locale);
const vsizetype resCount = ReadVal(formula, resVal, locale, locale.decimalPoint(), locale.groupSeparator());
const vsizetype resCount = ReadVal(formula, resVal, locale, VLocaleCharacter(LocaleDecimalPoint(locale)),
VLocaleCharacter(LocaleGroupSeparator(locale)));
// cppcheck-suppress unreadVariable
QString errorMsg = QStringLiteral("Conversion failed. Locale: '%1'.").arg(locale.name());

View File

@ -28,8 +28,9 @@
#include "tst_vtranslatevars.h"
#include "../vpatterndb/vtranslatevars.h"
#include "../qmuparser/qmuparsererror.h"
#include "../qmuparser/qmudef.h"
#include "testvapplication.h"
#include "../vmisc/compatibility.h"
#include <QtTest>
@ -59,6 +60,11 @@ void TST_VTranslateVars::TestFormulaFromUser_data()
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(auto &locale : allLocales)
{
if (not SupportedLocale(locale))
{
continue;
}
PrepareValFromUser(1000.5, locale);
PrepareValFromUser(-1000.5, locale);
}
@ -89,6 +95,11 @@ void TST_VTranslateVars::TestFormulaToUser_data()
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for(auto &locale : allLocales)
{
if (not SupportedLocale(locale))
{
continue;
}
PrepareValToUser(1000.5, locale);
PrepareValToUser(-1000.5, locale);
}
@ -129,9 +140,9 @@ void TST_VTranslateVars::PrepareValToUser(double d, const QLocale &locale)
{
const QString formulaFromSystem = QLocale::c().toString(d);
QString formulaToUser = locale.toString(d);
if (locale.groupSeparator().isSpace())
if (VLocaleCharacter(LocaleGroupSeparator(locale)).isSpace())
{
formulaToUser.replace(locale.groupSeparator(), QString());
formulaToUser.replace(LocaleGroupSeparator(locale), QString());
}
PrepareVal(formulaFromSystem, formulaToUser, locale);