mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 18:44:13 +02:00
Default the modulus when a part becomes a Cyclique (modulo) part
Turning the default "Chiffre 1" part into a "Cyclique (modulo)" one left the modulus spin box at 0, and a modulus of 0 means "no cycle" -- so the part counted upward forever instead of wrapping, which is the whole point of the type. Reported on #593 against a modulus-7 test and, more usefully, against a real April 5000 PLC layout addressed %IX0.0..%IX0.31 per card. setType() defaulted the modulus to 8 inside the block that installs numeric behaviour, and that block runs only when the *previous* type was non-numeric. Switching from one numeric type to another skips it. Since a fresh part starts out as "Chiffre 1", the ordinary way to reach this feature -- change the type of the part in front of you -- was exactly the path that skipped the default. Going the long way round, via "Texte", set the modulus to 8 and worked, which is why the feature tests fine when you build the context some other way. Moved the default out of that block so it applies whatever the part was before, and made it fire only when the current modulus is unusable, so a value the user picked on purpose survives switching type away and back. The wrap/carry arithmetic itself was already correct: with a carry target in front of it, a modulus-32 part yields %IX0.0..%IX0.31, %IX1.0 as asked. Saved configurations are untouched -- a stored modulus, including a 0 left behind by this bug, still loads and round-trips exactly as it was.
This commit is contained in:
@@ -359,8 +359,6 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) {
|
||||
ui -> value_field -> setValidator(intValidator);
|
||||
ui -> increase_spinBox -> setEnabled(true);
|
||||
ui -> increase_spinBox -> setValue(1);
|
||||
if (t == wrap)
|
||||
ui -> modulus_spinBox -> setValue(8);
|
||||
}
|
||||
//@t isn't a numeric type
|
||||
else if (t == string
|
||||
@@ -414,6 +412,16 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) {
|
||||
ui -> increase_spinBox -> setDisabled(true);
|
||||
}
|
||||
}
|
||||
//A modulus of 0 means "no cycle", which makes a Cyclique part behave
|
||||
//exactly like a plain digit. Defaulting it used to live in the numeric
|
||||
//behavior block above, which is skipped when the previous type was
|
||||
//itself numeric -- so the ordinary path of turning the default
|
||||
//"Chiffre 1" into a "Cyclique (modulo)" left the modulus at 0 and
|
||||
//produced a wrap part that never wrapped. Kept out of that block so it
|
||||
//applies whatever the part was before, and only when the current value
|
||||
//is unusable, so a modulus the user chose on purpose is not clobbered.
|
||||
if (t == wrap && ui -> modulus_spinBox -> value() <= 0)
|
||||
ui -> modulus_spinBox -> setValue(8);
|
||||
ui -> modulus_spinBox -> setEnabled(t == wrap);
|
||||
type_= t;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user