]> sigrok.org Git - pulseview.git/commitdiff
Add a hotkey and setting for showing/hiding the minor analog grid.
authorUwe Hermann <redacted>
Fri, 31 Mar 2017 06:27:28 +0000 (08:27 +0200)
committerUwe Hermann <redacted>
Fri, 31 Mar 2017 17:32:51 +0000 (19:32 +0200)
The vdiv grid is always shown and is what most users will expect. The
additional "minor" grid could be confusing, so make that configurable.

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/analogsignal.cpp
pv/view/view.cpp
pv/view/view.hpp

index 4068e6f4ead816e7b2e9814f829efb6f4d06b8bc..936fe8ac6d453384a96c1dedbea1a9f3d75e3174 100644 (file)
@@ -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
index a00351bc074a7721d5f4282a53281dbe4ff42513..e221e5627c2b337c2dc797151a34947fa77844ee 100644 (file)
@@ -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
index ee04e2b3c3284ec99196109fa2c8df9b2dc63cb2..0bda0f76d20434cf7b2b8ee233b4f47bd071e0c6 100644 (file)
@@ -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_;
index 7bd77f69b2ae2ec06ea5157449487efea5ec4ee3..925c48e1dff67826a0d52a038fee091a2d00479d 100644 (file)
@@ -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<void(QVariant)> > GlobalSettings::callbacks_;
 bool GlobalSettings::tracking_ = false;
index 45247377391267eada5bb5438ce841870022c3ee..1c07c308d71a5170e9c227a251fa14238aafde01 100644 (file)
@@ -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();
index 5c399e43c38d1523abe748e52cb9c0d44039d792..d13c8e197e3bfc917cd0ec697fbdfe72c54a2947 100644 (file)
@@ -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<views::ViewBase> 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<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_analog_minor_grid(state);
+       }
+}
+
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
index a0a6d3375b0f5225b97ced6c27b8a0fe1c12bd01..6541ccc6dff181e2cf386ed75657f5c0ecf11d1c 100644 (file)
@@ -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_;
index a15861c88d0ecfd8e4649389762dea8312dae754..906bbabb71a827746e5eb7b1aef39a89b3f28d76 100644 (file)
@@ -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_;
index 0e3fa98fffc4b91b8f94af291c179ed20314724c..8f5494acea39b4e0c449c9e2976e3ac589b0aaf1 100644 (file)
@@ -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<shared_ptr<TraceTreeItem>> items(
index 05d9d60193a00c2b7120f4a8dca1b4719c9d63a4..08b8a37e51498db342eb82d5ce1ab4b67e4b884e 100644 (file)
@@ -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.
         */