def METHOD_NAME(item_names, view, menu_action_text, dialog_class):
    """Adds an entity to object or relationship tree view.
    Args:
        item_names (dict): row data keyed by column index
        view (QTreeView): object or relationship tree view
        menu_action_text (str): entry in tree view's context menu
        dialog_class (Type): relevant QDialog class for adding the entity
    """
    add_items_action = None
    for action in view._menu.actions():
        if action.text() == menu_action_text:
            add_items_action = action
            break
    if add_items_action is None:
        raise RuntimeError("Menu action not found.")
    patched = "spinetoolbox.spine_db_editor.widgets.tree_view_mixin." + dialog_class.__name__
    with mock.patch(patched) as mock_dialog:
        add_items_action.trigger()
        arguments_list = mock_dialog.call_args_list
    for arguments in arguments_list:
        add_items_dialog = dialog_class(*arguments[0])
        with signal_waiter(add_items_dialog.model.rowsInserted) as waiter:
            QApplication.processEvents()
            waiter.wait()
        for column, name in item_names.items():
            item_name_index = add_items_dialog.model.index(0, column)
            add_items_dialog.set_model_data(item_name_index, name)
        add_items_dialog.accept()