src/objecttypes/modelobject.cpp

Mon, 23 Sep 2019 14:06:36 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 23 Sep 2019 14:06:36 +0300
changeset 4
68988ebc2a68
parent 3
55a55a9ec2c2
child 6
73e448b2943d
permissions
-rw-r--r--

added regular expressions for the parser

#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