]> sigrok.org Git - pulseview.git/blobdiff - pv/dialogs/settings.cpp
Settings: Refactor out a checkbox creator method
[pulseview.git] / pv / dialogs / settings.cpp
index 5e2be818c34c60f3634c976f503a12c635728764..c1833f0df74c0a1de6f93794fb9149b39b57d92d 100644 (file)
@@ -23,7 +23,6 @@
 #include <boost/version.hpp>
 
 #include <QApplication>
-#include <QCheckBox>
 #include <QDialogButtonBox>
 #include <QFormLayout>
 #include <QGroupBox>
@@ -101,6 +100,17 @@ void Settings::create_pages()
        viewButton->setTextAlignment(Qt::AlignHCenter);
        viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
 
+#ifdef ENABLE_DECODE
+       // Decoder page
+       pages->addWidget(get_decoder_settings_form(pages));
+
+       QListWidgetItem *decoderButton = new QListWidgetItem(page_list);
+       decoderButton->setIcon(QIcon(":/icons/add-decoder.svg"));
+       decoderButton->setText(tr("Decoders"));
+       decoderButton->setTextAlignment(Qt::AlignHCenter);
+       decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+#endif
+
        // About page
        pages->addWidget(get_about_page(pages));
 
@@ -111,10 +121,20 @@ void Settings::create_pages()
        aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
 }
 
-QWidget *Settings::get_view_settings_form(QWidget *parent) const
+QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const
 {
        GlobalSettings settings;
 
+       QCheckBox *cb = new QCheckBox();
+       cb->setChecked(settings.value(key).toBool());
+       connect(cb, SIGNAL(stateChanged(int)), this, slot);
+       return cb;
+}
+
+QWidget *Settings::get_view_settings_form(QWidget *parent) const
+{
+       QCheckBox *cb;
+
        QWidget *form = new QWidget(parent);
        QVBoxLayout *form_layout = new QVBoxLayout(form);
 
@@ -125,32 +145,52 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
        QFormLayout *trace_view_layout = new QFormLayout();
        trace_view_group->setLayout(trace_view_layout);
 
-       QCheckBox *coloured_bg_cb = new QCheckBox();
-       coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
-       connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
-       trace_view_layout->addRow(tr("Use coloured trace &background"), coloured_bg_cb);
+       cb = create_checkbox(GlobalSettings::Key_View_ColouredBG,
+               SLOT(on_view_colouredBG_changed(int)));
+       trace_view_layout->addRow(tr("Use coloured trace &background"), cb);
+
+       cb = create_checkbox(GlobalSettings::Key_View_AlwaysZoomToFit,
+               SLOT(on_view_alwaysZoomToFit_changed(int)));
+       trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), cb);
+
+       cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
+               SLOT(on_view_stickyScrolling_changed(int)));
+       trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
+
+       cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
+               SLOT(on_view_showSamplingPoints_changed(int)));
+       trace_view_layout->addRow(tr("Show data &sampling points"), cb);
+
+       cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
+               SLOT(on_view_showAnalogMinorGrid_changed(int)));
+       trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), cb);
 
-       QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
-       always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
-       connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
-       trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), always_zoom_to_fit_cb);
+       return form;
+}
 
-       QCheckBox *sticky_scrolling_cb = new QCheckBox();
-       sticky_scrolling_cb->setChecked(settings.value(GlobalSettings::Key_View_StickyScrolling).toBool());
-       connect(sticky_scrolling_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_stickyScrolling_changed(int)));
-       trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), sticky_scrolling_cb);
+QWidget *Settings::get_decoder_settings_form(QWidget *parent) const
+{
+#ifdef ENABLE_DECODE
+       QCheckBox *cb;
+
+       QWidget *form = new QWidget(parent);
+       QVBoxLayout *form_layout = new QVBoxLayout(form);
 
-       QCheckBox *show_sampling_points_cb = new QCheckBox();
-       show_sampling_points_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
-       connect(show_sampling_points_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showSamplingPoints_changed(int)));
-       trace_view_layout->addRow(tr("Show data &sampling points"), show_sampling_points_cb);
+       // Decoder settings
+       QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
+       form_layout->addWidget(decoder_group);
 
-       QCheckBox *show_analog_minor_grid_cb = new QCheckBox();
-       show_analog_minor_grid_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool());
-       connect(show_analog_minor_grid_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showAnalogMinorGrid_changed(int)));
-       trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), show_analog_minor_grid_cb);
+       QFormLayout *decoder_layout = new QFormLayout();
+       decoder_group->setLayout(decoder_layout);
+
+       cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
+               SLOT(on_dec_initialStateConfigurable_changed(int)));
+       decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
 
        return form;
+#else
+       (void)parent;
+#endif
 }
 
 #ifdef ENABLE_DECODE
@@ -251,6 +291,7 @@ QWidget *Settings::get_about_page(QWidget *parent) const
 #endif
 
        /* Set up the supported field */
+       s.append("<tr><td colspan=\"2\"></td></tr>");
        s.append("<tr><td colspan=\"2\"><b>" +
                tr("Supported hardware drivers:") + "</b></td></tr>");
        for (auto entry : context->drivers()) {
@@ -259,6 +300,7 @@ QWidget *Settings::get_about_page(QWidget *parent) const
                                QString::fromUtf8(entry.second->long_name().c_str())));
        }
 
+       s.append("<tr><td colspan=\"2\"></td></tr>");
        s.append("<tr><td colspan=\"2\"><b>" +
                tr("Supported input formats:") + "</b></td></tr>");
        for (auto entry : context->input_formats()) {
@@ -267,6 +309,7 @@ QWidget *Settings::get_about_page(QWidget *parent) const
                                QString::fromUtf8(entry.second->description().c_str())));
        }
 
+       s.append("<tr><td colspan=\"2\"></td></tr>");
        s.append("<tr><td colspan=\"2\"><b>" +
                tr("Supported output formats:") + "</b></td></tr>");
        for (auto entry : context->output_formats()) {
@@ -276,6 +319,7 @@ QWidget *Settings::get_about_page(QWidget *parent) const
        }
 
 #ifdef ENABLE_DECODE
+       s.append("<tr><td colspan=\"2\"></td></tr>");
        s.append("<tr><td colspan=\"2\"><b>" +
                tr("Supported protocol decoders:") + "</b></td></tr>");
        GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
@@ -362,5 +406,11 @@ void Settings::on_view_showAnalogMinorGrid_changed(int state)
        settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
 }
 
+void Settings::on_dec_initialStateConfigurable_changed(int state)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
+}
+
 } // namespace dialogs
 } // namespace pv