Skip to content
Snippets Groups Projects
Commit 186fafed authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

[i589] QREDataLoaderProperties catch nullptr ()

Merging branch 'i589'  into 'r20.3'.

See merge request !1622
parents 486e0f96 8df46bc2
No related branches found
No related tags found
2 merge requests!1625From20.3,!1622QREDataLoaderProperties catch nullptr
Pipeline #98613 passed
BornAgain-20.3
> Hotfix:
* Prevent crash in QRE loader (#589)
BornAgain-20.2, released 2023.05.04 BornAgain-20.2, released 2023.05.04
> Hotfix: > Hotfix:
* Correct polarized specular computation without user provided pol matrices (#549) * Correct polarized specular computation without user provided pol matrices (#549)
......
...@@ -112,11 +112,12 @@ void QREDataLoader::populateImportSettingsWidget(QWidget* parent) ...@@ -112,11 +112,12 @@ void QREDataLoader::populateImportSettingsWidget(QWidget* parent)
m_propertiesWidget->m_ui->linesToSkipEdit->setText(m_importSettings.linesToSkip); m_propertiesWidget->m_ui->linesToSkipEdit->setText(m_importSettings.linesToSkip);
for (const auto dataType : {DataType::Q, DataType::R, DataType::dR}) { for (const auto dataType : {DataType::Q, DataType::R, DataType::dR}) {
m_propertiesWidget->columnSpinBox((int)dataType) if (QSpinBox* sb = m_propertiesWidget->columnSpinBox((int)dataType))
->setValue(m_importSettings.columnDefinitions[dataType].column + 1); // view is 1-based // view is 1-based
sb->setValue(m_importSettings.columnDefinitions[dataType].column + 1);
m_propertiesWidget->factorSpinBox((int)dataType) if (QDoubleSpinBox* sb = m_propertiesWidget->factorSpinBox((int)dataType))
->setValue(m_importSettings.columnDefinitions[dataType].factor); sb->setValue(m_importSettings.columnDefinitions[dataType].factor);
} }
m_propertiesWidget->m_ui->enableErrorCheckBox->setChecked( m_propertiesWidget->m_ui->enableErrorCheckBox->setChecked(
...@@ -618,7 +619,10 @@ void QREDataLoader::applyImportSettings() ...@@ -618,7 +619,10 @@ void QREDataLoader::applyImportSettings()
for (const auto dataType : m_importSettings.columnDefinitions.keys()) { for (const auto dataType : m_importSettings.columnDefinitions.keys()) {
auto& colDef = m_importSettings.columnDefinitions[dataType]; auto& colDef = m_importSettings.columnDefinitions[dataType];
colDef.column = m_propertiesWidget->columnSpinBox((int)dataType)->value() - 1; if (const auto* sb = m_propertiesWidget->columnSpinBox((int)dataType))
colDef.column = sb->value() - 1;
else
ASSERT(false);
colDef.factor = m_propertiesWidget->factor((int)dataType); colDef.factor = m_propertiesWidget->factor((int)dataType);
} }
......
...@@ -40,17 +40,23 @@ QREDataLoaderProperties::QREDataLoaderProperties() ...@@ -40,17 +40,23 @@ QREDataLoaderProperties::QREDataLoaderProperties()
// In the following: disable the checkbox before signaling propertyChanged to suppress ghost // In the following: disable the checkbox before signaling propertyChanged to suppress ghost
// value changes in case the propertiesChanged signals triggers long calculations (the // value changes in case the propertiesChanged signals triggers long calculations (the
// spinbox would see a timeout in its "pressed"-loop and generate a second value change) // spinbox would see a timeout in its "pressed"-loop and generate a second value change)
connect(columnSpinBox(dataType), QOverload<int>::of(&QSpinBox::valueChanged), [=]() { connect(columnSpinBox(dataType), QOverload<int>::of(&QSpinBox::valueChanged), [&]() {
columnSpinBox(dataType)->setEnabled(false); QSpinBox* sb = columnSpinBox(dataType);
if (sb)
sb->setEnabled(false);
emit propertiesChanged(); emit propertiesChanged();
columnSpinBox(dataType)->setEnabled(true); if (sb)
sb->setEnabled(true);
}); });
connect(factorSpinBox(dataType), QOverload<double>::of(&QDoubleSpinBox::valueChanged), connect(factorSpinBox(dataType), QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[=]() { [&]() {
factorSpinBox(dataType)->setEnabled(false); QDoubleSpinBox* sb = factorSpinBox(dataType);
if (sb)
sb->setEnabled(false);
emit propertiesChanged(); emit propertiesChanged();
factorSpinBox(dataType)->setEnabled(true); if (sb)
sb->setEnabled(true);
}); });
} }
} }
...@@ -59,8 +65,10 @@ void QREDataLoaderProperties::allowFactors(bool b) ...@@ -59,8 +65,10 @@ void QREDataLoaderProperties::allowFactors(bool b)
{ {
m_allowFactors = b; m_allowFactors = b;
for (int dataType = 0; dataType < 3; dataType++) { for (int dataType = 0; dataType < 3; dataType++) {
factorLabel(dataType)->setVisible(b); if (auto* label = factorLabel(dataType))
factorSpinBox(dataType)->setVisible(b); label->setVisible(b);
if (auto* sb = factorSpinBox(dataType))
sb->setVisible(b);
} }
updateErrorEnabling(m_ui->enableErrorCheckBox->isChecked()); updateErrorEnabling(m_ui->enableErrorCheckBox->isChecked());
...@@ -68,8 +76,8 @@ void QREDataLoaderProperties::allowFactors(bool b) ...@@ -68,8 +76,8 @@ void QREDataLoaderProperties::allowFactors(bool b)
double QREDataLoaderProperties::factor(int dataType) const double QREDataLoaderProperties::factor(int dataType) const
{ {
auto* const spinBox = factorSpinBox(dataType); auto* const sb = factorSpinBox(dataType);
return spinBox->isVisible() ? spinBox->value() : 1.0; return sb && sb->isVisible() ? sb->value() : 1.0;
} }
void QREDataLoaderProperties::updateErrorEnabling(bool enabled) const void QREDataLoaderProperties::updateErrorEnabling(bool enabled) const
...@@ -100,20 +108,26 @@ void QREDataLoaderProperties::onErrorEnablingChanged() ...@@ -100,20 +108,26 @@ void QREDataLoaderProperties::onErrorEnablingChanged()
QSpinBox* QREDataLoaderProperties::columnSpinBox(int dataType) const QSpinBox* QREDataLoaderProperties::columnSpinBox(int dataType) const
{ {
const int lineInLayout = dataType; const int lineInLayout = dataType;
return dynamic_cast<QSpinBox*>( QLayoutItem* item = m_ui->gridLayout->itemAtPosition(lineInLayout, columnColumn);
m_ui->gridLayout->itemAtPosition(lineInLayout, columnColumn)->widget()); if (!item)
return {};
return dynamic_cast<QSpinBox*>(item->widget());
} }
QDoubleSpinBox* QREDataLoaderProperties::factorSpinBox(int dataType) const QDoubleSpinBox* QREDataLoaderProperties::factorSpinBox(int dataType) const
{ {
const int lineInLayout = dataType; const int lineInLayout = dataType;
return dynamic_cast<QDoubleSpinBox*>( QLayoutItem* item = m_ui->gridLayout->itemAtPosition(lineInLayout, factorColumn);
m_ui->gridLayout->itemAtPosition(lineInLayout, factorColumn)->widget()); if (!item)
return {};
return dynamic_cast<QDoubleSpinBox*>(item->widget());
} }
QLabel* QREDataLoaderProperties::factorLabel(int dataType) const QLabel* QREDataLoaderProperties::factorLabel(int dataType) const
{ {
const int lineInLayout = dataType; const int lineInLayout = dataType;
return dynamic_cast<QLabel*>( QLayoutItem* item = m_ui->gridLayout->itemAtPosition(lineInLayout, factorLabelColumn);
m_ui->gridLayout->itemAtPosition(lineInLayout, factorLabelColumn)->widget()); if (!item)
return {};
return dynamic_cast<QLabel*>(item->widget());
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment