src/ui/polygonobjecteditor.cpp

changeset 81
62373840e33a
child 83
b8bd338eb602
equal deleted inserted replaced
80:764381756899 81:62373840e33a
1 #include <QVBoxLayout>
2 #include "model.h"
3 #include "widgets/vec3editor.h"
4 #include "polygonobjecteditor.h"
5
6 PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) :
7 QWidget{parent},
8 model{model},
9 storedObjectId{ldraw::NULL_ID.value}
10 {
11 this->setLayout(new QVBoxLayout{this});
12 this->setObjectId(id);
13 }
14
15 // destructor needed for std::unique_ptr
16 PolygonObjectEditor::~PolygonObjectEditor()
17 {
18 }
19
20 ldraw::id_t PolygonObjectEditor::objectId() const
21 {
22 return this->storedObjectId;
23 }
24
25 void PolygonObjectEditor::setObjectId(ldraw::id_t id)
26 {
27 this->storedObjectId = id;
28 this->updateNumRows();
29 }
30
31 void PolygonObjectEditor::updateNumRows()
32 {
33 const ldraw::Object* object = model->get(this->storedObjectId);
34 const int number = object->numPoints();
35 if (static_cast<int>(this->vec3Editors.size()) > number)
36 {
37 this->vec3Editors.resize(number);
38 }
39 else
40 {
41 while (static_cast<int>(this->vec3Editors.size()) < number)
42 {
43 const glm::vec3& value = object->getPoint(this->vec3Editors.size());
44 this->vec3Editors.emplace_back(std::make_unique<Vec3Editor>(value, this));
45 this->layout()->addWidget(this->vec3Editors.back().get());
46 }
47 }
48 }

mercurial