Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtablewidget_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 QTABLEWIDGET_P_H
5#define QTABLEWIDGET_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. This header file may change
12// from version to version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtWidgets/private/qtwidgetsglobal_p.h>
18#include <qheaderview.h>
19#include <qtablewidget.h>
20#include <qabstractitemmodel.h>
21#include <private/qabstractitemmodel_p.h>
22#include <private/qtableview_p.h>
23#include <private/qwidgetitemdata_p.h>
24
25QT_REQUIRE_CONFIG(tablewidget);
26
28
30{
32public:
34};
35
37{
38public:
39 inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
40 { return (*i1 < *i2); }
41};
42
44{
45public:
46 inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
47 { return (*i2 < *i1); }
48};
49
51{
53 friend class QTableWidget;
54
55public:
56 QTableModel(int rows, int columns, QTableWidget *parent);
58
59 bool insertRows(int row, int count = 1, const QModelIndex &parent = QModelIndex()) override;
60 bool insertColumns(int column, int count = 1, const QModelIndex &parent = QModelIndex()) override;
61
62 bool removeRows(int row, int count = 1, const QModelIndex &parent = QModelIndex()) override;
63 bool removeColumns(int column, int count = 1, const QModelIndex &parent = QModelIndex()) override;
64
65 void setItem(int row, int column, QTableWidgetItem *item);
67 QTableWidgetItem *item(int row, int column) const;
70
77
78 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
80
82
83 void setRowCount(int rows);
84 void setColumnCount(int columns);
85
86 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
87 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
88
89 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
90 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
91 bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override;
92 bool clearItemData(const QModelIndex &index) override;
93
94 QMap<int, QVariant> itemData(const QModelIndex &index) const override;
95
96 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
97 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override;
98
99 Qt::ItemFlags flags(const QModelIndex &index) const override;
100
101 void sort(int column, Qt::SortOrder order) override;
106
107 void ensureSorted(int column, Qt::SortOrder order, int start, int end);
109 void updateRowIndexes(QModelIndexList &indexes, int movedFromRow, int movedToRow);
114
115 bool isValid(const QModelIndex &index) const;
116 inline long tableIndex(int row, int column) const
117 { return (row * horizontalHeaderItems.size()) + column; }
118
119 void clear();
120 void clearContents();
121 void itemChanged(QTableWidgetItem *item, const QList<int> &roles = QList<int>());
122
124 const QTableWidgetItem *itemPrototype() const;
126
127 // dnd
128 QStringList mimeTypes() const override;
129 QMimeData *mimeData(const QModelIndexList &indexes) const override;
130 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
131 int row, int column, const QModelIndex &parent) override;
132 Qt::DropActions supportedDropActions() const override;
133
135
136private:
137 const QTableWidgetItem *prototype;
138 QList<QTableWidgetItem *> tableItems;
139 QList<QTableWidgetItem *> verticalHeaderItems;
140 QList<QTableWidgetItem *> horizontalHeaderItems;
141
142 // A cache must be mutable if get-functions should have const modifiers
143 mutable QModelIndexList cachedIndexes;
144};
145
147{
148 Q_DECLARE_PUBLIC(QTableWidget)
149public:
151 inline QTableModel *tableModel() const { return qobject_cast<QTableModel*>(model); }
152 void setup();
153
154 // view signals
160 // model signals
162 // selection signals
163 void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &current);
164 // sorting
165 void _q_sort();
166 void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
167};
168
170{
171public:
174 int id;
175 bool headerItem; // Qt 7 TODO: inline this stuff in the public class.
176};
177
179
180#endif // QTABLEWIDGET_P_H
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the data in row and column with parent.
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
Definition qmap.h:186
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
\inmodule QtCore
bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
void removeItem(QTableWidgetItem *item)
static bool itemLessThan(const QPair< QTableWidgetItem *, int > &left, const QPair< QTableWidgetItem *, int > &right)
void setRowCount(int rows)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns for the children of the given parent.
QTableWidgetItem * verticalHeaderItem(int section)
void setVerticalHeaderItem(int section, QTableWidgetItem *item)
bool clearItemData(const QModelIndex &index) override
void ensureSorted(int column, Qt::SortOrder order, int start, int end)
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override
Sets the data for the given role and section in the header with the specified orientation to the valu...
void setItemPrototype(const QTableWidgetItem *item)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
QMap< int, QVariant > itemData(const QModelIndex &index) const override
Returns a map with values for all predefined roles in the model for the item at the given index.
QTableWidgetItem * takeHorizontalHeaderItem(int section)
void setItem(int row, int column, QTableWidgetItem *item)
bool insertRows(int row, int count=1, const QModelIndex &parent=QModelIndex()) override
QStringList mimeTypes() const override
Returns the list of allowed MIME types.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the data for the given role and section in the header with the specified orientation.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
\reimp
bool isValid(const QModelIndex &index) const
QTableWidgetItem * createItem() const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the data in row and column with parent.
static QList< QTableWidgetItem * >::iterator sortedInsertionIterator(const QList< QTableWidgetItem * >::iterator &begin, const QList< QTableWidgetItem * >::iterator &end, Qt::SortOrder order, QTableWidgetItem *item)
QTableWidgetItem * horizontalHeaderItem(int section)
void setHorizontalHeaderItem(int section, QTableWidgetItem *item)
void itemChanged(QTableWidgetItem *item, const QList< int > &roles=QList< int >())
QMimeData * internalMimeData() const
const QTableWidgetItem * itemPrototype() const
bool insertColumns(int column, int count=1, const QModelIndex &parent=QModelIndex()) override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets the role data for the item at index to value.
bool removeColumns(int column, int count=1, const QModelIndex &parent=QModelIndex()) override
QTableWidgetItem * takeItem(int row, int column)
void setColumnCount(int columns)
bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles) override
Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole...
void sort(int column, Qt::SortOrder order) override
static bool itemGreaterThan(const QPair< QTableWidgetItem *, int > &left, const QPair< QTableWidgetItem *, int > &right)
bool removeRows(int row, int count=1, const QModelIndex &parent=QModelIndex()) override
long tableIndex(int row, int column) const
QList< QTableWidgetItem * > columnItems(int column) const
void updateRowIndexes(QModelIndexList &indexes, int movedFromRow, int movedToRow)
void clearContents()
Qt::DropActions supportedDropActions() const override
QTableWidgetItem * takeVerticalHeaderItem(int section)
QTableWidgetItemPrivate(QTableWidgetItem *item)
QTableWidgetItem * q
The QTableWidgetItem class provides an item for use with the QTableWidget class.
QList< QTableWidgetItem * > items
void _q_emitItemClicked(const QModelIndex &index)
void _q_emitItemActivated(const QModelIndex &index)
void _q_emitItemChanged(const QModelIndex &index)
void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &current)
void _q_emitItemPressed(const QModelIndex &index)
void _q_emitItemEntered(const QModelIndex &index)
void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QTableModel * tableModel() const
void _q_emitItemDoubleClicked(const QModelIndex &index)
The QTableWidget class provides an item-based table view with a default model.
\inmodule QtCore
Definition qvariant.h:64
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:97
@ DisplayRole
SortOrder
Definition qnamespace.h:120
DropAction
std::pair< T1, T2 > QPair
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
GLuint GLuint end
GLenum GLuint id
[7]
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint left
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint start
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLfixed GLfixed GLint GLint order
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
QMimeData * mimeData
QGraphicsItem * item