Tie the "sticky scrolling" setting in with the settings mgmt
authorSoeren Apel <soeren@apelpie.net>
Sun, 12 Mar 2017 20:32:35 +0000 (21:32 +0100)
committerSoeren Apel <soeren@apelpie.net>
Sun, 12 Mar 2017 20:32:35 +0000 (21:32 +0100)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/view/view.cpp
pv/view/view.hpp

index 5346e5c91fc2b16ba1fcdecda2a3e8c8241a06c1..a3738b73e0920da9163e129d53d63b7f8c4330ac 100644 (file)
@@ -125,7 +125,12 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
        QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
        always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
        connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
        QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
        always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
        connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
-       trace_view_layout->addRow(tr("&Always zoom-to-fit during capture"), always_zoom_to_fit_cb);
+       trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), always_zoom_to_fit_cb);
+
+       QCheckBox *sticky_scrolling_cb = new QCheckBox();
+       sticky_scrolling_cb->setChecked(settings.value(GlobalSettings::Key_View_StickyScrolling).toBool());
+       connect(sticky_scrolling_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_stickyScrolling_changed(int)));
+       trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), sticky_scrolling_cb);
 
        return form;
 }
 
        return form;
 }
@@ -248,5 +253,12 @@ void Settings::on_view_colouredBG_changed(int state)
        settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
 }
 
        settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
 }
 
+void Settings::on_view_stickyScrolling_changed(int state)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
+}
+
+
 } // namespace dialogs
 } // namespace pv
 } // namespace dialogs
 } // namespace pv
index f050112051085e57672d058a03f7b0fefd73b6a7..b204d683ad24829edcfa6f94084206d7bf289d86 100644 (file)
@@ -49,6 +49,7 @@ private Q_SLOTS:
        void on_page_changed(QListWidgetItem *current, QListWidgetItem *previous);
        void on_view_alwaysZoomToFit_changed(int state);
        void on_view_colouredBG_changed(int state);
        void on_page_changed(QListWidgetItem *current, QListWidgetItem *previous);
        void on_view_alwaysZoomToFit_changed(int state);
        void on_view_colouredBG_changed(int state);
+       void on_view_stickyScrolling_changed(int state);
 
 private:
        DeviceManager &device_manager_;
 
 private:
        DeviceManager &device_manager_;
index d24822413038c5a63be439c1d1038b53fd49d1e4..2e29a1717c2092d4d643137d8930646e64f3999a 100644 (file)
@@ -23,6 +23,7 @@ namespace pv {
 
 const QString GlobalSettings::Key_View_AlwaysZoomToFit = "View_AlwaysZoomToFit";
 const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG";
 
 const QString GlobalSettings::Key_View_AlwaysZoomToFit = "View_AlwaysZoomToFit";
 const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG";
+const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling";
 
 std::multimap< QString, std::function<void(QVariant)> > GlobalSettings::callbacks_;
 bool GlobalSettings::tracking_ = false;
 
 std::multimap< QString, std::function<void(QVariant)> > GlobalSettings::callbacks_;
 bool GlobalSettings::tracking_ = false;
index 9581e294ba658518e393f7e5966324e9a92f3433..ba0e28032b18ea995feab78928ede7f334995ad6 100644 (file)
@@ -36,6 +36,7 @@ class GlobalSettings : public QSettings
 public:
        static const QString Key_View_AlwaysZoomToFit;
        static const QString Key_View_ColouredBG;
 public:
        static const QString Key_View_AlwaysZoomToFit;
        static const QString Key_View_ColouredBG;
+       static const QString Key_View_StickyScrolling;
 
 public:
        GlobalSettings();
 
 public:
        GlobalSettings();
index d8247825d47c9c01ae818760b63b75679644112d..9164c6e82ac0e330623ff8105db4a6c92a311d24 100644 (file)
@@ -86,6 +86,8 @@ MainWindow::MainWindow(DeviceManager &device_manager,
 
        GlobalSettings::register_change_handler(GlobalSettings::Key_View_ColouredBG,
                bind(&MainWindow::on_settingViewColouredBg_changed, this, _1));
 
        GlobalSettings::register_change_handler(GlobalSettings::Key_View_ColouredBG,
                bind(&MainWindow::on_settingViewColouredBg_changed, this, _1));
+       GlobalSettings::register_change_handler(GlobalSettings::Key_View_StickyScrolling,
+               bind(&MainWindow::on_settingViewStickyScrolling_changed, this, _1));
 
        setup_ui();
        restore_ui_settings();
 
        setup_ui();
        restore_ui_settings();
@@ -717,15 +719,6 @@ void MainWindow::on_tab_close_requested(int index)
                remove_session(session);
 }
 
                remove_session(session);
 }
 
-void MainWindow::on_view_sticky_scrolling_shortcut()
-{
-       shared_ptr<views::ViewBase> viewbase = get_active_view();
-       views::TraceView::View* view =
-               qobject_cast<views::TraceView::View*>(viewbase.get());
-       if (view)
-               view->toggle_sticky_scrolling();
-}
-
 void MainWindow::on_view_coloured_bg_shortcut()
 {
        GlobalSettings settings;
 void MainWindow::on_view_coloured_bg_shortcut()
 {
        GlobalSettings settings;
@@ -734,6 +727,14 @@ void MainWindow::on_view_coloured_bg_shortcut()
        settings.setValue(GlobalSettings::Key_View_ColouredBG, !state);
 }
 
        settings.setValue(GlobalSettings::Key_View_ColouredBG, !state);
 }
 
+void MainWindow::on_view_sticky_scrolling_shortcut()
+{
+       GlobalSettings settings;
+
+       bool state = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
+       settings.setValue(GlobalSettings::Key_View_StickyScrolling, !state);
+}
+
 void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value)
 {
        bool state = new_value.toBool();
 void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value)
 {
        bool state = new_value.toBool();
@@ -749,6 +750,21 @@ void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value)
        }
 }
 
        }
 }
 
+void MainWindow::on_settingViewStickyScrolling_changed(const QVariant new_value)
+{
+       bool state = new_value.toBool();
+
+       for (auto entry : view_docks_) {
+               shared_ptr<views::ViewBase> viewbase = entry.second;
+
+               // Only trace views have this setting
+               views::TraceView::View* view =
+                               qobject_cast<views::TraceView::View*>(viewbase.get());
+               if (view)
+                       view->enable_sticky_scrolling(state);
+       }
+}
+
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
index e3a51c6d88f5b32a62c2801eed7c743e3b33d4bf..50708c2035a9f1069545292e03a50d3f6017e34d 100644 (file)
@@ -121,10 +121,11 @@ private Q_SLOTS:
        void on_tab_changed(int index);
        void on_tab_close_requested(int index);
 
        void on_tab_changed(int index);
        void on_tab_close_requested(int index);
 
-       void on_view_sticky_scrolling_shortcut();
        void on_view_coloured_bg_shortcut();
        void on_view_coloured_bg_shortcut();
+       void on_view_sticky_scrolling_shortcut();
 
        void on_settingViewColouredBg_changed(const QVariant new_value);
 
        void on_settingViewColouredBg_changed(const QVariant new_value);
+       void on_settingViewStickyScrolling_changed(const QVariant new_value);
 
        void on_close_current_tab();
 
 
        void on_close_current_tab();
 
index cc0ceb79cabfadaa68fa1396997de3ba79930b78..d47b4fd15315d61fe33d46ab9d11087954702114 100644 (file)
@@ -567,11 +567,6 @@ void View::enable_sticky_scrolling(bool state)
        sticky_scrolling_ = state;
 }
 
        sticky_scrolling_ = state;
 }
 
-void View::toggle_sticky_scrolling()
-{
-       sticky_scrolling_ = !sticky_scrolling_;
-}
-
 void View::enable_coloured_bg(bool state)
 {
        const vector<shared_ptr<TraceTreeItem>> items(
 void View::enable_coloured_bg(bool state)
 {
        const vector<shared_ptr<TraceTreeItem>> items(
index c289cfcb00ce93060d42c5095ba18a689444972d..930f6cd2b560c26b32fd96ede652b5e32a39ca0e 100644 (file)
@@ -205,11 +205,6 @@ public:
         */
        void enable_sticky_scrolling(bool state);
 
         */
        void enable_sticky_scrolling(bool state);
 
-       /**
-        * Toggle sticky scrolling.
-        */
-       void toggle_sticky_scrolling(void);
-
        /**
         * Enables or disables coloured trace backgrounds. If they're not
         * coloured then they will use alternating colors.
        /**
         * Enables or disables coloured trace backgrounds. If they're not
         * coloured then they will use alternating colors.