From: Soeren Apel Date: Tue, 5 May 2020 16:39:25 +0000 (+0200) Subject: Rework signals for modularity X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1f3033cb3e63de7cfe98dab537460443917fece3;p=pulseview.git Rework signals for modularity --- diff --git a/main.cpp b/main.cpp index da5fffcd..793f4ce1 100644 --- a/main.cpp +++ b/main.cpp @@ -60,6 +60,7 @@ #include "pv/mainwindow.hpp" #include "pv/session.hpp" #include "pv/util.hpp" +#include "pv/data/segment.hpp" #ifdef ANDROID #include @@ -274,8 +275,9 @@ int main(int argc, char *argv[]) for (int i = 0; i < argc; i++) open_files.emplace_back(argv[i]); - qRegisterMetaType("util::Timestamp"); qRegisterMetaType("uint64_t"); + qRegisterMetaType("util::Timestamp"); + qRegisterMetaType("data::Segment"); // Prepare the global settings since logging needs them early on pv::GlobalSettings settings; diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index 57d09502..02cb83e4 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -84,7 +84,7 @@ uint64_t Analog::max_sample_count() const return l; } -void Analog::notify_samples_added(QObject* segment, uint64_t start_sample, +void Analog::notify_samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample) { samples_added(segment, start_sample, end_sample); diff --git a/pv/data/analog.hpp b/pv/data/analog.hpp index 026d8046..bcdf7bc9 100644 --- a/pv/data/analog.hpp +++ b/pv/data/analog.hpp @@ -59,7 +59,7 @@ public: uint64_t max_sample_count() const; - void notify_samples_added(QObject* segment, uint64_t start_sample, + void notify_samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample); void notify_min_max_changed(float min, float max); @@ -67,7 +67,7 @@ public: Q_SIGNALS: void samples_cleared(); - void samples_added(QObject* segment, uint64_t start_sample, + void samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample); void min_max_changed(float min, float max); diff --git a/pv/data/analogsegment.cpp b/pv/data/analogsegment.cpp index 342612aa..e6f9626c 100644 --- a/pv/data/analogsegment.cpp +++ b/pv/data/analogsegment.cpp @@ -89,11 +89,11 @@ void AnalogSegment::append_interleaved_samples(const float *data, append_payload_to_envelope_levels(); if (sample_count > 1) - owner_.notify_samples_added(this, prev_sample_count + 1, - prev_sample_count + 1 + sample_count); + owner_.notify_samples_added(shared_ptr(shared_from_this()), + prev_sample_count + 1, prev_sample_count + 1 + sample_count); else - owner_.notify_samples_added(this, prev_sample_count + 1, - prev_sample_count + 1); + owner_.notify_samples_added(shared_ptr(shared_from_this()), + prev_sample_count + 1, prev_sample_count + 1); } void AnalogSegment::get_samples(int64_t start_sample, int64_t end_sample, diff --git a/pv/data/analogsegment.hpp b/pv/data/analogsegment.hpp index df25f0b7..846837ce 100644 --- a/pv/data/analogsegment.hpp +++ b/pv/data/analogsegment.hpp @@ -27,6 +27,7 @@ #include +using std::enable_shared_from_this; using std::pair; namespace AnalogSegmentTest { @@ -38,7 +39,7 @@ namespace data { class Analog; -class AnalogSegment : public Segment +class AnalogSegment : public Segment, public enable_shared_from_this { Q_OBJECT diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 7aefbf5f..038da649 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -53,6 +53,11 @@ const deque< shared_ptr >& Logic::logic_segments() const return segments_; } +deque< shared_ptr >& Logic::logic_segments() +{ + return segments_; +} + vector< shared_ptr > Logic::segments() const { return vector< shared_ptr >(segments_.begin(), segments_.end()); @@ -90,7 +95,7 @@ uint64_t Logic::max_sample_count() const return l; } -void Logic::notify_samples_added(QObject* segment, uint64_t start_sample, +void Logic::notify_samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample) { samples_added(segment, start_sample, end_sample); diff --git a/pv/data/logic.hpp b/pv/data/logic.hpp index 18622c1e..e45ff2f6 100644 --- a/pv/data/logic.hpp +++ b/pv/data/logic.hpp @@ -47,6 +47,7 @@ public: void push_segment(shared_ptr &segment); const deque< shared_ptr >& logic_segments() const; + deque< shared_ptr >& logic_segments(); vector< shared_ptr > segments() const; @@ -60,13 +61,13 @@ public: uint64_t max_sample_count() const; - void notify_samples_added(QObject* segment, uint64_t start_sample, + void notify_samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample); Q_SIGNALS: void samples_cleared(); - void samples_added(QObject* segment, uint64_t start_sample, + void samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample); private: diff --git a/pv/data/logicsegment.cpp b/pv/data/logicsegment.cpp index b9e57caa..a1832576 100644 --- a/pv/data/logicsegment.cpp +++ b/pv/data/logicsegment.cpp @@ -341,11 +341,11 @@ void LogicSegment::append_payload(void *data, uint64_t data_size) append_payload_to_mipmap(); if (sample_count > 1) - owner_.notify_samples_added(this, prev_sample_count + 1, - prev_sample_count + 1 + sample_count); + owner_.notify_samples_added(shared_ptr(shared_from_this()), + prev_sample_count + 1, prev_sample_count + 1 + sample_count); else - owner_.notify_samples_added(this, prev_sample_count + 1, - prev_sample_count + 1); + owner_.notify_samples_added(shared_ptr(shared_from_this()), + prev_sample_count + 1, prev_sample_count + 1); } void LogicSegment::get_samples(int64_t start_sample, diff --git a/pv/data/logicsegment.hpp b/pv/data/logicsegment.hpp index 67959b31..1f151eeb 100644 --- a/pv/data/logicsegment.hpp +++ b/pv/data/logicsegment.hpp @@ -22,11 +22,11 @@ #include "segment.hpp" -#include #include #include +using std::enable_shared_from_this; using std::pair; using std::shared_ptr; using std::vector; @@ -48,7 +48,7 @@ namespace data { class Logic; -class LogicSegment : public Segment +class LogicSegment : public Segment, public enable_shared_from_this { Q_OBJECT diff --git a/pv/data/segment.hpp b/pv/data/segment.hpp index f5a00c95..54d236eb 100644 --- a/pv/data/segment.hpp +++ b/pv/data/segment.hpp @@ -121,4 +121,6 @@ protected: } // namespace data } // namespace pv +Q_DECLARE_METATYPE(pv::data::Segment); + #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index d09615c8..2ca5a835 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -155,8 +155,8 @@ void SignalBase::set_data(shared_ptr data) if (data_) { disconnect(data.get(), SIGNAL(samples_cleared()), this, SLOT(on_samples_cleared())); - disconnect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)), - this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t))); + disconnect(data.get(), SIGNAL(samples_added(shared_ptr, uint64_t, uint64_t)), + this, SLOT(on_samples_added(shared_ptr, uint64_t, uint64_t))); if (channel_type_ == AnalogChannel) { shared_ptr analog = analog_data(); @@ -172,8 +172,8 @@ void SignalBase::set_data(shared_ptr data) if (data_) { connect(data.get(), SIGNAL(samples_cleared()), this, SLOT(on_samples_cleared())); - connect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)), - this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t))); + connect(data.get(), SIGNAL(samples_added(shared_ptr, uint64_t, uint64_t)), + this, SLOT(on_samples_added(shared_ptr, uint64_t, uint64_t))); if (channel_type_ == AnalogChannel) { shared_ptr analog = analog_data(); @@ -752,7 +752,7 @@ void SignalBase::on_samples_cleared() samples_cleared(); } -void SignalBase::on_samples_added(QObject* segment, uint64_t start_sample, +void SignalBase::on_samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample) { if (conversion_type_ != NoConversion) { @@ -766,8 +766,7 @@ void SignalBase::on_samples_added(QObject* segment, uint64_t start_sample, } } - data::Segment* s = qobject_cast(segment); - samples_added(s->segment_id(), start_sample, end_sample); + samples_added(segment->segment_id(), start_sample, end_sample); } void SignalBase::on_min_max_changed(float min, float max) diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index d6f11d82..733900d5 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -55,6 +55,7 @@ class AnalogSegment; class DecoderStack; class Logic; class LogicSegment; +class Segment; class SignalData; class SignalBase : public QObject @@ -322,7 +323,7 @@ Q_SIGNALS: private Q_SLOTS: void on_samples_cleared(); - void on_samples_added(QObject* segment, uint64_t start_sample, + void on_samples_added(shared_ptr segment, uint64_t start_sample, uint64_t end_sample); void on_min_max_changed(float min, float max);