# HG changeset patch # User Teemu Piippo # Date 1584539536 -7200 # Node ID b8bd338eb602f030d60b79276118b8ef0f07df60 # Parent 70c67c2c4e368b521aba5728117b66886175328b refactor, added splitter diff -r 70c67c2c4e36 -r b8bd338eb602 src/ui/polygonobjecteditor.cpp --- 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 +#include #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& 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(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(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(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{}); } } } diff -r 70c67c2c4e36 -r b8bd338eb602 src/ui/polygonobjecteditor.h --- 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 #include "main.h" +#include "../widgets/vec3editor.h" class Model; @@ -15,5 +16,5 @@ void updateNumRows(); Model* model; ldraw::id_t storedObjectId; - std::vector> vec3Editors; + std::optional vec3Editors[4]; }; diff -r 70c67c2c4e36 -r b8bd338eb602 src/widgets/vec3editor.h --- 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 flags = 0); + explicit Vec3Editor(const glm::vec3& value, QWidget* parent = nullptr, QFlags flags = 0); ~Vec3Editor(); glm::vec3 value() const; void setValue(const glm::vec3& value);