[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 "helpers.h"
|
||||||
#include "customdebug.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),
|
ModelPanel(parent, model, generalSettings, firmware),
|
||||||
ui(new Ui::FlightMode),
|
ui(new Ui::FlightMode),
|
||||||
phaseIdx(phaseIdx),
|
phaseIdx(phaseIdx),
|
||||||
@@ -53,10 +53,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
|
|||||||
|
|
||||||
// Phase switch
|
// Phase switch
|
||||||
if (phaseIdx > 0) {
|
if (phaseIdx > 0) {
|
||||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::MixesContext, this);
|
ui->swtch->setModel(switchModel);
|
||||||
ui->swtch->setModel(rawSwitchItemModel);
|
connect(ui->swtch, SIGNAL(activated(int)), this, SLOT(phaseSwitchChanged(int)));
|
||||||
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
|
|
||||||
connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int)));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ui->swtch->hide();
|
ui->swtch->hide();
|
||||||
@@ -287,11 +285,8 @@ FlightModePanel::~FlightModePanel()
|
|||||||
|
|
||||||
void FlightModePanel::update()
|
void FlightModePanel::update()
|
||||||
{
|
{
|
||||||
if (rawSwitchItemModel) {
|
|
||||||
rawSwitchItemModel->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->name->setText(phase.name);
|
ui->name->setText(phase.name);
|
||||||
|
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
|
||||||
|
|
||||||
int scale = firmware->getCapability(SlowScale);
|
int scale = firmware->getCapability(SlowScale);
|
||||||
ui->fadeIn->setValue(float(phase.fadeIn)/scale);
|
ui->fadeIn->setValue(float(phase.fadeIn)/scale);
|
||||||
@@ -382,11 +377,15 @@ void FlightModePanel::phaseName_editingFinished()
|
|||||||
emit nameModified();
|
emit nameModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlightModePanel::phaseSwitch_currentIndexChanged(int index)
|
void FlightModePanel::phaseSwitchChanged(int index)
|
||||||
{
|
{
|
||||||
if (!lock) {
|
if (lock)
|
||||||
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
return;
|
||||||
phase.swtch = RawSwitch(comboBox->itemData(index).toInt());
|
|
||||||
|
bool ok;
|
||||||
|
const RawSwitch rs(ui->swtch->itemData(index).toInt(&ok));
|
||||||
|
if (ok && phase.swtch.toValue() != rs.toValue()) {
|
||||||
|
phase.swtch = rs;
|
||||||
emit modified();
|
emit modified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -719,14 +718,18 @@ FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralS
|
|||||||
ModelPanel(parent, model, generalSettings, firmware),
|
ModelPanel(parent, model, generalSettings, firmware),
|
||||||
modesCount(firmware->getCapability(FlightModes))
|
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);
|
QGridLayout * gridLayout = new QGridLayout(this);
|
||||||
tabWidget = new QTabWidget(this);
|
tabWidget = new QTabWidget(this);
|
||||||
for (int i=0; i<modesCount; i++) {
|
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);
|
tab->setProperty("index", i);
|
||||||
panels << tab;
|
connect(tab, &FlightModePanel::modified, this, &FlightModesPanel::modified);
|
||||||
connect(tab, SIGNAL(modified()), this, SLOT(onPhaseModified()));
|
connect(tab, &FlightModePanel::nameModified, this, &FlightModesPanel::onPhaseNameChanged);
|
||||||
connect(tab, SIGNAL(nameModified()), this, SLOT(onPhaseNameChanged()));
|
connect(this, &FlightModesPanel::updated, tab, &FlightModePanel::update);
|
||||||
tabWidget->addTab(tab, getTabName(i));
|
tabWidget->addTab(tab, getTabName(i));
|
||||||
}
|
}
|
||||||
gridLayout->addWidget(tabWidget, 0, 0, 1, 1);
|
gridLayout->addWidget(tabWidget, 0, 0, 1, 1);
|
||||||
@@ -737,11 +740,6 @@ FlightModesPanel::~FlightModesPanel()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlightModesPanel::onPhaseModified()
|
|
||||||
{
|
|
||||||
emit modified();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString FlightModesPanel::getTabName(int index)
|
QString FlightModesPanel::getTabName(int index)
|
||||||
{
|
{
|
||||||
QString result = tr("Flight Mode %1").arg(index);
|
QString result = tr("Flight Mode %1").arg(index);
|
||||||
@@ -764,10 +762,5 @@ void FlightModesPanel::onPhaseNameChanged()
|
|||||||
|
|
||||||
void FlightModesPanel::update()
|
void FlightModesPanel::update()
|
||||||
{
|
{
|
||||||
on_tabWidget_currentChanged(tabWidget->currentIndex());
|
emit updated();
|
||||||
}
|
|
||||||
|
|
||||||
void FlightModesPanel::on_tabWidget_currentChanged(int index)
|
|
||||||
{
|
|
||||||
panels[index]->update();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class FlightModePanel : public ModelPanel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FlightModePanel(QWidget *parent, ModelData &model, int modeIdx, GeneralSettings & generalSettings, Firmware * firmware);
|
FlightModePanel(QWidget *parent, ModelData &model, int modeIdx, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchFilterItemModel * switchModel);
|
||||||
virtual ~FlightModePanel();
|
virtual ~FlightModePanel();
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
@@ -45,7 +45,7 @@ class FlightModePanel : public ModelPanel
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void phaseName_editingFinished();
|
void phaseName_editingFinished();
|
||||||
void phaseSwitch_currentIndexChanged(int index);
|
void phaseSwitchChanged(int index);
|
||||||
void phaseFadeIn_editingFinished();
|
void phaseFadeIn_editingFinished();
|
||||||
void phaseFadeOut_editingFinished();
|
void phaseFadeOut_editingFinished();
|
||||||
void phaseTrimUse_currentIndexChanged(int index);
|
void phaseTrimUse_currentIndexChanged(int index);
|
||||||
@@ -104,18 +104,20 @@ class FlightModesPanel : public ModelPanel
|
|||||||
FlightModesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
FlightModesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||||
virtual ~FlightModesPanel();
|
virtual ~FlightModesPanel();
|
||||||
|
|
||||||
virtual void update();
|
public slots:
|
||||||
|
virtual void update() override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void updated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPhaseModified();
|
|
||||||
void onPhaseNameChanged();
|
void onPhaseNameChanged();
|
||||||
void on_tabWidget_currentChanged(int index);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString getTabName(int index);
|
||||||
|
|
||||||
int modesCount;
|
int modesCount;
|
||||||
QTabWidget *tabWidget;
|
QTabWidget *tabWidget;
|
||||||
QString getTabName(int index);
|
|
||||||
QVector<FlightModePanel *> panels;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "multiprotocols.h"
|
#include "multiprotocols.h"
|
||||||
#include "checklistdialog.h"
|
#include "checklistdialog.h"
|
||||||
|
|
||||||
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus):
|
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus, RawSwitchFilterItemModel * switchModel):
|
||||||
ModelPanel(parent, model, generalSettings, firmware),
|
ModelPanel(parent, model, generalSettings, firmware),
|
||||||
timer(timer),
|
timer(timer),
|
||||||
ui(new Ui::Timer)
|
ui(new Ui::Timer)
|
||||||
@@ -50,9 +50,9 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mode
|
// Mode
|
||||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::TimersContext, this);
|
ui->mode->setModel(switchModel);
|
||||||
ui->mode->setModel(rawSwitchItemModel);
|
|
||||||
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
||||||
|
connect(ui->mode, SIGNAL(activated(int)), this, SLOT(onModeChanged(int)));
|
||||||
|
|
||||||
if (!firmware->getCapability(PermTimers)) {
|
if (!firmware->getCapability(PermTimers)) {
|
||||||
ui->persistent->hide();
|
ui->persistent->hide();
|
||||||
@@ -92,12 +92,11 @@ TimerPanel::~TimerPanel()
|
|||||||
|
|
||||||
void TimerPanel::update()
|
void TimerPanel::update()
|
||||||
{
|
{
|
||||||
rawSwitchItemModel->update();
|
|
||||||
|
|
||||||
int hour = timer.val / 3600;
|
int hour = timer.val / 3600;
|
||||||
int min = (timer.val - (hour * 3600)) / 60;
|
int min = (timer.val - (hour * 3600)) / 60;
|
||||||
int sec = (timer.val - (hour * 3600)) % 60;
|
int sec = (timer.val - (hour * 3600)) % 60;
|
||||||
|
|
||||||
|
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
||||||
ui->value->setTime(QTime(hour, min, sec));
|
ui->value->setTime(QTime(hour, min, sec));
|
||||||
|
|
||||||
if (firmware->getCapability(PermTimers)) {
|
if (firmware->getCapability(PermTimers)) {
|
||||||
@@ -131,10 +130,15 @@ void TimerPanel::on_value_editingFinished()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerPanel::on_mode_currentIndexChanged(int index)
|
void TimerPanel::onModeChanged(int index)
|
||||||
{
|
{
|
||||||
if (!lock) {
|
if (lock)
|
||||||
timer.mode = RawSwitch(ui->mode->itemData(index).toInt());
|
return;
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
const RawSwitch rs(ui->mode->itemData(index).toInt(&ok));
|
||||||
|
if (ok && timer.mode.toValue() != rs.toValue()) {
|
||||||
|
timer.mode = rs;
|
||||||
emit modified();
|
emit modified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -937,11 +941,15 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
|||||||
}
|
}
|
||||||
|
|
||||||
QWidget * prevFocus = ui->image;
|
QWidget * prevFocus = ui->image;
|
||||||
|
RawSwitchFilterItemModel * swModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::TimersContext, this);
|
||||||
|
connect(this, &SetupPanel::updated, swModel, &RawSwitchFilterItemModel::update);
|
||||||
|
|
||||||
for (int i=0; i<CPN_MAX_TIMERS; i++) {
|
for (int i=0; i<CPN_MAX_TIMERS; i++) {
|
||||||
if (i<firmware->getCapability(Timers)) {
|
if (i<firmware->getCapability(Timers)) {
|
||||||
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus);
|
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus, swModel);
|
||||||
ui->gridLayout->addWidget(timers[i], 1+i, 1);
|
ui->gridLayout->addWidget(timers[i], 1+i, 1);
|
||||||
connect(timers[i], &TimerPanel::modified, this, &SetupPanel::modified);
|
connect(timers[i], &TimerPanel::modified, this, &SetupPanel::modified);
|
||||||
|
connect(this, &SetupPanel::updated, timers[i], &TimerPanel::update);
|
||||||
prevFocus = timers[i]->getLastFocus();
|
prevFocus = timers[i]->getLastFocus();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1219,15 +1227,13 @@ void SetupPanel::update()
|
|||||||
updatePotWarnings();
|
updatePotWarnings();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i<firmware->getCapability(Timers); i++) {
|
|
||||||
timers[i]->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0; i<CPN_MAX_MODULES+1; i++) {
|
for (int i=0; i<CPN_MAX_MODULES+1; i++) {
|
||||||
if (modules[i]) {
|
if (modules[i]) {
|
||||||
modules[i]->update();
|
modules[i]->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupPanel::updateBeepCenter()
|
void SetupPanel::updateBeepCenter()
|
||||||
|
|||||||
@@ -37,14 +37,14 @@ class TimerPanel : public ModelPanel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget *prevFocus);
|
TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget *prevFocus, RawSwitchFilterItemModel * switchModel);
|
||||||
virtual ~TimerPanel();
|
virtual ~TimerPanel();
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
QWidget * getLastFocus();
|
QWidget * getLastFocus();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_mode_currentIndexChanged(int index);
|
void onModeChanged(int index);
|
||||||
void on_value_editingFinished();
|
void on_value_editingFinished();
|
||||||
void on_minuteBeep_toggled(bool checked);
|
void on_minuteBeep_toggled(bool checked);
|
||||||
void on_name_editingFinished();
|
void on_name_editingFinished();
|
||||||
@@ -52,7 +52,6 @@ class TimerPanel : public ModelPanel
|
|||||||
private:
|
private:
|
||||||
TimerData & timer;
|
TimerData & timer;
|
||||||
Ui::Timer * ui;
|
Ui::Timer * ui;
|
||||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ModulePanel : public ModelPanel
|
class ModulePanel : public ModelPanel
|
||||||
@@ -126,6 +125,7 @@ class SetupPanel : public ModelPanel
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void extendedLimitsToggled();
|
void extendedLimitsToggled();
|
||||||
|
void updated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_name_editingFinished();
|
void on_name_editingFinished();
|
||||||
|
|||||||
Reference in New Issue
Block a user