Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qheaderview_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 QHEADERVIEW_P_H
5#define QHEADERVIEW_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 "qheaderview.h"
20#include "private/qabstractitemview_p.h"
21
22#include "QtCore/qbitarray.h"
23#include "QtWidgets/qapplication.h"
24#if QT_CONFIG(label)
25#include "QtWidgets/qlabel.h"
26#endif
27
28#include <array>
29
31
33
35{
36 Q_DECLARE_PUBLIC(QHeaderView)
37
38public:
39 enum StateVersion { VersionMarker = 0xff };
40
42 : state(NoState),
43 headerOffset(0),
44 sortIndicatorOrder(Qt::DescendingOrder),
48 lastPos(-1),
49 firstPos(-1),
50 originalSize(-1),
51 section(-1),
52 target(-1),
53 firstPressed(-1),
54 pressed(-1),
55 hover(-1),
56 length(0),
64 allowUserMoveOfSection0(true), // will be false for QTreeView and true for QTableView
71 lastSectionLogicalIdx(-1), // Only trust when we stretch last section
74 sectionIndicator(nullptr),
75#endif
76 globalResizeMode(QHeaderView::Interactive),
79 {}
80
81
82 int lastVisibleVisualIndex() const;
84 void setNewLastSection(int visualIndexForLastSection);
89 void updateHiddenSections(int logicalFirst, int logicalLast);
90 void resizeSections(QHeaderView::ResizeMode globalMode, bool useGlobalMode = false);
91 void sectionsRemoved(const QModelIndex &,int,int);
92 void sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart,
93 int logicalEnd, const QModelIndex &destinationParent,
94 int logicalDestination);
95 void sectionsMoved(const QModelIndex &sourceParent, int logicalStart,
96 int logicalEnd, const QModelIndex &destinationParent,
97 int logicalDestination);
98 void sectionsAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(),
100 void sectionsChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(),
102
103 bool isSectionSelected(int section) const;
104 bool isFirstVisibleSection(int section) const;
105 bool isLastVisibleSection(int section) const;
106
107 inline bool rowIntersectsSelection(int row) const {
109 }
110
111 inline bool columnIntersectsSelection(int column) const {
113 }
114
115 inline bool sectionIntersectsSelection(int logical) const {
117 }
118
119 inline bool isRowSelected(int row) const {
120 return (selectionModel ? selectionModel->isRowSelected(row, root) : false);
121 }
122
123 inline bool isColumnSelected(int column) const {
125 }
126
130 else if (sectionSelected.size() != sectionCount() * 2)
131 sectionSelected.fill(false, sectionCount() * 2);
132 else sectionSelected.fill(false);
133 }
134
135 inline int sectionCount() const {return sectionItems.size();}
136
137 inline bool reverse() const {
138 return orientation == Qt::Horizontal && q_func()->isRightToLeft();
139 }
140
141 inline int logicalIndex(int visualIndex) const {
143 }
144
145 inline int visualIndex(int logicalIndex) const {
147 }
148
156
157 inline bool isVisualIndexHidden(int visual) const {
158 return sectionItems.at(visual).isHidden;
159 }
160
161 inline void setVisualIndexHidden(int visual, bool hidden) {
162 sectionItems[visual].isHidden = hidden;
163 }
164
165 inline bool hasAutoResizeSections() const {
167 }
168
170
171 inline void invalidateCachedSizeHint() const {
173 }
174
175 inline void initializeIndexMapping() const {
177 || logicalIndices.size() != sectionCount()) {
180 for (int s = 0; s < sectionCount(); ++s) {
181 visualIndices[s] = s;
182 logicalIndices[s] = s;
183 }
184 }
185 }
186
192
193 inline void saveCascadingSectionSize(int visual, int size) {
194 if (!cascadingSectionSize.contains(visual)) {
198 }
199 }
200
201 inline bool sectionIsCascadable(int visual) const {
203 }
204
205 inline int modelSectionCount() const {
206 return (orientation == Qt::Horizontal
208 : model->rowCount(root));
209 }
210
212 if (!delayedResize.isActive())
213 delayedResize.start(0, q_func());
214 }
215
216 inline void executePostedResize() const {
217 if (delayedResize.isActive() && state == NoState) {
218 const_cast<QHeaderView*>(q_func())->resizeSections();
219 }
220 }
221
227
228 void clear();
229 void flipSortIndicator(int section);
231 void cascadingResize(int visual, int newSize);
232
234
241
242 mutable QList<int> visualIndices; // visualIndex = visualIndices.at(logicalIndex)
243 mutable QList<int> logicalIndices; // logicalIndex = row or column in the model
244 mutable QBitArray sectionSelected; // from logical index to bit
245 mutable QHash<int, int> hiddenSectionSize; // from logical index to section size
246 mutable QHash<int, int> cascadingSectionSize; // from visual index to section size
249
252
256 int section; // used for resizing and moving sections
260 int hover;
261
278 int lastSectionLogicalIdx; // Only trust if we stretch LastSection
280 Qt::Alignment defaultAlignment;
281#if QT_CONFIG(label)
282 QLabel *sectionIndicator;
283#endif
287 // header sections
288
289 struct SectionItem {
290 uint size : 20;
292 uint resizeMode : 5; // (holding QHeaderView::ResizeMode)
294
295 union { // This union is made in order to save space and ensure good vector performance (on remove)
296 mutable int calculated_startpos; // <- this is the primary used member.
297 mutable int tmpLogIdx; // When one of these 'tmp'-members has been used we call
298 int tmpDataStreamSectionCount; // recalcSectionStartPos() or set sectionStartposRecalc to true
299 }; // to ensure that calculated_startpos will be calculated afterwards.
300
301 inline SectionItem() : size(0), isHidden(0), resizeMode(QHeaderView::Interactive) {}
304 inline int sectionSize() const { return size; }
305 inline int calculatedEndPos() const { return calculated_startpos + size; }
306#ifndef QT_NO_DATASTREAM
307 inline void write(QDataStream &out) const
308 { out << static_cast<int>(size); out << 1; out << (int)resizeMode; }
309 inline void read(QDataStream &in)
310 { int m; in >> m; size = m; in >> tmpDataStreamSectionCount; in >> m; resizeMode = m; }
311#endif
312 };
313
314 QList<SectionItem> sectionItems;
319 QList<LayoutChangeItem> layoutChangePersistentSections;
320 std::array<QMetaObject::Connection, 8> modelConnections;
321
322 void createSectionItems(int start, int end, int sectionSize, QHeaderView::ResizeMode mode);
324 void resizeSectionItem(int visualIndex, int oldSize, int newSize);
325 void setDefaultSectionSize(int size);
327 void recalcSectionStartPos() const; // not really const
328
329 inline int headerLength() const { // for debugging
330 int len = 0;
331 for (const auto &section : sectionItems)
332 len += section.size;
333 return len;
334 }
335
337 {
338 QBitArray sectionHidden;
339 if (!hiddenSectionSize.isEmpty()) {
340 sectionHidden.resize(sectionItems.size());
341 for (int u = 0; u < sectionItems.size(); ++u)
342 sectionHidden[u] = sectionItems.at(u).isHidden;
343 }
344 return sectionHidden;
345 }
346
347 void setHiddenSectionsFromBitVector(const QBitArray &sectionHidden) {
348 SectionItem *sectionData = sectionItems.data();
349 for (int i = 0; i < sectionHidden.size(); ++i)
350 sectionData[i].isHidden = sectionHidden.at(i);
351 }
352
353 int headerSectionSize(int visual) const;
354 int headerSectionPosition(int visual) const;
355 int headerVisualIndexAt(int position) const;
356
357 // resize mode
361
362 // other
363 int viewSectionSizeHint(int logical) const;
364 int adjustedVisualIndex(int visualIndex) const;
366 void updateSectionsBeforeAfter(int logical);
367
368#ifndef QT_NO_DATASTREAM
369 void write(QDataStream &out) const;
370 bool read(QDataStream &in);
371#endif
372
373};
376
378
379#endif // QHEADERVIEW_P_H
LayoutChangeHint
This enum describes the way the model changes layout.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
QPointer< QItemSelectionModel > selectionModel
QPersistentModelIndex root
\inmodule QtCore
Definition qbasictimer.h:18
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
bool isActive() const noexcept
Returns true if the timer is running and has not been stopped; otherwise returns false.
Definition qbasictimer.h:34
\inmodule QtCore
Definition qbitarray.h:13
void clear()
Clears the contents of the bit array and makes it empty.
Definition qbitarray.h:87
bool fill(bool aval, qsizetype asize=-1)
Sets every bit in the bit array to value, returning true if successful; otherwise returns false.
Definition qbitarray.h:124
void resize(qsizetype size)
Resizes the bit array to size bits.
qsizetype size() const
Returns the number of bits stored in the bit array.
Definition qbitarray.h:76
\inmodule QtCore\reentrant
Definition qdatastream.h:46
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
Definition qhash.h:951
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
Definition qhash.h:928
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1303
int headerSectionSize(int visual) const
void updateDefaultSectionSizeFromStyle()
void sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination)
int headerLength() const
int headerVisualIndexAt(int position) const
void cascadingResize(int visual, int newSize)
Qt::SortOrder defaultSortOrderForSection(int section) const
void saveCascadingSectionSize(int visual, int size)
void setupSectionIndicator(int section, int position)
Qt::Alignment defaultAlignment
void setDefaultValues(Qt::Orientation o)
int logicalIndex(int visualIndex) const
void recalcSectionStartPos() const
void setNewLastSection(int visualIndexForLastSection)
void sectionsRemoved(const QModelIndex &, int, int)
void initializeIndexMapping() const
void sectionsAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void updateHiddenSections(int logicalFirst, int logicalLast)
void invalidateCachedSizeHint() const
bool rowIntersectsSelection(int row) const
void removeSectionsFromSectionItems(int start, int end)
Qt::Orientation orientation
QBitArray sectionSelected
void updateSectionIndicator(int section, int position)
int sectionCount() const
int lastVisibleVisualIndex() const
void createSectionItems(int start, int end, int sectionSize, QHeaderView::ResizeMode mode)
QHash< int, int > cascadingSectionSize
std::array< QMetaObject::Connection, 8 > modelConnections
bool sectionIsCascadable(int visual) const
int modelSectionCount() const
bool read(QDataStream &in)
bool isFirstVisibleSection(int section) const
bool isSectionSelected(int section) const
void restoreSizeOnPrevLastSection()
void setHeaderSectionResizeMode(int visual, QHeaderView::ResizeMode mode)
void resizeSections(QHeaderView::ResizeMode globalMode, bool useGlobalMode=false)
bool reverse() const
int headerSectionPosition(int visual) const
void setGlobalHeaderResizeMode(QHeaderView::ResizeMode mode)
void flipSortIndicator(int section)
bool isColumnSelected(int column) const
void write(QDataStream &out) const
bool preventCursorChangeInSetOffset
void executePostedResize() const
QHeaderView::ResizeMode globalResizeMode
void setHiddenSectionsFromBitVector(const QBitArray &sectionHidden)
void sectionsMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination)
int adjustedVisualIndex(int visualIndex) const
bool isRowSelected(int row) const
int visualIndex(int logicalIndex) const
bool isVisualIndexHidden(int visual) const
QStyleOptionHeader getStyleOption() const
QList< int > logicalIndices
enum QHeaderViewPrivate::State state
void resizeSectionItem(int visualIndex, int oldSize, int newSize)
bool isLastVisibleSection(int section) const
QHeaderView::ResizeMode headerSectionResizeMode(int visual) const
int sectionHandleAt(int position)
void setVisualIndexHidden(int visual, bool hidden)
void setScrollOffset(const QScrollBar *scrollBar, QAbstractItemView::ScrollMode scrollMode)
QBasicTimer delayedResize
QList< LayoutChangeItem > layoutChangePersistentSections
bool columnIntersectsSelection(int column) const
QHash< int, int > hiddenSectionSize
Qt::SortOrder sortIndicatorOrder
bool sectionIntersectsSelection(int logical) const
void setDefaultSectionSize(int size)
void maybeRestorePrevLastSectionAndStretchLast()
QBitArray sectionsHiddenToBitVector() const
void updateSectionsBeforeAfter(int logical)
void sectionsChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
QList< int > visualIndices
int viewSectionSizeHint(int logical) const
bool hasAutoResizeSections() const
QList< SectionItem > sectionItems
The QHeaderView class provides a header row or header column for item views.
Definition qheaderview.h:18
ResizeMode
The resize mode specifies the behavior of the header sections.
Definition qheaderview.h:39
Q_INVOKABLE bool isColumnSelected(int column, const QModelIndex &parent=QModelIndex()) const
Returns true if all items are selected in the column with the given parent.
Q_INVOKABLE bool isRowSelected(int row, const QModelIndex &parent=QModelIndex()) const
Returns true if all items are selected in the row with the given parent.
Q_INVOKABLE bool columnIntersectsSelection(int column, const QModelIndex &parent=QModelIndex()) const
Returns true if there are any items selected in the column with the given parent.
Q_INVOKABLE bool rowIntersectsSelection(int row, const QModelIndex &parent=QModelIndex()) const
Returns true if there are any items selected in the row with the given parent.
The QLabel widget provides a text or image display.
Definition qlabel.h:20
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void resize(qsizetype size)
Definition qlist.h:403
\inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection.
\inmodule QtCore
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition qscrollbar.h:20
\inmodule QtCore
Definition qsize.h:25
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ AlignVCenter
Definition qnamespace.h:155
@ AlignCenter
Definition qnamespace.h:163
@ AlignLeft
Definition qnamespace.h:144
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
SortOrder
Definition qnamespace.h:121
DBusConnection * connection
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLenum mode
const GLfloat * m
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLuint GLsizei const GLchar * label
[43]
GLenum target
GLuint start
GLenum GLenum GLsizei void GLsizei void * column
GLdouble s
[6]
Definition qopenglext.h:235
GLuint in
GLenum GLenum GLsizei void * row
GLenum GLsizei len
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_CONFIG(feature)
#define QT_REQUIRE_CONFIG(feature)
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
unsigned int uint
Definition qtypes.h:34
if(qFloatDistance(a, b)<(1<< 7))
[0]
QTextStream out(stdout)
[7]
QObject::connect nullptr
QScrollBar * scrollBar
void write(QDataStream &out) const
SectionItem(int length, QHeaderView::ResizeMode mode)