]> sigrok.org Git - pulseview.git/blame - pv/dialogs/decoder.cpp
Modified Decode to only use LogicSignals
[pulseview.git] / pv / dialogs / decoder.cpp
CommitLineData
c8c28626
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
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
19 */
20
c8c28626 21extern "C" {
df840662 22#include <libsigrokdecode/libsigrokdecode.h>
c8c28626
JH
23}
24
708c5523
JH
25#include <utility>
26
27#include <boost/foreach.hpp>
28
29#include <QDebug>
30
df840662
JH
31#include "decoder.h"
32
708c5523 33#include <pv/view/logicsignal.h>
535554a4
JH
34#include <pv/view/signal.h>
35
36using namespace boost;
37using namespace std;
38
c8c28626
JH
39namespace pv {
40namespace dialogs {
41
535554a4 42Decoder::Decoder(QWidget *parent, const srd_decoder *decoder,
3045c869
JH
43 const vector< shared_ptr<view::LogicSignal> > &sigs,
44 GHashTable *options) :
c8c28626 45 QDialog(parent),
535554a4 46 _sigs(sigs),
67fe5e9c 47 _binding(decoder, options),
c8c28626
JH
48 _layout(this),
49 _form(this),
50 _form_layout(&_form),
df840662 51 _heading(this),
c8c28626
JH
52 _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
53 Qt::Horizontal, this)
54{
535554a4
JH
55 const GSList *probe;
56
df840662
JH
57 setWindowTitle(tr("Configure %1").arg(decoder->name));
58
535554a4 59 _heading.setText(tr("<h2>%1</h2>%2")
df840662
JH
60 .arg(decoder->longname)
61 .arg(decoder->desc));
c8c28626
JH
62
63 connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
64 connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
65
66 _form.setLayout(&_form_layout);
67
68 setLayout(&_layout);
df840662 69 _layout.addWidget(&_heading);
c8c28626
JH
70 _layout.addWidget(&_form);
71 _layout.addWidget(&_button_box);
535554a4 72
de646fae 73 _form_layout.addRow(new QLabel(tr("<h3>Probes</h3>"), &_form));
535554a4
JH
74
75 // Add the mandatory probes
76 for(probe = decoder->probes; probe; probe = probe->next) {
77 const struct srd_probe *const p =
78 (struct srd_probe *)probe->data;
79 QComboBox *const combo = create_probe_selector(
80 &_form, p->name);
81 _form_layout.addRow(tr("<b>%1</b> (%2) *")
82 .arg(p->name).arg(p->desc), combo);
83
84 _probe_selector_map[p] = combo;
85 }
86
87 // Add the optional probes
88 for(probe = decoder->opt_probes; probe; probe = probe->next) {
89 const struct srd_probe *const p =
90 (struct srd_probe *)probe->data;
91 QComboBox *const combo = create_probe_selector(
92 &_form, p->name);
93 _form_layout.addRow(tr("<b>%1</b> (%2)")
94 .arg(p->name).arg(p->desc), combo);
95
96 _probe_selector_map[p] = combo;
97 }
f5a2fb83
JH
98
99 _form_layout.addRow(new QLabel(
100 tr("<i>* Required Probes</i>"), &_form));
67fe5e9c
JH
101
102 // Add the options
103 if (!_binding.properties().empty()) {
104 _form_layout.addRow(new QLabel(tr("<h3>Options</h3>"),
105 &_form));
106 _binding.add_properties_to_form(&_form_layout);
107 }
108}
109
110void Decoder::accept()
111{
112 QDialog::accept();
113 _binding.commit();
535554a4
JH
114}
115
116QComboBox* Decoder::create_probe_selector(
117 QWidget *parent, const char *name)
118{
119 QComboBox *selector = new QComboBox(parent);
120
121 selector->addItem("-", qVariantFromValue(-1));
122 selector->setCurrentIndex(0);
123
124 for(size_t i = 0; i < _sigs.size(); i++) {
3045c869 125 const shared_ptr<view::LogicSignal> s(_sigs[i]);
535554a4
JH
126 assert(s);
127
3045c869
JH
128 if (s->enabled())
129 {
535554a4
JH
130 selector->addItem(s->get_name(), qVariantFromValue(i));
131 if(s->get_name().toLower().contains(
132 QString(name).toLower()))
133 selector->setCurrentIndex(i + 1);
134 }
135 }
136
137 return selector;
c8c28626
JH
138}
139
3045c869 140map<const srd_probe*, shared_ptr<view::LogicSignal> > Decoder::get_probes()
708c5523 141{
3045c869 142 map<const srd_probe*, shared_ptr<view::LogicSignal> > probe_map;
708c5523
JH
143 for(map<const srd_probe*, QComboBox*>::const_iterator i =
144 _probe_selector_map.begin();
145 i != _probe_selector_map.end(); i++)
146 {
147 const QComboBox *const combo = (*i).second;
148 const int probe_index =
149 combo->itemData(combo->currentIndex()).value<int>();
150 if(probe_index >= 0) {
3045c869
JH
151 shared_ptr<view::LogicSignal> sig = _sigs[probe_index];
152 probe_map[(*i).first] = sig;
708c5523
JH
153 }
154 }
155
156 return probe_map;
157}
158
c8c28626
JH
159} // namespace dialogs
160} // namespace pv