Wed, 25 Mar 2020 16:07:20 +0200
added PolygonObject and refactored away a lot of boilerplate
| 6 | 1 | #include <QBrush> |
| 2 | #include <QFont> | |
| 14 | 3 | #include "object.h" |
| 3 | 4 | |
| 46 | 5 | static std::int32_t getIdForNewObject() |
| 6 | 6 | { |
| 46 | 7 | static std::int32_t id = 0; |
| 6 | 8 | id += 1; |
| 9 | return id; | |
| 10 | } | |
| 3 | 11 | |
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
12 | ldraw::Object::Object() : |
| 6 | 13 | id {getIdForNewObject()} |
| 3 | 14 | { |
| 15 | } | |
| 16 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
17 | ldraw::Object::~Object() |
| 3 | 18 | { |
| 19 | } | |
| 20 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
21 | bool ldraw::Object::hasColor() const |
| 3 | 22 | { |
| 23 | return false; | |
| 24 | } | |
| 25 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
26 | QVariant ldraw::Object::getProperty(Property id) const |
| 3 | 27 | { |
| 28 | Q_UNUSED(id); | |
| 29 | return {}; | |
| 30 | } | |
| 31 | ||
|
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
32 | void ldraw::Object::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) |
| 3 | 33 | { |
|
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
34 | Q_UNUSED(result) |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
35 | Q_UNUSED(pair) |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
36 | } |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
37 | |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
38 | /** |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
39 | * @brief public interface to setProperty |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
40 | */ |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
41 | ldraw::Object::SetPropertyResult ldraw::Object::setProperty(const PropertyKeyValue& pair) |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
42 | { |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
43 | SetPropertyResult result; |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
44 | this->setProperty(&result, pair); |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
45 | return result; |
| 3 | 46 | } |
| 47 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
48 | QBrush ldraw::Object::textRepresentationForeground() const |
| 6 | 49 | { |
| 50 | return {}; | |
| 51 | } | |
| 52 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
53 | QBrush ldraw::Object::textRepresentationBackground() const |
| 6 | 54 | { |
| 55 | return {}; | |
| 56 | } | |
| 57 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
58 | QFont ldraw::Object::textRepresentationFont() const |
| 6 | 59 | { |
| 60 | return {}; | |
| 61 | } | |
| 62 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
63 | void ldraw::Object::getPolygons(std::vector<gl::Polygon>& polygons, GetPolygonsContext* context) const |
| 21 | 64 | { |
| 65 | Q_UNUSED(polygons) | |
| 66 | Q_UNUSED(context) | |
| 67 | } | |
| 68 | ||
|
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
46
diff
changeset
|
69 | const glm::vec3& ldraw::Object::getPoint(int index) const |
|
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
46
diff
changeset
|
70 | { |
|
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
71 | Q_UNUSED(index); |
|
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
46
diff
changeset
|
72 | throw BadPointIndex{}; |
|
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
46
diff
changeset
|
73 | } |
|
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
46
diff
changeset
|
74 | |
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
75 | ldraw::ColoredObject::ColoredObject(const Color color_index) : |
| 13 | 76 | colorIndex{color_index} |
| 3 | 77 | { |
| 78 | } | |
| 79 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
80 | bool ldraw::ColoredObject::hasColor() const |
| 3 | 81 | { |
| 82 | return true; | |
| 83 | } | |
| 84 | ||
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
85 | QVariant ldraw::ColoredObject::getProperty(Property id) const |
| 3 | 86 | { |
| 87 | switch (id) | |
| 88 | { | |
| 89 | case Property::Color: | |
| 13 | 90 | return colorIndex.index; |
| 3 | 91 | default: |
| 13 | 92 | return Object::getProperty(id); |
| 3 | 93 | } |
| 94 | } | |
| 95 | ||
|
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
96 | void ldraw::ColoredObject::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) |
| 3 | 97 | { |
|
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
98 | LDRAW_OBJECT_HANDLE_SET_PROPERTY(Color, {colorIndex.index = value;}); |
|
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
81
diff
changeset
|
99 | Object::setProperty(result, pair); |
| 3 | 100 | } |
|
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
101 | |
|
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
102 | QString ldraw::Empty::textRepresentation() const |
|
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
103 | { |
|
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
104 | return ""; |
|
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
105 | } |