src/ui/polygonobjecteditor.cpp

changeset 81
62373840e33a
child 83
b8bd338eb602
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ui/polygonobjecteditor.cpp	Tue Mar 17 23:13:29 2020 +0200
@@ -0,0 +1,48 @@
+#include <QVBoxLayout>
+#include "model.h"
+#include "widgets/vec3editor.h"
+#include "polygonobjecteditor.h"
+
+PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) :
+	QWidget{parent},
+	model{model},
+	storedObjectId{ldraw::NULL_ID.value}
+{
+	this->setLayout(new QVBoxLayout{this});
+	this->setObjectId(id);
+}
+
+// destructor needed for std::unique_ptr
+PolygonObjectEditor::~PolygonObjectEditor()
+{
+}
+
+ldraw::id_t PolygonObjectEditor::objectId() const
+{
+	return this->storedObjectId;
+}
+
+void PolygonObjectEditor::setObjectId(ldraw::id_t id)
+{
+	this->storedObjectId = id;
+	this->updateNumRows();
+}
+
+void PolygonObjectEditor::updateNumRows()
+{
+	const ldraw::Object* object = model->get(this->storedObjectId);
+	const int number = object->numPoints();
+	if (static_cast<int>(this->vec3Editors.size()) > number)
+	{
+		this->vec3Editors.resize(number);
+	}
+	else
+	{
+		while (static_cast<int>(this->vec3Editors.size()) < number)
+		{
+			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());
+		}
+	}
+}

mercurial