From ddad5411c2fe4f3364b69447d9190e1519bac016 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Tue, 23 May 2023 18:43:20 +0200
Subject: [PATCH] rm factor spinbox, rm signal

---
 GUI/View/Import/Legacy1dDialog.cpp | 134 ++++++-----------------------
 GUI/View/Import/Legacy1dDialog.h   |  27 +-----
 2 files changed, 30 insertions(+), 131 deletions(-)

diff --git a/GUI/View/Import/Legacy1dDialog.cpp b/GUI/View/Import/Legacy1dDialog.cpp
index a26865edf66..447d03acf1c 100644
--- a/GUI/View/Import/Legacy1dDialog.cpp
+++ b/GUI/View/Import/Legacy1dDialog.cpp
@@ -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());
-}
diff --git a/GUI/View/Import/Legacy1dDialog.h b/GUI/View/Import/Legacy1dDialog.h
index 22caea41f13..1e334ea69d4 100644
--- a/GUI/View/Import/Legacy1dDialog.h
+++ b/GUI/View/Import/Legacy1dDialog.h
@@ -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;
 };
-- 
GitLab