X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=8787073d5875e1d82c64d826eb845b26e09c9b3c;hb=36a8185e7e594990d475e6a043d5924605ca0f58;hp=dab9c7866fab2b61ac85438dfe336bb05a96a9cd;hpb=c9da51187f8db0c9822d544a0253e0e7a58945d7;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index dab9c78..8787073 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(), @@ -234,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")); @@ -366,6 +386,40 @@ void MainWindow::on_new_view(Session *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();