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
+1
View File
@@ -17,6 +17,7 @@ set(shared_HDRS
hexspinbox.h
autoprecisioncombobox.h
autotimeedit.h
autospinbox.h
)
qt5_wrap_cpp(shared_SRCS ${shared_HDRS})
+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;
};
+12 -4
View File
@@ -35,7 +35,8 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
QDoubleSpinBox(parent),
field(nullptr),
panel(nullptr),
lock(false)
lock(false),
offset(0)
{
connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double)));
}
@@ -58,7 +59,7 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
{
if (field) {
lock = true;
setValue(float(*field) / multiplier());
setValue(float(*field + offset) / multiplier());
lock = false;
}
}
@@ -69,6 +70,12 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
updateValue();
}
void setOffset(int offset)
{
this->offset = offset;
updateValue();
}
protected:
int multiplier()
{
@@ -91,8 +98,8 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
if (panel && panel->lock)
return;
if (field && !lock) {
*field = round(value * multiplier());
emit currentDataChanged(value);
*field = round(value * multiplier() - offset);
emit currentDataChanged(*field);
if (panel) {
emit panel->modified();
}
@@ -103,4 +110,5 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
int * field = nullptr;
GenericPanel * panel = nullptr;
bool lock = false;
int offset = 0;
};
+81
View File
@@ -0,0 +1,81 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QSpinBox>
#include "genericpanel.h"
class AutoSpinBox : public QSpinBox
{
Q_OBJECT
public:
explicit AutoSpinBox(QWidget * parent = nullptr):
QSpinBox(parent),
field(nullptr),
panel(nullptr),
lock(false)
{
connect(this, QOverload<int>::of(&AutoSpinBox::valueChanged), this, &AutoSpinBox::onValueChanged);
}
void setField(int & field, GenericPanel * panel = nullptr)
{
this->field = &field;
this->panel = panel;
updateValue();
}
void setField(unsigned int & field, GenericPanel * panel = nullptr)
{
this->field = (int *)&field;
this->panel = panel;
updateValue();
}
void updateValue()
{
lock = true;
if (field) {
setValue(*field);
}
lock = false;
}
protected slots:
void onValueChanged(int value)
{
if (panel && panel->lock)
return;
if (field && !lock) {
*field = value;
if (panel) {
emit panel->modified();
}
}
}
protected:
int * field;
GenericPanel * panel;
bool lock;
};
+1
View File
@@ -41,6 +41,7 @@ class GenericPanel : public QWidget
friend class AutoPrecisionComboBox;
friend class AutoBitsetCheckBox;
friend class AutoTimeEdit;
friend class AutoSpinBox;
public:
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware);