From: Joel Holdsworth Date: Mon, 2 Dec 2013 21:03:14 +0000 (+0000) Subject: Implemented zoom-fit X-Git-Tag: pulseview-0.2.0~198 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ca46b5342f79e4786b973c83ed6a4cde5a51908d;p=pulseview.git Implemented zoom-fit --- diff --git a/pulseview.qrc b/pulseview.qrc index a7108b48..6830e00d 100644 --- a/pulseview.qrc +++ b/pulseview.qrc @@ -15,6 +15,7 @@ icons/trigger-low.svg icons/trigger-none.svg icons/trigger-rising.svg + icons/zoom-fit.png icons/zoom-in.png icons/zoom-out.png diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 45e804db..5485ea75 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -160,6 +160,16 @@ void MainWindow::setup_ui() QString::fromUtf8("actionViewZoomOut")); menu_view->addAction(action_view_zoom_out); + QAction *const action_view_zoom_fit = new QAction(this); + action_view_zoom_fit->setText(QApplication::translate( + "MainWindow", "Zoom to &Fit", 0, QApplication::UnicodeUTF8)); + action_view_zoom_fit->setIcon(QIcon::fromTheme("zoom-fit", + QIcon(":/icons/zoom-fit.png"))); + action_view_zoom_fit->setShortcut(QKeySequence(Qt::Key_F)); + action_view_zoom_fit->setObjectName( + QString::fromUtf8("actionViewZoomFit")); + menu_view->addAction(action_view_zoom_fit); + menu_view->addSeparator(); QAction *action_view_show_cursors = new QAction(this); @@ -211,6 +221,7 @@ void MainWindow::setup_ui() toolbar->addSeparator(); toolbar->addAction(action_view_zoom_in); toolbar->addAction(action_view_zoom_out); + toolbar->addAction(action_view_zoom_fit); addToolBar(toolbar); // Setup the sampling bar @@ -329,6 +340,11 @@ void MainWindow::on_actionViewZoomOut_triggered() _view->zoom(-1); } +void MainWindow::on_actionViewZoomFit_triggered() +{ + _view->zoom_fit(); +} + void MainWindow::on_actionViewShowCursors_triggered() { assert(_view); diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 88f62729..8895a5e7 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -89,6 +89,8 @@ private slots: void on_actionViewZoomOut_triggered(); + void on_actionViewZoomFit_triggered(); + void on_actionViewShowCursors_triggered(); void on_actionAbout_triggered(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 4cfb3978..abf522c0 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -153,6 +155,43 @@ void View::zoom(double steps, int offset) set_scale_offset(new_scale, new_offset); } +void View::zoom_fit() +{ + using pv::data::SignalData; + + const vector< shared_ptr > sigs( + session().get_signals()); + + // Make a set of all the visible data objects + set< shared_ptr > visible_data; + BOOST_FOREACH(const shared_ptr sig, sigs) + if (sig->enabled()) + visible_data.insert(sig->data()); + + if (visible_data.empty()) + return; + + double left_time = DBL_MAX, right_time = DBL_MIN; + BOOST_FOREACH(const shared_ptr d, visible_data) + { + const double start_time = d->get_start_time(); + left_time = min(left_time, start_time); + right_time = max(right_time, start_time + + d->get_max_sample_count() / d->get_samplerate()); + } + + assert(left_time < right_time); + if (right_time - left_time < 1e-12) + return; + + assert(_viewport); + const int w = _viewport->width(); + if (w <= 0) + return; + + set_scale_offset((right_time - left_time) / w, left_time); +} + void View::set_scale_offset(double scale, double offset) { _scale = scale; diff --git a/pv/view/view.h b/pv/view/view.h index c25ed78a..bc99bdd7 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -86,6 +86,8 @@ public: void zoom(double steps); void zoom(double steps, int offset); + void zoom_fit(); + /** * Sets the scale and offset. * @param scale The new view scale in seconds per pixel.