Fix emitting of currentLayerChanged() signal

Use layer ID instead of persistent index to remember last layer.
Persistent index will get invalid during removal of layers and
the signal was not emitted when current index got invalid (none).

This was causing a crash in GPS information widget
Fix #11143 take 3 (cannot remove visibility groups)

Now we also handle rules that are not valid anymore
Make rule-based renderer rule keys persistent

So they can be used for visibility groups - before they got assigned new keys
on every instantiation of Rule
Fix #11169 (toggling symbol visibility does not trigger refresh)

This could have happened when the same project was reloaded, then map canvas
failed to clear itself and some connections to repaintRequested were broken