- selector_ = new QComboBox(parent);
- for (unsigned int i = 0; i < values_.size(); i++) {
- const pair<Glib::VariantBase, QString> &v = values_[i];
- selector_->addItem(v.second, qVariantFromValue(v.first));
- if (v.first.equal(variant))
- selector_->setCurrentIndex(i);
+ if (is_range_) {
+ // Use slider
+ if (slider_layout_widget_)
+ return slider_layout_widget_;
+
+ slider_ = new QSlider();
+ // Sliders can't handle float values, so we just use it to specify
+ // the number of steps that we're away from the range's beginning
+ slider_->setOrientation(Qt::Horizontal);
+ slider_->setMinimum(0);
+ slider_->setMaximum(values_.size() - 1);
+ slider_->setSingleStep(1);
+
+ slider_label_ = new QLabel();
+
+ slider_layout_widget_ = new QWidget(parent);
+ QHBoxLayout *layout = new QHBoxLayout(slider_layout_widget_);
+ layout->addWidget(slider_);
+ layout->addWidget(slider_label_);
+
+ update_widget();
+
+ if (auto_commit)
+ connect(slider_, SIGNAL(valueChanged(int)),
+ this, SLOT(on_value_changed(int)));
+
+ return slider_layout_widget_;
+
+ } else {
+ // Use combo box
+ if (selector_)
+ return selector_;
+
+ selector_ = new QComboBox(parent);
+ for (unsigned int i = 0; i < values_.size(); i++) {
+ const pair<Glib::VariantBase, QString> &v = values_[i];
+ selector_->addItem(v.second, qVariantFromValue(v.first));
+ }
+
+ update_widget();
+
+ if (auto_commit)
+ connect(selector_, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(on_current_index_changed(int)));
+
+ return selector_;
+ }
+}
+
+void Enum::update_widget()
+{
+ Glib::VariantBase variant;
+
+ try {
+ variant = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;