refactor, added splitter

Wed, 18 Mar 2020 15:52:16 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 18 Mar 2020 15:52:16 +0200
changeset 83
b8bd338eb602
parent 82
70c67c2c4e36
child 84
7137c20979af

refactor, added splitter

src/ui/polygonobjecteditor.cpp file | annotate | diff | comparison | revisions
src/ui/polygonobjecteditor.h file | annotate | diff | comparison | revisions
src/widgets/vec3editor.h file | annotate | diff | comparison | revisions
--- 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{});
 		}
 	}
 }
--- a/src/ui/polygonobjecteditor.h	Tue Mar 17 23:13:47 2020 +0200
+++ b/src/ui/polygonobjecteditor.h	Wed Mar 18 15:52:16 2020 +0200
@@ -1,6 +1,7 @@
 #pragma once
 #include <QWidget>
 #include "main.h"
+#include "../widgets/vec3editor.h"
 
 class Model;
 
@@ -15,5 +16,5 @@
 	void updateNumRows();
 	Model* model;
 	ldraw::id_t storedObjectId;
-	std::vector<std::unique_ptr<class Vec3Editor>> vec3Editors;
+	std::optional<Vec3Editor> vec3Editors[4];
 };
--- a/src/widgets/vec3editor.h	Tue Mar 17 23:13:47 2020 +0200
+++ b/src/widgets/vec3editor.h	Wed Mar 18 15:52:16 2020 +0200
@@ -15,7 +15,7 @@
 	{
 		NoMultiplyButton = 0x1
 	};
-	explicit Vec3Editor(const glm::vec3& value = {}, QWidget* parent = nullptr, QFlags<Flag> flags = 0);
+	explicit Vec3Editor(const glm::vec3& value, QWidget* parent = nullptr, QFlags<Flag> flags = 0);
 	~Vec3Editor();
 	glm::vec3 value() const;
 	void setValue(const glm::vec3& value);

mercurial