From 3af2b090e52870a0d3fef47bf437e489a6c66951 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Sun, 3 Jun 2018 17:20:14 -0400 Subject: [PATCH] Fix remaining model editor sync issues with RawSource changes. (#5936) * [Companion] Fix RawSource updates in Custom Function selectors (part fix for #4917). * [Companion] Fix RawSource updates in HeliPanel selectors (closes #4917). --- companion/src/modeledit/customfunctions.cpp | 31 +++++++++++++++++++++++------ companion/src/modeledit/customfunctions.h | 1 + companion/src/modeledit/heli.cpp | 16 ++++++++++++--- companion/src/modeledit/heli.h | 1 + 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 47d6d94ff..79d8699f0 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -69,6 +69,9 @@ void RepeatComboBox::update() CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware): GenericPanel(parent, model, generalSettings, firmware), functions(model ? model->customFn : generalSettings.customFn), + rawSwitchItemModel(NULL), + rawSrcInputsItemModel(NULL), + rawSrcAllItemModel(NULL), mediaPlayerCurrent(-1), mediaPlayer(NULL) { @@ -76,11 +79,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, lock = true; int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); - rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? SpecialFunctionsContext : GlobalFunctionsContext); - rawSrcInputsItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_TRIMS|POPULATE_SWITCHES); - rawSrcInputsItemModel->setParent(this); - rawSrcAllItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_SWITCHES|POPULATE_GVARS|POPULATE_TRIMS|POPULATE_TELEMETRY|POPULATE_TELEMETRYEXT|POPULATE_SCRIPT_OUTPUTS); - rawSrcAllItemModel->setParent(this); + setDataModels(); if (!firmware->getCapability(VoicesAsNumbers)) { tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength)); @@ -251,6 +250,26 @@ CustomFunctionsPanel::~CustomFunctionsPanel() { } +void CustomFunctionsPanel::setDataModels() +{ + if (rawSwitchItemModel) + rawSwitchItemModel->update(); + else + rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? SpecialFunctionsContext : GlobalFunctionsContext); + + // The RawSource item models have to be reloaded on every update(). TODO: convert to filtered model like for RawSwitches + + if (rawSrcInputsItemModel) + rawSrcInputsItemModel->deleteLater(); + if (rawSrcAllItemModel) + rawSrcAllItemModel->deleteLater(); + + rawSrcInputsItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_TRIMS|POPULATE_SWITCHES); + rawSrcInputsItemModel->setParent(this); + rawSrcAllItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_SWITCHES|POPULATE_GVARS|POPULATE_TRIMS|POPULATE_TELEMETRY|POPULATE_TELEMETRYEXT|POPULATE_SCRIPT_OUTPUTS); + rawSrcAllItemModel->setParent(this); +} + void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state) { if (!lock) { @@ -589,7 +608,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) void CustomFunctionsPanel::update() { - rawSwitchItemModel->update(); + setDataModels(); lock = true; int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index 1aa8b899e..8c4c5cd99 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -60,6 +60,7 @@ class CustomFunctionsPanel : public GenericPanel CustomFunctionData * functions; private slots: + void setDataModels(); void customFunctionEdited(); void functionEdited(); void fsw_customContextMenuRequested(QPoint pos); diff --git a/companion/src/modeledit/heli.cpp b/companion/src/modeledit/heli.cpp index dfcf32c0e..bc8fd74fc 100644 --- a/companion/src/modeledit/heli.cpp +++ b/companion/src/modeledit/heli.cpp @@ -24,12 +24,12 @@ HeliPanel::HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware): ModelPanel(parent, model, generalSettings, firmware), - ui(new Ui::Heli) + ui(new Ui::Heli), + rawSourceItemModel(nullptr) { ui->setupUi(this); - rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, &model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS); - rawSourceItemModel->setParent(this); + setDataModels(); connect(ui->swashType, SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); connect(ui->swashRingVal, SIGNAL(editingFinished()), this, SLOT(edited())); @@ -66,9 +66,19 @@ HeliPanel::~HeliPanel() delete ui; } +void HeliPanel::setDataModels() +{ + if (rawSourceItemModel) + rawSourceItemModel->deleteLater(); + + rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS); + rawSourceItemModel->setParent(this); +} + void HeliPanel::update() { lock = true; + setDataModels(); ui->swashType->setCurrentIndex(model->swashRingData.type); ui->swashCollectiveSource->setModel(rawSourceItemModel); diff --git a/companion/src/modeledit/heli.h b/companion/src/modeledit/heli.h index a6abb1d98..6944fcafe 100644 --- a/companion/src/modeledit/heli.h +++ b/companion/src/modeledit/heli.h @@ -37,6 +37,7 @@ class HeliPanel : public ModelPanel void update(); private slots: + void setDataModels(); void edited(); private: -- 2.11.4.GIT