From: Joel Holdsworth Date: Mon, 31 Dec 2012 11:50:18 +0000 (+0000) Subject: Added probes to decoder dialog X-Git-Tag: pulseview-0.2.0~316 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=535554a4d1855b6c15bf20746b3aafd8c53a6ca9;p=pulseview.git Added probes to decoder dialog --- diff --git a/pv/dialogs/decoder.cpp b/pv/dialogs/decoder.cpp index afb5852d..abd25041 100644 --- a/pv/dialogs/decoder.cpp +++ b/pv/dialogs/decoder.cpp @@ -24,12 +24,19 @@ extern "C" { #include "decoder.h" +#include + +using namespace boost; +using namespace std; + namespace pv { namespace dialogs { -Decoder::Decoder(QWidget *parent, const srd_decoder *decoder) : +Decoder::Decoder(QWidget *parent, const srd_decoder *decoder, + const vector< shared_ptr > &sigs) : QDialog(parent), _decoder(decoder), + _sigs(sigs), _layout(this), _form(this), _form_layout(&_form), @@ -37,9 +44,11 @@ Decoder::Decoder(QWidget *parent, const srd_decoder *decoder) : _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this) { + const GSList *probe; + setWindowTitle(tr("Configure %1").arg(decoder->name)); - _heading.setText(tr("

%1

%2") + _heading.setText(tr("

%1

%2") .arg(decoder->longname) .arg(decoder->desc)); @@ -52,6 +61,55 @@ Decoder::Decoder(QWidget *parent, const srd_decoder *decoder) : _layout.addWidget(&_heading); _layout.addWidget(&_form); _layout.addWidget(&_button_box); + + _form_layout.addRow(new QLabel("

Probes

", &_form)); + + // Add the mandatory probes + for(probe = decoder->probes; probe; probe = probe->next) { + const struct srd_probe *const p = + (struct srd_probe *)probe->data; + QComboBox *const combo = create_probe_selector( + &_form, p->name); + _form_layout.addRow(tr("%1 (%2) *") + .arg(p->name).arg(p->desc), combo); + + _probe_selector_map[p] = combo; + } + + // Add the optional probes + for(probe = decoder->opt_probes; probe; probe = probe->next) { + const struct srd_probe *const p = + (struct srd_probe *)probe->data; + QComboBox *const combo = create_probe_selector( + &_form, p->name); + _form_layout.addRow(tr("%1 (%2)") + .arg(p->name).arg(p->desc), combo); + + _probe_selector_map[p] = combo; + } +} + +QComboBox* Decoder::create_probe_selector( + QWidget *parent, const char *name) +{ + QComboBox *selector = new QComboBox(parent); + + selector->addItem("-", qVariantFromValue(-1)); + selector->setCurrentIndex(0); + + for(size_t i = 0; i < _sigs.size(); i++) { + const shared_ptr s(_sigs[i]); + assert(s); + + if (s->enabled()) { + selector->addItem(s->get_name(), qVariantFromValue(i)); + if(s->get_name().toLower().contains( + QString(name).toLower())) + selector->setCurrentIndex(i + 1); + } + } + + return selector; } } // namespace dialogs diff --git a/pv/dialogs/decoder.h b/pv/dialogs/decoder.h index eed33ac0..150d02c5 100644 --- a/pv/dialogs/decoder.h +++ b/pv/dialogs/decoder.h @@ -21,6 +21,11 @@ #ifndef PULSEVIEW_PV_DECODER_H #define PULSEVIEW_PV_DECODER_H +#include +#include + +#include + #include #include #include @@ -31,15 +36,28 @@ struct srd_decoder; namespace pv { + +namespace view { +class Signal; +} + namespace dialogs { class Decoder : public QDialog { public: - Decoder(QWidget *parent, const srd_decoder *decoder); + Decoder(QWidget *parent, const srd_decoder *decoder, + const std::vector< boost::shared_ptr > &sigs); + +private: + QComboBox* create_probe_selector( + QWidget *parent, const char *name); private: const srd_decoder *const _decoder; + const std::vector< boost::shared_ptr > &_sigs; + + std::map _probe_selector_map; QVBoxLayout _layout; diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index eae10674..aa06601c 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -388,7 +388,10 @@ void MainWindow::add_decoder(QObject *action) (srd_decoder*)((QAction*)action)->data().value(); assert(dec); - dialogs::Decoder dlg(this, dec); + const std::vector< boost::shared_ptr > &sigs = + _session.get_signals(); + + dialogs::Decoder dlg(this, dec, sigs); dlg.exec(); }