Refactor setup hardware, trainer and calibration

This commit is contained in:
elecpower
2021-04-16 07:02:09 +10:00
parent 1f593c4f9e
commit 1a8502e284
25 changed files with 1081 additions and 2278 deletions
+16 -6
View File
@@ -32,15 +32,17 @@ class AutoCheckBox: public QCheckBox
QCheckBox(parent),
field(nullptr),
panel(nullptr),
lock(false)
lock(false),
invert(false)
{
connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
connect(this, &AutoCheckBox::toggled, this, &AutoCheckBox::onToggled);
}
void setField(bool & field, GenericPanel * panel = nullptr)
void setField(bool & field, GenericPanel * panel = nullptr, bool invert = false)
{
this->field = &field;
this->panel = panel;
this->invert = invert;
updateValue();
}
@@ -49,11 +51,17 @@ class AutoCheckBox: public QCheckBox
QCheckBox::setEnabled(enabled);
}
void setInvert(bool invert)
{
this->invert = invert;
updateValue();
}
void updateValue()
{
if (field) {
lock = true;
setChecked(*field);
setChecked(invert ? !(*field) : *field);
lock = false;
}
}
@@ -67,8 +75,9 @@ class AutoCheckBox: public QCheckBox
if (panel && panel->lock)
return;
if (field && !lock) {
*field = checked;
emit currentDataChanged(checked);
const bool val = invert ? !checked : checked;
*field = val;
emit currentDataChanged(val);
if (panel)
emit panel->modified();
}
@@ -78,4 +87,5 @@ class AutoCheckBox: public QCheckBox
bool *field = nullptr;
GenericPanel *panel = nullptr;
bool lock = false;
bool invert = false;
};