src/linetypes/object.cpp

changeset 14
20d2ed3af73d
parent 13
6e838748867b
child 17
a5111f4e6412
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/linetypes/object.cpp	Sun Nov 03 18:13:38 2019 +0200
@@ -0,0 +1,112 @@
+#include <QBrush>
+#include <QFont>
+#include "object.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;
+}
+
+linetypes::Object::Object() :
+	id {getIdForNewObject()}
+{
+}
+
+linetypes::Object::~Object()
+{
+}
+
+bool linetypes::Object::hasColor() const
+{
+	return false;
+}
+
+QVariant linetypes::Object::getProperty(Property id) const
+{
+	Q_UNUSED(id);
+	return {};
+}
+
+auto linetypes::Object::setProperty(Property id, const QVariant& value)
+	-> SetPropertyResult
+{
+	Q_UNUSED(id)
+	Q_UNUSED(value)
+	return SetPropertyResult::PropertyNotHandled;
+}
+
+QBrush linetypes::Object::textRepresentationForeground() const
+{
+	return {};
+}
+
+QBrush linetypes::Object::textRepresentationBackground() const
+{
+	return {};
+}
+
+QFont linetypes::Object::textRepresentationFont() const
+{
+	return {};
+}
+
+linetypes::ColoredObject::ColoredObject(const Color color_index) :
+	colorIndex{color_index}
+{
+}
+
+bool linetypes::ColoredObject::hasColor() const
+{
+	return true;
+}
+
+QVariant linetypes::ColoredObject::getProperty(Property id) const
+{
+	switch (id)
+	{
+	case Property::Color:
+		return colorIndex.index;
+	default:
+		return Object::getProperty(id);
+	}
+}
+
+auto linetypes::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 linetypes::Empty::textRepresentation() const
+{
+	return "";
+}

mercurial