1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-16 21:05:26 +03:00

Fixes #2465 - A little bit refactoring done while fixing this one

This commit is contained in:
bsongis 2015-07-18 17:22:26 +02:00
parent 2b804f92b5
commit 90ebaf2d88
8 changed files with 76 additions and 72 deletions

View file

@ -95,6 +95,36 @@ void populateGvSourceCB(QComboBox *b, int value)
b->setCurrentIndex(value); b->setCurrentIndex(value);
} }
void populateFileComboBox(QComboBox * b, const QSet<QString> & 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) QString getProtocolStr(const int proto)
{ {
static const char *strings[] = { "OFF", static const char *strings[] = { "OFF",

View file

@ -26,6 +26,8 @@ extern const QColor colors[C9X_MAX_CURVES];
#define TRIM_MODE_NONE 0x1F // 0b11111 #define TRIM_MODE_NONE 0x1F // 0b11111
void populateGvSourceCB(QComboBox *b, int value); void populateGvSourceCB(QComboBox *b, int value);
void populateFileComboBox(QComboBox * b, const QSet<QString> & set, const QString & current);
void getFileComboBoxValue(QComboBox * b, char * dest, int length);
void populateRotEncCB(QComboBox *b, int value, int renumber); void populateRotEncCB(QComboBox *b, int value, int renumber);
QString getTheme(); QString getTheme();

View file

@ -442,16 +442,9 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
else { else {
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
if (modified) { if (modified) {
memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
int vml = firmware->getCapability(VoicesMaxLength);
if (fswtchParamArmT[i]->currentText() != "----") {
widgetsMask |= CUSTOM_FUNCTION_PLAY;
for (int j=0; j<std::min(fswtchParamArmT[i]->currentText().length(), vml); j++) {
cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j);
}
}
} }
populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet); populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
if (fswtchParamArmT[i]->currentText() != "----") { if (fswtchParamArmT[i]->currentText() != "----") {
widgetsMask |= CUSTOM_FUNCTION_PLAY; widgetsMask |= CUSTOM_FUNCTION_PLAY;
} }
@ -460,16 +453,12 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
else if (func==FuncBackgroundMusic) { else if (func==FuncBackgroundMusic) {
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
if (modified) { if (modified) {
memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
int vml=firmware->getCapability(VoicesMaxLength); }
if (fswtchParamArmT[i]->currentText() != "----") { populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
widgetsMask |= CUSTOM_FUNCTION_PLAY; if (fswtchParamArmT[i]->currentText() != "----") {
for (int j=0; j<std::min(fswtchParamArmT[i]->currentText().length(),vml); j++) { widgetsMask |= CUSTOM_FUNCTION_PLAY;
cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j);
}
}
} }
populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet);
} }
else if (func==FuncPlaySound) { else if (func==FuncPlaySound) {
if (modified) cfn.param = (uint8_t)fswtchParamT[i]->currentIndex(); if (modified) cfn.param = (uint8_t)fswtchParamT[i]->currentIndex();
@ -485,27 +474,9 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
else if (func==FuncPlayScript) { else if (func==FuncPlayScript) {
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
if (modified) { if (modified) {
memset(cfn.paramarm, 0, sizeof(cfn.paramarm)); getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, 8);
int vml = 8/*TODO*/;
if (fswtchParamArmT[i]->currentText() != "----") {
for (int j=0; j<std::min(fswtchParamArmT[i]->currentText().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; j<std::min(fswtchParamArmT[i]->currentText().length(), vml); j++) {
cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j);
}
}
} }
populateFileComboBox(fswtchParamArmT[i], scriptsSet, cfn.paramarm);
} }
else if (func==FuncBacklight && IS_TARANIS_PLUS(GetEepromInterface()->getBoard())) { else if (func==FuncBacklight && IS_TARANIS_PLUS(GetEepromInterface()->getBoard())) {
if (modified) cfn.param = (uint8_t)fswtchBLcolor[i]->value(); if (modified) cfn.param = (uint8_t)fswtchBLcolor[i]->value();
@ -659,30 +630,6 @@ void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value)
b->setCurrentIndex(value); b->setCurrentIndex(value);
} }
void CustomFunctionsPanel::populateFuncParamArmTCB(QComboBox *b, char * value, const QSet<QString> &paramsList)
{
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) void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode)
{ {
QStringList qs; QStringList qs;

View file

@ -65,7 +65,6 @@ class CustomFunctionsPanel : public GenericPanel
void populateFuncCB(QComboBox *b, unsigned int value); void populateFuncCB(QComboBox *b, unsigned int value);
void populateGVmodeCB(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 populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
void populateFuncParamArmTCB(QComboBox *b, char * value, const QSet<QString> & paramsList);
bool initialized; bool initialized;
QSet<QString> tracksSet; QSet<QString> tracksSet;

View file

@ -340,6 +340,13 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
ui->screenType->setField(screen.type, this); ui->screenType->setField(screen.type, this);
lock = false; lock = false;
if (IS_TARANIS(firmware->getBoard())) {
QSet<QString> 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(); update();
} }
@ -362,6 +369,7 @@ void TelemetryCustomScreen::update()
{ {
lock = true; lock = true;
ui->scriptName->setVisible(screen.type == TELEMETRY_SCREEN_SCRIPT);
ui->screenNums->setVisible(screen.type == TELEMETRY_SCREEN_NUMBERS); ui->screenNums->setVisible(screen.type == TELEMETRY_SCREEN_NUMBERS);
ui->screenBars->setVisible(screen.type == TELEMETRY_SCREEN_BARS); 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) void TelemetryCustomScreen::customFieldChanged(int value)
{ {
if (!lock) { if (!lock) {

View file

@ -60,6 +60,7 @@ class TelemetryCustomScreen: public ModelPanel
private slots: private slots:
void on_screenType_currentIndexChanged(int index); void on_screenType_currentIndexChanged(int index);
void scriptNameEdited();
void customFieldChanged(int index); void customFieldChanged(int index);
void barSourceChanged(int index); void barSourceChanged(int index);
void barMinChanged(double value); void barMinChanged(double value);

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>283</width> <width>915</width>
<height>86</height> <height>305</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,7 +15,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="screenScript" stretch="0,0,1"> <layout class="QHBoxLayout" name="screenScript" stretch="0,0,0,1">
<item> <item>
<widget class="QLabel" name="screenTypeLabel"> <widget class="QLabel" name="screenTypeLabel">
<property name="sizePolicy"> <property name="sizePolicy">
@ -52,7 +52,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_16"> <widget class="QComboBox" name="scriptName">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -70,7 +77,7 @@
<widget class="QGroupBox" name="screenBars"> <widget class="QGroupBox" name="screenBars">
<layout class="QGridLayout" name="screenBarsLayout" columnstretch="1,0,1,0"> <layout class="QGridLayout" name="screenBarsLayout" columnstretch="1,0,1,0">
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_266"> <widget class="QLabel" name="minLabel">
<property name="text"> <property name="text">
<string>Min</string> <string>Min</string>
</property> </property>
@ -80,7 +87,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_265"> <widget class="QLabel" name="sourceLabel">
<property name="text"> <property name="text">
<string>Source</string> <string>Source</string>
</property> </property>
@ -90,7 +97,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QLabel" name="label_267"> <widget class="QLabel" name="gaugeLabel">
<property name="text"> <property name="text">
<string>Gauge</string> <string>Gauge</string>
</property> </property>
@ -100,7 +107,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="0" column="3">
<widget class="QLabel" name="label_268"> <widget class="QLabel" name="maxLabel">
<property name="text"> <property name="text">
<string>Max</string> <string>Max</string>
</property> </property>

View file

@ -3,7 +3,7 @@
#include <QComboBox> #include <QComboBox>
#include "genericpanel.h" #include "genericpanel.h"
#include <QDebug>
class AutoComboBox: public QComboBox class AutoComboBox: public QComboBox
{ {
Q_OBJECT Q_OBJECT