src/ui/polygonobjecteditor.cpp

changeset 83
b8bd338eb602
parent 81
62373840e33a
child 84
7137c20979af
--- a/src/ui/polygonobjecteditor.cpp	Tue Mar 17 23:13:47 2020 +0200
+++ b/src/ui/polygonobjecteditor.cpp	Wed Mar 18 15:52:16 2020 +0200
@@ -1,4 +1,5 @@
 #include <QVBoxLayout>
+#include <QSplitter>
 #include "model.h"
 #include "widgets/vec3editor.h"
 #include "polygonobjecteditor.h"
@@ -9,6 +10,12 @@
 	storedObjectId{ldraw::NULL_ID.value}
 {
 	this->setLayout(new QVBoxLayout{this});
+	for (std::optional<Vec3Editor>& editorPointer : this->vec3Editors)
+	{
+		editorPointer.emplace(glm::vec3{}, this);
+		this->layout()->addWidget(&*editorPointer);
+	}
+	this->layout()->addWidget(new QSplitter{Qt::Vertical, this});
 	this->setObjectId(id);
 }
 
@@ -31,18 +38,19 @@
 void PolygonObjectEditor::updateNumRows()
 {
 	const ldraw::Object* object = model->get(this->storedObjectId);
-	const int number = object->numPoints();
-	if (static_cast<int>(this->vec3Editors.size()) > number)
+	const int numPoints = object->numPoints();
+	for (int i = 0; i < countof(this->vec3Editors); i += 1)
 	{
-		this->vec3Editors.resize(number);
-	}
-	else
-	{
-		while (static_cast<int>(this->vec3Editors.size()) < number)
+		Vec3Editor& editor = *this->vec3Editors[i];
+		if (i < numPoints)
 		{
-			const glm::vec3& value = object->getPoint(this->vec3Editors.size());
-			this->vec3Editors.emplace_back(std::make_unique<Vec3Editor>(value, this));
-			this->layout()->addWidget(this->vec3Editors.back().get());
+			editor.setVisible(true);
+			editor.setValue(object->getPoint(i));
+		}
+		else
+		{
+			editor.setVisible(false);
+			editor.setValue(glm::vec3{});
 		}
 	}
 }

mercurial