Refactor reset param functions
This commit is contained in:
@@ -447,7 +447,7 @@ CustomFuncResetParamItemModel::CustomFuncResetParamItemModel(const GeneralSettin
|
|||||||
setId(IMID_CustomFuncResetParam);
|
setId(IMID_CustomFuncResetParam);
|
||||||
setUpdateMask(IMUE_TeleSensors);
|
setUpdateMask(IMUE_TeleSensors);
|
||||||
|
|
||||||
for (int i = 0; i < CustomFunctionData::resetParamCount(modelData); i++) {
|
for (int i = 0; i < CustomFunctionData::resetParamCount(); i++) {
|
||||||
QStandardItem * modelItem = new QStandardItem();
|
QStandardItem * modelItem = new QStandardItem();
|
||||||
modelItem->setData(i, IMDR_Id);
|
modelItem->setData(i, IMDR_Id);
|
||||||
setDynamicItemData(modelItem, i);
|
setDynamicItemData(modelItem, i);
|
||||||
@@ -459,7 +459,7 @@ void CustomFuncResetParamItemModel::setDynamicItemData(QStandardItem * item, con
|
|||||||
{
|
{
|
||||||
CustomFunctionData cfd = CustomFunctionData(AssignFunc::FuncReset);
|
CustomFunctionData cfd = CustomFunctionData(AssignFunc::FuncReset);
|
||||||
cfd.param = value;
|
cfd.param = value;
|
||||||
item->setText(cfd.paramToString(modelData));
|
item->setText(CustomFunctionData::resetToString(modelData));
|
||||||
item->setData(CustomFunctionData::isResetParamAvailable(modelData, value), IMDR_Available);
|
item->setData(CustomFunctionData::isResetParamAvailable(modelData, value), IMDR_Available);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||||
{
|
{
|
||||||
QStringList qs;
|
QStringList qs;
|
||||||
@@ -169,13 +133,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
|
|||||||
return harpicToString(param);
|
return harpicToString(param);
|
||||||
}
|
}
|
||||||
else if (func == FuncReset) {
|
else if (func == FuncReset) {
|
||||||
QComboBox cb;
|
return resetToString(model, param);
|
||||||
CustomFunctionData::populateResetParams(model, &cb);
|
|
||||||
int pos = cb.findData(param);
|
|
||||||
if (pos >= 0)
|
|
||||||
return cb.itemText(pos);
|
|
||||||
else
|
|
||||||
return QString(CPN_STR_UNKNOWN_ITEM);
|
|
||||||
}
|
}
|
||||||
else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) {
|
else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) {
|
||||||
return RawSource(param).toString(model);
|
return RawSource(param).toString(model);
|
||||||
@@ -270,12 +228,54 @@ int CustomFunctionData::funcContext(int index)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
int CustomFunctionData::resetParamCount(const ModelData * model)
|
QString CustomFunctionData::resetToString(const ModelData * model, int value)
|
||||||
{
|
{
|
||||||
QComboBox cb;
|
Firmware * firmware = getCurrentFirmware();
|
||||||
CustomFunctionData::populateResetParams(model, &cb);
|
int step = CPN_MAX_TIMERS;
|
||||||
return cb.count();
|
|
||||||
|
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
|
// static
|
||||||
|
|||||||
@@ -116,10 +116,10 @@ class CustomFunctionData {
|
|||||||
QString harpicToString() const;
|
QString harpicToString() const;
|
||||||
QString gvarAdjustModeToString() const;
|
QString gvarAdjustModeToString() const;
|
||||||
|
|
||||||
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 QString resetToString(const ModelData * model, int value);
|
||||||
|
static int resetParamCount();
|
||||||
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user