2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
22 #include <libsigrokdecode/libsigrokdecode.h>
27 #include <boost/foreach.hpp>
33 #include <pv/view/logicsignal.h>
34 #include <pv/view/signal.h>
36 using namespace boost;
42 Decoder::Decoder(QWidget *parent, const srd_decoder *decoder,
43 const vector< shared_ptr<view::Signal> > &sigs) :
51 _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
56 setWindowTitle(tr("Configure %1").arg(decoder->name));
58 _heading.setText(tr("<h2>%1</h2>%2")
59 .arg(decoder->longname)
62 connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
63 connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
65 _form.setLayout(&_form_layout);
68 _layout.addWidget(&_heading);
69 _layout.addWidget(&_form);
70 _layout.addWidget(&_button_box);
72 _form_layout.addRow(new QLabel("<h3>Probes</h3>", &_form));
74 // Add the mandatory probes
75 for(probe = decoder->probes; probe; probe = probe->next) {
76 const struct srd_probe *const p =
77 (struct srd_probe *)probe->data;
78 QComboBox *const combo = create_probe_selector(
80 _form_layout.addRow(tr("<b>%1</b> (%2) *")
81 .arg(p->name).arg(p->desc), combo);
83 _probe_selector_map[p] = combo;
86 // Add the optional probes
87 for(probe = decoder->opt_probes; probe; probe = probe->next) {
88 const struct srd_probe *const p =
89 (struct srd_probe *)probe->data;
90 QComboBox *const combo = create_probe_selector(
92 _form_layout.addRow(tr("<b>%1</b> (%2)")
93 .arg(p->name).arg(p->desc), combo);
95 _probe_selector_map[p] = combo;
98 _form_layout.addRow(new QLabel(
99 tr("<i>* Required Probes</i>"), &_form));
102 QComboBox* Decoder::create_probe_selector(
103 QWidget *parent, const char *name)
105 QComboBox *selector = new QComboBox(parent);
107 selector->addItem("-", qVariantFromValue(-1));
108 selector->setCurrentIndex(0);
110 for(size_t i = 0; i < _sigs.size(); i++) {
111 const shared_ptr<view::Signal> s(_sigs[i]);
115 selector->addItem(s->get_name(), qVariantFromValue(i));
116 if(s->get_name().toLower().contains(
117 QString(name).toLower()))
118 selector->setCurrentIndex(i + 1);
125 map<const srd_probe*, shared_ptr<view::Signal> > Decoder::get_probes()
127 map<const srd_probe*, shared_ptr<view::Signal> > probe_map;
128 for(map<const srd_probe*, QComboBox*>::const_iterator i =
129 _probe_selector_map.begin();
130 i != _probe_selector_map.end(); i++)
132 const QComboBox *const combo = (*i).second;
133 const int probe_index =
134 combo->itemData(combo->currentIndex()).value<int>();
135 if(probe_index >= 0) {
136 shared_ptr<view::Signal> sig = _sigs[probe_index];
137 if(dynamic_cast<pv::view::LogicSignal*>(sig.get()))
138 probe_map[(*i).first] = sig;
140 qDebug() << "Currently only logic signals "
141 "are supported for decoding";
148 } // namespace dialogs