Add x, y, z properties to VectorInput

Wed, 22 Jun 2022 22:50:37 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 22 Jun 2022 22:50:37 +0300
changeset 255
5188f8a74a5c
parent 254
b7b29cb82360
child 256
c6f5de03dc0f

Add x, y, z properties to VectorInput

widgets/CMakeLists.txt file | annotate | diff | comparison | revisions
widgets/vec3editor.cpp file | annotate | diff | comparison | revisions
widgets/vec3editor.h file | annotate | diff | comparison | revisions
--- a/widgets/CMakeLists.txt	Wed Jun 22 21:46:38 2022 +0300
+++ b/widgets/CMakeLists.txt	Wed Jun 22 22:50:37 2022 +0300
@@ -24,6 +24,7 @@
 target_include_directories(ldforgewidgets PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
 target_include_directories(ldforgewidgets PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
 target_link_libraries(ldforgewidgets Qt5::Widgets)
+set_target_properties(ldforgewidgets PROPERTIES AUTOMOC 1)
 
 get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake LOCATION)
 execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_PLUGINS
--- a/widgets/vec3editor.cpp	Wed Jun 22 21:46:38 2022 +0300
+++ b/widgets/vec3editor.cpp	Wed Jun 22 22:50:37 2022 +0300
@@ -13,7 +13,6 @@
 VectorInput::VectorInput(QWidget *parent, QFlags<Flag> flags) :
 	QWidget{parent}
 {
-	
 	this->ui.setupUi(this);
 	if (flags.testFlag(NoMultiplyButton)) {
 		this->ui.multiply->setVisible(false);
@@ -50,6 +49,36 @@
 	Q_EMIT this->valueChanged(value);
 }
 
+qreal VectorInput::x() const
+{
+	return this->ui.x->value();
+}
+
+qreal VectorInput::y() const
+{
+	return this->ui.y->value();
+}
+
+qreal VectorInput::z() const
+{
+	return this->ui.z->value();
+}
+
+void VectorInput::setX(qreal x)
+{
+	this->ui.x->setValue(x);
+}
+
+void VectorInput::setY(qreal y)
+{
+	this->ui.y->setValue(y);
+}
+
+void VectorInput::setZ(qreal z)
+{
+	this->ui.z->setValue(z);
+}
+
 std::array<DoubleSpinBox*, 3> VectorInput::spinboxes()
 {
 	return {this->ui.x, this->ui.y, this->ui.z};
--- a/widgets/vec3editor.h	Wed Jun 22 21:46:38 2022 +0300
+++ b/widgets/vec3editor.h	Wed Jun 22 22:50:37 2022 +0300
@@ -6,6 +6,9 @@
 class VectorInput : public QWidget
 {
 	Q_OBJECT
+	Q_PROPERTY(qreal x READ x WRITE setX)
+	Q_PROPERTY(qreal y READ y WRITE setY)
+	Q_PROPERTY(qreal z READ z WRITE setZ)
 	Ui_Vec3Editor ui;
 public:
 	enum Flag
@@ -17,8 +20,13 @@
 	~VectorInput();
 	glm::vec3 value() const;
 	void setValue(const glm::vec3& value);
-Q_SIGNALS:
-	void valueChanged(const glm::vec3& value);
+	qreal x() const;
+	qreal y() const;
+	qreal z() const;
+	Q_SLOT void setX(qreal x);
+	Q_SLOT void setY(qreal y);
+	Q_SLOT void setZ(qreal z);
+	Q_SIGNAL void valueChanged(const glm::vec3& value);
 private:
 	std::array<class DoubleSpinBox*, 3> spinboxes();
 	Q_SLOT void multiplyPressed();

mercurial