+void MainWindow::on_session_name_changed()
+{
+ // Update the corresponding dock widget's name(s)
+ Session *session = qobject_cast<Session*>(QObject::sender());
+ assert(session);
+
+ for (const 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_session_device_changed()
+{
+ Session *session = qobject_cast<Session*>(QObject::sender());
+ assert(session);
+
+ // Ignore if caller is not the currently focused session
+ // unless there is only one session
+ if ((sessions_.size() > 1) && (session != last_focused_session_.get()))
+ return;
+
+ update_acq_button(session);
+}
+
+void MainWindow::on_session_capture_state_changed(int state)
+{
+ (void)state;
+
+ Session *session = qobject_cast<Session*>(QObject::sender());
+ assert(session);
+
+ // Ignore if caller is not the currently focused session
+ // unless there is only one session
+ if ((sessions_.size() > 1) && (session != last_focused_session_.get()))
+ return;
+
+ update_acq_button(session);
+}
+
+void MainWindow::on_new_view(Session *session, int view_type)
+{
+ // We get a pointer and need a reference
+ for (shared_ptr<Session>& s : sessions_)
+ if (s.get() == session)
+ add_view((views::ViewType)view_type, *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_show_decoder_selector(Session *session)
+{
+#ifdef ENABLE_DECODE
+ // Close dock widget if it's already showing and return
+ for (auto& entry : sub_windows_) {
+ QDockWidget* dock = entry.first;
+ shared_ptr<subwindows::SubWindowBase> decoder_selector =
+ dynamic_pointer_cast<subwindows::decoder_selector::SubWindow>(entry.second);
+
+ if (decoder_selector && (&decoder_selector->session() == session)) {
+ sub_windows_.erase(dock);
+ dock->close();
+ return;
+ }
+ }
+
+ // We get a pointer and need a reference
+ for (shared_ptr<Session>& s : sessions_)
+ if (s.get() == session)
+ add_subwindow(subwindows::SubWindowTypeDecoderSelector, *s);
+#endif
+}
+
+void MainWindow::on_sub_window_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();
+ }
+
+ sub_windows_.erase(dock);
+ dock->close();
+
+ // Restore focus to the last used main view
+ if (last_focused_session_)
+ last_focused_session_->main_view()->setFocus();
+}
+
+void MainWindow::on_view_colored_bg_shortcut()
+{
+ GlobalSettings settings;
+
+ bool state = settings.value(GlobalSettings::Key_View_ColoredBG).toBool();
+ settings.setValue(GlobalSettings::Key_View_ColoredBG, !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_close_current_tab()
+{
+ int tab = session_selector_.currentIndex();
+
+ on_tab_close_requested(tab);
+}
+