Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtreeview_p.h
Go to the documentation of this file.
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_P_H
5#define QTREEVIEW_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "private/qabstractitemview_p.h"
20#include <QtCore/qabstractitemmodel.h>
21#include <QtCore/qlist.h>
22#if QT_CONFIG(animation)
23#include <QtCore/qvariantanimation.h>
24#endif
25
27
29
31{
33 hasMoreSiblings(false), total(0), level(0), height(0) {}
34 QModelIndex index; // we remove items whenever the indexes are invalidated
35 int parentItem; // parent item index in viewItems
38 uint hasChildren : 1; // if the item has visible children (even if collapsed)
40 uint total : 28; // total number of children visible
41 uint level : 16; // indentation
42 int height : 16; // row height
43};
44
46
47class Q_WIDGETS_EXPORT QTreeViewPrivate : public QAbstractItemViewPrivate
48{
49 Q_DECLARE_PUBLIC(QTreeView)
50public:
51
54 header(nullptr), indent(20), lastViewedItem(0), defaultItemHeight(-1),
55 uniformRowHeights(false), rootDecoration(true),
56 itemsExpandable(true), sortingEnabled(false),
57 expandsOnDoubleClick(true),
58 allColumnsShowFocus(false), customIndent(false), current(0), spanning(false),
59 animationsEnabled(false), columnResizeTimerID(0),
60 autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false), hasRemovedItems(false),
61 treePosition(0) {}
62
64 void initialize();
65 int logicalIndexForTree() const;
66 inline bool isTreePosition(int logicalIndex) const
67 {
68 return logicalIndex == logicalIndexForTree();
69 }
70
71 QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const override;
72 void adjustViewOptionsForIndex(QStyleOptionViewItem *option, const QModelIndex &current) const override;
73
74#if QT_CONFIG(animation)
75 struct AnimatedOperation : public QVariantAnimation
76 {
77 int item;
78 QPixmap before;
79 QPixmap after;
81 AnimatedOperation() : item(0) { setEasingCurve(QEasingCurve::InOutQuad); }
82 int top() const { return startValue().toInt(); }
83 QRect rect() const { QRect rect = viewport->rect(); rect.moveTop(top()); return rect; }
84 void updateCurrentValue(const QVariant &) override { viewport->update(rect()); }
85 void updateState(State state, State) override { if (state == Stopped) before = after = QPixmap(); }
86 } animatedOperation;
87 void prepareAnimatedOperation(int item, QVariantAnimation::Direction d);
88 void beginAnimatedOperation();
89 void drawAnimatedOperation(QPainter *painter) const;
90 QPixmap renderTreeToPixmapForAnimation(const QRect &rect) const;
91 void _q_endAnimatedOperation();
92#endif // animation
93
94 void expand(int item, bool emitSignal);
95 void collapse(int item, bool emitSignal);
96
97 void _q_columnsAboutToBeRemoved(const QModelIndex &, int, int) override;
98 void _q_columnsRemoved(const QModelIndex &, int, int) override;
99 void _q_modelAboutToBeReset();
100 void _q_sortIndicatorChanged(int column, Qt::SortOrder order);
101 void _q_modelDestroyed() override;
102 QRect intersectedRect(const QRect rect, const QModelIndex &topLeft, const QModelIndex &bottomRight) const override;
103
104 void layout(int item, bool recusiveExpanding = false, bool afterIsUninitialized = false);
105
106 int pageUp(int item) const;
107 int pageDown(int item) const;
108 int itemForKeyHome() const;
109 int itemForKeyEnd() const;
110
111 int itemHeight(int item) const;
112 int indentationForItem(int item) const;
113 int coordinateForItem(int item) const;
114 int itemAtCoordinate(int coordinate) const;
115
116 int viewIndex(const QModelIndex &index) const;
117 QModelIndex modelIndex(int i, int column = 0) const;
118
119 void insertViewItems(int pos, int count, const QTreeViewItem &viewItem);
120 void removeViewItems(int pos, int count);
121#if 0
122 bool checkViewItems() const;
123#endif
124
125 int firstVisibleItem(int *offset = nullptr) const;
126 int lastVisibleItem(int firstVisual = -1, int offset = -1) const;
127 int columnAt(int x) const;
128 bool hasVisibleChildren( const QModelIndex& parent) const;
129
130 bool expandOrCollapseItemAtPos(const QPoint &pos);
131
132 void updateScrollBars();
133
134 int itemDecorationAt(const QPoint &pos) const;
135 QRect itemDecorationRect(const QModelIndex &index) const;
136
137 QList<QPair<int, int>> columnRanges(const QModelIndex &topIndex,
138 const QModelIndex &bottomIndex) const;
139 void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command);
140
141 QPair<int,int> startAndEndColumns(const QRect &rect) const;
142
143 void updateChildCount(const int parentItem, const int delta);
144
145 void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItem *option, int y, int bottom) const;
146
147 // logicalIndices: vector of currently visibly logical indices
148 // itemPositions: vector of view item positions (beginning/middle/end/onlyone)
149 void calcLogicalIndices(QList<int> *logicalIndices,
151 int right) const;
152 int widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option, int i) const;
155
157 mutable int lastViewedItem;
158 int defaultItemHeight; // this is just a number; contentsHeight() / numItems
159 bool uniformRowHeights; // used when all rows have the same height
166
167 // used for drawing
169 mutable int current;
170 mutable bool spanning;
171
172 // used when expanding and collapsing items
175
176 inline bool storeExpanded(const QPersistentModelIndex &idx) {
177 if (expandedIndexes.contains(idx))
178 return false;
179 expandedIndexes.insert(idx);
180 return true;
181 }
182
183 inline bool isIndexExpanded(const QModelIndex &idx) const {
184 //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
185 return !(idx.flags() & Qt::ItemNeverHasChildren) && isPersistent(idx) && expandedIndexes.contains(idx);
186 }
187
188 // used when hiding and showing items
190
191 inline bool isRowHidden(const QModelIndex &idx) const {
192 if (hiddenIndexes.isEmpty())
193 return false;
194 //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
195 return isPersistent(idx) && hiddenIndexes.contains(idx);
196 }
197
198 inline bool isItemHiddenOrDisabled(int i) const {
199 if (i < 0 || i >= viewItems.size())
200 return false;
201 const QModelIndex index = viewItems.at(i).index;
202 return isRowHidden(index) || !isIndexEnabled(index);
203 }
204
205 inline int above(int item) const
206 { int i = item; while (isItemHiddenOrDisabled(--item)){} return item < 0 ? i : item; }
207 inline int below(int item) const
208 { int i = item; while (isItemHiddenOrDisabled(++item)){} return item >= viewItems.size() ? i : item; }
209 inline void invalidateHeightCache(int item) const
210 { viewItems[item].height = 0; }
211
212 inline int accessibleTable2Index(const QModelIndex &index) const {
213 return (viewIndex(index) + (header ? 1 : 0)) * model->columnCount()+index.column();
214 }
215
216 int accessibleTree2Index(const QModelIndex &index) const;
217
218 void updateIndentationFromStyle();
219
220 // used for spanning rows
222
223 // used for updating resized columns
226
227 // used for the automatic opening of nodes during DND
230
231 // used for drawing highlighted expand/collapse indicators
232 mutable int hoverBranch;
233
234 // used for blocking recursion when calling setViewportMargins from updateGeometries
236
237 // If we should clean the set
239
240 // tree position
242};
243
245
246#endif // QTREEVIEW_P_H
Direction
This enum describes the direction of the animation when in \l Running state.
virtual QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
virtual void adjustViewOptionsForIndex(QStyleOptionViewItem *, const QModelIndex &) const
virtual QRect intersectedRect(const QRect rect, const QModelIndex &topLeft, const QModelIndex &bottomRight) const
virtual void _q_columnsRemoved(const QModelIndex &parent, int start, int end)
bool isPersistent(const QModelIndex &index) const
virtual void _q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
bool isIndexEnabled(const QModelIndex &index) const
\inmodule QtCore
Definition qbasictimer.h:18
The QHeaderView class provides a header row or header column for item views.
Definition qheaderview.h:18
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
\inmodule QtCore
Qt::ItemFlags flags() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:30
Definition qset.h:18
bool isEmpty() const
Definition qset.h:52
bool contains(const T &value) const
Definition qset.h:71
iterator insert(const T &value)
Definition qset.h:155
int columnCount(const QModelIndex &parent=QModelIndex()) const override
\reimp
QHeaderView * header
bool isRowHidden(const QModelIndex &idx) const
bool isItemHiddenOrDisabled(int i) const
void invalidateHeightCache(int item) const
bool isIndexExpanded(const QModelIndex &idx) const
bool storeExpanded(const QPersistentModelIndex &idx)
int below(int item) const
bool isTreePosition(int logicalIndex) const
Definition qtreeview_p.h:66
QPair< int, int > leftAndRight
QList< int > columnsToUpdate
QList< QTreeViewItem > viewItems
int accessibleTable2Index(const QModelIndex &index) const
int above(int item) const
QSet< QPersistentModelIndex > hiddenIndexes
QSet< QPersistentModelIndex > spanningIndexes
bool geometryRecursionBlock
QSet< QPersistentModelIndex > expandedIndexes
QBasicTimer openTimer
void updateChildCount(const int parentItem, const int delta)
The QTreeView class provides a default model/view implementation of a tree view.
Definition qtreeview.h:20
\inmodule QtCore
\inmodule QtCore
Definition qvariant.h:64
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
rect
[4]
else opt state
[0]
Combined button and popup list for selecting options.
SortOrder
Definition qnamespace.h:120
@ ItemNeverHasChildren
std::pair< T1, T2 > QPair
static bool initialize()
Definition qctf.cpp:67
static QString header(const QString &name)
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLint level
GLint GLsizei GLsizei height
GLuint index
[2]
GLboolean r
[2]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint left
GLint GLint bottom
GLuint start
GLenum GLuint GLintptr offset
GLint y
GLenum GLenum GLsizei void GLsizei void * column
GLuint GLenum option
GLfixed GLfixed GLint GLint order
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_REQUIRE_CONFIG(feature)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
unsigned int uint
Definition qtypes.h:29
QSqlQueryModel * model
[16]
QObject::connect nullptr
QVBoxLayout * layout
animation setEasingCurve(QEasingCurve::InOutQuad)
QGraphicsItem * item
view viewport() -> scroll(dx, dy, deviceRect)
selection select(topLeft, bottomRight)
QPainter painter(this)
[7]
QModelIndex index
Definition qtreeview_p.h:34
uint hasMoreSiblings
Definition qtreeview_p.h:39
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent