From 19cb9ef4414c757cdc25c9c65440a6d276f6bb5b Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 13 Dec 2020 21:02:28 +1100 Subject: [PATCH] Model printer use adjust ref toString function --- companion/src/helpers.cpp | 20 ---------------- companion/src/helpers.h | 1 - companion/src/modelprinter.cpp | 44 +++++++++++++++++----------------- 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index b18dcaf0e..020f1b45b 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -235,26 +235,6 @@ void Helpers::populateGVCB(QComboBox & b, int value, const ModelData & model) b.setCurrentIndex(count); } -// Returns Diff/Expo/Weight/Offset adjustment value as either a percentage or a global variable name. -QString Helpers::getAdjustmentString(int16_t val, const ModelData * model, bool sign) -{ - QString ret; - if (val >= -10000 && val <= 10000) { - ret = "%1%"; - if (sign && val > 0) - ret.prepend("+"); - ret = ret.arg(val); - } - else { - ret = RawSource(SOURCE_TYPE_GVAR, abs(val) - 10001).toString(model); - if (val < 0) - ret.prepend("-"); - else if (sign) - ret.prepend("+"); - } - return ret; -} - // TODO: Move lookup to GVarData class (w/out combobox) void Helpers::populateGvarUseCB(QComboBox * b, unsigned int phase) { diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 25e4611ae..107ca2aa0 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -102,7 +102,6 @@ namespace Helpers { void populateGvarUseCB(QComboBox *b, unsigned int phase); void populateGVCB(QComboBox & b, int value, const ModelData & model); - QString getAdjustmentString(int16_t val, const ModelData * model = NULL, bool sign = false); void populateFileComboBox(QComboBox * b, const QSet & set, const QString & current); void getFileComboBoxValue(QComboBox * b, char * dest, int length); diff --git a/companion/src/modelprinter.cpp b/companion/src/modelprinter.cpp index 5e5d7a349..61bfedda9 100644 --- a/companion/src/modelprinter.cpp +++ b/companion/src/modelprinter.cpp @@ -24,6 +24,7 @@ #include "boards.h" #include "helpers_html.h" #include "appdata.h" +#include "adjustmentreference.h" #include #include @@ -396,7 +397,7 @@ QString ModelPrinter::printInputLine(const ExpoData & input) str += input.srcRaw.toString(&model, &generalSettings).toHtmlEscaped(); } - str += " " + tr("Weight").toHtmlEscaped() + QString("(%1)").arg(Helpers::getAdjustmentString(input.weight, &model, true).toHtmlEscaped()); + str += " " + tr("Weight(%1)").arg(AdjustmentReference(input.weight).toString(&model, true)).toHtmlEscaped(); if (input.curve.value) str += " " + input.curve.toString(&model).toHtmlEscaped(); @@ -405,19 +406,18 @@ QString ModelPrinter::printInputLine(const ExpoData & input) str += " " + flightModesStr.toHtmlEscaped(); if (input.swtch.type != SWITCH_TYPE_NONE) - str += " " + tr("Switch").toHtmlEscaped() + QString("(%1)").arg(input.swtch.toString(getCurrentBoard(), &generalSettings)).toHtmlEscaped(); + str += " " + tr("Switch(%1)").arg(input.swtch.toString(getCurrentBoard(), &generalSettings)).toHtmlEscaped(); if (firmware->getCapability(VirtualInputs)) { - if (input.carryTrim>0) - str += " " + tr("NoTrim").toHtmlEscaped(); - else if (input.carryTrim<0) - str += " " + RawSource(SOURCE_TYPE_TRIM, (-(input.carryTrim)-1)).toString(&model, &generalSettings).toHtmlEscaped(); + if (input.carryTrim > 0) + str += " " + tr("NoTrim"); + else if (input.carryTrim < 0) + str += " " + RawSource(SOURCE_TYPE_TRIM, (-(input.carryTrim) - 1)).toString(&model, &generalSettings).toHtmlEscaped(); } if (input.offset) - str += " " + tr("Offset(%1)").arg(Helpers::getAdjustmentString(input.offset, &model)).toHtmlEscaped(); - + str += " " + tr("Offset(%1)").arg(AdjustmentReference(input.offset).toString(&model)).toHtmlEscaped(); if (firmware->getCapability(HasExpoNames) && input.name[0]) str += QString(" [%1]").arg(input.name).toHtmlEscaped(); @@ -440,7 +440,7 @@ QString ModelPrinter::printMixerLine(const MixData & mix, bool showMultiplex, in } // highlight source if needed QString source = mix.srcRaw.toString(&model, &generalSettings).toHtmlEscaped(); - if ( (mix.srcRaw.type == SOURCE_TYPE_CH) && (mix.srcRaw.index+1 == (int)highlightedSource) ) { + if ( (mix.srcRaw.type == SOURCE_TYPE_CH) && (mix.srcRaw.index + 1 == (int)highlightedSource) ) { source = "" + source + ""; } str += " " + source; @@ -448,35 +448,35 @@ QString ModelPrinter::printMixerLine(const MixData & mix, bool showMultiplex, in if (mix.mltpx == MLTPX_MUL && !showMultiplex) str += " " + tr("MULT!").toHtmlEscaped(); else - str += " " + tr("Weight") + QString("(%1)").arg(Helpers::getAdjustmentString(mix.weight, &model, true)).toHtmlEscaped(); + str += " " + tr("Weight(%1)").arg(AdjustmentReference(mix.weight).toString(&model, true)).toHtmlEscaped(); QString flightModesStr = printFlightModes(mix.flightModes); if (!flightModesStr.isEmpty()) str += " " + flightModesStr.toHtmlEscaped(); if (mix.swtch.type != SWITCH_TYPE_NONE) - str += " " + tr("Switch") + QString("(%1)").arg(mix.swtch.toString(getCurrentBoard(), &generalSettings)).toHtmlEscaped(); + str += " " + tr("Switch(%1)").arg(mix.swtch.toString(getCurrentBoard(), &generalSettings)).toHtmlEscaped(); if (mix.carryTrim > 0) - str += " " + tr("NoTrim").toHtmlEscaped(); + str += " " + tr("NoTrim"); else if (mix.carryTrim < 0) str += " " + RawSource(SOURCE_TYPE_TRIM, (-(mix.carryTrim)-1)).toString(&model, &generalSettings); if (firmware->getCapability(HasNoExpo) && mix.noExpo) str += " " + tr("No DR/Expo").toHtmlEscaped(); if (mix.sOffset) - str += " " + tr("Offset") + QString("(%1)").arg(Helpers::getAdjustmentString(mix.sOffset, &model)).toHtmlEscaped(); + str += " " + tr("Offset(%1)").arg(AdjustmentReference(mix.sOffset).toString(&model)).toHtmlEscaped(); if (mix.curve.value) str += " " + mix.curve.toString(&model).toHtmlEscaped(); int scale = firmware->getCapability(SlowScale); if (scale == 0) scale = 1; if (mix.delayDown || mix.delayUp) - str += " " + tr("Delay") + QString("(u%1:d%2)").arg((double)mix.delayUp/scale).arg((double)mix.delayDown/scale).toHtmlEscaped(); + str += " " + tr("Delay(u%1:d%2)").arg((double)mix.delayUp / scale).arg((double)mix.delayDown / scale).toHtmlEscaped(); if (mix.speedDown || mix.speedUp) - str += " " + tr("Slow") + QString("(u%1:d%2)").arg((double)mix.speedUp/scale).arg((double)mix.speedDown/scale).toHtmlEscaped(); + str += " " + tr("Slow(u%1:d%2)").arg((double)mix.speedUp / scale).arg((double)mix.speedDown / scale).toHtmlEscaped(); if (mix.mixWarn) - str += " " + tr("Warn") + QString("(%1)").arg(mix.mixWarn).toHtmlEscaped(); + str += " " + tr("Warn(%1)").arg(mix.mixWarn).toHtmlEscaped(); if (firmware->getCapability(HasMixerNames) && mix.name[0]) str += QString(" [%1]").arg(mix.name).toHtmlEscaped(); return str; @@ -496,13 +496,13 @@ QString ModelPrinter::printFlightModes(unsigned int flightModes) { int numFlightModes = firmware->getCapability(FlightModes); if (numFlightModes && flightModes) { - if (flightModes == (unsigned int)(1<getCapability(FlightModes); if (numFlightModes && flightModes) { - if (flightModes == (unsigned int)(1<