src/ui/objecteditor.cpp

changeset 183
97b591813c8b
parent 182
27fb1c3c9fbb
child 200
ca23936b455b
--- a/src/ui/objecteditor.cpp	Sun Mar 13 20:26:28 2022 +0200
+++ b/src/ui/objecteditor.cpp	Tue Mar 15 18:52:48 2022 +0200
@@ -1,9 +1,6 @@
-#include <QVBoxLayout>
+#include <QCheckBox>
+#include <QLineEdit>
 #include <QFormLayout>
-#include <QPushButton>
-#include <QLabel>
-#include <QSpinBox>
-#include <QSplitter>
 #include "objecteditor.h"
 #include "document.h"
 #include "modeleditor.h"
@@ -59,6 +56,22 @@
 		{
 			vec3Editor->setValue(value.value<glm::vec3>());
 		}
+		else
+		{
+			QCheckBox* checkBox = qobject_cast<QCheckBox*>(widget);
+			if (checkBox != nullptr)
+			{
+				checkBox->setChecked(value.toBool());
+			}
+			else
+			{
+				QLineEdit* lineEdit = qobject_cast<QLineEdit*>(widget);
+				if (lineEdit != nullptr)
+				{
+					lineEdit->setText(value.toString());
+				}
+			}
+		}
 	}
 }
 
@@ -66,7 +79,7 @@
 {
 	this->objectId = id;
 	const ldraw::Object* object = this->document->getModel().get(id);
-	this->ui.properties->setVisible(object != nullptr);
+	this->ui.properties->setEnabled(object != nullptr);
 	if (object != nullptr)
 	{
 		this->ui.typeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>");
@@ -77,8 +90,8 @@
 			const auto it = this->propertyWidgets.find(property);
 			if (it != this->propertyWidgets.end())
 			{
-				it->first->setVisible(not value.isNull());
-				it->second->setVisible(not value.isNull());
+				it->first->setEnabled(not value.isNull());
+				it->second->setEnabled(not value.isNull());
 				if (not value.isNull())
 				{
 					setValueToWidget(it->second, value);
@@ -103,6 +116,16 @@
 	this->handlePropertyChange(this->sender(), QVariant::fromValue(value));
 }
 
+void ObjectEditor::handleBoolChange(bool value)
+{
+	this->handlePropertyChange(this->sender(), QVariant::fromValue(value));
+}
+
+void ObjectEditor::handleStringChange(const QString &value)
+{
+	this->handlePropertyChange(this->sender(), QVariant::fromValue(value));
+}
+
 QWidget* ObjectEditor::makeEditorWidgetForProperty(ldraw::Property property)
 {
 	QWidget* const parent = qobject_cast<QWidget*>(this->parent());
@@ -118,6 +141,18 @@
 		connect(editor, &Vec3Editor::valueChanged, this, &ObjectEditor::handleVec3Change);
 		return editor;
 	}
+	else if (ldraw::traits(property).type == qMetaTypeId<bool>())
+	{
+		QCheckBox* editor = new QCheckBox{{}, parent};
+		connect(editor, &QCheckBox::clicked, this, &ObjectEditor::handleBoolChange);
+		return editor;
+	}
+	else if (ldraw::traits(property).type == qMetaTypeId<QString>())
+	{
+		QLineEdit* editor = new QLineEdit{{}, parent};
+		connect(editor, &QLineEdit::textChanged, this, &ObjectEditor::handleStringChange);
+		return editor;
+	}
 	else
 	{
 		return nullptr;

mercurial