src/linetypes/object.h

Sat, 14 Dec 2019 23:00:01 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 14 Dec 2019 23:00:01 +0200
changeset 20
cef43609a374
parent 17
a5111f4e6412
child 21
0133e565e072
permissions
-rw-r--r--

fixed build

#pragma once
#include <QPointF>
#include <QString>
#include <QStringView>
#include "main.h"
#include "colors.h"
#include "vertex.h"

namespace linetypes
{
	struct Id { unsigned int value; };
	enum class Property;
	class Object;
	class ColoredObject;
	class Empty;
}

/**
 * @brief Different properties that can be queried with getProperty
 */
enum class linetypes::Property
{
	Color, // Color of the object
	Text, // Text contained in a comment
	Point1, // First vertex in a polygon or edge line
	Point2, // Second vertex in a polygon or edge line
	Point3, // Third vertex in a polygon
	Point4, // Fourth vertex in a quadrilateral
	ControlPoint1, // First control point in a conditional edge line
	ControlPoint2, // Second control point in a conditional edge line
	Position, // Position of a subfile reference
	Transformation, // Transformation matrix of a subfile reference
	ReferenceName, // Subfile reference name
	IsInverted, // Whether or not the object has been inverted with BFC INVERTNEXT
	ErrorMessage // For error lines, why parsing failed
};

class linetypes::Object
{
public:
	enum class SetPropertyResult
	{
		Success = 0,
		PropertyNotHandled,
		InvalidValue
	};
	Object();
	Object(const Object&) = delete;
	virtual ~Object();
	const Id id;
	//virtual void toString(QTextStream &out) = 0;
	virtual bool hasColor() const;
	virtual QVariant getProperty(Property id) const;
	virtual SetPropertyResult setProperty(Property id, const QVariant& value);
	virtual QString textRepresentation() const = 0;
	virtual QBrush textRepresentationForeground() const;
	virtual QBrush textRepresentationBackground() const;
	virtual QFont textRepresentationFont() const;
};

class linetypes::ColoredObject : public Object
{
public:
	ColoredObject(const Color colorIndex = colors::main);
	bool hasColor() const override final;
	QVariant getProperty(Property id) const override;
	SetPropertyResult setProperty(Property id, const QVariant& value) override;
private:
	Color colorIndex = colors::main;
};

/**
 * @brief Represents an empty line.
 */
class linetypes::Empty : public Object
{
	QString textRepresentation() const override;
};

mercurial