]> sigrok.org Git - pulseview.git/commitdiff
Fix view setting restoration
authorSoeren Apel <redacted>
Sat, 16 May 2020 21:46:02 +0000 (23:46 +0200)
committerSoeren Apel <redacted>
Fri, 22 May 2020 13:21:29 +0000 (15:21 +0200)
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index ee4a4042fdc072a5de65a089ad0b29c874745167..cfafdc082ca6dc4d439c034a2e3b3a39a08faadd 100644 (file)
@@ -286,7 +286,7 @@ void View::reset_view_state()
        zero_offset_ = 0;
        custom_zero_offset_set_ = false;
        updating_scroll_ = false;
-       settings_restored_ = false;
+       restoring_state_ = false;
        always_zoom_to_fit_ = false;
        tick_period_ = 0;
        tick_prefix_ = pv::util::SIPrefix::yocto;
@@ -300,10 +300,8 @@ void View::reset_view_state()
        grabbed_widget_ = nullptr;
        hover_point_ = QPoint(-1, -1);
        scroll_needs_defaults_ = true;
-       saved_v_offset_ = 0;
        scale_at_acq_start_ = 0;
        offset_at_acq_start_ = 0;
-       suppress_zoom_to_fit_after_acq_ = false;
 
        show_cursors_ = false;
        cursor_state_changed(show_cursors_);
@@ -314,6 +312,8 @@ void View::reset_view_state()
 
        // Make sure the standard bar's segment selector is in sync
        set_segment_display_mode(segment_display_mode_);
+
+       scrollarea_->verticalScrollBar()->setRange(-100000000, 100000000);
 }
 
 Session& View::session()
@@ -541,14 +541,12 @@ void View::restore_settings(QSettings &settings)
        }
 
        if (settings.contains("v_offset")) {
+               // Note: see eventFilter() for additional information
                saved_v_offset_ = settings.value("v_offset").toInt();
-               set_v_offset(saved_v_offset_);
                scroll_needs_defaults_ = false;
-               // Note: see eventFilter() for additional information
        }
 
-       settings_restored_ = true;
-       suppress_zoom_to_fit_after_acq_ = true;
+       restoring_state_ = true;
 
        // Update the ruler so that it uses the new scale
        calculate_tick_spacing();
@@ -888,7 +886,7 @@ void View::set_scale_offset(double scale, const Timestamp& offset)
        // Disable sticky scrolling / always zoom to fit when acquisition runs
        // and user drags the viewport
        if ((scale_ == scale) && (offset_ != offset) &&
-                       (session_.get_capture_state() == Session::Running)) {
+               (session_.get_capture_state() == Session::Running)) {
 
                if (sticky_scrolling_) {
                        sticky_scrolling_ = false;
@@ -1565,7 +1563,7 @@ bool View::eventFilter(QObject *object, QEvent *event)
                // resized to their final sizes.
                update_layout();
 
-               if (settings_restored_)
+               if (restoring_state_)
                        determine_if_header_was_shrunk();
                else
                        resize_header_to_fit();
@@ -1575,10 +1573,8 @@ bool View::eventFilter(QObject *object, QEvent *event)
                        scroll_needs_defaults_ = false;
                }
 
-               if (saved_v_offset_) {
+               if (restoring_state_)
                        set_v_offset(saved_v_offset_);
-                       saved_v_offset_ = 0;
-               }
        }
 
        return QObject::eventFilter(object, event);
@@ -1963,13 +1959,14 @@ void View::capture_state_updated(int state)
                // the main view of this session (other trace views may be used for
                // zooming and we don't want to mess them up)
                bool state = settings.value(GlobalSettings::Key_View_ZoomToFitDuringAcq).toBool();
-               if (is_main_view_ && state) {
+               if (is_main_view_ && state && !restoring_state_) {
                        always_zoom_to_fit_ = true;
                        always_zoom_to_fit_changed(always_zoom_to_fit_);
                }
 
                // Enable sticky scrolling if the setting is enabled
-               sticky_scrolling_ = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
+               sticky_scrolling_ = !restoring_state_ &&
+                       settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
 
                // Reset all traces to segment 0
                current_segment_ = 0;
@@ -1995,12 +1992,13 @@ void View::capture_state_updated(int state)
                // Only perform zoom-to-fit if the user hasn't altered the viewport and
                // we didn't restore settings in the meanwhile
                if (zoom_to_fit_after_acq &&
-                       !suppress_zoom_to_fit_after_acq_ &&
+                       !restoring_state_ &&
                        (scale_ == scale_at_acq_start_) &&
-                       (offset_ == offset_at_acq_start_))
+                       (sticky_scrolling_ || (offset_ == offset_at_acq_start_))) {
                        zoom_fit(false);  // We're stopped, so the GUI state doesn't matter
+               }
 
-               suppress_zoom_to_fit_after_acq_ = false;
+               restoring_state_ = false;
        }
 }
 
index 63bafbfeac958f745241a6dbbb7678ae28ebd42c..b4c946d6449f29ada6eec4191c5d3adc769ca691 100644 (file)
@@ -536,7 +536,7 @@ private:
        bool custom_zero_offset_set_;
 
        bool updating_scroll_;
-       bool settings_restored_;
+       bool restoring_state_;
        bool header_was_shrunk_;
 
        bool sticky_scrolling_;
@@ -569,18 +569,12 @@ private:
        // This is true when the defaults couldn't be set due to insufficient info
        bool scroll_needs_defaults_;
 
-       // A nonzero value indicates the v offset to restore. See View::resizeEvent()
+       // The v offset to restore. See View::eventFilter()
        int saved_v_offset_;
 
        // These are used to determine whether the view was altered after acq started
        double scale_at_acq_start_;
        pv::util::Timestamp offset_at_acq_start_;
-
-       // Used to suppress performing a "zoom to fit" when the session stops. This
-       // is needed when the view's settings are restored before acquisition ends.
-       // In that case we want to keep the restored settings, not have a "zoom to fit"
-       // mess them up.
-       bool suppress_zoom_to_fit_after_acq_;
 };
 
 } // namespace trace