Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Refactor implementation of observer pattern in low-level classes #449
Many objects need to get notified about changes in other objects, for example when clicking CTRL+Z, the undo stack reverts changes in objects and the GUI needs to get notified about these changes. For higher level classes we do this with Qt's signal/slot mechanism as it is easy to use and very safe.
But this works only in classes derived from
Until now, the lower level classes had implemented the observer pattern by declaring an interface for observers and register/unregister methods. But that was also a bit annoying since it leads to a lot of code and multiple inheritance. And it was a bit dangerous since objects and their observers weren't automatically disconnected if either the object or the observer was destroyed. So it was easy to access dangling pointers.
This PR replaces the observer pattern with an implementation which doesn't need any inheritance and is much more safe to use. Accessing dangling pointers should no longer be possible since the objects and their observers are automatically disconnected if either the object or the observer is destroyed.
Required for #446