src/ui/objecteditor.cpp

Wed, 25 May 2022 17:25:24 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 25 May 2022 17:25:24 +0300
changeset 192
e6faeffed1d1
parent 183
97b591813c8b
child 200
ca23936b455b
permissions
-rw-r--r--

remove dead code

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 "modeleditor.h"
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"
181
79de20dc6a1e fix build
Teemu Piippo <teemu@hecknology.net>
parents: 180
diff changeset
9 #include "widgets/vec3editor.h"
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
10 #include "ui_objecteditor.h"
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
12 ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) :
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
13 QWidget{document},
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
14 ui{*new Ui_ObjectEditor},
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
15 document{document}
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 {
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
17 this->ui.setupUi(this);
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
18 this->setObjectId(id);
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
19 QFormLayout* formLayout = new QFormLayout{ui.properties};
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
20 this->ui.properties->setLayout(formLayout);
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
21 for (const ldraw::Property property : ldraw::ALL_PROPERTIES)
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
22 {
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
23 QWidget* editorWidget = this->makeEditorWidgetForProperty(property);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
24 if (editorWidget != nullptr)
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
25 {
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
26 editorWidget->setProperty("_property_id", static_cast<int>(property));
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
27 QLabel* propertyLabel = new QLabel{ldraw::traits(property).name.data()};
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
28 formLayout->addRow(propertyLabel, editorWidget);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
29 this->propertyWidgets[property] = {propertyLabel, editorWidget};
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
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 }
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
32 this->setObjectId(ldraw::NULL_ID);
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
33 }
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
34
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
35 ObjectEditor::~ObjectEditor()
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
36 {
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
37 delete &this->ui;
177
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
38 }
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
39
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
40 QString titleCase(const QString& string)
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
41 {
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
42 return string.left(1).toUpper() + string.mid(1);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
45 void setValueToWidget(QWidget* widget, const QVariant& value)
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
46 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
47 ColorIndexInput* colorIndexInput = qobject_cast<ColorIndexInput*>(widget);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
48 if (colorIndexInput != nullptr)
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
49 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
50 colorIndexInput->setSelectedColor(value.value<ldraw::Color>());
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
51 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
52 else
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
53 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
54 Vec3Editor* vec3Editor = qobject_cast<Vec3Editor*>(widget);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
55 if (vec3Editor != nullptr)
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
56 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
57 vec3Editor->setValue(value.value<glm::vec3>());
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
58 }
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
59 else
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
60 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
61 QCheckBox* checkBox = qobject_cast<QCheckBox*>(widget);
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
62 if (checkBox != nullptr)
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
63 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
64 checkBox->setChecked(value.toBool());
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
65 }
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
66 else
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
67 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
68 QLineEdit* lineEdit = qobject_cast<QLineEdit*>(widget);
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
69 if (lineEdit != nullptr)
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
70 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
71 lineEdit->setText(value.toString());
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
72 }
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
73 }
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
74 }
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
75 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
76 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
77
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 void ObjectEditor::setObjectId(const ldraw::id_t id)
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 this->objectId = id;
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
81 const ldraw::Object* object = this->document->getModel().get(id);
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
82 this->ui.properties->setEnabled(object != nullptr);
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
83 if (object != nullptr)
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 {
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
85 this->ui.typeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>");
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
86 this->ui.typeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24));
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
87 for (const ldraw::Property property : ldraw::ALL_PROPERTIES)
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 {
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
89 const QVariant value = object->getProperty(property);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
90 const auto it = this->propertyWidgets.find(property);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
91 if (it != this->propertyWidgets.end())
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
92 {
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
93 it->first->setEnabled(not value.isNull());
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
94 it->second->setEnabled(not value.isNull());
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
95 if (not value.isNull())
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
96 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
97 setValueToWidget(it->second, value);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
98 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
99 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 else
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 {
182
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
104 this->ui.typeNameLabel->setText(tr("No object selected"));
27fb1c3c9fbb add ui file to object editor
Teemu Piippo <teemu@hecknology.net>
parents: 181
diff changeset
105 this->ui.typeIconLabel->clear();
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107 }
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
108
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
109 void ObjectEditor::handleColorChange(ldraw::Color value)
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
110 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
111 this->handlePropertyChange(this->sender(), QVariant::fromValue(value));
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
112 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
113
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
114 void ObjectEditor::handleVec3Change(const glm::vec3 &value)
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
115 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
116 this->handlePropertyChange(this->sender(), QVariant::fromValue(value));
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
117 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
118
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
119 void ObjectEditor::handleBoolChange(bool value)
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
120 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
121 this->handlePropertyChange(this->sender(), QVariant::fromValue(value));
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
122 }
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
123
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
124 void ObjectEditor::handleStringChange(const QString &value)
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
125 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
126 this->handlePropertyChange(this->sender(), QVariant::fromValue(value));
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
127 }
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
128
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
129 QWidget* ObjectEditor::makeEditorWidgetForProperty(ldraw::Property property)
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
130 {
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
131 QWidget* const parent = qobject_cast<QWidget*>(this->parent());
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
132 if (ldraw::traits(property).type == qMetaTypeId<ldraw::Color>())
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
133 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
134 ColorIndexInput* colorWidget = new ColorIndexInput{this->document, {0}, parent};
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
135 connect(colorWidget, &ColorIndexInput::colorChanged, this, &ObjectEditor::handleColorChange);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
136 return colorWidget;
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
137 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
138 else if (ldraw::traits(property).type == qMetaTypeId<glm::vec3>())
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
139 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
140 Vec3Editor* editor = new Vec3Editor{{}, parent};
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
141 connect(editor, &Vec3Editor::valueChanged, this, &ObjectEditor::handleVec3Change);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
142 return editor;
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
143 }
183
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
144 else if (ldraw::traits(property).type == qMetaTypeId<bool>())
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
145 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
146 QCheckBox* editor = new QCheckBox{{}, parent};
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
147 connect(editor, &QCheckBox::clicked, this, &ObjectEditor::handleBoolChange);
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
148 return editor;
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
149 }
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
150 else if (ldraw::traits(property).type == qMetaTypeId<QString>())
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
151 {
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
152 QLineEdit* editor = new QLineEdit{{}, parent};
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
153 connect(editor, &QLineEdit::textChanged, this, &ObjectEditor::handleStringChange);
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
154 return editor;
97b591813c8b - Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents: 182
diff changeset
155 }
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
156 else
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
157 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
158 return nullptr;
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
159 }
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 177
diff changeset
160 }
180
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
161
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
162 void ObjectEditor::handlePropertyChange(QObject *caller, const QVariant &value)
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
163 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
164 QVariant propertyVariant = caller->property("_property_id");
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
165 if (not propertyVariant.isNull())
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
166 {
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
167 ldraw::Property const property = static_cast<ldraw::Property>(propertyVariant.toInt());
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
168 this->document->editModel()->setObjectProperty(this->objectId, property, value);
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
169 }
5b7a8f2270ff Handle properties in a generic manner in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
170 }

mercurial