+void MainWindow::on_session_name_changed()
+{
+ // Update the corresponding dock widget's name(s)
+ Session *session = qobject_cast<Session*>(QObject::sender());
+ assert(session);
+
+ for (shared_ptr<views::ViewBase> view : session->views()) {
+ // Get the dock that contains the view
+ for (auto entry : view_docks_)
+ if (entry.second == view) {
+ entry.first->setObjectName(session->name());
+ entry.first->setWindowTitle(session->name());
+ }
+ }
+
+ // Update the tab widget by finding the main window and the tab from that
+ for (auto entry : session_windows_)
+ if (entry.first.get() == session) {
+ QMainWindow *window = entry.second;
+ const int index = session_selector_.indexOf(window);
+ session_selector_.setTabText(index, session->name());
+ }
+
+ // Refresh window title if the affected session has focus
+ if (session == last_focused_session_.get())
+ setWindowTitle(session->name() + " - " + WindowTitle);
+}
+
+void MainWindow::on_capture_state_changed(QObject *obj)
+{
+ Session *caller = qobject_cast<Session*>(obj);
+
+ // Ignore if caller is not the currently focused session
+ // unless there is only one session
+ if ((sessions_.size() > 1) && (caller != last_focused_session_.get()))
+ return;
+
+ int state = caller->get_capture_state();
+
+ const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_};
+ run_stop_button_->setIcon(*icons[state]);
+ run_stop_button_->setText((state == pv::Session::Stopped) ?
+ tr("Run") : tr("Stop"));
+}
+
+void MainWindow::on_new_view(Session *session)
+{
+ // We get a pointer and need a reference
+ for (shared_ptr<Session> s : sessions_)
+ if (s.get() == session)
+ add_view(session->name(), views::ViewTypeTrace, *s);
+}
+
+void MainWindow::on_view_close_clicked()
+{
+ // Find the dock widget that contains the close button that was clicked
+ QObject *w = QObject::sender();
+ QDockWidget *dock = nullptr;
+
+ while (w) {
+ dock = qobject_cast<QDockWidget*>(w);
+ if (dock)
+ break;
+ w = w->parent();
+ }
+
+ // Get the view contained in the dock widget
+ shared_ptr<views::ViewBase> view;
+
+ for (auto entry : view_docks_)
+ if (entry.first == dock)
+ view = entry.second;
+
+ // Deregister the view
+ for (shared_ptr<Session> session : sessions_) {
+ if (!session->has_view(view))
+ continue;
+
+ // Also destroy the entire session if its main view is closing...
+ if (view == session->main_view()) {
+ // ...but only if data is saved or the user confirms closing
+ if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
+ tr("This session contains unsaved data. Close it anyway?"),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
+ remove_session(session);
+ break;
+ } else
+ // All other views can be closed at any time as no data will be lost
+ remove_view(view);
+ }
+}
+
+void MainWindow::on_tab_changed(int index)
+{
+ shared_ptr<Session> session = get_tab_session(index);
+
+ if (session)
+ on_focused_session_changed(session);
+}
+
+void MainWindow::on_tab_close_requested(int index)
+{
+ shared_ptr<Session> session = get_tab_session(index);
+
+ if (!session)
+ return;
+
+ if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
+ tr("This session contains unsaved data. Close it anyway?"),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
+ remove_session(session);
+}
+
+void MainWindow::on_view_coloured_bg_shortcut()
+{
+ GlobalSettings settings;
+
+ bool state = settings.value(GlobalSettings::Key_View_ColouredBG).toBool();
+ settings.setValue(GlobalSettings::Key_View_ColouredBG, !state);
+}
+
+void MainWindow::on_view_sticky_scrolling_shortcut()
+{
+ GlobalSettings settings;
+
+ bool state = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
+ 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_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();
+
+ for (auto entry : view_docks_) {
+ shared_ptr<views::ViewBase> viewbase = entry.second;
+
+ // Only trace views have this setting
+ views::trace::View* view =
+ qobject_cast<views::trace::View*>(viewbase.get());
+ if (view)
+ view->enable_coloured_bg(state);
+ }
+}
+
+void MainWindow::on_settingViewShowSamplingPoints_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::trace::View* view =
+ qobject_cast<views::trace::View*>(viewbase.get());
+ if (view)
+ view->enable_show_sampling_points(state);
+ }
+}
+
+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::trace::View* view =
+ qobject_cast<views::trace::View*>(viewbase.get());
+ if (view)
+ view->enable_show_analog_minor_grid(state);
+ }
+}
+
+void MainWindow::on_close_current_tab()
+{
+ int tab = session_selector_.currentIndex();
+
+ on_tab_close_requested(tab);
+}
+