src/objecttypes/modelobject.cpp

Thu, 03 Oct 2019 11:45:44 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 03 Oct 2019 11:45:44 +0300
changeset 5
593a658cba8e
parent 3
55a55a9ec2c2
child 6
73e448b2943d
permissions
-rw-r--r--

stuff

#include "modelobject.h"

static Uuid &getUuidForNewObject()
{
    static Uuid running_uuid {0, 0};
    incrementUuid(running_uuid);
    return running_uuid;
}

modelobjects::BaseObject::BaseObject() :
    id {getUuidForNewObject()}
{
}

modelobjects::BaseObject::~BaseObject()
{
}

bool modelobjects::BaseObject::hasColor() const
{
	return false;
}

QVariant modelobjects::BaseObject::getProperty(Property id) const
{
	Q_UNUSED(id);
	return {};
}

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

modelobjects::ColoredBaseObject::ColoredBaseObject(const Color color_index) :
	color_index{color_index}
{
}

bool modelobjects::ColoredBaseObject::hasColor() const
{
	return true;
}

QVariant modelobjects::ColoredBaseObject::getProperty(Property id) const
{
	switch (id)
	{
	case Property::Color:
		return color_index.index;
	default:
		return BaseObject::getProperty(id);
	}
}

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

mercurial