fix(cpn): Model print global and special functions (#3075)
* fix(cpn): Model print global and special functions * fix(cpn): Model print sf/gf adjust gvar abbreviate further * fix(cpn): Model print gf/sf move to table format * fix(cpn): Model print gf housekeeping
This commit is contained in:
@@ -132,8 +132,11 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData
|
||||
|
||||
QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
{
|
||||
if (!isParamAvailable())
|
||||
return "";
|
||||
|
||||
QStringList qs;
|
||||
if (func <= FuncInstantTrim) {
|
||||
if ((func >= FuncOverrideCH1 && func <= FuncOverrideCHLast) || func == FuncSetScreen) {
|
||||
return QString("%1").arg(param);
|
||||
}
|
||||
else if (func == FuncLogs) {
|
||||
@@ -148,12 +151,25 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
else if (func == FuncReset) {
|
||||
return resetToString(param, model);
|
||||
}
|
||||
else if (func >= FuncSetTimer1 && func <= FuncSetTimerLast) {
|
||||
div_t qrM = div(abs(param), 60);
|
||||
div_t qrH = div(qrM.quot, 60);
|
||||
|
||||
QString val = QString("%1").arg(qrH.rem, 2, 10, QChar('0'));
|
||||
|
||||
if (qrH.quot > 0)
|
||||
val.prepend(QString("%1:").arg(qrH.quot));
|
||||
|
||||
val.append(QString(":%1").arg(qrM.rem, 2, 10, QChar('0')));
|
||||
|
||||
if (param < 0)
|
||||
val.prepend("-");
|
||||
|
||||
return val;
|
||||
}
|
||||
else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) {
|
||||
return RawSource(param).toString(model);
|
||||
}
|
||||
else if (func ==FuncSetScreen) {
|
||||
return QString("%1").arg(param);
|
||||
}
|
||||
else if (func == FuncPlayPrompt || func == FuncPlayBoth) {
|
||||
if ( getCurrentFirmware()->getCapability(VoicesAsNumbers)) {
|
||||
return QString("%1").arg(param);
|
||||
@@ -162,38 +178,48 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
return paramarm;
|
||||
}
|
||||
}
|
||||
else if (func >= FuncAdjustGV1 && func < FuncCount) {
|
||||
else if (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) {
|
||||
switch (adjustMode) {
|
||||
case FUNC_ADJUST_GVAR_CONSTANT:
|
||||
return gvarAdjustModeToString(adjustMode) + QString(" %1").arg(param);
|
||||
return QString("%1").arg(param);
|
||||
case FUNC_ADJUST_GVAR_SOURCE:
|
||||
case FUNC_ADJUST_GVAR_GVAR:
|
||||
return RawSource(param).toString();
|
||||
case FUNC_ADJUST_GVAR_INCDEC:
|
||||
const float val = param * model->gvarData[func - FuncAdjustGV1].multiplierGet();
|
||||
const QString unit = model->gvarData[func - FuncAdjustGV1].unitToString();
|
||||
return gvarAdjustModeToString(adjustMode) + QString(": %1%2").arg(val).arg(unit);
|
||||
return QString("%1= %2%3").arg(val < 0 ? "-" : "+").arg(abs(val)).arg(unit);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
QString CustomFunctionData::repeatToString() const
|
||||
QString CustomFunctionData::repeatToString(const bool abbrev) const
|
||||
{
|
||||
return repeatToString(repeatParam);
|
||||
return repeatToString(repeatParam, func, abbrev);
|
||||
}
|
||||
|
||||
// static
|
||||
QString CustomFunctionData::repeatToString(const int value)
|
||||
QString CustomFunctionData::repeatToString(const int value, const AssignFunc func, const bool abbrev)
|
||||
{
|
||||
if (!isRepeatParamAvailable(func))
|
||||
return "";
|
||||
|
||||
return repeatToString(value, abbrev);
|
||||
}
|
||||
|
||||
// static
|
||||
QString CustomFunctionData::repeatToString(const int value, const bool abbrev)
|
||||
{
|
||||
if (value == -1) {
|
||||
return tr("Played once, not during startup");
|
||||
return abbrev ? tr("!1x") : tr("Played once, not during startup");
|
||||
}
|
||||
else if (value == 0) {
|
||||
return tr("No repeat");
|
||||
return abbrev ? tr("1x") : tr("No repeat");
|
||||
}
|
||||
else {
|
||||
return tr("Repeat %1s").arg(value);
|
||||
return abbrev ? tr("%1s").arg(value) : tr("Repeat %1s").arg(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +387,7 @@ AbstractStaticItemModel * CustomFunctionData::repeatItemModel()
|
||||
mdl->setName("customfunctiondata.repeat");
|
||||
|
||||
for (int i = -1; i <= 60; i++) {
|
||||
mdl->appendToItemList(repeatToString(i), i);
|
||||
mdl->appendToItemList(repeatToString(i, false), i);
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
@@ -409,3 +435,49 @@ AbstractStaticItemModel * CustomFunctionData::gvarAdjustModeItemModel()
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
bool CustomFunctionData::isParamAvailable() const
|
||||
{
|
||||
// not available list
|
||||
const QList<AssignFunc> funcList = {
|
||||
FuncTrainer,
|
||||
FuncTrainerRUD,
|
||||
FuncTrainerELE,
|
||||
FuncTrainerTHR,
|
||||
FuncTrainerAIL,
|
||||
FuncTrainerChannels,
|
||||
FuncInstantTrim,
|
||||
FuncVario,
|
||||
FuncScreenshot,
|
||||
FuncBackgroundMusicPause,
|
||||
FuncSetFailsafe,
|
||||
FuncRangeCheckInternalModule,
|
||||
FuncRangeCheckExternalModule,
|
||||
FuncBindInternalModule,
|
||||
FuncBindExternalModule,
|
||||
FuncRacingMode,
|
||||
FuncDisableTouch
|
||||
};
|
||||
|
||||
return funcList.contains(func) ? false : true;
|
||||
}
|
||||
|
||||
bool CustomFunctionData::isRepeatParamAvailable() const
|
||||
{
|
||||
return isRepeatParamAvailable(func);
|
||||
}
|
||||
|
||||
// static
|
||||
bool CustomFunctionData::isRepeatParamAvailable(const AssignFunc func)
|
||||
{
|
||||
const QList<AssignFunc> funcList = {
|
||||
FuncPlaySound,
|
||||
FuncPlayHaptic,
|
||||
FuncPlayValue,
|
||||
FuncPlayPrompt,
|
||||
FuncPlayBoth,
|
||||
FuncSetScreen
|
||||
};
|
||||
|
||||
return funcList.contains(func) ? true : false;
|
||||
}
|
||||
|
||||
@@ -112,11 +112,13 @@ class CustomFunctionData {
|
||||
bool isEmpty() const;
|
||||
QString funcToString(const ModelData * model = nullptr) const;
|
||||
QString paramToString(const ModelData * model = nullptr) const;
|
||||
QString repeatToString() const;
|
||||
QString repeatToString(const bool abbrev) const;
|
||||
QString enabledToString() const;
|
||||
QString playSoundToString() const;
|
||||
QString harpicToString() const;
|
||||
QString gvarAdjustModeToString() const;
|
||||
bool isRepeatParamAvailable() const;
|
||||
bool isParamAvailable() const;
|
||||
|
||||
static QString nameToString(const int index, const bool globalContext = false);
|
||||
static QString funcToString(const AssignFunc func, const ModelData * model = nullptr);
|
||||
@@ -125,7 +127,9 @@ class CustomFunctionData {
|
||||
static QString resetToString(const int value, const ModelData * model = nullptr);
|
||||
static int resetParamCount();
|
||||
static bool isResetParamAvailable(const int index, const ModelData * model = nullptr);
|
||||
static QString repeatToString(const int value);
|
||||
static QString repeatToString(const int value, const AssignFunc func, const bool abbrev);
|
||||
static QString repeatToString(const int value, const bool abbrev);
|
||||
static bool isRepeatParamAvailable(const AssignFunc func);
|
||||
static QStringList playSoundStringList();
|
||||
static QString playSoundToString(const int value);
|
||||
static QString harpicToString(const int value);
|
||||
|
||||
@@ -619,30 +619,6 @@ QString ModelPrinter::printLogicalSwitchLine(int idx)
|
||||
return result;
|
||||
}
|
||||
|
||||
QString ModelPrinter::printCustomFunctionLine(int idx, bool gfunc)
|
||||
{
|
||||
QString result;
|
||||
CustomFunctionData cf;
|
||||
if (gfunc) {
|
||||
if (model.noGlobalFunctions)
|
||||
return result;
|
||||
cf = generalSettings.customFn[idx];
|
||||
}
|
||||
else
|
||||
cf = model.customFn[idx];
|
||||
if (cf.swtch.type == SWITCH_TYPE_NONE)
|
||||
return result;
|
||||
|
||||
result += cf.swtch.toString(getCurrentBoard(), &generalSettings) + " - ";
|
||||
result += cf.funcToString(&model) + " (";
|
||||
result += cf.paramToString(&model) + ")";
|
||||
if (!cf.repeatToString().isEmpty())
|
||||
result += " " + cf.repeatToString();
|
||||
if (!cf.enabledToString().isEmpty())
|
||||
result += " " + cf.enabledToString();
|
||||
return result;
|
||||
}
|
||||
|
||||
QString ModelPrinter::printCurveName(int idx)
|
||||
{
|
||||
return model.curves[idx].nameToString(idx).toHtmlEscaped();
|
||||
|
||||
@@ -58,7 +58,6 @@ class ModelPrinter: public QObject
|
||||
QString printInputLine(const ExpoData & ed);
|
||||
QString printMixerLine(const MixData & md, bool showMultiplex, int highlightedSource = 0);
|
||||
QString printLogicalSwitchLine(int idx);
|
||||
QString printCustomFunctionLine(int idx, bool gfunc = false);
|
||||
QString printChannelName(int idx);
|
||||
QString printCurveName(int idx);
|
||||
QString printCurve(int idx);
|
||||
@@ -103,6 +102,7 @@ class ModelPrinter: public QObject
|
||||
QString printTelemetryScreenType(unsigned int val);
|
||||
QString printTelemetryScreen(unsigned int idx, unsigned int line, unsigned int width);
|
||||
QString printChecklist();
|
||||
const GeneralSettings * gs() { return &generalSettings; }
|
||||
|
||||
private:
|
||||
Firmware * firmware;
|
||||
|
||||
@@ -190,7 +190,8 @@ void MultiModelPrinter::MultiColumns::appendFieldSeparator(const bool sep)
|
||||
for (int cc=0; cc < modelPrinterMap.size(); cc++) { \
|
||||
ModelPrinter * modelPrinter = modelPrinterMap.value(cc).second; \
|
||||
const ModelData * model = modelPrinterMap.value(cc).first; \
|
||||
(void)(model); (void)(modelPrinter); \
|
||||
const GeneralSettings * generalSettings = modelPrinter->gs(); \
|
||||
(void)(model); (void)(modelPrinter); (void)(generalSettings); \
|
||||
columns.append(cc, (what)); \
|
||||
} \
|
||||
columns.endCompare();
|
||||
@@ -729,6 +730,8 @@ QString MultiModelPrinter::printSpecialFunctions()
|
||||
MultiColumns columns(modelPrinterMap.size());
|
||||
int count = 0;
|
||||
columns.appendSectionTableStart();
|
||||
columns.appendRowHeader(QStringList() << "" << tr("Switch") << tr("Function") << tr("Parameters") << tr("Repeat") << tr("Enabled"));
|
||||
|
||||
for (int i=0; i < firmware->getCapability(CustomFunctions); i++) {
|
||||
bool sfEmpty = true;
|
||||
for (int k=0; k < modelPrinterMap.size(); k++) {
|
||||
@@ -739,8 +742,12 @@ QString MultiModelPrinter::printSpecialFunctions()
|
||||
}
|
||||
if (!sfEmpty) {
|
||||
count++;
|
||||
columns.appendRowStart(tr("SF%1").arg(i+1), 20);
|
||||
COMPARECELL(modelPrinter->printCustomFunctionLine(i));
|
||||
columns.appendRowStart(tr("SF%1").arg(i + 1), 20);
|
||||
COMPARECELLWIDTH(!model->customFn[i].isEmpty() ? model->customFn[i].swtch.toString(getCurrentBoard(), &defaultSettings, model) : "", 10);
|
||||
COMPARECELLWIDTH(!model->customFn[i].isEmpty() ? model->customFn[i].funcToString(model) : "", 20);
|
||||
COMPARECELLWIDTH(!model->customFn[i].isEmpty() ? model->customFn[i].paramToString(model) : "", 20);
|
||||
COMPARECELLWIDTH(!model->customFn[i].isEmpty() ? model->customFn[i].repeatToString(true) : "", 10);
|
||||
COMPARECELLWIDTH(!model->customFn[i].isEmpty() ? DataHelpers::boolToString(model->customFn[i].enabled, DataHelpers::BOOL_FMT_YN) : "", 10);
|
||||
columns.appendRowEnd();
|
||||
}
|
||||
}
|
||||
@@ -894,6 +901,7 @@ QString MultiModelPrinter::printGlobalFunctions()
|
||||
int idx = -1;
|
||||
MultiColumns columns(modelPrinterMap.size());
|
||||
columns.appendSectionTableStart();
|
||||
columns.appendRowHeader(QStringList() << "" << tr("Switch") << tr("Function") << tr("Parameters") << tr("Repeat") << tr("Enabled"));
|
||||
|
||||
for (int k=0; k < modelPrinterMap.size(); k++) {
|
||||
if (!modelPrinterMap.value(k).first->noGlobalFunctions) {
|
||||
@@ -904,13 +912,18 @@ QString MultiModelPrinter::printGlobalFunctions()
|
||||
|
||||
if (idx > -1) {
|
||||
ModelPrinter * modelPrinter = modelPrinterMap.value(idx).second;
|
||||
(void)(modelPrinter);
|
||||
const GeneralSettings * generalSettings = modelPrinter->gs();
|
||||
|
||||
for (int i=0; i < firmware->getCapability(GlobalFunctions); i++) {
|
||||
txt = modelPrinter->printCustomFunctionLine(i, true);
|
||||
if (!txt.isEmpty()) {
|
||||
for (int i = 0; i < firmware->getCapability(GlobalFunctions); i++) {
|
||||
if (!generalSettings->customFn[i].isEmpty()) {
|
||||
count++;
|
||||
ROWLABELCOMPARECELL(tr("GF%1").arg(i+1), 20, modelPrinter->printCustomFunctionLine(i, true), 80);
|
||||
columns.appendRowStart(tr("GF%1").arg(i + 1), 20);
|
||||
COMPARECELLWIDTH(generalSettings->customFn[i].swtch.toString(getCurrentBoard(), &defaultSettings), 10);
|
||||
COMPARECELLWIDTH(generalSettings->customFn[i].funcToString(), 20);
|
||||
COMPARECELLWIDTH(generalSettings->customFn[i].paramToString(), 20);
|
||||
COMPARECELLWIDTH(generalSettings->customFn[i].repeatToString(true), 10);
|
||||
COMPARECELLWIDTH(DataHelpers::boolToString(generalSettings->customFn[i].enabled, DataHelpers::BOOL_FMT_YN), 10);
|
||||
columns.appendRowEnd();
|
||||
}
|
||||
}
|
||||
columns.appendTableEnd();
|
||||
@@ -942,8 +955,7 @@ QString MultiModelPrinter::printChecklist()
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
QString MultiModelPrinter::printFunctionSwitches()
|
||||
QString MultiModelPrinter::printFunctionSwitches()
|
||||
{
|
||||
QString str;
|
||||
MultiColumns columns(modelPrinterMap.size());
|
||||
|
||||
Reference in New Issue
Block a user