(core): change slot behavior to manage optional parameters
Description
-
For the moment, we can connect a signal to a slot, only if:
-
Signal number of parameters
>=
Slot number of parameters. -
It is frustrating to create new slots when you need to add a parameter and almost copy/past all the code from a previous slot.
Proposal
- It can be useful to take into account optional parameters in slots.
Links / references
We had a problem with the SStatus
service for example.
In this case, we have had to implement specials slots with a parameter because the already implemented ones had no parameters.
/// SLOT : change label color
void changeToGreen();
/// SLOT : change nth label color
void changeNthToGreen(const int index);
This parameter allows to change the state of a particular status when there is more than one.
If we had optional slot parameters, it allows us to write something like:
void changeToGreen(const int index = -1);
Anything change in the XML
instead that we can connect this slot to different kind of signals and do something like:
<connect>
<signal>ChessboardDetector/chessboardDetected</signal>
<slot>Status/changeToGreen</slot>
</connect>
<!-- AND -->
<connect>
<signal>TLMatrixSynchronizer/matrixSynchronized</signal>
<slot>Status/changeToGreen</slot> <!-- instead of changeNthToGreen -->
</connect>
<!-- or even more interesting -->
<connect>
<signal>ChessboardDetector/chessboardDetected</signal>
<signal>TLMatrixSynchronizer/matrixSynchronized</signal>
<slot>Status/changeToGreen</slot>
</connect>