From d213034bfd56be0e2c6c6be3e0db958f176fe836 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 28 Feb 2021 05:13:34 +1100 Subject: [PATCH 01/12] Add item data models for action and reset param --- .../src/firmwares/customfunctiondata.cpp | 88 +++++++++++++-- companion/src/firmwares/customfunctiondata.h | 16 ++- companion/src/modeledit/customfunctions.cpp | 102 ++++++++---------- companion/src/modeledit/customfunctions.h | 15 +-- 4 files changed, 143 insertions(+), 78 deletions(-) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index d4942c60c..56891dc46 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -22,6 +22,7 @@ #include "eeprominterface.h" #include "radiodata.h" #include "radiodataconversionstate.h" +#include "compounditemmodels.h" void CustomFunctionData::clear() { @@ -200,7 +201,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const else if (func >= FuncAdjustGV1 && func < FuncCount) { switch (adjustMode) { case FUNC_ADJUST_GVAR_CONSTANT: - return tr("Value ") + QString("%1").arg(param); + return tr("Value") + QString(" %1").arg(param); case FUNC_ADJUST_GVAR_SOURCE: case FUNC_ADJUST_GVAR_GVAR: return RawSource(param).toString(); @@ -209,7 +210,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const QString unit; val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet(); unit = model->gvarData[func - FuncAdjustGV1].unitToString(); - return QString("Increment: %1%2").arg(val).arg(unit); + return tr("Increment") + QString(": %1%2").arg(val).arg(unit); } } return ""; @@ -217,15 +218,20 @@ QString CustomFunctionData::paramToString(const ModelData * model) const QString CustomFunctionData::repeatToString() const { - if (repeatParam == -1) { - return tr("played once, not during startup"); + return repeatToString(repeatParam); +} + +// static +QString CustomFunctionData::repeatToString(int value) const +{ + if (value == -1) { + return tr("Played once, not during startup"); } - else if (repeatParam == 0) { - return ""; + else if (value == 0) { + return tr("No repeat"); } else { - unsigned int step = 1; - return tr("repeat(%1s)").arg(step * repeatParam); + return tr("Repeat(%1s)").arg(value); } } @@ -312,3 +318,69 @@ void CustomFunctionData::convert(RadioDataConversionState & cstate) param = RawSource(param).convert(cstate.withComponentField("PARAM")).toValue(); } } + +// static +QString CustomFunctionData::harpicToString(int value) +{ + return QString("%1").arg(value); +} + +// static +QStringList CustomFunctionData::playsoundStringList() +{ + return QStringList("Beep 1" "Beep 2" "Beep 3" "Warn 1" "Warn 2" "Cheep" "Ratata" "Tick" + "Siren" "Ring" "SciFi" "Robot" "Chirp" "Tada" "Crickt" "AlmClk"); +} + +// static +QString CustomFunctionData::playsoundToString(int value) +{ + QStringList strl = playsoundStringList(); + if (value < strl.count()) + return strl.at(value); + else + return CPN_STR_UNKNOWN_ITEM; +} + +// static +AbstractStaticItemModel * CustomFunctionData::repeatItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("customfunctiondata.repeat"); + + for (int i = -1; i <= 60; i++) { + mdl->appendToItemList(repeatToString(i), i); + } + + mdl->loadItemList(); + return mdl; +} + +// static +AbstractStaticItemModel * CustomFunctionData::playSoundsItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("customfunctiondata.playsounds"); + + for (int i = 0; i <= 60; i++) { + mdl->appendToItemList(playsoundsToString(i), i); + } + + mdl->loadItemList(); + return mdl; +} + +// static +AbstractStaticItemModel * CustomFunctionData::harpicItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("customfunctiondata.harpic"); + + for (int i = 0; i <= 3; i++) { + mdl->appendToItemList(harpicToString(i), i); + } + + mdl->loadItemList(); + return mdl; +} + diff --git a/companion/src/firmwares/customfunctiondata.h b/companion/src/firmwares/customfunctiondata.h index 9e597441f..63c68e2d0 100644 --- a/companion/src/firmwares/customfunctiondata.h +++ b/companion/src/firmwares/customfunctiondata.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef CUSTOMFUNCTIONDATA_H -#define CUSTOMFUNCTIONDATA_H +#pragma once #include "boards.h" #include "constants.h" @@ -32,6 +31,7 @@ class Firmware; class ModelData; class GeneralSettings; class RadioDataConversionState; +class AbstractStaticItemModel; enum AssignFunc { FuncOverrideCH1 = 0, @@ -109,6 +109,8 @@ class CustomFunctionData { QString paramToString(const ModelData * model) const; QString repeatToString() const; QString enabledToString() const; + QString playsoundsToString() const; + QString harpicToString() const; static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value); static void populatePlaySoundParams(QStringList & qs); @@ -120,7 +122,11 @@ class CustomFunctionData { void convert(RadioDataConversionState & cstate); + static QString repeatToString(int value); + static QStringList playsoundStringList(); + static QString playsoundsToString(int value); + static QString harpicToString(int value); + static AbstractStaticItemModel * repeatItemModel(); + static AbstractStaticItemModel * playsoundsItemModel(); + static AbstractStaticItemModel * harpicItemModel(); }; - - -#endif // CUSTOMFUNCTIONDATA_H diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 5c15bd538..66f317ab2 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -30,7 +30,7 @@ RepeatComboBox::RepeatComboBox(QWidget *parent, int & repeatParam): repeatParam(repeatParam) { unsigned int step = 1; - int value = repeatParam/step; + int value = repeatParam / step; setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); @@ -59,7 +59,7 @@ void RepeatComboBox::onIndexChanged(int index) void RepeatComboBox::update() { unsigned int step = 1; - int value = repeatParam/step; + int value = repeatParam / step; if (step == 1) { value++; } @@ -77,18 +77,35 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, lock = true; fswCapability = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); - rawSwitchFilteredModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch), - model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext); - connectItemModelEvents(rawSwitchFilteredModel); + dlgFilterFactory = new FilteredItemModelFactory(); - rawSourceAllModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource)); - connectItemModelEvents(rawSourceAllModel); + funcActionsId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncAction), + model ? CustomFunctionData::AllFunctionContexts : CustomFunctionData::GlobalFunctionsContext), + "Function Actions"); + connectItemModelEvents(dlgFilterFactory->getItemModel(funcActionsId)); - rawSourceInputsModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), RawSource::InputSourceGroups); - connectItemModelEvents(rawSourceInputsModel); + funcResetParamId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncResetParam)), + "Reset Params"); + connectItemModelEvents(dlgFilterFactory->getItemModel(funcResetParamId)); - rawSourceGVarsModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), RawSource::GVarsGroup); - connectItemModelEvents(rawSourceGVarsModel); + rawSwitchId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch), + model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext), + "RawSwitch"); + connectItemModelEvents(dlgFilterFactory->getItemModel(rawSwitchId)); + + rawSourceAllId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource)), + "RawSource All"); + connectItemModelEvents(dlgFilterFactory->getItemModel(rawSourceAllId)); + + rawSourceInputsId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), + RawSource::InputSourceGroups), + "RawSource Inputs"); + connectItemModelEvents(dlgFilterFactory->getItemModel(rawSourceInputsId)); + + rawSourceGVarsId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), + RawSource::GVarsGroup), + "RawSource GVars"); + connectItemModelEvents(dlgFilterFactory->getItemModel(rawSourceGVarsId)); if (!firmware->getCapability(VoicesAsNumbers)) { tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength)); @@ -135,32 +152,24 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); connect(label, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequested(QPoint))); tableLayout->addWidget(i, 0, label); - // s1.report("label"); // The switch fswtchSwtch[i] = new QComboBox(this); - fswtchSwtch[i]->setModel(rawSwitchFilteredModel); + fswtchSwtch[i]->setModel(dlgFilterFactory->getItemModel(rawSwitchId)); fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue())); fswtchSwtch[i]->setProperty("index", i); fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); fswtchSwtch[i]->setMaxVisibleItems(10); connect(fswtchSwtch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); tableLayout->addWidget(i, 1, fswtchSwtch[i]); - // s1.report("switch"); // The function fswtchFunc[i] = new QComboBox(this); - if (!i) { - populateFuncCB(fswtchFunc[i], functions[i].func); - } - else { - fswtchFunc[i]->setModel(fswtchFunc[0]->model()); - fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func)); - } + fswtchFunc[i]->setModel(dlgFilterFactory->getItemModel(funcActionsId)); + fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func)); fswtchFunc[i]->setProperty("index", i); connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited())); tableLayout->addWidget(i, 2, fswtchFunc[i]); - // s1.report("func"); // The parameters QHBoxLayout * paramLayout = new QHBoxLayout(); @@ -250,10 +259,7 @@ CustomFunctionsPanel::~CustomFunctionsPanel() { if (mediaPlayer) stopSound(mediaPlayerCurrent); - delete rawSwitchFilteredModel; - delete rawSourceAllModel; - delete rawSourceInputsModel; - delete rawSourceGVarsModel; + delete dlgFilterFactory; } void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state) @@ -653,33 +659,6 @@ void CustomFunctionsPanel::onCustomContextMenuRequested(QPoint pos) contextMenu.exec(globalPos); } -void CustomFunctionsPanel::populateFuncCB(QComboBox *b, unsigned int value) -{ - b->clear(); - for (unsigned int i = 0; i < FuncCount; i++) { - if (((i >= FuncOverrideCH1 && i <= FuncOverrideCH32) && (!model || !firmware->getCapability(SafetyChannelCustomFunction))) || - ((i == FuncVolume || i == FuncBackgroundMusic || i == FuncBackgroundMusicPause) && !firmware->getCapability(HasVolume)) || - ((i == FuncPlayScript && !IS_HORUS_OR_TARANIS(firmware->getBoard()))) || - ((i == FuncPlayHaptic) && !firmware->getCapability(Haptic)) || - ((i == FuncPlayBoth) && !firmware->getCapability(HasBeeper)) || - ((i == FuncLogs) && !firmware->getCapability(HasSDLogs)) || - ((i == FuncSetTimer3) && firmware->getCapability(Timers) < 3) || - ((i == FuncScreenshot) && !IS_HORUS_OR_TARANIS(firmware->getBoard())) || - ((i >= FuncRangeCheckInternalModule && i <= FuncBindExternalModule) && (!model || !firmware->getCapability(DangerousFunctions))) || - ((i >= FuncAdjustGV1 && i <= FuncAdjustGVLast) && (!model || !firmware->getCapability(Gvars))) - ) { - // skipped - continue; - } - else { - b->addItem(CustomFunctionData(AssignFunc(i)).funcToString(model), i); - if (i == value) { - b->setCurrentIndex(b->count() - 1); - } - } - } -} - void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value) { b->clear(); @@ -705,25 +684,30 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi b->setCurrentIndex(value); } else if (function == FuncReset) { - CustomFunctionData::populateResetParams(model, b, value); + b->setModel(dlgFilterFactory->getItemModel(funcResetParamId)); + b->setCurrentIndex(b->findData(value)); } else if (function == FuncVolume || function == FuncBacklight) { - b->setModel(rawSourceInputsModel); + b->setModel(dlgFilterFactory->getItemModel(rawSourceInputsId)); b->setCurrentIndex(b->findData(value)); } else if (function == FuncPlayValue) { - b->setModel(rawSourceAllModel); + b->setModel(dlgFilterFactory->getItemModel(rawSourceAllId)); b->setCurrentIndex(b->findData(value)); } else if (function >= FuncAdjustGV1 && function <= FuncAdjustGVLast) { switch (adjustmode) { case 1: - b->setModel(rawSourceInputsModel); + b->setModel(dlgFilterFactory->getItemModel(rawSourceInputsId)); b->setCurrentIndex(b->findData(value)); + if (b->currentIndex() < 0) + b->setCurrentIndex(0); break; case 2: - b->setModel(rawSourceGVarsModel); + b->setModel(dlgFilterFactory->getItemModel(rawSourceGVarsId)); b->setCurrentIndex(b->findData(value)); + if (b->currentIndex() < 0) + b->setCurrentIndex(0); break; } } @@ -828,7 +812,7 @@ bool CustomFunctionsPanel::moveUpAllowed() const return selectedIndex > 0; } -void CustomFunctionsPanel::connectItemModelEvents(const FilteredItemModel * itemModel) +void CustomFunctionsPanel::connectItemModelEvents(FilteredItemModel * itemModel) { connect(itemModel, &FilteredItemModel::aboutToBeUpdated, this, &CustomFunctionsPanel::onItemModelAboutToBeUpdated); connect(itemModel, &FilteredItemModel::updateComplete, this, &CustomFunctionsPanel::onItemModelUpdateComplete); diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index e41baf672..7a1fd9c39 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -27,6 +27,7 @@ #include class CompoundItemModelFactory; +class FilteredItemModelFactory; class FilteredItemModel; class TimerEdit; @@ -87,7 +88,6 @@ class CustomFunctionsPanel : public GenericPanel void onItemModelUpdateComplete(); private: - void populateFuncCB(QComboBox *b, unsigned int value); void populateGVmodeCB(QComboBox *b, unsigned int value); void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0); bool hasClipboardData(QByteArray * data = nullptr) const; @@ -96,12 +96,15 @@ class CustomFunctionsPanel : public GenericPanel bool moveUpAllowed() const; void swapData(int idx1, int idx2); void resetCBsAndRefresh(int idx); - void connectItemModelEvents(const FilteredItemModel * itemModel); + void connectItemModelEvents(FilteredItemModel * itemModel); - FilteredItemModel * rawSwitchFilteredModel; - FilteredItemModel * rawSourceAllModel; - FilteredItemModel * rawSourceInputsModel; - FilteredItemModel * rawSourceGVarsModel; + FilteredItemModelFactory * dlgFilterFactory; + int funcActionsId; + int funcResetParamId; + int rawSwitchId; + int rawSourceAllId; + int rawSourceInputsId; + int rawSourceGVarsId; QSet tracksSet; QSet scriptsSet; From e6e41f18d7fe8a6dd52ade378749b80278b0c1e0 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 1 Mar 2021 10:00:21 +1100 Subject: [PATCH 02/12] Add static models --- .../src/firmwares/customfunctiondata.cpp | 75 +++++++++---------- companion/src/firmwares/customfunctiondata.h | 14 ++-- companion/src/modeledit/customfunctions.cpp | 58 +++++++------- companion/src/modeledit/customfunctions.h | 5 +- 4 files changed, 75 insertions(+), 77 deletions(-) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 56891dc46..428e4eead 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -24,6 +24,16 @@ #include "radiodataconversionstate.h" #include "compounditemmodels.h" +void CustomFunctionData::convert(RadioDataConversionState & cstate) +{ + cstate.setComponent(tr("CFN"), 8); + cstate.setSubComp(nameToString(cstate.subCompIdx, (cstate.toModel() ? false : true))); + swtch.convert(cstate); + if (func == FuncVolume || func == FuncBacklight || func == FuncPlayValue || (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast && adjustMode == 1)) { + param = RawSource(param).convert(cstate.withComponentField("PARAM")).toValue(); + } +} + void CustomFunctionData::clear() { memset(reinterpret_cast(this), 0, sizeof(CustomFunctionData)); @@ -95,9 +105,9 @@ QString CustomFunctionData::funcToString(const ModelData * model) const else if (func == FuncSetFailsafe) return tr("Set Failsafe"); else if (func == FuncRangeCheckInternalModule) - return tr("RangeCheck Int. Module"); + return tr("Range Check Int. Module"); else if (func == FuncRangeCheckExternalModule) - return tr("RangeCheck Ext. Module"); + return tr("Range Check Ext. Module"); else if (func == FuncBindInternalModule) return tr("Bind Int. Module"); else if (func == FuncBindExternalModule) @@ -143,17 +153,6 @@ void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox b->setCurrentIndex(b->findData(value)); } -void CustomFunctionData::populatePlaySoundParams(QStringList & qs) -{ - qs <<"Beep 1" << "Beep 2" << "Beep 3" << "Warn1" << "Warn2" << "Cheep" << "Ratata" << "Tick" << "Siren" << "Ring" ; - qs << "SciFi" << "Robot" << "Chirp" << "Tada" << "Crickt" << "AlmClk" ; -} - -void CustomFunctionData::populateHapticParams(QStringList & qs) -{ - qs << "0" << "1" << "2" << "3"; -} - QString CustomFunctionData::paramToString(const ModelData * model) const { QStringList qs; @@ -164,18 +163,10 @@ QString CustomFunctionData::paramToString(const ModelData * model) const return QString("%1").arg(param / 10.0) + tr("s"); } else if (func == FuncPlaySound) { - CustomFunctionData::populatePlaySoundParams(qs); - if (param >= 0 && param < (int)qs.count()) - return qs.at(param); - else - return tr("Inconsistent parameter"); + return playSoundToString(param); } else if (func == FuncPlayHaptic) { - CustomFunctionData::populateHapticParams(qs); - if (param >= 0 && param < (int)qs.count()) - return qs.at(param); - else - return tr("Inconsistent parameter"); + return harpicToString(param); } else if (func == FuncReset) { QComboBox cb; @@ -184,7 +175,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const if (pos >= 0) return cb.itemText(pos); else - return tr("Inconsistent parameter"); + return QString(CPN_STR_UNKNOWN_ITEM); } else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) { RawSource item(param); @@ -222,7 +213,7 @@ QString CustomFunctionData::repeatToString() const } // static -QString CustomFunctionData::repeatToString(int value) const +QString CustomFunctionData::repeatToString(int value) { if (value == -1) { return tr("Played once, not during startup"); @@ -309,14 +300,9 @@ bool CustomFunctionData::isResetParamAvailable(const ModelData * model, int inde return false; } -void CustomFunctionData::convert(RadioDataConversionState & cstate) +QString CustomFunctionData::harpicToString() const { - cstate.setComponent(tr("CFN"), 8); - cstate.setSubComp(nameToString(cstate.subCompIdx, (cstate.toModel() ? false : true))); - swtch.convert(cstate); - if (func == FuncVolume || func == FuncBacklight || func == FuncPlayValue || (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast && adjustMode == 1)) { - param = RawSource(param).convert(cstate.withComponentField("PARAM")).toValue(); - } + return harpicToString(param); } // static @@ -326,20 +312,27 @@ QString CustomFunctionData::harpicToString(int value) } // static -QStringList CustomFunctionData::playsoundStringList() +QStringList CustomFunctionData::playSoundStringList() { - return QStringList("Beep 1" "Beep 2" "Beep 3" "Warn 1" "Warn 2" "Cheep" "Ratata" "Tick" - "Siren" "Ring" "SciFi" "Robot" "Chirp" "Tada" "Crickt" "AlmClk"); + QStringList strl; + strl << tr("Beep 1") << tr("Beep 2") << tr("Beep 3") << tr("Warn 1") << tr("Warn 2") << tr("Cheep") << tr("Ratata") << tr("Tick") + << tr("Siren") << tr("Ring") << tr("Sci Fi") << tr("Robot") << tr("Chirp") << tr("Tada") << tr("Cricket") << tr("Alarm Clock"); + return strl; +} + +QString CustomFunctionData::playSoundToString() const +{ + return playSoundToString(param); } // static -QString CustomFunctionData::playsoundToString(int value) +QString CustomFunctionData::playSoundToString(int value) { - QStringList strl = playsoundStringList(); + QStringList strl = playSoundStringList(); if (value < strl.count()) return strl.at(value); else - return CPN_STR_UNKNOWN_ITEM; + return QString(CPN_STR_UNKNOWN_ITEM); } // static @@ -357,13 +350,13 @@ AbstractStaticItemModel * CustomFunctionData::repeatItemModel() } // static -AbstractStaticItemModel * CustomFunctionData::playSoundsItemModel() +AbstractStaticItemModel * CustomFunctionData::playSoundItemModel() { AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); mdl->setName("customfunctiondata.playsounds"); - for (int i = 0; i <= 60; i++) { - mdl->appendToItemList(playsoundsToString(i), i); + for (int i = 0; i < playSoundStringList().count(); i++) { + mdl->appendToItemList(playSoundToString(i), i); } mdl->loadItemList(); diff --git a/companion/src/firmwares/customfunctiondata.h b/companion/src/firmwares/customfunctiondata.h index 63c68e2d0..2301e6567 100644 --- a/companion/src/firmwares/customfunctiondata.h +++ b/companion/src/firmwares/customfunctiondata.h @@ -102,6 +102,8 @@ class CustomFunctionData { unsigned int adjustMode; int repeatParam; + void convert(RadioDataConversionState & cstate); + void clear(); bool isEmpty() const; QString nameToString(int index, bool globalContext = false) const; @@ -109,24 +111,20 @@ class CustomFunctionData { QString paramToString(const ModelData * model) const; QString repeatToString() const; QString enabledToString() const; - QString playsoundsToString() const; + QString playSoundToString() const; QString harpicToString() const; static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value); - static void populatePlaySoundParams(QStringList & qs); - static void populateHapticParams(QStringList & qs); static bool isFuncAvailable(int index); static int funcContext(int index); static int resetParamCount(const ModelData * model); static bool isResetParamAvailable(const ModelData * model, int index); - void convert(RadioDataConversionState & cstate); - static QString repeatToString(int value); - static QStringList playsoundStringList(); - static QString playsoundsToString(int value); + static QStringList playSoundStringList(); + static QString playSoundToString(int value); static QString harpicToString(int value); static AbstractStaticItemModel * repeatItemModel(); - static AbstractStaticItemModel * playsoundsItemModel(); + static AbstractStaticItemModel * playSoundItemModel(); static AbstractStaticItemModel * harpicItemModel(); }; diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 66f317ab2..f2f2e07f1 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -19,6 +19,7 @@ */ #include "customfunctions.h" +#include "compounditemmodels.h" #include "filtereditemmodels.h" #include "helpers.h" #include "appdata.h" @@ -77,35 +78,39 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, lock = true; fswCapability = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); - dlgFilterFactory = new FilteredItemModelFactory(); + tabModelFactory = new CompoundItemModelFactory(&generalSettings, model); + playSoundId = tabModelFactory->registerItemModel(CustomFunctionData::playSoundItemModel()); + harpicId = tabModelFactory->registerItemModel(CustomFunctionData::harpicItemModel()); - funcActionsId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncAction), + tabFilterFactory = new FilteredItemModelFactory(); + + funcActionsId = tabFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncAction), model ? CustomFunctionData::AllFunctionContexts : CustomFunctionData::GlobalFunctionsContext), "Function Actions"); - connectItemModelEvents(dlgFilterFactory->getItemModel(funcActionsId)); + connectItemModelEvents(tabFilterFactory->getItemModel(funcActionsId)); - funcResetParamId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncResetParam)), + funcResetParamId = tabFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncResetParam)), "Reset Params"); - connectItemModelEvents(dlgFilterFactory->getItemModel(funcResetParamId)); + connectItemModelEvents(tabFilterFactory->getItemModel(funcResetParamId)); - rawSwitchId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch), + rawSwitchId = tabFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch), model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext), "RawSwitch"); - connectItemModelEvents(dlgFilterFactory->getItemModel(rawSwitchId)); + connectItemModelEvents(tabFilterFactory->getItemModel(rawSwitchId)); - rawSourceAllId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource)), + rawSourceAllId = tabFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource)), "RawSource All"); - connectItemModelEvents(dlgFilterFactory->getItemModel(rawSourceAllId)); + connectItemModelEvents(tabFilterFactory->getItemModel(rawSourceAllId)); - rawSourceInputsId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), + rawSourceInputsId = tabFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), RawSource::InputSourceGroups), "RawSource Inputs"); - connectItemModelEvents(dlgFilterFactory->getItemModel(rawSourceInputsId)); + connectItemModelEvents(tabFilterFactory->getItemModel(rawSourceInputsId)); - rawSourceGVarsId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), + rawSourceGVarsId = tabFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), RawSource::GVarsGroup), "RawSource GVars"); - connectItemModelEvents(dlgFilterFactory->getItemModel(rawSourceGVarsId)); + connectItemModelEvents(tabFilterFactory->getItemModel(rawSourceGVarsId)); if (!firmware->getCapability(VoicesAsNumbers)) { tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength)); @@ -155,7 +160,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, // The switch fswtchSwtch[i] = new QComboBox(this); - fswtchSwtch[i]->setModel(dlgFilterFactory->getItemModel(rawSwitchId)); + fswtchSwtch[i]->setModel(tabFilterFactory->getItemModel(rawSwitchId)); fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue())); fswtchSwtch[i]->setProperty("index", i); fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); @@ -165,7 +170,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, // The function fswtchFunc[i] = new QComboBox(this); - fswtchFunc[i]->setModel(dlgFilterFactory->getItemModel(funcActionsId)); + fswtchFunc[i]->setModel(tabFilterFactory->getItemModel(funcActionsId)); fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func)); fswtchFunc[i]->setProperty("index", i); connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited())); @@ -259,7 +264,8 @@ CustomFunctionsPanel::~CustomFunctionsPanel() { if (mediaPlayer) stopSound(mediaPlayerCurrent); - delete dlgFilterFactory; + delete tabModelFactory; + delete tabFilterFactory; } void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state) @@ -674,37 +680,35 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi QStringList qs; b->setModel(new QStandardItemModel(b)); // clear combo box but not any shared item model if (function == FuncPlaySound) { - CustomFunctionData::populatePlaySoundParams(qs); - b->addItems(qs); - b->setCurrentIndex(value); + b->setModel(tabModelFactory->getItemModel(playSoundId)); + b->setCurrentIndex(b->findData(value)); } else if (function == FuncPlayHaptic) { - CustomFunctionData::populateHapticParams(qs); - b->addItems(qs); - b->setCurrentIndex(value); + b->setModel(tabModelFactory->getItemModel(harpicId)); + b->setCurrentIndex(b->findData(value)); } else if (function == FuncReset) { - b->setModel(dlgFilterFactory->getItemModel(funcResetParamId)); + b->setModel(tabFilterFactory->getItemModel(funcResetParamId)); b->setCurrentIndex(b->findData(value)); } else if (function == FuncVolume || function == FuncBacklight) { - b->setModel(dlgFilterFactory->getItemModel(rawSourceInputsId)); + b->setModel(tabFilterFactory->getItemModel(rawSourceInputsId)); b->setCurrentIndex(b->findData(value)); } else if (function == FuncPlayValue) { - b->setModel(dlgFilterFactory->getItemModel(rawSourceAllId)); + b->setModel(tabFilterFactory->getItemModel(rawSourceAllId)); b->setCurrentIndex(b->findData(value)); } else if (function >= FuncAdjustGV1 && function <= FuncAdjustGVLast) { switch (adjustmode) { case 1: - b->setModel(dlgFilterFactory->getItemModel(rawSourceInputsId)); + b->setModel(tabFilterFactory->getItemModel(rawSourceInputsId)); b->setCurrentIndex(b->findData(value)); if (b->currentIndex() < 0) b->setCurrentIndex(0); break; case 2: - b->setModel(dlgFilterFactory->getItemModel(rawSourceGVarsId)); + b->setModel(tabFilterFactory->getItemModel(rawSourceGVarsId)); b->setCurrentIndex(b->findData(value)); if (b->currentIndex() < 0) b->setCurrentIndex(0); diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index 7a1fd9c39..e74ce0d66 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -98,13 +98,16 @@ class CustomFunctionsPanel : public GenericPanel void resetCBsAndRefresh(int idx); void connectItemModelEvents(FilteredItemModel * itemModel); - FilteredItemModelFactory * dlgFilterFactory; + CompoundItemModelFactory * tabModelFactory; + FilteredItemModelFactory * tabFilterFactory; int funcActionsId; int funcResetParamId; int rawSwitchId; int rawSourceAllId; int rawSourceInputsId; int rawSourceGVarsId; + int playSoundId; + int harpicId; QSet tracksSet; QSet scriptsSet; From cb4ee1b30dd76d165f6f8ae9b34452216903dc60 Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 2 Mar 2021 22:23:31 +1100 Subject: [PATCH 03/12] Revert RepeatComboBox to standard ComboBox and add item model --- .../src/firmwares/customfunctiondata.cpp | 2 +- companion/src/modeledit/customfunctions.cpp | 62 +++---------------- companion/src/modeledit/customfunctions.h | 32 ++-------- 3 files changed, 16 insertions(+), 80 deletions(-) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 428e4eead..84e49ceb3 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -222,7 +222,7 @@ QString CustomFunctionData::repeatToString(int value) return tr("No repeat"); } else { - return tr("Repeat(%1s)").arg(value); + return tr("Repeat %1s").arg(value); } } diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index f2f2e07f1..6be75f28f 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -19,54 +19,11 @@ */ #include "customfunctions.h" -#include "compounditemmodels.h" -#include "filtereditemmodels.h" #include "helpers.h" #include "appdata.h" #include -RepeatComboBox::RepeatComboBox(QWidget *parent, int & repeatParam): - QComboBox(parent), - repeatParam(repeatParam) -{ - unsigned int step = 1; - int value = repeatParam / step; - - setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); - - if (step == 1) { - addItem(tr("Played once, not during startup"), -1); - value++; - } - - addItem(tr("No repeat"), 0); - - for (unsigned int i = step; i <= 60; i += step) { - addItem(tr("%1s").arg(i), i); - } - - setCurrentIndex(value); - - connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int))); -} - -void RepeatComboBox::onIndexChanged(int index) -{ - repeatParam = itemData(index).toInt(); - emit modified(); -} - -void RepeatComboBox::update() -{ - unsigned int step = 1; - int value = repeatParam / step; - if (step == 1) { - value++; - } - setCurrentIndex(value); -} - CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware, CompoundItemModelFactory * sharedItemModels): GenericPanel(parent, model, generalSettings, firmware), @@ -81,6 +38,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, tabModelFactory = new CompoundItemModelFactory(&generalSettings, model); playSoundId = tabModelFactory->registerItemModel(CustomFunctionData::playSoundItemModel()); harpicId = tabModelFactory->registerItemModel(CustomFunctionData::harpicItemModel()); + repeatId = tabModelFactory->registerItemModel(CustomFunctionData::repeatItemModel()); tabFilterFactory = new FilteredItemModelFactory(); @@ -239,9 +197,12 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, QHBoxLayout * repeatLayout = new QHBoxLayout(); tableLayout->addLayout(i, 4, repeatLayout); - fswtchRepeat[i] = new RepeatComboBox(this, functions[i].repeatParam); + fswtchRepeat[i] = new QComboBox(this); + fswtchRepeat[i]->setProperty("index", i); + fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatId)); + fswtchRepeat[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); repeatLayout->addWidget(fswtchRepeat[i], i + 1); - connect(fswtchRepeat[i], SIGNAL(modified()), this, SLOT(onRepeatModified())); + connect(fswtchRepeat[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); fswtchEnable[i] = new QCheckBox(this); fswtchEnable[i]->setProperty("index", i); @@ -375,11 +336,6 @@ void CustomFunctionsPanel::functionEdited() } } -void CustomFunctionsPanel::onRepeatModified() -{ - emit modified(); -} - void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) { CustomFunctionData & cfn = functions[i]; @@ -480,8 +436,10 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) } else if (func == FuncPlaySound || func == FuncPlayHaptic || func == FuncPlayValue || func == FuncPlayPrompt || func == FuncPlayBoth || func == FuncBackgroundMusic) { if (func != FuncBackgroundMusic) { + if (modified) + cfn.repeatParam = fswtchRepeat[i]->currentData().toInt(); widgetsMask |= CUSTOM_FUNCTION_REPEAT; - fswtchRepeat[i]->update(); + fswtchRepeat[i]->setCurrentIndex(fswtchRepeat[i]->findData(cfn.repeatParam)); } if (func == FuncPlayValue) { if (modified) @@ -505,7 +463,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) if (modified) { if (fswtchParamGV[i]->isChecked()) { fswtchParam[i]->setMinimum(1); - cfn.param = std::min(fswtchParam[i]->value(),5.0)+(fswtchParamGV[i]->isChecked() ? 250 : 0); + cfn.param = std::min(fswtchParam[i]->value(), 5.0) + (fswtchParamGV[i]->isChecked() ? 250 : 0); } else { cfn.param = fswtchParam[i]->value(); diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index e74ce0d66..1085e78b1 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -18,39 +18,19 @@ * GNU General Public License for more details. */ -#ifndef _CUSTOMFUNCTIONS_H_ -#define _CUSTOMFUNCTIONS_H_ +#pragma once #include "modeledit.h" #include "eeprominterface.h" +#include "compounditemmodels.h" +#include "filtereditemmodels.h" #include -class CompoundItemModelFactory; -class FilteredItemModelFactory; -class FilteredItemModel; class TimerEdit; constexpr char MIMETYPE_CUSTOM_FUNCTION[] = "application/x-companion-custom-function"; -class RepeatComboBox: public QComboBox -{ - Q_OBJECT - - public: - RepeatComboBox(QWidget * parent, int & repeatParam); - void update(); - - signals: - void modified(); - - private slots: - void onIndexChanged(int); - - protected: - int & repeatParam; -}; - class CustomFunctionsPanel : public GenericPanel { Q_OBJECT @@ -69,7 +49,6 @@ class CustomFunctionsPanel : public GenericPanel void functionEdited(); void onCustomContextMenuRequested(QPoint pos); void refreshCustomFunction(int index, bool modified=false); - void onRepeatModified(); bool playSound(int index); void stopSound(int index); void toggleSound(bool play); @@ -108,6 +87,7 @@ class CustomFunctionsPanel : public GenericPanel int rawSourceGVarsId; int playSoundId; int harpicId; + int repeatId; QSet tracksSet; QSet scriptsSet; @@ -121,7 +101,7 @@ class CustomFunctionsPanel : public GenericPanel QComboBox * fswtchParamT[CPN_MAX_SPECIAL_FUNCTIONS]; QComboBox * fswtchParamArmT[CPN_MAX_SPECIAL_FUNCTIONS]; QCheckBox * fswtchEnable[CPN_MAX_SPECIAL_FUNCTIONS]; - RepeatComboBox * fswtchRepeat[CPN_MAX_SPECIAL_FUNCTIONS]; + QComboBox * fswtchRepeat[CPN_MAX_SPECIAL_FUNCTIONS]; QComboBox * fswtchGVmode[CPN_MAX_SPECIAL_FUNCTIONS]; QSlider * fswtchBLcolor[CPN_MAX_SPECIAL_FUNCTIONS]; QMediaPlayer * mediaPlayer; @@ -130,5 +110,3 @@ class CustomFunctionsPanel : public GenericPanel int fswCapability; int modelsUpdateCnt; }; - -#endif // _CUSTOMFUNCTIONS_H_ From f0d4c88f03551282a41df432467d478b3bbf57e6 Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 2 Mar 2021 23:17:21 +1100 Subject: [PATCH 04/12] Gvar adjust mode to item model --- .../src/firmwares/customfunctiondata.cpp | 45 ++++++++++++++++--- companion/src/firmwares/customfunctiondata.h | 8 +++- companion/src/modeledit/customfunctions.cpp | 17 ++----- companion/src/modeledit/customfunctions.h | 2 +- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 84e49ceb3..2cd9d27a2 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -314,10 +314,8 @@ QString CustomFunctionData::harpicToString(int value) // static QStringList CustomFunctionData::playSoundStringList() { - QStringList strl; - strl << tr("Beep 1") << tr("Beep 2") << tr("Beep 3") << tr("Warn 1") << tr("Warn 2") << tr("Cheep") << tr("Ratata") << tr("Tick") - << tr("Siren") << tr("Ring") << tr("Sci Fi") << tr("Robot") << tr("Chirp") << tr("Tada") << tr("Cricket") << tr("Alarm Clock"); - return strl; + return QStringList({ tr("Beep 1"), tr("Beep 2"), tr("Beep 3"), tr("Warn 1"), tr("Warn 2"), tr("Cheep"), tr("Ratata"), tr("Tick"), + tr("Siren"), tr("Ring"), tr("Sci Fi"), tr("Robot"), tr("Chirp"), tr("Tada"), tr("Cricket"), tr("Alarm Clock") }); } QString CustomFunctionData::playSoundToString() const @@ -328,13 +326,35 @@ QString CustomFunctionData::playSoundToString() const // static QString CustomFunctionData::playSoundToString(int value) { - QStringList strl = playSoundStringList(); + const QStringList strl = playSoundStringList(); if (value < strl.count()) return strl.at(value); else return QString(CPN_STR_UNKNOWN_ITEM); } +QString CustomFunctionData::gvarAdjustModeToString() const +{ + return gvarAdjustModeToString(adjustMode); +} + +// static +QString CustomFunctionData::gvarAdjustModeToString(int value) +{ + switch (value) { + case FUNC_ADJUST_GVAR_CONSTANT: + return tr("Value"); + case FUNC_ADJUST_GVAR_SOURCE: + return tr("Source"); + case FUNC_ADJUST_GVAR_GVAR: + return tr("GVAR"); + case FUNC_ADJUST_GVAR_INCDEC: + return tr("Increment"); + default: + return QString(CPN_STR_UNKNOWN_ITEM); + } +} + // static AbstractStaticItemModel * CustomFunctionData::repeatItemModel() { @@ -353,7 +373,7 @@ AbstractStaticItemModel * CustomFunctionData::repeatItemModel() AbstractStaticItemModel * CustomFunctionData::playSoundItemModel() { AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); - mdl->setName("customfunctiondata.playsounds"); + mdl->setName("customfunctiondata.playsound"); for (int i = 0; i < playSoundStringList().count(); i++) { mdl->appendToItemList(playSoundToString(i), i); @@ -377,3 +397,16 @@ AbstractStaticItemModel * CustomFunctionData::harpicItemModel() return mdl; } +// static +AbstractStaticItemModel * CustomFunctionData::gvarAdjustModeItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("customfunctiondata.gvaradjustmode"); + + for (int i = 0; i < FUNC_ADJUST_GVAR_COUNT; i++) { + mdl->appendToItemList(gvarAdjustModeToString(i), i); + } + + mdl->loadItemList(); + return mdl; +} diff --git a/companion/src/firmwares/customfunctiondata.h b/companion/src/firmwares/customfunctiondata.h index 2301e6567..949ac9ee5 100644 --- a/companion/src/firmwares/customfunctiondata.h +++ b/companion/src/firmwares/customfunctiondata.h @@ -78,7 +78,8 @@ enum GVarAdjustModes FUNC_ADJUST_GVAR_CONSTANT, FUNC_ADJUST_GVAR_SOURCE, FUNC_ADJUST_GVAR_GVAR, - FUNC_ADJUST_GVAR_INCDEC + FUNC_ADJUST_GVAR_INCDEC, + FUNC_ADJUST_GVAR_COUNT }; class CustomFunctionData { @@ -113,18 +114,21 @@ class CustomFunctionData { QString enabledToString() const; QString playSoundToString() const; QString harpicToString() const; + QString gvarAdjustModeToString() const; static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value); static bool isFuncAvailable(int index); static int funcContext(int index); static int resetParamCount(const ModelData * model); static bool isResetParamAvailable(const ModelData * model, int index); - static QString repeatToString(int value); static QStringList playSoundStringList(); static QString playSoundToString(int value); static QString harpicToString(int value); + static QStringList gvarAdjustModeStringList(); + static QString gvarAdjustModeToString(int value); static AbstractStaticItemModel * repeatItemModel(); static AbstractStaticItemModel * playSoundItemModel(); static AbstractStaticItemModel * harpicItemModel(); + static AbstractStaticItemModel * gvarAdjustModeItemModel(); }; diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 6be75f28f..05eefb96b 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -39,6 +39,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, playSoundId = tabModelFactory->registerItemModel(CustomFunctionData::playSoundItemModel()); harpicId = tabModelFactory->registerItemModel(CustomFunctionData::harpicItemModel()); repeatId = tabModelFactory->registerItemModel(CustomFunctionData::repeatItemModel()); + gvarAdjustModeId = tabModelFactory->registerItemModel(CustomFunctionData::gvarAdjustModeItemModel()); tabFilterFactory = new FilteredItemModelFactory(); @@ -140,7 +141,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, fswtchGVmode[i] = new QComboBox(this); fswtchGVmode[i]->setProperty("index", i); - populateGVmodeCB(fswtchGVmode[i], functions[i].adjustMode); + fswtchGVmode[i]->setModel(tabModelFactory->getItemModel(gvarAdjustModeId)); fswtchGVmode[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); connect(fswtchGVmode[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); paramLayout->addWidget(fswtchGVmode[i]); @@ -382,8 +383,8 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) else if (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) { int gvidx = func - FuncAdjustGV1; if (modified) - cfn.adjustMode = fswtchGVmode[i]->currentIndex(); - fswtchGVmode[i]->setCurrentIndex(cfn.adjustMode); + cfn.adjustMode = fswtchGVmode[i]->currentData().toInt(); + fswtchGVmode[i]->setCurrentIndex(fswtchGVmode[i]->findData(cfn.adjustMode)); widgetsMask |= CUSTOM_FUNCTION_GV_MODE | CUSTOM_FUNCTION_ENABLE; if (cfn.adjustMode == FUNC_ADJUST_GVAR_CONSTANT || cfn.adjustMode == FUNC_ADJUST_GVAR_INCDEC) { if (modified) @@ -623,16 +624,6 @@ void CustomFunctionsPanel::onCustomContextMenuRequested(QPoint pos) contextMenu.exec(globalPos); } -void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value) -{ - b->clear(); - b->addItem(tr("Value")); - b->addItem(tr("Source")); - b->addItem(tr("GVAR")); - b->addItem(tr("Increment")); - b->setCurrentIndex(value); -} - void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode) { QStringList qs; diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index 1085e78b1..6d1668114 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -67,7 +67,6 @@ class CustomFunctionsPanel : public GenericPanel void onItemModelUpdateComplete(); private: - void populateGVmodeCB(QComboBox *b, unsigned int value); void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0); bool hasClipboardData(QByteArray * data = nullptr) const; bool insertAllowed() const; @@ -88,6 +87,7 @@ class CustomFunctionsPanel : public GenericPanel int playSoundId; int harpicId; int repeatId; + int gvarAdjustModeId; QSet tracksSet; QSet scriptsSet; From 263d2854a74c804fa98fb16f176fab91c28757c3 Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 3 Mar 2021 07:24:43 +1100 Subject: [PATCH 05/12] Housekeeping --- companion/src/firmwares/customfunctiondata.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 2cd9d27a2..8d2d4e87c 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -178,8 +178,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const return QString(CPN_STR_UNKNOWN_ITEM); } else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) { - RawSource item(param); - return item.toString(model); + return RawSource(param).toString(model); } else if (func == FuncPlayPrompt || func == FuncPlayBoth) { if ( getCurrentFirmware()->getCapability(VoicesAsNumbers)) { @@ -192,16 +191,14 @@ QString CustomFunctionData::paramToString(const ModelData * model) const else if (func >= FuncAdjustGV1 && func < FuncCount) { switch (adjustMode) { case FUNC_ADJUST_GVAR_CONSTANT: - return tr("Value") + QString(" %1").arg(param); + return gvarAdjustModeToString(adjustMode) + QString(" %1").arg(param); case FUNC_ADJUST_GVAR_SOURCE: case FUNC_ADJUST_GVAR_GVAR: return RawSource(param).toString(); case FUNC_ADJUST_GVAR_INCDEC: - float val; - QString unit; - val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet(); - unit = model->gvarData[func - FuncAdjustGV1].unitToString(); - return tr("Increment") + QString(": %1%2").arg(val).arg(unit); + const float val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet(); + const QString unit = model->gvarData[func - FuncAdjustGV1].unitToString(); + return gvarAdjustModeToString(adjustMode) + QString(": %1%2").arg(val).arg(unit); } } return ""; @@ -347,7 +344,7 @@ QString CustomFunctionData::gvarAdjustModeToString(int value) case FUNC_ADJUST_GVAR_SOURCE: return tr("Source"); case FUNC_ADJUST_GVAR_GVAR: - return tr("GVAR"); + return tr("Global Variable"); case FUNC_ADJUST_GVAR_INCDEC: return tr("Increment"); default: From 6feb5a3ca985ed35326d4d818e4c9c9d3c8e5f2e Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 3 Mar 2021 08:51:54 +1100 Subject: [PATCH 06/12] Refactor reset param functions --- .../src/datamodels/compounditemmodels.cpp | 4 +- .../src/firmwares/customfunctiondata.cpp | 94 +++++++++---------- companion/src/firmwares/customfunctiondata.h | 4 +- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/companion/src/datamodels/compounditemmodels.cpp b/companion/src/datamodels/compounditemmodels.cpp index 039e90244..f47741341 100644 --- a/companion/src/datamodels/compounditemmodels.cpp +++ b/companion/src/datamodels/compounditemmodels.cpp @@ -447,7 +447,7 @@ CustomFuncResetParamItemModel::CustomFuncResetParamItemModel(const GeneralSettin setId(IMID_CustomFuncResetParam); setUpdateMask(IMUE_TeleSensors); - for (int i = 0; i < CustomFunctionData::resetParamCount(modelData); i++) { + for (int i = 0; i < CustomFunctionData::resetParamCount(); i++) { QStandardItem * modelItem = new QStandardItem(); modelItem->setData(i, IMDR_Id); setDynamicItemData(modelItem, i); @@ -459,7 +459,7 @@ void CustomFuncResetParamItemModel::setDynamicItemData(QStandardItem * item, con { CustomFunctionData cfd = CustomFunctionData(AssignFunc::FuncReset); cfd.param = value; - item->setText(cfd.paramToString(modelData)); + item->setText(CustomFunctionData::resetToString(modelData)); item->setData(CustomFunctionData::isResetParamAvailable(modelData, value), IMDR_Available); } diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 8d2d4e87c..aa2f64bbd 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -117,42 +117,6 @@ QString CustomFunctionData::funcToString(const ModelData * model) const } } -void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox * b, unsigned int value = 0) -{ - int val = 0; - Firmware * firmware = Firmware::getCurrentVariant(); - - for (int i = 0; i < CPN_MAX_TIMERS; i++, val++) { - if (i < firmware->getCapability(Timers)) { - RawSource item = RawSource(SOURCE_TYPE_SPECIAL, i + SOURCE_TYPE_SPECIAL_TIMER1_IDX); - b->addItem(item.toString(model), val); - } - } - - b->addItem(tr("Flight"), val++); - b->addItem(tr("Telemetry"), val++); - - int reCount = firmware->getCapability(RotaryEncoders); - if (reCount == 1) { - b->addItem(tr("Rotary Encoder"), val++); - } - else if (reCount == 2) { - b->addItem(tr("REa"), val++); - b->addItem(tr("REb"), val++); - } - - if (model) { - for (int i = 0; i < firmware->getCapability(Sensors); ++i) { - if (model->sensorData[i].isAvailable()) { - RawSource item = RawSource(SOURCE_TYPE_TELEMETRY, 3 * i); - b->addItem(item.toString(model), val + i); - } - } - } - - b->setCurrentIndex(b->findData(value)); -} - QString CustomFunctionData::paramToString(const ModelData * model) const { QStringList qs; @@ -169,13 +133,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const return harpicToString(param); } else if (func == FuncReset) { - QComboBox cb; - CustomFunctionData::populateResetParams(model, &cb); - int pos = cb.findData(param); - if (pos >= 0) - return cb.itemText(pos); - else - return QString(CPN_STR_UNKNOWN_ITEM); + return resetToString(model, param); } else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) { return RawSource(param).toString(model); @@ -270,12 +228,54 @@ int CustomFunctionData::funcContext(int index) return ret; } + // static -int CustomFunctionData::resetParamCount(const ModelData * model) +QString CustomFunctionData::resetToString(const ModelData * model, int value) { - QComboBox cb; - CustomFunctionData::populateResetParams(model, &cb); - return cb.count(); + Firmware * firmware = getCurrentFirmware(); + int step = CPN_MAX_TIMERS; + + if (value < step) { + if (value < firmware->getCapability(Timers)) + return RawSource(SOURCE_TYPE_SPECIAL, value + SOURCE_TYPE_SPECIAL_TIMER1_IDX).toString(model); + else + return QString(CPN_STR_UNKNOWN_ITEM); + } + + if (value < ++step) + return tr("Flight"); + + if (value < ++step) + return tr("Telemetry"); + + int reCount = firmware->getCapability(RotaryEncoders); + + if (reCount > 0 && value < step + reCount) { + if (reCount == 1 && value < step + 1) + return tr("Rotary Encoder"); + else if (reCount == 2) { + if (value < step + 1) + return tr("REa"); + else + return tr("REb"); + } + else + return QString(CPN_STR_UNKNOWN_ITEM); + } + step += reCount; + + if (value < step + firmware->getCapability(Sensors)) + return RawSource(SOURCE_TYPE_TELEMETRY, 3 * (value - step)).toString(model); + + return QString(CPN_STR_UNKNOWN_ITEM); +} + +// static +int CustomFunctionData::resetParamCount() +{ + Firmware * firmware = getCurrentFirmware(); + + return CPN_MAX_TIMERS + 2 + firmware->getCapability(RotaryEncoders) + firmware->getCapability(Sensors); } // static diff --git a/companion/src/firmwares/customfunctiondata.h b/companion/src/firmwares/customfunctiondata.h index 949ac9ee5..3240256f3 100644 --- a/companion/src/firmwares/customfunctiondata.h +++ b/companion/src/firmwares/customfunctiondata.h @@ -116,10 +116,10 @@ class CustomFunctionData { QString harpicToString() const; QString gvarAdjustModeToString() const; - static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value); static bool isFuncAvailable(int index); static int funcContext(int index); - static int resetParamCount(const ModelData * model); + static QString resetToString(const ModelData * model, int value); + static int resetParamCount(); static bool isResetParamAvailable(const ModelData * model, int index); static QString repeatToString(int value); static QStringList playSoundStringList(); From c78a784236d3a5cb0b90ed0cb8ce9710bebd9028 Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 3 Mar 2021 23:29:23 +1100 Subject: [PATCH 07/12] Compile and other tweaks --- companion/src/datamodels/compounditemmodels.cpp | 4 +--- companion/src/datamodels/compounditemmodels.h | 5 +---- companion/src/firmwares/customfunctiondata.cpp | 5 +++-- companion/src/modeledit/customfunctions.cpp | 13 ++++++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/companion/src/datamodels/compounditemmodels.cpp b/companion/src/datamodels/compounditemmodels.cpp index f47741341..24aac5aa9 100644 --- a/companion/src/datamodels/compounditemmodels.cpp +++ b/companion/src/datamodels/compounditemmodels.cpp @@ -457,9 +457,7 @@ CustomFuncResetParamItemModel::CustomFuncResetParamItemModel(const GeneralSettin void CustomFuncResetParamItemModel::setDynamicItemData(QStandardItem * item, const int value) const { - CustomFunctionData cfd = CustomFunctionData(AssignFunc::FuncReset); - cfd.param = value; - item->setText(CustomFunctionData::resetToString(modelData)); + item->setText(CustomFunctionData::resetToString(modelData, value)); item->setData(CustomFunctionData::isResetParamAvailable(modelData, value), IMDR_Available); } diff --git a/companion/src/datamodels/compounditemmodels.h b/companion/src/datamodels/compounditemmodels.h index de32fc902..c6d204cb3 100644 --- a/companion/src/datamodels/compounditemmodels.h +++ b/companion/src/datamodels/compounditemmodels.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef COMPOUNDITEMMODELS_H -#define COMPOUNDITEMMODELS_H +#pragma once #include "rawsource.h" #include "rawswitch.h" @@ -361,5 +360,3 @@ class CompoundItemModelFactory private: void setSourceId(AbstractItemModel * itemModel); }; - -#endif // COMPOUNDITEMMODELS_H diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index aa2f64bbd..b5bece769 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -262,6 +262,7 @@ QString CustomFunctionData::resetToString(const ModelData * model, int value) else return QString(CPN_STR_UNKNOWN_ITEM); } + step += reCount; if (value < step + firmware->getCapability(Sensors)) @@ -291,8 +292,8 @@ bool CustomFunctionData::isResetParamAvailable(const ModelData * model, int inde } else if (index < CPN_MAX_TIMERS + firmware->getCapability(RotaryEncoders)) return true; - else if (model && index < CPN_MAX_TIMERS + firmware->getCapability(RotaryEncoders) + firmware->getCapability(Sensors)) - return model->sensorData[index - CPN_MAX_TIMERS - firmware->getCapability(RotaryEncoders)].isAvailable(); + else if (model && index < resetParamCount()) + return model->sensorData[index - (CPN_MAX_TIMERS + 2 + firmware->getCapability(RotaryEncoders))].isAvailable(); return false; } diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 05eefb96b..7f3e8ee19 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -99,7 +99,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, playIcon.addImage("stop.png", QIcon::Normal, QIcon::On); QStringList headerLabels; - headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << tr("Enable"); + headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << ""; TableLayout * tableLayout = new TableLayout(this, fswCapability, headerLabels); for (int i = 0; i < fswCapability; i++) { @@ -119,19 +119,21 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, // The switch fswtchSwtch[i] = new QComboBox(this); + fswtchSwtch[i]->setProperty("index", i); fswtchSwtch[i]->setModel(tabFilterFactory->getItemModel(rawSwitchId)); fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue())); - fswtchSwtch[i]->setProperty("index", i); fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); + fswtchSwtch[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); fswtchSwtch[i]->setMaxVisibleItems(10); connect(fswtchSwtch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); tableLayout->addWidget(i, 1, fswtchSwtch[i]); // The function fswtchFunc[i] = new QComboBox(this); + fswtchFunc[i]->setProperty("index", i); fswtchFunc[i]->setModel(tabFilterFactory->getItemModel(funcActionsId)); fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func)); - fswtchFunc[i]->setProperty("index", i); + fswtchFunc[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited())); tableLayout->addWidget(i, 2, fswtchFunc[i]); @@ -148,8 +150,8 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, fswtchParamGV[i] = new QCheckBox(this); fswtchParamGV[i]->setProperty("index", i); - fswtchParamGV[i]->setText("GV"); - fswtchParamGV[i]->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); + fswtchParamGV[i]->setText(tr("GV")); + fswtchParamGV[i]->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); connect(fswtchParamGV[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited())); paramLayout->addWidget(fswtchParamGV[i]); @@ -202,6 +204,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, fswtchRepeat[i]->setProperty("index", i); fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatId)); fswtchRepeat[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); + fswtchRepeat[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); repeatLayout->addWidget(fswtchRepeat[i], i + 1); connect(fswtchRepeat[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); From 6c3f7b1ca64b324bdade41ae2ba7368bea52cba0 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 4 Mar 2021 07:59:24 +1100 Subject: [PATCH 08/12] Consistency and statics --- .../src/datamodels/compounditemmodels.cpp | 6 ++--- .../src/firmwares/customfunctiondata.cpp | 27 ++++++++++++------- companion/src/firmwares/customfunctiondata.h | 21 ++++++++------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/companion/src/datamodels/compounditemmodels.cpp b/companion/src/datamodels/compounditemmodels.cpp index 24aac5aa9..83e046c13 100644 --- a/companion/src/datamodels/compounditemmodels.cpp +++ b/companion/src/datamodels/compounditemmodels.cpp @@ -420,7 +420,7 @@ CustomFuncActionItemModel::CustomFuncActionItemModel(const GeneralSettings * con void CustomFuncActionItemModel::setDynamicItemData(QStandardItem * item, const int value) const { - item->setText(CustomFunctionData(AssignFunc(value)).funcToString(modelData)); + item->setText(CustomFunctionData::funcToString((AssignFunc)value, modelData)); item->setData(CustomFunctionData::isFuncAvailable(value), IMDR_Available); } @@ -457,8 +457,8 @@ CustomFuncResetParamItemModel::CustomFuncResetParamItemModel(const GeneralSettin void CustomFuncResetParamItemModel::setDynamicItemData(QStandardItem * item, const int value) const { - item->setText(CustomFunctionData::resetToString(modelData, value)); - item->setData(CustomFunctionData::isResetParamAvailable(modelData, value), IMDR_Available); + item->setText(CustomFunctionData::resetToString(value, modelData)); + item->setData(CustomFunctionData::isResetParamAvailable(value, modelData), IMDR_Available); } void CustomFuncResetParamItemModel::update(const int event) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index b5bece769..43fd3c149 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -47,12 +47,19 @@ bool CustomFunctionData::isEmpty() const return (swtch.type == SWITCH_TYPE_NONE); } -QString CustomFunctionData::nameToString(int index, bool globalContext) const +// static +QString CustomFunctionData::nameToString(const int index, const bool globalContext) { return RadioData::getElementName((globalContext ? tr("GF") : tr("SF")), index + 1, 0, true); } QString CustomFunctionData::funcToString(const ModelData * model) const +{ + return funcToString(func, model); +} + +// static +QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData * model) { if (func >= FuncOverrideCH1 && func <= FuncOverrideCHLast) return tr("Override %1").arg(RawSource(SOURCE_TYPE_CH, func).toString(model)); @@ -133,7 +140,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const return harpicToString(param); } else if (func == FuncReset) { - return resetToString(model, param); + return resetToString(param, model); } else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) { return RawSource(param).toString(model); @@ -168,7 +175,7 @@ QString CustomFunctionData::repeatToString() const } // static -QString CustomFunctionData::repeatToString(int value) +QString CustomFunctionData::repeatToString(const int value) { if (value == -1) { return tr("Played once, not during startup"); @@ -198,7 +205,7 @@ QString CustomFunctionData::enabledToString() const } // static -bool CustomFunctionData::isFuncAvailable(int index) +bool CustomFunctionData::isFuncAvailable(const int index) { Firmware * fw = getCurrentFirmware(); @@ -217,7 +224,7 @@ bool CustomFunctionData::isFuncAvailable(int index) } // static -int CustomFunctionData::funcContext(int index) +int CustomFunctionData::funcContext(const int index) { int ret = AllFunctionContexts; @@ -230,7 +237,7 @@ int CustomFunctionData::funcContext(int index) } // static -QString CustomFunctionData::resetToString(const ModelData * model, int value) +QString CustomFunctionData::resetToString(const int value, const ModelData * model) { Firmware * firmware = getCurrentFirmware(); int step = CPN_MAX_TIMERS; @@ -280,7 +287,7 @@ int CustomFunctionData::resetParamCount() } // static -bool CustomFunctionData::isResetParamAvailable(const ModelData * model, int index) +bool CustomFunctionData::isResetParamAvailable(const int index, const ModelData * model) { Firmware * firmware = getCurrentFirmware(); @@ -304,7 +311,7 @@ QString CustomFunctionData::harpicToString() const } // static -QString CustomFunctionData::harpicToString(int value) +QString CustomFunctionData::harpicToString(const int value) { return QString("%1").arg(value); } @@ -322,7 +329,7 @@ QString CustomFunctionData::playSoundToString() const } // static -QString CustomFunctionData::playSoundToString(int value) +QString CustomFunctionData::playSoundToString(const int value) { const QStringList strl = playSoundStringList(); if (value < strl.count()) @@ -337,7 +344,7 @@ QString CustomFunctionData::gvarAdjustModeToString() const } // static -QString CustomFunctionData::gvarAdjustModeToString(int value) +QString CustomFunctionData::gvarAdjustModeToString(const int value) { switch (value) { case FUNC_ADJUST_GVAR_CONSTANT: diff --git a/companion/src/firmwares/customfunctiondata.h b/companion/src/firmwares/customfunctiondata.h index 3240256f3..d5a08a96f 100644 --- a/companion/src/firmwares/customfunctiondata.h +++ b/companion/src/firmwares/customfunctiondata.h @@ -107,26 +107,27 @@ class CustomFunctionData { void clear(); bool isEmpty() const; - QString nameToString(int index, bool globalContext = false) const; QString funcToString(const ModelData * model = nullptr) const; - QString paramToString(const ModelData * model) const; + QString paramToString(const ModelData * model = nullptr) const; QString repeatToString() const; QString enabledToString() const; QString playSoundToString() const; QString harpicToString() const; QString gvarAdjustModeToString() const; - static bool isFuncAvailable(int index); - static int funcContext(int index); - static QString resetToString(const ModelData * model, int value); + static QString nameToString(const int index, const bool globalContext = false); + static QString funcToString(const AssignFunc func, const ModelData * model = nullptr); + static bool isFuncAvailable(const int index); + static int funcContext(const int index); + static QString resetToString(const int value, const ModelData * model = nullptr); static int resetParamCount(); - static bool isResetParamAvailable(const ModelData * model, int index); - static QString repeatToString(int value); + static bool isResetParamAvailable(const int index, const ModelData * model = nullptr); + static QString repeatToString(const int value); static QStringList playSoundStringList(); - static QString playSoundToString(int value); - static QString harpicToString(int value); + static QString playSoundToString(const int value); + static QString harpicToString(const int value); static QStringList gvarAdjustModeStringList(); - static QString gvarAdjustModeToString(int value); + static QString gvarAdjustModeToString(const int value); static AbstractStaticItemModel * repeatItemModel(); static AbstractStaticItemModel * playSoundItemModel(); static AbstractStaticItemModel * harpicItemModel(); From 3ba689d98927182ee39e1eff5202e56fbe4b1076 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 4 Mar 2021 08:05:15 +1100 Subject: [PATCH 09/12] Remove unused slider --- companion/src/modeledit/customfunctions.cpp | 11 ----------- companion/src/modeledit/customfunctions.h | 1 - 2 files changed, 12 deletions(-) diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 7f3e8ee19..c773e90e5 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -182,15 +182,6 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, connect(fswtchParamArmT[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); connect(fswtchParamArmT[i], SIGNAL(editTextChanged ( const QString)), this, SLOT(customFunctionEdited())); - fswtchBLcolor[i] = new QSlider(this); - fswtchBLcolor[i]->setProperty("index", i); - fswtchBLcolor[i]->setMinimum(0); - fswtchBLcolor[i]->setMaximum(100); - fswtchBLcolor[i]->setSingleStep(1); - fswtchBLcolor[i]->setOrientation(Qt::Horizontal); - paramLayout->addWidget(fswtchBLcolor[i]); - connect(fswtchBLcolor[i], SIGNAL(sliderReleased()), this, SLOT(customFunctionEdited())); - playBT[i] = new QToolButton(this); playBT[i]->setProperty("index", i); playBT[i]->setIcon(playIcon); @@ -310,7 +301,6 @@ void CustomFunctionsPanel::toggleSound(bool play) #define CUSTOM_FUNCTION_ENABLE (1<<6) #define CUSTOM_FUNCTION_REPEAT (1<<7) #define CUSTOM_FUNCTION_PLAY (1<<8) -#define CUSTOM_FUNCTION_BL_COLOR (1<<9) #define CUSTOM_FUNCTION_SHOW_FUNC (1<<10) @@ -551,7 +541,6 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) fswtchEnable[i]->setChecked(false); fswtchRepeat[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_REPEAT); fswtchGVmode[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_GV_MODE); - fswtchBLcolor[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_BL_COLOR); playBT[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_PLAY); } diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index 6d1668114..87775246d 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -103,7 +103,6 @@ class CustomFunctionsPanel : public GenericPanel QCheckBox * fswtchEnable[CPN_MAX_SPECIAL_FUNCTIONS]; QComboBox * fswtchRepeat[CPN_MAX_SPECIAL_FUNCTIONS]; QComboBox * fswtchGVmode[CPN_MAX_SPECIAL_FUNCTIONS]; - QSlider * fswtchBLcolor[CPN_MAX_SPECIAL_FUNCTIONS]; QMediaPlayer * mediaPlayer; int selectedIndex; From 227b225deaf778a60ce9641edf29bf098992028b Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 4 Mar 2021 08:22:45 +1100 Subject: [PATCH 10/12] Consistency with radio --- companion/src/firmwares/customfunctiondata.cpp | 4 ++-- companion/src/modeledit/customfunctions.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 43fd3c149..d78c1a349 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -94,7 +94,7 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData else if (func == FuncPlayValue) return tr("Play Value"); else if (func == FuncPlayScript) - return tr("Play Script"); + return tr("Lua Script"); else if (func == FuncLogs) return tr("SD Logs"); else if (func == FuncVolume) @@ -354,7 +354,7 @@ QString CustomFunctionData::gvarAdjustModeToString(const int value) case FUNC_ADJUST_GVAR_GVAR: return tr("Global Variable"); case FUNC_ADJUST_GVAR_INCDEC: - return tr("Increment"); + return tr("Inc/Decrement"); default: return QString(CPN_STR_UNKNOWN_ITEM); } diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index c773e90e5..230cf5e4c 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -201,7 +201,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, fswtchEnable[i] = new QCheckBox(this); fswtchEnable[i]->setProperty("index", i); - fswtchEnable[i]->setText(tr("ON")); + fswtchEnable[i]->setText(tr("Enable")); fswtchEnable[i]->setFixedWidth(200); repeatLayout->addWidget(fswtchEnable[i], i + 1); connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited())); From fc03ba58d08302bab895178b26d6908b9df855bb Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 4 Mar 2021 08:25:47 +1100 Subject: [PATCH 11/12] Revert enable label --- companion/src/modeledit/customfunctions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 230cf5e4c..c773e90e5 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -201,7 +201,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, fswtchEnable[i] = new QCheckBox(this); fswtchEnable[i]->setProperty("index", i); - fswtchEnable[i]->setText(tr("Enable")); + fswtchEnable[i]->setText(tr("ON")); fswtchEnable[i]->setFixedWidth(200); repeatLayout->addWidget(fswtchEnable[i], i + 1); connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited())); From 19add4de921d6f143c07ab6657818dd0683d4673 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 4 Mar 2021 08:47:21 +1100 Subject: [PATCH 12/12] Remove some depreciated Rotary Encoder code --- .../src/datamodels/compounditemmodels.cpp | 3 --- .../src/firmwares/customfunctiondata.cpp | 23 +++---------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/companion/src/datamodels/compounditemmodels.cpp b/companion/src/datamodels/compounditemmodels.cpp index 83e046c13..f72eb4f34 100644 --- a/companion/src/datamodels/compounditemmodels.cpp +++ b/companion/src/datamodels/compounditemmodels.cpp @@ -109,7 +109,6 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett addItems(SOURCE_TYPE_LUA_OUTPUT, RawSource::ScriptsGroup, firmware->getCapability(LuaOutputsPerScript), i * 16); addItems(SOURCE_TYPE_VIRTUAL_INPUT, RawSource::InputsGroup, firmware->getCapability(VirtualInputs)); addItems(SOURCE_TYPE_STICK, RawSource::SourcesGroup, board->getCapability(Board::MaxAnalogs)); - addItems(SOURCE_TYPE_ROTARY_ENCODER, RawSource::SourcesGroup, firmware->getCapability(RotaryEncoders)); addItems(SOURCE_TYPE_TRIM, RawSource::TrimsGroup, board->getCapability(Board::NumTrims)); addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, 1); addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, board->getCapability(Board::Switches)); @@ -170,7 +169,6 @@ RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSett addItems(SWITCH_TYPE_TELEMETRY, -1); addItems(SWITCH_TYPE_FLIGHT_MODE, -firmware->getCapability(FlightModes)); addItems(SWITCH_TYPE_VIRTUAL, -firmware->getCapability(LogicalSwitches)); - addItems(SWITCH_TYPE_ROTARY_ENCODER, -firmware->getCapability(RotaryEncoders)); addItems(SWITCH_TYPE_TRIM, -board->getCapability(Board::NumTrimSwitches)); addItems(SWITCH_TYPE_MULTIPOS_POT, -(board->getCapability(Board::MultiposPots) * board->getCapability(Board::MultiposPotsPositions))); addItems(SWITCH_TYPE_SWITCH, -board->getCapability(Board::SwitchPositions)); @@ -181,7 +179,6 @@ RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSett addItems(SWITCH_TYPE_SWITCH, board->getCapability(Board::SwitchPositions)); addItems(SWITCH_TYPE_MULTIPOS_POT, board->getCapability(Board::MultiposPots) * board->getCapability(Board::MultiposPotsPositions)); addItems(SWITCH_TYPE_TRIM, board->getCapability(Board::NumTrimSwitches)); - addItems(SWITCH_TYPE_ROTARY_ENCODER, firmware->getCapability(RotaryEncoders)); addItems(SWITCH_TYPE_VIRTUAL, firmware->getCapability(LogicalSwitches)); addItems(SWITCH_TYPE_FLIGHT_MODE, firmware->getCapability(FlightModes)); addItems(SWITCH_TYPE_TELEMETRY, 1); diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index d78c1a349..98157cae2 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -255,23 +255,6 @@ QString CustomFunctionData::resetToString(const int value, const ModelData * mod if (value < ++step) return tr("Telemetry"); - int reCount = firmware->getCapability(RotaryEncoders); - - if (reCount > 0 && value < step + reCount) { - if (reCount == 1 && value < step + 1) - return tr("Rotary Encoder"); - else if (reCount == 2) { - if (value < step + 1) - return tr("REa"); - else - return tr("REb"); - } - else - return QString(CPN_STR_UNKNOWN_ITEM); - } - - step += reCount; - if (value < step + firmware->getCapability(Sensors)) return RawSource(SOURCE_TYPE_TELEMETRY, 3 * (value - step)).toString(model); @@ -283,7 +266,7 @@ int CustomFunctionData::resetParamCount() { Firmware * firmware = getCurrentFirmware(); - return CPN_MAX_TIMERS + 2 + firmware->getCapability(RotaryEncoders) + firmware->getCapability(Sensors); + return CPN_MAX_TIMERS + 2 + firmware->getCapability(Sensors); } // static @@ -297,10 +280,10 @@ bool CustomFunctionData::isResetParamAvailable(const int index, const ModelData else return false; } - else if (index < CPN_MAX_TIMERS + firmware->getCapability(RotaryEncoders)) + else if (index < CPN_MAX_TIMERS + 2) return true; else if (model && index < resetParamCount()) - return model->sensorData[index - (CPN_MAX_TIMERS + 2 + firmware->getCapability(RotaryEncoders))].isAvailable(); + return model->sensorData[index - (CPN_MAX_TIMERS + 2)].isAvailable(); return false; }