]> sigrok.org Git - pulseview.git/blob - pv/data/decodesignal.cpp
bc453d21b0fcc55608c81e0acf70970278d179cd
[pulseview.git] / pv / data / decodesignal.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
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, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "logic.hpp"
21 #include "logicsegment.hpp"
22 #include "decodesignal.hpp"
23 #include "signaldata.hpp"
24
25 #include <pv/binding/decoder.hpp>
26 #include <pv/data/decode/decoder.hpp>
27 #include <pv/data/decoderstack.hpp>
28 #include <pv/session.hpp>
29
30 using std::make_shared;
31 using std::shared_ptr;
32 using pv::data::decode::Decoder;
33
34 namespace pv {
35 namespace data {
36
37 DecodeSignal::DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack) :
38         SignalBase(nullptr, SignalBase::DecodeChannel),
39         decoder_stack_(decoder_stack)
40 {
41         set_name(QString::fromUtf8(decoder_stack_->stack().front()->decoder()->name));
42
43         connect(decoder_stack_.get(), SIGNAL(new_annotations()),
44                 this, SLOT(on_new_annotations()));
45 }
46
47 DecodeSignal::~DecodeSignal()
48 {
49 }
50
51 bool DecodeSignal::is_decode_signal() const
52 {
53         return true;
54 }
55
56 shared_ptr<pv::data::DecoderStack> DecodeSignal::decoder_stack() const
57 {
58         return decoder_stack_;
59 }
60
61 void DecodeSignal::stack_decoder(srd_decoder *decoder)
62 {
63         assert(decoder);
64         assert(decoder_stack);
65         decoder_stack_->push(make_shared<data::decode::Decoder>(decoder));
66         decoder_stack_->begin_decode();
67 }
68
69 void DecodeSignal::remove_decoder(int index)
70 {
71         decoder_stack_->remove(index);
72         decoder_stack_->begin_decode();
73 }
74
75 bool DecodeSignal::toggle_decoder_visibility(int index)
76 {
77         const list< shared_ptr<Decoder> > stack(decoder_stack_->stack());
78
79         auto iter = stack.cbegin();
80         for (int i = 0; i < index; i++, iter++)
81                 assert(iter != stack.end());
82
83         shared_ptr<Decoder> dec = *iter;
84
85         // Toggle decoder visibility
86         bool state = false;
87         if (dec) {
88                 state = !dec->shown();
89                 dec->show(state);
90         }
91
92         return state;
93 }
94
95 void DecodeSignal::on_new_annotations()
96 {
97         // Forward the signal to the frontend
98         new_annotations();
99 }
100
101 } // namespace data
102 } // namespace pv