mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 12:25:12 +03:00
Add support for rawsource and rawswitch in autocombobox
This commit is contained in:
parent
aac6c74e59
commit
950fa3d105
3 changed files with 67 additions and 13 deletions
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include "genericpanel.h"
|
#include "genericpanel.h"
|
||||||
|
#include "rawsource.h"
|
||||||
|
#include "rawswitch.h"
|
||||||
|
|
||||||
class AutoComboBox: public QComboBox
|
class AutoComboBox: public QComboBox
|
||||||
{
|
{
|
||||||
|
@ -34,7 +36,9 @@ class AutoComboBox: public QComboBox
|
||||||
panel(nullptr),
|
panel(nullptr),
|
||||||
next(0),
|
next(0),
|
||||||
lock(false),
|
lock(false),
|
||||||
hasModel(false)
|
hasModel(false),
|
||||||
|
rawSource(nullptr),
|
||||||
|
rawSwitch(nullptr)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
|
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
|
||||||
}
|
}
|
||||||
|
@ -77,6 +81,8 @@ class AutoComboBox: public QComboBox
|
||||||
void setField(unsigned int & field, GenericPanel * panel = nullptr)
|
void setField(unsigned int & field, GenericPanel * panel = nullptr)
|
||||||
{
|
{
|
||||||
this->field = (int *)&field;
|
this->field = (int *)&field;
|
||||||
|
this->rawSource = nullptr;
|
||||||
|
this->rawSwitch = nullptr;
|
||||||
this->panel = panel;
|
this->panel = panel;
|
||||||
updateValue();
|
updateValue();
|
||||||
}
|
}
|
||||||
|
@ -84,6 +90,26 @@ class AutoComboBox: public QComboBox
|
||||||
void setField(int & field, GenericPanel * panel = nullptr)
|
void setField(int & field, GenericPanel * panel = nullptr)
|
||||||
{
|
{
|
||||||
this->field = &field;
|
this->field = &field;
|
||||||
|
this->rawSource = nullptr;
|
||||||
|
this->rawSwitch = nullptr;
|
||||||
|
this->panel = panel;
|
||||||
|
updateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setField(RawSource & field, GenericPanel * panel = nullptr)
|
||||||
|
{
|
||||||
|
this->rawSource = &field;
|
||||||
|
this->rawSwitch = nullptr;
|
||||||
|
this->field = nullptr;
|
||||||
|
this->panel = panel;
|
||||||
|
updateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setField(RawSwitch & field, GenericPanel * panel = nullptr)
|
||||||
|
{
|
||||||
|
this->rawSwitch = &field;
|
||||||
|
this->rawSource = nullptr;
|
||||||
|
this->field = nullptr;
|
||||||
this->panel = panel;
|
this->panel = panel;
|
||||||
updateValue();
|
updateValue();
|
||||||
}
|
}
|
||||||
|
@ -108,10 +134,18 @@ class AutoComboBox: public QComboBox
|
||||||
|
|
||||||
void updateValue()
|
void updateValue()
|
||||||
{
|
{
|
||||||
if (!field)
|
if (!field && !rawSource && !rawSwitch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock = true;
|
lock = true;
|
||||||
setCurrentIndex(findData(*field));
|
|
||||||
|
if (field)
|
||||||
|
setCurrentIndex(findData(*field));
|
||||||
|
else if (rawSource)
|
||||||
|
setCurrentIndex(findData(rawSource->toValue()));
|
||||||
|
else if (rawSwitch)
|
||||||
|
setCurrentIndex(findData(rawSwitch->toValue()));
|
||||||
|
|
||||||
lock = false;
|
lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,15 +157,29 @@ class AutoComboBox: public QComboBox
|
||||||
{
|
{
|
||||||
if (panel && panel->lock)
|
if (panel && panel->lock)
|
||||||
return;
|
return;
|
||||||
if (index > -1) {
|
if (lock || index < 0)
|
||||||
const int val = itemData(index).toInt();
|
return;
|
||||||
if (field && !lock) {
|
|
||||||
*field = val;
|
bool ok;
|
||||||
emit currentDataChanged(val);
|
const int val = itemData(index).toInt(&ok);
|
||||||
if (panel)
|
if (!ok)
|
||||||
emit panel->modified();
|
return;
|
||||||
}
|
|
||||||
|
if (field && *field != val) {
|
||||||
|
*field = val;
|
||||||
}
|
}
|
||||||
|
else if (rawSource && rawSource->toValue() != val) {
|
||||||
|
*rawSource = RawSource(val);
|
||||||
|
}
|
||||||
|
else if (rawSwitch && rawSwitch->toValue() != val) {
|
||||||
|
*rawSwitch = RawSwitch(val);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
emit currentDataChanged(val);
|
||||||
|
if (panel)
|
||||||
|
emit panel->modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -140,4 +188,6 @@ class AutoComboBox: public QComboBox
|
||||||
int next = 0;
|
int next = 0;
|
||||||
bool lock = false;
|
bool lock = false;
|
||||||
bool hasModel = false;
|
bool hasModel = false;
|
||||||
|
RawSource *rawSource = nullptr;
|
||||||
|
RawSwitch *rawSwitch = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -76,7 +76,9 @@ class AutoLineEdit: public QLineEdit
|
||||||
protected slots:
|
protected slots:
|
||||||
void onEdited()
|
void onEdited()
|
||||||
{
|
{
|
||||||
if ((panel && panel->lock) || lock)
|
if (panel && panel->lock)
|
||||||
|
return;
|
||||||
|
if (lock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (field)
|
if (field)
|
||||||
|
|
|
@ -77,7 +77,9 @@ class AutoTimeEdit: public QTimeEdit
|
||||||
protected slots:
|
protected slots:
|
||||||
void onTimeChanged(QTime time)
|
void onTimeChanged(QTime time)
|
||||||
{
|
{
|
||||||
if ((panel && panel->lock) || !field || lock)
|
if (panel && panel->lock)
|
||||||
|
return;
|
||||||
|
if (!field || lock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned int val = time.hour() * 3600 + time.minute() * 60 + time.second();
|
unsigned int val = time.hour() * 3600 + time.minute() * 60 + time.second();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue