diff --git a/companion/src/shared/autocheckbox.h b/companion/src/shared/autocheckbox.h index a9e70d255..1c1a7207c 100644 --- a/companion/src/shared/autocheckbox.h +++ b/companion/src/shared/autocheckbox.h @@ -51,11 +51,11 @@ class AutoCheckBox: public QCheckBox void updateValue() { - if (!field) - return; - lock = true; - setChecked(*field); - lock = false; + if (field) { + lock = true; + setChecked(*field); + lock = false; + } } signals: diff --git a/companion/src/shared/autodoublespinbox.h b/companion/src/shared/autodoublespinbox.h index 6560b6ea2..a6466269e 100644 --- a/companion/src/shared/autodoublespinbox.h +++ b/companion/src/shared/autodoublespinbox.h @@ -21,7 +21,7 @@ #pragma once #include -#include "modeledit/modeledit.h" +#include "genericpanel.h" #if __GNUC__ #include #endif @@ -31,23 +31,23 @@ class AutoDoubleSpinBox: public QDoubleSpinBox Q_OBJECT public: - explicit AutoDoubleSpinBox(QWidget *parent = 0): + explicit AutoDoubleSpinBox(QWidget * parent = nullptr): QDoubleSpinBox(parent), - field(NULL), - panel(NULL), + field(nullptr), + panel(nullptr), lock(false) { connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double))); } - void setField(int & field, ModelPanel * panel=NULL) + void setField(int & field, GenericPanel * panel = nullptr) { this->field = &field; this->panel = panel; updateValue(); } - void setField(unsigned int & field, ModelPanel * panel=NULL) + void setField(unsigned int & field, GenericPanel * panel = nullptr) { this->field = (int *)&field; this->panel = panel; @@ -57,7 +57,9 @@ class AutoDoubleSpinBox: public QDoubleSpinBox void updateValue() { if (field) { - setValue(float(*field)/multiplier()); + lock = true; + setValue(float(*field) / multiplier()); + lock = false; } } @@ -80,11 +82,17 @@ class AutoDoubleSpinBox: public QDoubleSpinBox } } + signals: + void currentDataChanged(double value); + protected slots: void onValueChanged(double value) { + if (panel && panel->lock) + return; if (field && !lock) { *field = round(value * multiplier()); + emit currentDataChanged(value); if (panel) { emit panel->modified(); } @@ -92,7 +100,7 @@ class AutoDoubleSpinBox: public QDoubleSpinBox } protected: - int * field; - ModelPanel * panel; - bool lock; + int * field = nullptr; + GenericPanel * panel = nullptr; + bool lock = false; }; diff --git a/companion/src/shared/autohexspinbox.h b/companion/src/shared/autohexspinbox.h index d7df46bd6..40cc24da4 100644 --- a/companion/src/shared/autohexspinbox.h +++ b/companion/src/shared/autohexspinbox.h @@ -21,23 +21,23 @@ #pragma once #include "hexspinbox.h" -#include "modeledit/modeledit.h" +#include "genericpanel.h" class AutoHexSpinBox: public HexSpinBox { Q_OBJECT public: - explicit AutoHexSpinBox(QWidget *parent = 0): + explicit AutoHexSpinBox(QWidget * parent = nullptr): HexSpinBox(parent), - field(NULL), - panel(NULL), + field(nullptr), + panel(nullptr), lock(false) { connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); } - void setField(unsigned int & field, ModelPanel * panel=NULL) + void setField(unsigned int & field, GenericPanel * panel = nullptr) { this->field = &field; this->panel = panel; @@ -47,15 +47,23 @@ class AutoHexSpinBox: public HexSpinBox void updateValue() { if (field) { + lock = true; setValue(*field); + lock = false; } } + signals: + void currentDataChanged(int value); + protected slots: void onValueChanged(int value) { + if (panel && panel->lock) + return; if (field && !lock) { *field = value; + emit currentDataChanged(value); if (panel) { emit panel->modified(); } @@ -63,7 +71,7 @@ class AutoHexSpinBox: public HexSpinBox } protected: - unsigned int * field; - ModelPanel * panel; - bool lock; + unsigned int * field = nullptr; + GenericPanel * panel = nullptr; + bool lock = false; }; diff --git a/companion/src/shared/autolineedit.h b/companion/src/shared/autolineedit.h index 0f888e6df..173d16e95 100644 --- a/companion/src/shared/autolineedit.h +++ b/companion/src/shared/autolineedit.h @@ -29,11 +29,11 @@ class AutoLineEdit: public QLineEdit Q_OBJECT public: - explicit AutoLineEdit(QWidget *parent = nullptr, bool updateOnChange = false): + explicit AutoLineEdit(QWidget * parent = nullptr, bool updateOnChange = false): QLineEdit(parent), field(NULL), - strField(NULL), - panel(NULL), + strField(nullptr), + panel(nullptr), lock(false) { if (updateOnChange) @@ -86,15 +86,15 @@ class AutoLineEdit: public QLineEdit else return; + emit currentDataChanged(); + if (panel) emit panel->modified(); - - emit currentDataChanged(); } protected: char * field; - QString * strField; - GenericPanel * panel; - bool lock; + QString * strField = nullptr; + GenericPanel * panel = nullptr; + bool lock = false; }; diff --git a/companion/src/shared/autoprecisioncombobox.h b/companion/src/shared/autoprecisioncombobox.h index e93059199..72dd89406 100644 --- a/companion/src/shared/autoprecisioncombobox.h +++ b/companion/src/shared/autoprecisioncombobox.h @@ -123,7 +123,7 @@ class AutoPrecisionComboBox: public QComboBox if (*m_field != val) { *m_field = rangecheckDecimals(val); updateValue(); - emit valueChanged(); + emit currentDataChanged(value); } } @@ -134,7 +134,7 @@ class AutoPrecisionComboBox: public QComboBox if (*m_field != value) { *m_field = rangecheckDecimals(value); updateValue(); - emit valueChanged(); + emit currentDataChanged((int)value); } } @@ -160,7 +160,7 @@ class AutoPrecisionComboBox: public QComboBox } signals: - void valueChanged(); + void currentDataChanged(int index); protected slots: void init() @@ -203,13 +203,13 @@ class AutoPrecisionComboBox: public QComboBox void onCurrentIndexChanged(int index) { - if (index < 0) + if (index < 0 || (m_panel && m_panel->lock) || m_lock) return; - if (m_field && !m_lock) { + if (m_field) { *m_field = itemData(index).toUInt(); + emit currentDataChanged(index); if (m_panel) emit m_panel->modified(); - emit valueChanged(); } }