Add static models

This commit is contained in:
elecpower
2021-03-02 21:35:25 +11:00
parent d213034bfd
commit e6e41f18d7
4 changed files with 75 additions and 77 deletions
+34 -41
View File
@@ -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<void *>(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("<font color=red><b>Inconsistent parameter</b></font>");
return playSoundToString(param);
}
else if (func == FuncPlayHaptic) {
CustomFunctionData::populateHapticParams(qs);
if (param >= 0 && param < (int)qs.count())
return qs.at(param);
else
return tr("<font color=red><b>Inconsistent parameter</b></font>");
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("<font color=red><b>Inconsistent parameter</b></font>");
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();
+6 -8
View File
@@ -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();
};
+31 -27
View File
@@ -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);
+4 -1
View File
@@ -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<QString> tracksSet;
QSet<QString> scriptsSet;