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

rm factor spinbox, rm signal

parent a2424b55
No related branches found
No related tags found
1 merge request!1649Generic legacy 1D tables can again be read, now using new modal format dialog (#601)
......@@ -28,7 +28,6 @@
ImportSettings1D Legacy1dDialog::Msettings = legacy1D_3cols;
Legacy1dDialog::Legacy1dDialog()
: m_allowFactors(false)
{
setWindowTitle("Define legacy input format");
setWindowFlags(Qt::Dialog);
......@@ -58,40 +57,40 @@ Legacy1dDialog::Legacy1dDialog()
auto form211 = new QFormLayout;
w21->setLayout(form211);
m_linesToSkipEdit = new QLineEdit;
form211->addRow("Ignore line numbers:", m_linesToSkipEdit);
auto linesToSkipEdit = new QLineEdit;
form211->addRow("Ignore line numbers:", linesToSkipEdit);
if (Msettings.linesToSkip.empty())
m_linesToSkipEdit->setPlaceholderText("Example: 1-5, 12");
linesToSkipEdit->setPlaceholderText("Example: 1-5, 12");
else
m_linesToSkipEdit->setText(QString::fromStdString(Msettings.linesToSkip));
connect(m_linesToSkipEdit, &QLineEdit::textEdited,
linesToSkipEdit->setText(QString::fromStdString(Msettings.linesToSkip));
connect(linesToSkipEdit, &QLineEdit::textEdited,
[&p = Msettings](const QString& text) { p.linesToSkip = text.toStdString(); });
m_headerPrefixEdit = new QLineEdit;
form211->addRow("Ignore lines starting with:", m_headerPrefixEdit);
auto headerPrefixEdit = new QLineEdit;
form211->addRow("Ignore lines starting with:", headerPrefixEdit);
if (Msettings.headerPrefix.empty())
m_headerPrefixEdit->setPlaceholderText("#,//");
headerPrefixEdit->setPlaceholderText("#,//");
else
m_headerPrefixEdit->setText(QString::fromStdString(Msettings.headerPrefix));
connect(m_headerPrefixEdit, &QLineEdit::textEdited,
headerPrefixEdit->setText(QString::fromStdString(Msettings.headerPrefix));
connect(headerPrefixEdit, &QLineEdit::textEdited,
[&p = Msettings](const QString& text) { p.headerPrefix = text.toStdString(); });
m_separatorCombo = new QComboBox;
form211->addRow("Separator:", m_separatorCombo);
m_separatorCombo->addItem("SPACE");
m_separatorCombo->addItem("TAB");
m_separatorCombo->addItem(",");
m_separatorCombo->addItem(";");
m_separatorCombo->setCurrentText(QString::fromStdString(Msettings.separator));
connect(m_separatorCombo, &QComboBox::currentTextChanged,
auto separatorCombo = new QComboBox;
form211->addRow("Separator:", separatorCombo);
separatorCombo->addItem("SPACE");
separatorCombo->addItem("TAB");
separatorCombo->addItem(",");
separatorCombo->addItem(";");
separatorCombo->setCurrentText(QString::fromStdString(Msettings.separator));
connect(separatorCombo, &QComboBox::currentTextChanged,
[&p = Msettings](const QString& text) { p.separator = text.toStdString(); });
m_qUnitCombo = new QComboBox;
form211->addRow("Q given in units of:", m_qUnitCombo);
m_qUnitCombo->addItem("1/nm");
m_qUnitCombo->addItem("1/Å");
m_qUnitCombo->setCurrentIndex((int)Msettings.qUnit);
connect(m_qUnitCombo, &QComboBox::currentIndexChanged,
auto qUnitCombo = new QComboBox;
form211->addRow("Q given in units of:", qUnitCombo);
qUnitCombo->addItem("1/nm");
qUnitCombo->addItem("1/Å");
qUnitCombo->setCurrentIndex((int)Msettings.qUnit);
connect(qUnitCombo, &QComboBox::currentIndexChanged,
[&p = Msettings](int i) { p.qUnit = (QUnit)i; });
auto buttonline = new QHBoxLayout;
......@@ -102,18 +101,9 @@ Legacy1dDialog::Legacy1dDialog()
okButton->setDefault(true);
connect(okButton, &QPushButton::clicked, this, &Legacy1dDialog::accept);
allowFactors(false);
connect(m_headerPrefixEdit, &QLineEdit::textChanged, [this]() { emit propertiesChanged(); });
connect(m_linesToSkipEdit, &QLineEdit::textChanged, [this]() { emit propertiesChanged(); });
connect(m_separatorCombo, &QComboBox::currentTextChanged,
[this]() { emit propertiesChanged(); });
connect(m_enableErrorCheckBox, &QCheckBox::stateChanged, this,
&Legacy1dDialog::onErrorEnablingChanged);
connect(m_qUnitCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
[this]() { emit propertiesChanged(); });
// connect(m_enableErrorCheckBox, &QCheckBox::stateChanged, this,
// &Legacy1dDialog::onErrorEnablingChanged);
for (int i = 0; i < 3; i++) {
// In the following: disable the checkbox before signaling propertyChanged to suppress ghost
......@@ -123,67 +113,13 @@ Legacy1dDialog::Legacy1dDialog()
QSpinBox* sb = columnSpinBox(i);
if (sb)
sb->setEnabled(false);
emit propertiesChanged();
if (sb)
sb->setEnabled(true);
});
connect(factorSpinBox(i), QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this, i]() {
QDoubleSpinBox* sb = factorSpinBox(i);
if (sb)
sb->setEnabled(false);
emit propertiesChanged();
if (sb)
sb->setEnabled(true);
});
}
}
void Legacy1dDialog::allowFactors(bool b)
{
m_allowFactors = b;
for (int dataType = 0; dataType < 3; dataType++) {
if (auto* label = factorLabel(dataType))
label->setVisible(b);
if (auto* sb = factorSpinBox(dataType))
sb->setVisible(b);
}
updateErrorEnabling(m_enableErrorCheckBox->isChecked());
}
double Legacy1dDialog::factor(int dataType) const
{
auto* const sb = factorSpinBox(dataType);
return sb && sb->isVisible() ? sb->value() : 1.0;
}
void Legacy1dDialog::updateErrorEnabling(bool enabled) const
{
const int lineInLayout = 2;
for (int col = 2; col < m_gridLayout->columnCount(); col++) {
auto* const layoutItem = m_gridLayout->itemAtPosition(lineInLayout, col);
if (layoutItem) {
QWidget* w = layoutItem->widget();
if (w) {
const bool belongsToFactor = col == factorColumn || col == factorLabelColumn;
w->setVisible(enabled && (!belongsToFactor || m_allowFactors));
}
}
}
}
void Legacy1dDialog::onErrorEnablingChanged()
{
const bool isEnabled = m_enableErrorCheckBox->isChecked();
updateErrorEnabling(isEnabled);
emit propertiesChanged();
}
QSpinBox* Legacy1dDialog::columnSpinBox(int dataType) const
{
const int lineInLayout = dataType;
......@@ -192,21 +128,3 @@ QSpinBox* Legacy1dDialog::columnSpinBox(int dataType) const
return {};
return dynamic_cast<QSpinBox*>(item->widget());
}
QDoubleSpinBox* Legacy1dDialog::factorSpinBox(int dataType) const
{
const int lineInLayout = dataType;
QLayoutItem* item = m_gridLayout->itemAtPosition(lineInLayout, factorColumn);
if (!item)
return {};
return dynamic_cast<QDoubleSpinBox*>(item->widget());
}
QLabel* Legacy1dDialog::factorLabel(int dataType) const
{
const int lineInLayout = dataType;
QLayoutItem* item = m_gridLayout->itemAtPosition(lineInLayout, factorLabelColumn);
if (!item)
return {};
return dynamic_cast<QLabel*>(item->widget());
}
......@@ -25,38 +25,19 @@ class Legacy1dDialog : public QDialog {
public:
Legacy1dDialog();
//! Factors shall not be supported. However, since the requirements have been there,
//! they are only deactivated. Call allowFactors(true) to enable them.
void allowFactors(bool b);
double factor(int dataType) const;
class QSpinBox* columnSpinBox(int dataType) const;
class QDoubleSpinBox* factorSpinBox(int dataType) const;
class QGridLayout* m_gridLayout;
class QCheckBox* m_enableErrorCheckBox;
class QLineEdit* m_headerPrefixEdit;
class QLineEdit* m_linesToSkipEdit;
class QComboBox* m_separatorCombo;
class QComboBox* m_qUnitCombo;
signals:
void propertiesChanged();
class QLineEdit* headerPrefixEdit;
class QLineEdit* linesToSkipEdit;
class QComboBox* separatorCombo;
class QComboBox* qUnitCombo;
private:
void updateErrorEnabling(bool enabled) const;
void onErrorEnablingChanged();
class QLabel* factorLabel(int dataType) const;
// factors shall not be supported. However, since the requirements have been there,
// they are only deactivated. Call allowFactors(true) to enable them.
bool m_allowFactors;
static const int columnColumn = 3;
static const int factorLabelColumn = 4;
static const int factorColumn = factorLabelColumn + 1;
static ImportSettings1D Msettings;
};
......
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