1 | /* $Id: UIChooserNode.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIChooserNode class definition.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-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 "UIChooserNode.h"
|
---|
30 | #include "UIChooserNodeGroup.h"
|
---|
31 | #include "UIChooserNodeGlobal.h"
|
---|
32 | #include "UIChooserNodeMachine.h"
|
---|
33 |
|
---|
34 | /* Other VBox includes: */
|
---|
35 | #include "iprt/cpp/utils.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | UIChooserNode::UIChooserNode(UIChooserNode *pParent /* = 0 */, bool fFavorite /* = false */)
|
---|
39 | : QObject(pParent)
|
---|
40 | , m_pParent(pParent)
|
---|
41 | , m_fFavorite(fFavorite)
|
---|
42 | , m_pModel(0)
|
---|
43 | , m_fDisabled(false)
|
---|
44 | {
|
---|
45 | }
|
---|
46 |
|
---|
47 | UIChooserNode::~UIChooserNode()
|
---|
48 | {
|
---|
49 | if (!m_pItem.isNull())
|
---|
50 | delete m_pItem.data();
|
---|
51 | }
|
---|
52 |
|
---|
53 | UIChooserNodeGroup *UIChooserNode::toGroupNode()
|
---|
54 | {
|
---|
55 | return static_cast<UIChooserNodeGroup*>(this);
|
---|
56 | }
|
---|
57 |
|
---|
58 | UIChooserNodeGlobal *UIChooserNode::toGlobalNode()
|
---|
59 | {
|
---|
60 | return static_cast<UIChooserNodeGlobal*>(this);
|
---|
61 | }
|
---|
62 |
|
---|
63 | UIChooserNodeMachine *UIChooserNode::toMachineNode()
|
---|
64 | {
|
---|
65 | return static_cast<UIChooserNodeMachine*>(this);
|
---|
66 | }
|
---|
67 |
|
---|
68 | UIChooserNode *UIChooserNode::rootNode() const
|
---|
69 | {
|
---|
70 | return isRoot() ? unconst(this) : parentNode()->rootNode();
|
---|
71 | }
|
---|
72 |
|
---|
73 | UIChooserAbstractModel *UIChooserNode::model() const
|
---|
74 | {
|
---|
75 | return m_pModel ? m_pModel : rootNode()->model();
|
---|
76 | }
|
---|
77 |
|
---|
78 | int UIChooserNode::position()
|
---|
79 | {
|
---|
80 | return parentNode() ? parentNode()->positionOf(this) : 0;
|
---|
81 | }
|
---|
82 |
|
---|
83 | bool UIChooserNode::isDisabled() const
|
---|
84 | {
|
---|
85 | return m_fDisabled;
|
---|
86 | }
|
---|
87 |
|
---|
88 | void UIChooserNode::setDisabled(bool fDisabled)
|
---|
89 | {
|
---|
90 | if (fDisabled == m_fDisabled)
|
---|
91 | return;
|
---|
92 | m_fDisabled = fDisabled;
|
---|
93 | if (m_pItem)
|
---|
94 | m_pItem->setDisabledEffect(m_fDisabled);
|
---|
95 | }
|
---|