2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "sweeptimingwidget.h"
28 SweepTimingWidget::SweepTimingWidget(const char *suffix,
32 _read_only_value(this),
37 setContentsMargins(0, 0, 0, 0);
39 _value.setDecimals(0);
40 _value.setSuffix(QString::fromUtf8(suffix));
42 connect(&_list, SIGNAL(currentIndexChanged(int)),
43 this, SIGNAL(value_changed()));
44 connect(&_value, SIGNAL(editingFinished()),
45 this, SIGNAL(value_changed()));
49 _layout.addWidget(&_read_only_value);
50 _layout.addWidget(&_list);
51 _layout.addWidget(&_value);
56 void SweepTimingWidget::show_none()
59 _read_only_value.hide();
64 void SweepTimingWidget::show_read_only()
66 _value_type = ReadOnly;
67 _read_only_value.show();
72 void SweepTimingWidget::show_min_max_step(uint64_t min, uint64_t max,
75 _value_type = MinMaxStep;
77 _value.setRange(min, max);
78 _value.setSingleStep(step);
80 _read_only_value.hide();
85 void SweepTimingWidget::show_list(const uint64_t *vals, size_t count)
90 for (size_t i = 0; i < count; i++)
92 char *const s = sr_samplerate_string(vals[i]);
93 _list.addItem(QString::fromUtf8(s),
94 qVariantFromValue(vals[i]));
98 _read_only_value.hide();
103 uint64_t SweepTimingWidget::value() const
112 return (uint64_t)_value.value();
116 const int index = _list.currentIndex();
117 return (index >= 0) ? _list.itemData(
118 index).value<uint64_t>() : 0;
122 // Unexpected value type
128 void SweepTimingWidget::set_value(uint64_t value)
130 _read_only_value.setText(QString("%1").arg(value));
132 _value.setValue(value);
134 for (int i = 0; i < _list.count(); i++)
135 if (value == _list.itemData(i).value<uint64_t>())
136 _list.setCurrentIndex(i);