From: Soeren Apel Date: Mon, 20 Nov 2017 21:50:53 +0000 (+0100) Subject: Flesh out segment display mode handling X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=341d9a7975be53bb44af8d2deeba9b4a5e086929;p=pulseview.git Flesh out segment display mode handling --- diff --git a/pv/session.cpp b/pv/session.cpp index b9612d0e..a44c6f99 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -960,14 +960,14 @@ void Session::free_unused_memory() void Session::signal_new_segment() { - int new_segment_id = 1; + int new_segment_id = 0; if ((cur_logic_segment_ != nullptr) || !cur_analog_segments_.empty()) { // Determine new frame/segment number, assuming that all // signals have the same number of frames/segments if (cur_logic_segment_) { - new_segment_id = logic_data_->get_segment_count(); + new_segment_id = logic_data_->get_segment_count() - 1; } else { shared_ptr any_channel = (*cur_analog_segments_.begin()).first; @@ -978,7 +978,7 @@ void Session::signal_new_segment() shared_ptr data(base->analog_data()); assert(data); - new_segment_id = data->get_segment_count(); + new_segment_id = data->get_segment_count() - 1; } } diff --git a/pv/session.hpp b/pv/session.hpp index 1cb370a9..76019612 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -254,7 +254,7 @@ Q_SIGNALS: void trigger_event(util::Timestamp location); - void new_segment(int new_frame_id); + void new_segment(int new_segment_id); void data_received(); diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index 90e441e0..cb4c0325 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -662,7 +662,7 @@ shared_ptr AnalogSignal::get_analog_segment_to_paint() try { segment = segments.at(current_segment_); } catch (out_of_range) { - qDebug() << "Current analog segment out of range for signal" << base_->name(); + qDebug() << "Current analog segment out of range for signal" << base_->name() << ":" << current_segment_; } } } @@ -685,7 +685,7 @@ shared_ptr AnalogSignal::get_logic_segment_to_paint() co try { segment = segments.at(current_segment_); } catch (out_of_range) { - qDebug() << "Current logic segment out of range for signal" << base_->name(); + qDebug() << "Current logic segment out of range for signal" << base_->name() << ":" << current_segment_; } } } diff --git a/pv/views/trace/logicsignal.cpp b/pv/views/trace/logicsignal.cpp index 4a3a80a7..bbb00ef6 100644 --- a/pv/views/trace/logicsignal.cpp +++ b/pv/views/trace/logicsignal.cpp @@ -362,7 +362,7 @@ shared_ptr LogicSignal::get_logic_segment_to_paint() con try { segment = segments.at(current_segment_); } catch (out_of_range) { - qDebug() << "Current logic segment out of range for signal" << base_->name(); + qDebug() << "Current logic segment out of range for signal" << base_->name() << ":" << current_segment_; } } } diff --git a/pv/views/trace/standardbar.cpp b/pv/views/trace/standardbar.cpp index 6363e2ec..65f9ae3e 100644 --- a/pv/views/trace/standardbar.cpp +++ b/pv/views/trace/standardbar.cpp @@ -89,10 +89,15 @@ StandardBar::StandardBar(Session &session, QWidget *parent, segment_selector_->hide(); connect(&session_, SIGNAL(new_segment(int)), this, SLOT(on_new_segment(int))); + connect(segment_selector_, SIGNAL(valueChanged(int)), - view_, SLOT(on_segment_changed(int))); + this, SLOT(on_segment_selected(int))); connect(view_, SIGNAL(segment_changed(int)), this, SLOT(on_segment_changed(int))); + + connect(this, SIGNAL(segment_selected(int)), + view_, SLOT(on_segment_changed(int))); + connect(view_, SIGNAL(segment_display_mode_changed(bool)), this, SLOT(on_segment_display_mode_changed(bool))); @@ -196,7 +201,7 @@ void StandardBar::on_new_segment(int new_segment_id) { if (new_segment_id > 1) { show_multi_segment_ui(true); - segment_selector_->setMaximum(new_segment_id); + segment_selector_->setMaximum(new_segment_id + 1); } else show_multi_segment_ui(false); } @@ -205,7 +210,21 @@ void StandardBar::on_segment_changed(int segment_id) { // This is called when the current segment was changed // by other parts of the UI, e.g. the view itself - segment_selector_->setValue(segment_id); + + // We need to adjust the value by 1 because internally, segments + // start at 0 while they start with 1 for the spinbox + segment_selector_->setValue(segment_id + 1); + + segment_selected(segment_id); +} + +void StandardBar::on_segment_selected(int ui_segment_id) +{ + // This is called when the user selected a segment using the spin box + + // We need to adjust the value by 1 because internally, segments + // start at 0 while they start with 1 for the spinbox + segment_selected(ui_segment_id - 1); } void StandardBar::on_segment_display_mode_changed(bool segment_selectable) diff --git a/pv/views/trace/standardbar.hpp b/pv/views/trace/standardbar.hpp index e1394372..a6e8606e 100644 --- a/pv/views/trace/standardbar.hpp +++ b/pv/views/trace/standardbar.hpp @@ -75,6 +75,9 @@ protected: QSpinBox *segment_selector_; +Q_SIGNALS: + void segment_selected(int segment_id); + protected Q_SLOTS: void on_actionViewZoomIn_triggered(); @@ -90,6 +93,7 @@ protected Q_SLOTS: void on_new_segment(int new_segment_id); void on_segment_changed(int segment_id); + void on_segment_selected(int ui_segment_id); void on_segment_display_mode_changed(bool segment_selectable); private: diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index e26e8fc2..a79396d1 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -1420,7 +1420,7 @@ void View::on_segment_changed(int segment) switch (segment_display_mode_) { case Trace::ShowLastSegmentOnly: case Trace::ShowSingleSegmentOnly: - current_segment_ = segment - 1; + current_segment_ = segment; for (shared_ptr signal : signals_) signal->set_current_segment(current_segment_); viewport_->update();