fix: enforce customisable switch rules when configuring (#4994)
This commit is contained in:
@@ -1697,106 +1697,195 @@ AbstractStaticItemModel * ModelData::trainerModeItemModel(const GeneralSettings
|
||||
return mdl;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchConfig(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchConfig, index, 2);
|
||||
else
|
||||
return FUNC_SWITCH_CONFIG_NONE;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchConfig(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchConfig, index, 2);
|
||||
else
|
||||
return FUNC_SWITCH_CONFIG_NONE;
|
||||
}
|
||||
void ModelData::setFuncSwitchConfig(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchConfig, value, index, 2);
|
||||
}
|
||||
|
||||
void ModelData::setFuncSwitchConfig(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchConfig, value, index, 2);
|
||||
}
|
||||
// static
|
||||
QString ModelData::funcSwitchConfigToString(unsigned int value)
|
||||
{
|
||||
switch (value) {
|
||||
case FUNC_SWITCH_CONFIG_NONE:
|
||||
return tr("NONE");
|
||||
case FUNC_SWITCH_CONFIG_TOGGLE:
|
||||
return tr("TOGGLE");
|
||||
case FUNC_SWITCH_CONFIG_2POS:
|
||||
return tr("2POS");
|
||||
default:
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
QString ModelData::funcSwitchConfigToString(unsigned int value)
|
||||
{
|
||||
switch (value) {
|
||||
case FUNC_SWITCH_CONFIG_NONE:
|
||||
return tr("NONE");
|
||||
case FUNC_SWITCH_CONFIG_TOGGLE:
|
||||
return tr("TOGGLE");
|
||||
case FUNC_SWITCH_CONFIG_2POS:
|
||||
return tr("2POS");
|
||||
default:
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
}
|
||||
}
|
||||
// static
|
||||
AbstractStaticItemModel * ModelData::funcSwitchConfigItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName(AIM_MODELDATA_FUNCSWITCHCONFIG);
|
||||
for (unsigned int i = FUNC_SWITCH_CONFIG_FIRST; i <= FUNC_SWITCH_CONFIG_LAST; i++) {
|
||||
mdl->appendToItemList(funcSwitchConfigToString(i), i);
|
||||
}
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
// static
|
||||
AbstractStaticItemModel * ModelData::funcSwitchConfigItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName(AIM_MODELDATA_FUNCSWITCHCONFIG);
|
||||
AbstractStaticItemModel * ModelData::funcSwitchGroupStartSwitchModel(int switchcnt)
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName(AIM_MODELDATA_FUNCSWITCHGROUPSTARTSWITCH);
|
||||
|
||||
for (unsigned int i = FUNC_SWITCH_CONFIG_FIRST; i <= FUNC_SWITCH_CONFIG_LAST; i++) {
|
||||
mdl->appendToItemList(funcSwitchConfigToString(i), i);
|
||||
}
|
||||
mdl->appendToItemList(tr("Restore"), 0);
|
||||
for (unsigned int i = 1; i <= switchcnt; i += 1) {
|
||||
mdl->appendToItemList(tr("SW") + QString::number(i), i);
|
||||
}
|
||||
mdl->appendToItemList(tr("Off"), switchcnt + 1);
|
||||
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchGroup(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchGroup, index, 2);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
AbstractStaticItemModel * ModelData::funcSwitchGroupsModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName(AIM_MODELDATA_FUNCSWITCHGROUPS);
|
||||
|
||||
void ModelData::setFuncSwitchGroup(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchGroup, value, index, 2);
|
||||
}
|
||||
mdl->appendToItemList(tr("---"), 0);
|
||||
for (unsigned int i = 1; i <= 3; i += 1) {
|
||||
mdl->appendToItemList(tr("Group ") + QString::number(i), i);
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchAlwaysOnGroup(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION) {
|
||||
unsigned int grp = getFuncSwitchGroup(index);
|
||||
unsigned int switchcnt = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches);
|
||||
return Helpers::getBitmappedValue(functionSwitchGroup, grp, 1, 2 * switchcnt);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
void ModelData::setFuncSwitchAlwaysOnGroup(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION) {
|
||||
unsigned int grp = getFuncSwitchGroup(index);
|
||||
unsigned int switchcnt = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches);
|
||||
Helpers::setBitmappedValue(functionSwitchGroup, value, grp, 1, 2 * switchcnt);
|
||||
}
|
||||
}
|
||||
unsigned int ModelData::getFuncSwitchGroup(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchGroup, index, 2);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchStart(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchStartConfig, index, 2);
|
||||
else
|
||||
return FUNC_SWITCH_START_INACTIVE;
|
||||
}
|
||||
void ModelData::setFuncSwitchGroup(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchGroup, value, index, 2);
|
||||
}
|
||||
|
||||
void ModelData::setFuncSwitchStart(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchStartConfig, value, index, 2);
|
||||
}
|
||||
unsigned int ModelData::getFuncSwitchAlwaysOnGroup(unsigned int group) const
|
||||
{
|
||||
if (group > 0 && group < 4) {
|
||||
unsigned int switchcnt = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches);
|
||||
return Helpers::getBitmappedValue(functionSwitchGroup, group, 1, 2 * switchcnt);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchAlwaysOnGroupForSwitch(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return getFuncSwitchAlwaysOnGroup(getFuncSwitchGroup(index));
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModelData::setFuncSwitchAlwaysOnGroup(unsigned int group, unsigned int value)
|
||||
{
|
||||
if (group > 0 && group < 4) {
|
||||
unsigned int switchcnt = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches);
|
||||
Helpers::setBitmappedValue(functionSwitchGroup, value, group, 1, 2 * switchcnt);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchStart(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchStartConfig, index, 2);
|
||||
else
|
||||
return FUNC_SWITCH_START_OFF;
|
||||
}
|
||||
|
||||
void ModelData::setFuncSwitchStart(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchStartConfig, value, index, 2);
|
||||
}
|
||||
|
||||
int ModelData::getFuncGroupSwitchCount(unsigned int group, int switchcnt) const
|
||||
{
|
||||
int grpSwitchCount = 0;
|
||||
for (int i = 0; i < switchcnt; i += 1) {
|
||||
if (getFuncSwitchGroup(i) == group) {
|
||||
grpSwitchCount += 1;
|
||||
}
|
||||
}
|
||||
return grpSwitchCount;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncGroupSwitchStart(unsigned int group, int switchcnt) const
|
||||
{
|
||||
bool allDown = true;
|
||||
for (int i = 0; i < switchcnt; i += 1) {
|
||||
if (getFuncSwitchGroup(i) == group) {
|
||||
if (getFuncSwitchStart(i) == FUNC_SWITCH_START_ON)
|
||||
return i + 1;
|
||||
if (getFuncSwitchStart(i) != FUNC_SWITCH_START_OFF)
|
||||
allDown = false;
|
||||
}
|
||||
}
|
||||
if (allDown && getFuncGroupSwitchCount(group, switchcnt) > 0) return switchcnt + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModelData::setFuncGroupSwitchStart(unsigned int group, unsigned int value, int switchcnt)
|
||||
{
|
||||
for (int i = 0; i < switchcnt; i += 1) {
|
||||
if (getFuncSwitchGroup(i) == group)
|
||||
setFuncSwitchStart(i, value ? ModelData::FUNC_SWITCH_START_OFF : ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||
}
|
||||
if (value > 0 && value <= switchcnt) {
|
||||
setFuncSwitchStart(value - 1, ModelData::FUNC_SWITCH_START_ON);
|
||||
}
|
||||
}
|
||||
|
||||
void ModelData::setGroupSwitchState(uint8_t group, int switchcnt)
|
||||
{
|
||||
// Check rules for always on group
|
||||
// - Toggle switch type not valid, change all switches to 2POS
|
||||
// - One switch must be turned on, turn on first switch if needed
|
||||
if (getFuncSwitchAlwaysOnGroup(group)) {
|
||||
for (int j = 0; j < switchcnt; j += 1) {
|
||||
if (getFuncSwitchGroup(j) == group) {
|
||||
setFuncSwitchConfig(j, FUNC_SWITCH_CONFIG_2POS); // Toggle not valid
|
||||
}
|
||||
}
|
||||
if (getFuncGroupSwitchStart(group, switchcnt) == switchcnt + 1) {
|
||||
// Start state for all switches is off - set all to 'last'
|
||||
for (int j = 0; j < switchcnt; j += 1)
|
||||
if (getFuncSwitchGroup(j) == group)
|
||||
setFuncSwitchStart(j, FUNC_SWITCH_START_PREVIOUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
QString ModelData::funcSwitchStartToString(unsigned int value)
|
||||
{
|
||||
switch (value) {
|
||||
case FUNC_SWITCH_START_INACTIVE:
|
||||
return tr("Inactive");
|
||||
case FUNC_SWITCH_START_ACTIVE:
|
||||
return tr("Active");
|
||||
case FUNC_SWITCH_START_OFF:
|
||||
return tr("Off");
|
||||
case FUNC_SWITCH_START_ON:
|
||||
return tr("On");
|
||||
case FUNC_SWITCH_START_PREVIOUS:
|
||||
return tr("Restore");
|
||||
default:
|
||||
|
||||
@@ -46,6 +46,8 @@ class AbstractStaticItemModel;
|
||||
constexpr char AIM_MODELDATA_TRAINERMODE[] {"modeldata.trainermode"};
|
||||
constexpr char AIM_MODELDATA_FUNCSWITCHCONFIG[] {"modeldata.funcswitchconfig"};
|
||||
constexpr char AIM_MODELDATA_FUNCSWITCHSTART[] {"modeldata.funcswitchstart"};
|
||||
constexpr char AIM_MODELDATA_FUNCSWITCHGROUPSTARTSWITCH[] = {"modeldata.funcswitchgroupstartswitch"};
|
||||
constexpr char AIM_MODELDATA_FUNCSWITCHGROUPS[] = {"modeldata.funcswitchgroups"};
|
||||
|
||||
class RSSIAlarmData {
|
||||
public:
|
||||
@@ -214,10 +216,9 @@ class ModelData {
|
||||
};
|
||||
|
||||
enum FunctionSwitchStart {
|
||||
FUNC_SWITCH_START_ACTIVE,
|
||||
FUNC_SWITCH_START_FIRST = FUNC_SWITCH_START_ACTIVE,
|
||||
FUNC_SWITCH_START_INACTIVE,
|
||||
//FUNC_SWITCH_START_FIRST = FUNC_SWITCH_START_INACTIVE,
|
||||
FUNC_SWITCH_START_ON,
|
||||
FUNC_SWITCH_START_FIRST = FUNC_SWITCH_START_ON,
|
||||
FUNC_SWITCH_START_OFF,
|
||||
FUNC_SWITCH_START_PREVIOUS,
|
||||
FUNC_SWITCH_START_LAST = FUNC_SWITCH_START_PREVIOUS
|
||||
};
|
||||
@@ -331,15 +332,22 @@ class ModelData {
|
||||
void setFuncSwitchConfig(unsigned int index, unsigned int value);
|
||||
static QString funcSwitchConfigToString(unsigned int value);
|
||||
static AbstractStaticItemModel * funcSwitchConfigItemModel();
|
||||
|
||||
static AbstractStaticItemModel * funcSwitchGroupStartSwitchModel(int switchcnt);
|
||||
static AbstractStaticItemModel * funcSwitchGroupsModel();
|
||||
|
||||
unsigned int getFuncSwitchGroup(unsigned int index) const;
|
||||
void setFuncSwitchGroup(unsigned int index, unsigned int value);
|
||||
|
||||
unsigned int getFuncSwitchAlwaysOnGroup(unsigned int index) const;
|
||||
void setFuncSwitchAlwaysOnGroup(unsigned int index, unsigned int value);
|
||||
unsigned int getFuncSwitchAlwaysOnGroup(unsigned int group) const;
|
||||
unsigned int getFuncSwitchAlwaysOnGroupForSwitch(unsigned int index) const;
|
||||
void setFuncSwitchAlwaysOnGroup(unsigned int group, unsigned int value);
|
||||
void setGroupSwitchState(uint8_t group, int switchcnt);
|
||||
|
||||
unsigned int getFuncSwitchStart(unsigned int index) const;
|
||||
void setFuncSwitchStart(unsigned int index, unsigned int value);
|
||||
int getFuncGroupSwitchCount(unsigned int group, int switchcnt) const;
|
||||
unsigned int getFuncGroupSwitchStart(unsigned int group, int switchcnt) const;
|
||||
void setFuncGroupSwitchStart(unsigned int group, unsigned int value, int switchcnt);
|
||||
static QString funcSwitchStartToString(unsigned int value);
|
||||
static AbstractStaticItemModel * funcSwitchStartItemModel();
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
constexpr char FIM_TIMERSWITCH[] {"Timer Switch"};
|
||||
constexpr char FIM_THRSOURCE[] {"Throttle Source"};
|
||||
constexpr char FIM_TRAINERMODE[] {"Trainer Mode"};
|
||||
// constexpr char FIM_TRAINERMODE[] {"Trainer Mode"};
|
||||
constexpr char FIM_ANTENNAMODE[] {"Antenna Mode"};
|
||||
constexpr char FIM_HATSMODE[] {"Hats Mode"};
|
||||
|
||||
@@ -1246,14 +1246,42 @@ void ModulePanel::updateTrainerModeItemModel()
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
bool FilteredGroupSwitchesModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
if (sourceRow == 0) return true;
|
||||
if (sourceRow == m_switchcnt + 1) {
|
||||
if (m_model->getFuncSwitchAlwaysOnGroup(m_group) || m_model->getFuncGroupSwitchCount(m_group, m_switchcnt) == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (m_model->getFuncSwitchGroup(sourceRow - 1) == m_group)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FilteredSwitchGroupsModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
if (sourceRow == 0) return true;
|
||||
if (m_model->getFuncSwitchConfig(m_switch) == ModelData::FUNC_SWITCH_CONFIG_NONE) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FilteredSwitchConfigsModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
if (sourceRow == ModelData::FUNC_SWITCH_CONFIG_NONE || sourceRow == ModelData::FUNC_SWITCH_CONFIG_2POS) return true;
|
||||
return !m_model->getFuncSwitchAlwaysOnGroupForSwitch(m_switch);
|
||||
}
|
||||
|
||||
FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::FunctionSwitches)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
AbstractStaticItemModel *fsConfig = ModelData::funcSwitchConfigItemModel();
|
||||
fsConfig = ModelData::funcSwitchConfigItemModel();
|
||||
AbstractStaticItemModel *fsStart = ModelData::funcSwitchStartItemModel();
|
||||
AbstractStaticItemModel *fsGroups = ModelData::funcSwitchGroupsModel();
|
||||
|
||||
Board::Type board = firmware->getBoard();
|
||||
|
||||
@@ -1261,6 +1289,8 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
||||
|
||||
switchcnt = Boards::getCapability(board, Board::FunctionSwitches);
|
||||
|
||||
fsGroupStart = ModelData::funcSwitchGroupStartSwitchModel(switchcnt);
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
QLabel * lblSwitchId = new QLabel(this);
|
||||
lblSwitchId->setText(tr("SW%1").arg(i + 1));
|
||||
@@ -1272,19 +1302,19 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
||||
|
||||
QComboBox * cboConfig = new QComboBox(this);
|
||||
cboConfig->setProperty("index", i);
|
||||
cboConfig->setModel(fsConfig);
|
||||
auto configFilter = new FilteredSwitchConfigsModel(fsConfig, i, &model);
|
||||
cboConfig->setModel(configFilter);
|
||||
filterSwitchConfigs << configFilter;
|
||||
|
||||
QComboBox * cboStartPosn = new QComboBox(this);
|
||||
cboStartPosn->setProperty("index", i);
|
||||
cboStartPosn->setModel(fsStart);
|
||||
|
||||
QSpinBox * sbGroup = new QSpinBox(this);
|
||||
sbGroup->setProperty("index", i);
|
||||
sbGroup->setMaximum(3);
|
||||
sbGroup->setSpecialValueText("-");
|
||||
|
||||
QCheckBox * cbAlwaysOnGroup = new QCheckBox(this);
|
||||
cbAlwaysOnGroup->setProperty("index", i);
|
||||
QComboBox * cboGroup = new QComboBox(this);
|
||||
cboGroup->setProperty("index", i);
|
||||
auto groupFilter = new FilteredSwitchGroupsModel(fsGroups, i, &model);
|
||||
cboGroup->setModel(groupFilter);
|
||||
filterSwitchGroups << groupFilter;
|
||||
|
||||
int row = 0;
|
||||
int coloffset = 1;
|
||||
@@ -1292,20 +1322,43 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
||||
ui->gridSwitches->addWidget(aleName, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboConfig, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboStartPosn, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(sbGroup, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cbAlwaysOnGroup, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboGroup, row++, i + coloffset);
|
||||
|
||||
connect(aleName, &AutoLineEdit::currentDataChanged, this, &FunctionSwitchesPanel::on_nameEditingFinished);
|
||||
connect(cboConfig, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_configCurrentIndexChanged);
|
||||
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_startPosnCurrentIndexChanged);
|
||||
connect(sbGroup, QOverload<int>::of(&QSpinBox::valueChanged), this, &FunctionSwitchesPanel::on_groupChanged);
|
||||
connect(cbAlwaysOnGroup, &QCheckBox::toggled, this, &FunctionSwitchesPanel::on_alwaysOnGroupChanged);
|
||||
connect(cboGroup, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_groupChanged);
|
||||
|
||||
aleNames << aleName;
|
||||
cboConfigs << cboConfig;
|
||||
cboStartupPosns << cboStartPosn;
|
||||
sbGroups << sbGroup;
|
||||
cboGroups << cboGroup;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i += 1) {
|
||||
QLabel * lblGroupId = new QLabel(this);
|
||||
lblGroupId->setText(tr("Group %1").arg(i + 1));
|
||||
|
||||
QCheckBox * cbAlwaysOnGroup = new QCheckBox(this);
|
||||
cbAlwaysOnGroup->setProperty("index", i);
|
||||
|
||||
QComboBox * cboStartPosn = new QComboBox(this);
|
||||
cboStartPosn->setProperty("index", i);
|
||||
auto filter = new FilteredGroupSwitchesModel(fsGroupStart, i + 1, &model, switchcnt);
|
||||
cboStartPosn->setModel(filter);
|
||||
filterGroupSwitches << filter;
|
||||
|
||||
int row = 0;
|
||||
int coloffset = 1;
|
||||
ui->gridGroups->addWidget(lblGroupId, row++, i + coloffset);
|
||||
ui->gridGroups->addWidget(cbAlwaysOnGroup, row++, i + coloffset);
|
||||
ui->gridGroups->addWidget(cboStartPosn, row++, i + coloffset);
|
||||
|
||||
connect(cbAlwaysOnGroup, &QCheckBox::toggled, this, &FunctionSwitchesPanel::on_alwaysOnGroupChanged);
|
||||
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_groupStartPosnCurrentIndexChanged);
|
||||
|
||||
cbAlwaysOnGroups << cbAlwaysOnGroup;
|
||||
cboGroupStartupPosns << cboStartPosn;
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -1319,38 +1372,31 @@ FunctionSwitchesPanel::~FunctionSwitchesPanel()
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::update()
|
||||
{
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
update(i);
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::update(int index)
|
||||
{
|
||||
lock = true;
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
filterSwitchConfigs[i]->invalidate();
|
||||
filterSwitchGroups[i]->invalidate();
|
||||
|
||||
aleNames[i]->update();
|
||||
cboConfigs[i]->setCurrentIndex(model->getFuncSwitchConfig(i));
|
||||
cboConfigs[i]->setCurrentIndex(filterSwitchConfigs[i]->mapFromSource(fsConfig->index(model->getFuncSwitchConfig(i), 0)).row());
|
||||
cboStartupPosns[i]->setCurrentIndex(model->getFuncSwitchStart(i));
|
||||
unsigned int grp = model->getFuncSwitchGroup(i);
|
||||
sbGroups[i]->setValue(grp);
|
||||
cbAlwaysOnGroups[i]->setChecked(model->getFuncSwitchAlwaysOnGroup(i));
|
||||
cboGroups[i]->setCurrentIndex(grp);
|
||||
|
||||
if (cboConfigs[i]->currentIndex() < 2)
|
||||
cboStartupPosns[i]->setEnabled(false);
|
||||
else
|
||||
cboStartupPosns[i]->setEnabled(true);
|
||||
cboStartupPosns[i]->setEnabled(cboConfigs[i]->currentIndex() >= ModelData::FUNC_SWITCH_CONFIG_2POS && (grp == 0));
|
||||
|
||||
if (cboConfigs[i]->currentIndex() < 1)
|
||||
sbGroups[i]->setEnabled(false);
|
||||
else
|
||||
sbGroups[i]->setEnabled(true);
|
||||
cboGroups[i]->setEnabled(cboConfigs[i]->currentIndex() >= ModelData::FUNC_SWITCH_CONFIG_TOGGLE);
|
||||
}
|
||||
|
||||
if (!(sbGroups[i]->isEnabled()) || grp < 1)
|
||||
cbAlwaysOnGroups[i]->setEnabled(false);
|
||||
else
|
||||
cbAlwaysOnGroups[i]->setEnabled(true);
|
||||
for (int i = 0; i < 3; i += 1) {
|
||||
filterGroupSwitches[i]->invalidate();
|
||||
|
||||
model->setGroupSwitchState(i + 1, switchcnt);
|
||||
|
||||
cbAlwaysOnGroups[i]->setChecked(model->getFuncSwitchAlwaysOnGroup(i + 1));
|
||||
cboGroupStartupPosns[i]->setCurrentIndex(filterGroupSwitches[i]->mapFromSource(fsGroupStart->index(model->getFuncGroupSwitchStart(i + 1, switchcnt), 0)).row());
|
||||
}
|
||||
|
||||
lock = false;
|
||||
@@ -1372,14 +1418,16 @@ void FunctionSwitchesPanel::on_configCurrentIndexChanged(int index)
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
unsigned int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && model->getFuncSwitchConfig(i) != (unsigned int)index) {
|
||||
model->setFuncSwitchConfig(i, index);
|
||||
if (index < 2)
|
||||
model->setFuncSwitchStart(i, ModelData::FUNC_SWITCH_START_INACTIVE);
|
||||
if (index < 1)
|
||||
model->setFuncSwitchGroup(i, 0);
|
||||
update(i);
|
||||
unsigned int sw = sender()->property("index").toInt(&ok);
|
||||
unsigned int config = filterSwitchConfigs[sw]->mapToSource(filterSwitchConfigs[sw]->index(index, 0)).row();
|
||||
if (ok && model->getFuncSwitchConfig(sw) != config) {
|
||||
model->setFuncSwitchConfig(sw, config);
|
||||
if (config != ModelData::FUNC_SWITCH_CONFIG_2POS) {
|
||||
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||
if ((config == ModelData::FUNC_SWITCH_CONFIG_NONE) || model->getFuncSwitchAlwaysOnGroupForSwitch(sw))
|
||||
model->setFuncSwitchGroup(sw, 0);
|
||||
}
|
||||
update();
|
||||
emit modified();
|
||||
emit updateDataModels();
|
||||
}
|
||||
@@ -1397,9 +1445,31 @@ void FunctionSwitchesPanel::on_startPosnCurrentIndexChanged(int index)
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
unsigned int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && model->getFuncSwitchStart(i) != (unsigned int)index) {
|
||||
model->setFuncSwitchStart(i, index);
|
||||
unsigned int sw = sender()->property("index").toInt(&ok);
|
||||
if (ok && model->getFuncSwitchStart(sw) != (unsigned int)index) {
|
||||
model->setFuncSwitchStart(sw, index);
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::on_groupStartPosnCurrentIndexChanged(int index)
|
||||
{
|
||||
if (!sender())
|
||||
return;
|
||||
|
||||
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
unsigned int grp = sender()->property("index").toInt(&ok);
|
||||
unsigned int sw = filterGroupSwitches[grp]->mapToSource(filterGroupSwitches[grp]->index(index, 0)).row();
|
||||
if (ok && model->getFuncGroupSwitchStart(grp + 1, switchcnt) != sw) {
|
||||
model->setFuncGroupSwitchStart(grp + 1, sw, switchcnt);
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
@@ -1411,15 +1481,27 @@ void FunctionSwitchesPanel::on_groupChanged(int value)
|
||||
if (!sender())
|
||||
return;
|
||||
|
||||
QSpinBox * sb = qobject_cast<QSpinBox *>(sender());
|
||||
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||
|
||||
if (sb && !lock) {
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && model->getFuncSwitchGroup(i) != (unsigned int)value) {
|
||||
model->setFuncSwitchGroup(i, (unsigned int)value);
|
||||
update(i);
|
||||
int sw = sender()->property("index").toInt(&ok);
|
||||
unsigned int grp = filterSwitchGroups[sw]->mapToSource(filterSwitchGroups[sw]->index(value, 0)).row();
|
||||
if (ok && model->getFuncSwitchGroup(sw) != grp) {
|
||||
unsigned oldGrp = model->getFuncSwitchGroup(sw);
|
||||
if (model->getFuncSwitchAlwaysOnGroup(grp)) {
|
||||
if (model->getFuncSwitchConfig(sw) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE)
|
||||
model->setFuncSwitchConfig(sw, ModelData::FUNC_SWITCH_CONFIG_2POS);
|
||||
}
|
||||
if ((grp == 0) || (model->getFuncGroupSwitchStart(grp, switchcnt) == 0))
|
||||
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||
else
|
||||
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_OFF);
|
||||
model->setFuncSwitchGroup(sw, grp);
|
||||
if (oldGrp > 0)
|
||||
model->setFuncGroupSwitchStart(oldGrp, model->getFuncGroupSwitchStart(oldGrp, switchcnt), switchcnt);
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
@@ -1436,10 +1518,22 @@ void FunctionSwitchesPanel::on_alwaysOnGroupChanged(int value)
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
int grp = sender()->property("index").toInt(&ok) + 1;
|
||||
|
||||
if (ok) {
|
||||
model->setFuncSwitchAlwaysOnGroup(i, (unsigned int)value);
|
||||
model->setFuncSwitchAlwaysOnGroup(grp, (unsigned int)value);
|
||||
if (value) {
|
||||
for (int i = 0; i < switchcnt; i += 1) {
|
||||
if ((model->getFuncSwitchGroup(i) == grp) && (model->getFuncSwitchConfig(i) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE))
|
||||
model->setFuncSwitchConfig(i, ModelData::FUNC_SWITCH_CONFIG_2POS);
|
||||
}
|
||||
if (model->getFuncGroupSwitchStart(grp, switchcnt) == switchcnt + 1) {
|
||||
for (int i = 0; i < switchcnt; i += 1) {
|
||||
if (model->getFuncSwitchGroup(i) == grp)
|
||||
model->setFuncSwitchStart(i, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "compounditemmodels.h"
|
||||
#include "filtereditemmodels.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer";
|
||||
|
||||
namespace Ui {
|
||||
@@ -142,6 +144,103 @@ class ModulePanel : public ModelPanel
|
||||
static bool isExternalModule(int index) { return index > 0; }
|
||||
};
|
||||
|
||||
class FilteredGroupSwitchesModel: public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FilteredGroupSwitchesModel(AbstractItemModel * sourceModel, int group, ModelData * model, int switchcnt) :
|
||||
QSortFilterProxyModel(nullptr),
|
||||
m_group(group),
|
||||
m_switchcnt(switchcnt),
|
||||
m_model(model)
|
||||
{
|
||||
setFilterKeyColumn(0);
|
||||
setDynamicSortFilter(true);
|
||||
setSourceModel(sourceModel);
|
||||
}
|
||||
|
||||
explicit FilteredGroupSwitchesModel(AbstractItemModel * sourceModel) :
|
||||
FilteredGroupSwitchesModel(sourceModel, 0, nullptr, 0) {}
|
||||
virtual ~FilteredGroupSwitchesModel() {};
|
||||
|
||||
void setGroup(int group) { m_group = group; }
|
||||
int getGroup() const { return m_group; }
|
||||
void setSwitchcnt(int n) { m_switchcnt = n; }
|
||||
int getSwitchcnt() const { return m_switchcnt; }
|
||||
void setModel(ModelData* model) { m_model = model; }
|
||||
ModelData* getModel() const { return m_model; }
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||
|
||||
private:
|
||||
int m_group = 0;
|
||||
int m_switchcnt = 0;
|
||||
ModelData* m_model = nullptr;
|
||||
};
|
||||
|
||||
class FilteredSwitchGroupsModel: public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FilteredSwitchGroupsModel(AbstractItemModel * sourceModel, int sw, ModelData * model) :
|
||||
QSortFilterProxyModel(nullptr),
|
||||
m_switch(sw),
|
||||
m_model(model)
|
||||
{
|
||||
setFilterKeyColumn(0);
|
||||
setDynamicSortFilter(true);
|
||||
setSourceModel(sourceModel);
|
||||
}
|
||||
|
||||
explicit FilteredSwitchGroupsModel(AbstractItemModel * sourceModel) :
|
||||
FilteredSwitchGroupsModel(sourceModel, 0, nullptr) {}
|
||||
virtual ~FilteredSwitchGroupsModel() {};
|
||||
|
||||
void setSwitch(int group) { m_switch = group; }
|
||||
int getSwitch() const { return m_switch; }
|
||||
void setModel(ModelData* model) { m_model = model; }
|
||||
ModelData* getModel() const { return m_model; }
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||
|
||||
private:
|
||||
int m_switch = 0;
|
||||
ModelData* m_model = nullptr;
|
||||
};
|
||||
|
||||
class FilteredSwitchConfigsModel: public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FilteredSwitchConfigsModel(AbstractItemModel * sourceModel, int sw, ModelData * model) :
|
||||
QSortFilterProxyModel(nullptr),
|
||||
m_switch(sw),
|
||||
m_model(model)
|
||||
{
|
||||
setFilterKeyColumn(0);
|
||||
setDynamicSortFilter(true);
|
||||
setSourceModel(sourceModel);
|
||||
}
|
||||
|
||||
explicit FilteredSwitchConfigsModel(AbstractItemModel * sourceModel) :
|
||||
FilteredSwitchConfigsModel(sourceModel, 0, nullptr) {}
|
||||
virtual ~FilteredSwitchConfigsModel() {};
|
||||
|
||||
void setSwitch(int group) { m_switch = group; }
|
||||
int getSwitch() const { return m_switch; }
|
||||
void setModel(ModelData* model) { m_model = model; }
|
||||
ModelData* getModel() const { return m_model; }
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||
|
||||
private:
|
||||
int m_switch = 0;
|
||||
ModelData* m_model = nullptr;
|
||||
};
|
||||
|
||||
class FunctionSwitchesPanel : public ModelPanel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -150,8 +249,7 @@ class FunctionSwitchesPanel : public ModelPanel
|
||||
FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
virtual ~FunctionSwitchesPanel();
|
||||
|
||||
virtual void update();
|
||||
void update(int index);
|
||||
void update();
|
||||
|
||||
signals:
|
||||
void updateDataModels();
|
||||
@@ -160,6 +258,7 @@ class FunctionSwitchesPanel : public ModelPanel
|
||||
void on_nameEditingFinished();
|
||||
void on_configCurrentIndexChanged(int index);
|
||||
void on_startPosnCurrentIndexChanged(int index);
|
||||
void on_groupStartPosnCurrentIndexChanged(int index);
|
||||
void on_groupChanged(int value);
|
||||
void on_alwaysOnGroupChanged(int value);
|
||||
|
||||
@@ -168,9 +267,15 @@ class FunctionSwitchesPanel : public ModelPanel
|
||||
QVector<AutoLineEdit *> aleNames;
|
||||
QVector<QComboBox *> cboConfigs;
|
||||
QVector<QComboBox *> cboStartupPosns;
|
||||
QVector<QSpinBox *> sbGroups;
|
||||
QVector<QComboBox *> cboGroups;
|
||||
QVector<QCheckBox *> cbAlwaysOnGroups;
|
||||
QVector<QComboBox *> cboGroupStartupPosns;
|
||||
QVector<FilteredGroupSwitchesModel *> filterGroupSwitches;
|
||||
QVector<FilteredSwitchGroupsModel *> filterSwitchGroups;
|
||||
QVector<FilteredSwitchConfigsModel *> filterSwitchConfigs;
|
||||
int switchcnt;
|
||||
AbstractStaticItemModel *fsConfig;
|
||||
AbstractStaticItemModel *fsGroupStart;
|
||||
};
|
||||
|
||||
class SetupPanel : public ModelPanel
|
||||
|
||||
@@ -63,13 +63,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblType">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblName">
|
||||
<property name="text">
|
||||
@@ -77,6 +70,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblType">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lblStartupPosn">
|
||||
<property name="text">
|
||||
@@ -97,17 +97,71 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="lblAlwaysOnGroup">
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayoutGroups">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblGroups">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Switch Groups</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridGroups">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="groupId">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblAlwaysOn">
|
||||
<property name="text">
|
||||
<string>Always On</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblStartSwitch">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<spacer name="horizontalSpacerGroups">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
||||
@@ -1002,7 +1002,7 @@ QString MultiModelPrinter::printFunctionSwitches()
|
||||
columns.appendRowStart(tr("Always On"), 20);
|
||||
|
||||
for (int i = 0; i < numFS; i++) {
|
||||
COMPARECELLWIDTH((model->getFuncSwitchAlwaysOnGroup((unsigned int)i) == 0 ? "No" : "Yes"), colwidth);
|
||||
COMPARECELLWIDTH((model->getFuncSwitchAlwaysOnGroupForSwitch((unsigned int)i) == 0 ? "No" : "Yes"), colwidth);
|
||||
}
|
||||
|
||||
columns.appendRowEnd();
|
||||
|
||||
Reference in New Issue
Block a user