1 | /* $Id: UIQObjectStuff.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIQObjectStuff class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* GUI includes: */
|
---|
29 | #include "UIQObjectStuff.h"
|
---|
30 |
|
---|
31 |
|
---|
32 | UIQObjectPropertySetter::UIQObjectPropertySetter(QObject *pObject, const QString &strPropertyName, const QVariant &value)
|
---|
33 | : m_strPropertyName(strPropertyName)
|
---|
34 | , m_value(value)
|
---|
35 | {
|
---|
36 | /* Add object into list: */
|
---|
37 | m_objects << pObject;
|
---|
38 | /* Init properties: */
|
---|
39 | init();
|
---|
40 | }
|
---|
41 |
|
---|
42 | UIQObjectPropertySetter::UIQObjectPropertySetter(const QList<QObject*> &objects, const QString &strPropertyName, const QVariant &value)
|
---|
43 | : m_strPropertyName(strPropertyName)
|
---|
44 | , m_value(value)
|
---|
45 | {
|
---|
46 | /* Add objects into list: */
|
---|
47 | foreach (QObject *pObject, objects)
|
---|
48 | m_objects << pObject;
|
---|
49 | /* Init properties: */
|
---|
50 | init();
|
---|
51 | }
|
---|
52 |
|
---|
53 | UIQObjectPropertySetter::~UIQObjectPropertySetter()
|
---|
54 | {
|
---|
55 | /* Deinit properties: */
|
---|
56 | deinit();
|
---|
57 | /* Notify listeners that we are done: */
|
---|
58 | emit sigAboutToBeDestroyed();
|
---|
59 | }
|
---|
60 |
|
---|
61 | void UIQObjectPropertySetter::init()
|
---|
62 | {
|
---|
63 | foreach (const QPointer<QObject> &pObject, m_objects)
|
---|
64 | {
|
---|
65 | if (pObject)
|
---|
66 | {
|
---|
67 | pObject->setProperty(m_strPropertyName.toLatin1().constData(), m_value);
|
---|
68 | //printf("UIQObjectPropertySetter::UIQObjectPropertySetter: Property {%s} set.\n",
|
---|
69 | // m_strPropertyName.toLatin1().constData());
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | void UIQObjectPropertySetter::deinit()
|
---|
75 | {
|
---|
76 | foreach (const QPointer<QObject> &pObject, m_objects)
|
---|
77 | {
|
---|
78 | if (pObject)
|
---|
79 | {
|
---|
80 | pObject->setProperty(m_strPropertyName.toLatin1().constData(), QVariant());
|
---|
81 | //printf("UIQObjectPropertySetter::~UIQObjectPropertySetter: Property {%s} cleared.\n",
|
---|
82 | // m_strPropertyName.toLatin1().constData());
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|