src/mainwindow.cpp

changeset 1249
6a8f76f0f4d1
parent 1246
0054d13ed614
child 1250
e2755ccf3667
--- a/src/mainwindow.cpp	Thu Feb 15 12:19:10 2018 +0200
+++ b/src/mainwindow.cpp	Thu Feb 15 14:40:59 2018 +0200
@@ -22,6 +22,7 @@
 #include <QFileDialog>
 #include <QPushButton>
 #include <QSettings>
+#include "generics/reverse.h"
 #include "main.h"
 #include "canvas.h"
 #include "mainwindow.h"
@@ -316,17 +317,19 @@
 //
 int MainWindow::deleteSelection()
 {
-	if (selectedObjects().isEmpty())
-		return 0;
-
-	QSet<LDObject*> selectionCopy = selectedObjects();
+	int count = 0;
+	QModelIndexList thingsToRemove = ui.objectList->selectionModel()->selectedIndexes();
 
-	// Delete the objects that were being selected
-	for (LDObject* object : selectionCopy)
-		m_currentDocument->remove(object);
+	for (QModelIndex index : reverse(thingsToRemove))
+	{
+		if (m_currentDocument->hasIndex(index.row(), index.column()))
+		{
+			m_currentDocument->removeAt(index);
+			count += 1;
+		}
+	}
 
-	refresh();
-	return countof(selectionCopy);
+	return count;
 }
 
 // ---------------------------------------------------------------------------------------------------------------------

mercurial