]> sigrok.org Git - pulseview.git/commitdiff
Shift more methods to DecodeSignal
authorSoeren Apel <redacted>
Sat, 8 Apr 2017 10:51:13 +0000 (12:51 +0200)
committerSoeren Apel <redacted>
Tue, 4 Jul 2017 21:14:36 +0000 (23:14 +0200)
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/views/trace/decodetrace.cpp

index bc453d21b0fcc55608c81e0acf70970278d179cd..253e3a987c6dbeb59e1f6344deff7d76c5aa4692 100644 (file)
 
 #include <pv/binding/decoder.hpp>
 #include <pv/data/decode/decoder.hpp>
+#include <pv/data/decode/row.hpp>
 #include <pv/data/decoderstack.hpp>
 #include <pv/session.hpp>
 
 using std::make_shared;
 using std::shared_ptr;
 using pv::data::decode::Decoder;
+using pv::data::decode::Row;
 
 namespace pv {
 namespace data {
@@ -58,6 +60,11 @@ shared_ptr<pv::data::DecoderStack> DecodeSignal::decoder_stack() const
        return decoder_stack_;
 }
 
+const list< shared_ptr<Decoder> >& DecodeSignal::decoder_stack_list() const
+{
+       return decoder_stack_->stack();
+}
+
 void DecodeSignal::stack_decoder(srd_decoder *decoder)
 {
        assert(decoder);
@@ -92,6 +99,25 @@ bool DecodeSignal::toggle_decoder_visibility(int index)
        return state;
 }
 
+QString DecodeSignal::error_message() const
+{
+       return decoder_stack_->error_message();
+}
+
+vector<Row> DecodeSignal::visible_rows() const
+{
+       return decoder_stack_->get_visible_rows();
+}
+
+void DecodeSignal::get_annotation_subset(
+       vector<pv::data::decode::Annotation> &dest,
+       const decode::Row &row, uint64_t start_sample,
+       uint64_t end_sample) const
+{
+       return decoder_stack_->get_annotation_subset(dest, row,
+               start_sample, end_sample);
+}
+
 void DecodeSignal::on_new_annotations()
 {
        // Forward the signal to the frontend
index 23ab209b73a2faa784806fe5d24b68abd6683e96..0f3a0330e3ad9029ad742d796294452d091f91ef 100644 (file)
 #ifndef PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
 #define PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
 
+#include <vector>
+
+#include <QString>
+
 #include <libsigrokdecode/libsigrokdecode.h>
 
 #include <pv/data/signalbase.hpp>
 
+using std::list;
+using std::vector;
 using std::shared_ptr;
 
 namespace pv {
 namespace data {
 
+namespace decode {
+class Annotation;
+class Decoder;
+class Row;
+}
+
 class DecoderStack;
 class Logic;
 class SignalData;
@@ -42,12 +54,25 @@ public:
        virtual ~DecodeSignal();
 
        bool is_decode_signal() const;
-       shared_ptr<pv::data::DecoderStack> decoder_stack() const;
+       shared_ptr<data::DecoderStack> decoder_stack() const;
+       const list< shared_ptr<data::decode::Decoder> >& decoder_stack_list() const;
 
        void stack_decoder(srd_decoder *decoder);
        void remove_decoder(int index);
        bool toggle_decoder_visibility(int index);
 
+       QString error_message() const;
+
+       vector<decode::Row> visible_rows() const;
+
+       /**
+        * Extracts sorted annotations between two period into a vector.
+        */
+       void get_annotation_subset(
+               vector<pv::data::decode::Annotation> &dest,
+               const decode::Row &row, uint64_t start_sample,
+               uint64_t end_sample) const;
+
 Q_SIGNALS:
        void new_annotations();
 
index d151a92dad5fee2def16d1b7f582204c25b92f33..dfc1fe5d321a93d3430cf62529892ea11c36900e 100644 (file)
@@ -69,6 +69,9 @@ using std::tie;
 using std::unordered_set;
 using std::vector;
 
+using pv::data::decode::Annotation;
+using pv::data::decode::Row;
+
 namespace pv {
 namespace views {
 namespace trace {
@@ -179,16 +182,11 @@ void DecodeTrace::paint_back(QPainter &p, ViewItemPaintParams &pp)
 
 void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
 {
-       using namespace pv::data::decode;
-
-       shared_ptr<pv::data::DecoderStack> decoder_stack = base_->decoder_stack();
-
        const int text_height = ViewItemPaintParams::text_height();
        row_height_ = (text_height * 6) / 4;
        const int annotation_height = (text_height * 5) / 4;
 
-       assert(decoder_stack);
-       const QString err = decoder_stack->error_message();
+       const QString err = decode_signal_->error_message();
        if (!err.isEmpty()) {
                draw_unresolved_period(
                        p, annotation_height, pp.left(), pp.right());
@@ -204,7 +202,7 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
        pair<uint64_t, uint64_t> sample_range = get_sample_range(
                pp.left(), pp.right());
 
-       const vector<Row> rows(decoder_stack->get_visible_rows());
+       const vector<Row> rows = decode_signal_->visible_rows();
 
        visible_rows_.clear();
        for (const Row& row : rows) {
@@ -227,7 +225,7 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
                base_colour >>= 16;
 
                vector<Annotation> annotations;
-               decoder_stack->get_annotation_subset(annotations, row,
+               decode_signal_->get_annotation_subset(annotations, row,
                        sample_range.first, sample_range.second);
                if (!annotations.empty()) {
                        draw_annotations(annotations, p, annotation_height, pp, y,
@@ -251,8 +249,6 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
 
 void DecodeTrace::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
-       using namespace pv::data::decode;
-
        assert(row_height_);
 
        for (size_t i = 0; i < visible_rows_.size(); i++) {
@@ -293,11 +289,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
 {
        using pv::data::decode::Decoder;
 
-       shared_ptr<pv::data::DecoderStack> decoder_stack = base_->decoder_stack();
-
        assert(form);
-       assert(parent);
-       assert(decoder_stack);
 
        // Add the standard options
        Trace::populate_popup_form(parent, form);
@@ -307,7 +299,8 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
        channel_selectors_.clear();
        decoder_forms_.clear();
 
-       const list< shared_ptr<Decoder> >& stack = decoder_stack->stack();
+       const list< shared_ptr<Decoder> >& stack =
+               decode_signal_->decoder_stack_list();
 
        if (stack.empty()) {
                QLabel *const l = new QLabel(