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 inline int accessibleTable2Index(const QModelIndex &index) const {
145 const int vHeader = verticalHeader ? 1 : 0;
146 return (index.row() + (horizontalHeader ? 1 : 0)) * (index.model()->columnCount() + vHeader)
147 + index.column() + vHeader;
148 }
149
150 int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const;
151 int sectionSpanSize(const QHeaderView *header, int logical, int span) const;
152 bool spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const;
153 void drawAndClipSpans(const QRegion &area, QPainter *painter,
154 const QStyleOptionViewItem &option, QBitArray *drawn,
155 int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn);
156 void drawCell(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index);
157 int widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option) const;
158 int heightHintForIndex(const QModelIndex &index, int hint, QStyleOptionViewItem &option) const;
159
160 bool showGrid;
161 Qt::PenStyle gridStyle;
162 QBasicTimer columnResizeTimer;
163 QBasicTimer rowResizeTimer;
164 QList<int> columnsToUpdate;
165 QList<int> rowsToUpdate;
166 QHeaderView *horizontalHeader;
167 QHeaderView *verticalHeader;
168#if QT_CONFIG(abstractbutton)
169 QTableCornerButton *cornerWidget;
170 QMetaObject::Connection cornerWidgetConnection;
171#endif
172 QMetaObject::Connection selectionmodelConnection;
173 std::array<QMetaObject::Connection, 4> modelConnections;
174 std::array<QMetaObject::Connection, 7> verHeaderConnections;
175 std::array<QMetaObject::Connection, 5> horHeaderConnections;
176 std::vector<QMetaObject::Connection> dynHorHeaderConnections;
177
178 bool sortingEnabled;
179 bool geometryRecursionBlock;
180 QPoint visualCursor; // (Row,column) cell coordinates to track through span navigation.
181
182 QSpanCollection spans;
183
184 void setSpan(int row, int column, int rowSpan, int columnSpan);
185 QSpanCollection::Span span(int row, int column) const;
186 inline int rowSpan(int row, int column) const {
187 return span(row, column).height();
188 }
189 inline int columnSpan(int row, int column) const {
190 return span(row, column).width();
191 }
192 inline bool hasSpans() const {
193 return !spans.spans.empty();
194 }
195 inline int rowSpanHeight(int row, int span) const {
196 return sectionSpanSize(verticalHeader, row, span);
197 }
198 inline int columnSpanWidth(int column, int span) const {
199 return sectionSpanSize(horizontalHeader, column, span);
200 }
201 inline int rowSpanEndLogical(int row, int span) const {
202 return sectionSpanEndLogical(verticalHeader, row, span);
203 }
204 inline int columnSpanEndLogical(int column, int span) const {
205 return sectionSpanEndLogical(horizontalHeader, column, span);
206 }
207
208 inline bool isRowHidden(int row) const {
209 return verticalHeader->isSectionHidden(row);
210 }
211 inline bool isColumnHidden(int column) const {
212 return horizontalHeader->isSectionHidden(column);
213 }
214 inline bool isCellEnabled(int row, int column) const {
215 return isIndexEnabled(model->index(row, column, root));
216 }
217
218 enum class SearchDirection
219 {
220 Increasing,
221 Decreasing
222 };
223 int nextActiveVisualRow(int rowToStart, int column, int limit,
224 SearchDirection searchDirection) const;
225 int nextActiveVisualColumn(int row, int columnToStart, int limit,
226 SearchDirection searchDirection) const;
227
228 QRect visualSpanRect(const QSpanCollection::Span &span) const;
229
230 void selectRow(int row, bool anchor);
231 void selectColumn(int column, bool anchor);
232
233 void updateSpanInsertedRows(const QModelIndex &parent, int start, int end);
234 void updateSpanInsertedColumns(const QModelIndex &parent, int start, int end);
235 void updateSpanRemovedRows(const QModelIndex &parent, int start, int end);
236 void updateSpanRemovedColumns(const QModelIndex &parent, int start, int end);
237 void sortIndicatorChanged(int column, Qt::SortOrder order);
238};
239
240QT_END_NAMESPACE
241
242#endif // QTABLEVIEW_P_H
QT_REQUIRE_CONFIG(tableview)