diff -r 2bdc3ac5e77c -r 55a55a9ec2c2 src/objecttypes/modelobject.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/objecttypes/modelobject.cpp Sun Sep 22 11:51:41 2019 +0300 @@ -0,0 +1,81 @@ +#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); + } +}