# HG changeset patch # User Teemu Piippo # Date 1572797828 -7200 # Node ID 9e18ec63eec3d8910a9b30107ee27a2011d7c1c3 # Parent 20d2ed3af73db783e24ea180f6be4e0ca6867cf3 split quadrilateral and triangle into their own source files diff -r 20d2ed3af73d -r 9e18ec63eec3 CMakeLists.txt --- a/CMakeLists.txt Sun Nov 03 18:13:38 2019 +0200 +++ b/CMakeLists.txt Sun Nov 03 18:17:08 2019 +0200 @@ -32,8 +32,9 @@ src/linetypes/errorline.cpp src/linetypes/metacommand.cpp src/linetypes/object.cpp - src/linetypes/polygon.cpp + src/linetypes/quadrilateral.cpp src/linetypes/subfilereference.cpp + src/linetypes/triangle.cpp src/settingseditor/librarieseditor.cpp src/settingseditor/settingseditor.cpp ) @@ -58,8 +59,9 @@ src/linetypes/errorline.h src/linetypes/metacommand.h src/linetypes/object.h - src/linetypes/polygon.h + src/linetypes/quadrilateral.h src/linetypes/subfilereference.h + src/linetypes/triangle.h src/settingseditor/librarieseditor.h src/settingseditor/settingseditor.h ) diff -r 20d2ed3af73d -r 9e18ec63eec3 src/linetypes/polygon.cpp --- a/src/linetypes/polygon.cpp Sun Nov 03 18:13:38 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 20d2ed3af73d -r 9e18ec63eec3 src/linetypes/polygon.h --- a/src/linetypes/polygon.h Sun Nov 03 18:13:38 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -#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 20d2ed3af73d -r 9e18ec63eec3 src/linetypes/quadrilateral.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/quadrilateral.cpp Sun Nov 03 18:17:08 2019 +0200 @@ -0,0 +1,68 @@ +#include "quadrilateral.h" + +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 20d2ed3af73d -r 9e18ec63eec3 src/linetypes/quadrilateral.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/quadrilateral.h Sun Nov 03 18:17:08 2019 +0200 @@ -0,0 +1,25 @@ +#pragma once +#include "object.h" + +namespace linetypes +{ + class Quadrilateral; +} + +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 20d2ed3af73d -r 9e18ec63eec3 src/linetypes/triangle.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/triangle.cpp Sun Nov 03 18:17:08 2019 +0200 @@ -0,0 +1,59 @@ +#include "triangle.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])); +} diff -r 20d2ed3af73d -r 9e18ec63eec3 src/linetypes/triangle.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/linetypes/triangle.h Sun Nov 03 18:17:08 2019 +0200 @@ -0,0 +1,24 @@ +#include "object.h" + +namespace linetypes +{ + class Triangle; +} + +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] = {{}}; +}; + diff -r 20d2ed3af73d -r 9e18ec63eec3 src/parser.cpp --- a/src/parser.cpp Sun Nov 03 18:13:38 2019 +0200 +++ b/src/parser.cpp Sun Nov 03 18:17:08 2019 +0200 @@ -24,8 +24,9 @@ #include "linetypes/errorline.h" #include "linetypes/metacommand.h" #include "linetypes/object.h" -#include "linetypes/polygon.h" +#include "linetypes/quadrilateral.h" #include "linetypes/subfilereference.h" +#include "linetypes/triangle.h" struct BodyParseError {