X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=9a3f197d4c2174edd3a9b814b9b340d1fc695fce;hp=205c95ca95a765670d5386e16345ef176dcdf804;hb=669686c18ca6f1ee0697ae7804bfddf4fc6bd1e1;hpb=3432032fbc693b58a0c65427c025b9553c419237 diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 205c95ca..9a3f197d 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -70,7 +70,7 @@ const QString MainWindow::WindowTitle = tr("PulseView"); MainWindow::MainWindow(DeviceManager &device_manager, string open_file_name, string open_file_format, - QWidget *parent) : + bool restore_sessions, QWidget *parent) : QMainWindow(parent), device_manager_(device_manager), session_selector_(this), @@ -92,7 +92,7 @@ MainWindow::MainWindow(DeviceManager &device_manager, bind(&MainWindow::on_settingViewShowAnalogMinorGrid_changed, this, _1)); setup_ui(); - restore_ui_settings(); + restore_ui_settings(restore_sessions); if (!open_file_name.empty()) { shared_ptr session = add_session(); @@ -188,6 +188,7 @@ shared_ptr MainWindow::add_view(const QString &title, dock_main->setCentralWidget(v.get()); dock->setWidget(dock_main); + dock->setContextMenuPolicy(Qt::PreventContextMenu); dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable); @@ -302,8 +303,18 @@ shared_ptr MainWindow::add_session() void MainWindow::remove_session(shared_ptr session) { + // Determine the height of the button before it collapses int h = new_session_button_->height(); + // Stop capture while the session still exists so that the UI can be + // updated in case we're currently running. If so, this will schedule a + // call to our on_capture_state_changed() slot for the next run of the + // event loop. We need to have this executed immediately or else it will + // be dismissed since the session object will be deleted by the time we + // leave this method and the event loop gets a chance to run again. + session->stop_capture(); + QApplication::processEvents(); + for (shared_ptr view : session->views()) remove_view(view); @@ -315,6 +326,7 @@ void MainWindow::remove_session(shared_ptr session) if (last_focused_session_ == session) last_focused_session_.reset(); + // Remove the session from our list of sessions (which also destroys it) sessions_.remove_if([&](shared_ptr s) { return s == session; }); @@ -454,10 +466,9 @@ void MainWindow::save_ui_settings() settings.setValue("sessions", id); } -void MainWindow::restore_ui_settings() +void MainWindow::restore_ui_settings(bool restore_sessions) { QSettings settings; - int i, session_count; settings.beginGroup("MainWindow"); @@ -469,13 +480,17 @@ void MainWindow::restore_ui_settings() settings.endGroup(); - session_count = settings.value("sessions", 0).toInt(); + if (restore_sessions) { + int i, session_count; - for (i = 0; i < session_count; i++) { - settings.beginGroup("Session" + QString::number(i)); - shared_ptr session = add_session(); - session->restore_settings(settings); - settings.endGroup(); + session_count = settings.value("sessions", 0).toInt(); + + for (i = 0; i < session_count; i++) { + settings.beginGroup("Session" + QString::number(i)); + shared_ptr session = add_session(); + session->restore_settings(settings); + settings.endGroup(); + } } } @@ -720,7 +735,8 @@ void MainWindow::on_tab_close_requested(int index) { shared_ptr session = get_tab_session(index); - assert(session); + if (!session) + return; if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"), tr("This session contains unsaved data. Close it anyway?"),