1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "abstractmenu.h" |
6 | |
7 | #include <QMenu> |
8 | #include <QDebug> |
9 | |
10 | class AbstractMenuPrivate |
11 | { |
12 | friend class AbstractMenu; |
13 | QMenu *menu; |
14 | }; |
15 | |
16 | AbstractMenu::AbstractMenu(void *qMenu) |
17 | : d(new AbstractMenuPrivate()) |
18 | { |
19 | if (!qMenu) { |
20 | qCritical() << "Failed, use QAction(0x0) to AbstractAction"; |
21 | abort(); |
22 | } |
23 | |
24 | d->menu = static_cast<QMenu*>(qMenu); |
25 | QMenu::connect(d->menu, &QMenu::destroyed, |
26 | d->menu, [this]() { |
27 | delete this; |
28 | },Qt::UniqueConnection); |
29 | } |
30 | |
31 | AbstractMenu::~AbstractMenu() |
32 | { |
33 | if (d) { |
34 | delete d; |
35 | } |
36 | } |
37 | |
38 | void *AbstractMenu::qMenu() |
39 | { |
40 | return d->menu; |
41 | } |
42 |