From 05d820c83f8f11d213da87e4d809fb6777003da6 Mon Sep 17 00:00:00 2001 From: Bela Schaum Date: Thu, 12 Sep 2024 12:53:55 +0200 Subject: [PATCH] Fix decimal point char + locale on QT --- src/base/conv/numtostr.cpp | 10 ++++++---- src/chart/options/channel.h | 1 - src/dataframe/old/datatable.h | 3 +-- test/qtest/window.cpp | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/base/conv/numtostr.cpp b/src/base/conv/numtostr.cpp index 27324e741..956b090c5 100644 --- a/src/base/conv/numtostr.cpp +++ b/src/base/conv/numtostr.cpp @@ -36,20 +36,22 @@ std::string NumberToString::convert(double number) ("%." + std::to_string(fractionDigitCount) + "f").c_str(), number)); - auto decimalPoint = - std::min(number_view.find('.'), number_view.size()); + auto decimalPoint = std::min(number_view.find(decimalPointChar), + number_view.size()); if (decimalPoint != number_view.size()) { if (!fillFractionWithZero) { number_view = number_view.substr(0, number_view.find_last_not_of('0') + 1); } - if (number_view.ends_with('.')) { + if (number_view.ends_with(decimalPointChar)) { number_view.remove_suffix(1); } } if (number_view.starts_with('-') - && number_view.find_last_not_of("0.") == 0) { + && number_view.find_last_not_of(std::string_view{ + std::initializer_list{'0', decimalPointChar, '\0'}}) + == 0) { number_view.remove_prefix(1); ++begin; --decimalPoint; diff --git a/src/chart/options/channel.h b/src/chart/options/channel.h index a1cdcf7a7..5d048e51d 100644 --- a/src/chart/options/channel.h +++ b/src/chart/options/channel.h @@ -6,7 +6,6 @@ #include #include -#include "dataframe/old/datatable.h" #include "dataframe/old/types.h" #include "autoparam.h" diff --git a/src/dataframe/old/datatable.h b/src/dataframe/old/datatable.h index 22adafccb..71e3c8b1f 100644 --- a/src/dataframe/old/datatable.h +++ b/src/dataframe/old/datatable.h @@ -5,9 +5,8 @@ #ifndef DATAFRAME_OLD2_DATATABLE_H #define DATAFRAME_OLD2_DATATABLE_H -#include - #include "../impl/dataframe.h" +#include "chart/options/channel.h" #include "types.h" diff --git a/test/qtest/window.cpp b/test/qtest/window.cpp index 1f7448ad7..c4535c613 100644 --- a/test/qtest/window.cpp +++ b/test/qtest/window.cpp @@ -27,6 +27,7 @@ Window::Window(QWidget *parent) : chart.run(); animStep(); installEventFilter(this); + setlocale(LC_NUMERIC, "C"); } void Window::animStep()