]> sigrok.org Git - pulseview.git/blame - pv/widgets/sweeptimingwidget.cpp
SweepTimingWidget removed Read Only support
[pulseview.git] / pv / widgets / sweeptimingwidget.cpp
CommitLineData
1198b887
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "sweeptimingwidget.h"
22
23#include <assert.h>
24
25namespace pv {
26namespace widgets {
27
28SweepTimingWidget::SweepTimingWidget(const char *suffix,
29 QWidget *parent) :
30 QWidget(parent),
31 _layout(this),
1198b887
JH
32 _value(this),
33 _list(this),
34 _value_type(None)
35{
36 setContentsMargins(0, 0, 0, 0);
37
38 _value.setDecimals(0);
39 _value.setSuffix(QString::fromUtf8(suffix));
40
41 connect(&_list, SIGNAL(currentIndexChanged(int)),
42 this, SIGNAL(value_changed()));
43 connect(&_value, SIGNAL(editingFinished()),
44 this, SIGNAL(value_changed()));
45
46 setLayout(&_layout);
47 _layout.setMargin(0);
1198b887
JH
48 _layout.addWidget(&_list);
49 _layout.addWidget(&_value);
50
51 show_none();
52}
53
54void SweepTimingWidget::show_none()
55{
56 _value_type = None;
1198b887
JH
57 _value.hide();
58 _list.hide();
59}
60
61void SweepTimingWidget::show_min_max_step(uint64_t min, uint64_t max,
62 uint64_t step)
63{
64 _value_type = MinMaxStep;
65
66 _value.setRange(min, max);
67 _value.setSingleStep(step);
68
1198b887
JH
69 _value.show();
70 _list.hide();
71}
72
73void SweepTimingWidget::show_list(const uint64_t *vals, size_t count)
74{
75 _value_type = List;
76
77 _list.clear();
78 for (size_t i = 0; i < count; i++)
79 {
80 char *const s = sr_samplerate_string(vals[i]);
81 _list.addItem(QString::fromUtf8(s),
82 qVariantFromValue(vals[i]));
83 g_free(s);
84 }
85
1198b887
JH
86 _value.hide();
87 _list.show();
88}
89
90uint64_t SweepTimingWidget::value() const
91{
92 switch(_value_type)
93 {
94 case None:
1198b887
JH
95 return 0;
96
97 case MinMaxStep:
98 return (uint64_t)_value.value();
99
100 case List:
101 {
102 const int index = _list.currentIndex();
103 return (index >= 0) ? _list.itemData(
104 index).value<uint64_t>() : 0;
105 }
106
107 default:
108 // Unexpected value type
109 assert(0);
110 return 0;
111 }
112}
113
114void SweepTimingWidget::set_value(uint64_t value)
115{
1198b887
JH
116 _value.setValue(value);
117
118 for (int i = 0; i < _list.count(); i++)
119 if (value == _list.itemData(i).value<uint64_t>())
120 _list.setCurrentIndex(i);
121}
122
123} // widgets
124} // pv