Skip to content

Commit

Permalink
[skip ci] use QLocale class consistently to make it possible to chang…
Browse files Browse the repository at this point in the history
…e it application-wide
  • Loading branch information
wwmayer committed Mar 26, 2020
1 parent caee1eb commit ec8b1bc
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/Base/UnitsSchema.cpp
Expand Up @@ -38,7 +38,7 @@ using namespace Base;
QString UnitsSchema::toLocale(const Base::Quantity& quant, double factor, const QString& unitString) const
{
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
QLocale Lc = QLocale::system();
QLocale Lc;
const QuantityFormat& format = quant.getFormat();
if (format.option != QuantityFormat::None) {
uint opt = static_cast<uint>(format.option);
Expand Down
1 change: 0 additions & 1 deletion src/Base/UnitsSchemaCentimeters.cpp
Expand Up @@ -27,7 +27,6 @@
#endif

#include <QString>
#include <QLocale>
#include "Exception.h"
#include "UnitsApi.h"
#include "UnitsSchemaCentimeters.h"
Expand Down
1 change: 0 additions & 1 deletion src/Base/UnitsSchemaImperial1.cpp
Expand Up @@ -30,7 +30,6 @@
#endif

#include <QString>
#include <QLocale>
#include "Console.h"
#include "Exception.h"
#include "UnitsApi.h"
Expand Down
1 change: 0 additions & 1 deletion src/Base/UnitsSchemaInternal.cpp
Expand Up @@ -27,7 +27,6 @@
#endif

#include <QString>
#include <QLocale>
#include "Exception.h"
#include "UnitsApi.h"
#include "UnitsSchemaInternal.h"
Expand Down
1 change: 0 additions & 1 deletion src/Base/UnitsSchemaMKS.cpp
Expand Up @@ -27,7 +27,6 @@
#endif

#include <QString>
#include <QLocale>
#include "Exception.h"
#include "UnitsApi.h"
#include "UnitsSchemaMKS.h"
Expand Down
1 change: 0 additions & 1 deletion src/Base/UnitsSchemaMmMin.cpp
Expand Up @@ -27,7 +27,6 @@
#endif

#include <QString>
#include <QLocale>
#include "Exception.h"
#include "UnitsApi.h"
#include "UnitsSchemaMmMin.h"
Expand Down
6 changes: 3 additions & 3 deletions src/Gui/Application.cpp
Expand Up @@ -305,7 +305,7 @@ Application::Application(bool GUIenabled)
// install the last active language
ParameterGrp::handle hPGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp");
hPGrp = hPGrp->GetGroup("Preferences")->GetGroup("General");
QString lang = QLocale::languageToString(QLocale::system().language());
QString lang = QLocale::languageToString(QLocale().language());
Translator::instance()->activateLanguage(hPGrp->GetASCII("Language", (const char*)lang.toLatin1()).c_str());
GetWidgetFactorySupplier();

Expand All @@ -319,7 +319,7 @@ Application::Application(bool GUIenabled)
// Check for the symbols for group separator and decimal point. They must be different otherwise
// Qt doesn't work properly.
#if defined(Q_OS_WIN32)
if (QLocale::system().groupSeparator() == QLocale::system().decimalPoint()) {
if (QLocale().groupSeparator() == QLocale().decimalPoint()) {
QMessageBox::critical(0, QLatin1String("Invalid system settings"),
QLatin1String("Your system uses the same symbol for decimal point and group separator.\n\n"
"This causes serious problems and makes the application fail to work properly.\n"
Expand All @@ -331,7 +331,7 @@ Application::Application(bool GUIenabled)
// http://forum.freecadweb.org/viewtopic.php?f=10&t=6910
// A workaround is to disable the group separator for double-to-string conversion, i.e.
// setting the flag 'OmitGroupSeparator'.
QLocale loc = QLocale::system();
QLocale loc;
loc.setNumberOptions(QLocale::OmitGroupSeparator);
QLocale::setDefault(loc);
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/DlgGeneralImp.cpp
Expand Up @@ -131,7 +131,7 @@ void DlgGeneralImp::saveSettings()

setRecentFileSize();
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
QString lang = QLocale::languageToString(QLocale::system().language());
QString lang = QLocale::languageToString(QLocale().language());
QByteArray language = hGrp->GetASCII("Language", (const char*)lang.toLatin1()).c_str();
QByteArray current = ui->Languages->itemData(ui->Languages->currentIndex()).toByteArray();
if (current != language) {
Expand Down Expand Up @@ -182,7 +182,7 @@ void DlgGeneralImp::loadSettings()

// search for the language files
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
QString langToStr = QLocale::languageToString(QLocale::system().language());
QString langToStr = QLocale::languageToString(QLocale().language());
QByteArray language = hGrp->GetASCII("Language", langToStr.toLatin1()).c_str();

int index = 1;
Expand Down
12 changes: 6 additions & 6 deletions src/Gui/DlgSettingsColorGradientImp.cpp
Expand Up @@ -136,17 +136,17 @@ bool DlgSettingsColorGradientImp::isOutInvisible() const
void DlgSettingsColorGradientImp::setRange( float fMin, float fMax )
{
ui->floatLineEditMax->blockSignals(true);
ui->floatLineEditMax->setText(QLocale::system().toString(fMax, 'f', numberOfDecimals()));
ui->floatLineEditMax->setText(QLocale().toString(fMax, 'f', numberOfDecimals()));
ui->floatLineEditMax->blockSignals(false);
ui->floatLineEditMin->blockSignals(true);
ui->floatLineEditMin->setText(QLocale::system().toString(fMin, 'f', numberOfDecimals()));
ui->floatLineEditMin->setText(QLocale().toString(fMin, 'f', numberOfDecimals()));
ui->floatLineEditMin->blockSignals(false);
}

void DlgSettingsColorGradientImp::getRange(float& fMin, float& fMax) const
{
fMax = QLocale::system().toFloat(ui->floatLineEditMax->text());
fMin = QLocale::system().toFloat(ui->floatLineEditMin->text());
fMax = QLocale().toFloat(ui->floatLineEditMax->text());
fMin = QLocale().toFloat(ui->floatLineEditMin->text());
}

void DlgSettingsColorGradientImp::setNumberOfLabels(int val)
Expand All @@ -171,8 +171,8 @@ int DlgSettingsColorGradientImp::numberOfDecimals() const

void DlgSettingsColorGradientImp::accept()
{
double fMax = QLocale::system().toDouble(ui->floatLineEditMax->text());
double fMin = QLocale::system().toDouble(ui->floatLineEditMin->text());
double fMax = QLocale().toDouble(ui->floatLineEditMax->text());
double fMin = QLocale().toDouble(ui->floatLineEditMin->text());

if (fMax <= fMin) {
QMessageBox::warning(this, tr("Wrong parameter"),
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/DlgUnitsCalculatorImp.cpp
Expand Up @@ -159,9 +159,9 @@ void DlgUnitsCalculator::valueChanged(const Base::Quantity& quant)
// at first use scientific notation, if there is no "e", we can round it to the user-defined decimals,
// but the user-defined decimals might be too low for cases like "10 um" in "in",
// thus only if value > 0.005 because FC's default are 2 decimals
QString val = QLocale::system().toString(value, 'g');
QString val = QLocale().toString(value, 'g');
if (!val.contains(QChar::fromLatin1('e')) && (value > 0.005))
val = QLocale::system().toString(value, 'f', Base::UnitsApi::getDecimals());
val = QLocale().toString(value, 'f', Base::UnitsApi::getDecimals());
// create the output string
QString out = QString::fromLatin1("%1 %2").arg(val, ui->UnitInput->text());
ui->ValueOutput->setText(out);
Expand Down
116 changes: 63 additions & 53 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -937,7 +937,7 @@ PropertyFloatItem::PropertyFloatItem()
QVariant PropertyFloatItem::toString(const QVariant& prop) const
{
double value = prop.toDouble();
QString data = QLocale::system().toString(value, 'f', decimals());
QString data = QLocale().toString(value, 'f', decimals());

if (hasExpression())
data += QString::fromLatin1(" ( %1 )").arg(QString::fromStdString(getExpressionString()));
Expand Down Expand Up @@ -1116,7 +1116,7 @@ PropertyFloatConstraintItem::PropertyFloatConstraintItem()
QVariant PropertyFloatConstraintItem::toString(const QVariant& prop) const
{
double value = prop.toDouble();
QString data = QLocale::system().toString(value, 'f', decimals());
QString data = QLocale().toString(value, 'f', decimals());
return QVariant(data);
}

Expand Down Expand Up @@ -1317,11 +1317,12 @@ PropertyVectorItem::PropertyVectorItem()

QVariant PropertyVectorItem::toString(const QVariant& prop) const
{
QLocale loc;
const Base::Vector3d& value = prop.value<Base::Vector3d>();
QString data = QString::fromLatin1("[%1 %2 %3]")
.arg(QLocale::system().toString(value.x, 'f', 2),
QLocale::system().toString(value.y, 'f', 2),
QLocale::system().toString(value.z, 'f', 2));
.arg(loc.toString(value.x, 'f', 2),
loc.toString(value.y, 'f', 2),
loc.toString(value.z, 'f', 2));
if (hasExpression())
data += QString::fromLatin1(" ( %1 )").arg(QString::fromStdString(getExpressionString()));
return QVariant(data);
Expand Down Expand Up @@ -1363,12 +1364,13 @@ QWidget* PropertyVectorItem::createEditor(QWidget* parent, const QObject* /*rece

void PropertyVectorItem::setEditorData(QWidget *editor, const QVariant& data) const
{
QLocale loc;
QLineEdit* le = qobject_cast<QLineEdit*>(editor);
const Base::Vector3d& value = data.value<Base::Vector3d>();
QString text = QString::fromLatin1("[%1 %2 %3]")
.arg(QLocale::system().toString(value.x, 'f', 2),
QLocale::system().toString(value.y, 'f', 2),
QLocale::system().toString(value.z, 'f', 2));
.arg(loc.toString(value.x, 'f', 2),
loc.toString(value.y, 'f', 2),
loc.toString(value.z, 'f', 2));
le->setProperty("coords", data);
le->setText(text);
}
Expand Down Expand Up @@ -1634,24 +1636,25 @@ PropertyMatrixItem::PropertyMatrixItem()

QVariant PropertyMatrixItem::toString(const QVariant& prop) const
{
QLocale loc;
const Base::Matrix4D& value = prop.value<Base::Matrix4D>();
QString text = QString::fromLatin1("[%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16]")
.arg(QLocale::system().toString(value[0][0], 'f', 2), //(unsigned short usNdx)
QLocale::system().toString(value[0][1], 'f', 2),
QLocale::system().toString(value[0][2], 'f', 2),
QLocale::system().toString(value[0][3], 'f', 2),
QLocale::system().toString(value[1][0], 'f', 2),
QLocale::system().toString(value[1][1], 'f', 2),
QLocale::system().toString(value[1][2], 'f', 2),
QLocale::system().toString(value[1][3], 'f', 2),
QLocale::system().toString(value[2][0], 'f', 2))
.arg(QLocale::system().toString(value[2][1], 'f', 2),
QLocale::system().toString(value[2][2], 'f', 2),
QLocale::system().toString(value[2][3], 'f', 2),
QLocale::system().toString(value[3][0], 'f', 2),
QLocale::system().toString(value[3][1], 'f', 2),
QLocale::system().toString(value[3][2], 'f', 2),
QLocale::system().toString(value[3][3], 'f', 2));
.arg(loc.toString(value[0][0], 'f', 2), //(unsigned short usNdx)
loc.toString(value[0][1], 'f', 2),
loc.toString(value[0][2], 'f', 2),
loc.toString(value[0][3], 'f', 2),
loc.toString(value[1][0], 'f', 2),
loc.toString(value[1][1], 'f', 2),
loc.toString(value[1][2], 'f', 2),
loc.toString(value[1][3], 'f', 2),
loc.toString(value[2][0], 'f', 2))
.arg(loc.toString(value[2][1], 'f', 2),
loc.toString(value[2][2], 'f', 2),
loc.toString(value[2][3], 'f', 2),
loc.toString(value[3][0], 'f', 2),
loc.toString(value[3][1], 'f', 2),
loc.toString(value[3][2], 'f', 2),
loc.toString(value[3][3], 'f', 2));
return QVariant(text);
}

Expand Down Expand Up @@ -1707,25 +1710,26 @@ QWidget* PropertyMatrixItem::createEditor(QWidget* parent, const QObject* /*rece

void PropertyMatrixItem::setEditorData(QWidget *editor, const QVariant& data) const
{
QLocale loc;
QLineEdit* le = qobject_cast<QLineEdit*>(editor);
const Base::Matrix4D& value = data.value<Base::Matrix4D>();
QString text = QString::fromLatin1("[%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16]")
.arg(QLocale::system().toString(value[0][0], 'f', 2), //(unsigned short usNdx)
QLocale::system().toString(value[0][1], 'f', 2),
QLocale::system().toString(value[0][2], 'f', 2),
QLocale::system().toString(value[0][3], 'f', 2),
QLocale::system().toString(value[1][0], 'f', 2),
QLocale::system().toString(value[1][1], 'f', 2),
QLocale::system().toString(value[1][2], 'f', 2),
QLocale::system().toString(value[1][3], 'f', 2),
QLocale::system().toString(value[2][0], 'f', 2))
.arg(QLocale::system().toString(value[2][1], 'f', 2),
QLocale::system().toString(value[2][2], 'f', 2),
QLocale::system().toString(value[2][3], 'f', 2),
QLocale::system().toString(value[3][0], 'f', 2),
QLocale::system().toString(value[3][1], 'f', 2),
QLocale::system().toString(value[3][2], 'f', 2),
QLocale::system().toString(value[3][3], 'f', 2));
.arg(loc.toString(value[0][0], 'f', 2), //(unsigned short usNdx)
loc.toString(value[0][1], 'f', 2),
loc.toString(value[0][2], 'f', 2),
loc.toString(value[0][3], 'f', 2),
loc.toString(value[1][0], 'f', 2),
loc.toString(value[1][1], 'f', 2),
loc.toString(value[1][2], 'f', 2),
loc.toString(value[1][3], 'f', 2),
loc.toString(value[2][0], 'f', 2))
.arg(loc.toString(value[2][1], 'f', 2),
loc.toString(value[2][2], 'f', 2),
loc.toString(value[2][3], 'f', 2),
loc.toString(value[3][0], 'f', 2),
loc.toString(value[3][1], 'f', 2),
loc.toString(value[3][2], 'f', 2),
loc.toString(value[3][3], 'f', 2));
le->setText(text);
}

Expand Down Expand Up @@ -1939,14 +1943,16 @@ void PlacementEditor::showValue(const QVariant& d)
p.getRotation().getRawValue(dir, angle);
angle = Base::toDegrees<double>(angle);
pos = p.getPosition();

QLocale loc;
QString data = QString::fromUtf8("[(%1 %2 %3);%4 \xc2\xb0;(%5 %6 %7)]")
.arg(QLocale::system().toString(dir.x,'f',2),
QLocale::system().toString(dir.y,'f',2),
QLocale::system().toString(dir.z,'f',2),
QLocale::system().toString(angle,'f',2),
QLocale::system().toString(pos.x,'f',2),
QLocale::system().toString(pos.y,'f',2),
QLocale::system().toString(pos.z,'f',2));
.arg(loc.toString(dir.x,'f',2),
loc.toString(dir.y,'f',2),
loc.toString(dir.z,'f',2),
loc.toString(angle,'f',2),
loc.toString(pos.x,'f',2),
loc.toString(pos.y,'f',2),
loc.toString(pos.z,'f',2));
getLabel()->setText(data);
}

Expand Down Expand Up @@ -2138,12 +2144,14 @@ QVariant PropertyPlacementItem::toolTip(const App::Property* prop) const
p.getRotation().getRawValue(dir, angle);
angle = Base::toDegrees<double>(angle);
pos = p.getPosition();

QLocale loc;
QString data = QString::fromUtf8("Axis: (%1 %2 %3)\n"
"Angle: %4\n"
"Position: (%5 %6 %7)")
.arg(QLocale::system().toString(dir.x,'f',decimals()),
QLocale::system().toString(dir.y,'f',decimals()),
QLocale::system().toString(dir.z,'f',decimals()),
.arg(loc.toString(dir.x,'f',decimals()),
loc.toString(dir.y,'f',decimals()),
loc.toString(dir.z,'f',decimals()),
Base::Quantity(angle, Base::Unit::Angle).getUserString(),
Base::Quantity(pos.x, Base::Unit::Length).getUserString(),
Base::Quantity(pos.y, Base::Unit::Length).getUserString(),
Expand All @@ -2159,10 +2167,12 @@ QVariant PropertyPlacementItem::toString(const QVariant& prop) const
p.getRotation().getRawValue(dir, angle);
angle = Base::toDegrees<double>(angle);
pos = p.getPosition();

QLocale loc;
QString data = QString::fromUtf8("[(%1 %2 %3); %4; (%5 %6 %7)]")
.arg(QLocale::system().toString(dir.x,'f',2),
QLocale::system().toString(dir.y,'f',2),
QLocale::system().toString(dir.z,'f',2),
.arg(loc.toString(dir.x,'f',2),
loc.toString(dir.y,'f',2),
loc.toString(dir.z,'f',2),
Base::Quantity(angle, Base::Unit::Angle).getUserString(),
Base::Quantity(pos.x, Base::Unit::Length).getUserString(),
Base::Quantity(pos.y, Base::Unit::Length).getUserString(),
Expand Down
10 changes: 5 additions & 5 deletions src/Mod/Part/Gui/DlgFilletEdges.cpp
Expand Up @@ -110,7 +110,7 @@ void FilletRadiusDelegate::setModelData(QWidget *editor, QAbstractItemModel *mod
spinBox->interpretText();
//double value = spinBox->value();
//QString value = QString::fromLatin1("%1").arg(spinBox->value(),0,'f',2);
//QString value = QLocale::system().toString(spinBox->value().getValue(),'f',Base::UnitsApi::getDecimals());
//QString value = QLocale().toString(spinBox->value().getValue(),'f',Base::UnitsApi::getDecimals());
Base::Quantity value = spinBox->value();

model->setData(index, QVariant::fromValue<Base::Quantity>(value), Qt::EditRole);
Expand Down Expand Up @@ -594,8 +594,8 @@ void DlgFilletEdges::setupFillet(const std::vector<App::DocumentObject*>& objs)
if (it != d->edge_ids.end()) {
int index = it - d->edge_ids.begin();
model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole);
//model->setData(model->index(index, 1), QVariant(QLocale::system().toString(et->radius1,'f',Base::UnitsApi::getDecimals())));
//model->setData(model->index(index, 2), QVariant(QLocale::system().toString(et->radius2,'f',Base::UnitsApi::getDecimals())));
//model->setData(model->index(index, 1), QVariant(QLocale().toString(et->radius1,'f',Base::UnitsApi::getDecimals())));
//model->setData(model->index(index, 2), QVariant(QLocale().toString(et->radius2,'f',Base::UnitsApi::getDecimals())));
model->setData(model->index(index, 1), QVariant::fromValue<Base::Quantity>(Base::Quantity(et->radius1, Base::Unit::Length)));
model->setData(model->index(index, 2), QVariant::fromValue<Base::Quantity>(Base::Quantity(et->radius2, Base::Unit::Length)));

Expand Down Expand Up @@ -751,8 +751,8 @@ void DlgFilletEdges::on_shapeObject_activated(int index)
for (std::vector<int>::iterator it = d->edge_ids.begin(); it != d->edge_ids.end(); ++it) {
model->setData(model->index(index, 0), QVariant(tr("Edge%1").arg(*it)));
model->setData(model->index(index, 0), QVariant(*it), Qt::UserRole);
//model->setData(model->index(index, 1), QVariant(QLocale::system().toString(1.0,'f',Base::UnitsApi::getDecimals())));
//model->setData(model->index(index, 2), QVariant(QLocale::system().toString(1.0,'f',Base::UnitsApi::getDecimals())));
//model->setData(model->index(index, 1), QVariant(QLocale().toString(1.0,'f',Base::UnitsApi::getDecimals())));
//model->setData(model->index(index, 2), QVariant(QLocale().toString(1.0,'f',Base::UnitsApi::getDecimals())));
model->setData(model->index(index, 1), QVariant::fromValue<Base::Quantity>(Base::Quantity(1.0,Base::Unit::Length)));
model->setData(model->index(index, 2), QVariant::fromValue<Base::Quantity>(Base::Quantity(1.0,Base::Unit::Length)));
std::stringstream element;
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp
Expand Up @@ -82,8 +82,9 @@ SketcherValidation::SketcherValidation(Sketcher::SketchObject* Obj, QWidget* par
Precision::Confusion() * 100000
};

QLocale loc;
for (int i=0; i<8; i++) {
ui->comboBoxTolerance->addItem(QLocale::system().toString(tolerances[i]), QVariant(tolerances[i]));
ui->comboBoxTolerance->addItem(loc.toString(tolerances[i]), QVariant(tolerances[i]));
}
ui->comboBoxTolerance->setCurrentIndex(5);
ui->comboBoxTolerance->setEditable(true);
Expand Down

0 comments on commit ec8b1bc

Please sign in to comment.