--- a/src/mainwindow.cpp Tue Jan 01 22:30:10 2019 +0200 +++ b/src/mainwindow.cpp Thu Feb 07 13:45:07 2019 +0200 @@ -188,6 +188,9 @@ delete m_grid; delete &ui; + for (QItemSelectionModel* model : m_selectionModels) + delete model; + for (Toolset* toolset : m_toolsets) delete toolset; } @@ -840,7 +843,7 @@ m_renderers[document].append(canvas); QMdiSubWindow* const subWindow = ui.viewport->addSubWindow(canvas); m_subWindows[canvas] = subWindow; - connect(canvas, &QObject::destroyed, this, &MainWindow::canvasClosed); + connect(canvas, &gl::Renderer::closed, this, &MainWindow::canvasClosed); ui.viewport->setActiveSubWindow(subWindow); return canvas; } @@ -873,6 +876,7 @@ { Canvas* canvas = qobject_cast<Canvas*>(sender()); + Q_ASSERT(canvas != nullptr); if (canvas != nullptr) { LDDocument* const document = canvas->document(); @@ -890,6 +894,10 @@ Canvas* canvas = getRendererForDocument(document); updateDocumentList(); connect(document, &LDDocument::windingChanged, canvas, &Canvas::fullUpdate); + + QItemSelectionModel* selection = new QItemSelectionModel; + m_selectionModels[document] = selection; + canvas->setSelectionModel(selection); } } @@ -927,19 +935,8 @@ canvas->fullUpdate(); QItemSelectionModel* selection = m_selectionModels.value(document); - - if (selection == nullptr) - { - selection = new QItemSelectionModel; - m_selectionModels[document] = selection; + ui.objectList->setSelectionModel(selection); - for (Canvas* canvas : m_renderers[document]) - canvas->setSelectionModel(m_selectionModels[document]); - } - else - { - ui.objectList->setSelectionModel(selection); - } } }