From: Soeren Apel Date: Tue, 16 Aug 2016 19:13:25 +0000 (+0200) Subject: Move signal data to SignalBase and adjust view::AnalogSignal X-Git-Tag: pulseview-0.4.0~274 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cbd2a2de848f957507096785d3be1cc97d30df9a;p=pulseview.git Move signal data to SignalBase and adjust view::AnalogSignal The signal data belongs to the signal base (M) and not the view's AnalogSignal (V). Hence we need to move it. --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 55397edf..62881528 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -19,8 +19,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "analog.hpp" +#include "logic.hpp" #include "signalbase.hpp" +#include "signaldata.hpp" +using std::dynamic_pointer_cast; using std::shared_ptr; using sigrok::Channel; @@ -99,5 +103,27 @@ QColor SignalBase::bgcolour() const return bgcolour_; } +void SignalBase::set_data(shared_ptr data) +{ + data_ = data; +} + +shared_ptr SignalBase::analog_data() const +{ + if (type() == ChannelType::ANALOG) + return dynamic_pointer_cast(data_); + else + return shared_ptr(); +} + +shared_ptr SignalBase::logic_data() const +{ + if (type() == ChannelType::LOGIC) + return dynamic_pointer_cast(data_); + else + return shared_ptr(); +} + + } // namespace data } // namespace pv diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index db1af1c7..ca3cd5c4 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -37,6 +37,10 @@ class ChannelType; namespace pv { namespace data { +class Analog; +class Logic; +class SignalData; + class SignalBase : public QObject { Q_OBJECT @@ -100,6 +104,22 @@ public: */ QColor bgcolour() const; + /** + * Sets the internal data object. + */ + void set_data(std::shared_ptr data); + + /** + * Get the internal data as analog data object in case of analog type. + */ + std::shared_ptr analog_data() const; + + /** + * Get the internal data as logic data object in case of logic type. + */ + std::shared_ptr logic_data() const; + + Q_SIGNALS: void enabled_changed(const bool &value); @@ -109,6 +129,8 @@ Q_SIGNALS: private: std::shared_ptr channel_; + std::shared_ptr data_; + QString name_; QColor colour_, bgcolour_; }; diff --git a/pv/session.cpp b/pv/session.cpp index e1a1f010..9d00a510 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -438,11 +438,11 @@ void Session::update_signals() case SR_CHANNEL_ANALOG: { - shared_ptr data( - new data::Analog()); + shared_ptr data(new data::Analog()); + signalbase->set_data(data); signal = shared_ptr( new view::AnalogSignal( - *this, signalbase, data)); + *this, signalbase)); all_signal_data_.insert(data); signalbases_.insert(signalbase); break; @@ -462,7 +462,7 @@ void Session::update_signals() signals_changed(); } -shared_ptr Session::signal_from_channel( +shared_ptr Session::signalbase_from_channel( shared_ptr channel) const { for (shared_ptr sig : signalbases_) { @@ -633,12 +633,10 @@ void Session::feed_in_analog(shared_ptr analog) cur_analog_segments_[channel] = segment; // Find the analog data associated with the channel - shared_ptr sig = - dynamic_pointer_cast( - signal_from_channel(channel)); - assert(sig); + shared_ptr base = signalbase_from_channel(channel); + assert(base); - shared_ptr data(sig->analog_data()); + shared_ptr data(base->analog_data()); assert(data); // Push the segment into the analog data. diff --git a/pv/session.hpp b/pv/session.hpp index 4c6c73e3..96da72d3 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -134,7 +134,7 @@ private: void update_signals(); - std::shared_ptr signal_from_channel( + std::shared_ptr signalbase_from_channel( std::shared_ptr channel) const; private: diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index cd57da06..fbffb2eb 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -71,10 +71,8 @@ const int AnalogSignal::InfoTextMarginBottom = 5; AnalogSignal::AnalogSignal( pv::Session &session, - shared_ptr base, - shared_ptr data) : + shared_ptr base) : Signal(session, base), - data_(data), scale_index_(4), // 20 per div scale_index_drag_offset_(0), div_height_(3 * QFontMetrics(QApplication::font()).height()), @@ -87,12 +85,7 @@ AnalogSignal::AnalogSignal( shared_ptr AnalogSignal::data() const { - return data_; -} - -shared_ptr AnalogSignal::analog_data() const -{ - return data_; + return base_->analog_data(); } std::pair AnalogSignal::v_extents() const @@ -135,7 +128,7 @@ void AnalogSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp) void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp) { - assert(data_); + assert(base_->analog_data()); assert(owner_); const int y = get_visual_y(); @@ -146,7 +139,7 @@ void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp) paint_grid(p, y, pp.left(), pp.right()); const deque< shared_ptr > &segments = - data_->analog_segments(); + base_->analog_data()->analog_segments(); if (segments.empty()) return; diff --git a/pv/view/analogsignal.hpp b/pv/view/analogsignal.hpp index f35fe79f..81fdf393 100644 --- a/pv/view/analogsignal.hpp +++ b/pv/view/analogsignal.hpp @@ -53,15 +53,12 @@ private: public: AnalogSignal(pv::Session &session, - std::shared_ptr base, - std::shared_ptr data); + std::shared_ptr base); virtual ~AnalogSignal() = default; std::shared_ptr data() const; - std::shared_ptr analog_data() const; - /** * Computes the vertical extents of the contents of this row item. * @return A pair containing the minimum and maximum y-values. @@ -134,8 +131,6 @@ private Q_SLOTS: void on_resolution_changed(int index); private: - std::shared_ptr data_; - QComboBox *resolution_cb_; float scale_;