Commit 81f8b5fc authored by Stefan Gerlach's avatar Stefan Gerlach

Fix locale of line edits in fit options widget and related improvements

parent 0b274be2
......@@ -47,6 +47,8 @@ public:
~Range() = default;
T min() const { return m_min; }
T max() const { return m_max; }
T& min() { return m_min; }
T& max() { return m_max; }
void setMin(T min) { m_min = min; } // no check (use first)
void setMax(T max) { m_max = std::max(m_min, max); }
void setRange(T min, T max) {
......
......@@ -5,7 +5,7 @@
--------------------------------------------------------------------
Copyright : (C) 2008 Tilman Benkert (thzs@gmx.net)
Copyright : (C) 2013-2015 Alexander Semke (alexander.semke@web.de)
Copyright : (C) 2016-2017 Stefan Gerlach (stefan.gerlach@uni.kn)
Copyright : (C) 2016-2020 Stefan Gerlach (stefan.gerlach@uni.kn)
***************************************************************************/
......@@ -56,6 +56,9 @@ constexpr std::add_const_t<T>& qAsConst(T& t) noexcept {
}
#endif
#define WAIT_CURSOR QApplication::setOverrideCursor(QCursor(Qt::WaitCursor))
#define RESET_CURSOR QApplication::restoreOverrideCursor()
#define UTF8_QSTRING(str) QString::fromUtf8(str)
#define STDSTRING(qstr) qstr.toUtf8().constData()
......@@ -64,6 +67,23 @@ constexpr std::add_const_t<T>& qAsConst(T& t) noexcept {
#define ENUM_COUNT(class, enum) \
(class::staticMetaObject.enumerator(class::staticMetaObject.indexOfEnumerator(#enum)).keyCount())
//////////////////////// LineEdit Access ///////////////////////////////
#define SET_INT_FROM_LE(var, le) { \
bool ok; \
const int tmp = QLocale().toInt(le->text(), &ok); \
if (ok) \
var = tmp; \
}
#define SET_DOUBLE_FROM_LE(var, le) { \
bool ok; \
const double tmp = QLocale().toDouble(le->text(), &ok); \
if (ok) \
var = tmp; \
}
//////////////////////// Accessor ///////////////////////////////
#define BASIC_ACCESSOR(type, var, method, Method) \
type method() const { return var; }; \
void set ## Method(const type value) { var = value; }
......@@ -153,8 +173,7 @@ constexpr std::add_const_t<T>& qAsConst(T& t) noexcept {
return d->var; \
}
#define WAIT_CURSOR QApplication::setOverrideCursor(QCursor(Qt::WaitCursor))
#define RESET_CURSOR QApplication::restoreOverrideCursor()
//////////////////////// Standard Setter /////////////////////
#define STD_SETTER_CMD_IMPL(class_name, cmd_name, value_type, field_name) \
class class_name ## cmd_name ## Cmd: public StandardSetterCmd<class_name::Private, value_type> { \
......@@ -248,7 +267,8 @@ class class_name ## cmd_name ## Cmd: public StandardSwapMethodSetterCmd<class_na
};
//xml-serialization/deserialization
//////////////////////// XML - serialization/deserialization /////
//QColor
#define WRITE_QCOLOR(color) \
do { \
......@@ -446,13 +466,6 @@ if (str.isEmpty()) \
else \
d->var = str.toDouble();
#define READ_DOUBLE_VALUE_LOCAL(name, var) \
str = attribs.value(name).toString(); \
if (str.isEmpty()) \
reader->raiseWarning(attributeWarning.subs(name).toString()); \
else \
var = str.toDouble();
#define READ_STRING_VALUE(name, var) \
str = attribs.value(name).toString(); \
if (str.isEmpty()) \
......
......@@ -2323,12 +2323,10 @@ bool XYFitCurve::load(XmlStreamReader* reader, bool preview) {
READ_COLUMN(yErrorColumn);
READ_INT_VALUE("autoRange", fitData.autoRange, bool);
double left{0}, right{0};
READ_DOUBLE_VALUE_LOCAL("xRangeMin", left); // old name
READ_DOUBLE_VALUE_LOCAL("xRangeMax", right); // old name
READ_DOUBLE_VALUE_LOCAL("fitRangeMin", left);
READ_DOUBLE_VALUE_LOCAL("fitRangeMax", right);
d->fitData.fitRange.setRange(left, right);
READ_DOUBLE_VALUE("xRangeMin", fitData.fitRange.min()); // old name
READ_DOUBLE_VALUE("xRangeMax", fitData.fitRange.max()); // old name
READ_DOUBLE_VALUE("fitRangeMin", fitData.fitRange.min());
READ_DOUBLE_VALUE("fitRangeMax", fitData.fitRange.min());
READ_INT_VALUE("modelCategory", fitData.modelCategory, nsl_fit_model_category);
READ_INT_VALUE("modelType", fitData.modelType, int);
READ_INT_VALUE("xWeightsType", fitData.xWeightsType, nsl_fit_weight_type);
......
......@@ -61,7 +61,7 @@ const QString getSystemInfo() {
#else
const QString buildType(i18n("Debug build"));
#endif
const QLocale locale{QLocale::system()};
const QLocale locale;
// TODO: show zeroDigit(), groupSeparator(), etc.
const QString localeInfo{QLatin1String(" (")
+ i18n("Decimal point: ") + '\'' + QString(locale.decimalPoint())
......
......@@ -599,9 +599,8 @@ void CartesianPlotDock::xMinChanged(const QString& value) {
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
bool ok;
const double xMin = locale.toDouble(value, &ok);
const double xMin = QLocale().toDouble(value, &ok);
if (ok) {
for (auto* plot : m_plotList)
plot->setXMin(xMin);
......@@ -613,9 +612,8 @@ void CartesianPlotDock::xMaxChanged(const QString& value) {
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
bool ok;
const double xMax = locale.toDouble(value, &ok);
const double xMax = QLocale().toDouble(value, &ok);
if (ok) {
for (auto* plot : m_plotList)
plot->setXMax(xMax);
......@@ -693,9 +691,8 @@ void CartesianPlotDock::yMinChanged(const QString& value) {
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
bool ok;
const double yMin = locale.toDouble(value, &ok);
const double yMin = QLocale().toDouble(value, &ok);
if (ok) {
for (auto* plot : m_plotList)
plot->setYMin(yMin);
......@@ -707,9 +704,8 @@ void CartesianPlotDock::yMaxChanged(const QString& value) {
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
bool ok;
const double yMax = locale.toDouble(value, &ok);
const double yMax = QLocale().toDouble(value, &ok);
if (ok) {
for (auto* plot : m_plotList)
plot->setYMax(yMax);
......@@ -1423,8 +1419,7 @@ void CartesianPlotDock::plotXMinChanged(double value) {
if (m_initializing)
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
ui.leXMin->setText(locale.toString(value));
ui.leXMin->setText(QLocale().toString(value));
ui.dateTimeEditXMin->setDateTime(QDateTime::fromMSecsSinceEpoch(value));
}
......@@ -1432,8 +1427,7 @@ void CartesianPlotDock::plotXMaxChanged(double value) {
if (m_initializing)
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
ui.leXMax->setText(locale.toString(value));
ui.leXMax->setText(QLocale().toString(value));
ui.dateTimeEditXMax->setDateTime( QDateTime::fromMSecsSinceEpoch(value) );
}
......@@ -1459,8 +1453,7 @@ void CartesianPlotDock::plotYMinChanged(double value) {
if (m_initializing)
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
ui.leYMin->setText(locale.toString(value));
ui.leYMin->setText(QLocale().toString(value));
ui.dateTimeEditYMin->setDateTime( QDateTime::fromMSecsSinceEpoch(value) );
}
......@@ -1468,8 +1461,7 @@ void CartesianPlotDock::plotYMaxChanged(double value) {
if (m_initializing)
return;
const Lock lock(m_initializing);
const QLocale locale{QLocale::system()};
ui.leYMax->setText(locale.toString(value));
ui.leYMax->setText(QLocale().toString(value));
ui.dateTimeEditYMax->setDateTime( QDateTime::fromMSecsSinceEpoch(value) );
}
......@@ -1670,9 +1662,8 @@ void CartesianPlotDock::load() {
ui.leRangeLast->setText( QString::number(m_plot->rangeLastValues()) );
ui.chkAutoScaleX->setChecked(m_plot->autoScaleX());
const QLocale locale{QLocale::system()};
ui.leXMin->setText(locale.toString(m_plot->xMin()));
ui.leXMax->setText(locale.toString(m_plot->xMax()));
ui.leXMin->setText(QLocale().toString(m_plot->xMin()));
ui.leXMax->setText(QLocale().toString(m_plot->xMax()));
ui.dateTimeEditXMin->setDisplayFormat(m_plot->xRangeDateTimeFormat());
ui.dateTimeEditXMax->setDisplayFormat(m_plot->xRangeDateTimeFormat());
ui.dateTimeEditXMin->setDateTime(QDateTime::fromMSecsSinceEpoch(m_plot->xMin()));
......@@ -1681,8 +1672,8 @@ void CartesianPlotDock::load() {
ui.cbXRangeFormat->setCurrentIndex( (int) m_plot->xRangeFormat() );
ui.chkAutoScaleY->setChecked(m_plot->autoScaleY());
ui.leYMin->setText(locale.toString(m_plot->yMin()));
ui.leYMax->setText(locale.toString(m_plot->yMax()));
ui.leYMin->setText(QLocale().toString(m_plot->yMin()));
ui.leYMax->setText(QLocale().toString(m_plot->yMax()));
ui.dateTimeEditYMin->setDisplayFormat(m_plot->yRangeDateTimeFormat());
ui.dateTimeEditYMax->setDisplayFormat(m_plot->yRangeDateTimeFormat());
ui.dateTimeEditYMin->setDateTime(QDateTime::fromMSecsSinceEpoch(m_plot->yMin()));
......
......@@ -47,22 +47,22 @@ FitOptionsWidget::FitOptionsWidget(QWidget* parent, XYFitCurve::FitData* fitData
ui.lRobust->setVisible(false);
ui.cbRobust->setVisible(false);
ui.leEps->setValidator( new QDoubleValidator(ui.leEps) );
ui.leMaxIterations->setValidator( new QIntValidator(ui.leMaxIterations) );
ui.leEps->setValidator( new QDoubleValidator(ui.leEps) );
ui.leEvaluatedPoints->setValidator( new QIntValidator(ui.leEvaluatedPoints) );
ui.leEps->setText(QString::number(m_fitData->eps));
ui.leMaxIterations->setText(QString::number(m_fitData->maxIterations));
ui.leEvaluatedPoints->setText(QString::number(m_fitData->evaluatedPoints));
ui.leMaxIterations->setText(QLocale().toString(m_fitData->maxIterations));
ui.leEps->setText(QLocale().toString(m_fitData->eps));
ui.leEvaluatedPoints->setText(QLocale().toString(static_cast<qulonglong>(m_fitData->evaluatedPoints)));
//range widgets
const auto* plot = static_cast<const CartesianPlot*>(fitCurve->parentAspect());
m_dateTimeRange = (plot->xRangeFormat() != CartesianPlot::RangeFormat::Numeric);
if (!m_dateTimeRange) {
ui.leMin->setText(QString::number(m_fitData->fitRange.min()));
ui.leMax->setText(QString::number(m_fitData->fitRange.max()));
ui.leEvalMin->setText(QString::number(m_fitData->evalRange.min()));
ui.leEvalMax->setText(QString::number(m_fitData->evalRange.max()));
ui.leMin->setText(QLocale().toString(m_fitData->fitRange.min()));
ui.leMax->setText(QLocale().toString(m_fitData->fitRange.max()));
ui.leEvalMin->setText(QLocale().toString(m_fitData->evalRange.min()));
ui.leEvalMax->setText(QLocale().toString(m_fitData->evalRange.max()));
} else {
ui.dateTimeEditMin->setDateTime( QDateTime::fromMSecsSinceEpoch(m_fitData->fitRange.min()) );
ui.dateTimeEditMax->setDateTime( QDateTime::fromMSecsSinceEpoch(m_fitData->fitRange.max()) );
......@@ -178,8 +178,8 @@ void FitOptionsWidget::autoEvalRangeChanged() {
m_fitData->evalRange.setRange(xMin, xMax);
if (!m_dateTimeRange) {
ui.leEvalMin->setText(QString::number(xMin));
ui.leEvalMax->setText(QString::number(xMax));
ui.leEvalMin->setText(QLocale().toString(xMin));
ui.leEvalMax->setText(QLocale().toString(xMax));
} else {
ui.dateTimeEditEvalMin->setDateTime(QDateTime::fromMSecsSinceEpoch(xMin));
ui.dateTimeEditEvalMax->setDateTime(QDateTime::fromMSecsSinceEpoch(xMax));
......@@ -189,12 +189,14 @@ void FitOptionsWidget::autoEvalRangeChanged() {
}
void FitOptionsWidget::fitRangeMinChanged() {
//TODO
const double xMin = ui.leMin->text().toDouble();
m_fitData->fitRange.setMin(xMin);
changed();
}
void FitOptionsWidget::fitRangeMaxChanged() {
//TODO
const double xMax = ui.leMax->text().toDouble();
m_fitData->fitRange.setMax(xMax);
......@@ -212,15 +214,11 @@ void FitOptionsWidget::fitRangeMaxDateTimeChanged(const QDateTime& dateTime) {
}
void FitOptionsWidget::evalRangeMinChanged() {
const double xMin = ui.leEvalMin->text().toDouble();
m_fitData->evalRange.setMin(xMin);
SET_DOUBLE_FROM_LE(m_fitData->evalRange.min(), ui.leEvalMin);
changed();
}
void FitOptionsWidget::evalRangeMaxChanged() {
const double xMax = ui.leEvalMax->text().toDouble();
m_fitData->evalRange.setMax(xMax);
SET_DOUBLE_FROM_LE(m_fitData->evalRange.max(), ui.leEvalMax);
changed();
}
......@@ -235,9 +233,10 @@ void FitOptionsWidget::evalRangeMaxDateTimeChanged(const QDateTime& dateTime) {
}
void FitOptionsWidget::applyClicked() {
m_fitData->maxIterations = ui.leMaxIterations->text().toFloat(); //TODO: float?
m_fitData->eps = ui.leEps->text().toFloat(); // TODO: float?
m_fitData->evaluatedPoints = ui.leEvaluatedPoints->text().toInt();
SET_INT_FROM_LE(m_fitData->maxIterations, ui.leMaxIterations);
SET_DOUBLE_FROM_LE(m_fitData->eps, ui.leEps);
SET_INT_FROM_LE(m_fitData->evaluatedPoints, ui.leEvaluatedPoints);
m_fitData->useDataErrors = ui.cbUseDataErrors->isChecked();
m_fitData->useResults = ui.cbUseResults->isChecked();
m_fitData->previewEnabled = ui.cbPreview->isChecked();
......
......@@ -44,6 +44,7 @@ private:
XYFitCurve* m_fitCurve;
bool m_changed{false};
bool m_dateTimeRange{false};
const QLocale locale;
signals:
void finished();
......
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