Add item data models for action and reset param

This commit is contained in:
elecpower
2021-03-01 07:32:00 +11:00
parent 1218e20104
commit d213034bfd
4 changed files with 143 additions and 78 deletions
+80 -8
View File
@@ -22,6 +22,7 @@
#include "eeprominterface.h" #include "eeprominterface.h"
#include "radiodata.h" #include "radiodata.h"
#include "radiodataconversionstate.h" #include "radiodataconversionstate.h"
#include "compounditemmodels.h"
void CustomFunctionData::clear() void CustomFunctionData::clear()
{ {
@@ -200,7 +201,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
else if (func >= FuncAdjustGV1 && func < FuncCount) { else if (func >= FuncAdjustGV1 && func < FuncCount) {
switch (adjustMode) { switch (adjustMode) {
case FUNC_ADJUST_GVAR_CONSTANT: 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_SOURCE:
case FUNC_ADJUST_GVAR_GVAR: case FUNC_ADJUST_GVAR_GVAR:
return RawSource(param).toString(); return RawSource(param).toString();
@@ -209,7 +210,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
QString unit; QString unit;
val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet(); val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet();
unit = model->gvarData[func - FuncAdjustGV1].unitToString(); 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 ""; return "";
@@ -217,15 +218,20 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
QString CustomFunctionData::repeatToString() const QString CustomFunctionData::repeatToString() const
{ {
if (repeatParam == -1) { return repeatToString(repeatParam);
return tr("played once, not during startup"); }
// static
QString CustomFunctionData::repeatToString(int value) const
{
if (value == -1) {
return tr("Played once, not during startup");
} }
else if (repeatParam == 0) { else if (value == 0) {
return ""; return tr("No repeat");
} }
else { else {
unsigned int step = 1; return tr("Repeat(%1s)").arg(value);
return tr("repeat(%1s)").arg(step * repeatParam);
} }
} }
@@ -312,3 +318,69 @@ void CustomFunctionData::convert(RadioDataConversionState & cstate)
param = RawSource(param).convert(cstate.withComponentField("PARAM")).toValue(); 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;
}
+11 -5
View File
@@ -18,8 +18,7 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifndef CUSTOMFUNCTIONDATA_H #pragma once
#define CUSTOMFUNCTIONDATA_H
#include "boards.h" #include "boards.h"
#include "constants.h" #include "constants.h"
@@ -32,6 +31,7 @@ class Firmware;
class ModelData; class ModelData;
class GeneralSettings; class GeneralSettings;
class RadioDataConversionState; class RadioDataConversionState;
class AbstractStaticItemModel;
enum AssignFunc { enum AssignFunc {
FuncOverrideCH1 = 0, FuncOverrideCH1 = 0,
@@ -109,6 +109,8 @@ class CustomFunctionData {
QString paramToString(const ModelData * model) const; QString paramToString(const ModelData * model) const;
QString repeatToString() const; QString repeatToString() const;
QString enabledToString() const; QString enabledToString() const;
QString playsoundsToString() const;
QString harpicToString() const;
static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value); static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value);
static void populatePlaySoundParams(QStringList & qs); static void populatePlaySoundParams(QStringList & qs);
@@ -120,7 +122,11 @@ class CustomFunctionData {
void convert(RadioDataConversionState & cstate); 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
+43 -59
View File
@@ -30,7 +30,7 @@ RepeatComboBox::RepeatComboBox(QWidget *parent, int & repeatParam):
repeatParam(repeatParam) repeatParam(repeatParam)
{ {
unsigned int step = 1; unsigned int step = 1;
int value = repeatParam/step; int value = repeatParam / step;
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
@@ -59,7 +59,7 @@ void RepeatComboBox::onIndexChanged(int index)
void RepeatComboBox::update() void RepeatComboBox::update()
{ {
unsigned int step = 1; unsigned int step = 1;
int value = repeatParam/step; int value = repeatParam / step;
if (step == 1) { if (step == 1) {
value++; value++;
} }
@@ -77,18 +77,35 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
lock = true; lock = true;
fswCapability = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); fswCapability = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
rawSwitchFilteredModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch), dlgFilterFactory = new FilteredItemModelFactory();
model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext);
connectItemModelEvents(rawSwitchFilteredModel);
rawSourceAllModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource)); funcActionsId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncAction),
connectItemModelEvents(rawSourceAllModel); model ? CustomFunctionData::AllFunctionContexts : CustomFunctionData::GlobalFunctionsContext),
"Function Actions");
connectItemModelEvents(dlgFilterFactory->getItemModel(funcActionsId));
rawSourceInputsModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), RawSource::InputSourceGroups); funcResetParamId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_CustomFuncResetParam)),
connectItemModelEvents(rawSourceInputsModel); "Reset Params");
connectItemModelEvents(dlgFilterFactory->getItemModel(funcResetParamId));
rawSourceGVarsModel = new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSource), RawSource::GVarsGroup); rawSwitchId = dlgFilterFactory->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch),
connectItemModelEvents(rawSourceGVarsModel); 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)) { if (!firmware->getCapability(VoicesAsNumbers)) {
tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength)); 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); label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
connect(label, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequested(QPoint))); connect(label, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequested(QPoint)));
tableLayout->addWidget(i, 0, label); tableLayout->addWidget(i, 0, label);
// s1.report("label");
// The switch // The switch
fswtchSwtch[i] = new QComboBox(this); 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]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue()));
fswtchSwtch[i]->setProperty("index", i); fswtchSwtch[i]->setProperty("index", i);
fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
fswtchSwtch[i]->setMaxVisibleItems(10); fswtchSwtch[i]->setMaxVisibleItems(10);
connect(fswtchSwtch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); connect(fswtchSwtch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
tableLayout->addWidget(i, 1, fswtchSwtch[i]); tableLayout->addWidget(i, 1, fswtchSwtch[i]);
// s1.report("switch");
// The function // The function
fswtchFunc[i] = new QComboBox(this); fswtchFunc[i] = new QComboBox(this);
if (!i) { fswtchFunc[i]->setModel(dlgFilterFactory->getItemModel(funcActionsId));
populateFuncCB(fswtchFunc[i], functions[i].func); fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func));
}
else {
fswtchFunc[i]->setModel(fswtchFunc[0]->model());
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func));
}
fswtchFunc[i]->setProperty("index", i); fswtchFunc[i]->setProperty("index", i);
connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited())); connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited()));
tableLayout->addWidget(i, 2, fswtchFunc[i]); tableLayout->addWidget(i, 2, fswtchFunc[i]);
// s1.report("func");
// The parameters // The parameters
QHBoxLayout * paramLayout = new QHBoxLayout(); QHBoxLayout * paramLayout = new QHBoxLayout();
@@ -250,10 +259,7 @@ CustomFunctionsPanel::~CustomFunctionsPanel()
{ {
if (mediaPlayer) if (mediaPlayer)
stopSound(mediaPlayerCurrent); stopSound(mediaPlayerCurrent);
delete rawSwitchFilteredModel; delete dlgFilterFactory;
delete rawSourceAllModel;
delete rawSourceInputsModel;
delete rawSourceGVarsModel;
} }
void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state) void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state)
@@ -653,33 +659,6 @@ void CustomFunctionsPanel::onCustomContextMenuRequested(QPoint pos)
contextMenu.exec(globalPos); 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) void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value)
{ {
b->clear(); b->clear();
@@ -705,25 +684,30 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi
b->setCurrentIndex(value); b->setCurrentIndex(value);
} }
else if (function == FuncReset) { 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) { else if (function == FuncVolume || function == FuncBacklight) {
b->setModel(rawSourceInputsModel); b->setModel(dlgFilterFactory->getItemModel(rawSourceInputsId));
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
} }
else if (function == FuncPlayValue) { else if (function == FuncPlayValue) {
b->setModel(rawSourceAllModel); b->setModel(dlgFilterFactory->getItemModel(rawSourceAllId));
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
} }
else if (function >= FuncAdjustGV1 && function <= FuncAdjustGVLast) { else if (function >= FuncAdjustGV1 && function <= FuncAdjustGVLast) {
switch (adjustmode) { switch (adjustmode) {
case 1: case 1:
b->setModel(rawSourceInputsModel); b->setModel(dlgFilterFactory->getItemModel(rawSourceInputsId));
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
if (b->currentIndex() < 0)
b->setCurrentIndex(0);
break; break;
case 2: case 2:
b->setModel(rawSourceGVarsModel); b->setModel(dlgFilterFactory->getItemModel(rawSourceGVarsId));
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
if (b->currentIndex() < 0)
b->setCurrentIndex(0);
break; break;
} }
} }
@@ -828,7 +812,7 @@ bool CustomFunctionsPanel::moveUpAllowed() const
return selectedIndex > 0; return selectedIndex > 0;
} }
void CustomFunctionsPanel::connectItemModelEvents(const FilteredItemModel * itemModel) void CustomFunctionsPanel::connectItemModelEvents(FilteredItemModel * itemModel)
{ {
connect(itemModel, &FilteredItemModel::aboutToBeUpdated, this, &CustomFunctionsPanel::onItemModelAboutToBeUpdated); connect(itemModel, &FilteredItemModel::aboutToBeUpdated, this, &CustomFunctionsPanel::onItemModelAboutToBeUpdated);
connect(itemModel, &FilteredItemModel::updateComplete, this, &CustomFunctionsPanel::onItemModelUpdateComplete); connect(itemModel, &FilteredItemModel::updateComplete, this, &CustomFunctionsPanel::onItemModelUpdateComplete);
+9 -6
View File
@@ -27,6 +27,7 @@
#include <QMediaPlayer> #include <QMediaPlayer>
class CompoundItemModelFactory; class CompoundItemModelFactory;
class FilteredItemModelFactory;
class FilteredItemModel; class FilteredItemModel;
class TimerEdit; class TimerEdit;
@@ -87,7 +88,6 @@ class CustomFunctionsPanel : public GenericPanel
void onItemModelUpdateComplete(); void onItemModelUpdateComplete();
private: private:
void populateFuncCB(QComboBox *b, unsigned int value);
void populateGVmodeCB(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); void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
bool hasClipboardData(QByteArray * data = nullptr) const; bool hasClipboardData(QByteArray * data = nullptr) const;
@@ -96,12 +96,15 @@ class CustomFunctionsPanel : public GenericPanel
bool moveUpAllowed() const; bool moveUpAllowed() const;
void swapData(int idx1, int idx2); void swapData(int idx1, int idx2);
void resetCBsAndRefresh(int idx); void resetCBsAndRefresh(int idx);
void connectItemModelEvents(const FilteredItemModel * itemModel); void connectItemModelEvents(FilteredItemModel * itemModel);
FilteredItemModel * rawSwitchFilteredModel; FilteredItemModelFactory * dlgFilterFactory;
FilteredItemModel * rawSourceAllModel; int funcActionsId;
FilteredItemModel * rawSourceInputsModel; int funcResetParamId;
FilteredItemModel * rawSourceGVarsModel; int rawSwitchId;
int rawSourceAllId;
int rawSourceInputsId;
int rawSourceGVarsId;
QSet<QString> tracksSet; QSet<QString> tracksSet;
QSet<QString> scriptsSet; QSet<QString> scriptsSet;