Sun, 03 Jul 2022 14:35:06 +0300
Cleanup polygonize a bit
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
1 | #include <QCheckBox> |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
2 | #include <QLineEdit> |
178 | 3 | #include <QFormLayout> |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
4 | #include "src/ui/objecteditor.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
5 | #include "src/widgets/colorindexinput.h" |
178 | 6 | #include "widgets/colorbutton.h" |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
7 | #include "widgets/vec3editor.h" |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
9 | using PropertyPointer = std::variant< |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
10 | glm::vec3*, |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
11 | glm::mat4*, |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
12 | QString*, |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
13 | ldraw::Color*, |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
14 | CircularFraction*>; |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
16 | enum class PropertyKey |
180
5b7a8f2270ff
Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
17 | { |
200 | 18 | Point1, |
19 | Point2, | |
20 | Point3, | |
21 | Point4, | |
22 | Control1, | |
23 | Control2, | |
24 | Color, | |
25 | Transformation, | |
26 | Name, | |
27 | Text, | |
28 | Code, | |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
200
diff
changeset
|
29 | Fraction, |
200 | 30 | }; |
180
5b7a8f2270ff
Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
31 | |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
32 | constexpr std::size_t NUM_PROPERTIES = static_cast<int>(PropertyKey::Fraction) + 1; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
33 | |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
34 | static QString propertyName(PropertyKey key) |
81
62373840e33a
object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | { |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
36 | switch (key) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
37 | case PropertyKey::Point1: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
38 | return ObjectEditor::tr("Vertex 1"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
39 | case PropertyKey::Point2: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
40 | return ObjectEditor::tr("Vertex 2"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
41 | case PropertyKey::Point3: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
42 | return ObjectEditor::tr("Vertex 3"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
43 | case PropertyKey::Point4: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
44 | return ObjectEditor::tr("Vertex 4"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
45 | case PropertyKey::Control1: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
46 | return ObjectEditor::tr("Control point 1"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
47 | case PropertyKey::Control2: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
48 | return ObjectEditor::tr("Control point 2"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
49 | case PropertyKey::Color: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
50 | return ObjectEditor::tr("Colour"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
51 | case PropertyKey::Transformation: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
52 | return ObjectEditor::tr("Transformation"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
53 | case PropertyKey::Name: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
54 | return ObjectEditor::tr("Name"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
55 | case PropertyKey::Text: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
56 | return ObjectEditor::tr("Text"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
57 | case PropertyKey::Code: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
58 | return ObjectEditor::tr("Code"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
59 | case PropertyKey::Fraction: |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
60 | return ObjectEditor::tr("Fraction"); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
61 | } |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
62 | return ""; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
63 | } |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
64 | |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
65 | static std::map<PropertyKey, PropertyPointer> collectProperties(ModelElement& element) |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
66 | { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
67 | std::map<PropertyKey, PropertyPointer> result; |
200 | 68 | std::visit<void>(overloaded{ |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
69 | [&](Colored<LineSegment>& edge) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
70 | result[PropertyKey::Point1] = &edge.p1; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
71 | result[PropertyKey::Point2] = &edge.p2; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
72 | result[PropertyKey::Color] = &edge.color; |
200 | 73 | }, |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
74 | [&](Colored<Triangle>& tri) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
75 | result[PropertyKey::Point1] = &tri.p1; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
76 | result[PropertyKey::Point2] = &tri.p2; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
77 | result[PropertyKey::Point3] = &tri.p3; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
78 | result[PropertyKey::Color] = &tri.color; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
79 | }, |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
80 | [&](Colored<Quadrilateral>& quad) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
81 | result[PropertyKey::Point1] = &quad.p1; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
82 | result[PropertyKey::Point2] = &quad.p2; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
83 | result[PropertyKey::Point3] = &quad.p3; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
84 | result[PropertyKey::Point4] = &quad.p4; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
85 | result[PropertyKey::Color] = &quad.color; |
200 | 86 | }, |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
87 | [&](Colored<ConditionalEdge>& cedge) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
88 | result[PropertyKey::Point1] = &cedge.p1; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
89 | result[PropertyKey::Point2] = &cedge.p2; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
90 | result[PropertyKey::Control1] = &cedge.c1; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
91 | result[PropertyKey::Control2] = &cedge.c2; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
92 | result[PropertyKey::Color] = &cedge.color; |
200 | 93 | }, |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
94 | [&](Colored<SubfileReference>& ref) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
95 | result[PropertyKey::Transformation] = &ref.transformation; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
96 | result[PropertyKey::Name] = &ref.name; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
97 | result[PropertyKey::Color] = &ref.color; |
200 | 98 | }, |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
99 | [&](Colored<CircularPrimitive>& circ) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
100 | result[PropertyKey::Transformation] = &circ.transformation; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
101 | result[PropertyKey::Fraction] = &circ.fraction; |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
102 | result[PropertyKey::Color] = &circ.color; |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
200
diff
changeset
|
103 | }, |
200 | 104 | [&](Empty) {}, |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
105 | [&](Comment& comment) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
106 | result[PropertyKey::Text] = &comment.text; |
200 | 107 | }, |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
108 | [&](ParseError& parseError) { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
109 | result[PropertyKey::Code] = &parseError.code; |
200 | 110 | }, |
111 | }, element); | |
112 | return result; | |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
113 | } |
249
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
114 | |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
115 | |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
116 | ObjectEditor::ObjectEditor(QWidget* parent) : |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
117 | QWidget{parent} |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
118 | { |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
119 | this->ui.setupUi(this); |
37d3c819cafa
Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
120 | } |