From: Soeren Apel Date: Sun, 5 Mar 2017 19:54:51 +0000 (+0100) Subject: MainWindow: Restructure add_view() X-Git-Tag: pulseview-0.4.0~169 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ddaded8bccdb05d700b4242b7b3ef59a55b39ac0;p=pulseview.git MainWindow: Restructure add_view() --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 879c8a52..2f9ab323 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -159,6 +159,7 @@ shared_ptr MainWindow::add_view(const QString &title, views::ViewType type, Session &session) { GlobalSettings settings; + shared_ptr v; QMainWindow *main_window = nullptr; for (auto entry : session_windows_) @@ -167,72 +168,75 @@ shared_ptr MainWindow::add_view(const QString &title, assert(main_window); - if (type == views::ViewTypeTrace) { - QDockWidget* dock = new QDockWidget(title, main_window); - dock->setObjectName(title); - main_window->addDockWidget(Qt::TopDockWidgetArea, dock); - - // Insert a QMainWindow into the dock widget to allow for a tool bar - QMainWindow *dock_main = new QMainWindow(dock); - dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag - - shared_ptr v = - make_shared(session, dock_main); - view_docks_[dock] = v; - session.register_view(v); + QDockWidget* dock = new QDockWidget(title, main_window); + dock->setObjectName(title); + main_window->addDockWidget(Qt::TopDockWidgetArea, dock); - dock_main->setCentralWidget(v.get()); - dock->setWidget(dock_main); + // Insert a QMainWindow into the dock widget to allow for a tool bar + QMainWindow *dock_main = new QMainWindow(dock); + dock_main->setWindowFlags(Qt::Widget); // Remove Qt::Window flag - dock->setFeatures(QDockWidget::DockWidgetMovable | - QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable); + if (type == views::ViewTypeTrace) + v = make_shared(session, dock_main); - QAbstractButton *close_btn = - dock->findChildren - ("qt_dockwidget_closebutton").front(); + if (!v) + return nullptr; - connect(close_btn, SIGNAL(clicked(bool)), - this, SLOT(on_view_close_clicked())); + view_docks_[dock] = v; + session.register_view(v); - if (type == views::ViewTypeTrace) { - connect(&session, SIGNAL(trigger_event(util::Timestamp)), - qobject_cast(v.get()), - SLOT(trigger_event(util::Timestamp))); + dock_main->setCentralWidget(v.get()); + dock->setWidget(dock_main); - v->enable_sticky_scrolling(true); - v->enable_coloured_bg(settings.value(GlobalSettings::Key_View_ColouredBG).toBool()); + dock->setFeatures(QDockWidget::DockWidgetMovable | + QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable); - shared_ptr main_bar = session.main_bar(); - if (!main_bar) { - /* Initial view, create the main bar */ - main_bar = make_shared(session, this, v.get()); - dock_main->addToolBar(main_bar.get()); - session.set_main_bar(main_bar); + QAbstractButton *close_btn = + dock->findChildren + ("qt_dockwidget_closebutton").front(); - connect(main_bar.get(), SIGNAL(new_view(Session*)), - this, SLOT(on_new_view(Session*))); + connect(close_btn, SIGNAL(clicked(bool)), + this, SLOT(on_view_close_clicked())); - main_bar->action_view_show_cursors()->setChecked(v->cursors_shown()); - - /* For the main view we need to prevent the dock widget from - * closing itself when its close button is clicked. This is - * so we can confirm with the user first. Regular views don't - * need this */ - close_btn->disconnect(SIGNAL(clicked()), dock, SLOT(close())); - } else { - /* Additional view, create a standard bar */ - pv::views::trace::StandardBar *standard_bar = - new pv::views::trace::StandardBar(session, this, v.get()); - dock_main->addToolBar(standard_bar); + connect(&session, SIGNAL(trigger_event(util::Timestamp)), + qobject_cast(v.get()), + SLOT(trigger_event(util::Timestamp))); - standard_bar->action_view_show_cursors()->setChecked(v->cursors_shown()); - } + if (type == views::ViewTypeTrace) { + views::TraceView::View *tv = + qobject_cast(v.get()); + + tv->enable_sticky_scrolling(true); + tv->enable_coloured_bg(settings.value(GlobalSettings::Key_View_ColouredBG).toBool()); + + shared_ptr main_bar = session.main_bar(); + if (!main_bar) { + /* Initial view, create the main bar */ + main_bar = make_shared(session, this, tv); + dock_main->addToolBar(main_bar.get()); + session.set_main_bar(main_bar); + + connect(main_bar.get(), SIGNAL(new_view(Session*)), + this, SLOT(on_new_view(Session*))); + + main_bar->action_view_show_cursors()->setChecked(tv->cursors_shown()); + + /* For the main view we need to prevent the dock widget from + * closing itself when its close button is clicked. This is + * so we can confirm with the user first. Regular views don't + * need this */ + close_btn->disconnect(SIGNAL(clicked()), dock, SLOT(close())); + } else { + /* Additional view, create a standard bar */ + pv::views::trace::StandardBar *standard_bar = + new pv::views::trace::StandardBar(session, this, tv); + dock_main->addToolBar(standard_bar); + + standard_bar->action_view_show_cursors()->setChecked(tv->cursors_shown()); } - - return v; } - return nullptr; + return v; } void MainWindow::remove_view(shared_ptr view)