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