]> sigrok.org Git - pulseview.git/commitdiff
Move signal data to SignalBase and adjust view::AnalogSignal
authorSoeren Apel <redacted>
Tue, 16 Aug 2016 19:13:25 +0000 (21:13 +0200)
committerUwe Hermann <redacted>
Thu, 18 Aug 2016 22:36:02 +0000 (00:36 +0200)
The signal data belongs to the signal base (M) and not
the view's AnalogSignal (V). Hence we need to move it.

pv/data/signalbase.cpp
pv/data/signalbase.hpp
pv/session.cpp
pv/session.hpp
pv/view/analogsignal.cpp
pv/view/analogsignal.hpp

index 55397edfc4177bd7fb60d264f43d49791db80523..62881528a0c37faa47aba0f97a1ff242f95dcce4 100644 (file)
  * 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<pv::data::SignalData> data)
+{
+       data_ = data;
+}
+
+shared_ptr<data::Analog> SignalBase::analog_data() const
+{
+       if (type() == ChannelType::ANALOG)
+               return dynamic_pointer_cast<data::Analog>(data_);
+       else
+               return shared_ptr<data::Analog>();
+}
+
+shared_ptr<data::Logic> SignalBase::logic_data() const
+{
+       if (type() == ChannelType::LOGIC)
+               return dynamic_pointer_cast<data::Logic>(data_);
+       else
+               return shared_ptr<data::Logic>();
+}
+
+
 } // namespace data
 } // namespace pv
index db1af1c718e4ddb0b8262b6790b5e2fd9afea2da..ca3cd5c47c8b0489490c65a66905cc0c000c3a47 100644 (file)
@@ -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<pv::data::SignalData> data);
+
+       /**
+        * Get the internal data as analog data object in case of analog type.
+        */
+       std::shared_ptr<pv::data::Analog> analog_data() const;
+
+       /**
+        * Get the internal data as logic data object in case of logic type.
+        */
+       std::shared_ptr<pv::data::Logic> logic_data() const;
+
+
 Q_SIGNALS:
        void enabled_changed(const bool &value);
 
@@ -109,6 +129,8 @@ Q_SIGNALS:
 
 private:
        std::shared_ptr<sigrok::Channel> channel_;
+       std::shared_ptr<pv::data::SignalData> data_;
+
        QString name_;
        QColor colour_, bgcolour_;
 };
index e1a1f010cf065dcad630f391161f819b5f494f0e..9d00a51032c649455b15eceab0f7dfdead57e335 100644 (file)
@@ -438,11 +438,11 @@ void Session::update_signals()
 
                                case SR_CHANNEL_ANALOG:
                                {
-                                       shared_ptr<data::Analog> data(
-                                               new data::Analog());
+                                       shared_ptr<data::Analog> data(new data::Analog());
+                                       signalbase->set_data(data);
                                        signal = shared_ptr<view::Signal>(
                                                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<data::SignalBase> Session::signal_from_channel(
+shared_ptr<data::SignalBase> Session::signalbase_from_channel(
        shared_ptr<sigrok::Channel> channel) const
 {
        for (shared_ptr<data::SignalBase> sig : signalbases_) {
@@ -633,12 +633,10 @@ void Session::feed_in_analog(shared_ptr<Analog> analog)
                        cur_analog_segments_[channel] = segment;
 
                        // Find the analog data associated with the channel
-                       shared_ptr<view::AnalogSignal> sig =
-                               dynamic_pointer_cast<view::AnalogSignal>(
-                                       signal_from_channel(channel));
-                       assert(sig);
+                       shared_ptr<data::SignalBase> base = signalbase_from_channel(channel);
+                       assert(base);
 
-                       shared_ptr<data::Analog> data(sig->analog_data());
+                       shared_ptr<data::Analog> data(base->analog_data());
                        assert(data);
 
                        // Push the segment into the analog data.
index 4c6c73e37483e60f3b72ace3fd68b6a26befd8e0..96da72d39be2c908ab41b470a151e63ec1b73a61 100644 (file)
@@ -134,7 +134,7 @@ private:
 
        void update_signals();
 
-       std::shared_ptr<data::SignalBase> signal_from_channel(
+       std::shared_ptr<data::SignalBase> signalbase_from_channel(
                std::shared_ptr<sigrok::Channel> channel) const;
 
 private:
index cd57da06b6073e0143f3f859bad2b70a8120a426..fbffb2ebb0061b7a05af272d5647fe45c37b229b 100644 (file)
@@ -71,10 +71,8 @@ const int AnalogSignal::InfoTextMarginBottom = 5;
 
 AnalogSignal::AnalogSignal(
        pv::Session &session,
-       shared_ptr<data::SignalBase> base,
-       shared_ptr<data::Analog> data) :
+       shared_ptr<data::SignalBase> 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<pv::data::SignalData> AnalogSignal::data() const
 {
-       return data_;
-}
-
-shared_ptr<pv::data::Analog> AnalogSignal::analog_data() const
-{
-       return data_;
+       return base_->analog_data();
 }
 
 std::pair<int, int> 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<pv::data::AnalogSegment> > &segments =
-               data_->analog_segments();
+               base_->analog_data()->analog_segments();
        if (segments.empty())
                return;
 
index f35fe79f1eb839ee719f452c3ca0183b4c7348ad..81fdf393abb16aab3e633582a5c83060d83df0c7 100644 (file)
@@ -53,15 +53,12 @@ private:
 
 public:
        AnalogSignal(pv::Session &session,
-               std::shared_ptr<data::SignalBase> base,
-               std::shared_ptr<pv::data::Analog> data);
+               std::shared_ptr<data::SignalBase> base);
 
        virtual ~AnalogSignal() = default;
 
        std::shared_ptr<pv::data::SignalData> data() const;
 
-       std::shared_ptr<pv::data::Analog> 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<pv::data::Analog> data_;
-
        QComboBox *resolution_cb_;
 
        float scale_;