From: Uwe Hermann Date: Fri, 31 Mar 2017 06:27:28 +0000 (+0200) Subject: Add a hotkey and setting for showing/hiding the minor analog grid. X-Git-Tag: pulseview-0.4.0~103 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=8ad61f4071a69445a6917d214b6592878447ddb1 Add a hotkey and setting for showing/hiding the minor analog grid. The vdiv grid is always shown and is what most users will expect. The additional "minor" grid could be confusing, so make that configurable. --- diff --git a/doc/pulseview.1 b/doc/pulseview.1 index 4068e6f4..936fe8ac 100644 --- a/doc/pulseview.1 +++ b/doc/pulseview.1 @@ -62,6 +62,9 @@ Enable / disable sticky scrolling. .B "." Show / hide sampling points. .TP +.B "g" +Show / hide analog minor grid (in addition to the vdiv grid). +.TP .B "c" Show / hide cursors. .TP diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index a00351bc..e221e562 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -140,6 +140,11 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const 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); + QCheckBox *show_analog_minor_grid_cb = new QCheckBox(); + show_analog_minor_grid_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool()); + connect(show_analog_minor_grid_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showAnalogMinorGrid_changed(int))); + trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), show_analog_minor_grid_cb); + return form; } @@ -275,5 +280,11 @@ void Settings::on_view_showSamplingPoints_changed(int state) settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false); } +void Settings::on_view_showAnalogMinorGrid_changed(int state) +{ + GlobalSettings settings; + settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false); +} + } // namespace dialogs } // namespace pv diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index ee04e2b3..0bda0f76 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -51,6 +51,7 @@ private Q_SLOTS: void on_view_colouredBG_changed(int state); void on_view_stickyScrolling_changed(int state); void on_view_showSamplingPoints_changed(int state); + void on_view_showAnalogMinorGrid_changed(int state); private: DeviceManager &device_manager_; diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 7bd77f69..925c48e1 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -29,6 +29,7 @@ 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"; +const QString GlobalSettings::Key_View_ShowAnalogMinorGrid = "View_ShowAnalogMinorGrid"; multimap< QString, function > GlobalSettings::callbacks_; bool GlobalSettings::tracking_ = false; diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index 45247377..1c07c308 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -42,6 +42,7 @@ public: static const QString Key_View_ColouredBG; static const QString Key_View_StickyScrolling; static const QString Key_View_ShowSamplingPoints; + static const QString Key_View_ShowAnalogMinorGrid; public: GlobalSettings(); diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 5c399e43..d13c8e19 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -88,6 +88,9 @@ MainWindow::MainWindow(DeviceManager &device_manager, GlobalSettings::register_change_handler(GlobalSettings::Key_View_ShowSamplingPoints, bind(&MainWindow::on_settingViewShowSamplingPoints_changed, this, _1)); + GlobalSettings::register_change_handler(GlobalSettings::Key_View_ShowAnalogMinorGrid, + bind(&MainWindow::on_settingViewShowAnalogMinorGrid_changed, this, _1)); + setup_ui(); restore_ui_settings(); @@ -205,6 +208,7 @@ shared_ptr MainWindow::add_view(const QString &title, tv->enable_coloured_bg(settings.value(GlobalSettings::Key_View_ColouredBG).toBool()); tv->enable_show_sampling_points(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool()); + tv->enable_show_analog_minor_grid(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool()); if (!main_bar) { /* Initial view, create the main bar */ @@ -348,6 +352,9 @@ void MainWindow::setup_ui() 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_show_analog_minor_grid_shortcut_ = new QShortcut(QKeySequence(Qt::Key_G), this, SLOT(on_view_show_analog_minor_grid_shortcut())); + view_show_analog_minor_grid_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); @@ -745,6 +752,14 @@ void MainWindow::on_view_show_sampling_points_shortcut() settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, !state); } +void MainWindow::on_view_show_analog_minor_grid_shortcut() +{ + GlobalSettings settings; + + bool state = settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool(); + settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, !state); +} + void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value) { bool state = new_value.toBool(); @@ -775,6 +790,21 @@ void MainWindow::on_settingViewShowSamplingPoints_changed(const QVariant new_val } } +void MainWindow::on_settingViewShowAnalogMinorGrid_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_analog_minor_grid(state); + } +} + void MainWindow::on_close_current_tab() { int tab = session_selector_.currentIndex(); diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index a0a6d337..6541ccc6 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -129,9 +129,11 @@ private Q_SLOTS: void on_view_coloured_bg_shortcut(); void on_view_sticky_scrolling_shortcut(); void on_view_show_sampling_points_shortcut(); + void on_view_show_analog_minor_grid_shortcut(); void on_settingViewColouredBg_changed(const QVariant new_value); void on_settingViewShowSamplingPoints_changed(const QVariant new_value); + void on_settingViewShowAnalogMinorGrid_changed(const QVariant new_value); void on_close_current_tab(); @@ -156,6 +158,7 @@ private: QShortcut *view_sticky_scrolling_shortcut_; QShortcut *view_show_sampling_points_shortcut_; + QShortcut *view_show_analog_minor_grid_shortcut_; QShortcut *view_coloured_bg_shortcut_; QShortcut *run_stop_shortcut_; QShortcut *close_application_shortcut_; diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index a15861c8..906bbabb 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -264,13 +264,19 @@ void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right) { p.setRenderHint(QPainter::Antialiasing, false); + GlobalSettings settings; + const bool show_analog_minor_grid = + settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool(); + if (pos_vdivs_ > 0) { p.setPen(QPen(GridMajorColor, 1, Qt::DashLine)); for (int i = 1; i <= pos_vdivs_; i++) { const float dy = i * div_height_; p.drawLine(QLineF(left, y - dy, right, y - dy)); } + } + if ((pos_vdivs_ > 0) && show_analog_minor_grid) { p.setPen(QPen(GridMinorColor, 1, Qt::DashLine)); for (int i = 0; i < pos_vdivs_; i++) { const float dy = i * div_height_; @@ -289,7 +295,9 @@ void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right) const float dy = i * div_height_; p.drawLine(QLineF(left, y + dy, right, y + dy)); } + } + if ((pos_vdivs_ > 0) && show_analog_minor_grid) { p.setPen(QPen(GridMinorColor, 1, Qt::DashLine)); for (int i = 0; i < neg_vdivs_; i++) { const float dy = i * div_height_; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 0e3fa98f..8f5494ac 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -561,6 +561,13 @@ void View::enable_show_sampling_points(bool state) viewport_->update(); } +void View::enable_show_analog_minor_grid(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 05d9d601..08b8a37e 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -217,6 +217,11 @@ public: */ void enable_show_sampling_points(bool state); + /** + * Enable or disable showing the analog minor grid. + */ + void enable_show_analog_minor_grid(bool state); + /** * Returns true if cursors are displayed. false otherwise. */