Cockatrice/cockatrice/src/game_graphics/player/menu/move_menu.h
DawnFire42 17f583013b
[CardMenu] Free the card menus and submenus rebuilt on each right-click (#7093)
* Parent card menu submenus to the menu that owns them

QMenu::addMenu(QMenu *) does not take ownership of the submenu, and these
submenus were created without a parent. Since CardMenu is rebuilt from
scratch on every right-click, each rebuild leaked the MoveMenu, PtMenu,
card counters and related-cards submenus.

Pass the owning CardMenu as the QWidget parent so Qt's parent-child
mechanism frees them with it.

* Delete the replaced card menu in TabGame to fix menu rebuild leak

PlayerMenu creates a new CardMenu on every right-click and TabGame installs
it with QAction::setMenu(), which does not take ownership, so the previous
menu was never freed. TabGame now deletes the menu it replaces and reuses a
single empty placeholder menu instead of allocating one per update. The
installed menu is also released when the tab is destroyed.
2026-11-06 20:51:00 +01:00

34 lines
740 B
C++

/**
* @file move_menu.h
* @ingroup GameMenusZones
*/
//! \todo Document this file.
#ifndef COCKATRICE_MOVE_MENU_H
#define COCKATRICE_MOVE_MENU_H
#include <QMenu>
#include <qtmetamacros.h>
class PlayerGraphicsItem;
class QAction;
class MoveMenu : public QMenu
{
Q_OBJECT
public:
explicit MoveMenu(PlayerGraphicsItem *player, QWidget *parent);
void setShortcutsActive();
void retranslateUi();
QAction *aMoveToTopLibrary = nullptr;
QAction *aMoveToXfromTopOfLibrary = nullptr;
QAction *aMoveToBottomLibrary = nullptr;
QAction *aMoveToHand = nullptr;
QAction *aMoveToTable = nullptr;
QAction *aMoveToGraveyard = nullptr;
QAction *aMoveToExile = nullptr;
};
#endif // COCKATRICE_MOVE_MENU_H