]> sigrok.org Git - pulseview.git/blobdiff - pv/views/trace/view.cpp
views/trace: Fix two -fsanitize=undefined issues.
[pulseview.git] / pv / views / trace / view.cpp
index 05e6da3e67000a75720595aba455697ac7d265d7..4ee791623d38d766404ef67d8854dfab8da1c46b 100644 (file)
@@ -130,7 +130,8 @@ View::View(Session &session, bool is_main_view, QWidget *parent) :
        // Note: Place defaults in View::reset_view_state(), not here
        splitter_(new QSplitter()),
        header_was_shrunk_(false),  // The splitter remains unchanged after a reset, so this goes here
-       sticky_scrolling_(false)  // Default setting is set in MainWindow::setup_ui()
+       sticky_scrolling_(false),  // Default setting is set in MainWindow::setup_ui()
+       scroll_needs_defaults_(true)
 {
        QVBoxLayout *root_layout = new QVBoxLayout(this);
        root_layout->setContentsMargins(0, 0, 0, 0);
@@ -493,6 +494,11 @@ void View::reset_zero_position()
        ruler_->update();
 }
 
+pv::util::Timestamp View::zero_offset() const
+{
+       return zero_offset_;
+}
+
 int View::owner_visual_v_offset() const
 {
        return -scrollarea_->verticalScrollBar()->sliderPosition();
@@ -505,6 +511,18 @@ void View::set_v_offset(int offset)
        viewport_->update();
 }
 
+void View::set_h_offset(int offset)
+{
+       scrollarea_->horizontalScrollBar()->setSliderPosition(offset);
+       header_->update();
+       viewport_->update();
+}
+
+int View::get_h_scrollbar_maximum() const
+{
+       return scrollarea_->horizontalScrollBar()->maximum();
+}
+
 unsigned int View::depth() const
 {
        return 0;
@@ -790,22 +808,36 @@ bool View::cursors_shown() const
 
 void View::show_cursors(bool show)
 {
-       show_cursors_ = show;
-       cursor_state_changed(show);
+       if (show_cursors_ != show) {
+               show_cursors_ = show;
+
+               cursor_state_changed(show);
+               ruler_->update();
+               viewport_->update();
+       }
+}
+
+void View::set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second)
+{
+       assert(cursors_);
+
+       cursors_->first()->set_time(first);
+       cursors_->second()->set_time(second);
+
        ruler_->update();
        viewport_->update();
 }
 
 void View::centre_cursors()
 {
-       if (cursors_) {
-               const double time_width = scale_ * viewport_->width();
-               cursors_->first()->set_time(offset_ + time_width * 0.4);
-               cursors_->second()->set_time(offset_ + time_width * 0.6);
+       assert(cursors_);
 
-               ruler_->update();
-               viewport_->update();
-       }
+       const double time_width = scale_ * viewport_->width();
+       cursors_->first()->set_time(offset_ + time_width * 0.4);
+       cursors_->second()->set_time(offset_ + time_width * 0.6);
+
+       ruler_->update();
+       viewport_->update();
 }
 
 shared_ptr<CursorPair> View::cursors() const
@@ -813,15 +845,17 @@ shared_ptr<CursorPair> View::cursors() const
        return cursors_;
 }
 
-void View::add_flag(const Timestamp& time)
+shared_ptr<Flag> View::add_flag(const Timestamp& time)
 {
-       flags_.push_back(make_shared<Flag>(*this, time,
-               QString("%1").arg(next_flag_text_)));
+       shared_ptr<Flag> flag =
+               make_shared<Flag>(*this, time, QString("%1").arg(next_flag_text_));
+       flags_.push_back(flag);
 
        next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
                (next_flag_text_ + 1);
 
        time_item_appearance_changed(true, true);
+       return flag;
 }
 
 void View::remove_flag(shared_ptr<Flag> flag)