src/ui/objecteditor.cpp

Sun, 26 Jun 2022 20:54:09 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 26 Jun 2022 20:54:09 +0300
changeset 262
dc33f8a707c4
parent 258
fe094d0687ad
child 263
59b6027b9843
permissions
-rw-r--r--

Add action to make a model unofficial (modifies the !LDRAW_ORG line)

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

mercurial