Qt 6.x
The Qt SDK
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
29
31
33{
34 Q_DECLARE_PUBLIC(QHeaderView)
35
36public:
37 enum StateVersion { VersionMarker = 0xff };
38
40 : state(NoState),
41 offset(0),
42 sortIndicatorOrder(Qt::DescendingOrder),
46 lastPos(-1),
47 firstPos(-1),
48 originalSize(-1),
49 section(-1),
50 target(-1),
51 firstPressed(-1),
52 pressed(-1),
53 hover(-1),
54 length(0),
62 allowUserMoveOfSection0(true), // will be false for QTreeView and true for QTableView
69 lastSectionLogicalIdx(-1), // Only trust when we stretch last section
72 sectionIndicator(nullptr),
73#endif
74 globalResizeMode(QHeaderView::Interactive),
77 {}
78
79
80 int lastVisibleVisualIndex() const;
82 void setNewLastSection(int visualIndexForLastSection);
87 void updateHiddenSections(int logicalFirst, int logicalLast);
88 void resizeSections(QHeaderView::ResizeMode globalMode, bool useGlobalMode = false);
89 void _q_sectionsRemoved(const QModelIndex &,int,int);
90 void _q_sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination);
91 void _q_sectionsMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination);
96
97 bool isSectionSelected(int section) const;
98 bool isFirstVisibleSection(int section) const;
99 bool isLastVisibleSection(int section) const;
100
101 inline bool rowIntersectsSelection(int row) const {
103 }
104
105 inline bool columnIntersectsSelection(int column) const {
107 }
108
109 inline bool sectionIntersectsSelection(int logical) const {
111 }
112
113 inline bool isRowSelected(int row) const {
114 return (selectionModel ? selectionModel->isRowSelected(row, root) : false);
115 }
116
117 inline bool isColumnSelected(int column) const {
119 }
120
124 else if (sectionSelected.size() != sectionCount() * 2)
125 sectionSelected.fill(false, sectionCount() * 2);
126 else sectionSelected.fill(false);
127 }
128
129 inline int sectionCount() const {return sectionItems.size();}
130
131 inline bool reverse() const {
132 return orientation == Qt::Horizontal && q_func()->isRightToLeft();
133 }
134
135 inline int logicalIndex(int visualIndex) const {
137 }
138
139 inline int visualIndex(int logicalIndex) const {
141 }
142
144 orientation = o;
147 ? Qt::Alignment(Qt::AlignCenter)
149 }
150
151 inline bool isVisualIndexHidden(int visual) const {
152 return sectionItems.at(visual).isHidden;
153 }
154
155 inline void setVisualIndexHidden(int visual, bool hidden) {
156 sectionItems[visual].isHidden = hidden;
157 }
158
159 inline bool hasAutoResizeSections() const {
161 }
162
164
165 inline void invalidateCachedSizeHint() const {
167 }
168
169 inline void initializeIndexMapping() const {
171 || logicalIndices.size() != sectionCount()) {
174 for (int s = 0; s < sectionCount(); ++s) {
175 visualIndices[s] = s;
176 logicalIndices[s] = s;
177 }
178 }
179 }
180
185 }
186
187 inline void saveCascadingSectionSize(int visual, int size) {
188 if (!cascadingSectionSize.contains(visual)) {
192 }
193 }
194
195 inline bool sectionIsCascadable(int visual) const {
197 }
198
199 inline int modelSectionCount() const {
200 return (orientation == Qt::Horizontal
202 : model->rowCount(root));
203 }
204
206 if (!delayedResize.isActive())
207 delayedResize.start(0, q_func());
208 }
209
210 inline void executePostedResize() const {
211 if (delayedResize.isActive() && state == NoState) {
212 const_cast<QHeaderView*>(q_func())->resizeSections();
213 }
214 }
215
216 void clear();
217 void flipSortIndicator(int section);
219 void cascadingResize(int visual, int newSize);
220
222
229
230 mutable QList<int> visualIndices; // visualIndex = visualIndices.at(logicalIndex)
231 mutable QList<int> logicalIndices; // logicalIndex = row or column in the model
232 mutable QBitArray sectionSelected; // from logical index to bit
233 mutable QHash<int, int> hiddenSectionSize; // from logical index to section size
234 mutable QHash<int, int> cascadingSectionSize; // from visual index to section size
237
240
244 int section; // used for resizing and moving sections
248 int hover;
249
266 int lastSectionLogicalIdx; // Only trust if we stretch LastSection
268 Qt::Alignment defaultAlignment;
269#if QT_CONFIG(label)
270 QLabel *sectionIndicator;
271#endif
275 // header sections
276
277 struct SectionItem {
278 uint size : 20;
280 uint resizeMode : 5; // (holding QHeaderView::ResizeMode)
282
283 union { // This union is made in order to save space and ensure good vector performance (on remove)
284 mutable int calculated_startpos; // <- this is the primary used member.
285 mutable int tmpLogIdx; // When one of these 'tmp'-members has been used we call
286 int tmpDataStreamSectionCount; // recalcSectionStartPos() or set sectionStartposRecalc to true
287 }; // to ensure that calculated_startpos will be calculated afterwards.
288
289 inline SectionItem() : size(0), isHidden(0), resizeMode(QHeaderView::Interactive) {}
292 inline int sectionSize() const { return size; }
293 inline int calculatedEndPos() const { return calculated_startpos + size; }
294#ifndef QT_NO_DATASTREAM
295 inline void write(QDataStream &out) const
296 { out << static_cast<int>(size); out << 1; out << (int)resizeMode; }
297 inline void read(QDataStream &in)
298 { int m; in >> m; size = m; in >> tmpDataStreamSectionCount; in >> m; resizeMode = m; }
299#endif
300 };
301
306 };
308
309 void createSectionItems(int start, int end, int sectionSize, QHeaderView::ResizeMode mode);
311 void resizeSectionItem(int visualIndex, int oldSize, int newSize);
312 void setDefaultSectionSize(int size);
314 void recalcSectionStartPos() const; // not really const
315
316 inline int headerLength() const { // for debugging
317 int len = 0;
318 for (const auto &section : sectionItems)
319 len += section.size;
320 return len;
321 }
322
324 {
325 QBitArray sectionHidden;
326 if (!hiddenSectionSize.isEmpty()) {
327 sectionHidden.resize(sectionItems.size());
328 for (int u = 0; u < sectionItems.size(); ++u)
329 sectionHidden[u] = sectionItems.at(u).isHidden;
330 }
331 return sectionHidden;
332 }
333
334 void setHiddenSectionsFromBitVector(const QBitArray &sectionHidden) {
335 SectionItem *sectionData = sectionItems.data();
336 for (int i = 0; i < sectionHidden.size(); ++i)
337 sectionData[i].isHidden = sectionHidden.at(i);
338 }
339
340 int headerSectionSize(int visual) const;
341 int headerSectionPosition(int visual) const;
342 int headerVisualIndexAt(int position) const;
343
344 // resize mode
348
349 // other
350 int viewSectionSizeHint(int logical) const;
351 int adjustedVisualIndex(int visualIndex) const;
353 void updateSectionsBeforeAfter(int logical);
354
355#ifndef QT_NO_DATASTREAM
356 void write(QDataStream &out) const;
357 bool read(QDataStream &in);
358#endif
359
360};
363
365
366#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:42
bool at(qsizetype i) const
Returns the value of the bit at index position i.
Definition qbitarray.h:105
void resize(qsizetype size)
Resizes the bit array to size bits.
bool fill(bool val, qsizetype size=-1)
Sets every bit in the bit array to value, returning true if successful; otherwise returns false.
Definition qbitarray.h:77
qsizetype size() const
Returns the number of bits stored in the bit array.
Definition qbitarray.h:31
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\inmodule QtCore
Definition qhash.h:818
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:991
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:949
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
Definition qhash.h:926
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1283
int headerSectionSize(int visual) const
void updateDefaultSectionSizeFromStyle()
int headerLength() const
void _q_sectionsRemoved(const QModelIndex &, int, int)
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 _q_sectionsChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void _q_sectionsMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination)
void recalcSectionStartPos() const
void setNewLastSection(int visualIndexForLastSection)
void initializeIndexMapping() const
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
void _q_sectionsAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
int lastVisibleVisualIndex() const
void createSectionItems(int start, int end, int sectionSize, QHeaderView::ResizeMode mode)
QHash< int, int > cascadingSectionSize
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
void _q_sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination)
QHeaderView::ResizeMode globalResizeMode
void setHiddenSectionsFromBitVector(const QBitArray &sectionHidden)
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)
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:37
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
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void resize(qsizetype size)
Definition qlist.h:392
\inmodule QtCore
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.
@ AlignVCenter
Definition qnamespace.h:154
@ AlignCenter
Definition qnamespace.h:162
@ AlignLeft
Definition qnamespace.h:143
Orientation
Definition qnamespace.h:97
@ Horizontal
Definition qnamespace.h:98
SortOrder
Definition qnamespace.h:120
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 GLuint GLintptr offset
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLsizei len
GLuint in
GLenum GLenum GLsizei void * row
GLdouble s
[6]
Definition qopenglext.h:235
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:144
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
unsigned int uint
Definition qtypes.h:29
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)