src/ui/objecteditor.cpp

Sun, 26 Jun 2022 21:00:06 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 26 Jun 2022 21:00:06 +0300
changeset 263
59b6027b9843
parent 258
fe094d0687ad
child 264
76a025db4948
permissions
-rw-r--r--

Move render layer files to new src/layers/ directory

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>
252
da4876bfd822 Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 249
diff changeset
4 #include <widgets/vec3editor.h>
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 #include "objecteditor.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"
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
8 #include "ui_objecteditor.h"
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
10 using PropertyPointer = std::variant<
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
11 glm::vec3*,
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
12 glm::mat4*,
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
13 QString*,
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
14 ldraw::Color*,
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
15 CircularFraction*>;
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
17 enum class 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,
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
30 Fraction,
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
31 };
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
32
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
33 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
34
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
35 static QString propertyName(PropertyKey key)
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 {
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
37 switch (key) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
38 case PropertyKey::Point1:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
39 return ObjectEditor::tr("Vertex 1");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
40 case PropertyKey::Point2:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
41 return ObjectEditor::tr("Vertex 2");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
42 case PropertyKey::Point3:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
43 return ObjectEditor::tr("Vertex 3");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
44 case PropertyKey::Point4:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
45 return ObjectEditor::tr("Vertex 4");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
46 case PropertyKey::Control1:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
47 return ObjectEditor::tr("Control point 1");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
48 case PropertyKey::Control2:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
49 return ObjectEditor::tr("Control point 2");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
50 case PropertyKey::Color:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
51 return ObjectEditor::tr("Colour");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
52 case PropertyKey::Transformation:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
53 return ObjectEditor::tr("Transformation");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
54 case PropertyKey::Name:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
55 return ObjectEditor::tr("Name");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
56 case PropertyKey::Text:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
57 return ObjectEditor::tr("Text");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
58 case PropertyKey::Code:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
59 return ObjectEditor::tr("Code");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
60 case PropertyKey::Fraction:
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
61 return ObjectEditor::tr("Fraction");
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
62 }
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
63 return "";
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
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
66 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
67 {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
68 std::map<PropertyKey, PropertyPointer> result;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
69 std::visit<void>(overloaded{
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
70 [&](Colored<LineSegment>& edge) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
71 result[PropertyKey::Point1] = &edge.p1;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
72 result[PropertyKey::Point2] = &edge.p2;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
73 result[PropertyKey::Color] = &edge.color;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
74 },
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
75 [&](Colored<Triangle>& tri) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
76 result[PropertyKey::Point1] = &tri.p1;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
77 result[PropertyKey::Point2] = &tri.p2;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
78 result[PropertyKey::Point3] = &tri.p3;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
79 result[PropertyKey::Color] = &tri.color;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
80 },
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
81 [&](Colored<Quadrilateral>& quad) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
82 result[PropertyKey::Point1] = &quad.p1;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
83 result[PropertyKey::Point2] = &quad.p2;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
84 result[PropertyKey::Point3] = &quad.p3;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
85 result[PropertyKey::Point4] = &quad.p4;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
86 result[PropertyKey::Color] = &quad.color;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
87 },
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
88 [&](Colored<ConditionalEdge>& cedge) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
89 result[PropertyKey::Point1] = &cedge.p1;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
90 result[PropertyKey::Point2] = &cedge.p2;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
91 result[PropertyKey::Control1] = &cedge.c1;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
92 result[PropertyKey::Control2] = &cedge.c2;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
93 result[PropertyKey::Color] = &cedge.color;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
94 },
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
95 [&](Colored<SubfileReference>& ref) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
96 result[PropertyKey::Transformation] = &ref.transformation;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
97 result[PropertyKey::Name] = &ref.name;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
98 result[PropertyKey::Color] = &ref.color;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
99 },
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
100 [&](Colored<CircularPrimitive>& circ) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
101 result[PropertyKey::Transformation] = &circ.transformation;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
102 result[PropertyKey::Fraction] = &circ.fraction;
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
103 result[PropertyKey::Color] = &circ.color;
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
104 },
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
105 [&](Empty) {},
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
106 [&](Comment& comment) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
107 result[PropertyKey::Text] = &comment.text;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
108 },
249
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
109 [&](ParseError& parseError) {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
110 result[PropertyKey::Code] = &parseError.code;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
111 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
112 }, element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
113 return result;
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
114 }
249
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
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
117 ObjectEditor::ObjectEditor(QWidget* parent) :
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
118 QWidget{parent}
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
119 {
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
120 this->ui.setupUi(this);
37d3c819cafa Done some work on object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
121 }

mercurial