src/ui/polygonobjecteditor.cpp

Wed, 18 Mar 2020 15:54:30 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 18 Mar 2020 15:54:30 +0200
changeset 84
7137c20979af
parent 83
b8bd338eb602
child 86
4bec0525ef1b
permissions
-rw-r--r--

fix

#include <QVBoxLayout>
#include <QSplitter>
#include "model.h"
#include "widgets/vec3editor.h"
#include "polygonobjecteditor.h"

PolygonObjectEditor::PolygonObjectEditor(Model* model, ldraw::id_t id, QWidget* parent) :
	QWidget{parent},
	model{model},
	storedObjectId{ldraw::NULL_ID.value}
{
	this->setLayout(new QVBoxLayout{this});
	for (std::optional<Vec3Editor>& editorPointer : this->vec3Editors)
	{
		editorPointer.emplace(glm::vec3{}, this);
		this->layout()->addWidget(&*editorPointer);
	}
	this->layout()->addWidget(new QSplitter{Qt::Vertical, this});
	this->setObjectId(id);
}

// destructor needed for std::unique_ptr
PolygonObjectEditor::~PolygonObjectEditor()
{
}

ldraw::id_t PolygonObjectEditor::objectId() const
{
	return this->storedObjectId;
}

void PolygonObjectEditor::setObjectId(ldraw::id_t id)
{
	this->storedObjectId = id;
	this->updateNumRows();
}

void PolygonObjectEditor::updateNumRows()
{
	const ldraw::Object* object = model->get(this->storedObjectId);
	const int numPoints = object != nullptr ? object->numPoints() : 0;
	for (int i = 0; i < countof(this->vec3Editors); i += 1)
	{
		Vec3Editor& editor = *this->vec3Editors[i];
		if (i < numPoints)
		{
			editor.setVisible(true);
			editor.setValue(object->getPoint(i));
		}
		else
		{
			editor.setVisible(false);
			editor.setValue(glm::vec3{});
		}
	}
}

mercurial