feat: allow Sticky LS state to persist across EM or optionally across reboot (#4978)
This commit is contained in:
@@ -116,6 +116,8 @@ Node convert<LogicalSwitchData>::encode(const LogicalSwitchData& rhs)
|
||||
node["delay"] = rhs.delay;
|
||||
node["duration"] = rhs.duration;
|
||||
node["andsw"] = YamlRawSwitchEncode(RawSwitch(rhs.andsw));
|
||||
node["lsPersist"] = (int)rhs.lsPersist;
|
||||
node["lsState"] = (int)rhs.lsState;
|
||||
|
||||
return node;
|
||||
}
|
||||
@@ -200,6 +202,9 @@ bool convert<LogicalSwitchData>::decode(const Node& node,
|
||||
node["andsw"] >> andsw;
|
||||
rhs.andsw = andsw.toValue();
|
||||
|
||||
node["lsPersist"] >> rhs.lsPersist;
|
||||
node["lsState"] >> rhs.lsState;
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
@@ -76,6 +76,8 @@ class LogicalSwitchData {
|
||||
unsigned int delay;
|
||||
unsigned int duration;
|
||||
int andsw;
|
||||
bool lsState;
|
||||
bool lsPersist;
|
||||
|
||||
void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
|
||||
bool isEmpty() const;
|
||||
|
||||
@@ -47,6 +47,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
if (lsCapabilityExt) {
|
||||
headerLabels << tr("Duration") << tr("Delay");
|
||||
}
|
||||
headerLabels << tr("Persistent");
|
||||
TableLayout * tableLayout = new TableLayout(this, lsCapability, headerLabels);
|
||||
|
||||
const int channelsMax = model.getChannelsMax(true);
|
||||
@@ -152,6 +153,13 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
connect(dsbDelay[i], SIGNAL(valueChanged(double)), this, SLOT(onDelayChanged(double)));
|
||||
tableLayout->addWidget(i, 6, dsbDelay[i]);
|
||||
}
|
||||
|
||||
cbPersist[i] = new QCheckBox(this);
|
||||
cbPersist[i]->setProperty("index", i);
|
||||
cbPersist[i]->setText(tr(""));
|
||||
cbPersist[i]->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
connect(cbPersist[i], SIGNAL(stateChanged(int)), this, SLOT(onPersistChanged()));
|
||||
tableLayout->addWidget(i, 7, cbPersist[i]);
|
||||
}
|
||||
|
||||
disableMouseScrolling();
|
||||
@@ -257,6 +265,16 @@ void LogicalSwitchesPanel::onDelayChanged(double delay)
|
||||
}
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::onPersistChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
QCheckBox *ckb = qobject_cast<QCheckBox*>(sender());
|
||||
int index = ckb->property("index").toInt();
|
||||
model->logicalSw[index].lsPersist = (ckb->checkState() ? 1 : 0);
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::onOffsetChanged()
|
||||
{
|
||||
offsetChangedAt(sender()->property("index").toInt());
|
||||
@@ -343,6 +361,7 @@ void LogicalSwitchesPanel::updateTimerParam(QDoubleSpinBox *sb, int timer, doubl
|
||||
#define DELAY_ENABLED 0x40
|
||||
#define DURATION_ENABLED 0x80
|
||||
#define LINE_ENABLED 0x100
|
||||
#define PERSIST_ENABLED 0x200
|
||||
|
||||
void LogicalSwitchesPanel::updateLine(int i)
|
||||
{
|
||||
@@ -391,6 +410,8 @@ void LogicalSwitchesPanel::updateLine(int i)
|
||||
}
|
||||
|
||||
case LS_FAMILY_STICKY: // no break
|
||||
mask |= PERSIST_ENABLED;
|
||||
cbPersist[i]->setChecked(model->logicalSw[i].lsPersist);
|
||||
case LS_FAMILY_VBOOL:
|
||||
mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE;
|
||||
cbSource1[i]->setModel(rawSwitchFilteredModel);
|
||||
@@ -432,6 +453,7 @@ void LogicalSwitchesPanel::updateLine(int i)
|
||||
dsbOffset2[i]->setVisible(mask & VALUE3_VISIBLE);
|
||||
teOffset[i]->setVisible(mask & VALUE_TO_VISIBLE);
|
||||
cbAndSwitch[i]->setVisible(mask & LINE_ENABLED);
|
||||
cbPersist[i]->setVisible(mask & PERSIST_ENABLED);
|
||||
if (lsCapabilityExt) {
|
||||
dsbDuration[i]->setVisible(mask & DURATION_ENABLED);
|
||||
dsbDelay[i]->setVisible(mask & DELAY_ENABLED);
|
||||
|
||||
@@ -47,6 +47,7 @@ class LogicalSwitchesPanel : public ModelPanel
|
||||
void onAndSwitchChanged(int value);
|
||||
void onDurationChanged(double duration);
|
||||
void onDelayChanged(double delay);
|
||||
void onPersistChanged();
|
||||
void onOffsetChanged();
|
||||
bool offsetChangedAt(int index);
|
||||
void updateLine(int index);
|
||||
@@ -74,6 +75,7 @@ class LogicalSwitchesPanel : public ModelPanel
|
||||
QDoubleSpinBox * dsbDelay[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QComboBox * cbSource1[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QComboBox * cbSource2[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QCheckBox * cbPersist[CPN_MAX_LOGICAL_SWITCHES];
|
||||
CompoundItemModelFactory * sharedItemModels;
|
||||
FilteredItemModel * rawSwitchFilteredModel;
|
||||
FilteredItemModel * rawSourceFilteredModel;
|
||||
|
||||
@@ -531,6 +531,8 @@ QString ModelPrinter::printLogicalSwitchLine(int idx)
|
||||
sw1Name = RawSwitch(ls.val1).toString(getCurrentBoard(), &generalSettings);
|
||||
sw2Name = RawSwitch(ls.val2).toString(getCurrentBoard(), &generalSettings);
|
||||
result += tr("Sticky") + QString("(%1, %2)").arg(sw1Name).arg(sw2Name);
|
||||
if (ls.lsPersist)
|
||||
result += tr(" Persistent");
|
||||
break;
|
||||
case LS_FAMILY_TIMER:
|
||||
result += tr("Timer") + QString("(%1, %2)").arg(ValToTim(ls.val1)).arg(ValToTim(ls.val2));
|
||||
|
||||
Reference in New Issue
Block a user