Fix crash when removing an item from a custom widget
Merge the startEditMode() and endEditMode() functions into one, and remove code duplication