From: Uwe Hermann Date: Fri, 17 Mar 2017 19:47:36 +0000 (+0100) Subject: Add a hotkey to show/hide sampling points. X-Git-Tag: pulseview-0.4.0~147 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=051ba3b399abbd83fea8b7ef6f8876884ac0786c;p=pulseview.git Add a hotkey to show/hide sampling points. This is also hooked up into the global settings, so it will be persistent across multiple PulseView runs. This fixes (parts of) bug #485. --- diff --git a/doc/pulseview.1 b/doc/pulseview.1 index d9238bb5..4068e6f4 100644 --- a/doc/pulseview.1 +++ b/doc/pulseview.1 @@ -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 diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 214ac9cf..068d99b3 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -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 diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index b204d683..741856fc 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -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_; diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 2e29a171..e0b7197b 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -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 > GlobalSettings::callbacks_; bool GlobalSettings::tracking_ = false; diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index ba0e2803..1b6560f9 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -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(); diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 4e6ab75d..b6cca7b2 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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 MainWindow::add_view(const QString &title, qobject_cast(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 viewbase = entry.second; + + // Only trace views have this setting + views::TraceView::View* view = + qobject_cast(viewbase.get()); + if (view) + view->enable_show_sampling_points(state); + } +} + void MainWindow::on_close_current_tab() { int tab = session_selector_.currentIndex(); diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index a99e0adf..90e91503 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -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_; diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index d4fac8b5..ea8fd510 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -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]; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 85955948..07e97666 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -562,6 +562,13 @@ pair 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> items( diff --git a/pv/view/view.hpp b/pv/view/view.hpp index 1d63417c..2ba157d8 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -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. */