Convert threshold display setting to a multi-value choice
authorSoeren Apel <soeren@apelpie.net>
Sun, 20 Aug 2017 14:18:50 +0000 (16:18 +0200)
committerSoeren Apel <soeren@apelpie.net>
Sun, 20 Aug 2017 14:18:50 +0000 (16:18 +0200)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/analogsignal.cpp
pv/views/trace/analogsignal.hpp

index 76966f4c93fdc4678bf50453ee96106ac78c22a9..1730e7ba2ebb78c8625c97073662fc68d0ed3398 100644 (file)
@@ -23,6 +23,7 @@
 #include <boost/version.hpp>
 
 #include <QApplication>
+#include <QComboBox>
 #include <QDialogButtonBox>
 #include <QFormLayout>
 #include <QGroupBox>
@@ -169,11 +170,17 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
 
        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);
-
-       cb = create_checkbox(GlobalSettings::Key_View_ShowConversionThresholds,
-               SLOT(on_view_showConversionThresholds_changed(int)));
-       trace_view_layout->addRow(tr("Show conversion thresholds in analog traces"), cb);
+       trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
+
+       QComboBox *thr_disp_mode_cb = new QComboBox();
+       thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
+       thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
+       thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
+       thr_disp_mode_cb->setCurrentIndex(
+               settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
+       connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
+       trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
 
        QSpinBox *default_div_height_sb = new QSpinBox();
        default_div_height_sb->setRange(20, 1000);
@@ -441,10 +448,10 @@ void Settings::on_view_showAnalogMinorGrid_changed(int state)
        settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
 }
 
-void Settings::on_view_showConversionThresholds_changed(int state)
+void Settings::on_view_conversionThresholdDispMode_changed(int state)
 {
        GlobalSettings settings;
-       settings.setValue(GlobalSettings::Key_View_ShowConversionThresholds, state ? true : false);
+       settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
 }
 
 void Settings::on_view_defaultDivHeight_changed(int value)
index 11277f7ae9563ac653d3378a421873214f5dfa8e..72c96125de580d77042cb853db0bc1d0a62e526a 100644 (file)
@@ -56,7 +56,7 @@ private Q_SLOTS:
        void on_view_stickyScrolling_changed(int state);
        void on_view_showSamplingPoints_changed(int state);
        void on_view_showAnalogMinorGrid_changed(int state);
-       void on_view_showConversionThresholds_changed(int state);
+       void on_view_conversionThresholdDispMode_changed(int state);
        void on_view_defaultDivHeight_changed(int value);
        void on_view_defaultLogicHeight_changed(int value);
        void on_dec_initialStateConfigurable_changed(int state);
index 895dda54317e3aa4ec21653456d10f9adcef11a5..eabe4d3c185498a5c19fd71ecb7eef8a420b33f1 100644 (file)
@@ -36,7 +36,7 @@ const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG";
 const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling";
 const QString GlobalSettings::Key_View_ShowSamplingPoints = "View_ShowSamplingPoints";
 const QString GlobalSettings::Key_View_ShowAnalogMinorGrid = "View_ShowAnalogMinorGrid";
-const QString GlobalSettings::Key_View_ShowConversionThresholds = "View_ShowConversionThresholds";
+const QString GlobalSettings::Key_View_ConversionThresholdDispMode = "View_ConversionThresholdDispMode";
 const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight";
 const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight";
 const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable";
index 201c5e20a9fc23f95b72f0d2f0cf2b546f9cee0c..9cf2978b68369751c76c9e53dc9ec0d6586ded04 100644 (file)
@@ -46,11 +46,17 @@ public:
        static const QString Key_View_StickyScrolling;
        static const QString Key_View_ShowSamplingPoints;
        static const QString Key_View_ShowAnalogMinorGrid;
-       static const QString Key_View_ShowConversionThresholds;
+       static const QString Key_View_ConversionThresholdDispMode;
        static const QString Key_View_DefaultDivHeight;
        static const QString Key_View_DefaultLogicHeight;
        static const QString Key_Dec_InitialStateConfigurable;
 
+       enum ConvThrDispMode {
+               ConvThrDispMode_None = 0,
+               ConvThrDispMode_Background,
+               ConvThrDispMode_Dots
+       };
+
 public:
        GlobalSettings();
 
index a78d65541ba6544713793d884bff0c8309002e1c..ef6581fc1dd90ba46edfa27a2a886d3da914f471 100644 (file)
@@ -113,12 +113,12 @@ AnalogSignal::AnalogSignal(
        connect(analog_data, SIGNAL(min_max_changed(float, float)),
                this, SLOT(on_min_max_changed(float, float)));
 
-       GlobalSettings::register_change_handler(GlobalSettings::Key_View_ShowConversionThresholds,
-               bind(&AnalogSignal::on_settingViewShowConversionThresholds_changed, this, _1));
+       GlobalSettings::register_change_handler(GlobalSettings::Key_View_ConversionThresholdDispMode,
+               bind(&AnalogSignal::on_settingViewConversionThresholdDispMode_changed, this, _1));
 
        GlobalSettings gs;
-       show_conversion_thresholds_ =
-               gs.value(GlobalSettings::Key_View_ShowConversionThresholds).toBool();
+       conversion_threshold_disp_mode_ =
+               gs.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt();
 
        div_height_ = gs.value(GlobalSettings::Key_View_DefaultDivHeight).toInt();
 
@@ -206,10 +206,13 @@ void AnalogSignal::paint_back(QPainter &p, ViewItemPaintParams &pp)
        if (!base_->enabled())
                return;
 
+       bool paint_thr_bg =
+               conversion_threshold_disp_mode_ == GlobalSettings::ConvThrDispMode_Background;
+
        const vector<double> thresholds = base_->get_conversion_thresholds();
 
        // Only display thresholds if we have some and we show analog samples
-       if ((thresholds.size() > 0) && show_conversion_thresholds_ &&
+       if ((thresholds.size() > 0) && paint_thr_bg &&
                ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth))) {
 
                const int visual_y = get_visual_y();
@@ -1073,9 +1076,9 @@ void AnalogSignal::on_display_type_changed(int index)
                owner_->row_item_appearance_changed(false, true);
 }
 
-void AnalogSignal::on_settingViewShowConversionThresholds_changed(const QVariant new_value)
+void AnalogSignal::on_settingViewConversionThresholdDispMode_changed(const QVariant new_value)
 {
-       show_conversion_thresholds_ = new_value.toBool();
+       conversion_threshold_disp_mode_ = new_value.toInt();
 
        if (owner_)
                owner_->row_item_appearance_changed(false, true);
index a36efce4879ca1c9e5602772ca41972ab2af280a..ffaac266020e3d2f098703efea3967591da32586 100644 (file)
@@ -173,7 +173,7 @@ private Q_SLOTS:
 
        void on_display_type_changed(int index);
 
-       void on_settingViewShowConversionThresholds_changed(const QVariant new_value);
+       void on_settingViewConversionThresholdDispMode_changed(const QVariant new_value);
 
 private:
        QComboBox *resolution_cb_, *conversion_cb_, *conv_threshold_cb_,
@@ -190,7 +190,7 @@ private:
 
        DisplayType display_type_;
        bool autoranging_;
-       bool show_conversion_thresholds_;
+       int conversion_threshold_disp_mode_;
 };
 
 } // namespace trace