Commit fafa93f6 authored by Stefan Gerlach's avatar Stefan Gerlach

[locale] Use number locale in most dialogs

parent 260ce708
......@@ -121,8 +121,8 @@ WorksheetView::WorksheetView(Worksheet* worksheet) : QGraphicsView(), m_workshee
}
//rescale to the original size
static const float hscale = QApplication::desktop()->physicalDpiX()/(Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch));
static const float vscale = QApplication::desktop()->physicalDpiY()/(Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch));
static const qreal hscale = QApplication::desktop()->physicalDpiX()/(Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch));
static const qreal vscale = QApplication::desktop()->physicalDpiY()/(Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch));
setTransform(QTransform::fromScale(hscale, vscale));
initBasicActions();
......
......@@ -27,13 +27,16 @@
***************************************************************************/
#include "SettingsDatasetsPage.h"
#include "backend/lib/macros.h"
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QDir>
#include <QMessageBox>
#include <QStandardPaths>
#include <KLocalizedString>
/**
* \brief Page for the 'General' settings of the Labplot settings dialog.
*/
......@@ -74,13 +77,14 @@ void SettingsDatasetsPage::loadSettings() {
size += QFileInfo(dir, file).size();
}
SET_NUMBER_LOCALE
QString sizeStr;
if (size > 1024*1024)
sizeStr = QString::number(size/1024/1024) + QLatin1String("MB");
sizeStr = numberLocale.toString(size/1024/1024) + QLatin1String("MB");
if (size > 1024)
sizeStr = QString::number(size/1024) + QLatin1String("kB");
sizeStr = numberLocale.toString(size/1024) + QLatin1String("kB");
else
sizeStr = QString::number(size) + QLatin1String("B");
sizeStr = numberLocale.toString(size) + QLatin1String("B");
ui.lSize->setText(i18n("Total size - %1", sizeStr));
} else
......
......@@ -72,9 +72,10 @@ MatrixFunctionDialog::MatrixFunctionDialog(Matrix* m, QWidget* parent) : QDialog
ui.teEquation->setFocus();
ui.teEquation->setMaximumHeight(QLineEdit().sizeHint().height()*2);
QString info = '[' + QString::number(m_matrix->xStart()) + ", " + QString::number(m_matrix->xEnd()) + "], " + i18np("%1 value", "%1 values", m_matrix->columnCount());
SET_NUMBER_LOCALE
QString info = '[' + numberLocale.toString(m_matrix->xStart()) + ", " + numberLocale.toString(m_matrix->xEnd()) + "], " + i18np("%1 value", "%1 values", m_matrix->columnCount());
ui.lXInfo->setText(info);
info = '[' + QString::number(m_matrix->yStart()) + ", " + QString::number(m_matrix->yEnd()) + "], " + i18np("%1 value", "%1 values", m_matrix->rowCount());
info = '[' + numberLocale.toString(m_matrix->yStart()) + ", " +numberLocale.toString(m_matrix->yEnd()) + "], " + i18np("%1 value", "%1 values", m_matrix->rowCount());
ui.lYInfo->setText(info);
ui.teEquation->setPlainText(m_matrix->formula());
......
......@@ -157,18 +157,19 @@ void AddSubtractValueDialog::setColumns(const QVector<Column*>& columns) {
//and show the first valid value in the first selected column as the value to add/subtract
const Column* column = m_columns.first();
const auto mode = column->columnMode();
SET_NUMBER_LOCALE
//TODO: switch
if (mode == AbstractColumn::ColumnMode::Integer) {
ui.lTimeValue->setVisible(false);
ui.dateTimeEdit->setVisible(false);
ui.leValue->setValidator(new QIntValidator(ui.leValue));
ui.leValue->setText(QString::number(column->integerAt(0)));
ui.leValue->setText(numberLocale.toString(column->integerAt(0)));
} else if (mode == AbstractColumn::ColumnMode::BigInt) {
ui.lTimeValue->setVisible(false);
ui.dateTimeEdit->setVisible(false);
//TODO: QLongLongVaildator
//TODO: QLongLongValidator
ui.leValue->setValidator(new QIntValidator(ui.leValue));
ui.leValue->setText(QString::number(column->bigIntAt(0)));
ui.leValue->setText(numberLocale.toString(column->bigIntAt(0)));
} else if (mode == AbstractColumn::ColumnMode::Numeric) {
ui.lTimeValue->setVisible(false);
ui.dateTimeEdit->setVisible(false);
......@@ -177,7 +178,7 @@ void AddSubtractValueDialog::setColumns(const QVector<Column*>& columns) {
for (int row = 0; row < column->rowCount(); ++row) {
const double value = column->valueAt(row);
if (!std::isnan(value)) {
ui.leValue->setText(QString::number(column->valueAt(row), 'g', 16));
ui.leValue->setText(numberLocale.toString(column->valueAt(row), 'g', 16));
break;
}
}
......@@ -199,25 +200,27 @@ void AddSubtractValueDialog::setColumns(const QVector<Column*>& columns) {
void AddSubtractValueDialog::setMatrices() {
const auto mode = m_matrix->mode();
SET_NUMBER_LOCALE
switch (mode) {
case AbstractColumn::ColumnMode::Integer:
ui.lTimeValue->setVisible(false);
ui.dateTimeEdit->setVisible(false);
ui.leValue->setValidator(new QIntValidator(ui.leValue));
ui.leValue->setText(QString::number(m_matrix->cell<int>(0,0)));
ui.leValue->setText(numberLocale.toString(m_matrix->cell<int>(0,0)));
break;
case AbstractColumn::ColumnMode::BigInt:
ui.lTimeValue->setVisible(false);
ui.dateTimeEdit->setVisible(false);
// TODO QLongLongValidator
// TODO: QLongLongValidator
ui.leValue->setValidator(new QIntValidator(ui.leValue));
ui.leValue->setText(QString::number(m_matrix->cell<qint64>(0,0)));
ui.leValue->setText(numberLocale.toString(m_matrix->cell<qint64>(0,0)));
break;
case AbstractColumn::ColumnMode::Numeric:
ui.lTimeValue->setVisible(false);
ui.dateTimeEdit->setVisible(false);
ui.leValue->setValidator(new QDoubleValidator(ui.leValue));
ui.leValue->setText(QString::number(m_matrix->cell<double>(0,0)));
ui.leValue->setText(numberLocale.toString(m_matrix->cell<double>(0,0)));
break;
case AbstractColumn::ColumnMode::DateTime:
case AbstractColumn::ColumnMode::Day:
......@@ -267,11 +270,18 @@ void AddSubtractValueDialog::generateForColumns() {
QString msg = getMessage(m_spreadsheet->name());
m_spreadsheet->beginMacro(msg);
SET_NUMBER_LOCALE
bool ok;
auto mode = m_columns.first()->columnMode();
const int rows = m_spreadsheet->rowCount();
if (mode == AbstractColumn::ColumnMode::Integer) {
QVector<int> new_data(rows);
int value = ui.leValue->text().toInt();
int value = numberLocale.toInt(ui.leValue->text(), &ok);
if (!ok) {
DEBUG("Integer value invalid!")
m_spreadsheet->endMacro();
return;
}
switch (m_operation) {
case Subtract:
......@@ -307,7 +317,12 @@ void AddSubtractValueDialog::generateForColumns() {
}
} else if (mode == AbstractColumn::ColumnMode::BigInt) {
QVector<qint64> new_data(rows);
qint64 value = ui.leValue->text().toLongLong();
qint64 value = numberLocale.toLongLong(ui.leValue->text(), &ok);
if (!ok) {
DEBUG("BigInt value invalid!")
m_spreadsheet->endMacro();
return;
}
switch (m_operation) {
case Subtract:
......@@ -343,7 +358,12 @@ void AddSubtractValueDialog::generateForColumns() {
}
} else if (mode == AbstractColumn::ColumnMode::Numeric) {
QVector<double> new_data(rows);
double value = ui.leValue->text().toDouble();
double value = numberLocale.toDouble(ui.leValue->text(), &ok);
if (!ok) {
DEBUG("Double value invalid!")
m_spreadsheet->endMacro();
return;
}
switch (m_operation) {
case Subtract:
value *= -1.;
......@@ -412,11 +432,18 @@ void AddSubtractValueDialog::generateForMatrices() {
auto mode = m_matrix->mode();
SET_NUMBER_LOCALE
bool ok;
const int rows = m_matrix->rowCount();
const int cols = m_matrix->columnCount();
if (mode == AbstractColumn::ColumnMode::Integer) {
int new_data;
int value = ui.leValue->text().toInt();
int value = numberLocale.toInt(ui.leValue->text(), &ok);
if (!ok) {
DEBUG("Integer value invalid!")
m_matrix->endMacro();
return;
}
switch (m_operation) {
case Subtract:
......@@ -452,7 +479,12 @@ void AddSubtractValueDialog::generateForMatrices() {
}
} else if (mode == AbstractColumn::ColumnMode::BigInt) {
qint64 new_data;
qint64 value = ui.leValue->text().toLongLong();
qint64 value = numberLocale.toLongLong(ui.leValue->text(), &ok);
if (!ok) {
DEBUG("BigInt value invalid!")
m_matrix->endMacro();
return;
}
switch (m_operation) {
case Subtract:
......@@ -485,7 +517,13 @@ void AddSubtractValueDialog::generateForMatrices() {
}
} else if (mode == AbstractColumn::ColumnMode::Numeric) {
double new_data;
double value = ui.leValue->text().toDouble();
double value = numberLocale.toDouble(ui.leValue->text(), &ok);
if (!ok) {
DEBUG("Double value invalid!")
m_matrix->endMacro();
return;
}
switch (m_operation) {
case Subtract:
value *= -1.;
......
......@@ -555,8 +555,20 @@ void DropValuesDialog::maskValues() const {
m_spreadsheet->beginMacro(i18n("%1: mask values", m_spreadsheet->name()));
const Operator op = static_cast<Operator>(ui.cbOperator->currentIndex());
const double value1 = ui.leValue1->text().toDouble();
const double value2 = ui.leValue2->text().toDouble();
SET_NUMBER_LOCALE
bool ok;
const double value1 = numberLocale.toDouble(ui.leValue1->text(), &ok);
if (!ok) {
DEBUG("Double value 1 invalid!")
m_spreadsheet->endMacro();
return;
}
const double value2 = numberLocale.toDouble(ui.leValue2->text(), &ok);
if (!ok) {
DEBUG("Double value 2 invalid!")
m_spreadsheet->endMacro();
return;
}
for (Column* col: m_columns) {
auto* task = new MaskValuesTask(col, op, value1, value2);
......@@ -580,8 +592,20 @@ void DropValuesDialog::dropValues() const {
m_spreadsheet->beginMacro(i18n("%1: drop values", m_spreadsheet->name()));
const Operator op = static_cast<Operator>(ui.cbOperator->currentIndex());
const double value1 = ui.leValue1->text().toDouble();
const double value2 = ui.leValue2->text().toDouble();
SET_NUMBER_LOCALE
bool ok;
const double value1 = numberLocale.toDouble(ui.leValue1->text(), &ok);
if (!ok) {
DEBUG("Double value 1 invalid!")
m_spreadsheet->endMacro();
return;
}
const double value2 = numberLocale.toDouble(ui.leValue2->text(), &ok);
if (!ok) {
DEBUG("Double value 2 invalid!")
m_spreadsheet->endMacro();
return;
}
for (Column* col: m_columns) {
auto* task = new DropValuesTask(col, op, value1, value2);
......
......@@ -112,7 +112,8 @@ EquidistantValuesDialog::~EquidistantValuesDialog() {
void EquidistantValuesDialog::setColumns(const QVector<Column*>& columns) {
m_columns = columns;
ui.leNumber->setText( QString::number(m_columns.first()->rowCount()) );
SET_NUMBER_LOCALE
ui.leNumber->setText( numberLocale.toString(m_columns.first()->rowCount()) );
}
void EquidistantValuesDialog::typeChanged(int index) {
......@@ -164,22 +165,35 @@ void EquidistantValuesDialog::generate() {
m_spreadsheet->name(),
m_columns.size()));
double start = ui.leFrom->text().toDouble();
double end = ui.leTo->text().toDouble();
int number;
double dist;
SET_NUMBER_LOCALE
bool ok;
double start = numberLocale.toDouble(ui.leFrom->text(), &ok);
if (!ok) {
DEBUG("Double value start invalid!")
m_spreadsheet->endMacro();
RESET_CURSOR;
return;
}
double end = numberLocale.toDouble(ui.leTo->text(), &ok);
if (!ok) {
DEBUG("Double value end invalid!")
m_spreadsheet->endMacro();
RESET_CURSOR;
return;
}
int number{0};
double dist{0};
if (ui.cbType->currentIndex() == 0) { //fixed number
number = ui.leNumber->text().toInt();
if (number!=1)
number = numberLocale.toInt(ui.leNumber->text(), &ok);
if (ok && number != 1)
dist = (end - start)/ (number - 1);
else
dist = 0;
} else { //fixed increment
dist = ui.leIncrement->text().toDouble();
number = (end-start)/dist + 1;
dist = numberLocale.toDouble(ui.leIncrement->text(), &ok);
if (ok)
number = (end-start)/dist + 1;
}
if (m_spreadsheet->rowCount()<number)
if (m_spreadsheet->rowCount() < number)
m_spreadsheet->setRowCount(number);
for (auto* col : m_columns) {
......
......@@ -82,6 +82,7 @@ ExportSpreadsheetDialog::ExportSpreadsheetDialog(QWidget* parent) : QDialog(pare
separators.takeAt(0); //remove the first entry "auto"
ui->cbSeparator->addItems(separators);
//TODO: use general setting for decimal separator?
ui->cbDecimalSeparator->addItem(i18n("Point '.'"));
ui->cbDecimalSeparator->addItem(i18n("Comma ','"));
......
......@@ -95,10 +95,17 @@ GoToDialog::~GoToDialog() {
}
int GoToDialog::row() {
return leRow->text().toInt();
SET_NUMBER_LOCALE
bool ok;
int row = numberLocale.toInt(leRow->text(), &ok);
return ok ? row : 0;
}
int GoToDialog::column() {
return leColumn->text().toInt();
SET_NUMBER_LOCALE
bool ok;
int col = numberLocale.toInt(leColumn->text(), &ok);
return ok ? col : 0;
}
......@@ -105,6 +105,7 @@ RandomValuesDialog::RandomValuesDialog(Spreadsheet* s, QWidget* parent) : QDialo
if (conf.exists()) {
ui.cbDistribution->setCurrentIndex(conf.readEntry("Distribution", 0));
this->distributionChanged(ui.cbDistribution->currentIndex()); //if index=0 no signal is emitted above, call this slot directly here
// TODO: better read double value
ui.leParameter1->setText(conf.readEntry("Parameter1"));
ui.leParameter2->setText(conf.readEntry("Parameter2"));
ui.leParameter3->setText(conf.readEntry("Parameter3"));
......@@ -123,6 +124,7 @@ RandomValuesDialog::~RandomValuesDialog() {
//save current settings
KConfigGroup conf(KSharedConfig::openConfig(), "RandomValuesDialog");
conf.writeEntry("Distribution", ui.cbDistribution->currentIndex());
// TODO: better save double value
conf.writeEntry("Parameter1", ui.leParameter1->text());
conf.writeEntry("Parameter2", ui.leParameter2->text());
conf.writeEntry("Parameter3", ui.leParameter3->text());
......@@ -146,6 +148,7 @@ void RandomValuesDialog::distributionChanged(int index) {
ui.leParameter3->hide();
ui.lFunc->setText("p(x) =");
//TODO: number locale
switch (dist) {
case nsl_sf_stats_gaussian:
ui.lParameter1->setText(UTF8_QSTRING("μ ="));
......@@ -406,6 +409,7 @@ void RandomValuesDialog::generate() {
QVector<int> data_int(rows);
QVector<qint64> data_bigint(rows);
//TODO: number locale
switch (dist) {
case nsl_sf_stats_gaussian: {
double mu = ui.leParameter1->text().toDouble();
......
......@@ -258,18 +258,20 @@ void StatisticsDialog::showStatistics() {
}
const QString StatisticsDialog::isNanValue(const double value) {
return (std::isnan(value) ? QLatin1String("-") : QString::number(value,'f'));
SET_NUMBER_LOCALE
return (std::isnan(value) ? QLatin1String("-") : numberLocale.toString(value,'f'));
}
QString modeValue(Column* column, double value) {
if (std::isnan(value))
return QLatin1String("-");
SET_NUMBER_LOCALE
switch (column->columnMode()) {
case AbstractColumn::ColumnMode::Integer:
return QString::number((int)value);
return numberLocale.toString((int)value);
case AbstractColumn::ColumnMode::BigInt:
return QString::number((qint64)value);
return numberLocale.toString((qint64)value);
case AbstractColumn::ColumnMode::Text:
//TODO
case AbstractColumn::ColumnMode::DateTime:
......@@ -279,7 +281,7 @@ QString modeValue(Column* column, double value) {
case AbstractColumn::ColumnMode::Month:
//TODO
case AbstractColumn::ColumnMode::Numeric:
return QString::number(value, 'f');
return numberLocale.toString(value, 'f');
}
return QString();
......
......@@ -31,9 +31,11 @@
#include "backend/worksheet/Worksheet.h"
#include "kdefrontend/GuiTools.h"
#include <QPainter>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QPainter>
#include <cmath>
......@@ -137,6 +139,11 @@ void DatapickerCurveWidget::setCurves(QList<DatapickerCurve*> list) {
m_curve = list.first();
m_aspect = list.first();
SET_NUMBER_LOCALE
ui.sbSize->setLocale(numberLocale);
ui.sbBorderWidth->setLocale(numberLocale);
ui.sbErrorBarSize->setLocale(numberLocale);
if (list.size() == 1) {
ui.lName->setEnabled(true);
ui.leName->setEnabled(true);
......
......@@ -58,6 +58,7 @@ FitOptionsWidget::FitOptionsWidget(QWidget* parent, XYFitCurve::FitData* fitData
ui.leMaxIterations->setText(numberLocale.toString(m_fitData->maxIterations));
ui.leEps->setText(numberLocale.toString(m_fitData->eps));
ui.leEvaluatedPoints->setText(numberLocale.toString(static_cast<qulonglong>(m_fitData->evaluatedPoints)));
ui.sbConfidenceInterval->setLocale(numberLocale);
//range widgets
const auto* plot = static_cast<const CartesianPlot*>(fitCurve->parentAspect());
......
......@@ -75,7 +75,7 @@ FitParametersWidget::FitParametersWidget(QWidget* parent) : QWidget(parent) {
ui.tableWidget->installEventFilter(this);
connect( ui.tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(changed()) );
connect(ui.tableWidget, SIGNAL(cellChanged(int, int)), this, SLOT(changed()) );
updateTableSize();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment