44 #ifndef QT_NO_TABLEWIDGET 47 #include <private/qtablewidget_p.h> 54 tableItems(rows * columns, 0),
55 verticalHeaderItems(rows, 0),
56 horizontalHeaderItems(columns, 0)
94 for (
int row = 0; row < rc; ++row)
109 for (
int j = i; j < n + i; ++j) {
116 for (
int v = row; v < row + count; ++v) {
134 for (
int row =
rowCount() - 1; row >= 0; --row) {
136 for (
int j = i; j < i + count; ++j) {
144 for (
int h=column; h<column+count; ++h) {
181 if (row < colItems.
count())
186 sortedRow = colItems.
count();
190 sortedRow =
qMax((
int)(it - colItems.
begin()), 0);
192 if (sortedRow != row) {
197 for (
int j = 0; j < cc; ++j)
201 for (
int j = 0; j < cc; ++j)
211 newPersistentIndexes);
357 const int id = item->
d->
id;
373 if (rows < 0 || rc == rows)
384 if (columns < 0 || cc == columns)
406 return itm->
data(role);
458 bool changed =
false;
460 if (itm->data(
it.key()) !=
it.value()) {
461 itm->setData(
it.key(),
it.value());
476 itm->setData(
it.key(),
it.value());
503 for (
int row = 0; row <
rowCount(); ++row) {
516 for (
int i = 0; i <
rowCount(); ++i) {
517 int r = (i < sortable.
count()
518 ? sortable.
at(i).second
519 : unsortable.
at(i - sortable.
count()));
545 int count = end - start + 1;
548 for (
int row = start; row <=
end; ++row) {
567 bool changed =
false;
568 for (
int i = 0; i < sorting.
count(); ++i) {
569 int oldRow = sorting.
at(i).second;
574 if ((newRow < oldRow) && !(*item < *colItems.
at(oldRow - 1)) && !(*colItems.
at(oldRow - 1) < *
item))
576 vit = colItems.
insert(vit, item);
577 if (newRow != oldRow) {
582 for (
int j = 0; j < cc; ++j)
586 for (
int j = 0; j < cc; ++j)
589 newVertical.
remove(oldRow);
590 newVertical.
insert(newRow, header);
594 for (
int j = i + 1; j < sorting.
count(); ++j) {
595 int otherRow = sorting.
at(j).second;
596 if (oldRow < otherRow && newRow >= otherRow)
598 else if (oldRow > otherRow && newRow <= otherRow)
609 newPersistentIndexes);
624 for (
int row = 0; row < rc; ++row) {
644 int movedFromRow,
int movedToRow)
647 for (it = indexes.
begin(); it != indexes.
end(); ++
it) {
648 int oldRow = (*it).row();
650 if (oldRow == movedFromRow)
652 else if (movedFromRow < oldRow && movedToRow >= oldRow)
654 else if (movedFromRow > oldRow && movedToRow <= oldRow)
656 if (newRow != oldRow)
657 *it =
index(newRow, (*it).column(), (*it).parent());
704 return itm->
data(role);
820 for (
int i = 0; i < indexes.
count(); ++i)
821 items <<
item(indexes.
at(i));
828 cachedIndexes.
clear();
838 }
else if (row == -1 || column == -1) {
844 return (view ? view->
dropMimeData(row, column, data, action) :
false);
880 : top(-1),
left(-1), bottom(-2),
right(-2)
891 : top(top), left(left), bottom(bottom), right(right)
1154 if (
QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0))
1155 model->itemChanged(
this);
1462 model->removeItem(
this);
1486 if (
values[i].value == value)
1497 model->itemChanged(
this);
1522 #ifndef QT_NO_DATASTREAM 1580 #endif // QT_NO_DATASTREAM 1719 q,
SIGNAL(itemSelectionChanged()));
1730 emit q->itemPressed(item);
1738 emit q->itemClicked(item);
1746 emit q->itemDoubleClicked(item);
1754 emit q->itemActivated(item);
1762 emit q->itemEntered(item);
1770 emit q->itemChanged(item);
1780 if (currentItem || previousItem)
1781 emit q->currentItemChanged(currentItem, previousItem);
1787 if (sortingEnabled) {
1788 int column = horizontalHeader->sortIndicatorSection();
1789 Qt::SortOrder order = horizontalHeader->sortIndicatorOrder();
1790 model->sort(column, order);
1797 if (sortingEnabled && topLeft.
isValid() && bottomRight.
isValid()) {
1798 int column = horizontalHeader->sortIndicatorSection();
1799 if (column >= topLeft.
column() && column <= bottomRight.
column()) {
1800 Qt::SortOrder order = horizontalHeader->sortIndicatorOrder();
1801 tableModel()->ensureSorted(column, order, topLeft.
row(), bottomRight.
row());
2035 d->tableModel()->setRowCount(rows);
2045 return d->model->rowCount();
2058 d->tableModel()->setColumnCount(columns);
2068 return d->model->columnCount();
2077 return d->tableModel()->index(item).row();
2086 return d->tableModel()->index(item).column();
2099 return d->tableModel()->item(row, column);
2124 if (item->
view != 0) {
2125 qWarning(
"QTableWidget: cannot insert an item that is already owned by another QTableWidget");
2128 d->tableModel()->setItem(row, column, item);
2153 return d->tableModel()->verticalHeaderItem(row);
2164 d->tableModel()->setVerticalHeaderItem(row, item);
2193 return d->tableModel()->horizontalHeaderItem(column);
2204 d->tableModel()->setHorizontalHeaderItem(column, item);
2234 for (
int i = 0; i < model->
rowCount() && i < labels.
count(); ++i) {
2320 d->selectionModel->setCurrentIndex(
d->tableModel()->index(item), command);
2365 d->model->sort(column, order);
2394 edit(
d->tableModel()->index(item));
2521 for (
int i = 0; i < ranges.
count(); ++i)
2544 for (
int i = 0; i < indexes.
count(); ++i) {
2567 for (
int i = 0; i < indexes.
size(); ++i)
2568 items.
append(
d->tableModel()->item(indexes.
at(i)));
2602 return d->tableModel()->item(
indexAt(p));
2613 QModelIndex index =
d->tableModel()->index(const_cast<QTableWidgetItem*>(item));
2629 QModelIndex index =
d->tableModel()->index(const_cast<QTableWidgetItem*>(item));
2642 return d->tableModel()->itemPrototype();
2661 d->tableModel()->setItemPrototype(item);
2670 d->tableModel()->insertRows(row);
2679 d->tableModel()->insertColumns(column);
2688 d->tableModel()->removeRows(row);
2697 d->tableModel()->removeColumns(column);
2710 d->tableModel()->clear();
2727 d->tableModel()->clearContents();
2738 return d_func()->tableModel()->QAbstractTableModel::mimeTypes();
2751 return d_func()->tableModel()->internalMimeData();
2765 #ifndef QT_NO_DRAGANDDROP 2773 return d_func()->tableModel()->QAbstractTableModel::dropMimeData(data, action , row, column, idx);
2783 return d_func()->tableModel()->QAbstractTableModel::supportedDropActions() |
Qt::MoveAction;
2807 return d->tableModel()->index(item);
2817 return d->tableModel()->item(index);
2825 Q_ASSERT(!
"QTableWidget::setModel() - Changing the model of the QTableWidget is not allowed.");
2834 #ifndef QT_NO_DRAGANDDROP 2843 if (
d->dropOn(event, &row, &col, &topIndex)) {
2847 for (
int i = 0; i < indexes.
count(); ++i) {
2853 for (
int i = 0; i < indexes.
count(); ++i)
2856 for (
int i = 0; i < indexes.
count(); ++i) {
2858 int r = index.
row() - top + topIndex.
row();
2860 setItem(r, c, taken.takeFirst());
2875 #include "moc_qtablewidget.cpp" 2877 #endif // QT_NO_TABLEWIDGET The QVariant class acts like a union for the most common Qt data types.
bool insertRows(int row, int count=1, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count rows into the model before the given row.
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
void openPersistentEditor(const QModelIndex &index)
Opens a persistent editor on the item at the given index.
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
virtual void clear()
Clears the selection model.
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
void clear()
Removes all the MIME type and data entries in the object.
#define QT_END_NAMESPACE
This macro expands to.
void beginInsertColumns(const QModelIndex &parent, int first, int last)
Begins a column insertion operation.
QPointer< QWidget > widget
void setItemPrototype(const QTableWidgetItem *item)
bool setData(const QModelIndex &index, const QVariant &value, int role)
Sets the role data for the item at index to value.
void remove(int i)
Removes the element at index position i.
static bool itemGreaterThan(const QPair< QTableWidgetItem *, int > &left, const QPair< QTableWidgetItem *, int > &right)
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
void setModel(QAbstractItemModel *model)
Reimplemented Function
QMap< int, QVariant > itemData(const QModelIndex &index) const
Returns a map with values for all predefined roles in the model for the item at the given index...
const QTableWidgetItem * itemPrototype() const
QModelIndexList selectedIndexes() const
Returns a list of all selected model item indexes.
QVector< QTableWidgetItem * > verticalHeaderItems
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
Sets the data for the given role and section in the header with the specified orientation to the valu...
QRect visualRect(const QModelIndex &index) const
Returns the rectangle on the viewport occupied by the given index.
DragDropMode dragDropMode() const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
bool removeRows(int row, int count=1, const QModelIndex &parent=QModelIndex())
On models that support this, removes count rows starting with the given row under parent parent from ...
QHeaderView * horizontalHeader() const
Returns the table view's horizontal header.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
Begins a column removal operation.
void setIndexWidget(const QModelIndex &index, QWidget *widget)
Sets the given widget on the item at the given index, passing the ownership of the widget to the view...
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Reimplemented Function
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
void ensureSorted(int column, Qt::SortOrder order, int start, int end)
bool removeColumns(int column, int count=1, const QModelIndex &parent=QModelIndex())
On models that support this, removes count columns starting with the given column under parent parent...
long tableIndex(int row, int column) const
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
int count(const T &t) const
Returns the number of occurrences of value in the list.
bool hasIndex(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false.
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
void endInsertRows()
Ends a row insertion operation.
bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles)
Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole...
static bool variantLessThan(const QVariant &v1, const QVariant &v2)
This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
void setItem(int row, int column, QTableWidgetItem *item)
DropIndicatorPosition dropIndicatorPosition() const
Returns the position of the drop indicator in relation to the closest item.
The QVector class is a template class that provides a dynamic array.
QTableWidgetItem * takeVerticalHeaderItem(int section)
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QWidget * indexWidget(const QModelIndex &index) const
Returns the widget for the item at the given index.
void updateRowIndexes(QModelIndexList &indexes, int movedFromRow, int movedToRow)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list t...
void resize(int size)
Sets the size of the vector to size.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
void dropEvent(QDropEvent *event)
This function is called with the given event when a drop event occurs over the widget.
virtual 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...
QTableWidgetItem * item(int row, int column) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
void append(const T &t)
Inserts value at the end of the list.
const QTableWidgetItem * prototype
#define QT_BEGIN_NAMESPACE
This macro expands to.
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
Compares a to b.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
QItemSelectionModel * selectionModel() const
Returns the current selection model.
T value(int i) const
Returns the value at index position i in the vector.
bool isSelected(const QModelIndex &index) const
Returns true if the given model item index is selected.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
void append(const T &t)
Inserts value at the end of the vector.
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.
QHeaderView * verticalHeader() const
Returns the table view's vertical header.
QModelIndex currentIndex() const
Returns the model index of the current item.
static bool itemLessThan(const QPair< QTableWidgetItem *, int > &left, const QPair< QTableWidgetItem *, int > &right)
void endRemoveRows()
Ends a row removal operation.
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the vector, searching forward from ind...
The QMimeData class provides a container for data that records information about its MIME type...
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
void sort(int column, Qt::SortOrder order)
Sorts the model by column in the given order.
The QTableView class provides a default model/view implementation of a table view.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QTableWidgetItem * verticalHeaderItem(int section)
QVector< QTableWidgetItem * > horizontalHeaderItems
const T & at(int i) const
Returns the item at index position i in the vector.
The QAbstractItemModel class provides the abstract interface for item model classes.
QVector< QTableWidgetItem * > columnItems(int column) const
void qStableSort(RandomAccessIterator start, RandomAccessIterator end)
void setColumnCount(int columns)
static QByteArray prototype(const QList< QByteArray > ¶meterTypes, const QList< QByteArray > ¶meterNames, bool *ok)
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
The QItemSelection class manages information about selected items in a model.
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Returns the data for the given role and section in the header with the specified orientation.
QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void setRowCount(int rows)
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)
Makes sure that the given item is visible in the table view, scrolling if necessary.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
QWidget * source() const
If the source of the drag operation is a widget in this application, this function returns that sourc...
QObject * parent() const
Returns a pointer to the parent object.
QModelIndexList cachedIndexes
QTableWidgetItem * createItem() const
The QPoint class defines a point in the plane using integer precision.
void setHorizontalHeaderItem(int section, QTableWidgetItem *item)
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns for the children of the given parent.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
bool isValid(const QModelIndex &index) const
The QModelIndex class is used to locate data in a data model.
int size() const
Returns the number of items in the list.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Returns the data stored under the given role for the item referred to by the index.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
The QRect class defines a rectangle in the plane using integer precision.
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
QTableWidgetItem * horizontalHeaderItem(int section)
QMimeData * internalMimeData() const
QTableWidgetItem * takeHorizontalHeaderItem(int section)
void endInsertColumns()
Ends a column insertion operation.
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
void setSortingEnabled(bool enable)
If enabled true enables sorting for the table and immediately trigger a call to sortByColumn() with t...
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows under the given parent.
QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of model indexes.
The QDataStream class provides serialization of binary data to a QIODevice.
void reserve(int size)
Attempts to allocate memory for at least size elements.
void closePersistentEditor(const QModelIndex &index)
Closes the persistent editor for the item at the given index.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
QModelIndex rootIndex() const
Returns the model index of the model's root item.
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
static const KeyPair *const end
static QVector< QTableWidgetItem * >::iterator sortedInsertionIterator(const QVector< QTableWidgetItem *>::iterator &begin, const QVector< QTableWidgetItem *>::iterator &end, Qt::SortOrder order, QTableWidgetItem *item)
QVector< QTableWidgetItem * > tableItems
bool event(QEvent *event)
Reimplemented Function
The QEvent class is the base class of all event classes.
bool insertColumns(int column, int count=1, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count new columns into the model before the given column...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
bool isSortingEnabled() const
int size() const
Returns the number of items in the vector.
QModelIndex indexAt(const QPoint &p) const
Returns the index position of the model item corresponding to the table item at position pos in conte...
QModelIndexList selectedIndexes() const
Reimplemented Function
The QAbstractTableModel class provides an abstract model that can be subclassed to create table model...
The QMap class is a template class that provides a skip-list-based dictionary.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specifi...
void reset()
Resets the model to its original state in any attached views.
QTableWidgetItem * takeItem(int row, int column)
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
int column() const
Returns the column this model index refers to.
void setVerticalHeaderItem(int section, QTableWidgetItem *item)
void endRemoveColumns()
Ends a column removal operation.
void itemChanged(QTableWidgetItem *item)
void removeItem(QTableWidgetItem *item)
The QIcon class provides scalable icons in different modes and states.
QTableModel(int rows, int columns, QTableWidget *parent)