src/objecttypes/modelobject.cpp

Sun, 03 Nov 2019 13:18:55 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 03 Nov 2019 13:18:55 +0200
changeset 11
771168ee2c76
parent 8
44679e468ba9
child 13
6e838748867b
permissions
-rw-r--r--

added matrix conversions and datastream operators

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

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

static unsigned int getIdForNewObject()
{
	static unsigned int id = 0;
	id += 1;
	return id;
}

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

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;
}

QBrush modelobjects::BaseObject::textRepresentationForeground() const
{
	return {};
}

QBrush modelobjects::BaseObject::textRepresentationBackground() const
{
	return {};
}

QFont modelobjects::BaseObject::textRepresentationFont() const
{
	return {};
}

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);
	}
}

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

mercurial