src/document.cpp

changeset 204
52e10e8d88cc
parent 203
1909a0123c72
child 205
1a4342d80de7
--- a/src/document.cpp	Tue Jun 07 21:35:29 2022 +0300
+++ b/src/document.cpp	Wed Jun 08 19:33:00 2022 +0300
@@ -32,7 +32,6 @@
 	colorTable{colorTable},
 	canvas{new Canvas{model, this, documents, colorTable, this}},
 	model{model},
-	documents{documents},
 	vertexMap{model}
 {
 	this->setMouseTracking(true);
@@ -183,31 +182,40 @@
 		switch (this->drawState.polygon.size())
 		{
 		case 2:
-			this->model->append(Colored<LineSegment>{
-				LineSegment{
-					.p1 = this->drawState.polygon[0],
-					.p2 = this->drawState.polygon[1],
-				},
-				ldraw::EDGE_COLOR});
+			Q_EMIT this->modelAction(AppendToModel{
+				.newElement = Colored<LineSegment>{
+					LineSegment{
+						.p1 = this->drawState.polygon[0],
+						.p2 = this->drawState.polygon[1],
+					},
+					ldraw::EDGE_COLOR,
+				}
+			});
 			break;
 		case 3:
-			this->model->append(Colored<Triangle>{
-				Triangle{
-					.p1 = this->drawState.polygon[0],
-					.p2 = this->drawState.polygon[1],
-					.p3 = this->drawState.polygon[2],
-				},
-				ldraw::MAIN_COLOR});
+			Q_EMIT this->modelAction(AppendToModel{
+				.newElement = Colored<Triangle>{
+					Triangle{
+						.p1 = this->drawState.polygon[0],
+						.p2 = this->drawState.polygon[1],
+						.p3 = this->drawState.polygon[2],
+					},
+					ldraw::MAIN_COLOR,
+				}
+			});
 			break;
 		case 4:
-			this->model->append(Colored<Quadrilateral>{
-				Quadrilateral{
-					.p1 = this->drawState.polygon[0],
-					.p2 = this->drawState.polygon[1],
-					.p3 = this->drawState.polygon[2],
-					.p4 = this->drawState.polygon[3],
-				},
-				ldraw::MAIN_COLOR});
+			Q_EMIT this->modelAction(AppendToModel{
+				.newElement = Colored<Quadrilateral>{
+					Quadrilateral{
+						.p1 = this->drawState.polygon[0],
+						.p2 = this->drawState.polygon[1],
+						.p3 = this->drawState.polygon[2],
+						.p4 = this->drawState.polygon[3],
+					},
+					ldraw::MAIN_COLOR,
+				}
+			});
 			break;
 		}
 	}

mercurial