1 #include <QVBoxLayout> |
1 #include <QVBoxLayout> |
2 #include <QSplitter> |
2 #include <QSplitter> |
3 #include "model.h" |
3 #include "model.h" |
|
4 #include "modeleditcontext.h" |
4 #include "widgets/vec3editor.h" |
5 #include "widgets/vec3editor.h" |
5 #include "polygonobjecteditor.h" |
6 #include "ui/polygonobjecteditor.h" |
|
7 |
|
8 constexpr char COLUMN_PROPERTY[] = "_ldforge_column"; |
6 |
9 |
7 PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) : |
10 PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) : |
8 QWidget{parent}, |
11 QWidget{parent}, |
9 model{model}, |
12 model{model}, |
10 storedObjectId{ldraw::NULL_ID.value} |
13 storedObjectId{ldraw::NULL_ID.value} |
11 { |
14 { |
12 this->setLayout(new QVBoxLayout{this}); |
15 this->setLayout(new QVBoxLayout{this}); |
13 for (std::optional<Vec3Editor>& editorPointer : this->vec3Editors) |
16 for (int i = 0; i < countof(this->vec3Editors); i += 1) |
14 { |
17 { |
|
18 std::optional<Vec3Editor>& editorPointer = this->vec3Editors[i]; |
15 editorPointer.emplace(glm::vec3{}, this); |
19 editorPointer.emplace(glm::vec3{}, this); |
|
20 editorPointer->setProperty(COLUMN_PROPERTY, QVariant::fromValue(i)); |
16 this->layout()->addWidget(&*editorPointer); |
21 this->layout()->addWidget(&*editorPointer); |
|
22 connect(&*editorPointer, &Vec3Editor::valueChanged, this, &PolygonObjectEditor::vectorChanged); |
17 } |
23 } |
18 this->layout()->addWidget(new QSplitter{Qt::Vertical, this}); |
24 this->layout()->addWidget(new QSplitter{Qt::Vertical, this}); |
19 this->setObjectId(id); |
25 this->setObjectId(id); |
20 } |
26 } |
21 |
27 |
33 { |
39 { |
34 this->storedObjectId = id; |
40 this->storedObjectId = id; |
35 this->updateNumRows(); |
41 this->updateNumRows(); |
36 } |
42 } |
37 |
43 |
|
44 void PolygonObjectEditor::vectorChanged(const glm::vec3& value) |
|
45 { |
|
46 bool ok; |
|
47 const int num = sender()->property(COLUMN_PROPERTY).toInt(&ok); |
|
48 if (ok and num >= 0 and num < countof(this->vec3Editors)) |
|
49 { |
|
50 Model::EditContext editor = this->model->edit(); |
|
51 editor.setObjectPoint(this->objectId(), num, value); |
|
52 } |
|
53 } |
|
54 |
38 void PolygonObjectEditor::updateNumRows() |
55 void PolygonObjectEditor::updateNumRows() |
39 { |
56 { |
40 const ldraw::Object* object = model->get(this->storedObjectId); |
57 const ldraw::Object* object = model->get(this->storedObjectId); |
41 const int numPoints = object != nullptr ? object->numPoints() : 0; |
58 const int numPoints = object != nullptr ? object->numPoints() : 0; |
42 for (int i = 0; i < countof(this->vec3Editors); i += 1) |
59 for (int i = 0; i < countof(this->vec3Editors); i += 1) |
43 { |
60 { |
44 Vec3Editor& editor = *this->vec3Editors[i]; |
61 Vec3Editor& editor = *this->vec3Editors[i]; |
|
62 QSignalBlocker blocker{&editor}; |
45 if (i < numPoints) |
63 if (i < numPoints) |
46 { |
64 { |
47 editor.setVisible(true); |
65 editor.setVisible(true); |
48 editor.setValue(object->getPoint(i)); |
66 editor.setValue(object->getPoint(i)); |
49 } |
67 } |