MainWindow: Prevent Qt from restoring the dock widgets
[pulseview.git] / pv / mainwindow.cpp
index 41c748b75d2908e732e410251f3c5d8a65a14779..33870145232afdd654a750cac5046169d7051201 100644 (file)
@@ -131,6 +131,16 @@ MainWindow::MainWindow(DeviceManager &device_manager,
                load_init_file(open_file_name, open_file_format);
 }
 
+MainWindow::~MainWindow()
+{
+       for (auto entry : view_docks_) {
+               const std::shared_ptr<QDockWidget> dock = entry.first;
+               dock->setWidget(0);
+               const std::shared_ptr<pv::view::View> view = entry.second;
+               session_.deregister_view(view);
+       }
+}
+
 QAction* MainWindow::action_open() const
 {
        return action_open_;
@@ -258,6 +268,8 @@ shared_ptr<pv::view::View> MainWindow::add_view(const QString &title,
                        v->enable_coloured_bg(action_view_coloured_bg_->isChecked());
                        action_view_show_cursors_->setChecked(v->cursors_shown());
                }
+
+               session.register_view(v);
        }
 
        return v;
@@ -795,6 +807,22 @@ void MainWindow::keyReleaseEvent(QKeyEvent *event)
        QMainWindow::keyReleaseEvent(event);
 }
 
+QMenu* MainWindow::createPopupMenu()
+{
+       return nullptr;
+}
+
+bool MainWindow::restoreState(const QByteArray &state, int version)
+{
+       (void)state;
+       (void)version;
+
+       // Do nothing. We don't want Qt to handle this, or else it
+       // will try to restore all the dock widgets and create havoc.
+
+       return false;
+}
+
 void MainWindow::show_session_error(
        const QString text, const QString info_text)
 {