_configure_button_action(NULL),
_probes_button(this),
_record_length_selector(this),
- _sample_rate_action(NULL),
- _sample_rate_list(this),
+ _sample_rate("Hz", this),
+ _updating_sample_rate(false),
_icon_red(":/icons/status-red.svg"),
_icon_green(":/icons/status-green.svg"),
_icon_grey(":/icons/status-grey.svg"),
this, SLOT(on_run_stop()));
connect(&_device_selector, SIGNAL(currentIndexChanged (int)),
this, SLOT(on_device_selected()));
-
- _sample_rate_value.setDecimals(0);
- _sample_rate_value.setSuffix("Hz");
+ connect(&_sample_rate, SIGNAL(value_changed()),
+ this, SLOT(on_sample_rate_changed()));
for (size_t i = 0; i < countof(RecordLengths); i++)
{
_configure_button_action = addWidget(&_configure_button);
addWidget(&_probes_button);
addWidget(&_record_length_selector);
- _sample_rate_list_action = addWidget(&_sample_rate_list);
- _sample_rate_value_action = addWidget(&_sample_rate_value);
- addWidget(&_run_stop_button);
+ addWidget(&_sample_rate);
- connect(&_sample_rate_list, SIGNAL(currentIndexChanged(int)),
- this, SLOT(on_sample_rate_changed()));
- connect(&_sample_rate_value, SIGNAL(editingFinished()),
- this, SLOT(on_sample_rate_changed()));
+ addWidget(&_run_stop_button);
}
void SamplingBar::set_device_list(
const uint64_t *elements = NULL;
gsize num_elements;
- assert(_sample_rate_value_action);
- assert(_sample_rate_list_action);
-
if (!sdi)
return;
+ _updating_sample_rate = true;
+
if (sr_config_list(sdi->driver, sdi, NULL,
SR_CONF_SAMPLERATE, &gvar_dict) != SR_OK)
+ {
+ _sample_rate.show_none();
+ _updating_sample_rate = false;
return;
-
- _sample_rate_list_action->setVisible(false);
- _sample_rate_value_action->setVisible(false);
+ }
if ((gvar_list = g_variant_lookup_value(gvar_dict,
- "samplerate-steps", G_VARIANT_TYPE("at")))) {
+ "samplerate-steps", G_VARIANT_TYPE("at"))))
+ {
elements = (const uint64_t *)g_variant_get_fixed_array(
gvar_list, &num_elements, sizeof(uint64_t));
- _sample_rate_value.setRange(elements[0], elements[1]);
- _sample_rate_value.setSingleStep(elements[2]);
+ _sample_rate.show_min_max_step(elements[0], elements[1],
+ elements[2]);
g_variant_unref(gvar_list);
-
- _sample_rate_action = _sample_rate_value_action;
}
else if ((gvar_list = g_variant_lookup_value(gvar_dict,
"samplerates", G_VARIANT_TYPE("at"))))
{
elements = (const uint64_t *)g_variant_get_fixed_array(
gvar_list, &num_elements, sizeof(uint64_t));
- _sample_rate_list.clear();
-
- for (unsigned int i = 0; i < num_elements; i++)
- {
- char *const s = sr_samplerate_string(elements[i]);
- _sample_rate_list.addItem(QString::fromUtf8(s),
- qVariantFromValue(elements[i]));
- g_free(s);
- }
-
- _sample_rate_list.show();
+ _sample_rate.show_list(elements, num_elements);
g_variant_unref(gvar_list);
-
- _sample_rate_action = _sample_rate_list_action;
}
+ _updating_sample_rate = false;
g_variant_unref(gvar_dict);
update_sample_rate_selector_value();
-
- // We delay showing the action, so that value change events
- // are ignored.
- if (_sample_rate_action)
- _sample_rate_action->setVisible(true);
}
void SamplingBar::update_sample_rate_selector_value()
samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
- assert(_sample_rate_value_action);
- assert(_sample_rate_list_action);
-
- if (_sample_rate_action == _sample_rate_value_action)
- _sample_rate_value.setValue(samplerate);
- else if (_sample_rate_action == _sample_rate_list_action)
- {
- for (int i = 0; i < _sample_rate_list.count(); i++)
- if (samplerate == _sample_rate_list.itemData(
- i).value<uint64_t>())
- _sample_rate_list.setCurrentIndex(i);
- }
+ _updating_sample_rate = true;
+ _sample_rate.set_value(samplerate);
+ _updating_sample_rate = false;
}
void SamplingBar::commit_sample_rate()
sr_dev_inst *const sdi = get_selected_device();
assert(sdi);
- assert(_sample_rate_value_action);
- assert(_sample_rate_list_action);
-
- if (_sample_rate_action == _sample_rate_value_action)
- sample_rate = (uint64_t)_sample_rate_value.value();
- else if (_sample_rate_action == _sample_rate_list_action)
- {
- const int index = _sample_rate_list.currentIndex();
- if (index >= 0)
- sample_rate = _sample_rate_list.itemData(
- index).value<uint64_t>();
- }
-
+ sample_rate = _sample_rate.value();
if (sample_rate == 0)
return;
void SamplingBar::on_sample_rate_changed()
{
- commit_sample_rate();
+ if (!_updating_sample_rate)
+ commit_sample_rate();
}
void SamplingBar::on_run_stop()
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "sweeptimingwidget.h"
+
+#include <assert.h>
+
+namespace pv {
+namespace widgets {
+
+SweepTimingWidget::SweepTimingWidget(const char *suffix,
+ QWidget *parent) :
+ QWidget(parent),
+ _layout(this),
+ _read_only_value(this),
+ _value(this),
+ _list(this),
+ _value_type(None)
+{
+ setContentsMargins(0, 0, 0, 0);
+
+ _value.setDecimals(0);
+ _value.setSuffix(QString::fromUtf8(suffix));
+
+ connect(&_list, SIGNAL(currentIndexChanged(int)),
+ this, SIGNAL(value_changed()));
+ connect(&_value, SIGNAL(editingFinished()),
+ this, SIGNAL(value_changed()));
+
+ setLayout(&_layout);
+ _layout.setMargin(0);
+ _layout.addWidget(&_read_only_value);
+ _layout.addWidget(&_list);
+ _layout.addWidget(&_value);
+
+ show_none();
+}
+
+void SweepTimingWidget::show_none()
+{
+ _value_type = None;
+ _read_only_value.hide();
+ _value.hide();
+ _list.hide();
+}
+
+void SweepTimingWidget::show_read_only()
+{
+ _value_type = ReadOnly;
+ _read_only_value.show();
+ _value.hide();
+ _list.hide();
+}
+
+void SweepTimingWidget::show_min_max_step(uint64_t min, uint64_t max,
+ uint64_t step)
+{
+ _value_type = MinMaxStep;
+
+ _value.setRange(min, max);
+ _value.setSingleStep(step);
+
+ _read_only_value.hide();
+ _value.show();
+ _list.hide();
+}
+
+void SweepTimingWidget::show_list(const uint64_t *vals, size_t count)
+{
+ _value_type = List;
+
+ _list.clear();
+ for (size_t i = 0; i < count; i++)
+ {
+ char *const s = sr_samplerate_string(vals[i]);
+ _list.addItem(QString::fromUtf8(s),
+ qVariantFromValue(vals[i]));
+ g_free(s);
+ }
+
+ _read_only_value.hide();
+ _value.hide();
+ _list.show();
+}
+
+uint64_t SweepTimingWidget::value() const
+{
+ switch(_value_type)
+ {
+ case None:
+ case ReadOnly:
+ return 0;
+
+ case MinMaxStep:
+ return (uint64_t)_value.value();
+
+ case List:
+ {
+ const int index = _list.currentIndex();
+ return (index >= 0) ? _list.itemData(
+ index).value<uint64_t>() : 0;
+ }
+
+ default:
+ // Unexpected value type
+ assert(0);
+ return 0;
+ }
+}
+
+void SweepTimingWidget::set_value(uint64_t value)
+{
+ _read_only_value.setText(QString("%1").arg(value));
+
+ _value.setValue(value);
+
+ for (int i = 0; i < _list.count(); i++)
+ if (value == _list.itemData(i).value<uint64_t>())
+ _list.setCurrentIndex(i);
+}
+
+} // widgets
+} // pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_WIDGETS_SWEEPTIMINGWIDGET_H
+#define PULSEVIEW_PV_WIDGETS_SWEEPTIMINGWIDGET_H
+
+#include <libsigrok/libsigrok.h>
+
+#include <QComboBox>
+#include <QDoubleSpinBox>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QWidget>
+
+namespace pv {
+namespace widgets {
+
+class SweepTimingWidget : public QWidget
+{
+ Q_OBJECT
+
+private:
+ enum ValueType
+ {
+ None,
+ ReadOnly,
+ MinMaxStep,
+ List
+ };
+
+public:
+ SweepTimingWidget(const char *suffix, QWidget *parent = NULL);
+
+ void show_none();
+ void show_read_only();
+ void show_min_max_step(uint64_t min, uint64_t max, uint64_t step);
+ void show_list(const uint64_t *vals, size_t count);
+
+ uint64_t value() const;
+ void set_value(uint64_t value);
+
+signals:
+ void value_changed();
+
+private:
+ QHBoxLayout _layout;
+
+ QLineEdit _read_only_value;
+ QDoubleSpinBox _value;
+ QComboBox _list;
+
+ ValueType _value_type;
+};
+
+} // widgets
+} // pv
+
+#endif // PULSEVIEW_PV_WIDGETS_SWEEPTIMINGWIDGET_H