]> sigrok.org Git - pulseview.git/commitdiff
Accept user-entered sample rates when external clock is enabled
authorSoeren Apel <redacted>
Thu, 12 Jul 2018 17:32:33 +0000 (19:32 +0200)
committerUwe Hermann <redacted>
Sat, 21 Jul 2018 16:57:21 +0000 (18:57 +0200)
pv/toolbars/mainbar.cpp
pv/views/trace/analogsignal.cpp
pv/widgets/sweeptimingwidget.cpp
pv/widgets/sweeptimingwidget.hpp

index 3c8b71e2f7b59a8162fcf39f23135c2d819cd46b..16888624bc2f124030005fc481ae6838f5adbba5 100644 (file)
@@ -302,6 +302,17 @@ void MainBar::update_sample_rate_selector()
 
        const shared_ptr<sigrok::Device> sr_dev = device->device();
 
+       try {
+               auto gvar = sr_dev->config_get(ConfigKey::EXTERNAL_CLOCK);
+               if (gvar.gobj()) {
+                       bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
+                               gvar).get();
+                       sample_rate_.allow_user_entered_values(value);
+               }
+       } catch (Error& error) {
+               // Do nothing
+       }
+
        if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
                try {
                        gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
@@ -729,6 +740,10 @@ void MainBar::on_sample_rate_changed()
 
 void MainBar::on_config_changed()
 {
+       // We want to also call update_sample_rate_selector() here in case
+       // the user changed the SR_CONF_EXTERNAL_CLOCK option. However,
+       // commit_sample_rate() does this already, so we don't call it here
+
        commit_sample_count();
        commit_sample_rate();
 }
index 1c0f0efa778ec5979ac199f92a4eb2823cfb9625..d8dbf6f1a08222fe71c1ed047316e3644d05dfd1 100644 (file)
@@ -1000,7 +1000,7 @@ void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
 
     connect(conv_threshold_cb_, SIGNAL(currentIndexChanged(int)),
             this, SLOT(on_conv_threshold_changed(int)));
-    connect(conv_threshold_cb_, SIGNAL(editTextChanged(const QString)),
+    connect(conv_threshold_cb_, SIGNAL(editTextChanged(const QString&)),
             this, SLOT(on_conv_threshold_changed()));  // index will be -1
 
        // Add the display type dropdown
index b4943225dd8d44ddae54fad59b7231e70a8c6e3f..12f5969eb707c9997c212e1d39f838541c1f5588 100644 (file)
@@ -47,6 +47,9 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix,
 
        connect(&list_, SIGNAL(currentIndexChanged(int)),
                this, SIGNAL(value_changed()));
+       connect(&list_, SIGNAL(editTextChanged(const QString&)),
+               this, SIGNAL(value_changed()));
+
        connect(&value_, SIGNAL(editingFinished()),
                this, SIGNAL(value_changed()));
 
@@ -58,6 +61,11 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix,
        show_none();
 }
 
+void SweepTimingWidget::allow_user_entered_values(bool value)
+{
+       list_.setEditable(value);
+}
+
 void SweepTimingWidget::show_none()
 {
        value_type_ = None;
@@ -144,9 +152,14 @@ uint64_t SweepTimingWidget::value() const
                return (uint64_t)value_.value();
        case List:
        {
+               if (list_.isEditable()) {
+                       uint64_t value;
+                       sr_parse_sizestring(list_.currentText().toUtf8().data(), &value);
+                       return value;
+               }
+
                const int index = list_.currentIndex();
-               return (index >= 0) ? list_.itemData(
-                       index).value<uint64_t>() : 0;
+               return (index >= 0) ? list_.itemData(index).value<uint64_t>() : 0;
        }
        default:
                // Unexpected value type
@@ -159,19 +172,25 @@ void SweepTimingWidget::set_value(uint64_t value)
 {
        value_.setValue(value);
 
-       int best_match = list_.count() - 1;
-       int64_t best_variance = INT64_MAX;
-
-       for (int i = 0; i < list_.count(); i++) {
-               const int64_t this_variance = abs(
-                       (int64_t)value - list_.itemData(i).value<int64_t>());
-               if (this_variance < best_variance) {
-                       best_variance = this_variance;
-                       best_match = i;
+       if (list_.isEditable()) {
+               char *const s = sr_si_string_u64(value, suffix_);
+               list_.lineEdit()->setText(QString::fromUtf8(s));
+               g_free(s);
+       } else {
+               int best_match = list_.count() - 1;
+               int64_t best_variance = INT64_MAX;
+
+               for (int i = 0; i < list_.count(); i++) {
+                       const int64_t this_variance = abs(
+                               (int64_t)value - list_.itemData(i).value<int64_t>());
+                       if (this_variance < best_variance) {
+                               best_variance = this_variance;
+                               best_match = i;
+                       }
                }
-       }
 
-       list_.setCurrentIndex(best_match);
+               list_.setCurrentIndex(best_match);
+       }
 }
 
 }  // namespace widgets
index 0b61bf4a64c9ef03815b37c12b9e05e58cc9e251..46d12d8e1e47c79687e4c8796bce51c762bf6ccc 100644 (file)
@@ -46,6 +46,8 @@ private:
 public:
        SweepTimingWidget(const char *suffix, QWidget *parent = nullptr);
 
+       void allow_user_entered_values(bool value);
+
        void show_none();
        void show_min_max_step(uint64_t min, uint64_t max, uint64_t step);
        void show_list(const uint64_t *vals, size_t count);