src/ui/polygonobjecteditor.cpp

Wed, 18 Mar 2020 15:52:16 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 18 Mar 2020 15:52:16 +0200
changeset 83
b8bd338eb602
parent 81
62373840e33a
child 84
7137c20979af
permissions
-rw-r--r--

refactor, added splitter

#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->numPoints();
	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