]> sigrok.org Git - pulseview.git/commitdiff
Added probes to decoder dialog
authorJoel Holdsworth <redacted>
Mon, 31 Dec 2012 11:50:18 +0000 (11:50 +0000)
committerJoel Holdsworth <redacted>
Sun, 29 Sep 2013 01:34:42 +0000 (10:34 +0900)
pv/dialogs/decoder.cpp
pv/dialogs/decoder.h
pv/mainwindow.cpp

index afb5852db729cf2b184b590cd6e48d42f7e9dc9e..abd25041e795aa8c1ca1f534cd23792018a233f3 100644 (file)
@@ -24,12 +24,19 @@ extern "C" {
 
 #include "decoder.h"
 
+#include <pv/view/signal.h>
+
+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<view::Signal> > &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("<h3>%1</h3>%2")
+       _heading.setText(tr("<h2>%1</h2>%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("<h3>Probes</h3>", &_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("<b>%1</b> (%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("<b>%1</b> (%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<view::Signal> 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
index eed33ac0f2dbdd9a67d73c36fa1519e16675776f..150d02c5cf8d4305fbd15e217cbb9cd17cbe480c 100644 (file)
 #ifndef PULSEVIEW_PV_DECODER_H
 #define PULSEVIEW_PV_DECODER_H
 
+#include <vector>
+#include <map>
+
+#include <boost/shared_ptr.hpp>
+
 #include <QComboBox>
 #include <QDialog>
 #include <QDialogButtonBox>
 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<view::Signal> > &sigs);
+
+private:
+       QComboBox* create_probe_selector(
+               QWidget *parent, const char *name);
 
 private:
        const srd_decoder *const _decoder;
+       const std::vector< boost::shared_ptr<view::Signal> > &_sigs;
+
+       std::map<const srd_probe*, QComboBox*> _probe_selector_map;
 
        QVBoxLayout _layout;
 
index eae106746b76b6313182ecdf9f7bdf7661b72fb5..aa06601c3824a6c74eab2ad74b33e3a3155040aa 100644 (file)
@@ -388,7 +388,10 @@ void MainWindow::add_decoder(QObject *action)
                (srd_decoder*)((QAction*)action)->data().value<void*>();
        assert(dec);
 
-       dialogs::Decoder dlg(this, dec);
+       const std::vector< boost::shared_ptr<view::Signal> > &sigs =
+               _session.get_signals();
+
+       dialogs::Decoder dlg(this, dec, sigs);
        dlg.exec();
 }