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,11 +51,11 @@ class AutoCheckBox: public QCheckBox
|
||||||
|
|
||||||
void updateValue()
|
void updateValue()
|
||||||
{
|
{
|
||||||
if (!field)
|
if (field) {
|
||||||
return;
|
lock = true;
|
||||||
lock = true;
|
setChecked(*field);
|
||||||
setChecked(*field);
|
lock = false;
|
||||||
lock = false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
#include "modeledit/modeledit.h"
|
#include "genericpanel.h"
|
||||||
#if __GNUC__
|
#if __GNUC__
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,23 +31,23 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AutoDoubleSpinBox(QWidget *parent = 0):
|
explicit AutoDoubleSpinBox(QWidget * parent = nullptr):
|
||||||
QDoubleSpinBox(parent),
|
QDoubleSpinBox(parent),
|
||||||
field(NULL),
|
field(nullptr),
|
||||||
panel(NULL),
|
panel(nullptr),
|
||||||
lock(false)
|
lock(false)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double)));
|
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->field = &field;
|
||||||
this->panel = panel;
|
this->panel = panel;
|
||||||
updateValue();
|
updateValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setField(unsigned int & field, ModelPanel * panel=NULL)
|
void setField(unsigned int & field, GenericPanel * panel = nullptr)
|
||||||
{
|
{
|
||||||
this->field = (int *)&field;
|
this->field = (int *)&field;
|
||||||
this->panel = panel;
|
this->panel = panel;
|
||||||
|
@ -57,7 +57,9 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
|
||||||
void updateValue()
|
void updateValue()
|
||||||
{
|
{
|
||||||
if (field) {
|
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:
|
protected slots:
|
||||||
void onValueChanged(double value)
|
void onValueChanged(double value)
|
||||||
{
|
{
|
||||||
|
if (panel && panel->lock)
|
||||||
|
return;
|
||||||
if (field && !lock) {
|
if (field && !lock) {
|
||||||
*field = round(value * multiplier());
|
*field = round(value * multiplier());
|
||||||
|
emit currentDataChanged(value);
|
||||||
if (panel) {
|
if (panel) {
|
||||||
emit panel->modified();
|
emit panel->modified();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +100,7 @@ class AutoDoubleSpinBox: public QDoubleSpinBox
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int * field;
|
int * field = nullptr;
|
||||||
ModelPanel * panel;
|
GenericPanel * panel = nullptr;
|
||||||
bool lock;
|
bool lock = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,23 +21,23 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "hexspinbox.h"
|
#include "hexspinbox.h"
|
||||||
#include "modeledit/modeledit.h"
|
#include "genericpanel.h"
|
||||||
|
|
||||||
class AutoHexSpinBox: public HexSpinBox
|
class AutoHexSpinBox: public HexSpinBox
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AutoHexSpinBox(QWidget *parent = 0):
|
explicit AutoHexSpinBox(QWidget * parent = nullptr):
|
||||||
HexSpinBox(parent),
|
HexSpinBox(parent),
|
||||||
field(NULL),
|
field(nullptr),
|
||||||
panel(NULL),
|
panel(nullptr),
|
||||||
lock(false)
|
lock(false)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
|
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->field = &field;
|
||||||
this->panel = panel;
|
this->panel = panel;
|
||||||
|
@ -47,15 +47,23 @@ class AutoHexSpinBox: public HexSpinBox
|
||||||
void updateValue()
|
void updateValue()
|
||||||
{
|
{
|
||||||
if (field) {
|
if (field) {
|
||||||
|
lock = true;
|
||||||
setValue(*field);
|
setValue(*field);
|
||||||
|
lock = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentDataChanged(int value);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onValueChanged(int value)
|
void onValueChanged(int value)
|
||||||
{
|
{
|
||||||
|
if (panel && panel->lock)
|
||||||
|
return;
|
||||||
if (field && !lock) {
|
if (field && !lock) {
|
||||||
*field = value;
|
*field = value;
|
||||||
|
emit currentDataChanged(value);
|
||||||
if (panel) {
|
if (panel) {
|
||||||
emit panel->modified();
|
emit panel->modified();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +71,7 @@ class AutoHexSpinBox: public HexSpinBox
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int * field;
|
unsigned int * field = nullptr;
|
||||||
ModelPanel * panel;
|
GenericPanel * panel = nullptr;
|
||||||
bool lock;
|
bool lock = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,11 +29,11 @@ class AutoLineEdit: public QLineEdit
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AutoLineEdit(QWidget *parent = nullptr, bool updateOnChange = false):
|
explicit AutoLineEdit(QWidget * parent = nullptr, bool updateOnChange = false):
|
||||||
QLineEdit(parent),
|
QLineEdit(parent),
|
||||||
field(NULL),
|
field(NULL),
|
||||||
strField(NULL),
|
strField(nullptr),
|
||||||
panel(NULL),
|
panel(nullptr),
|
||||||
lock(false)
|
lock(false)
|
||||||
{
|
{
|
||||||
if (updateOnChange)
|
if (updateOnChange)
|
||||||
|
@ -86,15 +86,15 @@ class AutoLineEdit: public QLineEdit
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
emit currentDataChanged();
|
||||||
|
|
||||||
if (panel)
|
if (panel)
|
||||||
emit panel->modified();
|
emit panel->modified();
|
||||||
|
|
||||||
emit currentDataChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char * field;
|
char * field;
|
||||||
QString * strField;
|
QString * strField = nullptr;
|
||||||
GenericPanel * panel;
|
GenericPanel * panel = nullptr;
|
||||||
bool lock;
|
bool lock = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -123,7 +123,7 @@ class AutoPrecisionComboBox: public QComboBox
|
||||||
if (*m_field != val) {
|
if (*m_field != val) {
|
||||||
*m_field = rangecheckDecimals(val);
|
*m_field = rangecheckDecimals(val);
|
||||||
updateValue();
|
updateValue();
|
||||||
emit valueChanged();
|
emit currentDataChanged(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class AutoPrecisionComboBox: public QComboBox
|
||||||
if (*m_field != value) {
|
if (*m_field != value) {
|
||||||
*m_field = rangecheckDecimals(value);
|
*m_field = rangecheckDecimals(value);
|
||||||
updateValue();
|
updateValue();
|
||||||
emit valueChanged();
|
emit currentDataChanged((int)value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ class AutoPrecisionComboBox: public QComboBox
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void valueChanged();
|
void currentDataChanged(int index);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void init()
|
void init()
|
||||||
|
@ -203,13 +203,13 @@ class AutoPrecisionComboBox: public QComboBox
|
||||||
|
|
||||||
void onCurrentIndexChanged(int index)
|
void onCurrentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0 || (m_panel && m_panel->lock) || m_lock)
|
||||||
return;
|
return;
|
||||||
if (m_field && !m_lock) {
|
if (m_field) {
|
||||||
*m_field = itemData(index).toUInt();
|
*m_field = itemData(index).toUInt();
|
||||||
|
emit currentDataChanged(index);
|
||||||
if (m_panel)
|
if (m_panel)
|
||||||
emit m_panel->modified();
|
emit m_panel->modified();
|
||||||
emit valueChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue