Support of inputs / mixes from 'next' continued. More duplicated code

removed.
This commit is contained in:
Bertrand Songis
2014-01-17 15:46:19 +01:00
parent ddd8d137fc
commit 11e83de0d3
15 changed files with 332 additions and 347 deletions
+82 -148
View File
@@ -3,126 +3,97 @@
#include "eeprominterface.h"
#include "helpers.h"
ExpoDialog::ExpoDialog(QWidget *parent, ExpoData *expoData, int stickMode) :
ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, int stickMode) :
QDialog(parent),
ui(new Ui::ExpoDialog),
model(model),
ed(expoData)
{
ui->setupUi(this);
QLabel * lb_fp[] = {ui->lb_FP0,ui->lb_FP1,ui->lb_FP2,ui->lb_FP3,ui->lb_FP4,ui->lb_FP5,ui->lb_FP6,ui->lb_FP7,ui->lb_FP8 };
QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 };
ui->setupUi(this);
QLabel * lb_fp[] = {ui->lb_FP0,ui->lb_FP1,ui->lb_FP2,ui->lb_FP3,ui->lb_FP4,ui->lb_FP5,ui->lb_FP6,ui->lb_FP7,ui->lb_FP8 };
QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 };
setWindowTitle(tr("DEST -> %1").arg(getStickStr(ed->chn)));
QRegExp rx(CHAR_FOR_NAMES_REGEX);
int gvars=0;
if (GetEepromInterface()->getCapability(HasVariants)) {
if ((GetCurrentFirmwareVariant() & GVARS_VARIANT)) {
gvars=1;
}
} else {
gvars=1;
}
setWindowTitle(tr("Edit %1").arg(getInputStr(model, ed->chn)));
QRegExp rx(CHAR_FOR_NAMES_REGEX);
if (gvars==0) {
ui->weightGV->setDisabled(true);
ui->curveGVarCB->hide();
if ((ed->curve.type == CurveReference::CURVE_REF_EXPO || ed->curve.type == CurveReference::CURVE_REF_DIFF) && ed->curve.value > 100) {
ed->curve.value = 0;
}
if (ed->weight>100 || ed->weight<-100) {
ed->weight = 100;
}
}
gvGroup = new GVarGroup(ui->weightGV, ui->weightSB, ui->weightCB, ed->weight, 100, 0, 100);
curveGroup = new CurveGroup(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, ed->curve);
populateGVCB(ui->weightCB, ed->weight);
populateSwitchCB(ui->switchesCB,ed->swtch);
ui->weightSB->setMinimum(0);
ui->weightSB->setMaximum(100);
if (ed->weight>100 || ed->weight<0) {
ui->weightGV->setChecked(true);
ui->weightSB->hide();
ui->weightCB->show();
} else {
ui->weightGV->setChecked(false);
ui->weightSB->setValue(ed->weight);
ui->weightSB->show();
ui->weightCB->hide();
}
ui->sideCB->setCurrentIndex(ed->mode-1);
populateSwitchCB(ui->switchesCB,ed->swtch);
// TODO keep this group, same in MixerDialog
CurveGroup * curveGroup = new CurveGroup(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, ed->curve);
ui->sideCB->setCurrentIndex(ed->mode-1);
if (!GetEepromInterface()->getCapability(FlightPhases)) {
ui->label_phases->hide();
for (int i=0; i<9; i++) {
lb_fp[i]->hide();
cb_fp[i]->hide();
}
} else {
int mask=1;
for (int i=0; i<9 ; i++) {
if ((ed->phases & mask)==0) {
cb_fp[i]->setChecked(true);
}
mask <<= 1;
}
for (int i=GetEepromInterface()->getCapability(FlightPhases); i<9;i++) {
lb_fp[i]->hide();
cb_fp[i]->hide();
}
}
if (GetEepromInterface()->getCapability(VirtualInputs)) {
ui->sideLabel->hide();
ui->sideCB->hide();
}
else {
ui->sourceLabel->hide();
ui->sourceCB->hide();
ui->scaleLabel->hide();
ui->scaleSB->hide();
ui->trimLabel->hide();
ui->trimCB->hide();
}
int expolength=GetEepromInterface()->getCapability(HasExpoNames);
if (!expolength) {
ui->label_name->hide();
ui->expoName->hide();
} else {
ui->expoName->setMaxLength(expolength);
}
ui->expoName->setValidator(new QRegExpValidator(rx, this));
ui->expoName->setText(ed->name);
valuesChanged();
connect(ui->expoName,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
connect(ui->curveTypeCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
connect(ui->curveGVarCB,SIGNAL(stateChanged(int)),this,SLOT(valuesChanged()));
connect(ui->curveValueCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
connect(ui->curveValueSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
connect(ui->weightCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
connect(ui->weightSB,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
connect(ui->switchesCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
connect(ui->sideCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
connect(ui->weightGV,SIGNAL(stateChanged(int)),this,SLOT(widgetChanged()));
if (!GetEepromInterface()->getCapability(FlightPhases)) {
ui->label_phases->hide();
for (int i=0; i<9; i++) {
connect(cb_fp[i],SIGNAL(toggled(bool)),this,SLOT(valuesChanged()));
lb_fp[i]->hide();
cb_fp[i]->hide();
}
QTimer::singleShot(0, this, SLOT(shrink()));
}
else {
int mask=1;
for (int i=0; i<9 ; i++) {
if ((ed->phases & mask)==0) {
cb_fp[i]->setChecked(true);
}
mask <<= 1;
}
for (int i=GetEepromInterface()->getCapability(FlightPhases); i<9;i++) {
lb_fp[i]->hide();
cb_fp[i]->hide();
}
}
if (GetEepromInterface()->getCapability(VirtualInputs)) {
ui->sideLabel->hide();
ui->sideCB->hide();
ui->inputName->setMaxLength(4);
populateSourceCB(ui->sourceCB, ed->srcRaw, POPULATE_SOURCES | POPULATE_SWITCHES | POPULATE_TRIMS | (GetEepromInterface()->getCapability(GvarsAsSources) ? POPULATE_GVARS : 0));
ui->sourceCB->removeItem(0);
}
else {
ui->inputNameLabel->hide();
ui->inputName->hide();
ui->sourceLabel->hide();
ui->sourceCB->hide();
ui->scaleLabel->hide();
ui->scaleSB->hide();
ui->trimLabel->hide();
ui->trimCB->hide();
}
int expolength = GetEepromInterface()->getCapability(HasExpoNames);
if (!expolength) {
ui->lineNameLabel->hide();
ui->lineName->hide();
}
else {
ui->lineName->setMaxLength(expolength);
}
ui->inputName->setValidator(new QRegExpValidator(rx, this));
ui->inputName->setText(model.inputNames[ed->chn]);
ui->lineName->setValidator(new QRegExpValidator(rx, this));
ui->lineName->setText(ed->name);
valuesChanged();
connect(ui->lineName,SIGNAL(editingFinished()),this,SLOT(valuesChanged()));
connect(ui->sourceCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
connect(ui->switchesCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
connect(ui->sideCB,SIGNAL(currentIndexChanged(int)),this,SLOT(valuesChanged()));
for (int i=0; i<9; i++) {
connect(cb_fp[i],SIGNAL(toggled(bool)),this,SLOT(valuesChanged()));
}
QTimer::singleShot(0, this, SLOT(shrink()));
}
ExpoDialog::~ExpoDialog()
{
delete ui;
delete gvGroup;
delete curveGroup;
delete ui;
}
void ExpoDialog::changeEvent(QEvent *e)
@@ -137,54 +108,17 @@ void ExpoDialog::changeEvent(QEvent *e)
}
}
void ExpoDialog::widgetChanged()
{
// TODO so many times duplicated :(
int gvars=0;
if (GetEepromInterface()->getCapability(HasVariants)) {
if ((GetCurrentFirmwareVariant() & GVARS_VARIANT)) {
gvars=1;
}
} else {
gvars=1;
}
/* TODO if (gvars==1) {
if (ui->expoCurveGV->isChecked()) {
ui->expoCurveCB->show();
ui->expoCurveSB->hide();
} else {
ui->expoCurveCB->hide();
ui->expoCurveSB->show();
}
if (ui->weightGV->isChecked()) {
ui->weightCB->show();
ui->weightSB->hide();
} else {
ui->weightCB->hide();
ui->weightSB->show();
}
} */
valuesChanged();
QTimer::singleShot(0, this, SLOT(shrink()));
}
void ExpoDialog::valuesChanged()
{
QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 };
if (ui->weightGV->isChecked()) {
ed->weight = ui->weightCB->itemData(ui->weightCB->currentIndex()).toInt();
} else {
ed->weight = ui->weightSB->value();
}
ed->srcRaw = RawSource(ui->sourceCB->itemData(ui->sourceCB->currentIndex()).toInt());
ed->swtch = RawSwitch(ui->switchesCB->itemData(ui->switchesCB->currentIndex()).toInt());
ed->mode = ui->sideCB->currentIndex() + 1;
int i=0;
for (i=0; i<ui->expoName->text().toAscii().length(); i++) {
ed->name[i]=ui->expoName->text().toAscii().at(i);
}
ed->name[i]=0;
strcpy(ed->name, ui->lineName->text().toAscii().data());
strcpy(model.inputNames[ed->chn], ui->inputName->text().toAscii().data());
ed->phases=0;
for (int i=8; i>=0 ; i--) {
if (!cb_fp[i]->checkState()) {
@@ -231,5 +165,5 @@ void ExpoDialog::valuesChanged()
void ExpoDialog::shrink()
{
resize(0,0);
resize(0,0);
}