fix some on properties and signal connection

This commit is contained in:
AndreaRigoni
2026-03-26 09:50:52 +00:00
parent 2c5d6842c3
commit e0ffeff5b7
22 changed files with 578 additions and 62 deletions

View File

@@ -14,11 +14,14 @@
#include "Core/Property.h"
#include "Core/Object.h"
#include "Core/Signal.h"
#include "Math/Dense.h"
namespace uLib {
namespace Qt {
double parseWithUnits(const QString& text, double* factorOut = nullptr, QString* suffixOut = nullptr);
class PropertyWidgetBase : public QWidget {
Q_OBJECT
public:
@@ -30,6 +33,9 @@ protected:
PropertyBase* m_BaseProperty;
QHBoxLayout* m_Layout;
QLabel* m_Label;
// Stores the uLib signal connection so it can be disconnected on destruction,
// preventing use-after-free when PropertyEditor::clear() deletes widgets.
Connection m_Connection;
};
class UnitLineEdit : public QLineEdit {
@@ -37,6 +43,7 @@ class UnitLineEdit : public QLineEdit {
public:
UnitLineEdit(QWidget* parent = nullptr);
void setValue(double val);
void setUnits(const QString& suffix, double factor = 1.0);
double getValue() const { return m_Value; }
void setIntegerOnly(bool b);
@@ -86,11 +93,19 @@ class VectorPropertyWidget : public PropertyWidgetBase {
public:
VectorPropertyWidget(Property<VecT>* prop, QWidget* parent = nullptr)
: PropertyWidgetBase(prop, parent), m_Prop(prop) {
QString units = QString::fromStdString(prop->GetUnits());
double factor = 1.0;
if (!units.isEmpty()) {
parseWithUnits("1 " + units, &factor);
}
for (int i = 0; i < Size; ++i) {
m_Edits[i] = new UnitLineEdit(this);
if (std::is_integral<typename VecT::Scalar>::value) {
m_Edits[i]->setIntegerOnly(true);
}
if (!units.isEmpty()) {
m_Edits[i]->setUnits(units, factor);
}
m_Layout->addWidget(m_Edits[i], 1);
connect(m_Edits[i], &UnitLineEdit::valueManualChanged, [this, i](double val){
@@ -100,10 +115,11 @@ public:
});
}
updateEdits();
uLib::Object::connect(m_Prop, &Property<VecT>::PropertyChanged, [this](){
m_Connection = uLib::Object::connect(m_Prop, &Property<VecT>::PropertyChanged, [this](){
updateEdits();
});
}
~VectorPropertyWidget() { m_Connection.disconnect(); }
private:
void updateEdits() {