X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=8787073d5875e1d82c64d826eb845b26e09c9b3c;hp=a99ba35298c39080930e764adcb699e0feb6d707;hb=36a8185e7e594990d475e6a043d5924605ca0f58;hpb=956a945e4d42d0d7718e6f1364d567f5e25ebf49 diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index a99ba352..8787073d 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -186,7 +186,14 @@ shared_ptr MainWindow::add_view(const QString &title, dock->setWidget(dock_main); dock->setFeatures(QDockWidget::DockWidgetMovable | - QDockWidget::DockWidgetFloatable); + QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable); + + QAbstractButton *close_btn = + dock->findChildren + ("qt_dockwidget_closebutton").front(); + + connect(close_btn, SIGNAL(clicked(bool)), + this, SLOT(on_view_close_clicked())); if (type == view::TraceView) { connect(&session, SIGNAL(trigger_event(util::Timestamp)), v.get(), @@ -200,6 +207,11 @@ shared_ptr MainWindow::add_view(const QString &title, main_bar = make_shared(session, *this); dock_main->addToolBar(main_bar.get()); session.set_main_bar(main_bar); + + connect(main_bar.get(), SIGNAL(new_session()), + this, SLOT(on_new_session())); + connect(main_bar.get(), SIGNAL(new_view(Session*)), + this, SLOT(on_new_view(Session*))); } main_bar->action_view_show_cursors()->setChecked(v->cursors_shown()); @@ -229,6 +241,19 @@ shared_ptr MainWindow::add_session() return session; } +void MainWindow::remove_session(shared_ptr session) +{ + for (shared_ptr view : session->views()) { + // Find the dock the view is contained in and close it + for (auto entry : view_docks_) + if (entry.second == view) + entry.first->close(); + } + + sessions_.remove_if([&](shared_ptr s) { + return s == session; }); +} + void MainWindow::setup_ui() { setObjectName(QString::fromUtf8("MainWindow")); @@ -348,6 +373,53 @@ void MainWindow::on_add_view(const QString &title, view::ViewType type, add_view(title, type, *s); } +void MainWindow::on_new_session() +{ + add_session(); +} + +void MainWindow::on_new_view(Session *session) +{ + // We get a pointer and need a reference + for (std::shared_ptr s : sessions_) + if (s.get() == session) + add_view(session->name(), pv::view::TraceView, *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 = 0; + + while (w) { + dock = qobject_cast(w); + if (dock) + break; + w = w->parent(); + } + + // Get the view contained in the dock widget + shared_ptr view; + + for (auto entry : view_docks_) + if (entry.first.get() == dock) + view = entry.second; + + // Deregister the view + for (shared_ptr session : sessions_) { + if (!session->has_view(view)) + continue; + + // Also destroy the entire session if its main view is closing + if (view == session->main_view()) { + remove_session(session); + break; + } else + session->deregister_view(view); + } +} + void MainWindow::on_actionViewStickyScrolling_triggered() { shared_ptr view = get_active_view();