src/ui/objecteditor.cpp

changeset 330
edb6c09cdd3c
parent 329
6d75fa09cc0c
child 331
638a7458ef5e
equal deleted inserted replaced
329:6d75fa09cc0c 330:edb6c09cdd3c
1 #include <QCheckBox>
2 #include <QLineEdit>
3 #include <QFormLayout>
4 #include "src/ui/objecteditor.h"
5 #include "src/widgets/colorindexinput.h"
6 #include "widgets/colorbutton.h"
7 #include "widgets/vec3editor.h"
8
9 using PropertyPointer = std::variant<
10 glm::vec3*,
11 glm::mat4*,
12 QString*,
13 ldraw::Color*,
14 CircularFraction*>;
15
16 enum class PropertyKey
17 {
18 Point1,
19 Point2,
20 Point3,
21 Point4,
22 Control1,
23 Control2,
24 Color,
25 Transformation,
26 Name,
27 Text,
28 Code,
29 Fraction,
30 };
31
32 constexpr std::size_t NUM_PROPERTIES = static_cast<int>(PropertyKey::Fraction) + 1;
33
34 static QString propertyName(PropertyKey key)
35 {
36 switch (key) {
37 case PropertyKey::Point1:
38 return ObjectEditor::tr("Vertex 1");
39 case PropertyKey::Point2:
40 return ObjectEditor::tr("Vertex 2");
41 case PropertyKey::Point3:
42 return ObjectEditor::tr("Vertex 3");
43 case PropertyKey::Point4:
44 return ObjectEditor::tr("Vertex 4");
45 case PropertyKey::Control1:
46 return ObjectEditor::tr("Control point 1");
47 case PropertyKey::Control2:
48 return ObjectEditor::tr("Control point 2");
49 case PropertyKey::Color:
50 return ObjectEditor::tr("Colour");
51 case PropertyKey::Transformation:
52 return ObjectEditor::tr("Transformation");
53 case PropertyKey::Name:
54 return ObjectEditor::tr("Name");
55 case PropertyKey::Text:
56 return ObjectEditor::tr("Text");
57 case PropertyKey::Code:
58 return ObjectEditor::tr("Code");
59 case PropertyKey::Fraction:
60 return ObjectEditor::tr("Fraction");
61 }
62 return "";
63 }
64
65 static std::map<PropertyKey, PropertyPointer> collectProperties(ModelElement& element)
66 {
67 std::map<PropertyKey, PropertyPointer> result;
68 std::visit<void>(overloaded{
69 [&](Colored<LineSegment>& edge) {
70 result[PropertyKey::Point1] = &edge.p1;
71 result[PropertyKey::Point2] = &edge.p2;
72 result[PropertyKey::Color] = &edge.color;
73 },
74 [&](Colored<Triangle>& tri) {
75 result[PropertyKey::Point1] = &tri.p1;
76 result[PropertyKey::Point2] = &tri.p2;
77 result[PropertyKey::Point3] = &tri.p3;
78 result[PropertyKey::Color] = &tri.color;
79 },
80 [&](Colored<Quadrilateral>& quad) {
81 result[PropertyKey::Point1] = &quad.p1;
82 result[PropertyKey::Point2] = &quad.p2;
83 result[PropertyKey::Point3] = &quad.p3;
84 result[PropertyKey::Point4] = &quad.p4;
85 result[PropertyKey::Color] = &quad.color;
86 },
87 [&](Colored<ConditionalEdge>& cedge) {
88 result[PropertyKey::Point1] = &cedge.p1;
89 result[PropertyKey::Point2] = &cedge.p2;
90 result[PropertyKey::Control1] = &cedge.c1;
91 result[PropertyKey::Control2] = &cedge.c2;
92 result[PropertyKey::Color] = &cedge.color;
93 },
94 [&](Colored<SubfileReference>& ref) {
95 result[PropertyKey::Transformation] = &ref.transformation;
96 result[PropertyKey::Name] = &ref.name;
97 result[PropertyKey::Color] = &ref.color;
98 },
99 [&](Colored<CircularPrimitive>& circ) {
100 result[PropertyKey::Transformation] = &circ.transformation;
101 result[PropertyKey::Fraction] = &circ.fraction;
102 result[PropertyKey::Color] = &circ.color;
103 },
104 [&](Empty) {},
105 [&](Comment& comment) {
106 result[PropertyKey::Text] = &comment.text;
107 },
108 [&](ParseError& parseError) {
109 result[PropertyKey::Code] = &parseError.code;
110 },
111 }, element);
112 return result;
113 }
114
115
116 ObjectEditor::ObjectEditor(QWidget* parent) :
117 QWidget{parent}
118 {
119 this->ui.setupUi(this);
120 }

mercurial