X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fwidgets%2Fsweeptimingwidget.cpp;h=9bb75c869a8f780c52e3e6590e2a54ebad94931e;hb=67d163940f97cd03137ddee93dd5aa115d0f4a5c;hp=b1164891419898bd588c511edc3ab45e58edf70f;hpb=1198b8872516662c257e5dcdec346094ed4f32dd;p=pulseview.git diff --git a/pv/widgets/sweeptimingwidget.cpp b/pv/widgets/sweeptimingwidget.cpp index b116489..9bb75c8 100644 --- a/pv/widgets/sweeptimingwidget.cpp +++ b/pv/widgets/sweeptimingwidget.cpp @@ -20,8 +20,14 @@ #include "sweeptimingwidget.h" +#include + #include +#include + +using std::vector; + namespace pv { namespace widgets { @@ -29,7 +35,6 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix, QWidget *parent) : QWidget(parent), _layout(this), - _read_only_value(this), _value(this), _list(this), _value_type(None) @@ -46,7 +51,6 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix, setLayout(&_layout); _layout.setMargin(0); - _layout.addWidget(&_read_only_value); _layout.addWidget(&_list); _layout.addWidget(&_value); @@ -56,15 +60,6 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix, 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(); } @@ -72,12 +67,14 @@ void SweepTimingWidget::show_read_only() void SweepTimingWidget::show_min_max_step(uint64_t min, uint64_t max, uint64_t step) { + assert(max > min); + assert(step > 0); + _value_type = MinMaxStep; _value.setRange(min, max); _value.setSingleStep(step); - _read_only_value.hide(); _value.show(); _list.hide(); } @@ -95,17 +92,55 @@ void SweepTimingWidget::show_list(const uint64_t *vals, size_t count) g_free(s); } - _read_only_value.hide(); _value.hide(); _list.show(); } +void SweepTimingWidget::show_125_list(uint64_t min, uint64_t max) +{ + assert(max > min); + + // Create a 1-2-5-10 list of entries. + const unsigned int FineScales[] = {1, 2, 5}; + uint64_t value, decade; + unsigned int fine; + vector values; + + // Compute the starting decade + for (decade = 1; decade * 10 <= min; decade *= 10); + + // Compute the first entry + for (fine = 0; fine < countof(FineScales); fine++) + if (FineScales[fine] * decade >= min) + break; + + assert(fine < countof(FineScales)); + + // Add the minimum entry if it's not on the 1-2-5 progression + if (min != FineScales[fine] * decade) + values.push_back(min); + + while ((value = FineScales[fine] * decade) < max) { + values.push_back(value); + if (++fine >= countof(FineScales)) + fine = 0, decade *= 10; + } + + // Add the max value + values.push_back(max); + + // Make a C array, and give it to the sweep timing widget + uint64_t *const values_array = new uint64_t[values.size()]; + copy(values.begin(), values.end(), values_array); + show_list(values_array, values.size()); + delete[] values_array; +} + uint64_t SweepTimingWidget::value() const { switch(_value_type) { case None: - case ReadOnly: return 0; case MinMaxStep: @@ -127,8 +162,6 @@ uint64_t SweepTimingWidget::value() const 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++)