From: Soeren Apel Date: Thu, 31 Aug 2017 06:24:53 +0000 (+0200) Subject: Implement showing only the selected segment X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=526c8c00a61aa5f6ac7e3ee56991db957b45828d;p=pulseview.git Implement showing only the selected segment --- diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index 07fc7cf7..cddf59c1 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -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 &segment = - segments.front(); + shared_ptr 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 &segment = - segments.front(); + shared_ptr 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(); diff --git a/pv/views/trace/logicsignal.cpp b/pv/views/trace/logicsignal.cpp index 40755184..e5361716 100644 --- a/pv/views/trace/logicsignal.cpp +++ b/pv/views/trace/logicsignal.cpp @@ -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 &segment = segments.front(); + shared_ptr 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(); diff --git a/pv/views/trace/logicsignal.hpp b/pv/views/trace/logicsignal.hpp index cf2f68d8..9899260a 100644 --- a/pv/views/trace/logicsignal.hpp +++ b/pv/views/trace/logicsignal.hpp @@ -21,6 +21,7 @@ #define PULSEVIEW_PV_VIEWS_TRACEVIEW_LOGICSIGNAL_HPP #include +#include #include #include "signal.hpp" diff --git a/pv/views/trace/signal.cpp b/pv/views/trace/signal.cpp index 1e277f0d..a286d95d 100644 --- a/pv/views/trace/signal.cpp +++ b/pv/views/trace/signal.cpp @@ -62,7 +62,8 @@ Signal::Signal(pv::Session &session, shared_ptr channel) : Trace(channel), session_(session), - name_widget_(nullptr) + name_widget_(nullptr), + current_segment_(0) { assert(base_); @@ -88,6 +89,16 @@ shared_ptr 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; diff --git a/pv/views/trace/signal.hpp b/pv/views/trace/signal.hpp index 7f88720f..2cc49a77 100644 --- a/pv/views/trace/signal.hpp +++ b/pv/views/trace/signal.hpp @@ -75,6 +75,10 @@ public: shared_ptr 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 diff --git a/pv/views/trace/standardbar.cpp b/pv/views/trace/standardbar.cpp index fa04c8e2..e2d6f3e2 100644 --- a/pv/views/trace/standardbar.cpp +++ b/pv/views/trace/standardbar.cpp @@ -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))); diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index ce78100f..8e6bd6f4 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -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 : signals_) + signal->set_current_segment(current_segment_); + + viewport_->update(); +} + void View::perform_delayed_view_update() { if (always_zoom_to_fit_) { diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index f0aa491e..fa54c068 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -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 > decode_traces_; #endif + /// The ID of the currently displayed segment + int current_segment_; + /// The view time scale in seconds per pixel. double scale_;