From 90ebaf2d886c187416d3c30334835530d53fa311 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sat, 18 Jul 2015 17:22:26 +0200 Subject: [PATCH] Fixes #2465 - A little bit refactoring done while fixing this one --- companion/src/helpers.cpp | 30 ++++++++ companion/src/helpers.h | 2 + companion/src/modeledit/customfunctions.cpp | 71 +++---------------- companion/src/modeledit/customfunctions.h | 1 - companion/src/modeledit/telemetry.cpp | 18 +++++ companion/src/modeledit/telemetry.h | 1 + .../src/modeledit/telemetry_customscreen.ui | 23 +++--- companion/src/shared/autocombobox.h | 2 +- 8 files changed, 76 insertions(+), 72 deletions(-) diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index a431385ec..353b9df97 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -95,6 +95,36 @@ void populateGvSourceCB(QComboBox *b, int value) b->setCurrentIndex(value); } +void populateFileComboBox(QComboBox * b, const QSet & set, const QString & current) +{ + b->addItem("----"); + + bool added = false; + // Convert set into list and sort it alphabetically case insensitive + QStringList list = QStringList::fromSet(set); + qSort(list.begin(), list.end(), caseInsensitiveLessThan); + foreach (QString entry, list) { + b->addItem(entry); + if (entry == current) { + b->setCurrentIndex(b->count()-1); + added = true; + } + } + + if (!added && !current.isEmpty()) { + b->addItem(current); + b->setCurrentIndex(b->count()-1); + } +} + +void getFileComboBoxValue(QComboBox * b, char * dest, int length) +{ + memset(dest, 0, length+1); + if (b->currentText() != "----") { + strncpy(dest, b->currentText().toAscii(), length); + } +} + QString getProtocolStr(const int proto) { static const char *strings[] = { "OFF", diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 659c718a8..69d5d56c6 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -26,6 +26,8 @@ extern const QColor colors[C9X_MAX_CURVES]; #define TRIM_MODE_NONE 0x1F // 0b11111 void populateGvSourceCB(QComboBox *b, int value); +void populateFileComboBox(QComboBox * b, const QSet & set, const QString & current); +void getFileComboBoxValue(QComboBox * b, char * dest, int length); void populateRotEncCB(QComboBox *b, int value, int renumber); QString getTheme(); diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 289def525..9ce05fba1 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -442,16 +442,9 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) else { widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; if (modified) { - memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); - int vml = firmware->getCapability(VoicesMaxLength); - if (fswtchParamArmT[i]->currentText() != "----") { - widgetsMask |= CUSTOM_FUNCTION_PLAY; - for (int j=0; jcurrentText().length(), vml); j++) { - cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j); - } - } + getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength)); } - populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet); + populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm); if (fswtchParamArmT[i]->currentText() != "----") { widgetsMask |= CUSTOM_FUNCTION_PLAY; } @@ -460,16 +453,12 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) else if (func==FuncBackgroundMusic) { widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; if (modified) { - memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); - int vml=firmware->getCapability(VoicesMaxLength); - if (fswtchParamArmT[i]->currentText() != "----") { - widgetsMask |= CUSTOM_FUNCTION_PLAY; - for (int j=0; jcurrentText().length(),vml); j++) { - cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j); - } - } + getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength)); + } + populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm); + if (fswtchParamArmT[i]->currentText() != "----") { + widgetsMask |= CUSTOM_FUNCTION_PLAY; } - populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet); } else if (func==FuncPlaySound) { if (modified) cfn.param = (uint8_t)fswtchParamT[i]->currentIndex(); @@ -485,27 +474,9 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) else if (func==FuncPlayScript) { widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; if (modified) { - memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); - int vml = 8/*TODO*/; - if (fswtchParamArmT[i]->currentText() != "----") { - for (int j=0; jcurrentText().length(), vml); j++) { - cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j); - } - } - } - populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, scriptsSet); - } - else if (func==FuncPlayScript) { - widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; - if (modified) { - memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); - int vml = 8/*TODO*/; - if (fswtchParamArmT[i]->currentText() != "----") { - for (int j=0; jcurrentText().length(), vml); j++) { - cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j); - } - } + getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, 8); } + populateFileComboBox(fswtchParamArmT[i], scriptsSet, cfn.paramarm); } else if (func==FuncBacklight && IS_TARANIS_PLUS(GetEepromInterface()->getBoard())) { if (modified) cfn.param = (uint8_t)fswtchBLcolor[i]->value(); @@ -659,30 +630,6 @@ void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value) b->setCurrentIndex(value); } -void CustomFunctionsPanel::populateFuncParamArmTCB(QComboBox *b, char * value, const QSet ¶msList) -{ - b->clear(); - b->addItem("----"); - - bool added = false; - QString currentvalue(value); - // Convert set into list and sort it alphabetically case insensitive - QStringList list = QStringList::fromSet(paramsList); - qSort(list.begin(), list.end(), caseInsensitiveLessThan); - foreach (QString entry, list) { - b->addItem(entry); - if (entry==currentvalue) { - b->setCurrentIndex(b->count()-1); - added = true; - } - } - - if (!added && strlen(value)) { - b->addItem(value); - b->setCurrentIndex(b->count()-1); - } -} - void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode) { QStringList qs; diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index 7b9775a53..4bddc7f0a 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -65,7 +65,6 @@ class CustomFunctionsPanel : public GenericPanel void populateFuncCB(QComboBox *b, unsigned int value); void populateGVmodeCB(QComboBox *b, unsigned int value); void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0); - void populateFuncParamArmTCB(QComboBox *b, char * value, const QSet & paramsList); bool initialized; QSet tracksSet; diff --git a/companion/src/modeledit/telemetry.cpp b/companion/src/modeledit/telemetry.cpp index bb9439fb9..650ba7659 100644 --- a/companion/src/modeledit/telemetry.cpp +++ b/companion/src/modeledit/telemetry.cpp @@ -340,6 +340,13 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, ui->screenType->setField(screen.type, this); lock = false; + if (IS_TARANIS(firmware->getBoard())) { + QSet scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS/TELEMETRY", QStringList() << "*.lua", 8); + populateFileComboBox(ui->scriptName, scriptsSet, screen.body.script.filename); + connect(ui->scriptName, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptNameEdited())); + connect(ui->scriptName, SIGNAL(editTextChanged ( const QString)), this, SLOT(scriptNameEdited())); + } + update(); } @@ -362,6 +369,7 @@ void TelemetryCustomScreen::update() { lock = true; + ui->scriptName->setVisible(screen.type == TELEMETRY_SCREEN_SCRIPT); ui->screenNums->setVisible(screen.type == TELEMETRY_SCREEN_NUMBERS); ui->screenBars->setVisible(screen.type == TELEMETRY_SCREEN_BARS); @@ -424,6 +432,16 @@ void TelemetryCustomScreen::on_screenType_currentIndexChanged(int index) } } +void TelemetryCustomScreen::scriptNameEdited() +{ + if (!lock) { + lock = true; + getFileComboBoxValue(ui->scriptName, screen.body.script.filename, 8); + emit modified(); + lock = false; + } +} + void TelemetryCustomScreen::customFieldChanged(int value) { if (!lock) { diff --git a/companion/src/modeledit/telemetry.h b/companion/src/modeledit/telemetry.h index f30a1cd21..cf8b4b992 100644 --- a/companion/src/modeledit/telemetry.h +++ b/companion/src/modeledit/telemetry.h @@ -60,6 +60,7 @@ class TelemetryCustomScreen: public ModelPanel private slots: void on_screenType_currentIndexChanged(int index); + void scriptNameEdited(); void customFieldChanged(int index); void barSourceChanged(int index); void barMinChanged(double value); diff --git a/companion/src/modeledit/telemetry_customscreen.ui b/companion/src/modeledit/telemetry_customscreen.ui index ea5498e03..0742b8d5d 100644 --- a/companion/src/modeledit/telemetry_customscreen.ui +++ b/companion/src/modeledit/telemetry_customscreen.ui @@ -6,8 +6,8 @@ 0 0 - 283 - 86 + 915 + 305 @@ -15,7 +15,7 @@ - + @@ -52,7 +52,14 @@ - + + + true + + + + + Qt::Horizontal @@ -70,7 +77,7 @@ - + Min @@ -80,7 +87,7 @@ - + Source @@ -90,7 +97,7 @@ - + Gauge @@ -100,7 +107,7 @@ - + Max diff --git a/companion/src/shared/autocombobox.h b/companion/src/shared/autocombobox.h index f66b6ba0d..9bc2cf2ec 100644 --- a/companion/src/shared/autocombobox.h +++ b/companion/src/shared/autocombobox.h @@ -3,7 +3,7 @@ #include #include "genericpanel.h" -#include + class AutoComboBox: public QComboBox { Q_OBJECT