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 session_state_mapper_(this),
75 icon_red_(":/icons/status-red.svg"),
76 icon_green_(":/icons/status-green.svg"),
77 icon_grey_(":/icons/status-grey.svg")
80 restore_ui_settings();
83 MainWindow::~MainWindow()
85 // Make sure we no longer hold any shared pointers to widgets after the
86 // destructor finishes (goes for sessions and sub windows alike)
88 while (!sessions_.empty())
89 remove_session(sessions_.front());
94 void MainWindow::show_session_error(const QString text, const QString info_text)
96 // TODO Emulate noquote()
97 qDebug() << "Notifying user of session error:" << info_text;
100 msg.setText(text + "\n\n" + info_text);
101 msg.setStandardButtons(QMessageBox::Ok);
102 msg.setIcon(QMessageBox::Warning);
106 shared_ptr<views::ViewBase> MainWindow::get_active_view() const
108 // If there's only one view, use it...
109 if (view_docks_.size() == 1)
110 return view_docks_.begin()->second;
112 // ...otherwise find the dock widget the widget with focus is contained in
113 QObject *w = QApplication::focusWidget();
114 QDockWidget *dock = nullptr;
117 dock = qobject_cast<QDockWidget*>(w);
123 // Get the view contained in the dock widget
124 for (auto& entry : view_docks_)
125 if (entry.first == dock)
131 shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
132 views::ViewType type, Session &session)
134 GlobalSettings settings;
135 shared_ptr<views::ViewBase> v;
137 QMainWindow *main_window = nullptr;
138 for (auto& entry : session_windows_)
139 if (entry.first.get() == &session)
140 main_window = entry.second;
144 shared_ptr<MainBar> main_bar = session.main_bar();
146 QDockWidget* dock = new QDockWidget(title, main_window);
147 dock->setObjectName(title);
148 main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
150 // Insert a QMainWindow into the dock widget to allow for a tool bar
151 QMainWindow *dock_main = new QMainWindow(dock);
152 dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
154 if (type == views::ViewTypeTrace)
155 // This view will be the main view if there's no main bar yet
156 v = make_shared<views::trace::View>(session,
157 (main_bar ? false : true), dock_main);
159 if (type == views::ViewTypeDecoderOutput)
160 v = make_shared<views::decoder_output::View>(session, false, dock_main);
166 view_docks_[dock] = v;
167 session.register_view(v);
169 dock_main->setCentralWidget(v.get());
170 dock->setWidget(dock_main);
172 dock->setContextMenuPolicy(Qt::PreventContextMenu);
173 dock->setFeatures(QDockWidget::DockWidgetMovable |
174 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
176 QAbstractButton *close_btn =
177 dock->findChildren<QAbstractButton*>("qt_dockwidget_closebutton") // clazy:exclude=detaching-temporary
180 connect(close_btn, SIGNAL(clicked(bool)),
181 this, SLOT(on_view_close_clicked()));
183 connect(&session, SIGNAL(trigger_event(int, util::Timestamp)),
184 qobject_cast<views::ViewBase*>(v.get()),
185 SLOT(trigger_event(int, util::Timestamp)));
187 if (type == views::ViewTypeTrace) {
188 views::trace::View *tv =
189 qobject_cast<views::trace::View*>(v.get());
192 /* Initial view, create the main bar */
193 main_bar = make_shared<MainBar>(session, this, tv);
194 dock_main->addToolBar(main_bar.get());
195 session.set_main_bar(main_bar);
197 connect(main_bar.get(), SIGNAL(new_view(Session*)),
198 this, SLOT(on_new_view(Session*)));
199 connect(main_bar.get(), SIGNAL(show_decoder_selector(Session*)),
200 this, SLOT(on_show_decoder_selector(Session*)));
202 main_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
204 /* For the main view we need to prevent the dock widget from
205 * closing itself when its close button is clicked. This is
206 * so we can confirm with the user first. Regular views don't
208 close_btn->disconnect(SIGNAL(clicked()), dock, SLOT(close()));
210 /* Additional view, create a standard bar */
211 pv::views::trace::StandardBar *standard_bar =
212 new pv::views::trace::StandardBar(session, this, tv);
213 dock_main->addToolBar(standard_bar);
215 standard_bar->action_view_show_cursors()->setChecked(tv->cursors_shown());
222 void MainWindow::remove_view(shared_ptr<views::ViewBase> view)
224 for (shared_ptr<Session> session : sessions_) {
225 if (!session->has_view(view))
228 // Find the dock the view is contained in and remove it
229 for (auto& entry : view_docks_)
230 if (entry.second == view) {
231 // Remove the view from the session
232 session->deregister_view(view);
234 // Remove the view from its parent; otherwise, Qt will
235 // call deleteLater() on it, which causes a double free
236 // since the shared_ptr in view_docks_ doesn't know
237 // that Qt keeps a pointer to the view around
238 view->setParent(nullptr);
240 // Delete the view's dock widget and all widgets inside it
241 entry.first->deleteLater();
243 // Remove the dock widget from the list and stop iterating
244 view_docks_.erase(entry.first);
250 shared_ptr<subwindows::SubWindowBase> MainWindow::add_subwindow(
251 subwindows::SubWindowType type, Session &session)
253 GlobalSettings settings;
254 shared_ptr<subwindows::SubWindowBase> v;
256 QMainWindow *main_window = nullptr;
257 for (auto& entry : session_windows_)
258 if (entry.first.get() == &session)
259 main_window = entry.second;
267 case subwindows::SubWindowTypeDecoderSelector:
268 title = tr("Decoder Selector");
275 QDockWidget* dock = new QDockWidget(title, main_window);
276 dock->setObjectName(title);
277 main_window->addDockWidget(Qt::TopDockWidgetArea, dock);
279 // Insert a QMainWindow into the dock widget to allow for a tool bar
280 QMainWindow *dock_main = new QMainWindow(dock);
281 dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
284 if (type == subwindows::SubWindowTypeDecoderSelector)
285 v = make_shared<subwindows::decoder_selector::SubWindow>(session, dock_main);
291 sub_windows_[dock] = v;
292 dock_main->setCentralWidget(v.get());
293 dock->setWidget(dock_main);
295 dock->setContextMenuPolicy(Qt::PreventContextMenu);
296 dock->setFeatures(QDockWidget::DockWidgetMovable |
297 QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
299 QAbstractButton *close_btn =
300 dock->findChildren<QAbstractButton*> // clazy:exclude=detaching-temporary
301 ("qt_dockwidget_closebutton").front();
303 connect(close_btn, SIGNAL(clicked(bool)),
304 this, SLOT(on_sub_window_close_clicked()));
306 if (v->has_toolbar())
307 dock_main->addToolBar(v->create_toolbar(dock_main));
309 if (v->minimum_width() > 0)
310 dock->setMinimumSize(v->minimum_width(), 0);
315 shared_ptr<Session> MainWindow::add_session()
317 static int last_session_id = 1;
318 QString name = tr("Session %1").arg(last_session_id++);
320 shared_ptr<Session> session = make_shared<Session>(device_manager_, name);
322 connect(session.get(), SIGNAL(add_view(const QString&, views::ViewType, Session*)),
323 this, SLOT(on_add_view(const QString&, views::ViewType, Session*)));
324 connect(session.get(), SIGNAL(name_changed()),
325 this, SLOT(on_session_name_changed()));
326 session_state_mapper_.setMapping(session.get(), session.get());
327 connect(session.get(), SIGNAL(capture_state_changed(int)),
328 &session_state_mapper_, SLOT(map()));
330 sessions_.push_back(session);
332 QMainWindow *window = new QMainWindow();
333 window->setWindowFlags(Qt::Widget); // Remove Qt::Window flag
334 session_windows_[session] = window;
336 int index = session_selector_.addTab(window, name);
337 session_selector_.setCurrentIndex(index);
338 last_focused_session_ = session;
340 window->setDockNestingEnabled(true);
342 shared_ptr<views::ViewBase> main_view =
343 add_view(name, views::ViewTypeTrace, *session);
348 void MainWindow::remove_session(shared_ptr<Session> session)
350 // Determine the height of the button before it collapses
351 int h = new_session_button_->height();
353 // Stop capture while the session still exists so that the UI can be
354 // updated in case we're currently running. If so, this will schedule a
355 // call to our on_capture_state_changed() slot for the next run of the
356 // event loop. We need to have this executed immediately or else it will
357 // be dismissed since the session object will be deleted by the time we
358 // leave this method and the event loop gets a chance to run again.
359 session->stop_capture();
360 QApplication::processEvents();
362 for (const shared_ptr<views::ViewBase>& view : session->views())
365 QMainWindow *window = session_windows_.at(session);
366 session_selector_.removeTab(session_selector_.indexOf(window));
368 session_windows_.erase(session);
370 if (last_focused_session_ == session)
371 last_focused_session_.reset();
373 // Remove the session from our list of sessions (which also destroys it)
374 sessions_.remove_if([&](shared_ptr<Session> s) {
375 return s == session; });
377 if (sessions_.empty()) {
378 // When there are no more tabs, the height of the QTabWidget
379 // drops to zero. We must prevent this to keep the static
381 for (QWidget *w : static_tab_widget_->findChildren<QWidget*>()) // clazy:exclude=range-loop
382 w->setMinimumHeight(h);
384 int margin = static_tab_widget_->layout()->contentsMargins().bottom();
385 static_tab_widget_->setMinimumHeight(h + 2 * margin);
386 session_selector_.setMinimumHeight(h + 2 * margin);
388 // Update the window title if there is no view left to
389 // generate focus change events
390 setWindowTitle(WindowTitle);
394 void MainWindow::add_session_with_file(string open_file_name,
395 string open_file_format, string open_setup_file_name)
397 shared_ptr<Session> session = add_session();
398 session->load_init_file(open_file_name, open_file_format, open_setup_file_name);
401 void MainWindow::add_default_session()
403 // Only add the default session if there would be no session otherwise
404 if (sessions_.size() > 0)
407 shared_ptr<Session> session = add_session();
409 // Check the list of available devices. Prefer the one that was
410 // found with user supplied scan specs (if applicable). Then try
411 // one of the auto detected devices that are not the demo device.
412 // Pick demo in the absence of "genuine" hardware devices.
413 shared_ptr<devices::HardwareDevice> user_device, other_device, demo_device;
414 for (const shared_ptr<devices::HardwareDevice>& dev : device_manager_.devices()) {
415 if (dev == device_manager_.user_spec_device()) {
417 } else if (dev->hardware_device()->driver()->name() == "demo") {
424 session->select_device(user_device);
425 else if (other_device)
426 session->select_device(other_device);
428 session->select_device(demo_device);
431 void MainWindow::save_sessions()
436 for (shared_ptr<Session>& session : sessions_) {
437 // Ignore sessions using the demo device or no device at all
438 if (session->device()) {
439 shared_ptr<devices::HardwareDevice> device =
440 dynamic_pointer_cast< devices::HardwareDevice >
444 device->hardware_device()->driver()->name() == "demo")
447 settings.beginGroup("Session" + QString::number(id++));
448 settings.remove(""); // Remove all keys in this group
449 session->save_settings(settings);
454 settings.setValue("sessions", id);
457 void MainWindow::restore_sessions()
460 int i, session_count;
462 session_count = settings.value("sessions", 0).toInt();
464 for (i = 0; i < session_count; i++) {
465 settings.beginGroup("Session" + QString::number(i));
466 shared_ptr<Session> session = add_session();
467 session->restore_settings(settings);
472 void MainWindow::setup_ui()
474 setObjectName(QString::fromUtf8("MainWindow"));
476 setCentralWidget(&session_selector_);
478 // Set the window icon
480 icon.addFile(QString(":/icons/pulseview.png"));
483 // Set up keyboard shortcuts that affect all views at once
484 view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut()));
485 view_sticky_scrolling_shortcut_->setAutoRepeat(false);
487 view_show_sampling_points_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Period), this, SLOT(on_view_show_sampling_points_shortcut()));
488 view_show_sampling_points_shortcut_->setAutoRepeat(false);
490 view_show_analog_minor_grid_shortcut_ = new QShortcut(QKeySequence(Qt::Key_G), this, SLOT(on_view_show_analog_minor_grid_shortcut()));
491 view_show_analog_minor_grid_shortcut_->setAutoRepeat(false);
493 view_colored_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_colored_bg_shortcut()));
494 view_colored_bg_shortcut_->setAutoRepeat(false);
496 // Set up the tab area
497 new_session_button_ = new QToolButton();
498 new_session_button_->setIcon(QIcon::fromTheme("document-new",
499 QIcon(":/icons/document-new.png")));
500 new_session_button_->setToolTip(tr("Create New Session"));
501 new_session_button_->setAutoRaise(true);
503 run_stop_button_ = new QToolButton();
504 run_stop_button_->setAutoRaise(true);
505 run_stop_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
506 run_stop_button_->setToolTip(tr("Start/Stop Acquisition"));
508 run_stop_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Space), run_stop_button_, SLOT(click()));
509 run_stop_shortcut_->setAutoRepeat(false);
511 settings_button_ = new QToolButton();
512 settings_button_->setIcon(QIcon::fromTheme("preferences-system",
513 QIcon(":/icons/preferences-system.png")));
514 settings_button_->setToolTip(tr("Settings"));
515 settings_button_->setAutoRaise(true);
517 QFrame *separator1 = new QFrame();
518 separator1->setFrameStyle(QFrame::VLine | QFrame::Raised);
519 QFrame *separator2 = new QFrame();
520 separator2->setFrameStyle(QFrame::VLine | QFrame::Raised);
522 QHBoxLayout* layout = new QHBoxLayout();
523 layout->setContentsMargins(2, 2, 2, 2);
524 layout->addWidget(new_session_button_);
525 layout->addWidget(separator1);
526 layout->addWidget(run_stop_button_);
527 layout->addWidget(separator2);
528 layout->addWidget(settings_button_);
530 static_tab_widget_ = new QWidget();
531 static_tab_widget_->setLayout(layout);
533 session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
534 session_selector_.setTabsClosable(true);
536 close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
537 close_application_shortcut_->setAutoRepeat(false);
539 close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(on_close_current_tab()));
541 connect(new_session_button_, SIGNAL(clicked(bool)),
542 this, SLOT(on_new_session_clicked()));
543 connect(run_stop_button_, SIGNAL(clicked(bool)),
544 this, SLOT(on_run_stop_clicked()));
545 connect(&session_state_mapper_, SIGNAL(mapped(QObject*)),
546 this, SLOT(on_capture_state_changed(QObject*)));
547 connect(settings_button_, SIGNAL(clicked(bool)),
548 this, SLOT(on_settings_clicked()));
550 connect(&session_selector_, SIGNAL(tabCloseRequested(int)),
551 this, SLOT(on_tab_close_requested(int)));
552 connect(&session_selector_, SIGNAL(currentChanged(int)),
553 this, SLOT(on_tab_changed(int)));
556 connect(static_cast<QApplication *>(QCoreApplication::instance()),
557 SIGNAL(focusChanged(QWidget*, QWidget*)),
558 this, SLOT(on_focus_changed()));
561 void MainWindow::save_ui_settings()
565 settings.beginGroup("MainWindow");
566 settings.setValue("state", saveState());
567 settings.setValue("geometry", saveGeometry());
571 void MainWindow::restore_ui_settings()
575 settings.beginGroup("MainWindow");
577 if (settings.contains("geometry")) {
578 restoreGeometry(settings.value("geometry").toByteArray());
579 restoreState(settings.value("state").toByteArray());
586 shared_ptr<Session> MainWindow::get_tab_session(int index) const
588 // Find the session that belongs to the tab's main window
589 for (auto& entry : session_windows_)
590 if (entry.second == session_selector_.widget(index))
596 void MainWindow::closeEvent(QCloseEvent *event)
598 bool data_saved = true;
600 for (auto& entry : session_windows_)
601 if (!entry.first->data_saved())
604 if (!data_saved && (QMessageBox::question(this, tr("Confirmation"),
605 tr("There is unsaved data. Close anyway?"),
606 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
615 QMenu* MainWindow::createPopupMenu()
620 bool MainWindow::restoreState(const QByteArray &state, int version)
625 // Do nothing. We don't want Qt to handle this, or else it
626 // will try to restore all the dock widgets and create havoc.
631 void MainWindow::on_add_view(const QString &title, views::ViewType type,
634 // We get a pointer and need a reference
635 for (shared_ptr<Session>& s : sessions_)
636 if (s.get() == session)
637 add_view(title, type, *s);
640 void MainWindow::on_focus_changed()
642 shared_ptr<views::ViewBase> view = get_active_view();
645 for (shared_ptr<Session> session : sessions_) {
646 if (session->has_view(view)) {
647 if (session != last_focused_session_) {
648 // Activate correct tab if necessary
649 shared_ptr<Session> tab_session = get_tab_session(
650 session_selector_.currentIndex());
651 if (tab_session != session)
652 session_selector_.setCurrentWidget(
653 session_windows_.at(session));
655 on_focused_session_changed(session);
663 if (sessions_.empty())
664 setWindowTitle(WindowTitle);
667 void MainWindow::on_focused_session_changed(shared_ptr<Session> session)
669 last_focused_session_ = session;
671 setWindowTitle(session->name() + " - " + WindowTitle);
673 // Update the state of the run/stop button, too
674 on_capture_state_changed(session.get());
677 void MainWindow::on_new_session_clicked()
682 void MainWindow::on_run_stop_clicked()
684 shared_ptr<Session> session = last_focused_session_;
689 switch (session->get_capture_state()) {
690 case Session::Stopped:
691 session->start_capture([&](QString message) {
692 show_session_error("Capture failed", message); });
694 case Session::AwaitingTrigger:
695 case Session::Running:
696 session->stop_capture();
701 void MainWindow::on_settings_clicked()
703 dialogs::Settings dlg(device_manager_);
707 void MainWindow::on_session_name_changed()
709 // Update the corresponding dock widget's name(s)
710 Session *session = qobject_cast<Session*>(QObject::sender());
713 for (const shared_ptr<views::ViewBase>& view : session->views()) {
714 // Get the dock that contains the view
715 for (auto& entry : view_docks_)
716 if (entry.second == view) {
717 entry.first->setObjectName(session->name());
718 entry.first->setWindowTitle(session->name());
722 // Update the tab widget by finding the main window and the tab from that
723 for (auto& entry : session_windows_)
724 if (entry.first.get() == session) {
725 QMainWindow *window = entry.second;
726 const int index = session_selector_.indexOf(window);
727 session_selector_.setTabText(index, session->name());
730 // Refresh window title if the affected session has focus
731 if (session == last_focused_session_.get())
732 setWindowTitle(session->name() + " - " + WindowTitle);
735 void MainWindow::on_capture_state_changed(QObject *obj)
737 Session *caller = qobject_cast<Session*>(obj);
739 // Ignore if caller is not the currently focused session
740 // unless there is only one session
741 if ((sessions_.size() > 1) && (caller != last_focused_session_.get()))
744 int state = caller->get_capture_state();
746 const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_};
747 run_stop_button_->setIcon(*icons[state]);
748 run_stop_button_->setText((state == pv::Session::Stopped) ?
749 tr("Run") : tr("Stop"));
752 void MainWindow::on_new_view(Session *session)
754 // We get a pointer and need a reference
755 for (shared_ptr<Session>& s : sessions_)
756 if (s.get() == session)
757 add_view(session->name(), views::ViewTypeTrace, *s);
760 void MainWindow::on_view_close_clicked()
762 // Find the dock widget that contains the close button that was clicked
763 QObject *w = QObject::sender();
764 QDockWidget *dock = nullptr;
767 dock = qobject_cast<QDockWidget*>(w);
773 // Get the view contained in the dock widget
774 shared_ptr<views::ViewBase> view;
776 for (auto& entry : view_docks_)
777 if (entry.first == dock)
780 // Deregister the view
781 for (shared_ptr<Session> session : sessions_) {
782 if (!session->has_view(view))
785 // Also destroy the entire session if its main view is closing...
786 if (view == session->main_view()) {
787 // ...but only if data is saved or the user confirms closing
788 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
789 tr("This session contains unsaved data. Close it anyway?"),
790 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
791 remove_session(session);
794 // All other views can be closed at any time as no data will be lost
799 void MainWindow::on_tab_changed(int index)
801 shared_ptr<Session> session = get_tab_session(index);
804 on_focused_session_changed(session);
807 void MainWindow::on_tab_close_requested(int index)
809 shared_ptr<Session> session = get_tab_session(index);
814 if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
815 tr("This session contains unsaved data. Close it anyway?"),
816 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
817 remove_session(session);
820 void MainWindow::on_show_decoder_selector(Session *session)
823 // Close dock widget if it's already showing and return
824 for (auto& entry : sub_windows_) {
825 QDockWidget* dock = entry.first;
826 shared_ptr<subwindows::SubWindowBase> decoder_selector =
827 dynamic_pointer_cast<subwindows::decoder_selector::SubWindow>(entry.second);
829 if (decoder_selector && (&decoder_selector->session() == session)) {
830 sub_windows_.erase(dock);
836 // We get a pointer and need a reference
837 for (shared_ptr<Session>& s : sessions_)
838 if (s.get() == session)
839 add_subwindow(subwindows::SubWindowTypeDecoderSelector, *s);
843 void MainWindow::on_sub_window_close_clicked()
845 // Find the dock widget that contains the close button that was clicked
846 QObject *w = QObject::sender();
847 QDockWidget *dock = nullptr;
850 dock = qobject_cast<QDockWidget*>(w);
856 sub_windows_.erase(dock);
860 void MainWindow::on_view_colored_bg_shortcut()
862 GlobalSettings settings;
864 bool state = settings.value(GlobalSettings::Key_View_ColoredBG).toBool();
865 settings.setValue(GlobalSettings::Key_View_ColoredBG, !state);
868 void MainWindow::on_view_sticky_scrolling_shortcut()
870 GlobalSettings settings;
872 bool state = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool();
873 settings.setValue(GlobalSettings::Key_View_StickyScrolling, !state);
876 void MainWindow::on_view_show_sampling_points_shortcut()
878 GlobalSettings settings;
880 bool state = settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
881 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, !state);
884 void MainWindow::on_view_show_analog_minor_grid_shortcut()
886 GlobalSettings settings;
888 bool state = settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
889 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, !state);
892 void MainWindow::on_close_current_tab()
894 int tab = session_selector_.currentIndex();
896 on_tab_close_requested(tab);