]> sigrok.org Git - pulseview.git/commitdiff
Flesh out segment display mode handling
authorSoeren Apel <redacted>
Mon, 20 Nov 2017 21:50:53 +0000 (22:50 +0100)
committerSoeren Apel <redacted>
Wed, 27 Dec 2017 17:40:19 +0000 (18:40 +0100)
pv/session.cpp
pv/session.hpp
pv/views/trace/analogsignal.cpp
pv/views/trace/logicsignal.cpp
pv/views/trace/standardbar.cpp
pv/views/trace/standardbar.hpp
pv/views/trace/view.cpp

index b9612d0e04f3b3a02f84dc55c4a6c3d4ae823d86..a44c6f9916f3b326a05e932950cee0acfacedf40 100644 (file)
@@ -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<sigrok::Channel> any_channel =
                                (*cur_analog_segments_.begin()).first;
@@ -978,7 +978,7 @@ void Session::signal_new_segment()
                        shared_ptr<data::Analog> data(base->analog_data());
                        assert(data);
 
-                       new_segment_id = data->get_segment_count();
+                       new_segment_id = data->get_segment_count() - 1;
                }
        }
 
index 1cb370a9eff216b2b4a541428e6d1c9b86bfc027..76019612a977eaff33fed75c6c5d932897863a2a 100644 (file)
@@ -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();
 
index 90e441e09f125392c5ccd215e0b2441b55f3c026..cb4c0325e3e83fd42fbd7335d09cf77faee4bef0 100644 (file)
@@ -662,7 +662,7 @@ shared_ptr<pv::data::AnalogSegment> 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<pv::data::LogicSegment> 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_;
                        }
                }
        }
index 4a3a80a7255fa7b5cd6a6f1bdb263bfce4bcfd3f..bbb00ef6ad862f6fa27a0e6c0cdb498080c921c7 100644 (file)
@@ -362,7 +362,7 @@ shared_ptr<pv::data::LogicSegment> 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_;
                        }
                }
        }
index 6363e2ec6fcc9717e92dfc3a327713836d5b93eb..65f9ae3e684d57434667ed4c48666a6cc3cf30bf 100644 (file)
@@ -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)
index e1394372dc4a0a5273b9b03501f99dba24c5d48e..a6e8606e132831044de132780cfecdd677167e8c 100644 (file)
@@ -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:
index e26e8fc2582a8a45b57f41d3abbf2d72940ed6f7..a79396d15b04715b0bb5f33ea461214190d0d044 100644 (file)
@@ -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> signal : signals_)
                        signal->set_current_segment(current_segment_);
                viewport_->update();