reworked selection model handling

Thu, 07 Feb 2019 15:43:18 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 07 Feb 2019 15:43:18 +0200
changeset 1439
36a4e5b156f7
parent 1438
988b6563d47d

reworked selection model handling

src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/mainwindow.h file | annotate | diff | comparison | revisions
--- a/src/mainwindow.cpp	Thu Feb 07 13:45:07 2019 +0200
+++ b/src/mainwindow.cpp	Thu Feb 07 15:43:18 2019 +0200
@@ -473,6 +473,26 @@
 	}
 }
 
+/*
+ * Returns the selection model associated with the given document. If the model does not
+ * exist yet, it will be created.
+ */
+auto MainWindow::selectionModelForDocument
+(
+	LDDocument* document
+) -> QItemSelectionModel*
+{
+	QItemSelectionModel* selectionModel = m_selectionModels[document];
+
+	if (selectionModel == nullptr)
+	{
+		selectionModel = new QItemSelectionModel;
+		m_selectionModels[document] = selectionModel;
+	}
+
+	return selectionModel;
+}
+
 // ---------------------------------------------------------------------------------------------------------------------
 //
 void MainWindow::spawnContextMenu (const QPoint& position)
@@ -845,6 +865,7 @@
 	m_subWindows[canvas] = subWindow;
 	connect(canvas, &gl::Renderer::closed, this, &MainWindow::canvasClosed);
 	ui.viewport->setActiveSubWindow(subWindow);
+	canvas->setSelectionModel(selectionModelForDocument(document));
 	return canvas;
 }
 
@@ -894,10 +915,6 @@
 		Canvas* canvas = getRendererForDocument(document);
 		updateDocumentList();
 		connect(document, &LDDocument::windingChanged, canvas, &Canvas::fullUpdate);
-
-		QItemSelectionModel* selection = new QItemSelectionModel;
-		m_selectionModels[document] = selection;
-		canvas->setSelectionModel(selection);
 	}
 }
 
@@ -934,8 +951,7 @@
 		for (Canvas* canvas : m_renderers[document])
 			canvas->fullUpdate();
 
-		QItemSelectionModel* selection = m_selectionModels.value(document);
-		ui.objectList->setSelectionModel(selection);
+		ui.objectList->setSelectionModel(selectionModelForDocument(document));
 
 	}
 }
@@ -982,7 +998,7 @@
 
 	if (selectionModel != m_selectionModels.end())
 	{
-		delete *selectionModel;
+		(*selectionModel)->deleteLater();
 		m_selectionModels.erase(selectionModel);
 	}
 }
--- a/src/mainwindow.h	Thu Feb 07 13:45:07 2019 +0200
+++ b/src/mainwindow.h	Thu Feb 07 15:43:18 2019 +0200
@@ -126,6 +126,8 @@
 	QMap<Canvas*, QMdiSubWindow*> m_subWindows;
 	int previousDivisions = MediumResolution;
 
+	QItemSelectionModel* selectionModelForDocument(LDDocument* document);
+
 private slots:
 	void finishInitialization();
 	void recentFileClicked();

mercurial