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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user