Commit 928e7506 authored by Stefan Gerlach's avatar Stefan Gerlach

[locale] Fix in fit parameter widget

parent 45309a1f
......@@ -70,14 +70,14 @@ constexpr std::add_const_t<T>& qAsConst(T& t) noexcept {
//////////////////////// LineEdit Access ///////////////////////////////
#define SET_INT_FROM_LE(var, le) { \
bool ok; \
const int tmp = QLocale().toInt(le->text(), &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); \
const double tmp = QLocale().toDouble((le)->text(), &ok); \
if (ok) \
var = tmp; \
}
......
......@@ -97,7 +97,7 @@ void FitParametersWidget::setFitData(XYFitCurve::FitData* data) {
auto* le = new QLineEdit(ui.tableWidget);
le->setValidator(new QDoubleValidator(le));
le->setFrame(false);
le->insert(QString::number(m_fitData->paramStartValues.at(i), 'g'));
le->insert(QLocale().toString(m_fitData->paramStartValues.at(i)));
ui.tableWidget->setCellWidget(i, 1, le);
connect(le, SIGNAL(textChanged(QString)), this, SLOT(startValueChanged()) );
......@@ -118,7 +118,7 @@ void FitParametersWidget::setFitData(XYFitCurve::FitData* data) {
le->setValidator(new QDoubleValidator(le));
le->setFrame(false);
if (m_fitData->paramLowerLimits.at(i) > -std::numeric_limits<double>::max())
le->insert(QString::number(m_fitData->paramLowerLimits.at(i), 'g'));
le->insert(QLocale().toString(m_fitData->paramLowerLimits.at(i)));
ui.tableWidget->setCellWidget(i, 3, le);
connect(le, SIGNAL(textChanged(QString)), this, SLOT(lowerLimitChanged()) );
......@@ -126,7 +126,7 @@ void FitParametersWidget::setFitData(XYFitCurve::FitData* data) {
le->setValidator(new QDoubleValidator(le));
le->setFrame(false);
if (m_fitData->paramUpperLimits.at(i) < std::numeric_limits<double>::max())
le->insert(QString::number(m_fitData->paramUpperLimits.at(i), 'g'));
le->insert(QLocale().toString(m_fitData->paramUpperLimits.at(i)));
ui.tableWidget->setCellWidget(i, 4, le);
connect(le, SIGNAL(textChanged(QString)), this, SLOT(upperLimitChanged()) );
}
......@@ -145,7 +145,7 @@ void FitParametersWidget::setFitData(XYFitCurve::FitData* data) {
auto* le = new QLineEdit(ui.tableWidget);
le->setValidator(new QDoubleValidator(le));
le->setFrame(false);
le->insert(QString::number(m_fitData->paramStartValues.at(i), 'g'));
le->insert(QLocale().toString(m_fitData->paramStartValues.at(i)));
ui.tableWidget->setCellWidget(i, 1, le);
connect(le, SIGNAL(textChanged(QString)), this, SLOT(startValueChanged()) );
......@@ -166,7 +166,7 @@ void FitParametersWidget::setFitData(XYFitCurve::FitData* data) {
le->setValidator(new QDoubleValidator(le));
le->setFrame(false);
if (m_fitData->paramLowerLimits.at(i) > -std::numeric_limits<double>::max())
le->insert(QString::number(m_fitData->paramLowerLimits.at(i), 'g'));
le->insert(QLocale().toString(m_fitData->paramLowerLimits.at(i)));
ui.tableWidget->setCellWidget(i, 3, le);
connect(le, SIGNAL(textChanged(QString)), this, SLOT(lowerLimitChanged()) );
......@@ -174,7 +174,7 @@ void FitParametersWidget::setFitData(XYFitCurve::FitData* data) {
le->setValidator(new QDoubleValidator(le));
le->setFrame(false);
if (m_fitData->paramUpperLimits.at(i) < std::numeric_limits<double>::max())
le->insert(QString::number(m_fitData->paramUpperLimits.at(i), 'g'));
le->insert(QLocale().toString(m_fitData->paramUpperLimits.at(i)));
ui.tableWidget->setCellWidget(i, 4, le);
connect(le, SIGNAL(textChanged(QString)), this, SLOT(upperLimitChanged()) );
}
......@@ -290,17 +290,17 @@ void FitParametersWidget::apply() {
DEBUG("FitParametersWidget::apply()");
if (m_fitData->modelCategory != nsl_fit_model_custom) { // pre-defined models
for (int i = 0; i < ui.tableWidget->rowCount(); ++i) {
m_fitData->paramStartValues[i] = ((QLineEdit *)ui.tableWidget->cellWidget(i, 1))->text().toDouble();
SET_DOUBLE_FROM_LE(m_fitData->paramStartValues[i], (QLineEdit *)ui.tableWidget->cellWidget(i, 1))
QWidget *widget = ui.tableWidget->cellWidget(i, 2)->layout()->itemAt(0)->widget();
m_fitData->paramFixed[i] = (qobject_cast<QCheckBox *>(widget))->isChecked();
if ( !((QLineEdit *)ui.tableWidget->cellWidget(i, 3))->text().isEmpty() )
m_fitData->paramLowerLimits[i] = ((QLineEdit *)ui.tableWidget->cellWidget(i, 3))->text().toDouble();
SET_DOUBLE_FROM_LE(m_fitData->paramLowerLimits[i], (QLineEdit *)ui.tableWidget->cellWidget(i, 3))
else
m_fitData->paramLowerLimits[i] = -std::numeric_limits<double>::max();
if ( !((QLineEdit *)ui.tableWidget->cellWidget(i, 4))->text().isEmpty() )
m_fitData->paramUpperLimits[i] = ((QLineEdit *)ui.tableWidget->cellWidget(i, 4))->text().toDouble();
SET_DOUBLE_FROM_LE(m_fitData->paramUpperLimits[i], (QLineEdit *)ui.tableWidget->cellWidget(i, 4))
else
m_fitData->paramUpperLimits[i] = std::numeric_limits<double>::max();
}
......@@ -317,17 +317,17 @@ void FitParametersWidget::apply() {
&& !((QLineEdit *)ui.tableWidget->cellWidget(i, 1))->text().simplified().isEmpty() ) {
m_fitData->paramNames.append( ui.tableWidget->item(i, 0)->text() );
m_fitData->paramNamesUtf8.append( ui.tableWidget->item(i, 0)->text() );
m_fitData->paramStartValues.append( ((QLineEdit *)ui.tableWidget->cellWidget(i, 1))->text().toDouble() );
m_fitData->paramStartValues.append( QLocale().toDouble(((QLineEdit *)ui.tableWidget->cellWidget(i, 1))->text()) );
QWidget *widget = ui.tableWidget->cellWidget(i, 2)->layout()->itemAt(0)->widget();
m_fitData->paramFixed.append( (qobject_cast<QCheckBox *>(widget))->isChecked() );
if ( !((QLineEdit *)ui.tableWidget->cellWidget(i, 3))->text().isEmpty() )
m_fitData->paramLowerLimits.append( ((QLineEdit *)ui.tableWidget->cellWidget(i, 3))->text().toDouble() );
m_fitData->paramLowerLimits.append( QLocale().toDouble(((QLineEdit *)ui.tableWidget->cellWidget(i, 3))->text()) );
else
m_fitData->paramLowerLimits.append(-std::numeric_limits<double>::max());
if ( !((QLineEdit *)ui.tableWidget->cellWidget(i, 4))->text().isEmpty() )
m_fitData->paramUpperLimits.append( ((QLineEdit *)ui.tableWidget->cellWidget(i, 4))->text().toDouble() );
m_fitData->paramUpperLimits.append( QLocale().toDouble(((QLineEdit *)ui.tableWidget->cellWidget(i, 4))->text()) );
else
m_fitData->paramUpperLimits.append(std::numeric_limits<double>::max());
}
......@@ -341,17 +341,14 @@ void FitParametersWidget::apply() {
void FitParametersWidget::startValueChanged() {
DEBUG("FitParametersWidget::startValueChanged()");
const int row = ui.tableWidget->currentRow();
const double value = ((QLineEdit *)ui.tableWidget->cellWidget(row, 1))->text().toDouble();
double value{1};
SET_DOUBLE_FROM_LE(value, (QLineEdit *)ui.tableWidget->cellWidget(row, 1))
double lowerLimit, upperLimit;
double lowerLimit{-std::numeric_limits<double>::max()}, upperLimit{std::numeric_limits<double>::max()};
if ( !((QLineEdit *)ui.tableWidget->cellWidget(row, 3))->text().isEmpty() )
lowerLimit = ((QLineEdit *)ui.tableWidget->cellWidget(row, 3))->text().toDouble();
else
lowerLimit = -std::numeric_limits<double>::max();
SET_DOUBLE_FROM_LE(lowerLimit, (QLineEdit *)ui.tableWidget->cellWidget(row, 3))
if ( !((QLineEdit *)ui.tableWidget->cellWidget(row, 4))->text().isEmpty() )
upperLimit = ((QLineEdit *)ui.tableWidget->cellWidget(row, 4))->text().toDouble();
else
upperLimit = std::numeric_limits<double>::max();
SET_DOUBLE_FROM_LE(upperLimit, (QLineEdit *)ui.tableWidget->cellWidget(row, 4))
const bool invalid = (value < lowerLimit || value > upperLimit);
highlightInvalid(row, 1, invalid);
......@@ -376,17 +373,14 @@ void FitParametersWidget::lowerLimitChanged() {
DEBUG("FitParametersWidget::lowerLimitChanged()");
const int row = ui.tableWidget->currentRow();
const double value = ((QLineEdit *)ui.tableWidget->cellWidget(row, 1))->text().toDouble();
double value{1};
SET_DOUBLE_FROM_LE(value, (QLineEdit *)ui.tableWidget->cellWidget(row, 1))
double lowerLimit, upperLimit;
double lowerLimit{-std::numeric_limits<double>::max()}, upperLimit{std::numeric_limits<double>::max()};
if ( !((QLineEdit *)ui.tableWidget->cellWidget(row, 3))->text().isEmpty() )
lowerLimit = ((QLineEdit *)ui.tableWidget->cellWidget(row, 3))->text().toDouble();
else
lowerLimit = -std::numeric_limits<double>::max();
SET_DOUBLE_FROM_LE(lowerLimit, (QLineEdit *)ui.tableWidget->cellWidget(row, 3))
if ( !((QLineEdit *)ui.tableWidget->cellWidget(row, 4))->text().isEmpty() )
upperLimit = ((QLineEdit *)ui.tableWidget->cellWidget(row, 4))->text().toDouble();
else
upperLimit = std::numeric_limits<double>::max();
SET_DOUBLE_FROM_LE(upperLimit, (QLineEdit *)ui.tableWidget->cellWidget(row, 4))
const bool invalid = (lowerLimit > value || lowerLimit > upperLimit);
highlightInvalid(row, 3, invalid);
......@@ -411,17 +405,14 @@ void FitParametersWidget::upperLimitChanged() {
DEBUG("FitParametersWidget::upperLimitChanged()");
const int row = ui.tableWidget->currentRow();
const double value = ((QLineEdit *)ui.tableWidget->cellWidget(row, 1))->text().toDouble();
double value{1};
SET_DOUBLE_FROM_LE(value, (QLineEdit *)ui.tableWidget->cellWidget(row, 1))
double lowerLimit, upperLimit;
double lowerLimit{-std::numeric_limits<double>::max()}, upperLimit{std::numeric_limits<double>::max()};
if ( !((QLineEdit *)ui.tableWidget->cellWidget(row, 3))->text().isEmpty() )
lowerLimit = ((QLineEdit *)ui.tableWidget->cellWidget(row, 3))->text().toDouble();
else
lowerLimit = -std::numeric_limits<double>::max();
SET_DOUBLE_FROM_LE(lowerLimit, (QLineEdit *)ui.tableWidget->cellWidget(row, 3))
if ( !((QLineEdit *)ui.tableWidget->cellWidget(row, 4))->text().isEmpty() )
upperLimit = ((QLineEdit *)ui.tableWidget->cellWidget(row, 4))->text().toDouble();
else
upperLimit = std::numeric_limits<double>::max();
SET_DOUBLE_FROM_LE(upperLimit, (QLineEdit *)ui.tableWidget->cellWidget(row, 4))
const bool invalid = (upperLimit < value || upperLimit < lowerLimit);
highlightInvalid(row, 4, invalid);
......
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