src/ui/objecteditor.cpp

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

mercurial