Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtableview_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// Qt-Security score:significant reason:default
4
5#ifndef QTABLEVIEW_P_H
6#define QTABLEVIEW_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include "qtableview.h"
21#include "qheaderview.h"
22
23#include <QtCore/QBasicTimer>
24#include <QtCore/QList>
25#include <QtCore/QMap>
26#include <QtCore/QSet>
27#include "private/qabstractitemview_p.h"
28
29#include <array>
30#include <list>
31#include <vector>
32
34
36
37/** \internal
38*
39* This is a list of span with a binary index to look up quickly a span at a certain index.
40*
41* The index is a map of map.
42* spans are mentaly divided into sub spans so that the start of any subspans doesn't overlap
43* with any other subspans. There is no real representation of the subspans.
44* The key of the first map is the row where the subspan starts, the value of the first map is
45* a list (map) of all subspans that starts at the same row. It is indexed with its row
46*/
48{
49public:
50 struct Span
51 {
52 int m_top;
53 int m_left;
54 int m_bottom;
55 int m_right;
56 bool will_be_deleted;
57 Span()
58 : m_top(-1), m_left(-1), m_bottom(-1), m_right(-1), will_be_deleted(false) { }
59 Span(int row, int column, int rowCount, int columnCount)
60 : m_top(row), m_left(column), m_bottom(row+rowCount-1), m_right(column+columnCount-1), will_be_deleted(false) { }
61 inline int top() const { return m_top; }
62 inline int left() const { return m_left; }
63 inline int bottom() const { return m_bottom; }
64 inline int right() const { return m_right; }
65 inline int height() const { return m_bottom - m_top + 1; }
66 inline int width() const { return m_right - m_left + 1; }
67 };
68
69 ~QSpanCollection()
70 {
71 qDeleteAll(spans);
72 }
73
74 void addSpan(Span *span);
75 void updateSpan(Span *span, int old_height);
76 Span *spanAt(int x, int y) const;
77 void clear();
78 QSet<Span *> spansInRect(int x, int y, int w, int h) const;
79
80 void updateInsertedRows(int start, int end);
81 void updateInsertedColumns(int start, int end);
82 void updateRemovedRows(int start, int end);
83 void updateRemovedColumns(int start, int end);
84
85#ifdef QT_BUILD_INTERNAL
86 bool checkConsistency() const;
87#endif
88
89 typedef std::list<Span *> SpanList;
90 SpanList spans; //lists of all spans
91private:
92 //the indexes are negative so the QMap::lowerBound do what i need.
93 typedef QMap<int, Span *> SubIndex;
94 typedef QMap<int, SubIndex> Index;
95 Index index;
96
97 bool cleanSpanSubIndex(SubIndex &subindex, int end, bool update = false);
98};
99
100Q_DECLARE_TYPEINFO ( QSpanCollection::Span, Q_RELOCATABLE_TYPE);
101
102#if QT_CONFIG(abstractbutton)
103class QTableCornerButton;
104#endif
105class Q_AUTOTEST_EXPORT QTableViewPrivate : public QAbstractItemViewPrivate
106{
107 Q_DECLARE_PUBLIC(QTableView)
108public:
109 QTableViewPrivate()
110 : showGrid(true), gridStyle(Qt::SolidLine),
111 horizontalHeader(nullptr), verticalHeader(nullptr),
112 sortingEnabled(false), geometryRecursionBlock(false),
113 visualCursor(QPoint())
114 {
115 wrapItemText = true;
116#if QT_CONFIG(draganddrop)
117 overwrite = true;
118#endif
119 }
120 void init();
121 void clearConnections();
122 void trimHiddenSelections(QItemSelectionRange *range) const;
123 QRect intersectedRect(const QRect rect, const QModelIndex &topLeft, const QModelIndex &bottomRight) const override;
124
125 inline bool isHidden(int row, int col) const {
126 return verticalHeader->isSectionHidden(row)
127 || horizontalHeader->isSectionHidden(col);
128 }
129 inline int visualRow(int logicalRow) const {
130 return verticalHeader->visualIndex(logicalRow);
131 }
132 inline int visualColumn(int logicalCol) const {
133 return horizontalHeader->visualIndex(logicalCol);
134 }
135 inline int logicalRow(int visualRow) const {
136 return verticalHeader->logicalIndex(visualRow);
137 }
138 inline int logicalColumn(int visualCol) const {
139 return horizontalHeader->logicalIndex(visualCol);
140 }
141
142 QStyleOptionViewItem::ViewItemPosition viewItemPosition(const QModelIndex &index) const;
143
144#if QT_CONFIG(accessibility)
145 inline int accessibleChildIndex(const QModelIndex &index) const override
146 {
147 const int vHeader = verticalHeader ? 1 : 0;
148 return (index.row() + (horizontalHeader ? 1 : 0)) * (index.model()->columnCount() + vHeader)
149 + index.column() + vHeader;
150 }
151#endif
152
153 int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const;
154 int sectionSpanSize(const QHeaderView *header, int logical, int span) const;
155 bool spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const;
156 void drawAndClipSpans(const QRegion &area, QPainter *painter,
157 const QStyleOptionViewItem &option, QBitArray *drawn,
158 int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn);
159 void drawCell(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index);
160 int widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option) const;
161 int heightHintForIndex(const QModelIndex &index, int hint, QStyleOptionViewItem &option) const;
162
163 bool showGrid;
164 Qt::PenStyle gridStyle;
165 QBasicTimer columnResizeTimer;
166 QBasicTimer rowResizeTimer;
167 QList<int> columnsToUpdate;
168 QList<int> rowsToUpdate;
169 QHeaderView *horizontalHeader;
170 QHeaderView *verticalHeader;
171#if QT_CONFIG(abstractbutton)
172 QTableCornerButton *cornerWidget;
173 QMetaObject::Connection cornerWidgetConnection;
174#endif
175 QMetaObject::Connection selectionmodelConnection;
176 std::array<QMetaObject::Connection, 4> modelConnections;
177 std::array<QMetaObject::Connection, 7> verHeaderConnections;
178 std::array<QMetaObject::Connection, 5> horHeaderConnections;
179 std::vector<QMetaObject::Connection> dynHorHeaderConnections;
180
181 bool sortingEnabled;
182 bool geometryRecursionBlock;
183 QPoint visualCursor; // (Row,column) cell coordinates to track through span navigation.
184
185 QSpanCollection spans;
186
187 void setSpan(int row, int column, int rowSpan, int columnSpan);
188 QSpanCollection::Span span(int row, int column) const;
189 inline int rowSpan(int row, int column) const {
190 return span(row, column).height();
191 }
192 inline int columnSpan(int row, int column) const {
193 return span(row, column).width();
194 }
195 inline bool hasSpans() const {
196 return !spans.spans.empty();
197 }
198 inline int rowSpanHeight(int row, int span) const {
199 return sectionSpanSize(verticalHeader, row, span);
200 }
201 inline int columnSpanWidth(int column, int span) const {
202 return sectionSpanSize(horizontalHeader, column, span);
203 }
204 inline int rowSpanEndLogical(int row, int span) const {
205 return sectionSpanEndLogical(verticalHeader, row, span);
206 }
207 inline int columnSpanEndLogical(int column, int span) const {
208 return sectionSpanEndLogical(horizontalHeader, column, span);
209 }
210
211 inline bool isRowHidden(int row) const {
212 return verticalHeader->isSectionHidden(row);
213 }
214 inline bool isColumnHidden(int column) const {
215 return horizontalHeader->isSectionHidden(column);
216 }
217 inline bool isCellEnabled(int row, int column) const {
218 return isIndexEnabled(model->index(row, column, root));
219 }
220
221 enum class SearchDirection
222 {
223 Increasing,
224 Decreasing
225 };
226 int nextActiveVisualRow(int rowToStart, int column, int limit,
227 SearchDirection searchDirection) const;
228 int nextActiveVisualColumn(int row, int columnToStart, int limit,
229 SearchDirection searchDirection) const;
230
231 QRect visualSpanRect(const QSpanCollection::Span &span) const;
232
233 void selectRow(int row, bool anchor);
234 void selectColumn(int column, bool anchor);
235
236 void updateSpanInsertedRows(const QModelIndex &parent, int start, int end);
237 void updateSpanInsertedColumns(const QModelIndex &parent, int start, int end);
238 void updateSpanRemovedRows(const QModelIndex &parent, int start, int end);
239 void updateSpanRemovedColumns(const QModelIndex &parent, int start, int end);
240 void sortIndicatorChanged(int column, Qt::SortOrder order);
241};
242
243QT_END_NAMESPACE
244
245#endif // QTABLEVIEW_P_H
QT_REQUIRE_CONFIG(tableview)