src/ui/objecteditor.cpp

Tue, 14 Jun 2022 19:50:31 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 14 Jun 2022 19:50:31 +0300
changeset 218
63125c36de73
parent 200
ca23936b455b
child 232
8efa3a33172e
permissions
-rw-r--r--

Replace config collector with a simpler system

#include <QCheckBox>
#include <QLineEdit>
#include <QFormLayout>
#include "objecteditor.h"
#include "document.h"
#include "widgets/colorbutton.h"
#include "widgets/colorindexinput.h"
#include "widgets/vec3editor.h"
#include "ui_objecteditor.h"

using PropertyValue = std::variant<
	const glm::vec3*,
	const glm::mat4*,
	const QString*,
	ldraw::Color>;

enum PropertyKey
{
	Point1,
	Point2,
	Point3,
	Point4,
	Control1,
	Control2,
	Color,
	Transformation,
	Name,
	Text,
	Code,
};

std::map<PropertyKey, PropertyValue> getProperties(const ModelElement& element)
{
	std::map<PropertyKey, PropertyValue> result;
	std::visit<void>(overloaded{
		[&](const Colored<LineSegment>& edge) {
			result[Point1] = &edge.p1;
			result[Point2] = &edge.p2;
			result[Color] = edge.color;
		},
		[&](const Colored<Triangle>& tri) {
			result[Point1] = &tri.p1;
			result[Point2] = &tri.p2;
			result[Point3] = &tri.p3;
			result[Color] = tri.color;
		},
		[&](const Colored<Quadrilateral>& quad) {
			result[Point1] = &quad.p1;
			result[Point2] = &quad.p2;
			result[Point3] = &quad.p3;
			result[Point4] = &quad.p4;
			result[Color] = quad.color;
		},
		[&](const Colored<ConditionalEdge>& cedge) {
			result[Point1] = &cedge.p1;
			result[Point2] = &cedge.p2;
			result[Control1] = &cedge.c1;
			result[Control2] = &cedge.c2;
			result[Color] = cedge.color;
		},
		[&](const Colored<SubfileReference>& ref) {
			result[Transformation] = &ref.transformation;
			result[Name] = &ref.name;
			result[Color] = ref.color;
		},
		[&](Empty) {},
		[&](const Comment& comment) {
			result[Text] = &comment.text;
		},
		[&](const ParseError& parseError) {
			result[Code] = &parseError.code;
		},
	}, element);
	return result;
}

mercurial