1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTREEVIEW_H |
5 | #define QTREEVIEW_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qabstractitemview.h> |
9 | |
10 | class tst_QTreeView; |
11 | |
12 | QT_REQUIRE_CONFIG(treeview); |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class QTreeViewPrivate; |
17 | class ; |
18 | |
19 | class Q_WIDGETS_EXPORT QTreeView : public QAbstractItemView |
20 | { |
21 | Q_OBJECT |
22 | Q_PROPERTY(int autoExpandDelay READ autoExpandDelay WRITE setAutoExpandDelay) |
23 | Q_PROPERTY(int indentation READ indentation WRITE setIndentation RESET resetIndentation) |
24 | Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated) |
25 | Q_PROPERTY(bool uniformRowHeights READ uniformRowHeights WRITE setUniformRowHeights) |
26 | Q_PROPERTY(bool itemsExpandable READ itemsExpandable WRITE setItemsExpandable) |
27 | Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled) |
28 | Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated) |
29 | Q_PROPERTY(bool allColumnsShowFocus READ allColumnsShowFocus WRITE setAllColumnsShowFocus) |
30 | Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap) |
31 | Q_PROPERTY(bool headerHidden READ isHeaderHidden WRITE setHeaderHidden) |
32 | Q_PROPERTY(bool expandsOnDoubleClick READ expandsOnDoubleClick WRITE setExpandsOnDoubleClick) |
33 | |
34 | public: |
35 | explicit QTreeView(QWidget *parent = nullptr); |
36 | ~QTreeView(); |
37 | |
38 | void setModel(QAbstractItemModel *model) override; |
39 | void setRootIndex(const QModelIndex &index) override; |
40 | void setSelectionModel(QItemSelectionModel *selectionModel) override; |
41 | |
42 | QHeaderView *() const; |
43 | void (QHeaderView *); |
44 | |
45 | int autoExpandDelay() const; |
46 | void setAutoExpandDelay(int delay); |
47 | |
48 | int indentation() const; |
49 | void setIndentation(int i); |
50 | void resetIndentation(); |
51 | |
52 | bool rootIsDecorated() const; |
53 | void setRootIsDecorated(bool show); |
54 | |
55 | bool uniformRowHeights() const; |
56 | void setUniformRowHeights(bool uniform); |
57 | |
58 | bool itemsExpandable() const; |
59 | void setItemsExpandable(bool enable); |
60 | |
61 | bool expandsOnDoubleClick() const; |
62 | void setExpandsOnDoubleClick(bool enable); |
63 | |
64 | int columnViewportPosition(int column) const; |
65 | int columnWidth(int column) const; |
66 | void setColumnWidth(int column, int width); |
67 | int columnAt(int x) const; |
68 | |
69 | bool isColumnHidden(int column) const; |
70 | void setColumnHidden(int column, bool hide); |
71 | |
72 | bool () const; |
73 | void (bool hide); |
74 | |
75 | bool isRowHidden(int row, const QModelIndex &parent) const; |
76 | void setRowHidden(int row, const QModelIndex &parent, bool hide); |
77 | |
78 | bool isFirstColumnSpanned(int row, const QModelIndex &parent) const; |
79 | void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span); |
80 | |
81 | bool isExpanded(const QModelIndex &index) const; |
82 | void setExpanded(const QModelIndex &index, bool expand); |
83 | |
84 | void setSortingEnabled(bool enable); |
85 | bool isSortingEnabled() const; |
86 | |
87 | void setAnimated(bool enable); |
88 | bool isAnimated() const; |
89 | |
90 | void setAllColumnsShowFocus(bool enable); |
91 | bool allColumnsShowFocus() const; |
92 | |
93 | void setWordWrap(bool on); |
94 | bool wordWrap() const; |
95 | |
96 | void setTreePosition(int logicalIndex); |
97 | int treePosition() const; |
98 | |
99 | void keyboardSearch(const QString &search) override; |
100 | |
101 | QRect visualRect(const QModelIndex &index) const override; |
102 | void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override; |
103 | QModelIndex indexAt(const QPoint &p) const override; |
104 | QModelIndex indexAbove(const QModelIndex &index) const; |
105 | QModelIndex indexBelow(const QModelIndex &index) const; |
106 | |
107 | void doItemsLayout() override; |
108 | void reset() override; |
109 | |
110 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, |
111 | const QList<int> &roles = QList<int>()) override; |
112 | void selectAll() override; |
113 | |
114 | Q_SIGNALS: |
115 | void expanded(const QModelIndex &index); |
116 | void collapsed(const QModelIndex &index); |
117 | |
118 | public Q_SLOTS: |
119 | void hideColumn(int column); |
120 | void showColumn(int column); |
121 | void expand(const QModelIndex &index); |
122 | void collapse(const QModelIndex &index); |
123 | void resizeColumnToContents(int column); |
124 | void sortByColumn(int column, Qt::SortOrder order); |
125 | void expandAll(); |
126 | void expandRecursively(const QModelIndex &index, int depth = -1); |
127 | void collapseAll(); |
128 | void expandToDepth(int depth); |
129 | |
130 | protected Q_SLOTS: |
131 | void columnResized(int column, int oldSize, int newSize); |
132 | void columnCountChanged(int oldCount, int newCount); |
133 | void columnMoved(); |
134 | void reexpand(); |
135 | void rowsRemoved(const QModelIndex &parent, int first, int last); |
136 | void verticalScrollbarValueChanged(int value) override; |
137 | |
138 | protected: |
139 | QTreeView(QTreeViewPrivate &dd, QWidget *parent = nullptr); |
140 | void scrollContentsBy(int dx, int dy) override; |
141 | void rowsInserted(const QModelIndex &parent, int start, int end) override; |
142 | void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override; |
143 | |
144 | QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override; |
145 | int horizontalOffset() const override; |
146 | int verticalOffset() const override; |
147 | |
148 | void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override; |
149 | QRegion visualRegionForSelection(const QItemSelection &selection) const override; |
150 | QModelIndexList selectedIndexes() const override; |
151 | |
152 | void changeEvent(QEvent *event) override; |
153 | void timerEvent(QTimerEvent *event) override; |
154 | void paintEvent(QPaintEvent *event) override; |
155 | |
156 | void drawTree(QPainter *painter, const QRegion ®ion) const; |
157 | virtual void drawRow(QPainter *painter, |
158 | const QStyleOptionViewItem &options, |
159 | const QModelIndex &index) const; |
160 | virtual void drawBranches(QPainter *painter, |
161 | const QRect &rect, |
162 | const QModelIndex &index) const; |
163 | |
164 | void mousePressEvent(QMouseEvent *event) override; |
165 | void mouseReleaseEvent(QMouseEvent *event) override; |
166 | void mouseDoubleClickEvent(QMouseEvent *event) override; |
167 | void mouseMoveEvent(QMouseEvent *event) override; |
168 | void keyPressEvent(QKeyEvent *event) override; |
169 | #if QT_CONFIG(draganddrop) |
170 | void dragMoveEvent(QDragMoveEvent *event) override; |
171 | #endif |
172 | bool viewportEvent(QEvent *event) override; |
173 | |
174 | void updateGeometries() override; |
175 | |
176 | QSize viewportSizeHint() const override; |
177 | |
178 | int sizeHintForColumn(int column) const override; |
179 | int indexRowSizeHint(const QModelIndex &index) const; |
180 | int rowHeight(const QModelIndex &index) const; |
181 | |
182 | void horizontalScrollbarAction(int action) override; |
183 | |
184 | bool isIndexHidden(const QModelIndex &index) const override; |
185 | void selectionChanged(const QItemSelection &selected, |
186 | const QItemSelection &deselected) override; |
187 | void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; |
188 | |
189 | private: |
190 | friend class ::tst_QTreeView; |
191 | friend class QAccessibleTable; |
192 | friend class QAccessibleTree; |
193 | friend class QAccessibleTableCell; |
194 | int visualIndex(const QModelIndex &index) const; |
195 | |
196 | Q_DECLARE_PRIVATE(QTreeView) |
197 | Q_DISABLE_COPY(QTreeView) |
198 | #if QT_CONFIG(animation) |
199 | Q_PRIVATE_SLOT(d_func(), void _q_endAnimatedOperation()) |
200 | #endif // animation |
201 | Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset()) |
202 | Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order)) |
203 | }; |
204 | |
205 | QT_END_NAMESPACE |
206 | |
207 | #endif // QTREEVIEW_H |
208 | |