]> sigrok.org Git - pulseview.git/commitdiff
Implement showing only the selected segment
authorSoeren Apel <redacted>
Thu, 31 Aug 2017 06:24:53 +0000 (08:24 +0200)
committerSoeren Apel <redacted>
Fri, 22 Sep 2017 18:58:16 +0000 (20:58 +0200)
pv/views/trace/analogsignal.cpp
pv/views/trace/logicsignal.cpp
pv/views/trace/logicsignal.hpp
pv/views/trace/signal.cpp
pv/views/trace/signal.hpp
pv/views/trace/standardbar.cpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 07fc7cf72add70fda687d3bc9b304bcfdf1d72fc..cddf59c15059cdda26a209b4781032f73fdd9bce 100644 (file)
@@ -28,6 +28,7 @@
 #include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
+#include <QDebug>
 #include <QFormLayout>
 #include <QGridLayout>
 #include <QLabel>
@@ -54,6 +55,7 @@ using std::max;
 using std::make_pair;
 using std::min;
 using std::numeric_limits;
+using std::out_of_range;
 using std::pair;
 using std::placeholders::_1;
 using std::shared_ptr;
@@ -271,8 +273,13 @@ void AnalogSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp)
                if (segments.empty())
                        return;
 
-               const shared_ptr<pv::data::AnalogSegment> &segment =
-                       segments.front();
+               shared_ptr<pv::data::AnalogSegment> segment;
+               try {
+                       segment = segments.at(current_segment_);
+               } catch (out_of_range) {
+                       qDebug() << "Current analog segment out of range for signal" << base_->name();
+                       return;
+               }
 
                const double pixels_offset = pp.pixels_offset();
                const double samplerate = max(1.0, segment->samplerate());
@@ -538,8 +545,13 @@ void AnalogSignal::paint_logic_mid(QPainter &p, ViewItemPaintParams &pp)
        if (segments.empty())
                return;
 
-       const shared_ptr<pv::data::LogicSegment> &segment =
-               segments.front();
+       shared_ptr<pv::data::LogicSegment> segment;
+       try {
+               segment = segments.at(current_segment_);
+       } catch (out_of_range) {
+               qDebug() << "Current logic segment out of range for signal" << base_->name();
+               return;
+       }
 
        double samplerate = segment->samplerate();
 
index 407551843bfdcaeaa633345108b69647c22fbc37..e536171667307c8e43a2a81876de90c3ca9f815c 100644 (file)
@@ -46,6 +46,7 @@ using std::max;
 using std::make_pair;
 using std::min;
 using std::none_of;
+using std::out_of_range;
 using std::pair;
 using std::shared_ptr;
 using std::vector;
@@ -196,7 +197,13 @@ void LogicSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp)
        if (segments.empty())
                return;
 
-       const shared_ptr<pv::data::LogicSegment> &segment = segments.front();
+       shared_ptr<pv::data::LogicSegment> segment;
+       try {
+               segment = segments.at(current_segment_);
+       } catch (out_of_range) {
+               qDebug() << "Current logic segment out of range for signal" << base_->name();
+               return;
+       }
 
        double samplerate = segment->samplerate();
 
index cf2f68d82cb90a2bed14560e72927202f100b47a..9899260a8cfc503f342802020a17e6db56d11a8e 100644 (file)
@@ -21,6 +21,7 @@
 #define PULSEVIEW_PV_VIEWS_TRACEVIEW_LOGICSIGNAL_HPP
 
 #include <QCache>
+#include <QDebug>
 #include <QSpinBox>
 
 #include "signal.hpp"
index 1e277f0d57196beb1ada1be3c4b016e4d44a5d95..a286d95d3c6d07e9b299aefce8ef48701668a987 100644 (file)
@@ -62,7 +62,8 @@ Signal::Signal(pv::Session &session,
        shared_ptr<data::SignalBase> channel) :
        Trace(channel),
        session_(session),
-       name_widget_(nullptr)
+       name_widget_(nullptr),
+       current_segment_(0)
 {
        assert(base_);
 
@@ -88,6 +89,16 @@ shared_ptr<data::SignalBase> Signal::base() const
        return base_;
 }
 
+void Signal::set_current_segment(const int segment)
+{
+       current_segment_ = segment;
+}
+
+int Signal::get_current_segment() const
+{
+       return current_segment_;
+}
+
 void Signal::save_settings(QSettings &settings) const
 {
        (void)settings;
index 7f88720f7943904142008b82d88f8103caefa464..2cc49a77d1962499c8bece819c5a0824485bf543 100644 (file)
@@ -75,6 +75,10 @@ public:
 
        shared_ptr<data::SignalBase> base() const;
 
+       void set_current_segment(const int segment);
+
+       int get_current_segment() const;
+
        virtual void save_settings(QSettings &settings) const;
 
        virtual void restore_settings(QSettings &settings);
@@ -98,6 +102,9 @@ protected:
        pv::Session &session_;
 
        QComboBox *name_widget_;
+
+       /// The ID of the currently displayed segment
+       int current_segment_;
 };
 
 } // namespace trace
index fa04c8e2318bf40e63f896abc8b345509e7ecbc2..e2d6f3e2b540c7d201208329f6a3958b6ec7b29d 100644 (file)
@@ -86,8 +86,11 @@ StandardBar::StandardBar(Session &session, QWidget *parent,
        action_view_show_cursors_->setText(tr("Show &Cursors"));
 
        segment_selector_->setMinimum(1);
+       segment_selector_->hide();
        connect(&session_, SIGNAL(frame_ended()),
                this, SLOT(on_segment_added()));
+       connect(segment_selector_, SIGNAL(valueChanged(int)),
+               view_, SLOT(on_segment_changed(int)));
 
        connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)),
                this, SLOT(on_always_zoom_to_fit_changed(bool)));
index ce78100f83383da5df9393ef28222cf02e577795..8e6bd6f405164d69dfe60f55f40dde007fd15c2d 100644 (file)
@@ -1363,6 +1363,16 @@ void View::capture_state_updated(int state)
        }
 }
 
+void View::on_segment_changed(int segment)
+{
+       current_segment_ = segment - 1;
+
+       for (shared_ptr<Signal> signal : signals_)
+               signal->set_current_segment(current_segment_);
+
+       viewport_->update();
+}
+
 void View::perform_delayed_view_update()
 {
        if (always_zoom_to_fit_) {
index f0aa491e585fa5f90998e9697a151404d2fb3275..fa54c068965d7245a17fb69fa3af308a03d50df9 100644 (file)
@@ -365,6 +365,8 @@ private Q_SLOTS:
        void signals_changed();
        void capture_state_updated(int state);
 
+       void on_segment_changed(int segment);
+
        virtual void perform_delayed_view_update();
 
        void process_sticky_events();
@@ -418,6 +420,9 @@ private:
        vector< shared_ptr<DecodeTrace> > decode_traces_;
 #endif
 
+       /// The ID of the currently displayed segment
+       int current_segment_;
+
        /// The view time scale in seconds per pixel.
        double scale_;