src/ui/objecteditor.cpp

Sat, 11 Jun 2022 15:20:24 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 11 Jun 2022 15:20:24 +0300
changeset 213
ee5758ddb6d2
parent 200
ca23936b455b
child 232
8efa3a33172e
permissions
-rw-r--r--

Rewrite prune to use graphs rather than O(n²) searches

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
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
3 #include <QFormLayout>
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include "objecteditor.h"
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
5 #include "document.h"
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
6 #include "widgets/colorbutton.h"
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
7 #include "widgets/colorindexinput.h"
181
79de20dc6a1e fix build
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
8 #include "widgets/vec3editor.h"
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
9 #include "ui_objecteditor.h"
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
11 using PropertyValue = std::variant<
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
12 const glm::vec3*,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
13 const glm::mat4*,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
14 const QString*,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
15 ldraw::Color>;
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
17 enum PropertyKey
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
18 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
19 Point1,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
20 Point2,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
21 Point3,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
22 Point4,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
23 Control1,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
24 Control2,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
25 Color,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
26 Transformation,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
27 Name,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
28 Text,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
29 Code,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
30 };
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
31
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
32 std::map<PropertyKey, PropertyValue> getProperties(const ModelElement& element)
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
34 std::map<PropertyKey, PropertyValue> result;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
35 std::visit<void>(overloaded{
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
36 [&](const Colored<LineSegment>& edge) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
37 result[Point1] = &edge.p1;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
38 result[Point2] = &edge.p2;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
39 result[Color] = edge.color;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
40 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
41 [&](const Colored<Triangle>& tri) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
42 result[Point1] = &tri.p1;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
43 result[Point2] = &tri.p2;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
44 result[Point3] = &tri.p3;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
45 result[Color] = tri.color;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
46 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
47 [&](const Colored<Quadrilateral>& quad) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
48 result[Point1] = &quad.p1;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
49 result[Point2] = &quad.p2;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
50 result[Point3] = &quad.p3;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
51 result[Point4] = &quad.p4;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
52 result[Color] = quad.color;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
53 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
54 [&](const Colored<ConditionalEdge>& cedge) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
55 result[Point1] = &cedge.p1;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
56 result[Point2] = &cedge.p2;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
57 result[Control1] = &cedge.c1;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
58 result[Control2] = &cedge.c2;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
59 result[Color] = cedge.color;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
60 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
61 [&](const Colored<SubfileReference>& ref) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
62 result[Transformation] = &ref.transformation;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
63 result[Name] = &ref.name;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
64 result[Color] = ref.color;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
65 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
66 [&](Empty) {},
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
67 [&](const Comment& comment) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
68 result[Text] = &comment.text;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
69 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
70 [&](const ParseError& parseError) {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
71 result[Code] = &parseError.code;
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
72 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
73 }, element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
74 return result;
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
75 }

mercurial