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"
56 #include <libsigrokcxx/libsigrokcxx.hpp>
58 using std::dynamic_pointer_cast;
59 using std::make_shared;
60 using std::shared_ptr;
69 using toolbars::MainBar;
71 const QString MainWindow::WindowTitle = tr("PulseView");
73 MainWindow::MainWindow(DeviceManager &device_manager, QWidget *parent) :
75 device_manager_(device_manager),
76 session_selector_(this),
77 session_state_mapper_(this),
78 icon_red_(":/icons/status-red.svg"),
79 icon_green_(":/icons/status-green.svg"),
80 icon_grey_(":/icons/status-grey.svg")
82 GlobalSettings::add_change_handler(this);
85 restore_ui_settings();
88 MainWindow::~MainWindow()
90 GlobalSettings::remove_change_handler(this);
92 // Make sure we no longer hold any shared pointers to widgets after the
93 // destructor finishes (goes for sessions and sub windows alike)
95 while (!sessions_.empty())
96 remove_session(sessions_.front());
101 void MainWindow::show_session_error(const QString text, const QString info_text)
103 // TODO Emulate noquote()
104 qDebug() << "Notifying user of session error:" << info_text;
107 msg.setText(text + "\n\n" + info_text);
108 msg.setStandardButtons(QMessageBox::Ok);
109 msg.setIcon(QMessageBox::Warning);
113 shared_ptr<views::ViewBase> MainWindow::get_active_view() const
115 // If there's only one view, use it...
116 if (view_docks_.size() == 1)
117 return view_docks_.begin()->second;
119 // ...otherwise find the dock widget the widget with focus is contained in
120 QObject *w = QApplication::focusWidget();
121 QDockWidget *dock = nullptr;
124 dock = qobject_cast<QDockWidget*>(w);
130 // Get the view contained in the dock widget
131 for (auto& entry : view_docks_)
132 if (entry.first == dock)
138 shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
139 views::ViewType type, Session &session)
141 GlobalSettings settings;
142 shared_ptr<views::ViewBase> v;
144 QMainWindow *main_window = nullptr;
145 for (auto& entry : session_windows_)
146 if (entry.first.get() == &session)
147 main_window = entry.second;
151 shared_ptr<MainBar> main_bar = session.main_bar();
153 QDockWidget* dock = new QDockWidget(title, main_window);
154 dock->setObjectName(title);
155 main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
157 // Insert a QMainWindow into the dock widget to allow for a tool bar
158 QMainWindow *dock_main = new QMainWindow(dock);
159 dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
161 if (type == views::ViewTypeTrace)
162 // This view will be the main view if there's no main bar yet
163 v = make_shared<views::trace::View>(session,
164 (main_bar ? false : true), dock_main);
169 view_docks_[dock] = v;
170 session.register_view(v);
172 dock_main->setCentralWidget(v.get());
173 dock->setWidget(dock_main);
175 dock->setContextMenuPolicy(Qt::PreventContextMenu);
176 dock->setFeatures(QDockWidget::DockWidgetMovable |
177 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
179 QAbstractButton *close_btn =
180 dock->findChildren<QAbstractButton*>("qt_dockwidget_closebutton") // clazy:exclude=detaching-temporary
183 connect(close_btn, SIGNAL(clicked(bool)),
184 this, SLOT(on_view_close_clicked()));
186 connect(&session, SIGNAL(trigger_event(int, util::Timestamp)),
187 qobject_cast<views::ViewBase*>(v.get()),
188 SLOT(trigger_event(int, util::Timestamp)));
190 if (type == views::ViewTypeTrace) {
191 views::trace::View *tv =
192 qobject_cast<views::trace::View*>(v.get());
194 tv->enable_colored_bg(settings.value(GlobalSettings::Key_View_ColoredBG).toBool());
195 tv->enable_show_sampling_points(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
196 tv->enable_show_analog_minor_grid(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool());
199 /* Initial view, create the main bar */
200 main_bar = make_shared<MainBar>(session, this, tv);
201 dock_main->addToolBar(main_bar.get());
202 session.set_main_bar(main_bar);
204 connect(main_bar.get(), SIGNAL(new_view(Session*)),
205 this, SLOT(on_new_view(Session*)));
206 connect(main_bar.get(), SIGNAL(show_decoder_selector(Session*)),
207 this, SLOT(on_show_decoder_selector(Session*)));
209 main_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
211 /* For the main view we need to prevent the dock widget from
212 * closing itself when its close button is clicked. This is
213 * so we can confirm with the user first. Regular views don't
215 close_btn->disconnect(SIGNAL(clicked()), dock, SLOT(close()));
217 /* Additional view, create a standard bar */
218 pv::views::trace::StandardBar *standard_bar =
219 new pv::views::trace::StandardBar(session, this, tv);
220 dock_main->addToolBar(standard_bar);
222 standard_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
229 void MainWindow::remove_view(shared_ptr<views::ViewBase> view)
231 for (shared_ptr<Session> session : sessions_) {
232 if (!session->has_view(view))
235 // Find the dock the view is contained in and remove it
236 for (auto& entry : view_docks_)
237 if (entry.second == view) {
238 // Remove the view from the session
239 session->deregister_view(view);
241 // Remove the view from its parent; otherwise, Qt will
242 // call deleteLater() on it, which causes a double free
243 // since the shared_ptr in view_docks_ doesn't know
244 // that Qt keeps a pointer to the view around
245 view->setParent(nullptr);
247 // Delete the view's dock widget and all widgets inside it
248 entry.first->deleteLater();
250 // Remove the dock widget from the list and stop iterating
251 view_docks_.erase(entry.first);
257 shared_ptr<subwindows::SubWindowBase> MainWindow::add_subwindow(
258 subwindows::SubWindowType type, Session &session)
260 GlobalSettings settings;
261 shared_ptr<subwindows::SubWindowBase> v;
263 QMainWindow *main_window = nullptr;
264 for (auto entry : session_windows_)
265 if (entry.first.get() == &session)
266 main_window = entry.second;
274 case subwindows::SubWindowTypeDecoderSelector:
275 title = tr("Decoder Selector");
282 QDockWidget* dock = new QDockWidget(title, main_window);
283 dock->setObjectName(title);
284 main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
286 // Insert a QMainWindow into the dock widget to allow for a tool bar
287 QMainWindow *dock_main = new QMainWindow(dock);
288 dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
291 if (type == subwindows::SubWindowTypeDecoderSelector)
292 v = make_shared<subwindows::decoder_selector::SubWindow>(session, dock_main);
298 sub_windows_[dock] = v;
299 dock_main->setCentralWidget(v.get());
300 dock->setWidget(dock_main);
302 dock->setContextMenuPolicy(Qt::PreventContextMenu);
303 dock->setFeatures(QDockWidget::DockWidgetMovable |
304 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
306 QAbstractButton *close_btn =
307 dock->findChildren<QAbstractButton*>
308 ("qt_dockwidget_closebutton").front();
310 connect(close_btn, SIGNAL(clicked(bool)),
311 this, SLOT(on_sub_window_close_clicked()));
313 if (v->has_toolbar())
314 dock_main->addToolBar(v->create_toolbar(dock_main));
316 if (v->minimum_width() > 0)
317 dock->setMinimumSize(v->minimum_width(), 0);
322 shared_ptr<Session> MainWindow::add_session()
324 static int last_session_id = 1;
325 QString name = tr("Session %1").arg(last_session_id++);
327 shared_ptr<Session> session = make_shared<Session>(device_manager_, name);
329 connect(session.get(), SIGNAL(add_view(const QString&, views::ViewType, Session*)),
330 this, SLOT(on_add_view(const QString&, views::ViewType, Session*)));
331 connect(session.get(), SIGNAL(name_changed()),
332 this, SLOT(on_session_name_changed()));
333 session_state_mapper_.setMapping(session.get(), session.get());
334 connect(session.get(), SIGNAL(capture_state_changed(int)),
335 &session_state_mapper_, SLOT(map()));
337 sessions_.push_back(session);
339 QMainWindow *window = new QMainWindow();
340 window->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
341 session_windows_[session] = window;
343 int index = session_selector_.addTab(window, name);
344 session_selector_.setCurrentIndex(index);
345 last_focused_session_ = session;
347 window->setDockNestingEnabled(true);
349 shared_ptr<views::ViewBase> main_view =
350 add_view(name, views::ViewTypeTrace, *session);
355 void MainWindow::remove_session(shared_ptr<Session> session)
357 // Determine the height of the button before it collapses
358 int h = new_session_button_->height();
360 // Stop capture while the session still exists so that the UI can be
361 // updated in case we're currently running. If so, this will schedule a
362 // call to our on_capture_state_changed() slot for the next run of the
363 // event loop. We need to have this executed immediately or else it will
364 // be dismissed since the session object will be deleted by the time we
365 // leave this method and the event loop gets a chance to run again.
366 session->stop_capture();
367 QApplication::processEvents();
369 for (const shared_ptr<views::ViewBase>& view : session->views())
372 QMainWindow *window = session_windows_.at(session);
373 session_selector_.removeTab(session_selector_.indexOf(window));
375 session_windows_.erase(session);
377 if (last_focused_session_ == session)
378 last_focused_session_.reset();
380 // Remove the session from our list of sessions (which also destroys it)
381 sessions_.remove_if([&](shared_ptr<Session> s) {
382 return s == session; });
384 if (sessions_.empty()) {
385 // When there are no more tabs, the height of the QTabWidget
386 // drops to zero. We must prevent this to keep the static
388 for (QWidget *w : static_tab_widget_->findChildren<QWidget*>()) // clazy:exclude=range-loop
389 w->setMinimumHeight(h);
391 int margin = static_tab_widget_->layout()->contentsMargins().bottom();
392 static_tab_widget_->setMinimumHeight(h + 2 * margin);
393 session_selector_.setMinimumHeight(h + 2 * margin);
395 // Update the window title if there is no view left to
396 // generate focus change events
397 setWindowTitle(WindowTitle);
401 void MainWindow::add_session_with_file(string open_file_name,
402 string open_file_format,
403 string open_setup_file_name)
405 shared_ptr<Session> session = add_session();
406 session->load_init_file(open_file_name,
408 open_setup_file_name);
411 void MainWindow::add_default_session()
413 // Only add the default session if there would be no session otherwise
414 if (sessions_.size() > 0)
417 shared_ptr<Session> session = add_session();
419 // Check the list of available devices. Prefer the one that was
420 // found with user supplied scan specs (if applicable). Then try
421 // one of the auto detected devices that are not the demo device.
422 // Pick demo in the absence of "genuine" hardware devices.
423 shared_ptr<devices::HardwareDevice> user_device, other_device, demo_device;
424 for (const shared_ptr<devices::HardwareDevice>& dev : device_manager_.devices()) {
425 if (dev == device_manager_.user_spec_device()) {
427 } else if (dev->hardware_device()->driver()->name() == "demo") {
434 session->select_device(user_device);
435 else if (other_device)
436 session->select_device(other_device);
438 session->select_device(demo_device);
441 void MainWindow::save_sessions()
446 for (shared_ptr<Session>& session : sessions_) {
447 // Ignore sessions using the demo device or no device at all
448 if (session->device()) {
449 shared_ptr<devices::HardwareDevice> device =
450 dynamic_pointer_cast< devices::HardwareDevice >
454 device->hardware_device()->driver()->name() == "demo")
457 settings.beginGroup("Session" + QString::number(id++));
458 settings.remove(""); // Remove all keys in this group
459 session->save_settings(settings);
464 settings.setValue("sessions", id);
467 void MainWindow::restore_sessions()
470 int i, session_count;
472 session_count = settings.value("sessions", 0).toInt();
474 for (i = 0; i < session_count; i++) {
475 settings.beginGroup("Session" + QString::number(i));
476 shared_ptr<Session> session = add_session();
477 session->restore_settings(settings);
482 void MainWindow::on_setting_changed(const QString &key, const QVariant &value)
484 if (key == GlobalSettings::Key_View_ColoredBG)
485 on_settingViewColoredBg_changed(value);
487 if (key == GlobalSettings::Key_View_ShowSamplingPoints)
488 on_settingViewShowSamplingPoints_changed(value);
490 if (key == GlobalSettings::Key_View_ShowAnalogMinorGrid)
491 on_settingViewShowAnalogMinorGrid_changed(value);
494 void MainWindow::setup_ui()
496 setObjectName(QString::fromUtf8("MainWindow"));
498 setCentralWidget(&session_selector_);
500 // Set the window icon
502 icon.addFile(QString(":/icons/pulseview.png"));
505 view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut()));
506 view_sticky_scrolling_shortcut_->setAutoRepeat(false);
508 view_show_sampling_points_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Period), this, SLOT(on_view_show_sampling_points_shortcut()));
509 view_show_sampling_points_shortcut_->setAutoRepeat(false);
511 view_show_analog_minor_grid_shortcut_ = new QShortcut(QKeySequence(Qt::Key_G), this, SLOT(on_view_show_analog_minor_grid_shortcut()));
512 view_show_analog_minor_grid_shortcut_->setAutoRepeat(false);
514 view_colored_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_colored_bg_shortcut()));
515 view_colored_bg_shortcut_->setAutoRepeat(false);
517 // Set up the tab area
518 new_session_button_ = new QToolButton();
519 new_session_button_->setIcon(QIcon::fromTheme("document-new",
520 QIcon(":/icons/document-new.png")));
521 new_session_button_->setToolTip(tr("Create New Session"));
522 new_session_button_->setAutoRaise(true);
524 run_stop_button_ = new QToolButton();
525 run_stop_button_->setAutoRaise(true);
526 run_stop_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
527 run_stop_button_->setToolTip(tr("Start/Stop Acquisition"));
529 run_stop_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Space), run_stop_button_, SLOT(click()));
530 run_stop_shortcut_->setAutoRepeat(false);
532 settings_button_ = new QToolButton();
533 settings_button_->setIcon(QIcon::fromTheme("preferences-system",
534 QIcon(":/icons/preferences-system.png")));
535 settings_button_->setToolTip(tr("Settings"));
536 settings_button_->setAutoRaise(true);
538 QFrame *separator1 = new QFrame();
539 separator1->setFrameStyle(QFrame::VLine | QFrame::Raised);
540 QFrame *separator2 = new QFrame();
541 separator2->setFrameStyle(QFrame::VLine | QFrame::Raised);
543 QHBoxLayout* layout = new QHBoxLayout();
544 layout->setContentsMargins(2, 2, 2, 2);
545 layout->addWidget(new_session_button_);
546 layout->addWidget(separator1);
547 layout->addWidget(run_stop_button_);
548 layout->addWidget(separator2);
549 layout->addWidget(settings_button_);
551 static_tab_widget_ = new QWidget();
552 static_tab_widget_->setLayout(layout);
554 session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
555 session_selector_.setTabsClosable(true);
557 close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
558 close_application_shortcut_->setAutoRepeat(false);
560 close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(on_close_current_tab()));
562 connect(new_session_button_, SIGNAL(clicked(bool)),
563 this, SLOT(on_new_session_clicked()));
564 connect(run_stop_button_, SIGNAL(clicked(bool)),
565 this, SLOT(on_run_stop_clicked()));
566 connect(&session_state_mapper_, SIGNAL(mapped(QObject*)),
567 this, SLOT(on_capture_state_changed(QObject*)));
568 connect(settings_button_, SIGNAL(clicked(bool)),
569 this, SLOT(on_settings_clicked()));
571 connect(&session_selector_, SIGNAL(tabCloseRequested(int)),
572 this, SLOT(on_tab_close_requested(int)));
573 connect(&session_selector_, SIGNAL(currentChanged(int)),
574 this, SLOT(on_tab_changed(int)));
577 connect(static_cast<QApplication *>(QCoreApplication::instance()),
578 SIGNAL(focusChanged(QWidget*, QWidget*)),
579 this, SLOT(on_focus_changed()));
582 void MainWindow::save_ui_settings()
586 settings.beginGroup("MainWindow");
587 settings.setValue("state", saveState());
588 settings.setValue("geometry", saveGeometry());
592 void MainWindow::restore_ui_settings()
596 settings.beginGroup("MainWindow");
598 if (settings.contains("geometry")) {
599 restoreGeometry(settings.value("geometry").toByteArray());
600 restoreState(settings.value("state").toByteArray());
607 shared_ptr<Session> MainWindow::get_tab_session(int index) const
609 // Find the session that belongs to the tab's main window
610 for (auto& entry : session_windows_)
611 if (entry.second == session_selector_.widget(index))
617 void MainWindow::closeEvent(QCloseEvent *event)
619 bool data_saved = true;
621 for (auto& entry : session_windows_)
622 if (!entry.first->data_saved())
625 if (!data_saved && (QMessageBox::question(this, tr("Confirmation"),
626 tr("There is unsaved data. Close anyway?"),
627 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
636 QMenu* MainWindow::createPopupMenu()
641 bool MainWindow::restoreState(const QByteArray &state, int version)
646 // Do nothing. We don't want Qt to handle this, or else it
647 // will try to restore all the dock widgets and create havoc.
652 void MainWindow::on_add_view(const QString &title, views::ViewType type,
655 // We get a pointer and need a reference
656 for (shared_ptr<Session>& s : sessions_)
657 if (s.get() == session)
658 add_view(title, type, *s);
661 void MainWindow::on_focus_changed()
663 shared_ptr<views::ViewBase> view = get_active_view();
666 for (shared_ptr<Session> session : sessions_) {
667 if (session->has_view(view)) {
668 if (session != last_focused_session_) {
669 // Activate correct tab if necessary
670 shared_ptr<Session> tab_session = get_tab_session(
671 session_selector_.currentIndex());
672 if (tab_session != session)
673 session_selector_.setCurrentWidget(
674 session_windows_.at(session));
676 on_focused_session_changed(session);
684 if (sessions_.empty())
685 setWindowTitle(WindowTitle);
688 void MainWindow::on_focused_session_changed(shared_ptr<Session> session)
690 last_focused_session_ = session;
692 setWindowTitle(session->name() + " - " + WindowTitle);
694 // Update the state of the run/stop button, too
695 on_capture_state_changed(session.get());
698 void MainWindow::on_new_session_clicked()
703 void MainWindow::on_run_stop_clicked()
705 shared_ptr<Session> session = last_focused_session_;
710 switch (session->get_capture_state()) {
711 case Session::Stopped:
712 session->start_capture([&](QString message) {
713 show_session_error("Capture failed", message); });
715 case Session::AwaitingTrigger:
716 case Session::Running:
717 session->stop_capture();
722 void MainWindow::on_settings_clicked()
724 dialogs::Settings dlg(device_manager_);
728 void MainWindow::on_session_name_changed()
730 // Update the corresponding dock widget's name(s)
731 Session *session = qobject_cast<Session*>(QObject::sender());
734 for (const shared_ptr<views::ViewBase>& view : session->views()) {
735 // Get the dock that contains the view
736 for (auto& entry : view_docks_)
737 if (entry.second == view) {
738 entry.first->setObjectName(session->name());
739 entry.first->setWindowTitle(session->name());
743 // Update the tab widget by finding the main window and the tab from that
744 for (auto& entry : session_windows_)
745 if (entry.first.get() == session) {
746 QMainWindow *window = entry.second;
747 const int index = session_selector_.indexOf(window);
748 session_selector_.setTabText(index, session->name());
751 // Refresh window title if the affected session has focus
752 if (session == last_focused_session_.get())
753 setWindowTitle(session->name() + " - " + WindowTitle);
756 void MainWindow::on_capture_state_changed(QObject *obj)
758 Session *caller = qobject_cast<Session*>(obj);
760 // Ignore if caller is not the currently focused session
761 // unless there is only one session
762 if ((sessions_.size() > 1) && (caller != last_focused_session_.get()))
765 int state = caller->get_capture_state();
767 const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_};
768 run_stop_button_->setIcon(*icons[state]);
769 run_stop_button_->setText((state == pv::Session::Stopped) ?
770 tr("Run") : tr("Stop"));
773 void MainWindow::on_new_view(Session *session)
775 // We get a pointer and need a reference
776 for (shared_ptr<Session>& s : sessions_)
777 if (s.get() == session)
778 add_view(session->name(), views::ViewTypeTrace, *s);
781 void MainWindow::on_view_close_clicked()
783 // Find the dock widget that contains the close button that was clicked
784 QObject *w = QObject::sender();
785 QDockWidget *dock = nullptr;
788 dock = qobject_cast<QDockWidget*>(w);
794 // Get the view contained in the dock widget
795 shared_ptr<views::ViewBase> view;
797 for (auto& entry : view_docks_)
798 if (entry.first == dock)
801 // Deregister the view
802 for (shared_ptr<Session> session : sessions_) {
803 if (!session->has_view(view))
806 // Also destroy the entire session if its main view is closing...
807 if (view == session->main_view()) {
808 // ...but only if data is saved or the user confirms closing
809 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
810 tr("This session contains unsaved data. Close it anyway?"),
811 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
812 remove_session(session);
815 // All other views can be closed at any time as no data will be lost
820 void MainWindow::on_tab_changed(int index)
822 shared_ptr<Session> session = get_tab_session(index);
825 on_focused_session_changed(session);
828 void MainWindow::on_tab_close_requested(int index)
830 shared_ptr<Session> session = get_tab_session(index);
835 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
836 tr("This session contains unsaved data. Close it anyway?"),
837 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
838 remove_session(session);
841 void MainWindow::on_show_decoder_selector(Session *session)
844 // Close dock widget if it's already showing and return
845 for (auto entry : sub_windows_) {
846 QDockWidget* dock = entry.first;
847 if (dynamic_pointer_cast<subwindows::decoder_selector::SubWindow>(entry.second)) {
848 sub_windows_.erase(dock);
854 // We get a pointer and need a reference
855 for (shared_ptr<Session> s : sessions_)
856 if (s.get() == session)
857 add_subwindow(subwindows::SubWindowTypeDecoderSelector, *s);
861 void MainWindow::on_sub_window_close_clicked()
863 // Find the dock widget that contains the close button that was clicked
864 QObject *w = QObject::sender();
865 QDockWidget *dock = nullptr;
868 dock = qobject_cast<QDockWidget*>(w);
874 sub_windows_.erase(dock);
878 void MainWindow::on_view_colored_bg_shortcut()
880 GlobalSettings settings;
882 bool state = settings.value(GlobalSettings::Key_View_ColoredBG).toBool();
883 settings.setValue(GlobalSettings::Key_View_ColoredBG, !state);
886 void MainWindow::on_view_sticky_scrolling_shortcut()
888 GlobalSettings settings;
890 bool state = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
891 settings.setValue(GlobalSettings::Key_View_StickyScrolling, !state);
894 void MainWindow::on_view_show_sampling_points_shortcut()
896 GlobalSettings settings;
898 bool state = settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
899 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, !state);
902 void MainWindow::on_view_show_analog_minor_grid_shortcut()
904 GlobalSettings settings;
906 bool state = settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
907 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, !state);
910 void MainWindow::on_settingViewColoredBg_changed(const QVariant new_value)
912 bool state = new_value.toBool();
914 for (auto& entry : view_docks_) {
915 shared_ptr<views::ViewBase> viewbase = entry.second;
917 // Only trace views have this setting
918 views::trace::View* view =
919 qobject_cast<views::trace::View*>(viewbase.get());
921 view->enable_colored_bg(state);
925 void MainWindow::on_settingViewShowSamplingPoints_changed(const QVariant new_value)
927 bool state = new_value.toBool();
929 for (auto& entry : view_docks_) {
930 shared_ptr<views::ViewBase> viewbase = entry.second;
932 // Only trace views have this setting
933 views::trace::View* view =
934 qobject_cast<views::trace::View*>(viewbase.get());
936 view->enable_show_sampling_points(state);
940 void MainWindow::on_settingViewShowAnalogMinorGrid_changed(const QVariant new_value)
942 bool state = new_value.toBool();
944 for (auto& entry : view_docks_) {
945 shared_ptr<views::ViewBase> viewbase = entry.second;
947 // Only trace views have this setting
948 views::trace::View* view =
949 qobject_cast<views::trace::View*>(viewbase.get());
951 view->enable_show_analog_minor_grid(state);
955 void MainWindow::on_close_current_tab()
957 int tab = session_selector_.currentIndex();
959 on_tab_close_requested(tab);