]> sigrok.org Git - pulseview.git/commitdiff
Move view-independent data from view::DecodeTrace to SignalBase
authorSoeren Apel <redacted>
Tue, 16 Aug 2016 19:32:56 +0000 (21:32 +0200)
committerUwe Hermann <redacted>
Thu, 18 Aug 2016 22:36:03 +0000 (00:36 +0200)
pv/data/signalbase.cpp
pv/data/signalbase.hpp
pv/session.cpp
pv/session.hpp
pv/view/decodetrace.cpp
pv/view/decodetrace.hpp
pv/view/view.cpp
pv/view/view.hpp

index 62881528a0c37faa47aba0f97a1ff242f95dcce4..3adf3338dc4d7cd4f6f41988bf667fab90ad1af3 100644 (file)
@@ -23,6 +23,9 @@
 #include "logic.hpp"
 #include "signalbase.hpp"
 #include "signaldata.hpp"
+#include "decode/row.hpp"
+
+#include <pv/binding/decoder.hpp>
 
 using std::dynamic_pointer_cast;
 using std::shared_ptr;
@@ -124,6 +127,23 @@ shared_ptr<data::Logic> SignalBase::logic_data() const
                return shared_ptr<data::Logic>();
 }
 
+#ifdef ENABLE_DECODE
+bool SignalBase::is_decode_signal() const
+{
+       return (decoder_stack_ != nullptr);
+}
+
+std::shared_ptr<pv::data::DecoderStack> SignalBase::decoder_stack() const
+{
+       return decoder_stack_;
+}
+
+void SignalBase::set_decoder_stack(std::shared_ptr<pv::data::DecoderStack>
+       decoder_stack)
+{
+       decoder_stack_ = decoder_stack;
+}
+#endif
 
 } // namespace data
 } // namespace pv
index ca3cd5c47c8b0489490c65a66905cc0c000c3a47..a682a56e1f52cadbb60a8a3a1dba9a80e2eacbc2 100644 (file)
@@ -38,6 +38,7 @@ namespace pv {
 namespace data {
 
 class Analog;
+class DecoderStack;
 class Logic;
 class SignalData;
 
@@ -119,6 +120,14 @@ public:
         */
        std::shared_ptr<pv::data::Logic> logic_data() const;
 
+#ifdef ENABLE_DECODE
+       bool is_decode_signal() const;
+
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack() const;
+
+       void set_decoder_stack(std::shared_ptr<pv::data::DecoderStack>
+               decoder_stack);
+#endif
 
 Q_SIGNALS:
        void enabled_changed(const bool &value);
@@ -131,6 +140,10 @@ private:
        std::shared_ptr<sigrok::Channel> channel_;
        std::shared_ptr<pv::data::SignalData> data_;
 
+#ifdef ENABLE_DECODE
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack_;
+#endif
+
        QString name_;
        QColor colour_, bgcolour_;
 };
index 852de2981eb7bd43d9e82cf03154ae7bbeadbff7..74cb82dc99aae5b847ca5660bc56d953e931d168 100644 (file)
@@ -144,8 +144,12 @@ void Session::set_device(shared_ptr<devices::Device> device)
        device_.reset();
 
        // Remove all stored data
-       for (std::shared_ptr<pv::view::View> view : views_)
+       for (std::shared_ptr<pv::view::View> view : views_) {
                view->clear_signals();
+#ifdef ENABLE_DECODE
+               view->clear_decode_traces();
+#endif
+       }
        for (const shared_ptr<data::SignalData> d : all_signal_data_)
                d->clear();
        all_signal_data_.clear();
@@ -158,7 +162,6 @@ void Session::set_device(shared_ptr<devices::Device> device)
        }
 
        logic_data_.reset();
-       decode_traces_.clear();
 
        signals_changed();
 
@@ -314,10 +317,10 @@ bool Session::add_decoder(srd_decoder *const dec)
                shared_ptr<data::SignalBase> signalbase =
                        shared_ptr<data::SignalBase>(new data::SignalBase(nullptr));
 
-               shared_ptr<view::DecodeTrace> d(
-                       new view::DecodeTrace(*this, signalbase, decoder_stack,
-                               decode_traces_.size()));
-               decode_traces_.push_back(d);
+               signalbase->set_decoder_stack(decoder_stack);
+
+               for (std::shared_ptr<pv::view::View> view : views_)
+                       view->add_decode_trace(signalbase);
        } catch (std::runtime_error e) {
                return false;
        }
@@ -330,19 +333,10 @@ bool Session::add_decoder(srd_decoder *const dec)
        return true;
 }
 
-vector< shared_ptr<view::DecodeTrace> > Session::get_decode_signals() const
+void Session::remove_decode_signal(shared_ptr<data::SignalBase> signalbase)
 {
-       return decode_traces_;
-}
-
-void Session::remove_decode_signal(view::DecodeTrace *signal)
-{
-       for (auto i = decode_traces_.begin(); i != decode_traces_.end(); i++)
-               if ((*i).get() == signal) {
-                       decode_traces_.erase(i);
-                       signals_changed();
-                       return;
-               }
+       for (std::shared_ptr<pv::view::View> view : views_)
+               view->remove_decode_trace(signalbase);
 }
 #endif
 
@@ -365,8 +359,12 @@ void Session::update_signals()
        if (!device_) {
                signalbases_.clear();
                logic_data_.reset();
-               for (std::shared_ptr<pv::view::View> view : views_)
+               for (std::shared_ptr<pv::view::View> view : views_) {
                        view->clear_signals();
+#ifdef ENABLE_DECODE
+                       view->clear_decode_traces();
+#endif
+               }
                return;
        }
 
@@ -376,8 +374,12 @@ void Session::update_signals()
        if (!sr_dev) {
                signalbases_.clear();
                logic_data_.reset();
-               for (std::shared_ptr<pv::view::View> view : views_)
+               for (std::shared_ptr<pv::view::View> view : views_) {
                        view->clear_signals();
+#ifdef ENABLE_DECODE
+                       view->clear_decode_traces();
+#endif
+               }
                return;
        }
 
index 83a73f4af7678252dc28b0afee6f25cf2b02b553..a4fc352d1969fd527951820bbf75e37f8b2b991c 100644 (file)
@@ -73,7 +73,6 @@ class Device;
 }
 
 namespace view {
-class DecodeTrace;
 class View;
 }
 
@@ -126,10 +125,7 @@ public:
 #ifdef ENABLE_DECODE
        bool add_decoder(srd_decoder *const dec);
 
-       std::vector< std::shared_ptr<view::DecodeTrace> >
-               get_decode_signals() const;
-
-       void remove_decode_signal(view::DecodeTrace *signal);
+       void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
 #endif
 
 private:
@@ -164,8 +160,6 @@ private:
 
        std::unordered_set< std::shared_ptr<pv::view::View> > views_;
 
-       std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
-
        mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
        capture_state capture_state_;
 
index 1f21b024fb4f79000d2bee510833a17950a54dcf..832b249d4caf00f0366b2f0024aae77f05f9a85a 100644 (file)
@@ -128,18 +128,17 @@ const QColor DecodeTrace::OutlineColours[16] = {
 };
 
 DecodeTrace::DecodeTrace(pv::Session &session,
-       shared_ptr<data::SignalBase> signalbase,
-       std::shared_ptr<pv::data::DecoderStack> decoder_stack, int index) :
+       shared_ptr<data::SignalBase> signalbase, int index) :
        Trace(signalbase),
        session_(session),
        signalbase_(signalbase),
-       decoder_stack_(decoder_stack),
        row_height_(0),
        max_visible_rows_(0),
        delete_mapper_(this),
        show_hide_mapper_(this)
 {
-       assert(decoder_stack_);
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
 
        // Determine shortest string we want to see displayed in full
        QFontMetrics m(QApplication::font());
@@ -148,7 +147,7 @@ DecodeTrace::DecodeTrace(pv::Session &session,
        signalbase_->set_name(QString::fromUtf8(decoder_stack->stack().front()->decoder()->name));
        signalbase_->set_colour(DecodeColours[index % countof(DecodeColours)]);
 
-       connect(decoder_stack_.get(), SIGNAL(new_decode_data()),
+       connect(decoder_stack.get(), SIGNAL(new_decode_data()),
                this, SLOT(on_new_decode_data()));
        connect(&delete_mapper_, SIGNAL(mapped(int)),
                this, SLOT(on_delete_decoder(int)));
@@ -161,9 +160,9 @@ bool DecodeTrace::enabled() const
        return true;
 }
 
-const std::shared_ptr<pv::data::DecoderStack>& DecodeTrace::decoder() const
+std::shared_ptr<data::SignalBase> DecodeTrace::base() const
 {
-       return decoder_stack_;
+       return base_;
 }
 
 pair<int, int> DecodeTrace::v_extents() const
@@ -186,12 +185,15 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
 {
        using namespace pv::data::decode;
 
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->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();
+       assert(decoder_stack);
+       const QString err = decoder_stack->error_message();
        if (!err.isEmpty()) {
                draw_unresolved_period(
                        p, annotation_height, pp.left(), pp.right());
@@ -207,8 +209,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
        pair<uint64_t, uint64_t> sample_range = get_sample_range(
                pp.left(), pp.right());
 
-       assert(decoder_stack_);
-       const vector<Row> rows(decoder_stack_->get_visible_rows());
+       const vector<Row> rows(decoder_stack->get_visible_rows());
 
        visible_rows_.clear();
        for (const Row& row : rows) {
@@ -231,7 +232,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
                base_colour >>= 16;
 
                vector<Annotation> annotations;
-               decoder_stack_->get_annotation_subset(annotations, row,
+               decoder_stack->get_annotation_subset(annotations, row,
                        sample_range.first, sample_range.second);
                if (!annotations.empty()) {
                        draw_annotations(annotations, p, annotation_height, pp, y,
@@ -297,9 +298,12 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
 {
        using pv::data::decode::Decoder;
 
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
        assert(form);
        assert(parent);
-       assert(decoder_stack_);
+       assert(decoder_stack);
 
        // Add the standard options
        Trace::populate_popup_form(parent, form);
@@ -309,7 +313,7 @@ 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 = decoder_stack->stack();
 
        if (stack.empty()) {
                QLabel *const l = new QLabel(
@@ -600,12 +604,15 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left,
 
        double samples_per_pixel, pixels_offset;
 
-       assert(decoder_stack_); 
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
+       assert(decoder_stack);
 
        shared_ptr<Logic> data;
        shared_ptr<data::SignalBase> signalbase;
 
-       const list< shared_ptr<Decoder> > &stack = decoder_stack_->stack();
+       const list< shared_ptr<Decoder> > &stack = decoder_stack->stack();
 
        // We get the logic data of the first channel in the list.
        // This works because we are currently assuming all
@@ -626,7 +633,7 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left,
        if (sample_count == 0)
                return;
 
-       const int64_t samples_decoded = decoder_stack_->samples_decoded();
+       const int64_t samples_decoded = decoder_stack->samples_decoded();
        if (sample_count == samples_decoded)
                return;
 
@@ -652,8 +659,11 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left,
 
 pair<double, double> DecodeTrace::get_pixels_offset_samples_per_pixel() const
 {
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
        assert(owner_);
-       assert(decoder_stack_);
+       assert(decoder_stack);
 
        const View *view = owner_->view();
        assert(view);
@@ -662,9 +672,9 @@ pair<double, double> DecodeTrace::get_pixels_offset_samples_per_pixel() const
        assert(scale > 0);
 
        const double pixels_offset =
-               ((view->offset() - decoder_stack_->start_time()) / scale).convert_to<double>();
+               ((view->offset() - decoder_stack->start_time()) / scale).convert_to<double>();
 
-       double samplerate = decoder_stack_->samplerate();
+       double samplerate = decoder_stack->samplerate();
 
        // Show sample rate as 1Hz when it is unknown
        if (samplerate == 0.0)
@@ -722,8 +732,11 @@ const QString DecodeTrace::get_annotation_at_point(const QPoint &point)
 
        vector<pv::data::decode::Annotation> annotations;
 
-       assert(decoder_stack_);
-       decoder_stack_->get_annotation_subset(annotations, visible_rows_[row],
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
+       assert(decoder_stack);
+       decoder_stack->get_annotation_subset(annotations, visible_rows_[row],
                sample_range.first, sample_range.second);
 
        return (annotations.empty()) ?
@@ -828,9 +841,12 @@ void DecodeTrace::create_decoder_form(int index,
                channel_selectors_.push_back(s);
        }
 
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
        // Add the options
        shared_ptr<binding::Decoder> binding(
-               new binding::Decoder(decoder_stack_, dec));
+               new binding::Decoder(decoder_stack, dec));
        binding->add_properties_to_form(decoder_form, true);
 
        bindings_.push_back(binding);
@@ -908,11 +924,14 @@ void DecodeTrace::commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec
 
 void DecodeTrace::commit_channels()
 {
-       assert(decoder_stack_);
-       for (shared_ptr<data::decode::Decoder> dec : decoder_stack_->stack())
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
+       assert(decoder_stack);
+       for (shared_ptr<data::decode::Decoder> dec : decoder_stack->stack())
                commit_decoder_channels(dec);
 
-       decoder_stack_->begin_decode();
+       decoder_stack->begin_decode();
 }
 
 void DecodeTrace::on_new_decode_data()
@@ -928,7 +947,7 @@ void DecodeTrace::delete_pressed()
 
 void DecodeTrace::on_delete()
 {
-       session_.remove_decode_signal(this);
+       session_.remove_decode_signal(base_);
 }
 
 void DecodeTrace::on_channel_selected(int)
@@ -938,30 +957,39 @@ void DecodeTrace::on_channel_selected(int)
 
 void DecodeTrace::on_stack_decoder(srd_decoder *decoder)
 {
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
        assert(decoder);
-       assert(decoder_stack_);
-       decoder_stack_->push(shared_ptr<data::decode::Decoder>(
+       assert(decoder_stack);
+       decoder_stack->push(shared_ptr<data::decode::Decoder>(
                new data::decode::Decoder(decoder)));
-       decoder_stack_->begin_decode();
+       decoder_stack->begin_decode();
 
        create_popup_form();
 }
 
 void DecodeTrace::on_delete_decoder(int index)
 {
-       decoder_stack_->remove(index);
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
+       decoder_stack->remove(index);
 
        // Update the popup
        create_popup_form();    
 
-       decoder_stack_->begin_decode();
+       decoder_stack->begin_decode();
 }
 
 void DecodeTrace::on_show_hide_decoder(int index)
 {
        using pv::data::decode::Decoder;
 
-       const list< shared_ptr<Decoder> > stack(decoder_stack_->stack());
+       std::shared_ptr<pv::data::DecoderStack> decoder_stack =
+               signalbase_->decoder_stack();
+
+       const list< shared_ptr<Decoder> > stack(decoder_stack->stack());
 
        // Find the decoder in the stack
        auto iter = stack.cbegin();
index 96332d97b46c8a3842ed1f8fa580ae9a59528ebf..f56953209293532716cad294997482b4348dfa65 100644 (file)
@@ -45,6 +45,7 @@ class Session;
 
 namespace data {
 class DecoderStack;
+class SignalBase;
 
 namespace decode {
 class Annotation;
@@ -86,13 +87,14 @@ private:
 
 public:
        DecodeTrace(pv::Session &session, std::shared_ptr<data::SignalBase> signalbase,
-               std::shared_ptr<pv::data::DecoderStack> decoder_stack,
                int index);
 
        bool enabled() const;
 
        const std::shared_ptr<pv::data::DecoderStack>& decoder() const;
 
+       std::shared_ptr<data::SignalBase> base() const;
+
        /**
         * Computes the vertical extents of the contents of this row item.
         * @return A pair containing the minimum and maximum y-values.
@@ -198,8 +200,8 @@ private Q_SLOTS:
 private:
        pv::Session &session_;
        std::shared_ptr<data::SignalBase> signalbase_;
-       std::shared_ptr<pv::data::DecoderStack> decoder_stack_;
 
+       std::vector<data::decode::Row> visible_rows_;
        uint64_t decode_start_, decode_end_;
 
        std::list< std::shared_ptr<pv::binding::Decoder> >
@@ -208,7 +210,6 @@ private:
        std::list<ChannelSelector> channel_selectors_;
        std::vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
 
-       std::vector<data::decode::Row> visible_rows_;
        std::map<data::decode::Row, int> row_title_widths_;
        int row_height_, max_visible_rows_;
 
index 7e47140c6bf2f3d4335df419e8cea74dd8976ecf..3f832474cebdf9415df879dc3592a7de27a25f7d 100644 (file)
@@ -201,6 +201,30 @@ void View::add_signal(const shared_ptr<view::Signal> signal)
        signals_.insert(signal);
 }
 
+#ifdef ENABLE_DECODE
+void View::clear_decode_traces()
+{
+       decode_traces_.clear();
+}
+
+void View::add_decode_trace(shared_ptr<data::SignalBase> signalbase)
+{
+       shared_ptr<view::DecodeTrace> d(
+               new view::DecodeTrace(session_, signalbase, decode_traces_.size()));
+       decode_traces_.push_back(d);
+}
+
+void View::remove_decode_trace(shared_ptr<data::SignalBase> signalbase)
+{
+       for (auto i = decode_traces_.begin(); i != decode_traces_.end(); i++)
+               if ((*i)->base() == signalbase) {
+                       decode_traces_.erase(i);
+                       signals_changed();
+                       return;
+               }
+}
+#endif
+
 View* View::view()
 {
        return this;
@@ -967,9 +991,7 @@ void View::signals_changed()
        set< shared_ptr<Trace> > traces(signals_.begin(), signals_.end());
 
 #ifdef ENABLE_DECODE
-       const vector< shared_ptr<DecodeTrace> > decode_traces(
-               session().get_decode_signals());
-       traces.insert(decode_traces.begin(), decode_traces.end());
+       traces.insert(decode_traces_.begin(), decode_traces_.end());
 #endif
 
        set< shared_ptr<Trace> > add_traces;
index d699be4ffaa37092391c8a492e6d30f82ba2849e..eeb43ec88303a79ed55f5a93107afe113cc7d143 100644 (file)
@@ -51,6 +51,7 @@ class Session;
 namespace view {
 
 class CursorHeader;
+class DecodeTrace;
 class Header;
 class Ruler;
 class Signal;
@@ -91,6 +92,14 @@ public:
 
        void add_signal(const std::shared_ptr<view::Signal> signal);
 
+#ifdef ENABLE_DECODE
+       void clear_decode_traces();
+
+       void add_decode_trace(std::shared_ptr<data::SignalBase> signalbase);
+
+       void remove_decode_trace(std::shared_ptr<data::SignalBase> signalbase);
+#endif
+
        /**
         * Returns the view of the owner.
         */
@@ -367,6 +376,10 @@ private:
 
        std::unordered_set< std::shared_ptr<view::Signal> > signals_;
 
+#ifdef ENABLE_DECODE
+       std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
+#endif
+
        /// The view time scale in seconds per pixel.
        double scale_;