From: Soeren Apel Date: Sat, 8 Apr 2017 10:51:13 +0000 (+0200) Subject: Shift more methods to DecodeSignal X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ecd07c20d34ce940163ac2e7fb26cb7ceac565bb;p=pulseview.git Shift more methods to DecodeSignal --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index bc453d21..253e3a98 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -24,12 +24,14 @@ #include #include +#include #include #include 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 DecodeSignal::decoder_stack() const return decoder_stack_; } +const list< shared_ptr >& 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 DecodeSignal::visible_rows() const +{ + return decoder_stack_->get_visible_rows(); +} + +void DecodeSignal::get_annotation_subset( + vector &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 diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index 23ab209b..0f3a0330 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -20,15 +20,27 @@ #ifndef PULSEVIEW_PV_DATA_DECODESIGNAL_HPP #define PULSEVIEW_PV_DATA_DECODESIGNAL_HPP +#include + +#include + #include #include +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 decoder_stack() const; + shared_ptr decoder_stack() const; + const list< shared_ptr >& 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 visible_rows() const; + + /** + * Extracts sorted annotations between two period into a vector. + */ + void get_annotation_subset( + vector &dest, + const decode::Row &row, uint64_t start_sample, + uint64_t end_sample) const; + Q_SIGNALS: void new_annotations(); diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index d151a92d..dfc1fe5d 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -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 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 sample_range = get_sample_range( pp.left(), pp.right()); - const vector rows(decoder_stack->get_visible_rows()); + const vector 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 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 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 >& stack = decoder_stack->stack(); + const list< shared_ptr >& stack = + decode_signal_->decoder_stack_list(); if (stack.empty()) { QLabel *const l = new QLabel(