# HG changeset patch # User Teemu Piippo # Date 1572797618 -7200 # Node ID 20d2ed3af73db783e24ea180f6be4e0ca6867cf3 # Parent 6e838748867b167c7e09cfc361679f90e469b734 renamings diff -r 6e838748867b -r 20d2ed3af73d CMakeLists.txt --- a/CMakeLists.txt Sun Nov 03 18:09:47 2019 +0200 +++ b/CMakeLists.txt Sun Nov 03 18:13:38 2019 +0200 @@ -26,14 +26,14 @@ src/parser.cpp src/version.cpp src/vertex.cpp - src/objecttypes/comment.cpp - src/objecttypes/conditionaledge.cpp - src/objecttypes/edge.cpp - src/objecttypes/errorline.cpp - src/objecttypes/metacommand.cpp - src/objecttypes/modelobject.cpp - src/objecttypes/polygon.cpp - src/objecttypes/subfilereference.cpp + src/linetypes/comment.cpp + src/linetypes/conditionaledge.cpp + src/linetypes/edge.cpp + src/linetypes/errorline.cpp + src/linetypes/metacommand.cpp + src/linetypes/object.cpp + src/linetypes/polygon.cpp + src/linetypes/subfilereference.cpp src/settingseditor/librarieseditor.cpp src/settingseditor/settingseditor.cpp ) @@ -52,14 +52,14 @@ src/utility.h src/version.h src/vertex.h - src/objecttypes/comment.h - src/objecttypes/conditionaledge.h - src/objecttypes/edge.h - src/objecttypes/errorline.h - src/objecttypes/metacommand.h - src/objecttypes/modelobject.h - src/objecttypes/polygon.h - src/objecttypes/subfilereference.h + src/linetypes/comment.h + src/linetypes/conditionaledge.h + src/linetypes/edge.h + src/linetypes/errorline.h + src/linetypes/metacommand.h + src/linetypes/object.h + src/linetypes/polygon.h + src/linetypes/subfilereference.h src/settingseditor/librarieseditor.h src/settingseditor/settingseditor.h ) diff -r 6e838748867b -r 20d2ed3af73d src/documentmanager.cpp --- a/src/documentmanager.cpp Sun Nov 03 18:09:47 2019 +0200 +++ b/src/documentmanager.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -3,7 +3,7 @@ #include #include "documentmanager.h" #include "modeleditcontext.h" -#include "objecttypes/comment.h" +#include "linetypes/comment.h" #include "parser.h" /** diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/comment.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/comment.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,9 @@ +#include +#include "comment.h" + +QFont linetypes::Comment::textRepresentationFont() const +{ + QFont font; + font.setItalic(true); + return font; +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/comment.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/comment.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,14 @@ +#pragma once +#include "object.h" +#include "metacommand.h" + +namespace linetypes +{ + class Comment; +} + +class linetypes::Comment : public MetaCommand +{ + using MetaCommand::MetaCommand; + QFont textRepresentationFont() const override; +}; diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/conditionaledge.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/conditionaledge.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,56 @@ +#include "conditionaledge.h" + +linetypes::ConditionalEdge::ConditionalEdge( + const Vertex& point_1, + const Vertex& point_2, + const Vertex& controlPoint_1, + const Vertex& controlPoint_2, + const Color color_index) : + Edge{point_1, point_2, color_index}, + controlPoint_1{controlPoint_1}, + controlPoint_2{controlPoint_2} +{ +} + +linetypes::ConditionalEdge::ConditionalEdge(const QVector& vertices, const Color color) : + Edge{vertices[0], vertices[1], color}, + controlPoint_1{vertices[2]}, + controlPoint_2{vertices[3]} +{ +} + +QVariant linetypes::ConditionalEdge::getProperty(Property property) const +{ + switch (property) + { + case Property::ControlPoint1: + return controlPoint_1; + case Property::ControlPoint2: + return controlPoint_2; + default: + return Edge::getProperty(property); + } +} + +auto linetypes::ConditionalEdge::setProperty( + Property property, + const QVariant& value) + -> SetPropertyResult +{ + switch (property) + { + case Property::ControlPoint1: + controlPoint_1 = value.value(); + case Property::ControlPoint2: + controlPoint_2 = value.value(); + default: + return Edge::setProperty(property, value); + } +} + +QString linetypes::ConditionalEdge::textRepresentation() const +{ + return Edge::textRepresentation() + utility::format("%1 %2", + vertexToStringParens(controlPoint_1), + vertexToStringParens(controlPoint_2)); +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/conditionaledge.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/conditionaledge.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,28 @@ +#pragma once +#include "edge.h" + +namespace linetypes +{ + class ConditionalEdge; +} + +class linetypes::ConditionalEdge : public Edge +{ +public: + ConditionalEdge() = default; + ConditionalEdge( + const Vertex& point_1, + const Vertex& point_2, + const Vertex& controlPoint_1, + const Vertex& controlPoint_2, + const Color colorIndex = colors::edge); + ConditionalEdge(const QVector& vertices, const Color color); + QVariant getProperty(Property property) const override; + SetPropertyResult setProperty( + Property property, + const QVariant& value) override; + QString textRepresentation() const override; +private: + Vertex controlPoint_1 = {}; + Vertex controlPoint_2 = {}; +}; diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/edge.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/edge.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,50 @@ +#include "edge.h" + +linetypes::Edge::Edge( + const Vertex& point_1, + const Vertex& point_2, + const Color color_index) : + ColoredObject{color_index}, + point_1{point_1}, + point_2{point_2} {} + +linetypes::Edge::Edge(const QVector& vertices, const Color color) : + ColoredObject{color}, + point_1{vertices[0]}, + point_2{vertices[1]} +{ +} + +QVariant linetypes::Edge::getProperty(Property property) const +{ + switch (property) + { + case Property::Point1: + return point_1; + case Property::Point2: + return point_2; + default: + return BaseClass::getProperty(property); + } +} + +auto linetypes::Edge::setProperty(Property property, const QVariant& value) + -> SetPropertyResult +{ + switch (property) + { + case Property::Point1: + point_1 = value.value(); + return SetPropertyResult::Success; + case Property::Point2: + point_2 = value.value(); + return SetPropertyResult::Success; + default: + return BaseClass::setProperty(property, value); + } +} + +QString linetypes::Edge::textRepresentation() const +{ + return utility::format("%1 %2", vertexToStringParens(point_1), vertexToStringParens(point_2)); +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/edge.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/edge.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,25 @@ +#pragma once +#include "object.h" + +namespace linetypes +{ + class Edge; +} + +class linetypes::Edge : public ColoredObject +{ +public: + using BaseClass = ColoredObject; + Edge() = default; + Edge(const Vertex& point_1, const Vertex& point_2, + const Color colorIndex = colors::edge); + Edge(const QVector& vertices, const Color color); + QVariant getProperty(Property property) const override; + SetPropertyResult setProperty( + Property property, + const QVariant& value) override; + QString textRepresentation() const override; +private: + Vertex point_1 = {}; + Vertex point_2 = {}; +}; diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/errorline.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/errorline.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,54 @@ +#include +#include "errorline.h" + +linetypes::ErrorLine::ErrorLine(QStringView text, QStringView message) : + text{text.toString()}, + message{message.toString()} +{ +} + +QVariant linetypes::ErrorLine::getProperty(Property property) const +{ + switch (property) + { + case Property::Text: + return this->text; + case Property::ErrorMessage: + return this->message; + default: + return Object::getProperty(property); + } +} + +auto linetypes::ErrorLine::setProperty( + Property property, + const QVariant& value) + -> SetPropertyResult +{ + switch (property) + { + case Property::Text: + this->text = value.toString(); + return SetPropertyResult::Success; + case Property::ErrorMessage: + this->message = value.toString(); + return SetPropertyResult::Success; + default: + return Object::setProperty(property, value); + } +} + +QString linetypes::ErrorLine::textRepresentation() const +{ + return this->text; +} + +QBrush linetypes::ErrorLine::textRepresentationForeground() const +{ + return QBrush{Qt::yellow}; +} + +QBrush linetypes::ErrorLine::textRepresentationBackground() const +{ + return QBrush{Qt::red}; +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/errorline.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/errorline.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,23 @@ +#pragma once +#include "object.h" + +namespace linetypes +{ + class ErrorLine; +} + +class linetypes::ErrorLine : public Object +{ +public: + ErrorLine(QStringView text = u"", QStringView message = u""); + QVariant getProperty(Property property) const override; + SetPropertyResult setProperty( + Property property, + const QVariant& value) override; + QString textRepresentation() const override; + QBrush textRepresentationForeground() const override; + QBrush textRepresentationBackground() const override; +private: + QString text; + QString message; +}; diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/metacommand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/metacommand.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,34 @@ +#include "metacommand.h" + +linetypes::MetaCommand::MetaCommand(QStringView text) : + Object{}, + storedText{text.toString()} {} + +QVariant linetypes::MetaCommand::getProperty(Property property) const +{ + switch (property) + { + case Property::Text: + return storedText; + default: + return Object::getProperty(property); + } +} + +auto linetypes::MetaCommand::setProperty(Property property, const QVariant& value) + -> SetPropertyResult +{ + switch (property) + { + case Property::Text: + storedText = value.toString(); + return SetPropertyResult::Success; + default: + return Object::setProperty(property, value); + } +} + +QString linetypes::MetaCommand::textRepresentation() const +{ + return this->storedText; +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/metacommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/metacommand.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,20 @@ +#pragma once +#include "object.h" + +namespace linetypes +{ + class MetaCommand; +} +class linetypes::MetaCommand : public Object +{ +public: + MetaCommand() = default; + MetaCommand(QStringView text); + QVariant getProperty(Property property) const override; + SetPropertyResult setProperty( + Property property, + const QVariant& value) override; + QString textRepresentation() const override; +private: + QString storedText = ""; +}; diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/object.cpp --- /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 +#include +#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 ""; +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/object.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/object.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,82 @@ +#pragma once +#include +#include +#include +#include "main.h" +#include "colors.h" +#include "vertex.h" + +namespace linetypes +{ + 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 unsigned int 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; +}; + +namespace linetypes +{ + using Id = std::decay_t; +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/polygon.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/polygon.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,126 @@ +#include "polygon.h" + +linetypes::Triangle::Triangle( + const Vertex& point_1, + const Vertex& point_2, + const Vertex& point_3, + Color color_index) : + ColoredObject{color_index}, + points{point_1, point_2, point_3} +{ +} + +linetypes::Triangle::Triangle(const QVector& vertices, const Color color) : + ColoredObject{color}, + points{vertices[0], vertices[1], vertices[2]} +{ +} + +QVariant linetypes::Triangle::getProperty(const Property id) const +{ + switch (id) + { + case Property::Point1: + return points[0]; + case Property::Point2: + return points[1]; + case Property::Point3: + return points[2]; + default: + return ColoredObject::getProperty(id); + } +} + +auto linetypes::Triangle::setProperty(Property id, const QVariant& value) + -> SetPropertyResult +{ + switch (id) + { + case Property::Point1: + points[0] = value.value(); + return SetPropertyResult::Success; + case Property::Point2: + points[1] = value.value(); + return SetPropertyResult::Success; + case Property::Point3: + points[2] = value.value(); + return SetPropertyResult::Success; + default: + return ColoredObject::setProperty(id, value); + } +} + +QString linetypes::Triangle::textRepresentation() const +{ + return utility::format("%1 %2 %3", + vertexToStringParens(points[0]), + vertexToStringParens(points[1]), + vertexToStringParens(points[2])); +} + +linetypes::Quadrilateral::Quadrilateral( + const Vertex& point_1, + const Vertex& point_2, + const Vertex& point_3, + const Vertex& point_4, + Color color_index) : + ColoredObject{color_index}, + points{point_1, point_2, point_3, point_4} +{ +} + +linetypes::Quadrilateral::Quadrilateral(const QVector& vertices, const Color color) : + ColoredObject{color}, + points{vertices[0], vertices[1], vertices[2], vertices[3]} +{ +} + +QVariant linetypes::Quadrilateral::getProperty(const Property id) const +{ + switch (id) + { + case Property::Point1: + return points[0]; + case Property::Point2: + return points[1]; + case Property::Point3: + return points[2]; + case Property::Point4: + return points[3]; + default: + return ColoredObject::getProperty(id); + } +} + +auto linetypes::Quadrilateral::setProperty( + const Property id, + const QVariant& value) + -> SetPropertyResult +{ + switch (id) + { + case Property::Point1: + points[0] = value.value(); + return SetPropertyResult::Success; + case Property::Point2: + points[1] = value.value(); + return SetPropertyResult::Success; + case Property::Point3: + points[2] = value.value(); + return SetPropertyResult::Success; + case Property::Point4: + points[3] = value.value(); + return SetPropertyResult::Success; + default: + return ColoredObject::setProperty(id, value); + } +} + +QString linetypes::Quadrilateral::textRepresentation() const +{ + return utility::format("%1 %2 %3 %4", + vertexToStringParens(points[0]), + vertexToStringParens(points[1]), + vertexToStringParens(points[2]), + vertexToStringParens(points[3])); +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/polygon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/polygon.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,43 @@ +#include +#include "object.h" + +namespace linetypes +{ + class Triangle; + class Quadrilateral; +} + +class linetypes::Triangle : public ColoredObject +{ +public: + Triangle() = default; + Triangle( + const Vertex &point_1, + const Vertex &point_2, + const Vertex &point_3, + Color colorIndex = colors::main); + Triangle(const QVector& vertices, const Color color); + QVariant getProperty(Property id) const override; + SetPropertyResult setProperty(Property id, const QVariant& value) override; + QString textRepresentation() const override; +private: + Vertex points[3] = {{}}; +}; + +class linetypes::Quadrilateral : public ColoredObject +{ +public: + Quadrilateral() = default; + Quadrilateral( + const Vertex &point_1, + const Vertex &point_2, + const Vertex &point_3, + const Vertex &point_4, + Color colorIndex = colors::main); + Quadrilateral(const QVector& vertices, const Color color); + QVariant getProperty(Property id) const override; + SetPropertyResult setProperty(Property id, const QVariant& value) override; + QString textRepresentation() const override; +private: + Vertex points[4] = {{}}; +}; diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/subfilereference.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/subfilereference.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,54 @@ +#include "subfilereference.h" + +linetypes::SubfileReference::SubfileReference( + const Vertex& position, + const Matrix3x3& transformation, + const QString& referenceName, + const Color color) : + ColoredObject{color}, + position{position}, + transformation{transformation}, + referenceName{referenceName} +{ +} + +QVariant linetypes::SubfileReference::getProperty(Property property) const +{ + switch (property) + { + case Property::Position: + return this->position; + case Property::Transformation: + return QVariant::fromValue(this->transformation); + case Property::ReferenceName: + return this->referenceName; + default: + return ColoredObject::getProperty(property); + } +} + +auto linetypes::SubfileReference::setProperty( + Property property, + const QVariant& value) + -> SetPropertyResult +{ + switch (property) + { + case Property::Position: + this->position = value.value(); + return SetPropertyResult::Success; + case Property::Transformation: + this->transformation = value.value(); + return SetPropertyResult::Success; + case Property::ReferenceName: + this->referenceName = value.toString(); + return SetPropertyResult::Success; + default: + return ColoredObject::setProperty(property, value); + } +} + +QString linetypes::SubfileReference::textRepresentation() const +{ + return referenceName + " " + vertexToStringParens(this->position); +} diff -r 6e838748867b -r 20d2ed3af73d src/linetypes/subfilereference.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/subfilereference.h Sun Nov 03 18:13:38 2019 +0200 @@ -0,0 +1,26 @@ +#pragma once +#include "object.h" +#include "matrix.h" + +namespace linetypes +{ + class SubfileReference; +} + +class linetypes::SubfileReference : public ColoredObject +{ +public: + SubfileReference() = default; + SubfileReference( + const Vertex& position, + const Matrix3x3& transformation, + const QString &referenceName, + const Color color = colors::main); + QVariant getProperty(Property property) const override; + SetPropertyResult setProperty(Property property, const QVariant& value) override; + QString textRepresentation() const override; +private: + Vertex position; + Matrix3x3 transformation; + QString referenceName; +}; diff -r 6e838748867b -r 20d2ed3af73d src/model.h --- a/src/model.h Sun Nov 03 18:09:47 2019 +0200 +++ b/src/model.h Sun Nov 03 18:13:38 2019 +0200 @@ -3,7 +3,7 @@ #include #include "main.h" #include "header.h" -#include "objecttypes/modelobject.h" +#include "linetypes/object.h" enum class HeaderProperty { diff -r 6e838748867b -r 20d2ed3af73d src/modeleditcontext.h --- a/src/modeleditcontext.h Sun Nov 03 18:09:47 2019 +0200 +++ b/src/modeleditcontext.h Sun Nov 03 18:13:38 2019 +0200 @@ -1,6 +1,6 @@ #pragma once #include "model.h" -#include "objecttypes/modelobject.h" +#include "linetypes/object.h" class Model::EditContext { diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/comment.cpp --- a/src/objecttypes/comment.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#include -#include "comment.h" - -QFont linetypes::Comment::textRepresentationFont() const -{ - QFont font; - font.setItalic(true); - return font; -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/comment.h --- a/src/objecttypes/comment.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#pragma once -#include "modelobject.h" -#include "metacommand.h" - -namespace linetypes -{ - class Comment; -} - -class linetypes::Comment : public MetaCommand -{ - using MetaCommand::MetaCommand; - QFont textRepresentationFont() const override; -}; diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/conditionaledge.cpp --- a/src/objecttypes/conditionaledge.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -#include "conditionaledge.h" - -linetypes::ConditionalEdge::ConditionalEdge( - const Vertex& point_1, - const Vertex& point_2, - const Vertex& controlPoint_1, - const Vertex& controlPoint_2, - const Color color_index) : - Edge{point_1, point_2, color_index}, - controlPoint_1{controlPoint_1}, - controlPoint_2{controlPoint_2} -{ -} - -linetypes::ConditionalEdge::ConditionalEdge(const QVector& vertices, const Color color) : - Edge{vertices[0], vertices[1], color}, - controlPoint_1{vertices[2]}, - controlPoint_2{vertices[3]} -{ -} - -QVariant linetypes::ConditionalEdge::getProperty(Property property) const -{ - switch (property) - { - case Property::ControlPoint1: - return controlPoint_1; - case Property::ControlPoint2: - return controlPoint_2; - default: - return Edge::getProperty(property); - } -} - -auto linetypes::ConditionalEdge::setProperty( - Property property, - const QVariant& value) - -> SetPropertyResult -{ - switch (property) - { - case Property::ControlPoint1: - controlPoint_1 = value.value(); - case Property::ControlPoint2: - controlPoint_2 = value.value(); - default: - return Edge::setProperty(property, value); - } -} - -QString linetypes::ConditionalEdge::textRepresentation() const -{ - return Edge::textRepresentation() + utility::format("%1 %2", - vertexToStringParens(controlPoint_1), - vertexToStringParens(controlPoint_2)); -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/conditionaledge.h --- a/src/objecttypes/conditionaledge.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#pragma once -#include "edge.h" - -namespace linetypes -{ - class ConditionalEdge; -} - -class linetypes::ConditionalEdge : public Edge -{ -public: - ConditionalEdge() = default; - ConditionalEdge( - const Vertex& point_1, - const Vertex& point_2, - const Vertex& controlPoint_1, - const Vertex& controlPoint_2, - const Color colorIndex = colors::edge); - ConditionalEdge(const QVector& vertices, const Color color); - QVariant getProperty(Property property) const override; - SetPropertyResult setProperty( - Property property, - const QVariant& value) override; - QString textRepresentation() const override; -private: - Vertex controlPoint_1 = {}; - Vertex controlPoint_2 = {}; -}; diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/edge.cpp --- a/src/objecttypes/edge.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -#include "edge.h" - -linetypes::Edge::Edge( - const Vertex& point_1, - const Vertex& point_2, - const Color color_index) : - ColoredObject{color_index}, - point_1{point_1}, - point_2{point_2} {} - -linetypes::Edge::Edge(const QVector& vertices, const Color color) : - ColoredObject{color}, - point_1{vertices[0]}, - point_2{vertices[1]} -{ -} - -QVariant linetypes::Edge::getProperty(Property property) const -{ - switch (property) - { - case Property::Point1: - return point_1; - case Property::Point2: - return point_2; - default: - return BaseClass::getProperty(property); - } -} - -auto linetypes::Edge::setProperty(Property property, const QVariant& value) - -> SetPropertyResult -{ - switch (property) - { - case Property::Point1: - point_1 = value.value(); - return SetPropertyResult::Success; - case Property::Point2: - point_2 = value.value(); - return SetPropertyResult::Success; - default: - return BaseClass::setProperty(property, value); - } -} - -QString linetypes::Edge::textRepresentation() const -{ - return utility::format("%1 %2", vertexToStringParens(point_1), vertexToStringParens(point_2)); -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/edge.h --- a/src/objecttypes/edge.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#pragma once -#include "objecttypes/modelobject.h" - -namespace linetypes -{ - class Edge; -} - -class linetypes::Edge : public ColoredObject -{ -public: - using BaseClass = ColoredObject; - Edge() = default; - Edge(const Vertex& point_1, const Vertex& point_2, - const Color colorIndex = colors::edge); - Edge(const QVector& vertices, const Color color); - QVariant getProperty(Property property) const override; - SetPropertyResult setProperty( - Property property, - const QVariant& value) override; - QString textRepresentation() const override; -private: - Vertex point_1 = {}; - Vertex point_2 = {}; -}; diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/errorline.cpp --- a/src/objecttypes/errorline.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -#include -#include "errorline.h" - -linetypes::ErrorLine::ErrorLine(QStringView text, QStringView message) : - text{text.toString()}, - message{message.toString()} -{ -} - -QVariant linetypes::ErrorLine::getProperty(Property property) const -{ - switch (property) - { - case Property::Text: - return this->text; - case Property::ErrorMessage: - return this->message; - default: - return Object::getProperty(property); - } -} - -auto linetypes::ErrorLine::setProperty( - Property property, - const QVariant& value) - -> SetPropertyResult -{ - switch (property) - { - case Property::Text: - this->text = value.toString(); - return SetPropertyResult::Success; - case Property::ErrorMessage: - this->message = value.toString(); - return SetPropertyResult::Success; - default: - return Object::setProperty(property, value); - } -} - -QString linetypes::ErrorLine::textRepresentation() const -{ - return this->text; -} - -QBrush linetypes::ErrorLine::textRepresentationForeground() const -{ - return QBrush{Qt::yellow}; -} - -QBrush linetypes::ErrorLine::textRepresentationBackground() const -{ - return QBrush{Qt::red}; -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/errorline.h --- a/src/objecttypes/errorline.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -#pragma once -#include "modelobject.h" - -namespace linetypes -{ - class ErrorLine; -} - -class linetypes::ErrorLine : public Object -{ -public: - ErrorLine(QStringView text = u"", QStringView message = u""); - QVariant getProperty(Property property) const override; - SetPropertyResult setProperty( - Property property, - const QVariant& value) override; - QString textRepresentation() const override; - QBrush textRepresentationForeground() const override; - QBrush textRepresentationBackground() const override; -private: - QString text; - QString message; -}; diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/metacommand.cpp --- a/src/objecttypes/metacommand.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -#include "metacommand.h" - -linetypes::MetaCommand::MetaCommand(QStringView text) : - Object{}, - storedText{text.toString()} {} - -QVariant linetypes::MetaCommand::getProperty(Property property) const -{ - switch (property) - { - case Property::Text: - return storedText; - default: - return Object::getProperty(property); - } -} - -auto linetypes::MetaCommand::setProperty(Property property, const QVariant& value) - -> SetPropertyResult -{ - switch (property) - { - case Property::Text: - storedText = value.toString(); - return SetPropertyResult::Success; - default: - return Object::setProperty(property, value); - } -} - -QString linetypes::MetaCommand::textRepresentation() const -{ - return this->storedText; -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/metacommand.h --- a/src/objecttypes/metacommand.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -#pragma once -#include "modelobject.h" - -namespace linetypes -{ - class MetaCommand; -} -class linetypes::MetaCommand : public Object -{ -public: - MetaCommand() = default; - MetaCommand(QStringView text); - QVariant getProperty(Property property) const override; - SetPropertyResult setProperty( - Property property, - const QVariant& value) override; - QString textRepresentation() const override; -private: - QString storedText = ""; -}; diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/modelobject.cpp --- a/src/objecttypes/modelobject.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -#include -#include -#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; -} - -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 ""; -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/modelobject.h --- a/src/objecttypes/modelobject.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -#pragma once -#include -#include -#include -#include "main.h" -#include "colors.h" -#include "vertex.h" - -namespace linetypes -{ - 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 unsigned int 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; -}; - -namespace linetypes -{ - using Id = std::decay_t; -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/polygon.cpp --- a/src/objecttypes/polygon.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -#include "polygon.h" - -linetypes::Triangle::Triangle( - const Vertex& point_1, - const Vertex& point_2, - const Vertex& point_3, - Color color_index) : - ColoredObject{color_index}, - points{point_1, point_2, point_3} -{ -} - -linetypes::Triangle::Triangle(const QVector& vertices, const Color color) : - ColoredObject{color}, - points{vertices[0], vertices[1], vertices[2]} -{ -} - -QVariant linetypes::Triangle::getProperty(const Property id) const -{ - switch (id) - { - case Property::Point1: - return points[0]; - case Property::Point2: - return points[1]; - case Property::Point3: - return points[2]; - default: - return ColoredObject::getProperty(id); - } -} - -auto linetypes::Triangle::setProperty(Property id, const QVariant& value) - -> SetPropertyResult -{ - switch (id) - { - case Property::Point1: - points[0] = value.value(); - return SetPropertyResult::Success; - case Property::Point2: - points[1] = value.value(); - return SetPropertyResult::Success; - case Property::Point3: - points[2] = value.value(); - return SetPropertyResult::Success; - default: - return ColoredObject::setProperty(id, value); - } -} - -QString linetypes::Triangle::textRepresentation() const -{ - return utility::format("%1 %2 %3", - vertexToStringParens(points[0]), - vertexToStringParens(points[1]), - vertexToStringParens(points[2])); -} - -linetypes::Quadrilateral::Quadrilateral( - const Vertex& point_1, - const Vertex& point_2, - const Vertex& point_3, - const Vertex& point_4, - Color color_index) : - ColoredObject{color_index}, - points{point_1, point_2, point_3, point_4} -{ -} - -linetypes::Quadrilateral::Quadrilateral(const QVector& vertices, const Color color) : - ColoredObject{color}, - points{vertices[0], vertices[1], vertices[2], vertices[3]} -{ -} - -QVariant linetypes::Quadrilateral::getProperty(const Property id) const -{ - switch (id) - { - case Property::Point1: - return points[0]; - case Property::Point2: - return points[1]; - case Property::Point3: - return points[2]; - case Property::Point4: - return points[3]; - default: - return ColoredObject::getProperty(id); - } -} - -auto linetypes::Quadrilateral::setProperty( - const Property id, - const QVariant& value) - -> SetPropertyResult -{ - switch (id) - { - case Property::Point1: - points[0] = value.value(); - return SetPropertyResult::Success; - case Property::Point2: - points[1] = value.value(); - return SetPropertyResult::Success; - case Property::Point3: - points[2] = value.value(); - return SetPropertyResult::Success; - case Property::Point4: - points[3] = value.value(); - return SetPropertyResult::Success; - default: - return ColoredObject::setProperty(id, value); - } -} - -QString linetypes::Quadrilateral::textRepresentation() const -{ - return utility::format("%1 %2 %3 %4", - vertexToStringParens(points[0]), - vertexToStringParens(points[1]), - vertexToStringParens(points[2]), - vertexToStringParens(points[3])); -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/polygon.h --- a/src/objecttypes/polygon.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -#include -#include "modelobject.h" - -namespace linetypes -{ - class Triangle; - class Quadrilateral; -} - -class linetypes::Triangle : public ColoredObject -{ -public: - Triangle() = default; - Triangle( - const Vertex &point_1, - const Vertex &point_2, - const Vertex &point_3, - Color colorIndex = colors::main); - Triangle(const QVector& vertices, const Color color); - QVariant getProperty(Property id) const override; - SetPropertyResult setProperty(Property id, const QVariant& value) override; - QString textRepresentation() const override; -private: - Vertex points[3] = {{}}; -}; - -class linetypes::Quadrilateral : public ColoredObject -{ -public: - Quadrilateral() = default; - Quadrilateral( - const Vertex &point_1, - const Vertex &point_2, - const Vertex &point_3, - const Vertex &point_4, - Color colorIndex = colors::main); - Quadrilateral(const QVector& vertices, const Color color); - QVariant getProperty(Property id) const override; - SetPropertyResult setProperty(Property id, const QVariant& value) override; - QString textRepresentation() const override; -private: - Vertex points[4] = {{}}; -}; diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/subfilereference.cpp --- a/src/objecttypes/subfilereference.cpp Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -#include "subfilereference.h" - -linetypes::SubfileReference::SubfileReference( - const Vertex& position, - const Matrix3x3& transformation, - const QString& referenceName, - const Color color) : - ColoredObject{color}, - position{position}, - transformation{transformation}, - referenceName{referenceName} -{ -} - -QVariant linetypes::SubfileReference::getProperty(Property property) const -{ - switch (property) - { - case Property::Position: - return this->position; - case Property::Transformation: - return QVariant::fromValue(this->transformation); - case Property::ReferenceName: - return this->referenceName; - default: - return ColoredObject::getProperty(property); - } -} - -auto linetypes::SubfileReference::setProperty( - Property property, - const QVariant& value) - -> SetPropertyResult -{ - switch (property) - { - case Property::Position: - this->position = value.value(); - return SetPropertyResult::Success; - case Property::Transformation: - this->transformation = value.value(); - return SetPropertyResult::Success; - case Property::ReferenceName: - this->referenceName = value.toString(); - return SetPropertyResult::Success; - default: - return ColoredObject::setProperty(property, value); - } -} - -QString linetypes::SubfileReference::textRepresentation() const -{ - return referenceName + " " + vertexToStringParens(this->position); -} diff -r 6e838748867b -r 20d2ed3af73d src/objecttypes/subfilereference.h --- a/src/objecttypes/subfilereference.h Sun Nov 03 18:09:47 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#pragma once -#include "modelobject.h" -#include "matrix.h" - -namespace linetypes -{ - class SubfileReference; -} - -class linetypes::SubfileReference : public ColoredObject -{ -public: - SubfileReference() = default; - SubfileReference( - const Vertex& position, - const Matrix3x3& transformation, - const QString &referenceName, - const Color color = colors::main); - QVariant getProperty(Property property) const override; - SetPropertyResult setProperty(Property property, const QVariant& value) override; - QString textRepresentation() const override; -private: - Vertex position; - Matrix3x3 transformation; - QString referenceName; -}; diff -r 6e838748867b -r 20d2ed3af73d src/parser.cpp --- a/src/parser.cpp Sun Nov 03 18:09:47 2019 +0200 +++ b/src/parser.cpp Sun Nov 03 18:13:38 2019 +0200 @@ -18,14 +18,14 @@ #include "model.h" #include "parser.h" -#include "objecttypes/comment.h" -#include "objecttypes/conditionaledge.h" -#include "objecttypes/edge.h" -#include "objecttypes/errorline.h" -#include "objecttypes/metacommand.h" -#include "objecttypes/modelobject.h" -#include "objecttypes/polygon.h" -#include "objecttypes/subfilereference.h" +#include "linetypes/comment.h" +#include "linetypes/conditionaledge.h" +#include "linetypes/edge.h" +#include "linetypes/errorline.h" +#include "linetypes/metacommand.h" +#include "linetypes/object.h" +#include "linetypes/polygon.h" +#include "linetypes/subfilereference.h" struct BodyParseError { diff -r 6e838748867b -r 20d2ed3af73d src/parser.h --- a/src/parser.h Sun Nov 03 18:09:47 2019 +0200 +++ b/src/parser.h Sun Nov 03 18:13:38 2019 +0200 @@ -18,7 +18,7 @@ #pragma once #include "main.h" -#include "objecttypes/modelobject.h" +#include "linetypes/object.h" #include "model.h" #include "modeleditcontext.h" #include "header.h"