diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -63,6 +63,20 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::close); + QObject::connect(ui->actionGrid, &QAction::toggled, [this](bool show) + { + ui->plot->showGrid(show); + ui->actionMinorGrid->setEnabled(show); + }); + + ui->actionMinorGrid->setEnabled(ui->actionGrid->isChecked()); + QObject::connect(ui->actionMinorGrid, &QAction::toggled, + ui->plot, &Plot::showMinorGrid); + + QObject::connect(ui->actionUnzoom, &QAction::triggered, + ui->plot, &Plot::unzoom); + + // port control signals QObject::connect(&portControl, &PortControl::portToggled, this, &MainWindow::onPortToggled); @@ -138,6 +152,10 @@ MainWindow::MainWindow(QWidget *parent) ui->plot->setAxis(ui->cbAutoScale->isChecked(), ui->spYmin->value(), ui->spYmax->value()); + // init grid + ui->plot->showGrid(ui->actionGrid->isChecked()); + ui->plot->showMinorGrid(ui->actionMinorGrid->isChecked()); + // init number format if (numberFormatButtons.checkedId() >= 0) { diff --git a/mainwindow.ui b/mainwindow.ui --- a/mainwindow.ui +++ b/mainwindow.ui @@ -469,7 +469,16 @@ + + + View + + + + + + @@ -534,6 +543,33 @@ Ctrl+Q + + + true + + + Grid + + + Show/hide grid + + + + + UnZoom + + + + + true + + + Minor Grid + + + Show/hide minor grid + + diff --git a/plot.cpp b/plot.cpp --- a/plot.cpp +++ b/plot.cpp @@ -65,3 +65,22 @@ void Plot::unzoomed() setAxisAutoScale(QwtPlot::xBottom); resetAxes(); } + +void Plot::showGrid(bool show) +{ + grid.enableX(show); + grid.enableY(show); + replot(); +} + +void Plot::showMinorGrid(bool show) +{ + grid.enableXMin(show); + grid.enableYMin(show); + replot(); +} + +void Plot::unzoom() +{ + zoomer.zoom(0); +} diff --git a/plot.h b/plot.h --- a/plot.h +++ b/plot.h @@ -37,6 +37,11 @@ private: void resetAxes(); +public slots: + void showGrid(bool show = true); + void showMinorGrid(bool show = true); + void unzoom(); + private slots: void unzoomed(); };