]> sigrok.org Git - pulseview.git/commitdiff
Show sample count selector only if setting supported.
authorMartin Ling <redacted>
Tue, 14 Jan 2014 19:59:49 +0000 (19:59 +0000)
committerJoel Holdsworth <redacted>
Sat, 18 Jan 2014 22:56:12 +0000 (22:56 +0000)
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h

index c57779c2f394bc546a4960631d9656bf63b5729a..a2ddaae6bb46a4bde8284b92438ee87716b2052d 100644 (file)
@@ -53,6 +53,7 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
        _sample_count(" samples", this),
        _sample_rate("Hz", this),
        _updating_sample_rate(false),
+       _updating_sample_count(false),
        _icon_red(":/icons/status-red.svg"),
        _icon_green(":/icons/status-green.svg"),
        _icon_grey(":/icons/status-grey.svg"),
@@ -68,7 +69,6 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
                this, SLOT(on_sample_rate_changed()));
 
        _sample_count.show_min_max_step(0, UINT64_MAX, 1);
-       _sample_count.set_value(DefaultRecordLength);
 
        set_capture_state(pv::SigSession::Stopped);
 
@@ -204,6 +204,32 @@ void SamplingBar::update_sample_rate_selector_value()
        _updating_sample_rate = false;
 }
 
+void SamplingBar::update_sample_count_selector()
+{
+       sr_dev_inst *const sdi = get_selected_device();
+       GVariant *gvar;
+       uint64_t samplecount;
+
+       assert(sdi);
+
+       if (sr_config_get(sdi->driver, sdi, NULL,
+               SR_CONF_LIMIT_SAMPLES, &gvar) != SR_OK)
+       {
+               _sample_count.show_none();
+       }
+       else
+       {
+               _sample_count.show_min_max_step(0, UINT64_MAX, 1);
+
+               samplecount = g_variant_get_uint64(gvar);
+               g_variant_unref(gvar);
+
+               _updating_sample_count = true;
+               _sample_count.set_value(samplecount);
+               _updating_sample_count = false;
+       }
+}
+
 void SamplingBar::commit_sample_count()
 {
        uint64_t sample_count = 0;
@@ -247,8 +273,12 @@ void SamplingBar::on_device_selected()
        if (_updating_device_selector)
                return;
 
+       update_sample_count_selector();
        update_sample_rate_selector();
 
+       if (_sample_count.value() == 0)
+               _sample_count.set_value(DefaultRecordLength);
+
        sr_dev_inst *const sdi = get_selected_device();
        _session.set_device(sdi);
 
@@ -265,7 +295,8 @@ void SamplingBar::on_device_selected()
 
 void SamplingBar::on_sample_count_changed()
 {
-       commit_sample_count();
+       if(!_updating_sample_count)
+               commit_sample_count();
 }
 
 void SamplingBar::on_sample_rate_changed()
index f6a2cdd6c009476384ff6183bd763469d10991bd..cf425775aeb83bbb01bca1413b8c4eb718bb2c22 100644 (file)
@@ -68,6 +68,7 @@ signals:
 private:
        void update_sample_rate_selector();
        void update_sample_rate_selector_value();
+       void update_sample_count_selector();
        void commit_sample_rate();
        void commit_sample_count();
 
@@ -91,6 +92,7 @@ private:
        pv::widgets::SweepTimingWidget _sample_count;
        pv::widgets::SweepTimingWidget _sample_rate;
        bool _updating_sample_rate;
+       bool _updating_sample_count;
 
        QIcon _icon_red;
        QIcon _icon_green;