8#include <private/qtablewidget_p.h>
17 tableItems(rows * columns, 0),
18 verticalHeaderItems(rows, 0),
19 horizontalHeaderItems(columns, 0)
30 if (
count < 1 || row < 0 || row > verticalHeaderItems.
size())
34 int rc = verticalHeaderItems.
size();
35 int cc = horizontalHeaderItems.
size();
47 if (
count < 1 || column < 0 || column > horizontalHeaderItems.
size())
51 int rc = verticalHeaderItems.
size();
52 int cc = horizontalHeaderItems.
size();
65 if (
count < 1 || row < 0 || row + count > verticalHeaderItems.
size())
72 for (
int j =
i;
j <
n +
i; ++
j) {
73 oldItem = tableItems.
at(
j);
75 oldItem->view =
nullptr;
80 oldItem = verticalHeaderItems.
at(
v);
82 oldItem->view =
nullptr;
92 if (
count < 1 || column < 0 || column + count > horizontalHeaderItems.
size())
100 oldItem = tableItems.
at(
j);
102 oldItem->view =
nullptr;
108 oldItem = horizontalHeaderItems.
at(
h);
110 oldItem->view =
nullptr;
121 if (i < 0 || i >= tableItems.
size())
129 oldItem->view =
nullptr;
130 delete tableItems.
at(
i);
137 tableItems[
i] =
item;
139 if (
view &&
view->isSortingEnabled()
140 &&
view->horizontalHeader()->sortIndicatorSection() ==
column) {
147 if (
item ==
nullptr) {
149 sortedRow = colItems.
size();
155 if (sortedRow !=
row) {
160 for (
int j = 0;
j < cc; ++
j)
164 for (
int j = 0;
j < cc; ++
j)
174 newPersistentIndexes);
215 tableItems[
i] =
nullptr;
223 verticalHeaderItems[
i] = 0;
229 horizontalHeaderItems[
i] = 0;
237 if (section < 0 || section >= horizontalHeaderItems.
size())
244 oldItem->view =
nullptr;
251 item->d->headerItem =
true;
253 horizontalHeaderItems[section] =
item;
259 if (section < 0 || section >= verticalHeaderItems.
size())
266 oldItem->view =
nullptr;
273 item->d->headerItem =
true;
275 verticalHeaderItems[section] =
item;
281 if (section < 0 || section >= horizontalHeaderItems.
size())
287 horizontalHeaderItems[section] = 0;
294 if (section < 0 || section >= verticalHeaderItems.
size())
300 verticalHeaderItems[section] = 0;
307 return horizontalHeaderItems.
value(section);
312 return verticalHeaderItems.
value(section);
320 const int id =
item->d->id;
321 if (
id >= 0 &&
id < tableItems.
size() && tableItems.
at(
id) ==
item) {
335 int rc = verticalHeaderItems.
size();
336 if (rows < 0 || rc == rows)
346 int cc = horizontalHeaderItems.
size();
347 if (columns < 0 || cc == columns)
357 return parent.isValid() ? 0 : verticalHeaderItems.
size();
362 return parent.isValid() ? 0 : horizontalHeaderItems.
size();
369 return itm->
data(role);
375 if (!
index.isValid())
385 if (!
value.isValid())
403 for (
int i = 0;
i < itm->values.
size(); ++
i) {
414 if (!
index.isValid())
424 if (itm->
data(role) !=
it.value()) {
454 const auto beginIter = itm->values.
cbegin();
455 const auto endIter = itm->values.
cend();
456 if (std::all_of(beginIter, endIter, [](
const QWidgetItemData&
data) ->
bool {
return !
data.value.isValid(); }))
465 if (!
index.isValid())
500 from.
reserve(numRows * numColumns);
501 to.
reserve(numRows * numColumns);
502 for (
int i = 0;
i < numRows; ++
i) {
503 int r = (
i < sortable.
size()
504 ? sortable.
at(
i).second
505 : unsortable.
at(
i - sortable.
size()));
506 for (
int c = 0;
c < numColumns; ++
c) {
515 tableItems = sorted_table;
536 if (itm ==
nullptr) {
552 bool changed =
false;
553 for (
int i = 0;
i < sorting.
size(); ++
i) {
554 distanceFromBegin = std::distance(colItems.
begin(), vit);
555 int oldRow = sorting.
at(
i).second;
560 int newRow =
qMax((
int)(vit - colItems.
begin()), 0);
561 if ((newRow < oldRow) && !(*
item < *colItems.
at(oldRow - 1)) && !(*colItems.
at(oldRow - 1) < *
item))
564 if (newRow != oldRow) {
568 newPersistentIndexes = oldPersistentIndexes;
574 for (
int j = 0;
j < cc; ++
j)
578 for (
int j = 0;
j < cc; ++
j)
581 newVertical.
remove(oldRow);
586 for (
int j =
i + 1;
j < sorting.
size(); ++
j) {
587 int otherRow = sorting.
at(
j).second;
588 if (oldRow < otherRow && newRow >= otherRow)
590 else if (oldRow > otherRow && newRow <= otherRow)
597 tableItems = newTable;
598 verticalHeaderItems = newVertical;
600 newPersistentIndexes);
617 if (itm ==
nullptr) {
635 int movedFromRow,
int movedToRow)
637 QModelIndexList::iterator
it;
639 int oldRow = (*it).row();
641 if (oldRow == movedFromRow)
643 else if (movedFromRow < oldRow && movedToRow >= oldRow)
645 else if (movedFromRow > oldRow && movedToRow <= oldRow)
647 if (newRow != oldRow)
678 return (*(
right.first) < *(
left .first));
688 itm = horizontalHeaderItems.
at(section);
689 else if (orientation ==
Qt::Vertical && section < verticalHeaderItems.
size())
690 itm = verticalHeaderItems.
at(section);
695 return itm->
data(role);
711 itm = horizontalHeaderItems.
at(section);
713 itm = verticalHeaderItems.
at(section);
723 return (
index.isValid()
724 &&
index.row() < verticalHeaderItems.
size()
725 &&
index.column() < horizontalHeaderItems.
size());
730 for (
int j = 0;
j < verticalHeaderItems.
size(); ++
j) {
731 if (verticalHeaderItems.
at(
j)) {
732 verticalHeaderItems.
at(
j)->view =
nullptr;
733 delete verticalHeaderItems.
at(
j);
734 verticalHeaderItems[
j] = 0;
737 for (
int k = 0; k < horizontalHeaderItems.
size(); ++k) {
738 if (horizontalHeaderItems.
at(k)) {
739 horizontalHeaderItems.
at(k)->view =
nullptr;
740 delete horizontalHeaderItems.
at(k);
741 horizontalHeaderItems[k] = 0;
750 for (
int i = 0;
i < tableItems.
size(); ++
i) {
751 if (tableItems.
at(
i)) {
752 tableItems.
at(
i)->view =
nullptr;
753 delete tableItems.
at(
i);
764 if (
item->d->headerItem) {
792 if (prototype !=
item) {
812 const int indexesCount = indexes.
size();
814 for (
int i = 0;
i < indexesCount; ++
i)
820 cachedIndexes = indexes;
822 cachedIndexes.
clear();
829 if (
index.isValid()) {
1113 model->itemChanged(
this);
1309 itemFlags(
Qt::ItemIsEditable
1310 |
Qt::ItemIsSelectable
1311 |
Qt::ItemIsUserCheckable
1313 |
Qt::ItemIsDragEnabled
1314 |
Qt::ItemIsDropEnabled)
1325 itemFlags(
Qt::ItemIsEditable
1326 |
Qt::ItemIsSelectable
1327 |
Qt::ItemIsUserCheckable
1329 |
Qt::ItemIsDragEnabled
1330 |
Qt::ItemIsDropEnabled)
1342 itemFlags(
Qt::ItemIsEditable
1343 |
Qt::ItemIsSelectable
1344 |
Qt::ItemIsUserCheckable
1346 |
Qt::ItemIsDragEnabled
1347 |
Qt::ItemIsDropEnabled)
1359 model->removeItem(
this);
1383 for (
int i = 0;
i <
values.size(); ++
i) {
1384 if (
values.at(
i).role == role) {
1400 model->itemChanged(
this, roles);
1411 if (
value.role == role)
1427#ifndef QT_NO_DATASTREAM
1455 return (view ? qobject_cast<QTableModel*>(view->
model()) :
nullptr);
1504 itemFlags(
other.itemFlags)
1519 itemFlags =
other.itemFlags;
1609 q,
SIGNAL(itemSelectionChanged()));
1670 if (currentItem || previousItem)
1671 emit q->currentItemChanged(currentItem, previousItem);
1895 d->tableModel()->setRowCount(rows);
1905 return d->model->rowCount();
1918 d->tableModel()->setColumnCount(columns);
1928 return d->model->columnCount();
1937 return d->tableModel()->index(
item).row();
1946 return d->tableModel()->index(
item).column();
1985 qWarning(
"QTableWidget: cannot insert an item that is already owned by another QTableWidget");
2003 item->view =
nullptr;
2013 return d->tableModel()->verticalHeaderItem(
row);
2024 d->tableModel()->setVerticalHeaderItem(
row,
item);
2039 itm->view =
nullptr;
2050 return d->tableModel()->horizontalHeaderItem(
column);
2063 d->tableModel()->setHorizontalHeaderItem(
column,
item);
2078 itm->view =
nullptr;
2096 item->setText(labels.at(
i));
2114 item->setText(labels.at(
i));
2173 d->selectionModel->setCurrentIndex(
d->tableModel()->index(
item), command);
2347 const int rangesCount = ranges.
size();
2348 result.reserve(rangesCount);
2349 for (
int i = 0;
i < rangesCount; ++
i)
2350 result.append({ranges.at(i).top(),
2351 ranges.at(i).left(),
2352 ranges.at(i).bottom(),
2353 ranges.at(i).right()});
2372 for (
const auto &
index : indexes) {
2394 const int indexCount = indexes.
size();
2396 for (
int i = 0;
i < indexCount; ++
i)
2431 return d->tableModel()->item(
indexAt(
p));
2471 return d->tableModel()->itemPrototype();
2490 d->tableModel()->setItemPrototype(
item);
2499 d->tableModel()->insertRows(
row);
2508 d->tableModel()->insertColumns(
column);
2517 d->tableModel()->removeRows(
row);
2526 d->tableModel()->removeColumns(
column);
2541 d->tableModel()->clear();
2555 d->tableModel()->clearContents();
2566 return d_func()->tableModel()->QAbstractTableModel::mimeTypes();
2584 if (cachedIndexes.
isEmpty()) {
2591 cachedIndexes.
clear();
2595 return d->tableModel()->internalMimeData();
2609#if QT_CONFIG(draganddrop)
2610 if (dropIndicatorPosition() == QAbstractItemView::OnItem) {
2617 return d_func()->tableModel()->QAbstractTableModel::dropMimeData(
data, action ,
row,
column, idx);
2627 return d_func()->tableModel()->QAbstractTableModel::supportedDropActions() |
Qt::MoveAction;
2653 return d->tableModel()->index(
item);
2663 return d->tableModel()->item(
index);
2671 Q_ASSERT(!
"QTableWidget::setModel() - Changing the model of the QTableWidget is not allowed.");
2680#if QT_CONFIG(draganddrop)
2682void QTableWidget::dropEvent(QDropEvent *
event) {
2685 dragDropMode() == QAbstractItemView::InternalMove)) {
2690 if (!
event->isAccepted() &&
d->dropOn(
event, &
row, &col, &topIndex)) {
2694 for (
const auto &
index : indexes) {
2700 const int indexesCount = indexes.
size();
2702 for (
const auto &
index : indexes)
2705 for (
const auto &
index : indexes) {
2715 if (
event->isAccepted())
2716 d->dropEventMoved =
true;
2719 QTableView::dropEvent(
event);
2725#include "moc_qtablewidget.cpp"
2726#include "moc_qtablewidget_p.cpp"
static bool variantLessThan(const QVariant &v1, const QVariant &v2)
void endResetModel()
Completes a model reset operation.
void endRemoveRows()
Ends a row removal operation.
QModelIndexList persistentIndexList() const
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
Begins a column removal operation.
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
void layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
bool checkIndex(const QModelIndex &index, CheckIndexOptions options=CheckIndexOption::NoOption) const
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void beginInsertColumns(const QModelIndex &parent, int first, int last)
Begins a column insertion operation.
void endInsertRows()
Ends a row insertion operation.
void beginResetModel()
Begins a model reset operation.
void endRemoveColumns()
Ends a column removal operation.
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
void endInsertColumns()
Ends a column insertion operation.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
virtual Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
QAbstractItemModel * model
QWidget * indexWidget(const QModelIndex &index) const
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
bool event(QEvent *event) override
\reimp
QModelIndex currentIndex() const
Returns the model index of the current item.
QModelIndex rootIndex() const
Returns the model index of the model's root item.
bool isPersistentEditorOpen(const QModelIndex &index) const
void setIndexWidget(const QModelIndex &index, QWidget *widget)
void openPersistentEditor(const QModelIndex &index)
Opens a persistent editor on the item at the given index.
ScrollHint
\value EnsureVisible Scroll to ensure that the item is visible.
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
QItemSelectionModel * selectionModel() const
Returns the current selection model.
void closePersistentEditor(const QModelIndex &index)
Closes the persistent editor for the item at the given index.
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.
\inmodule QtCore\reentrant
The QIcon class provides scalable icons in different modes and states.
Q_INVOKABLE bool isSelected(const QModelIndex &index) const
Returns true if the given model item index is selected.
QModelIndexList selectedIndexes
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
virtual void clear()
Clears the selection model.
qsizetype size() const noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
void remove(qsizetype i, qsizetype n=1)
void reserve(qsizetype size)
void resize(qsizetype size)
const_iterator cend() const noexcept
void append(parameter_type t)
const_iterator cbegin() const noexcept
iterator insert(const Key &key, const T &value)
const_iterator constBegin() const
const_iterator constEnd() const
constexpr int row() const noexcept
Returns the row this model index refers to.
constexpr int column() const noexcept
Returns the column this model index refers to.
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
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)
Qt::ItemFlags flags(const QModelIndex &index) const override
\reimp
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)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
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
QMimeData * mimeData(const QModelIndexList &indexes) const override
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
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
QTableModel(int rows, int columns, QTableWidget *parent)
QList< QTableWidgetItem * > columnItems(int column) const
void updateRowIndexes(QModelIndexList &indexes, int movedFromRow, int movedToRow)
Qt::DropActions supportedDropActions() const override
QTableWidgetItem * takeVerticalHeaderItem(int section)
QTableWidgetItem * item(int row, int column) const
QHeaderView * horizontalHeader
The QTableView class provides a default model/view implementation of a table view.
void setModel(QAbstractItemModel *model) override
\reimp
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible) override
\reimp
void setSortingEnabled(bool enable)
If enable is true, enables sorting for the table and immediately trigger a call to sortByColumn() wit...
QRect visualRect(const QModelIndex &index) const override
\reimp
QModelIndex indexAt(const QPoint &p) const override
Returns the index position of the model item corresponding to the table item at position pos in conte...
bool isSortingEnabled() const
QHeaderView * horizontalHeader() const
Returns the table view's horizontal header.
QModelIndexList selectedIndexes() const override
\reimp
QHeaderView * verticalHeader() const
Returns the table view's vertical header.
bool isIndexHidden(const QModelIndex &index) const override
\reimp
QTestTable * parent() const
list append(new Employee("Blackpool", "Stephen"))
QSet< QString >::iterator it
Combined button and popup list for selecting options.
std::pair< T1, T2 > QPair
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLint GLfloat GLfloat GLfloat v2
GLenum GLsizei GLsizei GLint * values
[15]
GLsizei const GLfloat * v
[13]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
GLfixed GLfixed GLint GLint order
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
static int compare(quint64 a, quint64 b)
QSqlQueryModel * model
[16]
QTextStream out(stdout)
[7]
selection select(topLeft, bottomRight)
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent