src/ui/polygonobjecteditor.cpp

changeset 83
b8bd338eb602
parent 81
62373840e33a
child 84
7137c20979af
equal deleted inserted replaced
82:70c67c2c4e36 83:b8bd338eb602
1 #include <QVBoxLayout> 1 #include <QVBoxLayout>
2 #include <QSplitter>
2 #include "model.h" 3 #include "model.h"
3 #include "widgets/vec3editor.h" 4 #include "widgets/vec3editor.h"
4 #include "polygonobjecteditor.h" 5 #include "polygonobjecteditor.h"
5 6
6 PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) : 7 PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) :
7 QWidget{parent}, 8 QWidget{parent},
8 model{model}, 9 model{model},
9 storedObjectId{ldraw::NULL_ID.value} 10 storedObjectId{ldraw::NULL_ID.value}
10 { 11 {
11 this->setLayout(new QVBoxLayout{this}); 12 this->setLayout(new QVBoxLayout{this});
13 for (std::optional<Vec3Editor>& editorPointer : this->vec3Editors)
14 {
15 editorPointer.emplace(glm::vec3{}, this);
16 this->layout()->addWidget(&*editorPointer);
17 }
18 this->layout()->addWidget(new QSplitter{Qt::Vertical, this});
12 this->setObjectId(id); 19 this->setObjectId(id);
13 } 20 }
14 21
15 // destructor needed for std::unique_ptr 22 // destructor needed for std::unique_ptr
16 PolygonObjectEditor::~PolygonObjectEditor() 23 PolygonObjectEditor::~PolygonObjectEditor()
29 } 36 }
30 37
31 void PolygonObjectEditor::updateNumRows() 38 void PolygonObjectEditor::updateNumRows()
32 { 39 {
33 const ldraw::Object* object = model->get(this->storedObjectId); 40 const ldraw::Object* object = model->get(this->storedObjectId);
34 const int number = object->numPoints(); 41 const int numPoints = object->numPoints();
35 if (static_cast<int>(this->vec3Editors.size()) > number) 42 for (int i = 0; i < countof(this->vec3Editors); i += 1)
36 { 43 {
37 this->vec3Editors.resize(number); 44 Vec3Editor& editor = *this->vec3Editors[i];
38 } 45 if (i < numPoints)
39 else
40 {
41 while (static_cast<int>(this->vec3Editors.size()) < number)
42 { 46 {
43 const glm::vec3& value = object->getPoint(this->vec3Editors.size()); 47 editor.setVisible(true);
44 this->vec3Editors.emplace_back(std::make_unique<Vec3Editor>(value, this)); 48 editor.setValue(object->getPoint(i));
45 this->layout()->addWidget(this->vec3Editors.back().get()); 49 }
50 else
51 {
52 editor.setVisible(false);
53 editor.setValue(glm::vec3{});
46 } 54 }
47 } 55 }
48 } 56 }

mercurial