BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
QREDataLoaderProperties.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Loaders/QREDataLoaderProperties.cpp
6 //! @brief Implements class AutomaticMultiColumnDataLoader1DProperties
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "ui_QREDataLoaderProperties.h"
17 #include <QCheckBox>
18 #include <QtGui>
19 
21  : m_allowFactors(false)
22 {
23  m_ui = new Ui::QREDataLoaderProperties;
24  m_ui->setupUi(this);
25 
26  allowFactors(false);
27 
28  connect(m_ui->headerPrefixEdit, &QLineEdit::textChanged, [=]() { emit propertiesChanged(); });
29  connect(m_ui->linesToSkipEdit, &QLineEdit::textChanged, [=]() { emit propertiesChanged(); });
30  connect(m_ui->separatorCombo, &QComboBox::currentTextChanged,
31  [=]() { emit propertiesChanged(); });
32 
33  connect(m_ui->enableErrorCheckBox, &QCheckBox::stateChanged, this,
35 
36  connect(m_ui->qUnitCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
37  [=]() { emit propertiesChanged(); });
38 
39  for (int dataType = 0; dataType < 3; dataType++) {
40  // In the following: disable the checkbox before signaling propertyChanged to suppress ghost
41  // value changes in case the propertiesChanged signals triggers long calculations (the
42  // spinbox would see a timeout in its "pressed"-loop and generate a second value change)
43  connect(columnSpinBox(dataType), QOverload<int>::of(&QSpinBox::valueChanged), [=]() {
44  columnSpinBox(dataType)->setEnabled(false);
45  emit propertiesChanged();
46  columnSpinBox(dataType)->setEnabled(true);
47  });
48 
49  connect(factorSpinBox(dataType), QOverload<double>::of(&QDoubleSpinBox::valueChanged),
50  [=]() {
51  factorSpinBox(dataType)->setEnabled(false);
52  emit propertiesChanged();
53  factorSpinBox(dataType)->setEnabled(true);
54  });
55  }
56 }
57 
59 {
60  m_allowFactors = b;
61  for (int dataType = 0; dataType < 3; dataType++) {
62  factorLabel(dataType)->setVisible(b);
63  factorSpinBox(dataType)->setVisible(b);
64  }
65 
66  updateErrorEnabling(m_ui->enableErrorCheckBox->isChecked());
67 }
68 
69 double QREDataLoaderProperties::factor(int dataType) const
70 {
71  auto* const spinBox = factorSpinBox(dataType);
72  return spinBox->isVisible() ? spinBox->value() : 1.0;
73 }
74 
76 {
77  const int lineInLayout = 2;
78 
79  for (int col = 2; col < m_ui->gridLayout->columnCount(); col++) {
80  auto* const layoutItem = m_ui->gridLayout->itemAtPosition(lineInLayout, col);
81  if (layoutItem) {
82  QWidget* w = layoutItem->widget();
83  if (w) {
84  const bool belongsToFactor = col == factorColumn || col == factorLabelColumn;
85  w->setVisible(enabled && (!belongsToFactor || m_allowFactors));
86  }
87  }
88  }
89 }
90 
92 {
93  const bool isEnabled = m_ui->enableErrorCheckBox->isChecked();
94 
95  updateErrorEnabling(isEnabled);
96 
97  emit propertiesChanged();
98 }
99 
100 QSpinBox* QREDataLoaderProperties::columnSpinBox(int dataType) const
101 {
102  const int lineInLayout = dataType;
103  return dynamic_cast<QSpinBox*>(
104  m_ui->gridLayout->itemAtPosition(lineInLayout, columnColumn)->widget());
105 }
106 
107 QDoubleSpinBox* QREDataLoaderProperties::factorSpinBox(int dataType) const
108 {
109  const int lineInLayout = dataType;
110  return dynamic_cast<QDoubleSpinBox*>(
111  m_ui->gridLayout->itemAtPosition(lineInLayout, factorColumn)->widget());
112 }
113 
114 QLabel* QREDataLoaderProperties::factorLabel(int dataType) const
115 {
116  const int lineInLayout = dataType;
117  return dynamic_cast<QLabel*>(
118  m_ui->gridLayout->itemAtPosition(lineInLayout, factorLabelColumn)->widget());
119 }
Defines class AutomaticMultiColumnDataLoader1DProperties.
QLabel * factorLabel(int dataType) const
void updateErrorEnabling(bool enabled) const
double factor(int dataType) const
void allowFactors(bool b)
Factors shall not be supported. However, since the requirements have been there, they are only deacti...
QSpinBox * columnSpinBox(int dataType) const
QDoubleSpinBox * factorSpinBox(int dataType) const
Ui::QREDataLoaderProperties * m_ui