1 | /* $Id: QITreeWidget.h 103988 2024-03-21 13:49:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QITreeWidget class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2023 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 | #ifndef FEQT_INCLUDED_SRC_extensions_QITreeWidget_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QITreeWidget_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QTreeWidget>
|
---|
36 | #include <QTreeWidgetItem>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 |
|
---|
41 | /* Forward declarations: */
|
---|
42 | class QITreeWidget;
|
---|
43 |
|
---|
44 | /** A functor base to be passed to QITabWidget::filterItems(..).
|
---|
45 | * Overload operator()(..) to filter out tree items. */
|
---|
46 | class SHARED_LIBRARY_STUFF QITreeWidgetItemFilter
|
---|
47 | {
|
---|
48 | public:
|
---|
49 |
|
---|
50 | /** Destructs item filter. */
|
---|
51 | virtual ~QITreeWidgetItemFilter() { /* Make VC++ 19.2 happy. */ }
|
---|
52 |
|
---|
53 | /** Returns whether item can pass the filter. */
|
---|
54 | virtual bool operator()(QTreeWidgetItem*) const
|
---|
55 | {
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 | };
|
---|
59 |
|
---|
60 | /** QTreeWidgetItem subclass extending standard functionality. */
|
---|
61 | class SHARED_LIBRARY_STUFF QITreeWidgetItem : public QObject, public QTreeWidgetItem
|
---|
62 | {
|
---|
63 | Q_OBJECT;
|
---|
64 |
|
---|
65 | public:
|
---|
66 |
|
---|
67 | /** Item type for QITreeWidgetItem. */
|
---|
68 | enum { ItemType = QTreeWidgetItem::UserType + 1 };
|
---|
69 |
|
---|
70 | /** Casts QTreeWidgetItem* to QITreeWidgetItem* if possible. */
|
---|
71 | static QITreeWidgetItem *toItem(QTreeWidgetItem *pItem);
|
---|
72 | /** Casts const QTreeWidgetItem* to const QITreeWidgetItem* if possible. */
|
---|
73 | static const QITreeWidgetItem *toItem(const QTreeWidgetItem *pItem);
|
---|
74 |
|
---|
75 | /** Constructs item. */
|
---|
76 | QITreeWidgetItem();
|
---|
77 |
|
---|
78 | /** Constructs item passing @a pTreeWidget into the base-class. */
|
---|
79 | QITreeWidgetItem(QITreeWidget *pTreeWidget);
|
---|
80 | /** Constructs item passing @a pTreeWidgetItem into the base-class. */
|
---|
81 | QITreeWidgetItem(QITreeWidgetItem *pTreeWidgetItem);
|
---|
82 |
|
---|
83 | /** Constructs item passing @a pTreeWidget and @a strings into the base-class. */
|
---|
84 | QITreeWidgetItem(QITreeWidget *pTreeWidget, const QStringList &strings);
|
---|
85 | /** Constructs item passing @a pTreeWidgetItem and @a strings into the base-class. */
|
---|
86 | QITreeWidgetItem(QITreeWidgetItem *pTreeWidgetItem, const QStringList &strings);
|
---|
87 |
|
---|
88 | /** Returns the parent tree-widget. */
|
---|
89 | QITreeWidget *parentTree() const;
|
---|
90 | /** Returns the parent tree-widget item. */
|
---|
91 | QITreeWidgetItem *parentItem() const;
|
---|
92 |
|
---|
93 | /** Returns the child tree-widget item with @a iIndex. */
|
---|
94 | QITreeWidgetItem *childItem(int iIndex) const;
|
---|
95 |
|
---|
96 | /** Returns default text. */
|
---|
97 | virtual QString defaultText() const;
|
---|
98 | };
|
---|
99 |
|
---|
100 |
|
---|
101 | /** QTreeWidget subclass extending standard functionality. */
|
---|
102 | class SHARED_LIBRARY_STUFF QITreeWidget : public QTreeWidget
|
---|
103 | {
|
---|
104 | Q_OBJECT;
|
---|
105 |
|
---|
106 | signals:
|
---|
107 |
|
---|
108 | /** Notifies about particular tree-widget @a pItem is painted with @a pPainter. */
|
---|
109 | void painted(QTreeWidgetItem *pItem, QPainter *pPainter);
|
---|
110 | /** Notifies about tree-widget being resized from @a oldSize to @a size. */
|
---|
111 | void resized(const QSize &size, const QSize &oldSize);
|
---|
112 |
|
---|
113 | public:
|
---|
114 |
|
---|
115 | /** Constructs tree-widget passing @a pParent to the base-class.
|
---|
116 | * @param fDelegatePaintingToSubclass Brings whether painting should be fully delegated to sub-class. */
|
---|
117 | QITreeWidget(QWidget *pParent = 0, bool fDelegatePaintingToSubclass = false);
|
---|
118 |
|
---|
119 | /** Defines @a sizeHint for tree-widget items. */
|
---|
120 | void setSizeHintForItems(const QSize &sizeHint);
|
---|
121 |
|
---|
122 | /** Returns the number of children. */
|
---|
123 | int childCount() const;
|
---|
124 | /** Returns the child item with @a iIndex. */
|
---|
125 | QITreeWidgetItem *childItem(int iIndex) const;
|
---|
126 | /** Returns a model-index of @a pItem specified. */
|
---|
127 | QModelIndex itemIndex(QTreeWidgetItem *pItem);
|
---|
128 | /** Recurses thru the subtree with a root @a pParent and returns a list of tree-items filtered by @a filter.
|
---|
129 | * When @a pParent is null then QTreeWidget::invisibleRootItem() is used as the root item. */
|
---|
130 | QList<QTreeWidgetItem*> filterItems(const QITreeWidgetItemFilter &filter, QTreeWidgetItem *pParent = 0);
|
---|
131 |
|
---|
132 | protected:
|
---|
133 |
|
---|
134 | /** Handles paint @a pEvent. */
|
---|
135 | void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE RT_FINAL;
|
---|
136 | /** Handles resize @a pEvent. */
|
---|
137 | void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE RT_FINAL;
|
---|
138 |
|
---|
139 | private:
|
---|
140 |
|
---|
141 | /** Recurses thru the subtree with a root @a pParent and appends a
|
---|
142 | * list of tree-items filtered by @a filter to @a filteredItemList. */
|
---|
143 | void filterItemsInternal(const QITreeWidgetItemFilter &filter, QTreeWidgetItem *pParent,
|
---|
144 | QList<QTreeWidgetItem*> &filteredItemList);
|
---|
145 |
|
---|
146 | /** Holds whether painting should be fully delegated to sub-class. */
|
---|
147 | bool m_fDelegatePaintingToSubclass;
|
---|
148 | };
|
---|
149 |
|
---|
150 |
|
---|
151 | #endif /* !FEQT_INCLUDED_SRC_extensions_QITreeWidget_h */
|
---|