X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fwidgets%2Fsweeptimingwidget.cpp;fp=pv%2Fwidgets%2Fsweeptimingwidget.cpp;h=b1164891419898bd588c511edc3ab45e58edf70f;hp=0000000000000000000000000000000000000000;hb=1198b8872516662c257e5dcdec346094ed4f32dd;hpb=bb2cdfffd5817feb7a6dcde19b6110a6c253a261 diff --git a/pv/widgets/sweeptimingwidget.cpp b/pv/widgets/sweeptimingwidget.cpp new file mode 100644 index 0000000..b116489 --- /dev/null +++ b/pv/widgets/sweeptimingwidget.cpp @@ -0,0 +1,140 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * 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 + +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() : 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()) + _list.setCurrentIndex(i); +} + +} // widgets +} // pv