Sun, 03 Nov 2019 18:13:38 +0200
renamings
--- 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 )
--- 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 <QFileInfo> #include "documentmanager.h" #include "modeleditcontext.h" -#include "objecttypes/comment.h" +#include "linetypes/comment.h" #include "parser.h" /**
--- /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 <QFont> +#include "comment.h" + +QFont linetypes::Comment::textRepresentationFont() const +{ + QFont font; + font.setItalic(true); + return font; +}
--- /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; +};
--- /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<Vertex>& 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<Vertex>(); + case Property::ControlPoint2: + controlPoint_2 = value.value<Vertex>(); + default: + return Edge::setProperty(property, value); + } +} + +QString linetypes::ConditionalEdge::textRepresentation() const +{ + return Edge::textRepresentation() + utility::format("%1 %2", + vertexToStringParens(controlPoint_1), + vertexToStringParens(controlPoint_2)); +}
--- /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<Vertex>& 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 = {}; +};
--- /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<Vertex>& 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<Vertex>(); + return SetPropertyResult::Success; + case Property::Point2: + point_2 = value.value<Vertex>(); + 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)); +}
--- /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<Vertex>& 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 = {}; +};
--- /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 <QBrush> +#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}; +}
--- /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; +};
--- /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; +}
--- /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 = ""; +};
--- /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 ""; +}
--- /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 <QPointF> +#include <QString> +#include <QStringView> +#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<decltype(Object::id)>; +}
--- /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<Vertex>& 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<Vertex>(); + return SetPropertyResult::Success; + case Property::Point2: + points[1] = value.value<Vertex>(); + return SetPropertyResult::Success; + case Property::Point3: + points[2] = value.value<Vertex>(); + 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<Vertex>& 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<Vertex>(); + return SetPropertyResult::Success; + case Property::Point2: + points[1] = value.value<Vertex>(); + return SetPropertyResult::Success; + case Property::Point3: + points[2] = value.value<Vertex>(); + return SetPropertyResult::Success; + case Property::Point4: + points[3] = value.value<Vertex>(); + 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])); +}
--- /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 <array> +#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<Vertex>& 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<Vertex>& 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] = {{}}; +};
--- /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<Vertex>(); + return SetPropertyResult::Success; + case Property::Transformation: + this->transformation = value.value<Matrix3x3>(); + 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); +}
--- /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; +};
--- 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 <memory> #include "main.h" #include "header.h" -#include "objecttypes/modelobject.h" +#include "linetypes/object.h" enum class HeaderProperty {
--- 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 {
--- 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 <QFont> -#include "comment.h" - -QFont linetypes::Comment::textRepresentationFont() const -{ - QFont font; - font.setItalic(true); - return font; -}
--- 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; -};
--- 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<Vertex>& 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<Vertex>(); - case Property::ControlPoint2: - controlPoint_2 = value.value<Vertex>(); - default: - return Edge::setProperty(property, value); - } -} - -QString linetypes::ConditionalEdge::textRepresentation() const -{ - return Edge::textRepresentation() + utility::format("%1 %2", - vertexToStringParens(controlPoint_1), - vertexToStringParens(controlPoint_2)); -}
--- 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<Vertex>& 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 = {}; -};
--- 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<Vertex>& 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<Vertex>(); - return SetPropertyResult::Success; - case Property::Point2: - point_2 = value.value<Vertex>(); - 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)); -}
--- 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<Vertex>& 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 = {}; -};
--- 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 <QBrush> -#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}; -}
--- 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; -};
--- 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; -}
--- 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 = ""; -};
--- 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 <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; -} - -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 ""; -}
--- 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 <QPointF> -#include <QString> -#include <QStringView> -#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<decltype(Object::id)>; -}
--- 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<Vertex>& 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<Vertex>(); - return SetPropertyResult::Success; - case Property::Point2: - points[1] = value.value<Vertex>(); - return SetPropertyResult::Success; - case Property::Point3: - points[2] = value.value<Vertex>(); - 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<Vertex>& 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<Vertex>(); - return SetPropertyResult::Success; - case Property::Point2: - points[1] = value.value<Vertex>(); - return SetPropertyResult::Success; - case Property::Point3: - points[2] = value.value<Vertex>(); - return SetPropertyResult::Success; - case Property::Point4: - points[3] = value.value<Vertex>(); - 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])); -}
--- 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 <array> -#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<Vertex>& 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<Vertex>& 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] = {{}}; -};
--- 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<Vertex>(); - return SetPropertyResult::Success; - case Property::Transformation: - this->transformation = value.value<Matrix3x3>(); - 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); -}
--- 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; -};
--- 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 {