Gvar adjust mode to item model

This commit is contained in:
elecpower
2021-03-02 23:17:21 +11:00
parent cb4ee1b30d
commit f0d4c88f03
4 changed files with 50 additions and 22 deletions
+39 -6
View File
@@ -314,10 +314,8 @@ QString CustomFunctionData::harpicToString(int value)
// static // static
QStringList CustomFunctionData::playSoundStringList() QStringList CustomFunctionData::playSoundStringList()
{ {
QStringList strl; return QStringList({ tr("Beep 1"), tr("Beep 2"), tr("Beep 3"), tr("Warn 1"), tr("Warn 2"), tr("Cheep"), tr("Ratata"), tr("Tick"),
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") });
<< tr("Siren") << tr("Ring") << tr("Sci Fi") << tr("Robot") << tr("Chirp") << tr("Tada") << tr("Cricket") << tr("Alarm Clock");
return strl;
} }
QString CustomFunctionData::playSoundToString() const QString CustomFunctionData::playSoundToString() const
@@ -328,13 +326,35 @@ QString CustomFunctionData::playSoundToString() const
// static // static
QString CustomFunctionData::playSoundToString(int value) QString CustomFunctionData::playSoundToString(int value)
{ {
QStringList strl = playSoundStringList(); const QStringList strl = playSoundStringList();
if (value < strl.count()) if (value < strl.count())
return strl.at(value); return strl.at(value);
else else
return QString(CPN_STR_UNKNOWN_ITEM); 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 // static
AbstractStaticItemModel * CustomFunctionData::repeatItemModel() AbstractStaticItemModel * CustomFunctionData::repeatItemModel()
{ {
@@ -353,7 +373,7 @@ AbstractStaticItemModel * CustomFunctionData::repeatItemModel()
AbstractStaticItemModel * CustomFunctionData::playSoundItemModel() AbstractStaticItemModel * CustomFunctionData::playSoundItemModel()
{ {
AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("customfunctiondata.playsounds"); mdl->setName("customfunctiondata.playsound");
for (int i = 0; i < playSoundStringList().count(); i++) { for (int i = 0; i < playSoundStringList().count(); i++) {
mdl->appendToItemList(playSoundToString(i), i); mdl->appendToItemList(playSoundToString(i), i);
@@ -377,3 +397,16 @@ AbstractStaticItemModel * CustomFunctionData::harpicItemModel()
return mdl; 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;
}
+6 -2
View File
@@ -78,7 +78,8 @@ enum GVarAdjustModes
FUNC_ADJUST_GVAR_CONSTANT, FUNC_ADJUST_GVAR_CONSTANT,
FUNC_ADJUST_GVAR_SOURCE, FUNC_ADJUST_GVAR_SOURCE,
FUNC_ADJUST_GVAR_GVAR, FUNC_ADJUST_GVAR_GVAR,
FUNC_ADJUST_GVAR_INCDEC FUNC_ADJUST_GVAR_INCDEC,
FUNC_ADJUST_GVAR_COUNT
}; };
class CustomFunctionData { class CustomFunctionData {
@@ -113,18 +114,21 @@ class CustomFunctionData {
QString enabledToString() const; QString enabledToString() const;
QString playSoundToString() const; QString playSoundToString() const;
QString harpicToString() const; QString harpicToString() const;
QString gvarAdjustModeToString() const;
static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value); static void populateResetParams(const ModelData * model, QComboBox * b, unsigned int value);
static bool isFuncAvailable(int index); static bool isFuncAvailable(int index);
static int funcContext(int index); static int funcContext(int index);
static int resetParamCount(const ModelData * model); static int resetParamCount(const ModelData * model);
static bool isResetParamAvailable(const ModelData * model, int index); static bool isResetParamAvailable(const ModelData * model, int index);
static QString repeatToString(int value); static QString repeatToString(int value);
static QStringList playSoundStringList(); static QStringList playSoundStringList();
static QString playSoundToString(int value); static QString playSoundToString(int value);
static QString harpicToString(int value); static QString harpicToString(int value);
static QStringList gvarAdjustModeStringList();
static QString gvarAdjustModeToString(int value);
static AbstractStaticItemModel * repeatItemModel(); static AbstractStaticItemModel * repeatItemModel();
static AbstractStaticItemModel * playSoundItemModel(); static AbstractStaticItemModel * playSoundItemModel();
static AbstractStaticItemModel * harpicItemModel(); static AbstractStaticItemModel * harpicItemModel();
static AbstractStaticItemModel * gvarAdjustModeItemModel();
}; };
+4 -13
View File
@@ -39,6 +39,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
playSoundId = tabModelFactory->registerItemModel(CustomFunctionData::playSoundItemModel()); playSoundId = tabModelFactory->registerItemModel(CustomFunctionData::playSoundItemModel());
harpicId = tabModelFactory->registerItemModel(CustomFunctionData::harpicItemModel()); harpicId = tabModelFactory->registerItemModel(CustomFunctionData::harpicItemModel());
repeatId = tabModelFactory->registerItemModel(CustomFunctionData::repeatItemModel()); repeatId = tabModelFactory->registerItemModel(CustomFunctionData::repeatItemModel());
gvarAdjustModeId = tabModelFactory->registerItemModel(CustomFunctionData::gvarAdjustModeItemModel());
tabFilterFactory = new FilteredItemModelFactory(); tabFilterFactory = new FilteredItemModelFactory();
@@ -140,7 +141,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
fswtchGVmode[i] = new QComboBox(this); fswtchGVmode[i] = new QComboBox(this);
fswtchGVmode[i]->setProperty("index", i); fswtchGVmode[i]->setProperty("index", i);
populateGVmodeCB(fswtchGVmode[i], functions[i].adjustMode); fswtchGVmode[i]->setModel(tabModelFactory->getItemModel(gvarAdjustModeId));
fswtchGVmode[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); fswtchGVmode[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
connect(fswtchGVmode[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); connect(fswtchGVmode[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
paramLayout->addWidget(fswtchGVmode[i]); paramLayout->addWidget(fswtchGVmode[i]);
@@ -382,8 +383,8 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
else if (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) { else if (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) {
int gvidx = func - FuncAdjustGV1; int gvidx = func - FuncAdjustGV1;
if (modified) if (modified)
cfn.adjustMode = fswtchGVmode[i]->currentIndex(); cfn.adjustMode = fswtchGVmode[i]->currentData().toInt();
fswtchGVmode[i]->setCurrentIndex(cfn.adjustMode); fswtchGVmode[i]->setCurrentIndex(fswtchGVmode[i]->findData(cfn.adjustMode));
widgetsMask |= CUSTOM_FUNCTION_GV_MODE | CUSTOM_FUNCTION_ENABLE; widgetsMask |= CUSTOM_FUNCTION_GV_MODE | CUSTOM_FUNCTION_ENABLE;
if (cfn.adjustMode == FUNC_ADJUST_GVAR_CONSTANT || cfn.adjustMode == FUNC_ADJUST_GVAR_INCDEC) { if (cfn.adjustMode == FUNC_ADJUST_GVAR_CONSTANT || cfn.adjustMode == FUNC_ADJUST_GVAR_INCDEC) {
if (modified) if (modified)
@@ -623,16 +624,6 @@ void CustomFunctionsPanel::onCustomContextMenuRequested(QPoint pos)
contextMenu.exec(globalPos); 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) void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode)
{ {
QStringList qs; QStringList qs;
+1 -1
View File
@@ -67,7 +67,6 @@ class CustomFunctionsPanel : public GenericPanel
void onItemModelUpdateComplete(); void onItemModelUpdateComplete();
private: private:
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;
bool insertAllowed() const; bool insertAllowed() const;
@@ -88,6 +87,7 @@ class CustomFunctionsPanel : public GenericPanel
int playSoundId; int playSoundId;
int harpicId; int harpicId;
int repeatId; int repeatId;
int gvarAdjustModeId;
QSet<QString> tracksSet; QSet<QString> tracksSet;
QSet<QString> scriptsSet; QSet<QString> scriptsSet;