diff -r 40e2940605a3 -r 4bec0525ef1b src/ui/polygonobjecteditor.cpp --- a/src/ui/polygonobjecteditor.cpp Wed Mar 18 17:11:23 2020 +0200 +++ b/src/ui/polygonobjecteditor.cpp Thu Mar 19 21:06:06 2020 +0200 @@ -1,8 +1,11 @@ #include #include #include "model.h" +#include "modeleditcontext.h" #include "widgets/vec3editor.h" -#include "polygonobjecteditor.h" +#include "ui/polygonobjecteditor.h" + +constexpr char COLUMN_PROPERTY[] = "_ldforge_column"; PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) : QWidget{parent}, @@ -10,10 +13,13 @@ storedObjectId{ldraw::NULL_ID.value} { this->setLayout(new QVBoxLayout{this}); - for (std::optional& editorPointer : this->vec3Editors) + for (int i = 0; i < countof(this->vec3Editors); i += 1) { + std::optional& editorPointer = this->vec3Editors[i]; editorPointer.emplace(glm::vec3{}, this); + editorPointer->setProperty(COLUMN_PROPERTY, QVariant::fromValue(i)); this->layout()->addWidget(&*editorPointer); + connect(&*editorPointer, &Vec3Editor::valueChanged, this, &PolygonObjectEditor::vectorChanged); } this->layout()->addWidget(new QSplitter{Qt::Vertical, this}); this->setObjectId(id); @@ -35,6 +41,17 @@ this->updateNumRows(); } +void PolygonObjectEditor::vectorChanged(const glm::vec3& value) +{ + bool ok; + const int num = sender()->property(COLUMN_PROPERTY).toInt(&ok); + if (ok and num >= 0 and num < countof(this->vec3Editors)) + { + Model::EditContext editor = this->model->edit(); + editor.setObjectPoint(this->objectId(), num, value); + } +} + void PolygonObjectEditor::updateNumRows() { const ldraw::Object* object = model->get(this->storedObjectId); @@ -42,6 +59,7 @@ for (int i = 0; i < countof(this->vec3Editors); i += 1) { Vec3Editor& editor = *this->vec3Editors[i]; + QSignalBlocker blocker{&editor}; if (i < numPoints) { editor.setVisible(true);