From f0d4c88f03551282a41df432467d478b3bbf57e6 Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 2 Mar 2021 23:17:21 +1100 Subject: [PATCH] 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;