Commit 0b831830 authored by Stefan Gerlach's avatar Stefan Gerlach

[locale] Number locale fixes

parent 1d3e2d42
......@@ -39,15 +39,16 @@
#include "commonfrontend/matrix/MatrixView.h"
#include "kdefrontend/spreadsheet/ExportSpreadsheetDialog.h"
#include <KLocalizedString>
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QHeaderView>
#include <QPrinter>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
/*!
This class manages matrix based data (i.e., mathematically
a MxN matrix with M rows, N columns). This data is typically
......
......@@ -30,8 +30,11 @@
#include "backend/matrix/MatrixModel.h"
#include "backend/matrix/Matrix.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <QBrush>
#include <QLocale>
/*!
\class MatrixModel
......
......@@ -41,6 +41,10 @@
#include "kdefrontend/matrix/MatrixFunctionDialog.h"
#include "kdefrontend/spreadsheet/StatisticsDialog.h"
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QAction>
#include <QStackedWidget>
#include <QTableView>
......@@ -57,8 +61,6 @@
#include <QMutex>
#include <QProcess>
#include <QHeaderView>
#include <KLocalizedString>
#include <QIcon>
#include <cfloat>
......@@ -1123,6 +1125,7 @@ void MatrixView::exportToFile(const QString& path, const QString& separator, QLo
const int cols = m_matrix->columnCount();
const int rows = m_matrix->rowCount();
const QVector<QVector<double> >* data = static_cast<QVector<QVector<double>>*>(m_matrix->data());
//TODO: use general setting for number locale?
QLocale locale(language);
for (int row = 0; row < rows; ++row) {
for (int col = 0; col < cols; ++col) {
......
......@@ -45,6 +45,28 @@
#include "backend/core/datatypes/DateTime2StringFilter.h"
#include "backend/core/datatypes/String2DateTimeFilter.h"
#include "kdefrontend/spreadsheet/ExportSpreadsheetDialog.h"
#include "kdefrontend/spreadsheet/PlotDataDialog.h"
#include "kdefrontend/spreadsheet/AddSubtractValueDialog.h"
#include "kdefrontend/spreadsheet/DropValuesDialog.h"
#include "kdefrontend/spreadsheet/GoToDialog.h"
#include "kdefrontend/spreadsheet/RescaleDialog.h"
#include "kdefrontend/spreadsheet/SortDialog.h"
#include "kdefrontend/spreadsheet/RandomValuesDialog.h"
#include "kdefrontend/spreadsheet/EquidistantValuesDialog.h"
#include "kdefrontend/spreadsheet/FunctionValuesDialog.h"
#include "kdefrontend/spreadsheet/StatisticsDialog.h"
#ifdef Q_OS_MAC
#include "3rdparty/kdmactouchbar/src/kdmactouchbar.h"
#endif
#include <KConfigGroup>
#include <KLocalizedString>
#include <KMessageBox>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QKeyEvent>
#include <QClipboard>
#include <QInputDialog>
......@@ -69,30 +91,11 @@
#include <QRandomGenerator>
#endif
#include <KConfigGroup>
#include <KLocalizedString>
#include <KMessageBox>
#include <KSharedConfig>
#include "kdefrontend/spreadsheet/ExportSpreadsheetDialog.h"
#include "kdefrontend/spreadsheet/PlotDataDialog.h"
#include "kdefrontend/spreadsheet/AddSubtractValueDialog.h"
#include "kdefrontend/spreadsheet/DropValuesDialog.h"
#include "kdefrontend/spreadsheet/GoToDialog.h"
#include "kdefrontend/spreadsheet/RescaleDialog.h"
#include "kdefrontend/spreadsheet/SortDialog.h"
#include "kdefrontend/spreadsheet/RandomValuesDialog.h"
#include "kdefrontend/spreadsheet/EquidistantValuesDialog.h"
#include "kdefrontend/spreadsheet/FunctionValuesDialog.h"
#include "kdefrontend/spreadsheet/StatisticsDialog.h"
#include <algorithm> //for std::reverse
extern "C" {
#include <gsl/gsl_math.h>
#ifdef Q_OS_MAC
#include "3rdparty/kdmactouchbar/src/kdmactouchbar.h"
#endif
}
enum NormalizationMethod {DivideBySum, DivideByMin, DivideByMax, DivideByCount,
DivideByMean, DivideByMedian, DivideByMode, DivideByRange,
......@@ -1423,7 +1426,7 @@ void SpreadsheetView::copySelection() {
formats << out_fltr->numericFormat();
}
QLocale locale;
SET_NUMBER_LOCALE
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
const Column* col_ptr = columns.at(c);
......@@ -1432,9 +1435,9 @@ void SpreadsheetView::copySelection() {
// output_str += col_ptr->formula(first_row + r);
// else
if (col_ptr->columnMode() == AbstractColumn::ColumnMode::Numeric)
output_str += locale.toString(col_ptr->valueAt(first_row + r), formats.at(c), 16); // copy with max. precision
output_str += numberLocale.toString(col_ptr->valueAt(first_row + r), formats.at(c), 16); // copy with max. precision
else if (col_ptr->columnMode() == AbstractColumn::ColumnMode::Integer || col_ptr->columnMode() == AbstractColumn::ColumnMode::BigInt)
output_str += QString::number(col_ptr->valueAt(first_row + r));
output_str += numberLocale.toString(col_ptr->valueAt(first_row + r));
else
output_str += col_ptr->asStringColumn()->textAt(first_row + r);
}
......@@ -1501,7 +1504,7 @@ void SpreadsheetView::pasteIntoSelection() {
input_col_count = cellTexts.at(i).count();
}
QLocale locale;
SET_NUMBER_LOCALE
// bool localeDetermined = false;
if ( (first_col == -1 || first_row == -1) || (last_row == first_row && last_col == first_col) ) {
......@@ -1583,14 +1586,14 @@ void SpreadsheetView::pasteIntoSelection() {
QVector<double> new_data(rows);
for (int r = 0; r < rows; ++r) {
if (c < cellTexts.at(r).count())
new_data[r] = locale.toDouble(cellTexts.at(r).at(c));
new_data[r] = numberLocale.toDouble(cellTexts.at(r).at(c));
}
col->replaceValues(0, new_data);
} else {
for (int r = 0; r < rows && r < input_row_count; r++) {
if ( isCellSelected(first_row + r, first_col + c) && (c < cellTexts.at(r).count()) ) {
if (!cellTexts.at(r).at(c).isEmpty())
col->setValueAt(first_row + r, locale.toDouble(cellTexts.at(r).at(c)));
col->setValueAt(first_row + r, numberLocale.toDouble(cellTexts.at(r).at(c)));
else
col->setValueAt(first_row + r, std::numeric_limits<double>::quiet_NaN());
}
......@@ -1601,14 +1604,14 @@ void SpreadsheetView::pasteIntoSelection() {
QVector<int> new_data(rows);
for (int r = 0; r < rows; ++r) {
if (c < cellTexts.at(r).count())
new_data[r] = locale.toInt(cellTexts.at(r).at(c));
new_data[r] = numberLocale.toInt(cellTexts.at(r).at(c));
}
col->replaceInteger(0, new_data);
} else {
for (int r = 0; r < rows && r < input_row_count; r++) {
if ( isCellSelected(first_row + r, first_col + c) && (c < cellTexts.at(r).count()) ) {
if (!cellTexts.at(r).at(c).isEmpty())
col->setIntegerAt(first_row + r, locale.toInt(cellTexts.at(r).at(c)));
col->setIntegerAt(first_row + r, numberLocale.toInt(cellTexts.at(r).at(c)));
else
col->setIntegerAt(first_row + r, 0);
}
......@@ -1618,13 +1621,13 @@ void SpreadsheetView::pasteIntoSelection() {
if (rows == m_spreadsheet->rowCount() && rows <= cellTexts.size()) {
QVector<qint64> new_data(rows);
for (int r = 0; r < rows; ++r)
new_data[r] = locale.toLongLong(cellTexts.at(r).at(c));
new_data[r] = numberLocale.toLongLong(cellTexts.at(r).at(c));
col->replaceBigInt(0, new_data);
} else {
for (int r = 0; r < rows && r < input_row_count; r++) {
if ( isCellSelected(first_row + r, first_col + c) && (c < cellTexts.at(r).count()) ) {
if (!cellTexts.at(r).at(c).isEmpty())
col->setBigIntAt(first_row + r, locale.toLongLong(cellTexts.at(r).at(c)));
col->setBigIntAt(first_row + r, numberLocale.toLongLong(cellTexts.at(r).at(c)));
else
col->setBigIntAt(first_row + r, 0);
}
......
......@@ -73,7 +73,6 @@ QLocale::Language SettingsGeneralPage::decimalSeparatorLocale() const {
return QLocale().language();
QChar groupSeparator{QLocale().groupSeparator()};
QChar decimalPoint{QLocale().decimalPoint()};
if (currentIndex == static_cast<int>(DecimalSeparator::Dot)) {
if (groupSeparator == QLocale(QLocale::Language::Zarma).groupSeparator()) // \u00a0
return QLocale::Language::Zarma; // . \u00a0
......
......@@ -148,6 +148,7 @@ void AsciiOptionsWidget::applyFilterSettings(AsciiFilter* filter) const {
filter->setCommentCharacter( ui.cbCommentCharacter->currentText() );
filter->setSeparatingCharacter( ui.cbSeparatingCharacter->currentText() );
//TODO: use general setting for decimal separator?
QLocale::Language lang;
if (ui.cbDecimalSeparator->currentIndex() == 0)
lang = QLocale::Language::C;
......@@ -175,6 +176,7 @@ void AsciiOptionsWidget::loadSettings() const {
ui.cbCommentCharacter->setCurrentText(conf.readEntry("CommentCharacter", "#"));
ui.cbSeparatingCharacter->setCurrentItem(conf.readEntry("SeparatingCharacter", "auto"));
//TODO: use general setting for decimal separator?
const QChar decimalSeparator = QLocale().decimalPoint();
int index = (decimalSeparator == '.') ? 0 : 1;
ui.cbDecimalSeparator->setCurrentIndex(conf.readEntry("DecimalSeparator", index));
......
......@@ -118,6 +118,7 @@ void DatasetMetadataManagerWidget::loadSettings() {
KConfigGroup conf(KSharedConfig::openConfig(), "DatasetMetadataManagerWidget");
ui.cbCommentCharacter->setCurrentItem(conf.readEntry("commentChar", "#"));
ui.cbSeparatingCharacter->setCurrentItem(conf.readEntry("separator", "auto"));
//TODO: use general setting for decimal separator?
ui.cbNumberFormat->setCurrentIndex(conf.readEntry("numberFormat", static_cast<int>(QLocale::AnyLanguage)));
ui.cbDateTimeFormat->setCurrentItem(conf.readEntry("dateTimeFormat", "yyyy-MM-dd hh:mm:ss.zzz"));
ui.chbCreateIndex->setChecked(conf.readEntry("createIndexColumn", false));
......
......@@ -159,7 +159,7 @@ void ImportSQLDatabaseWidget::loadSettings() {
ui.cbImportFrom->setCurrentIndex(config.readEntry("ImportFrom", 0));
importFromChanged(ui.cbImportFrom->currentIndex());
//TODO
//TODO: use general setting for decimal separator?
const QChar decimalSeparator = QLocale().decimalPoint();
int index = (decimalSeparator == '.') ? 0 : 1;
ui.cbDecimalSeparator->setCurrentIndex(config.readEntry("DecimalSeparator", index));
......@@ -342,6 +342,7 @@ void ImportSQLDatabaseWidget::refreshPreview() {
m_columnNames.clear();
m_columnModes.clear();
bool numeric = true;
//TODO: use general setting for decimal separator?
QLocale::Language lang;
if (ui.cbDecimalSeparator->currentIndex() == 0)
lang = QLocale::Language::C;
......@@ -443,6 +444,7 @@ void ImportSQLDatabaseWidget::read(AbstractDataSource* dataSource, AbstractFileF
//number and DateTime formatting
const QString& dateTimeFormat = ui.cbDateTimeFormat->currentText();
//TODO: use general setting for decimal separator?
QLocale::Language lang;
if (ui.cbDecimalSeparator->currentIndex() == 0)
lang = QLocale::Language::C;
......
......@@ -60,6 +60,7 @@ void JsonOptionsWidget::applyFilterSettings(JsonFilter* filter, const QModelInde
Q_ASSERT(filter);
filter->setModelRows(getIndexRows(index));
//TODO: use general setting for decimal separator?
filter->setNumberFormat( QLocale::Language(ui.cbNumberFormat->currentIndex()));
filter->setDateTimeFormat(ui.cbDateTimeFormat->currentText());
filter->setCreateIndexEnabled(ui.chbCreateIndex->isChecked());
......@@ -82,6 +83,7 @@ void JsonOptionsWidget::clearModel() {
void JsonOptionsWidget::loadSettings() const {
KConfigGroup conf(KSharedConfig::openConfig(), "ImportJson");
//TODO: use general setting for decimal separator?
ui.cbNumberFormat->setCurrentIndex(conf.readEntry("NumberFormat", (int)QLocale::AnyLanguage));
ui.cbDateTimeFormat->setCurrentItem(conf.readEntry("DateTimeFormat", "yyyy-MM-dd hh:mm:ss.zzz"));
ui.chbCreateIndex->setChecked(conf.readEntry("CreateIndex", false));
......
......@@ -39,14 +39,16 @@
#include "kdefrontend/widgets/FitOptionsWidget.h"
#include "kdefrontend/widgets/FitParametersWidget.h"
#include <KMessageWidget>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QMenu>
#include <QWidgetAction>
#include <QStandardItemModel>
#include <QStandardPaths>
#include <QClipboard>
#include <KMessageWidget>
extern "C" {
#include "backend/nsl/nsl_sf_stats.h"
}
......
......@@ -112,6 +112,7 @@ ExportSpreadsheetDialog::ExportSpreadsheetDialog(QWidget* parent) : QDialog(pare
ui->chkExportHeader->setChecked(conf.readEntry("Header", true));
ui->cbSeparator->setCurrentItem(conf.readEntry("Separator", "TAB"));
//TODO: use general setting for decimal separator?
const QChar decimalSeparator = QLocale().decimalPoint();
int index = (decimalSeparator == '.') ? 0 : 1;
ui->cbDecimalSeparator->setCurrentIndex(conf.readEntry("DecimalSeparator", index));
......
......@@ -758,6 +758,7 @@ void LabelWidget::dateTimeMenu() {
//application language was changed:
//determine the currently used language and use QLocale::toString()
//to get the strings translated into the currently used language
//TODO: why not use QLocale() ?
QSettings settings (configFile, QSettings::IniFormat);
settings.beginGroup(QLatin1String("Language"));
QByteArray languageCode;
......
......@@ -128,7 +128,8 @@ void EquationHighlighter::highlightBlock(const QString& text) {
bool isFraction = (u >= 0xbc && u <= 0xbe) || (u >= 0x2153 && u <= 0x215e);
bool isPower = (u >= 0xb2 && u <= 0xb3) || (u == 0x2070) || (u >= 0x2074 && u <= 0x2079);
bool isDigit = text[i].isDigit();
bool isDecimalPoint = text[i] == QLocale().decimalPoint();
SET_NUMBER_LOCALE
bool isDecimalPoint = text[i] == numberLocale.decimalPoint();
if (isFraction || isPower || isDigit || isDecimalPoint)
setFormat(i, 1, number);
......
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