src/linetypes/object.cpp

Thu, 27 Feb 2020 22:46:39 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 27 Feb 2020 22:46:39 +0200
changeset 61
4585d8d7a7ec
parent 46
98645c8e7704
child 81
62373840e33a
permissions
-rw-r--r--

moved GridProgram to Canvas

#include <QBrush>
#include <QFont>
#include "object.h"

static std::int32_t getIdForNewObject()
{
	static std::int32_t id = 0;
	id += 1;
	return id;
}

ldraw::Object::Object() :
	id {getIdForNewObject()}
{
}

ldraw::Object::~Object()
{
}

bool ldraw::Object::hasColor() const
{
	return false;
}

QVariant ldraw::Object::getProperty(Property id) const
{
	Q_UNUSED(id);
	return {};
}

auto ldraw::Object::setProperty(Property id, const QVariant& value)
	-> SetPropertyResult
{
	Q_UNUSED(id)
	Q_UNUSED(value)
	return SetPropertyResult::PropertyNotHandled;
}

QBrush ldraw::Object::textRepresentationForeground() const
{
	return {};
}

QBrush ldraw::Object::textRepresentationBackground() const
{
	return {};
}

QFont ldraw::Object::textRepresentationFont() const
{
	return {};
}

void ldraw::Object::getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const
{
	Q_UNUSED(polygons)
	Q_UNUSED(context)
}

ldraw::ColoredObject::ColoredObject(const Color color_index) :
	colorIndex{color_index}
{
}

bool ldraw::ColoredObject::hasColor() const
{
	return true;
}

QVariant ldraw::ColoredObject::getProperty(Property id) const
{
	switch (id)
	{
	case Property::Color:
		return colorIndex.index;
	default:
		return Object::getProperty(id);
	}
}

auto ldraw::ColoredObject::setProperty(Property id, const QVariant& value)
	-> SetPropertyResult
{
	switch (id)
	{
	case Property::Color:
		{
			bool ok;
			const int value_int = value.toInt(&ok);
			if (ok)
			{
				colorIndex.index = value_int;
				return SetPropertyResult::Success;
			}
			else
			{
				return SetPropertyResult::InvalidValue;
			}
		}
	default:
		return Object::setProperty(id, value);
	}
}

QString ldraw::Empty::textRepresentation() const
{
	return "";
}

mercurial