[Companion] Refactor FlightModePanel and TimerPanel to use shared RawSwitch data models instead of one per instance.
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include "helpers.h"
|
||||
#include "customdebug.h"
|
||||
|
||||
FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchFilterItemModel * switchModel):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::FlightMode),
|
||||
phaseIdx(phaseIdx),
|
||||
@@ -53,10 +53,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
|
||||
|
||||
// Phase switch
|
||||
if (phaseIdx > 0) {
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::MixesContext, this);
|
||||
ui->swtch->setModel(rawSwitchItemModel);
|
||||
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
|
||||
connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int)));
|
||||
ui->swtch->setModel(switchModel);
|
||||
connect(ui->swtch, SIGNAL(activated(int)), this, SLOT(phaseSwitchChanged(int)));
|
||||
}
|
||||
else {
|
||||
ui->swtch->hide();
|
||||
@@ -287,11 +285,8 @@ FlightModePanel::~FlightModePanel()
|
||||
|
||||
void FlightModePanel::update()
|
||||
{
|
||||
if (rawSwitchItemModel) {
|
||||
rawSwitchItemModel->update();
|
||||
}
|
||||
|
||||
ui->name->setText(phase.name);
|
||||
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
|
||||
|
||||
int scale = firmware->getCapability(SlowScale);
|
||||
ui->fadeIn->setValue(float(phase.fadeIn)/scale);
|
||||
@@ -382,11 +377,15 @@ void FlightModePanel::phaseName_editingFinished()
|
||||
emit nameModified();
|
||||
}
|
||||
|
||||
void FlightModePanel::phaseSwitch_currentIndexChanged(int index)
|
||||
void FlightModePanel::phaseSwitchChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
||||
phase.swtch = RawSwitch(comboBox->itemData(index).toInt());
|
||||
if (lock)
|
||||
return;
|
||||
|
||||
bool ok;
|
||||
const RawSwitch rs(ui->swtch->itemData(index).toInt(&ok));
|
||||
if (ok && phase.swtch.toValue() != rs.toValue()) {
|
||||
phase.swtch = rs;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
@@ -719,14 +718,18 @@ FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralS
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
modesCount(firmware->getCapability(FlightModes))
|
||||
{
|
||||
|
||||
RawSwitchFilterItemModel * swModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::MixesContext, this);
|
||||
connect(this, &FlightModesPanel::updated, swModel, &RawSwitchFilterItemModel::update);
|
||||
|
||||
QGridLayout * gridLayout = new QGridLayout(this);
|
||||
tabWidget = new QTabWidget(this);
|
||||
for (int i=0; i<modesCount; i++) {
|
||||
FlightModePanel * tab = new FlightModePanel(tabWidget, model, i, generalSettings, firmware);
|
||||
FlightModePanel * tab = new FlightModePanel(tabWidget, model, i, generalSettings, firmware, swModel);
|
||||
tab->setProperty("index", i);
|
||||
panels << tab;
|
||||
connect(tab, SIGNAL(modified()), this, SLOT(onPhaseModified()));
|
||||
connect(tab, SIGNAL(nameModified()), this, SLOT(onPhaseNameChanged()));
|
||||
connect(tab, &FlightModePanel::modified, this, &FlightModesPanel::modified);
|
||||
connect(tab, &FlightModePanel::nameModified, this, &FlightModesPanel::onPhaseNameChanged);
|
||||
connect(this, &FlightModesPanel::updated, tab, &FlightModePanel::update);
|
||||
tabWidget->addTab(tab, getTabName(i));
|
||||
}
|
||||
gridLayout->addWidget(tabWidget, 0, 0, 1, 1);
|
||||
@@ -737,11 +740,6 @@ FlightModesPanel::~FlightModesPanel()
|
||||
{
|
||||
}
|
||||
|
||||
void FlightModesPanel::onPhaseModified()
|
||||
{
|
||||
emit modified();
|
||||
}
|
||||
|
||||
QString FlightModesPanel::getTabName(int index)
|
||||
{
|
||||
QString result = tr("Flight Mode %1").arg(index);
|
||||
@@ -764,10 +762,5 @@ void FlightModesPanel::onPhaseNameChanged()
|
||||
|
||||
void FlightModesPanel::update()
|
||||
{
|
||||
on_tabWidget_currentChanged(tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
void FlightModesPanel::on_tabWidget_currentChanged(int index)
|
||||
{
|
||||
panels[index]->update();
|
||||
emit updated();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user