mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 17:25:13 +03:00
Standardisation of auto widgets
This commit is contained in:
parent
e801f490b3
commit
60ac1550f4
5 changed files with 53 additions and 37 deletions
|
@ -51,12 +51,12 @@ class AutoCheckBox: public QCheckBox
|
|||
|
||||
void updateValue()
|
||||
{
|
||||
if (!field)
|
||||
return;
|
||||
if (field) {
|
||||
lock = true;
|
||||
setChecked(*field);
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
signals:
|
||||
void currentDataChanged(bool value);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDoubleSpinBox>
|
||||
#include "modeledit/modeledit.h"
|
||||
#include "genericpanel.h"
|
||||
#if __GNUC__
|
||||
#include <math.h>
|
||||
#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) {
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -32,8 +32,8 @@ class AutoLineEdit: public QLineEdit
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue