2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <libsigrokdecode/libsigrokdecode.h>
31 #include <QApplication>
32 #include <QCloseEvent>
34 #include <QDockWidget>
35 #include <QHBoxLayout>
36 #include <QMessageBox>
41 #include "mainwindow.hpp"
43 #include "devicemanager.hpp"
44 #include "devices/hardwaredevice.hpp"
45 #include "dialogs/settings.hpp"
46 #include "globalsettings.hpp"
47 #include "toolbars/mainbar.hpp"
49 #include "views/trace/view.hpp"
50 #include "views/trace/standardbar.hpp"
53 #include "subwindows/decoder_selector/subwindow.hpp"
54 #include "views/decoder_output/view.hpp"
57 #include <libsigrokcxx/libsigrokcxx.hpp>
59 using std::dynamic_pointer_cast;
60 using std::make_shared;
61 using std::shared_ptr;
66 using toolbars::MainBar;
68 const QString MainWindow::WindowTitle = tr("PulseView");
70 MainWindow::MainWindow(DeviceManager &device_manager, QWidget *parent) :
72 device_manager_(device_manager),
73 session_selector_(this),
74 icon_red_(":/icons/status-red.svg"),
75 icon_green_(":/icons/status-green.svg"),
76 icon_grey_(":/icons/status-grey.svg")
79 restore_ui_settings();
82 MainWindow::~MainWindow()
84 // Make sure we no longer hold any shared pointers to widgets after the
85 // destructor finishes (goes for sessions and sub windows alike)
87 while (!sessions_.empty())
88 remove_session(sessions_.front());
93 void MainWindow::show_session_error(const QString text, const QString info_text)
95 // TODO Emulate noquote()
96 qDebug() << "Notifying user of session error:" << info_text;
99 msg.setText(text + "\n\n" + info_text);
100 msg.setStandardButtons(QMessageBox::Ok);
101 msg.setIcon(QMessageBox::Warning);
105 shared_ptr<views::ViewBase> MainWindow::get_active_view() const
107 // If there's only one view, use it...
108 if (view_docks_.size() == 1)
109 return view_docks_.begin()->second;
111 // ...otherwise find the dock widget the widget with focus is contained in
112 QObject *w = QApplication::focusWidget();
113 QDockWidget *dock = nullptr;
116 dock = qobject_cast<QDockWidget*>(w);
122 // Get the view contained in the dock widget
123 for (auto& entry : view_docks_)
124 if (entry.first == dock)
130 shared_ptr<views::ViewBase> MainWindow::add_view(views::ViewType type,
133 GlobalSettings settings;
134 shared_ptr<views::ViewBase> v;
136 QMainWindow *main_window = nullptr;
137 for (auto& entry : session_windows_)
138 if (entry.first.get() == &session)
139 main_window = entry.second;
143 shared_ptr<MainBar> main_bar = session.main_bar();
145 // Only use the view type in the name if it's not the main view
148 title = QString("%1 (%2)").arg(session.name(), views::ViewTypeNames[type]);
150 title = session.name();
152 QDockWidget* dock = new QDockWidget(title, main_window);
153 dock->setObjectName(title);
154 main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
156 // Insert a QMainWindow into the dock widget to allow for a tool bar
157 QMainWindow *dock_main = new QMainWindow(dock);
158 dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
160 if (type == views::ViewTypeTrace)
161 // This view will be the main view if there's no main bar yet
162 v = make_shared<views::trace::View>(session, (main_bar ? false : true), dock_main);
164 if (type == views::ViewTypeDecoderOutput)
165 v = make_shared<views::decoder_output::View>(session, false, dock_main);
171 view_docks_[dock] = v;
172 session.register_view(v);
174 dock_main->setCentralWidget(v.get());
175 dock->setWidget(dock_main);
177 dock->setContextMenuPolicy(Qt::PreventContextMenu);
178 dock->setFeatures(QDockWidget::DockWidgetMovable |
179 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
181 QAbstractButton *close_btn =
182 dock->findChildren<QAbstractButton*>("qt_dockwidget_closebutton") // clazy:exclude=detaching-temporary
185 connect(close_btn, SIGNAL(clicked(bool)),
186 this, SLOT(on_view_close_clicked()));
188 connect(&session, SIGNAL(trigger_event(int, util::Timestamp)),
189 qobject_cast<views::ViewBase*>(v.get()),
190 SLOT(trigger_event(int, util::Timestamp)));
192 if (type == views::ViewTypeTrace) {
193 views::trace::View *tv =
194 qobject_cast<views::trace::View*>(v.get());
197 /* Initial view, create the main bar */
198 main_bar = make_shared<MainBar>(session, this, tv);
199 dock_main->addToolBar(main_bar.get());
200 session.set_main_bar(main_bar);
202 connect(main_bar.get(), SIGNAL(new_view(Session*, int)),
203 this, SLOT(on_new_view(Session*, int)));
204 connect(main_bar.get(), SIGNAL(show_decoder_selector(Session*)),
205 this, SLOT(on_show_decoder_selector(Session*)));
207 main_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
209 /* For the main view we need to prevent the dock widget from
210 * closing itself when its close button is clicked. This is
211 * so we can confirm with the user first. Regular views don't
213 close_btn->disconnect(SIGNAL(clicked()), dock, SLOT(close()));
215 /* Additional view, create a standard bar */
216 pv::views::trace::StandardBar *standard_bar =
217 new pv::views::trace::StandardBar(session, this, tv);
218 dock_main->addToolBar(standard_bar);
220 standard_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
227 void MainWindow::remove_view(shared_ptr<views::ViewBase> view)
229 for (shared_ptr<Session> session : sessions_) {
230 if (!session->has_view(view))
233 // Find the dock the view is contained in and remove it
234 for (auto& entry : view_docks_)
235 if (entry.second == view) {
236 // Remove the view from the session
237 session->deregister_view(view);
239 // Remove the view from its parent; otherwise, Qt will
240 // call deleteLater() on it, which causes a double free
241 // since the shared_ptr in view_docks_ doesn't know
242 // that Qt keeps a pointer to the view around
243 view->setParent(nullptr);
245 // Delete the view's dock widget and all widgets inside it
246 entry.first->deleteLater();
248 // Remove the dock widget from the list and stop iterating
249 view_docks_.erase(entry.first);
255 shared_ptr<subwindows::SubWindowBase> MainWindow::add_subwindow(
256 subwindows::SubWindowType type, Session &session)
258 GlobalSettings settings;
259 shared_ptr<subwindows::SubWindowBase> v;
261 QMainWindow *main_window = nullptr;
262 for (auto& entry : session_windows_)
263 if (entry.first.get() == &session)
264 main_window = entry.second;
272 case subwindows::SubWindowTypeDecoderSelector:
273 title = tr("Decoder Selector");
280 QDockWidget* dock = new QDockWidget(title, main_window);
281 dock->setObjectName(title);
282 main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
284 // Insert a QMainWindow into the dock widget to allow for a tool bar
285 QMainWindow *dock_main = new QMainWindow(dock);
286 dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
289 if (type == subwindows::SubWindowTypeDecoderSelector)
290 v = make_shared<subwindows::decoder_selector::SubWindow>(session, dock_main);
296 sub_windows_[dock] = v;
297 dock_main->setCentralWidget(v.get());
298 dock->setWidget(dock_main);
300 dock->setContextMenuPolicy(Qt::PreventContextMenu);
301 dock->setFeatures(QDockWidget::DockWidgetMovable |
302 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
304 QAbstractButton *close_btn =
305 dock->findChildren<QAbstractButton*> // clazy:exclude=detaching-temporary
306 ("qt_dockwidget_closebutton").front();
308 // Allow all subwindows to be closed via ESC.
309 close_btn->setShortcut(QKeySequence(Qt::Key_Escape));
311 connect(close_btn, SIGNAL(clicked(bool)),
312 this, SLOT(on_sub_window_close_clicked()));
314 if (v->has_toolbar())
315 dock_main->addToolBar(v->create_toolbar(dock_main));
317 if (v->minimum_width() > 0)
318 dock->setMinimumSize(v->minimum_width(), 0);
323 shared_ptr<Session> MainWindow::add_session()
325 static int last_session_id = 1;
326 QString name = tr("Session %1").arg(last_session_id++);
328 shared_ptr<Session> session = make_shared<Session>(device_manager_, name);
330 connect(session.get(), SIGNAL(add_view(views::ViewType, Session*)),
331 this, SLOT(on_add_view(views::ViewType, Session*)));
332 connect(session.get(), SIGNAL(name_changed()),
333 this, SLOT(on_session_name_changed()));
334 connect(session.get(), SIGNAL(device_changed()),
335 this, SLOT(on_session_device_changed()));
336 connect(session.get(), SIGNAL(capture_state_changed(int)),
337 this, SLOT(on_session_capture_state_changed(int)));
339 sessions_.push_back(session);
341 QMainWindow *window = new QMainWindow();
342 window->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
343 session_windows_[session] = window;
345 int index = session_selector_.addTab(window, name);
346 session_selector_.setCurrentIndex(index);
347 last_focused_session_ = session;
349 window->setDockNestingEnabled(true);
351 shared_ptr<views::ViewBase> main_view = add_view(views::ViewTypeTrace, *session);
356 void MainWindow::remove_session(shared_ptr<Session> session)
358 // Determine the height of the button before it collapses
359 int h = new_session_button_->height();
361 // Stop capture while the session still exists so that the UI can be
362 // updated in case we're currently running. If so, this will schedule a
363 // call to our on_capture_state_changed() slot for the next run of the
364 // event loop. We need to have this executed immediately or else it will
365 // be dismissed since the session object will be deleted by the time we
366 // leave this method and the event loop gets a chance to run again.
367 session->stop_capture();
368 QApplication::processEvents();
370 for (const shared_ptr<views::ViewBase>& view : session->views())
373 QMainWindow *window = session_windows_.at(session);
374 session_selector_.removeTab(session_selector_.indexOf(window));
376 session_windows_.erase(session);
378 if (last_focused_session_ == session)
379 last_focused_session_.reset();
381 // Remove the session from our list of sessions (which also destroys it)
382 sessions_.remove_if([&](shared_ptr<Session> s) {
383 return s == session; });
385 if (sessions_.empty()) {
386 // When there are no more tabs, the height of the QTabWidget
387 // drops to zero. We must prevent this to keep the static
389 for (QWidget *w : static_tab_widget_->findChildren<QWidget*>()) // clazy:exclude=range-loop
390 w->setMinimumHeight(h);
392 int margin = static_tab_widget_->layout()->contentsMargins().bottom();
393 static_tab_widget_->setMinimumHeight(h + 2 * margin);
394 session_selector_.setMinimumHeight(h + 2 * margin);
396 // Update the window title if there is no view left to
397 // generate focus change events
398 setWindowTitle(WindowTitle);
402 void MainWindow::add_session_with_file(string open_file_name,
403 string open_file_format, string open_setup_file_name)
405 shared_ptr<Session> session = add_session();
406 session->load_init_file(open_file_name, open_file_format, open_setup_file_name);
409 void MainWindow::add_default_session()
411 // Only add the default session if there would be no session otherwise
412 if (sessions_.size() > 0)
415 shared_ptr<Session> session = add_session();
417 // Check the list of available devices. Prefer the one that was
418 // found with user supplied scan specs (if applicable). Then try
419 // one of the auto detected devices that are not the demo device.
420 // Pick demo in the absence of "genuine" hardware devices.
421 shared_ptr<devices::HardwareDevice> user_device, other_device, demo_device;
422 for (const shared_ptr<devices::HardwareDevice>& dev : device_manager_.devices()) {
423 if (dev == device_manager_.user_spec_device()) {
425 } else if (dev->hardware_device()->driver()->name() == "demo") {
432 session->select_device(user_device);
433 else if (other_device)
434 session->select_device(other_device);
436 session->select_device(demo_device);
439 void MainWindow::save_sessions()
444 for (shared_ptr<Session>& session : sessions_) {
445 // Ignore sessions using the demo device or no device at all
446 if (session->device()) {
447 shared_ptr<devices::HardwareDevice> device =
448 dynamic_pointer_cast< devices::HardwareDevice >
452 device->hardware_device()->driver()->name() == "demo")
455 settings.beginGroup("Session" + QString::number(id++));
456 settings.remove(""); // Remove all keys in this group
457 session->save_settings(settings);
462 settings.setValue("sessions", id);
465 void MainWindow::restore_sessions()
468 int i, session_count;
470 session_count = settings.value("sessions", 0).toInt();
472 for (i = 0; i < session_count; i++) {
473 settings.beginGroup("Session" + QString::number(i));
474 shared_ptr<Session> session = add_session();
475 session->restore_settings(settings);
480 void MainWindow::setup_ui()
482 setObjectName(QString::fromUtf8("MainWindow"));
484 setCentralWidget(&session_selector_);
486 // Set the window icon
488 icon.addFile(QString(":/icons/pulseview.png"));
491 // Set up keyboard shortcuts that affect all views at once
492 view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut()));
493 view_sticky_scrolling_shortcut_->setAutoRepeat(false);
495 view_show_sampling_points_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Period), this, SLOT(on_view_show_sampling_points_shortcut()));
496 view_show_sampling_points_shortcut_->setAutoRepeat(false);
498 view_show_analog_minor_grid_shortcut_ = new QShortcut(QKeySequence(Qt::Key_G), this, SLOT(on_view_show_analog_minor_grid_shortcut()));
499 view_show_analog_minor_grid_shortcut_->setAutoRepeat(false);
501 view_colored_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_colored_bg_shortcut()));
502 view_colored_bg_shortcut_->setAutoRepeat(false);
504 // Set up the tab area
505 new_session_button_ = new QToolButton();
506 new_session_button_->setIcon(QIcon::fromTheme("document-new",
507 QIcon(":/icons/document-new.png")));
508 new_session_button_->setToolTip(tr("Create New Session"));
509 new_session_button_->setAutoRaise(true);
511 run_stop_button_ = new QToolButton();
512 run_stop_button_->setAutoRaise(true);
513 run_stop_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
514 run_stop_button_->setToolTip(tr("Start/Stop Acquisition"));
516 run_stop_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Space), run_stop_button_, SLOT(click()));
517 run_stop_shortcut_->setAutoRepeat(false);
519 settings_button_ = new QToolButton();
520 settings_button_->setIcon(QIcon::fromTheme("preferences-system",
521 QIcon(":/icons/preferences-system.png")));
522 settings_button_->setToolTip(tr("Settings"));
523 settings_button_->setAutoRaise(true);
525 QFrame *separator1 = new QFrame();
526 separator1->setFrameStyle(QFrame::VLine | QFrame::Raised);
527 QFrame *separator2 = new QFrame();
528 separator2->setFrameStyle(QFrame::VLine | QFrame::Raised);
530 QHBoxLayout* layout = new QHBoxLayout();
531 layout->setContentsMargins(2, 2, 2, 2);
532 layout->addWidget(new_session_button_);
533 layout->addWidget(separator1);
534 layout->addWidget(run_stop_button_);
535 layout->addWidget(separator2);
536 layout->addWidget(settings_button_);
538 static_tab_widget_ = new QWidget();
539 static_tab_widget_->setLayout(layout);
541 session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
542 session_selector_.setTabsClosable(true);
544 close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
545 close_application_shortcut_->setAutoRepeat(false);
547 close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(on_close_current_tab()));
549 connect(new_session_button_, SIGNAL(clicked(bool)),
550 this, SLOT(on_new_session_clicked()));
551 connect(run_stop_button_, SIGNAL(clicked(bool)),
552 this, SLOT(on_run_stop_clicked()));
553 connect(settings_button_, SIGNAL(clicked(bool)),
554 this, SLOT(on_settings_clicked()));
556 connect(&session_selector_, SIGNAL(tabCloseRequested(int)),
557 this, SLOT(on_tab_close_requested(int)));
558 connect(&session_selector_, SIGNAL(currentChanged(int)),
559 this, SLOT(on_tab_changed(int)));
562 connect(static_cast<QApplication *>(QCoreApplication::instance()),
563 SIGNAL(focusChanged(QWidget*, QWidget*)),
564 this, SLOT(on_focus_changed()));
567 void MainWindow::update_acq_button(Session *session)
569 int state = session->get_capture_state();
571 const QString run_caption =
572 session->using_file_device() ? tr("Reload") : tr("Run");
574 const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_};
575 run_stop_button_->setIcon(*icons[state]);
576 run_stop_button_->setText((state == pv::Session::Stopped) ?
577 run_caption : tr("Stop"));
580 void MainWindow::save_ui_settings()
584 settings.beginGroup("MainWindow");
585 settings.setValue("state", saveState());
586 settings.setValue("geometry", saveGeometry());
590 void MainWindow::restore_ui_settings()
594 settings.beginGroup("MainWindow");
596 if (settings.contains("geometry")) {
597 restoreGeometry(settings.value("geometry").toByteArray());
598 restoreState(settings.value("state").toByteArray());
605 shared_ptr<Session> MainWindow::get_tab_session(int index) const
607 // Find the session that belongs to the tab's main window
608 for (auto& entry : session_windows_)
609 if (entry.second == session_selector_.widget(index))
615 void MainWindow::closeEvent(QCloseEvent *event)
617 bool data_saved = true;
619 for (auto& entry : session_windows_)
620 if (!entry.first->data_saved())
623 if (!data_saved && (QMessageBox::question(this, tr("Confirmation"),
624 tr("There is unsaved data. Close anyway?"),
625 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
634 QMenu* MainWindow::createPopupMenu()
639 bool MainWindow::restoreState(const QByteArray &state, int version)
644 // Do nothing. We don't want Qt to handle this, or else it
645 // will try to restore all the dock widgets and create havoc.
650 void MainWindow::on_add_view(views::ViewType type, Session *session)
652 // We get a pointer and need a reference
653 for (shared_ptr<Session>& s : sessions_)
654 if (s.get() == session)
658 void MainWindow::on_focus_changed()
660 shared_ptr<views::ViewBase> view = get_active_view();
663 for (shared_ptr<Session> session : sessions_) {
664 if (session->has_view(view)) {
665 if (session != last_focused_session_) {
666 // Activate correct tab if necessary
667 shared_ptr<Session> tab_session = get_tab_session(
668 session_selector_.currentIndex());
669 if (tab_session != session)
670 session_selector_.setCurrentWidget(
671 session_windows_.at(session));
673 on_focused_session_changed(session);
681 if (sessions_.empty())
682 setWindowTitle(WindowTitle);
685 void MainWindow::on_focused_session_changed(shared_ptr<Session> session)
687 last_focused_session_ = session;
689 setWindowTitle(session->name() + " - " + WindowTitle);
691 // Update the state of the run/stop button, too
692 update_acq_button(session.get());
695 void MainWindow::on_new_session_clicked()
700 void MainWindow::on_run_stop_clicked()
702 shared_ptr<Session> session = last_focused_session_;
707 switch (session->get_capture_state()) {
708 case Session::Stopped:
709 session->start_capture([&](QString message) {
710 show_session_error("Capture failed", message); });
712 case Session::AwaitingTrigger:
713 case Session::Running:
714 session->stop_capture();
719 void MainWindow::on_settings_clicked()
721 dialogs::Settings dlg(device_manager_);
725 void MainWindow::on_session_name_changed()
727 // Update the corresponding dock widget's name(s)
728 Session *session = qobject_cast<Session*>(QObject::sender());
731 for (const shared_ptr<views::ViewBase>& view : session->views()) {
732 // Get the dock that contains the view
733 for (auto& entry : view_docks_)
734 if (entry.second == view) {
735 entry.first->setObjectName(session->name());
736 entry.first->setWindowTitle(session->name());
740 // Update the tab widget by finding the main window and the tab from that
741 for (auto& entry : session_windows_)
742 if (entry.first.get() == session) {
743 QMainWindow *window = entry.second;
744 const int index = session_selector_.indexOf(window);
745 session_selector_.setTabText(index, session->name());
748 // Refresh window title if the affected session has focus
749 if (session == last_focused_session_.get())
750 setWindowTitle(session->name() + " - " + WindowTitle);
753 void MainWindow::on_session_device_changed()
755 Session *session = qobject_cast<Session*>(QObject::sender());
758 // Ignore if caller is not the currently focused session
759 // unless there is only one session
760 if ((sessions_.size() > 1) && (session != last_focused_session_.get()))
763 update_acq_button(session);
766 void MainWindow::on_session_capture_state_changed(int state)
770 Session *session = qobject_cast<Session*>(QObject::sender());
773 // Ignore if caller is not the currently focused session
774 // unless there is only one session
775 if ((sessions_.size() > 1) && (session != last_focused_session_.get()))
778 update_acq_button(session);
781 void MainWindow::on_new_view(Session *session, int view_type)
783 // We get a pointer and need a reference
784 for (shared_ptr<Session>& s : sessions_)
785 if (s.get() == session)
786 add_view((views::ViewType)view_type, *s);
789 void MainWindow::on_view_close_clicked()
791 // Find the dock widget that contains the close button that was clicked
792 QObject *w = QObject::sender();
793 QDockWidget *dock = nullptr;
796 dock = qobject_cast<QDockWidget*>(w);
802 // Get the view contained in the dock widget
803 shared_ptr<views::ViewBase> view;
805 for (auto& entry : view_docks_)
806 if (entry.first == dock)
809 // Deregister the view
810 for (shared_ptr<Session> session : sessions_) {
811 if (!session->has_view(view))
814 // Also destroy the entire session if its main view is closing...
815 if (view == session->main_view()) {
816 // ...but only if data is saved or the user confirms closing
817 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
818 tr("This session contains unsaved data. Close it anyway?"),
819 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
820 remove_session(session);
823 // All other views can be closed at any time as no data will be lost
828 void MainWindow::on_tab_changed(int index)
830 shared_ptr<Session> session = get_tab_session(index);
833 on_focused_session_changed(session);
836 void MainWindow::on_tab_close_requested(int index)
838 shared_ptr<Session> session = get_tab_session(index);
843 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
844 tr("This session contains unsaved data. Close it anyway?"),
845 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
846 remove_session(session);
849 void MainWindow::on_show_decoder_selector(Session *session)
852 // Close dock widget if it's already showing and return
853 for (auto& entry : sub_windows_) {
854 QDockWidget* dock = entry.first;
855 shared_ptr<subwindows::SubWindowBase> decoder_selector =
856 dynamic_pointer_cast<subwindows::decoder_selector::SubWindow>(entry.second);
858 if (decoder_selector && (&decoder_selector->session() == session)) {
859 sub_windows_.erase(dock);
865 // We get a pointer and need a reference
866 for (shared_ptr<Session>& s : sessions_)
867 if (s.get() == session)
868 add_subwindow(subwindows::SubWindowTypeDecoderSelector, *s);
872 void MainWindow::on_sub_window_close_clicked()
874 // Find the dock widget that contains the close button that was clicked
875 QObject *w = QObject::sender();
876 QDockWidget *dock = nullptr;
879 dock = qobject_cast<QDockWidget*>(w);
885 sub_windows_.erase(dock);
889 void MainWindow::on_view_colored_bg_shortcut()
891 GlobalSettings settings;
893 bool state = settings.value(GlobalSettings::Key_View_ColoredBG).toBool();
894 settings.setValue(GlobalSettings::Key_View_ColoredBG, !state);
897 void MainWindow::on_view_sticky_scrolling_shortcut()
899 GlobalSettings settings;
901 bool state = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
902 settings.setValue(GlobalSettings::Key_View_StickyScrolling, !state);
905 void MainWindow::on_view_show_sampling_points_shortcut()
907 GlobalSettings settings;
909 bool state = settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
910 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, !state);
913 void MainWindow::on_view_show_analog_minor_grid_shortcut()
915 GlobalSettings settings;
917 bool state = settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
918 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, !state);
921 void MainWindow::on_close_current_tab()
923 int tab = session_selector_.currentIndex();
925 on_tab_close_requested(tab);