TextDocument::populateContextMenu() is called when the user opens the contextmenu and intends to remove the menu items added in a previous invocation before adding an updated list of actions.
That list of actions to remove has to be menu-specific; it can be a static member variable since in practice there is only a single QMenu instance for the context menu.