feat(color): key shortcuts and quick menu favorites can be set to run stand alone Lua tools (#7083)

Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
philmoz
2026-02-20 13:53:36 +10:00
committed by GitHub
co-authored by elecpower
parent bcb154c0e2
commit 044c2a08d8
44 changed files with 1235 additions and 367 deletions
@@ -178,6 +178,7 @@ static const YamlLookupTable QMPageLut = {
{ GeneralSettings::QM_TOOLS_LS_MON, "TOOLS_LS_MON" },
{ GeneralSettings::QM_TOOLS_STATS, "TOOLS_STATS" },
{ GeneralSettings::QM_TOOLS_DEBUG, "TOOLS_DEBUG" },
{ GeneralSettings::QM_APP, "APP" },
};
YamlTelemetryBaudrate::YamlTelemetryBaudrate(
@@ -393,11 +394,25 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
if (hasColorLcd) {
for (int i = 0; i < MAX_KEYSHORTCUTS; i += 1)
if (rhs.keyShortcuts[i] != GeneralSettings::QM_NONE)
node["keyShortcuts"][std::to_string(i)]["shortcut"] = QMPageLut << rhs.keyShortcuts[i];
if (rhs.keyShortcuts[i] != GeneralSettings::QM_NONE) {
if (rhs.keyShortcuts[i] != GeneralSettings::QM_APP) {
node["keyShortcuts"][std::to_string(i)]["shortcut"] = QMPageLut << rhs.keyShortcuts[i];
} else {
std::string s("APP,");
s += rhs.keyShortcutTools[i];
node["keyShortcuts"][std::to_string(i)]["shortcut"] = s;
}
}
for (int i = 0; i < MAX_QMFAVOURITES; i += 1)
if (rhs.qmFavorites[i] != GeneralSettings::QM_NONE)
node["qmFavorites"][std::to_string(i)]["shortcut"] = QMPageLut << rhs.qmFavorites[i];
if (rhs.qmFavorites[i] != GeneralSettings::QM_NONE) {
if (rhs.qmFavorites[i] != GeneralSettings::QM_APP) {
node["qmFavorites"][std::to_string(i)]["shortcut"] = QMPageLut << rhs.qmFavorites[i];
} else {
std::string s("APP,");
s += rhs.qmFavoritesTools[i];
node["qmFavorites"][std::to_string(i)]["shortcut"] = s;
}
}
}
return node;
@@ -726,13 +741,35 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
node["favMultiMode"] >> rhs.favMultiMode;
if (node["keyShortcuts"]) {
for (int i = 0; i < MAX_KEYSHORTCUTS; i += 1)
node["keyShortcuts"][std::to_string(i)]["shortcut"] >> QMPageLut >> rhs.keyShortcuts[i];
for (int i = 0; i < MAX_KEYSHORTCUTS; i += 1) {
std::string val = node["keyShortcuts"][std::to_string(i)]["shortcut"].as<std::string>();
if (rhs.keyShortcutTools[i]) delete rhs.keyShortcutTools[i];
if (val.substr(0, 4) == "APP,") {
rhs.keyShortcuts[i] = GeneralSettings::QM_APP;
rhs.keyShortcutTools[i] = new char[val.size() - 3];
strncpy(rhs.keyShortcutTools[i], val.substr(4).c_str(), val.size() - 4);
rhs.keyShortcutTools[i][val.size() - 4] = 0;
} else {
node["keyShortcuts"][std::to_string(i)]["shortcut"] >> QMPageLut >> rhs.keyShortcuts[i];
rhs.keyShortcutTools[i] = nullptr;
}
}
}
if (node["qmFavorites"]) {
for (int i = 0; i < MAX_QMFAVOURITES; i += 1)
if (node["qmFavorites"][std::to_string(i)])
if (node["qmFavorites"][std::to_string(i)]) {
std::string val = node["qmFavorites"][std::to_string(i)]["shortcut"].as<std::string>();
if (rhs.qmFavoritesTools[i]) delete rhs.qmFavoritesTools[i];
if (val.substr(0, 4) == "APP,") {
rhs.qmFavorites[i] = GeneralSettings::QM_APP;
rhs.qmFavoritesTools[i] = new char[val.size() - 3];
strncpy(rhs.qmFavoritesTools[i], val.substr(4).c_str(), val.size() - 4);
rhs.qmFavoritesTools[i][val.size() - 4] = 0;
} else {
node["qmFavorites"][std::to_string(i)]["shortcut"] >> QMPageLut >> rhs.qmFavorites[i];
rhs.qmFavoritesTools[i] = nullptr;
}
}
}
// override critical settings after import
@@ -1061,6 +1061,9 @@ QString GeneralSettings::quickMenuToString(int value, bool keys)
return tr("Tools - Statistics");
case QM_TOOLS_DEBUG:
return tr("Tools - Debug");
// Lua stand alone script
case QM_APP:
return tr("App");
default:
return CPN_STR_UNKNOWN_ITEM;
}
@@ -276,6 +276,8 @@ class GeneralSettings {
QM_TOOLS_LS_MON,
QM_TOOLS_STATS,
QM_TOOLS_DEBUG,
// Lua stand alone script
QM_APP,
QM_COUNT,
};
@@ -451,7 +453,9 @@ class GeneralSettings {
SwitchConfig switchConfig[CPN_MAX_SWITCHES];
unsigned int keyShortcuts[MAX_KEYSHORTCUTS];
char* keyShortcutTools[MAX_KEYSHORTCUTS];
unsigned int qmFavorites[MAX_QMFAVOURITES];
char* qmFavoritesTools[MAX_QMFAVOURITES];
void switchConfigClear();
+120 -7
View File
@@ -23,6 +23,7 @@
#include "autocombobox.h"
#include "compounditemmodels.h"
#include "exclusivecombogroup.h"
#include "helpers.h"
#include <QLabel>
#include <QGridLayout>
@@ -32,22 +33,76 @@ GeneralFavsPanel::GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSe
board(firmware->getBoard()),
params(new QList<QWidget *>),
row(0),
col(0)
col(0),
lock(true),
cboFavTools(new QList<AutoComboBox *>),
strFavTools(new QList<QString *>)
{
grid = new QGridLayout(this);
// All values except QM_NONE are mutually exclusive
cboQMGrp = new ExclusiveComboGroup(this,
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE; });
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE ||
value == GeneralSettings::QM_APP; });
const int cnt = firmware->getCapability(QMFavourites);
// add lua tool scripts from radio profile sdcard
QStringList toolsSet = getListLuaTools();
QStandardItemModel *mdl = new QStandardItemModel(this);
for (int i = 0; i < toolsSet.size(); i++) {
QStandardItem *item = new QStandardItem(toolsSet[i]);
mdl->appendRow(item);
}
// Ensure existing configured tool is included in toolsSet as the radio profile
// sdcard contents may not match radio
for (int i = 0; i < cnt; i++) {
if (generalSettings.qmFavorites[i] == GeneralSettings::QM_APP) {
QString temp(generalSettings.qmFavoritesTools[i]);
if (!temp.isEmpty() && mdl->findItems(temp).size() < 1) {
QStandardItem *item = new QStandardItem(temp);
mdl->appendRow(item);
}
}
}
QSortFilterProxyModel *mdlTools = new QSortFilterProxyModel(this);
mdlTools->setSourceModel(mdl);
mdlTools->setSortCaseSensitivity(Qt::CaseInsensitive);
mdlTools->setFilterKeyColumn(0);
mdlTools->sort(0);
for (int i = 0; i < cnt; i++) {
addLabel(tr("# %1").arg(i + 1));
AutoComboBox *cbo = new AutoComboBox(this);
AutoComboBox *cboFav = new AutoComboBox(this);
cboFav->setProperty("index", i);
// separate item model per combo box due to mutual exclusivity
cbo->setModel(generalSettings.quickMenuItemModel(false));
cbo->setField(generalSettings.qmFavorites[i], this);
cboQMGrp->addCombo(cbo);
params->append(cbo);
cboFav->setModel(generalSettings.quickMenuItemModel(false));
cboFav->setField(generalSettings.qmFavorites[i], this);
connect(cboFav, &AutoComboBox::currentDataChanged, this, &GeneralFavsPanel::on_favChanged);
cboQMGrp->addCombo(cboFav);
params->append(cboFav);
AutoComboBox *cboFavTool = new AutoComboBox(this);
cboFavTool->setProperty("index", i);
cboFavTool->setModel(mdlTools);
// AutoComboBox does not support char * so use a proxy
QString *str = new QString(generalSettings.qmFavoritesTools[i]);
strFavTools->append(str);
cboFavTool->setField(*str, this);
if (generalSettings.qmFavorites[i] == GeneralSettings::QM_APP) {
if (cboFavTool->currentIndex() < 0)
cboFavTool->setCurrentIndex(0);
cboFavTool->setVisible(true);
} else {
cboFavTool->setCurrentIndex(0);
cboFavTool->setVisible(false);
}
connect(cboFavTool, &AutoComboBox::currentDataChanged, this, &GeneralFavsPanel::on_favToolChanged);
cboFavTools->append(cboFavTool);
params->append(cboFavTool);
addParams();
}
@@ -66,6 +121,7 @@ GeneralFavsPanel::GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSe
params->append(reset);
addParams();
lock = false;
initComboQMGroup();
addVSpring(grid, 0, grid->rowCount());
addHSpring(grid, grid->columnCount(), 0);
@@ -74,7 +130,25 @@ GeneralFavsPanel::GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSe
GeneralFavsPanel::~GeneralFavsPanel()
{
if (cboFavTools) {
delete cboFavTools; // dialog destructor will delete members
}
if (strFavTools) {
for (auto it = strFavTools->begin(); it != strFavTools->end(); ++it) {
delete *it;
}
delete strFavTools;
}
if (params) {
for (auto it = params->begin(); it != params->end(); ++it) {
delete *it;
}
delete params;
}
}
void GeneralFavsPanel::addLabel(QString text)
@@ -122,3 +196,42 @@ void GeneralFavsPanel::initComboQMGroup()
cboQMGrp->handleActivated(cbo, cbo->currentIndex());
}
}
void GeneralFavsPanel::on_favChanged()
{
if (!lock) {
const int idx = sender()->property("index").toInt();
const int i = cboFavTools->at(idx)->currentIndex();
cboFavTools->at(idx)->setCurrentIndex(0);
if (i == cboFavTools->at(idx)->currentIndex())
setToolName(idx); // force update
cboFavTools->at(idx)->setVisible(generalSettings.qmFavorites[idx] == GeneralSettings::QM_APP);
}
}
void GeneralFavsPanel::on_favToolChanged()
{
if (!lock) {
bool ok;
const int index = sender()->property("index").toInt(&ok);
if (ok) setToolName(index);
}
}
void GeneralFavsPanel::setToolName(int index)
{
if (generalSettings.qmFavoritesTools[index])
delete generalSettings.qmFavoritesTools[index];
if (generalSettings.qmFavorites[index] == GeneralSettings::QM_APP) {
// obtain current value from proxy
std::string str = strFavTools->at(index)->toStdString();
generalSettings.qmFavoritesTools[index] = new char[str.size() + 1];
strncpy(generalSettings.qmFavoritesTools[index], str.c_str(), str.size());
generalSettings.qmFavoritesTools[index][str.size()] = 0;
} else {
generalSettings.qmFavoritesTools[index] = nullptr;
}
}
@@ -22,6 +22,7 @@
#pragma once
#include "generaledit.h"
#include "autocombobox.h"
class ExclusiveComboGroup;
class QGridLayout;
@@ -34,17 +35,25 @@ class GeneralFavsPanel : public GeneralPanel
GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware);
virtual ~GeneralFavsPanel();
private slots:
void on_favChanged();
void on_favToolChanged();
private:
Board::Type board;
QGridLayout *grid;
QList<QWidget *> *params;
int row;
int col;
bool lock;
ExclusiveComboGroup *cboQMGrp;
QList<AutoComboBox *> *cboFavTools;
QList<QString *> *strFavTools;
void addLabel(QString text);
void addLine();
void addParams();
void addSection(QString text);
void initComboQMGroup();
void setToolName(int index);
};
+142 -14
View File
@@ -20,9 +20,9 @@
*/
#include "generalkeyshortcuts.h"
#include "autocombobox.h"
#include "compounditemmodels.h"
#include "exclusivecombogroup.h"
#include "helpers.h"
#include <QLabel>
#include <QGridLayout>
@@ -32,32 +32,79 @@ GeneralKeysPanel::GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSe
board(firmware->getBoard()),
params(new QList<QWidget *>),
row(0),
col(0)
col(0),
lock(true),
cboShortcuts(new QList<AutoComboBox *>),
cboShortcutTools(new QList<AutoComboBox *>),
strKeyShortcutTools(new QList<QString *>)
{
grid = new QGridLayout(this);
// All values except QM_NONE are mutually exclusive
// All values except QM_NONE and QM_APP are mutually exclusive
cboQMGrp = new ExclusiveComboGroup(this,
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE; });
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE ||
value == GeneralSettings::QM_APP; });
const int cnt = firmware->getCapability(KeyShortcuts);
// add lua tool scripts from radio profile sdcard
QStringList toolsSet = getListLuaTools();
QStandardItemModel *mdl = new QStandardItemModel(this);
for (int i = 0; i < toolsSet.size(); i++) {
QStandardItem *item = new QStandardItem(toolsSet[i]);
mdl->appendRow(item);
}
// Ensure existing configured tool is included in toolsSet as the radio profile
// sdcard contents may not match radio
for (int i = 0; i < cnt; i++) {
if (generalSettings.qmFavorites[i] == GeneralSettings::QM_APP) {
QString temp(generalSettings.qmFavoritesTools[i]);
if (!temp.isEmpty() && mdl->findItems(temp).size() < 1) {
QStandardItem *item = new QStandardItem(temp);
mdl->appendRow(item);
}
}
}
QSortFilterProxyModel *mdlTools = new QSortFilterProxyModel(this);
mdlTools->setSourceModel(mdl);
mdlTools->setSortCaseSensitivity(Qt::CaseInsensitive);
mdlTools->setFilterKeyColumn(0);
mdlTools->sort(0);
const int split = 2;
for (int i = 0; i < split; i++) {
if (i == 0) {
addSection(tr("Short Press"));
addSection(tr("Short Press"));
} else {
addLine();
addSection(tr("Long Press"));
}
for (int j = 0; j < (cnt / split); j++) {
const int idx = (i * (split + 1)) + j;
addLabel(j == 0 ? tr("MDL") : (j == 1 ? tr("SYS") : tr("TELE")));
AutoComboBox *cbo = new AutoComboBox(this);
AutoComboBox *cboShortcut = new AutoComboBox(this);
cboShortcut->setProperty("index", idx);
// separate item model per combo box due to mutual exclusivity
cbo->setModel(generalSettings.quickMenuItemModel(true));
cbo->setField(generalSettings.keyShortcuts[(i * (split + 1)) + j], this);
cboQMGrp->addCombo(cbo);
params->append(cbo);
cboShortcut->setModel(generalSettings.quickMenuItemModel(true));
cboShortcut->setField(generalSettings.keyShortcuts[idx], this);
connect(cboShortcut, &AutoComboBox::currentDataChanged, this, &GeneralKeysPanel::on_shortcutChanged);
cboShortcuts->append(cboShortcut);
cboQMGrp->addCombo(cboShortcut);
params->append(cboShortcut);
AutoComboBox *cboShortcutTool = new AutoComboBox(this);
cboShortcutTool->setProperty("index", idx);
cboShortcutTool->setModel(mdlTools);
// AutoComboBox does not support char * so use a proxy
QString *str = new QString(generalSettings.keyShortcutTools[idx]);
strKeyShortcutTools->append(str);
cboShortcutTool->setField(*str, this);
connect(cboShortcutTool, &AutoComboBox::currentDataChanged, this, &GeneralKeysPanel::on_shortcutToolChanged);
cboShortcutTools->append(cboShortcutTool);
params->append(cboShortcutTool);
addParams();
}
}
@@ -68,23 +115,45 @@ GeneralKeysPanel::GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSe
connect(reset, &QPushButton::clicked, [&] ()
{
generalSettings.setDefaultKeyShortcuts();
foreach(AutoComboBox *cb, findChildren<AutoComboBox*>())
cb->updateValue();
update();
initComboQMGroup();
});
params->append(reset);
addParams();
update();
initComboQMGroup();
addVSpring(grid, 0, grid->rowCount());
addHSpring(grid, grid->columnCount(), 0);
disableMouseScrolling();
lock = false;
}
GeneralKeysPanel::~GeneralKeysPanel()
{
if (cboShortcutTools) {
delete cboShortcutTools; // dialog destructor will delete members
}
if (cboShortcuts) {
delete cboShortcuts; // dialog destructor will delete members
}
if (strKeyShortcutTools) {
for (auto it = strKeyShortcutTools->begin(); it != strKeyShortcutTools->end(); ++it) {
delete *it;
}
delete strKeyShortcutTools;
}
if (params) {
for (auto it = params->begin(); it != params->end(); ++it) {
delete *it;
}
delete params;
}
}
void GeneralKeysPanel::addLabel(QString text)
@@ -132,3 +201,62 @@ void GeneralKeysPanel::initComboQMGroup()
cboQMGrp->handleActivated(cbo, cbo->currentIndex());
}
}
void GeneralKeysPanel::on_shortcutChanged()
{
if (!lock) {
const int idx = sender()->property("index").toInt();
if (generalSettings.keyShortcuts[idx] == GeneralSettings::QM_APP)
cboShortcutTools->at(idx)->setCurrentIndex(0);
setToolName(idx);
updateRow(idx);
}
}
void GeneralKeysPanel::on_shortcutToolChanged()
{
if (!lock) {
bool ok;
const int index = sender()->property("index").toInt(&ok);
if (ok) setToolName(index);
}
}
void GeneralKeysPanel::setToolName(int index)
{
if (generalSettings.keyShortcutTools[index])
delete generalSettings.keyShortcutTools[index];
if (generalSettings.keyShortcuts[index] == GeneralSettings::QM_APP) {
// obtain current value from proxy
std::string str = strKeyShortcutTools->at(index)->toStdString();
generalSettings.keyShortcutTools[index] = new char[str.size() + 1];
strncpy(generalSettings.keyShortcutTools[index], str.c_str(), str.size());
generalSettings.keyShortcutTools[index][str.size()] = 0;
} else {
generalSettings.keyShortcutTools[index] = nullptr;
}
}
void GeneralKeysPanel::update()
{
const int cnt = cboShortcuts->count();
for (int i = 0; i < cnt; i++)
updateRow(i);
}
void GeneralKeysPanel::updateRow(const int index)
{
lock = true;
cboShortcuts->at(index)->updateValue();
if (generalSettings.keyShortcuts[index] == GeneralSettings::QM_APP) {
cboShortcutTools->at(index)->updateValue();
cboShortcutTools->at(index)->setVisible(true);
} else {
cboShortcutTools->at(index)->setVisible(false);
}
lock = false;
}
@@ -22,6 +22,7 @@
#pragma once
#include "generaledit.h"
#include "autocombobox.h"
class ExclusiveComboGroup;
class QGridLayout;
@@ -34,17 +35,28 @@ class GeneralKeysPanel : public GeneralPanel
GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware);
virtual ~GeneralKeysPanel();
private slots:
void on_shortcutChanged();
void on_shortcutToolChanged();
private:
Board::Type board;
QGridLayout *grid;
QList<QWidget *> *params;
int row;
int col;
bool lock;
ExclusiveComboGroup *cboQMGrp;
QList<AutoComboBox *> *cboShortcuts;
QList<AutoComboBox *> *cboShortcutTools;
QList<QString *> *strKeyShortcutTools;
void addLabel(QString text);
void addLine();
void addParams();
void addSection(QString text);
void initComboQMGroup();
void setToolName(int index);
void update();
void updateRow(const int index);
};
+62
View File
@@ -42,6 +42,7 @@
#include <QRegularExpression>
#include <QProcess>
#include <QtGlobal>
#include <QFile>
using namespace Helpers;
@@ -541,6 +542,67 @@ QSet<QString> getFilesSet(const QString &path, const QStringList &filter, int ma
return result;
}
// based on /src/repos/edgetx/edgetx/radio/src/gui/colorlcd/radio/radio_tools.cpp
// loadLuaTools()
QStringList getListLuaTools()
{
const QString tdir = g.profile[g.id()].sdPath() + "/SCRIPTS/TOOLS";
QStringList result;
QDir dir(tdir);
if (dir.exists()) {
foreach (QString name, dir.entryList(QStringList() << "*.lua",
QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks)) {
QString path = tdir % "/" % name;
QFileInfo fi(path);
bool inFolder = fi.isDir();
QString toolname;
if (inFolder) {
// check if .lua with same name exists - skip folder to avoid duplicate entries
if (QFileInfo::exists(path % ".lua"))
continue;
// Default name is folder name
toolname = QDir(path).dirName();
// must have main.lua
path.append("/main.lua");
if (!QFileInfo::exists(path))
continue;
} else {
// Default name is file name
toolname = QFileInfo(path).completeBaseName();
}
// look for tool name in lua file to override default name
QFile file(path);
if (file.open(QFile::ReadOnly)) {
QByteArray ba = file.read(1024);
file.close();
if (ba.size() > 0) {
QByteArrayView view("TNS|");
int startpos = ba.indexOf(view);
if (startpos > -1) {
view = "|TNE";
int endpos = ba.indexOf(view, startpos + 1);
if (endpos > -1) {
toolname = ba.mid(startpos + 4, endpos - (startpos + 4)).data();
}
}
}
}
result.append(toolname);
}
}
return result;
}
bool GpsGlitchFilter::isGlitch(GpsCoord coord)
{
if ((fabs(coord.latitude) < 0.1) && (fabs(coord.longitude) < 0.1)) {
+1
View File
@@ -142,6 +142,7 @@ bool isTempFileName(const QString & fileName);
QString getSoundsPath(const GeneralSettings &generalSettings);
QSet<QString> getFilesSet(const QString &path, const QStringList &filter, int maxLen);
QStringList getListLuaTools();
class QTimeS : public QTime
+34 -2
View File
@@ -43,6 +43,8 @@ void AutoComboBox::initField()
m_curveType = nullptr;
m_flexType = nullptr;
m_switchType = nullptr;
m_qString = nullptr;
m_stdString = nullptr;
}
void AutoComboBox::clear()
@@ -129,6 +131,20 @@ void AutoComboBox::setField(Board::SwitchType & field, GenericPanel * panel)
updateValue();
}
void AutoComboBox::setField(QString & field, GenericPanel * panel)
{
setFieldInit(panel);
m_qString = &field;
updateValue();
}
void AutoComboBox::setField(std::string & field, GenericPanel * panel)
{
setFieldInit(panel);
m_stdString = &field;
updateValue();
}
void AutoComboBox::setFieldInit(GenericPanel * panel)
{
initField();
@@ -170,17 +186,29 @@ void AutoComboBox::updateValue()
setCurrentIndex(findData(*m_flexType));
else if (m_switchType)
setCurrentIndex(findData(*m_switchType));
else if (m_qString)
setCurrentIndex(findText(*m_qString));
else if (m_stdString)
setCurrentIndex(findText(QString(m_stdString->c_str())));
setLock(false);
}
void AutoComboBox::onCurrentIndexChanged(int index)
{
if (lock() || index < 0)
if (lock() || index < 0 || index >= count())
return;
bool ok;
const int val = itemData(index).toInt(&ok);
int val = 0;
QString str;
if (m_qString || m_stdString) {
str = itemText(index);
ok = true;
} else {
val = itemData(index).toInt(&ok);
}
if (ok) {
if (m_field && *m_field != val)
@@ -195,6 +223,10 @@ void AutoComboBox::onCurrentIndexChanged(int index)
*m_flexType = (Board::FlexType)val;
else if (m_switchType && *m_switchType != val)
*m_switchType = (Board::SwitchType)val;
else if (m_qString && *m_qString != str)
*m_qString = str;
else if (m_stdString && *m_stdString != str.toStdString())
*m_stdString = str.toStdString();
else
return;
+6
View File
@@ -29,6 +29,8 @@
#include <QComboBox>
#include <string.h>
/*
NOTE: Q_OBJECT classes cannot be templated and since we use signals we have no choice but to
take this approach or create a class per data type
@@ -57,6 +59,8 @@ class AutoComboBox : public QComboBox, public AutoWidget
void setField(CurveData::CurveType & field, GenericPanel * panel = nullptr);
void setField(Board::FlexType & field, GenericPanel * panel = nullptr);
void setField(Board::SwitchType & field, GenericPanel * panel = nullptr);
void setField(QString & field, GenericPanel * panel = nullptr);
void setField(std::string & field, GenericPanel * panel = nullptr);
void setAutoIndexes();
void setModel(QAbstractItemModel * model) override;
@@ -76,6 +80,8 @@ class AutoComboBox : public QComboBox, public AutoWidget
CurveData::CurveType *m_curveType;
Board::FlexType *m_flexType;
Board::SwitchType *m_switchType;
QString *m_qString;
std::string *m_stdString;
void initField();
void setFieldInit(GenericPanel * panel);