Tue, 11 Apr 2023 22:51:47 +0300
remove now unneeded type alias
#include <QDialog> #include <QCheckBox> #include <QSignalBlocker> #include "widgets/vec3editor.h" #include "widgets/multiplyfactordialog.h" VectorInput::VectorInput(const glm::vec3& value, QWidget* parent, QFlags<VectorInput::Flag> flags) : VectorInput{parent, flags} { this->setValue(value); } VectorInput::VectorInput(QWidget *parent, QFlags<Flag> flags) : QWidget{parent} { this->ui.setupUi(this); if (flags.testFlag(NoMultiplyButton)) { this->ui.multiply->setVisible(false); } else { connect(this->ui.multiply, &QPushButton::clicked, this, &VectorInput::multiplyPressed); } for (QDoubleSpinBox* spinbox : this->spinboxes()) { connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [&](double){ Q_EMIT this->valueChanged(this->value()); }); } } VectorInput::~VectorInput() { } glm::vec3 VectorInput::value() const { auto get = [](DoubleSpinBox* spinbox){ return static_cast<float>(spinbox->value()); }; return {get(this->ui.x), get(this->ui.y), get(this->ui.z)}; } void VectorInput::setValue(const glm::vec3& value) { auto set = [](DoubleSpinBox* spinbox, float value){ QSignalBlocker blocker{spinbox}; spinbox->setValue(static_cast<qreal>(value)); }; set(this->ui.x, value.x); set(this->ui.y, value.y); set(this->ui.z, value.z); 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}; } void VectorInput::multiplyPressed() { MultiplyFactorDialog dialog{this->value(), this}; const int dialogResult = dialog.exec(); if (dialogResult == QDialog::Accepted) { this->setValue(dialog.value()); } }