src/objecttypes/polygon.cpp

Sat, 05 Oct 2019 23:47:03 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 05 Oct 2019 23:47:03 +0300
changeset 7
68443f5be176
parent 6
73e448b2943d
child 8
44679e468ba9
permissions
-rw-r--r--

added the settings editor

#include "polygon.h"

modelobjects::Triangle::Triangle(
	const Vertex& point_1,
	const Vertex& point_2,
	const Vertex& point_3,
	Color color_index) :
	ColoredBaseObject{color_index},
	points{point_1, point_2, point_3}
{
}

QVariant modelobjects::Triangle::getProperty(const Property id) const
{
	switch (id)
	{
	case Property::Point1:
		return points[0];
	case Property::Point2:
		return points[1];
	case Property::Point3:
		return points[2];
	default:
		return ColoredBaseObject::getProperty(id);
	}
}

auto modelobjects::Triangle::setProperty(Property id, const QVariant& value)
	-> SetPropertyResult
{
	switch (id)
	{
	case Property::Point1:
		points[0] = value.value<Vertex>();
		return SetPropertyResult::Success;
	case Property::Point2:
		points[1] = value.value<Vertex>();
		return SetPropertyResult::Success;
	case Property::Point3:
		points[2] = value.value<Vertex>();
		return SetPropertyResult::Success;
	default:
		return ColoredBaseObject::setProperty(id, value);
	}
}

QString modelobjects::Triangle::textRepresentation() const
{
	return format("%1 %2 %3",
		vertexToStringParens(points[0]),
		vertexToStringParens(points[1]),
		vertexToStringParens(points[2]));
}

modelobjects::Quadrilateral::Quadrilateral(
	const Vertex& point_1,
	const Vertex& point_2,
	const Vertex& point_3,
	const Vertex& point_4,
	Color color_index) :
	ColoredBaseObject{color_index},
	points{point_1, point_2, point_3, point_4}
{
}

QVariant modelobjects::Quadrilateral::getProperty(const Property id) const
{
	switch (id)
	{
	case Property::Point1:
		return points[0];
	case Property::Point2:
		return points[1];
	case Property::Point3:
		return points[2];
	case Property::Point4:
		return points[3];
	default:
		return ColoredBaseObject::getProperty(id);
	}
}

auto modelobjects::Quadrilateral::setProperty(
	const Property id,
	const QVariant& value)
	-> SetPropertyResult
{
	switch (id)
	{
	case Property::Point1:
		points[0] = value.value<Vertex>();
		return SetPropertyResult::Success;
	case Property::Point2:
		points[1] = value.value<Vertex>();
		return SetPropertyResult::Success;
	case Property::Point3:
		points[2] = value.value<Vertex>();
		return SetPropertyResult::Success;
	case Property::Point4:
		points[3] = value.value<Vertex>();
		return SetPropertyResult::Success;
	default:
		return ColoredBaseObject::setProperty(id, value);
	}
}

QString modelobjects::Quadrilateral::textRepresentation() const
{
	return format("%1 %2 %3 %4",
		vertexToStringParens(points[0]),
		vertexToStringParens(points[1]),
		vertexToStringParens(points[2]),
		vertexToStringParens(points[3]));
}

mercurial