Add a hotkey to show/hide sampling points.
authorUwe Hermann <uwe@hermann-uwe.de>
Fri, 17 Mar 2017 19:47:36 +0000 (20:47 +0100)
committerUwe Hermann <uwe@hermann-uwe.de>
Fri, 17 Mar 2017 22:56:05 +0000 (23:56 +0100)
This is also hooked up into the global settings, so it will be
persistent across multiple PulseView runs.

This fixes (parts of) bug #485.

doc/pulseview.1
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/view/logicsignal.cpp
pv/view/view.cpp
pv/view/view.hpp

index d9238bb56201d9de7f1069b2cd5f50375d692049..4068e6f4ead816e7b2e9814f829efb6f4d06b8bc 100644 (file)
@@ -59,6 +59,9 @@ Zoom 1:1.
 .B "s"
 Enable / disable sticky scrolling.
 .TP
+.B "."
+Show / hide sampling points.
+.TP
 .B "c"
 Show / hide cursors.
 .TP
index 214ac9cf26e862aefd4208a4da84d685709d2655..068d99b3108ead8c35a5c2dce0e1884a096f6d9d 100644 (file)
@@ -133,6 +133,11 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
        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);
 
+       QCheckBox *show_sampling_points_cb = new QCheckBox();
+       show_sampling_points_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
+       connect(show_sampling_points_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showSamplingPoints_changed(int)));
+       trace_view_layout->addRow(tr("Show data &sampling points"), show_sampling_points_cb);
+
        return form;
 }
 
@@ -260,6 +265,11 @@ void Settings::on_view_stickyScrolling_changed(int state)
        settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
 }
 
+void Settings::on_view_showSamplingPoints_changed(int state)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
+}
 
 } // namespace dialogs
 } // namespace pv
index b204d683ad24829edcfa6f94084206d7bf289d86..741856fce758e3e67626ca094fad56627b0087f8 100644 (file)
@@ -50,6 +50,7 @@ private Q_SLOTS:
        void on_view_alwaysZoomToFit_changed(int state);
        void on_view_colouredBG_changed(int state);
        void on_view_stickyScrolling_changed(int state);
+       void on_view_showSamplingPoints_changed(int state);
 
 private:
        DeviceManager &device_manager_;
index 2e29a1717c2092d4d643137d8930646e64f3999a..e0b7197b966c4c1f1f1841c0651f4d85823e9cd7 100644 (file)
@@ -24,6 +24,7 @@ namespace pv {
 const QString GlobalSettings::Key_View_AlwaysZoomToFit = "View_AlwaysZoomToFit";
 const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG";
 const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling";
+const QString GlobalSettings::Key_View_ShowSamplingPoints = "View_ShowSamplingPoints";
 
 std::multimap< QString, std::function<void(QVariant)> > GlobalSettings::callbacks_;
 bool GlobalSettings::tracking_ = false;
index ba0e28032b18ea995feab78928ede7f334995ad6..1b6560f99bfa4d1a451ae3e11b01731f4141224c 100644 (file)
@@ -37,6 +37,7 @@ public:
        static const QString Key_View_AlwaysZoomToFit;
        static const QString Key_View_ColouredBG;
        static const QString Key_View_StickyScrolling;
+       static const QString Key_View_ShowSamplingPoints;
 
 public:
        GlobalSettings();
index 4e6ab75d9502b190e85e3823d839261fa36134f5..b6cca7b2edadb99d8313b7d92ccbf4313c028386 100644 (file)
@@ -87,6 +87,9 @@ 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_ShowSamplingPoints,
+               bind(&MainWindow::on_settingViewShowSamplingPoints_changed, this, _1));
+
        setup_ui();
        restore_ui_settings();
 
@@ -203,6 +206,7 @@ shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
                        qobject_cast<views::TraceView::View*>(v.get());
 
                tv->enable_coloured_bg(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
+               tv->enable_show_sampling_points(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
 
                if (!main_bar) {
                        /* Initial view, create the main bar */
@@ -343,6 +347,9 @@ void MainWindow::setup_ui()
        view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut()));
        view_sticky_scrolling_shortcut_->setAutoRepeat(false);
 
+       view_show_sampling_points_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Period), this, SLOT(on_view_show_sampling_points_shortcut()));
+       view_show_sampling_points_shortcut_->setAutoRepeat(false);
+
        view_coloured_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_coloured_bg_shortcut()));
        view_coloured_bg_shortcut_->setAutoRepeat(false);
 
@@ -732,6 +739,14 @@ void MainWindow::on_view_sticky_scrolling_shortcut()
        settings.setValue(GlobalSettings::Key_View_StickyScrolling, !state);
 }
 
+void MainWindow::on_view_show_sampling_points_shortcut()
+{
+       GlobalSettings settings;
+
+       bool state = settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
+       settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, !state);
+}
+
 void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value)
 {
        bool state = new_value.toBool();
@@ -747,6 +762,21 @@ void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value)
        }
 }
 
+void MainWindow::on_settingViewShowSamplingPoints_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_show_sampling_points(state);
+       }
+}
+
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
index a99e0adf9c7b4604c8b04c22869c45805531890a..90e915033b8bab19490a3614fbc3b5bc513e6fe5 100644 (file)
@@ -123,8 +123,10 @@ private Q_SLOTS:
 
        void on_view_coloured_bg_shortcut();
        void on_view_sticky_scrolling_shortcut();
+       void on_view_show_sampling_points_shortcut();
 
        void on_settingViewColouredBg_changed(const QVariant new_value);
+       void on_settingViewShowSamplingPoints_changed(const QVariant new_value);
 
        void on_close_current_tab();
 
@@ -148,6 +150,7 @@ private:
        QIcon icon_grey_;
 
        QShortcut *view_sticky_scrolling_shortcut_;
+       QShortcut *view_show_sampling_points_shortcut_;
        QShortcut *view_coloured_bg_shortcut_;
        QShortcut *run_stop_shortcut_;
        QShortcut *close_application_shortcut_;
index d4fac8b567d5ee10b9a86626e0eeb77adfe36a7e..ea8fd510d9401e98324f5e0daefcc15ffb8e1614 100644 (file)
@@ -38,6 +38,7 @@
 #include <pv/data/logicsegment.hpp>
 #include <pv/data/signalbase.hpp>
 #include <pv/view/view.hpp>
+#include <pv/globalsettings.hpp>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
@@ -229,6 +230,13 @@ void LogicSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
 
        delete[] cap_lines;
 
+       // Return if we don't need to paint the sampling points
+       GlobalSettings settings;
+       const bool show_sampling_points =
+               settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
+       if (!show_sampling_points)
+               return;
+
        // Paint the sampling points
        const uint64_t sampling_points_count = end_sample - start_sample + 1;
        QRectF *const sampling_points = new QRectF[sampling_points_count];
index 8595594803b58f21b3c33f439e51b69358d149ae..07e97666a2e60e59acd4309b17f294a28df37609 100644 (file)
@@ -562,6 +562,13 @@ pair<Timestamp, Timestamp> View::get_time_extents() const
        return make_pair(*left_time, *right_time);
 }
 
+void View::enable_show_sampling_points(bool state)
+{
+       (void)state;
+
+       viewport_->update();
+}
+
 void View::enable_coloured_bg(bool state)
 {
        const vector<shared_ptr<TraceTreeItem>> items(
index 1d63417cb89ab520dd7c43e07cfaf72f3b6240fd..2ba157d8c5ea9cedecca3338c86908855ca215c0 100644 (file)
@@ -205,6 +205,11 @@ public:
         */
        void enable_coloured_bg(bool state);
 
+       /**
+        * Enable or disable showing sampling points.
+        */
+       void enable_show_sampling_points(bool state);
+
        /**
         * Returns true if cursors are displayed. false otherwise.
         */