QTableModel Class Reference
#include <qtablewidget_p.h>
Inheritance diagram for QTableModel:
Detailed Description
Definition at line 70 of file qtablewidget_p.h.
Member Enumeration Documentation
Definition at line 74 of file qtablewidget_p.h.
00074 { 00075 ItemIsHeaderItem = 128 00076 }; // we need this to separate header items from other items
Constructor & Destructor Documentation
QTableModel::QTableModel | ( | int | rows, | |
int | columns, | |||
QTableWidget * | parent | |||
) |
Definition at line 31 of file qtablewidget.cpp.
00032 : QAbstractTableModel(parent), 00033 prototype(0), 00034 tableItems(rows * columns, 0), 00035 verticalHeaderItems(rows, 0), 00036 horizontalHeaderItems(columns, 0) 00037 {}
QTableModel::~QTableModel | ( | ) |
Member Function Documentation
bool QTableModel::insertRows | ( | int | row, | |
int | count = 1 , | |||
const QModelIndex & | parent = QModelIndex() | |||
) | [virtual] |
On models that support this, inserts count rows into the model before the given row. The items in the new row will be children of the item represented by the parentmodel index.
If row is 0, the rows are prepended to any existing rows in the parent. If row is rowCount(), the rows are appended to any existing rows in the parent. If parent has no children, a single column with count rows is inserted.
Returns true if the rows were successfully inserted; otherwise returns false.
The base class implementation does nothing and returns false.
If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide you own API for altering the data.
-
See also:
- insertColumns(), removeRows(), beginInsertRows(), endInsertRows()
Reimplemented from QAbstractItemModel.
Definition at line 45 of file qtablewidget.cpp.
References QAbstractItemModel::beginInsertRows(), QVector< T >::count(), QAbstractItemModel::endInsertRows(), horizontalHeaderItems, QVector< T >::insert(), QVector< T >::resize(), tableIndex(), tableItems, and verticalHeaderItems.
Referenced by setRowCount().
00046 { 00047 if (count < 1 || row < 0 || row > verticalHeaderItems.count()) 00048 return false; 00049 00050 beginInsertRows(QModelIndex(), row, row + count - 1); 00051 int rc = verticalHeaderItems.count(); 00052 int cc = horizontalHeaderItems.count(); 00053 verticalHeaderItems.insert(row, count, 0); 00054 if (rc == 0) 00055 tableItems.resize(cc * count); 00056 else 00057 tableItems.insert(tableIndex(row, 0), cc * count, 0); 00058 endInsertRows(); 00059 return true; 00060 }
Here is the call graph for this function:
bool QTableModel::insertColumns | ( | int | column, | |
int | count = 1 , | |||
const QModelIndex & | parent = QModelIndex() | |||
) | [virtual] |
On models that support this, inserts count new columns into the model before the given column. The items in each new column will be children of the item represented by the parent model index.
If column is 0, the columns are prepended to any existing columns. If column is columnCount(), the columns are appended to any existing columns. If parent has no children, a single row with count columns is inserted.
Returns true if the columns were successfully inserted; otherwise returns false.
The base class implementation does nothing and returns false.
If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide you own API for altering the data.
Reimplemented from QAbstractItemModel.
Definition at line 62 of file qtablewidget.cpp.
References QAbstractItemModel::beginInsertColumns(), QVector< T >::count(), QAbstractItemModel::endInsertColumns(), horizontalHeaderItems,QVector< T >::insert(), QVector< T >::resize(), row, tableIndex(), tableItems, and verticalHeaderItems.
Referenced by setColumnCount().
00063 { 00064 if (count < 1 || column < 0 || column > horizontalHeaderItems.count()) 00065 return false; 00066 00067 beginInsertColumns(QModelIndex(), column, column + count - 1); 00068 int rc = verticalHeaderItems.count(); 00069 int cc = horizontalHeaderItems.count(); 00070 horizontalHeaderItems.insert(column, count, 0); 00071 if (cc == 0) 00072 tableItems.resize(rc * count); 00073 else 00074 for (int row = 0; row < rc; ++row) 00075 tableItems.insert(tableIndex(row, column), count, 0); 00076 endInsertColumns(); 00077 return true; 00078 }
Here is the call graph for this function:
bool QTableModel::removeRows | ( | int | row, | |
int | count = 1 , | |||
const QModelIndex & | parent = QModelIndex() | |||
) | [virtual] |
On models that support this, removes count rows starting with the given row under parent parent from the model. Returns true if the rows were successfully removed; otherwise returns false.
The base class implementation does nothing and returns false.
If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide you own API for altering the data.
Reimplemented from QAbstractItemModel.
Definition at line 80 of file qtablewidget.cpp.
References QVector< T >::at(), QAbstractItemModel::beginRemoveRows(), columnCount(), QVector< T >::count(),QAbstractItemModel::endRemoveRows(), i, j, QTableWidgetItem::model, n, qMax(), QVector< T >::remove(), tableIndex(), tableItems, andverticalHeaderItems.
Referenced by setRowCount().
00081 { 00082 if (count < 1 || row < 0 || row + count > verticalHeaderItems.count()) 00083 return false; 00084 00085 beginRemoveRows(QModelIndex(), row, row + count - 1); 00086 int i = tableIndex(row, 0); 00087 int n = count * columnCount(); 00088 QTableWidgetItem *oldItem = 0; 00089 for (int j = i; j < n + i; ++j) { 00090 oldItem = tableItems.at(j); 00091 if (oldItem) 00092 oldItem->model = 0; 00093 delete oldItem; 00094 } 00095 tableItems.remove(qMax(i, 0), n); 00096 for (int v = row; v < row + count; ++v) { 00097 oldItem = verticalHeaderItems.at(v); 00098 if (oldItem) 00099 oldItem->model = 0; 00100 delete oldItem; 00101 } 00102 verticalHeaderItems.remove(row, count); 00103 endRemoveRows(); 00104 return true; 00105 }
Here is the call graph for this function:
bool QTableModel::removeColumns | ( | int | column, | |
int | count = 1 , | |||
const QModelIndex & | parent = QModelIndex() | |||
) | [virtual] |
On models that support this, removes count columns starting with the given column under parent parent from the model. Returns true if the columns were successfully removed; otherwise returns false.
The base class implementation does nothing and returns false.
If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide you own API for altering the data.
Reimplemented from QAbstractItemModel.
Definition at line 107 of file qtablewidget.cpp.
References QVector< T >::at(), QAbstractItemModel::beginRemoveColumns(), QVector< T >::count(), QAbstractItemModel::endRemoveColumns(), h,horizontalHeaderItems, i, j, QTableWidgetItem::model, QVector< T >::remove(), row, rowCount(), tableIndex(), and tableItems.
Referenced by setColumnCount().
00108 { 00109 if (count < 1 || column < 0 || column + count > horizontalHeaderItems.count()) 00110 return false; 00111 00112 beginRemoveColumns(QModelIndex(), column, column + count - 1); 00113 QTableWidgetItem *oldItem = 0; 00114 for (int row = rowCount() - 1; row >= 0; --row) { 00115 int i = tableIndex(row, column); 00116 for (int j = i; j < i + count; ++j) { 00117 oldItem = tableItems.at(j); 00118 if (oldItem) 00119 oldItem->model = 0; 00120 delete oldItem; 00121 } 00122 tableItems.remove(i, count); 00123 } 00124 for (int h=column; h<column+count; ++h) { 00125 oldItem = horizontalHeaderItems.at(h); 00126 if (oldItem) 00127 oldItem->model = 0; 00128 delete oldItem; 00129 } 00130 horizontalHeaderItems.remove(column, count); 00131 endRemoveColumns(); 00132 return true; 00133 }
Here is the call graph for this function:
void QTableModel::setItem | ( | int | row, | |
int | column, | |||
QTableWidgetItem * | item | |||
) |
Definition at line 135 of file qtablewidget.cpp.
References QVector< T >::at(), QVector< T >::begin(), QAbstractItemModel::changePersistentIndexList(), columnCount(), columnItems(), QVector< T >::count(), QAbstractItemModel::dataChanged(), emit, QVector< T >::end(), header(), QTableView::horizontalHeader(), i, QAbstractTableModel::index(),QVector< T >::insert(), QTableWidget::isSortingEnabled(), item(), j, QAbstractItemModel::layoutAboutToBeChanged(),QAbstractItemModel::layoutChanged(), QTableWidgetItem::model, QObject::parent(), QAbstractItemModel::persistentIndexList(), qMax(), QVector< T >::remove(), sortedInsertionIterator(), QHeaderView::sortIndicatorOrder(), QHeaderView::sortIndicatorSection(), tableIndex(), tableItems,updateRowIndexes(), and verticalHeaderItems.
00136 { 00137 int i = tableIndex(row, column); 00138 if (i < 0 || i >= tableItems.count()) 00139 return; 00140 QTableWidgetItem *oldItem = tableItems.at(i); 00141 if (item == oldItem) 00142 return; 00143 00144 // remove old 00145 if (oldItem) 00146 oldItem->model = 0; 00147 delete tableItems.at(i); 00148 00149 // set new 00150 if (item) 00151 item->model = this; 00152 tableItems[i] = item; 00153 00154 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); 00155 if (view && view->isSortingEnabled() 00156 && view->horizontalHeader()->sortIndicatorSection() == column) { 00157 // sorted insertion 00158 Qt::SortOrder order = view->horizontalHeader()->sortIndicatorOrder(); 00159 QVector<QTableWidgetItem*> colItems = columnItems(column); 00160 if (row < colItems.count()) 00161 colItems.remove(row); 00162 int sortedRow; 00163 if (item == 0) { 00164 // move to after all non-0 (sortable) items 00165 sortedRow = colItems.count(); 00166 } else { 00167 QVector<QTableWidgetItem*>::iterator it; 00168 it = sortedInsertionIterator(colItems.begin(), colItems.end(), order, item); 00169 sortedRow = qMax((int)(it - colItems.begin()), 0); 00170 } 00171 if (sortedRow != row) { 00172 emit layoutAboutToBeChanged(); 00173 // move the items @ row to sortedRow 00174 int cc = columnCount(); 00175 QVector<QTableWidgetItem*> rowItems(cc); 00176 for (int j = 0; j < cc; ++j) 00177 rowItems[j] = tableItems.at(tableIndex(row, j)); 00178 tableItems.remove(tableIndex(row, 0), cc); 00179 tableItems.insert(tableIndex(sortedRow, 0), cc, 0); 00180 for (int j = 0; j < cc; ++j) 00181 tableItems[tableIndex(sortedRow, j)] = rowItems.at(j); 00182 QTableWidgetItem *header = verticalHeaderItems.at(row); 00183 verticalHeaderItems.remove(row); 00184 verticalHeaderItems.insert(sortedRow, header); 00185 // update persistent indexes 00186 QModelIndexList oldPersistentIndexes = persistentIndexList(); 00187 QModelIndexList newPersistentIndexes = oldPersistentIndexes; 00188 updateRowIndexes(newPersistentIndexes, row, sortedRow); 00189 changePersistentIndexList(oldPersistentIndexes, 00190 newPersistentIndexes); 00191 00192 emit layoutChanged(); 00193 return; 00194 } 00195 } 00196 QModelIndex idx = QAbstractTableModel::index(row, column); 00197 emit dataChanged(idx, idx); 00198 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::takeItem | ( | int | row, | |
int | column | |||
) |
Definition at line 200 of file qtablewidget.cpp.
References i, QTableWidgetItem::model, tableIndex(), tableItems, and QVector< T >::value().
00201 { 00202 long i = tableIndex(row, column); 00203 QTableWidgetItem *itm = tableItems.value(i); 00204 if (itm) { 00205 itm->model = 0; 00206 tableItems[i] = 0; 00207 } 00208 return itm; 00209 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::item | ( | int | row, | |
int | column | |||
) | const |
Definition at line 211 of file qtablewidget.cpp.
References tableIndex(), tableItems, and QVector< T >::value().
Referenced by QTableWidgetPrivate::_q_emitCurrentItemChanged(), columnItems(), data(), ensureSorted(), flags(), index(), itemChanged(), mimeData(),removeItem(), setData(), setHorizontalHeaderItem(), setItem(), setItemPrototype(), setVerticalHeaderItem(), sort(), and sortedInsertionIterator().
00212 { 00213 return tableItems.value(tableIndex(row, column)); 00214 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::item | ( | const QModelIndex & | index | ) | const |
Definition at line 216 of file qtablewidget.cpp.
References QVector< T >::at(), QModelIndex::column(), index(), isValid(), QModelIndex::row(), tableIndex(), and tableItems.
00217 { 00218 if (!isValid(index)) 00219 return 0; 00220 return tableItems.at(tableIndex(index.row(), index.column())); 00221 }
Here is the call graph for this function:
void QTableModel::removeItem | ( | QTableWidgetItem * | item | ) |
Definition at line 223 of file qtablewidget.cpp.
References QAbstractItemModel::dataChanged(), emit, QAbstractItemModel::headerDataChanged(), Qt::Horizontal, horizontalHeaderItems, i, index(),QVector< T >::indexOf(), item(), tableItems, Qt::Vertical, and verticalHeaderItems.
Referenced by QTableWidgetItem::~QTableWidgetItem().
00224 { 00225 int i = tableItems.indexOf(item); 00226 if (i != -1) { 00227 tableItems[i] = 0; 00228 QModelIndex idx = index(item); 00229 emit dataChanged(idx, idx); 00230 return; 00231 } 00232 00233 i = verticalHeaderItems.indexOf(item); 00234 00235 if (i != -1) { 00236 verticalHeaderItems[i] = 0; 00237 emit headerDataChanged(Qt::Vertical, i, i); 00238 return; 00239 } 00240 i = horizontalHeaderItems.indexOf(item); 00241 if (i != -1) { 00242 horizontalHeaderItems[i] = 0; 00243 emit headerDataChanged(Qt::Horizontal, i, i); 00244 return; 00245 } 00246 }
Here is the call graph for this function:
void QTableModel::setHorizontalHeaderItem | ( | int | section, | |
QTableWidgetItem * | item | |||
) |
Definition at line 248 of file qtablewidget.cpp.
References QVector< T >::at(), QVector< T >::count(), emit, QAbstractItemModel::headerDataChanged(), Qt::Horizontal, horizontalHeaderItems, item(),QTableWidgetItem::itemFlags, ItemIsHeaderItem, and QTableWidgetItem::model.
00249 { 00250 if (section < 0 || section >= horizontalHeaderItems.count()) 00251 return; 00252 QTableWidgetItem *oldItem = horizontalHeaderItems.at(section); 00253 if (item == oldItem) 00254 return; 00255 00256 if (oldItem) 00257 oldItem->model = 0; 00258 delete oldItem; 00259 00260 if (item) { 00261 item->model = this; 00262 item->itemFlags = Qt::ItemFlags(int(item->itemFlags)|ItemIsHeaderItem); 00263 } 00264 horizontalHeaderItems[section] = item; 00265 emit headerDataChanged(Qt::Horizontal, section, section); 00266 }
Here is the call graph for this function:
void QTableModel::setVerticalHeaderItem | ( | int | section, | |
QTableWidgetItem * | item | |||
) |
Definition at line 268 of file qtablewidget.cpp.
References QVector< T >::at(), QVector< T >::count(), emit, QAbstractItemModel::headerDataChanged(), item(), QTableWidgetItem::itemFlags,ItemIsHeaderItem, QTableWidgetItem::model, Qt::Vertical, and verticalHeaderItems.
00269 { 00270 if (section < 0 || section >= verticalHeaderItems.count()) 00271 return; 00272 QTableWidgetItem *oldItem = verticalHeaderItems.at(section); 00273 if (item == oldItem) 00274 return; 00275 00276 if (oldItem) 00277 oldItem->model = 0; 00278 delete oldItem; 00279 00280 if (item) { 00281 item->model = this; 00282 item->itemFlags = Qt::ItemFlags(int(item->itemFlags)|ItemIsHeaderItem); 00283 } 00284 verticalHeaderItems[section] = item; 00285 emit headerDataChanged(Qt::Vertical, section, section); 00286 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::takeHorizontalHeaderItem | ( | int | section | ) |
Definition at line 288 of file qtablewidget.cpp.
References QVector< T >::at(), QVector< T >::count(), horizontalHeaderItems, QTableWidgetItem::itemFlags, ItemIsHeaderItem, andQTableWidgetItem::model.
00289 { 00290 if (section < 0 || section >= horizontalHeaderItems.count()) 00291 return 0; 00292 QTableWidgetItem *itm = horizontalHeaderItems.at(section); 00293 if (itm) { 00294 itm->model = 0; 00295 itm->itemFlags &= ~ItemIsHeaderItem; 00296 horizontalHeaderItems[section] = 0; 00297 } 00298 return itm; 00299 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::takeVerticalHeaderItem | ( | int | section | ) |
Definition at line 301 of file qtablewidget.cpp.
References QVector< T >::at(), QVector< T >::count(), QTableWidgetItem::itemFlags, ItemIsHeaderItem, QTableWidgetItem::model, andverticalHeaderItems.
00302 { 00303 if (section < 0 || section >= verticalHeaderItems.count()) 00304 return 0; 00305 QTableWidgetItem *itm = verticalHeaderItems.at(section); 00306 if (itm) { 00307 itm->model = 0; 00308 itm->itemFlags &= ~ItemIsHeaderItem; 00309 verticalHeaderItems[section] = 0; 00310 } 00311 return itm; 00312 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::horizontalHeaderItem | ( | int | section | ) |
Definition at line 314 of file qtablewidget.cpp.
References horizontalHeaderItems, and QVector< T >::value().
00315 { 00316 return horizontalHeaderItems.value(section); 00317 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::verticalHeaderItem | ( | int | section | ) |
Definition at line 319 of file qtablewidget.cpp.
References QVector< T >::value(), and verticalHeaderItems.
00320 { 00321 return verticalHeaderItems.value(section); 00322 }
Here is the call graph for this function:
QModelIndex QTableModel::index | ( | int | row, | |
int | column, | |||
const QModelIndex & | parent = QModelIndex() | |||
) | const [inline, virtual] |
Returns the index of the data in row and column with parent.
-
See also:
- parent()
Reimplemented from QAbstractTableModel.
Definition at line 100 of file qtablewidget_p.h.
References QAbstractTableModel::index(), and QObject::parent().
Referenced by data(), dropMimeData(), flags(), isValid(), item(), itemChanged(), removeItem(), setData(), and updateRowIndexes().
00101 { return QAbstractTableModel::index(row, column, parent); }
Here is the call graph for this function:
QModelIndex QTableModel::index | ( | const QTableWidgetItem * | item | ) | const |
Definition at line 324 of file qtablewidget.cpp.
References columnCount(), i, QAbstractTableModel::index(), QVector< T >::indexOf(), item(), row, and tableItems.
00325 { 00326 if (!item) 00327 return QModelIndex(); 00328 int i = tableItems.indexOf(const_cast<QTableWidgetItem*>(item)); 00329 if (i < 0) 00330 return QModelIndex(); 00331 int row = i / columnCount(); 00332 int col = i % columnCount(); 00333 return QAbstractTableModel::index(row, col); 00334 }
Here is the call graph for this function:
void QTableModel::setRowCount | ( | int | rows | ) |
Definition at line 336 of file qtablewidget.cpp.
References QVector< T >::count(), insertRows(), qMax(), removeRows(), and verticalHeaderItems.
00337 { 00338 int rc = verticalHeaderItems.count(); 00339 if (rows < 0 || rc == rows) 00340 return; 00341 if (rc < rows) 00342 insertRows(qMax(rc, 0), rows - rc); 00343 else 00344 removeRows(qMax(rows, 0), rc - rows); 00345 }
Here is the call graph for this function:
void QTableModel::setColumnCount | ( | int | columns | ) |
Definition at line 347 of file qtablewidget.cpp.
References QVector< T >::count(), horizontalHeaderItems, insertColumns(), qMax(), and removeColumns().
00348 { 00349 int cc = horizontalHeaderItems.count(); 00350 if (columns < 0 || cc == columns) 00351 return; 00352 if (cc < columns) 00353 insertColumns(qMax(cc, 0), columns - cc); 00354 else 00355 removeColumns(qMax(columns, 0), cc - columns); 00356 }
Here is the call graph for this function:
int QTableModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
Returns the number of rows under the given parent.
-
See also:
- columnCount()
Implements QAbstractItemModel.
Definition at line 358 of file qtablewidget.cpp.
References QVector< T >::count(), QObject::parent(), and verticalHeaderItems.
Referenced by columnItems(), dropMimeData(), removeColumns(), and sort().
00359 { 00360 return parent.isValid() ? 0 : verticalHeaderItems.count(); 00361 }
Here is the call graph for this function:
int QTableModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
Returns the number of columns for the children of the given parent.
In most subclasses, the number of columns is independent of the parent. For example:
itemviews/simpledommodel/dommodel.cpp columnCount /^$/
-
See also:
- rowCount()
Implements QAbstractItemModel.
Definition at line 363 of file qtablewidget.cpp.
References QVector< T >::count(), horizontalHeaderItems, and QObject::parent().
Referenced by ensureSorted(), index(), removeRows(), setItem(), and sort().
00364 { 00365 return parent.isValid() ? 0 : horizontalHeaderItems.count(); 00366 }
Here is the call graph for this function:
QVariant QTableModel::data | ( | const QModelIndex & | index, | |
int | role = Qt::DisplayRole | |||
) | const [virtual] |
Returns the data stored under the given role for the item referred to by the index.
-
See also:
- Qt::ItemDataRole, setData(), headerData()
Implements QAbstractItemModel.
Definition at line 368 of file qtablewidget.cpp.
References QTableWidgetItem::data(), index(), and item().
Referenced by dropMimeData().
00369 { 00370 QTableWidgetItem *itm = item(index); 00371 if (itm) 00372 return itm->data(role); 00373 return QVariant(); 00374 }
Here is the call graph for this function:
bool QTableModel::setData | ( | const QModelIndex & | index, | |
const QVariant & | value, | |||
int | role | |||
) | [virtual] |
Sets the role data for the item at index to value. Returns true if successful; otherwise returns false.
The dataChanged() signal should be emitted if the data was successfully set.
The base class implementation returns false. This function and data() must be reimplemented for editable models. Note that the dataChanged() signal must be emitted explicitly when reimplementing this function.
-
See also:
- Qt::ItemDataRole, data(), itemData()
Reimplemented from QAbstractItemModel.
Definition at line 376 of file qtablewidget.cpp.
References QModelIndex::column(), createItem(), index(), QModelIndex::isValid(), item(), QObject::parent(), QModelIndex::row(),QTableWidgetItem::setData(), QTableWidget::setItem(), and value.
Referenced by QTableWidgetItem::setBackground(), QTableWidgetItem::setBackgroundColor(), QTableWidgetItem::setCheckState(),QTableWidgetItem::setForeground(), QTableWidgetItem::setSizeHint(), QTableWidgetItem::setTextAlignment(), and QTableWidgetItem::setTextColor().
00377 { 00378 if (!index.isValid()) 00379 return false; 00380 00381 QTableWidgetItem *itm = item(index); 00382 if (itm) { 00383 itm->setData(role, value); 00384 return true; 00385 } 00386 00387 // don't create dummy table items for empty values 00388 if (!value.isValid()) 00389 return false; 00390 00391 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); 00392 if (!view) 00393 return false; 00394 00395 itm = createItem(); 00396 itm->setData(role, value); 00397 view->setItem(index.row(), index.column(), itm); 00398 return true; 00399 }
Here is the call graph for this function:
QVariant QTableModel::headerData | ( | int | section, | |
Qt::Orientation | orientation, | |||
int | role | |||
) | const [virtual] |
Returns the data for the given role and section in the header with the specified orientation.
-
See also:
- Qt::ItemDataRole, setHeaderData(), QHeaderView
Reimplemented from QAbstractItemModel.
Definition at line 627 of file qtablewidget.cpp.
References QVector< T >::at(), QVector< T >::count(), QTableWidgetItem::data(), Qt::DisplayRole, Qt::Horizontal, horizontalHeaderItems, Qt::Vertical, andverticalHeaderItems.
00628 { 00629 if (section < 0) 00630 return QVariant(); 00631 00632 QTableWidgetItem *itm = 0; 00633 if (orientation == Qt::Horizontal && section < horizontalHeaderItems.count()) 00634 itm = horizontalHeaderItems.at(section); 00635 else if (orientation == Qt::Vertical && section < verticalHeaderItems.count()) 00636 itm = verticalHeaderItems.at(section); 00637 else 00638 return QVariant(); // section is out of bounds 00639 00640 if (itm) 00641 return itm->data(role); 00642 if (role == Qt::DisplayRole) 00643 return section + 1; 00644 return QVariant(); 00645 }
Here is the call graph for this function:
bool QTableModel::setHeaderData | ( | int | section, | |
Qt::Orientation | orientation, | |||
const QVariant & | value, | |||
int | role | |||
) | [virtual] |
Sets the role for the header section to value. The orientation gives the orientation of the header.
Note that the headerDataChanged() signal must be emitted explicitly when reimplementing this function.
-
See also:
- Qt::ItemDataRole, headerData()
Reimplemented from QAbstractItemModel.
Definition at line 647 of file qtablewidget.cpp.
References QVector< T >::at(), Qt::Horizontal, horizontalHeaderItems, QTableWidgetItem::setData(), QVector< T >::size(), value, Qt::Vertical, andverticalHeaderItems.
00649 { 00650 if (section < 0 || 00651 (orientation == Qt::Horizontal && horizontalHeaderItems.size() <= section) || 00652 (orientation == Qt::Vertical && verticalHeaderItems.size() <= section)) 00653 return false; 00654 00655 QTableWidgetItem *itm = 0; 00656 if (orientation == Qt::Horizontal) 00657 itm = horizontalHeaderItems.at(section); 00658 else 00659 itm = verticalHeaderItems.at(section); 00660 if (itm) { 00661 itm->setData(role, value); 00662 return true; 00663 } 00664 return false; 00665 }
Here is the call graph for this function:
Qt::ItemFlags QTableModel::flags | ( | const QModelIndex & | index | ) | const [virtual] |
Returns the item flags for the given index.
The base class implementation returns a combination of flags that enables the item (ItemIsEnabled
) and allows it to be selected (ItemIsSelectable
).
-
See also:
- Qt::ItemFlags
Reimplemented from QAbstractItemModel.
Definition at line 401 of file qtablewidget.cpp.
References index(), QModelIndex::isValid(), item(), Qt::ItemIsDragEnabled, Qt::ItemIsDropEnabled, Qt::ItemIsEditable, Qt::ItemIsEnabled,Qt::ItemIsSelectable, and Qt::ItemIsUserCheckable.
00402 { 00403 if (!index.isValid()) 00404 return Qt::ItemIsDropEnabled; 00405 if (QTableWidgetItem *itm = item(index)) 00406 return itm->flags(); 00407 return (Qt::ItemIsEditable 00408 |Qt::ItemIsSelectable 00409 |Qt::ItemIsUserCheckable 00410 |Qt::ItemIsEnabled 00411 |Qt::ItemIsDragEnabled 00412 |Qt::ItemIsDropEnabled); 00413 }
Here is the call graph for this function:
void QTableModel::sort | ( | int | column, | |
Qt::SortOrder | order | |||
) | [virtual] |
Sorts the model by column in the given order.
The base class implementation does nothing.
Reimplemented from QAbstractItemModel.
Definition at line 415 of file qtablewidget.cpp.
References QVector< T >::append(), Qt::AscendingOrder, QVector< T >::at(), QVector< T >::begin(), c, QAbstractItemModel::changePersistentIndexList(),columnCount(), compare(), QVector< T >::count(), QAbstractItemModel::createIndex(), emit, QVector< T >::end(), i, item(), itemGreaterThan(),itemLessThan(), QAbstractItemModel::layoutAboutToBeChanged(), QAbstractItemModel::layoutChanged(), qStableSort(), QVector< T >::reserve(), row,rowCount(), tableIndex(), and tableItems.
Referenced by QTableWidgetPrivate::_q_sort().
00416 { 00417 QVector<QPair<QTableWidgetItem*, int> > sortable; 00418 QVector<int> unsortable; 00419 00420 sortable.reserve(rowCount()); 00421 unsortable.reserve(rowCount()); 00422 00423 for (int row = 0; row < rowCount(); ++row) { 00424 if (QTableWidgetItem *itm = item(row, column)) 00425 sortable.append(QPair<QTableWidgetItem*,int>(itm, row)); 00426 else 00427 unsortable.append(row); 00428 } 00429 00430 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan); 00431 qStableSort(sortable.begin(), sortable.end(), compare); 00432 00433 emit layoutAboutToBeChanged(); 00434 00435 QVector<QTableWidgetItem*> sorted_table(tableItems.count()); 00436 QModelIndexList from; 00437 QModelIndexList to; 00438 for (int i = 0; i < rowCount(); ++i) { 00439 int r = (i < sortable.count() 00440 ? sortable.at(i).second 00441 : unsortable.at(i - sortable.count())); 00442 for (int c = 0; c < columnCount(); ++c) { 00443 QTableWidgetItem *itm = item(r, c); 00444 sorted_table[tableIndex(i, c)] = itm; 00445 from << createIndex(r, c, 0); 00446 to << createIndex(i, c, 0); 00447 } 00448 } 00449 00450 tableItems = sorted_table; 00451 changePersistentIndexList(from, to); // ### slow 00452 00453 emit layoutChanged(); 00454 }
Here is the call graph for this function:
bool QTableModel::itemLessThan | ( | const QPair< QTableWidgetItem *, int > & | left, | |
const QPair< QTableWidgetItem *, int > & | right | |||
) | [static] |
Definition at line 615 of file qtablewidget.cpp.
References left(), and right().
Referenced by ensureSorted(), and sort().
Here is the call graph for this function:
bool QTableModel::itemGreaterThan | ( | const QPair< QTableWidgetItem *, int > & | left, | |
const QPair< QTableWidgetItem *, int > & | right | |||
) | [static] |
Definition at line 621 of file qtablewidget.cpp.
References left(), and right().
Referenced by ensureSorted(), and sort().
Here is the call graph for this function:
bool QTableModel::canConvertToDouble | ( | const QVariant & | value | ) | [static] |
Definition at line 456 of file qtablewidget.cpp.
References QVariant::Bool, QVariant::Char, QVariant::Double, QVariant::Int, QVariant::LongLong, QVariant::UInt, QVariant::ULongLong, and value.
Referenced by QTableWidgetItem::operator<().
00457 { 00458 switch (value.type()) { 00459 case QVariant::Bool: 00460 case QVariant::Int: 00461 case QVariant::UInt: 00462 case QVariant::LongLong: 00463 case QVariant::ULongLong: 00464 case QVariant::Double: 00465 case QVariant::Char: 00466 return true; 00467 default: 00468 return false; 00469 } 00470 return false; 00471 }
void QTableModel::ensureSorted | ( | int | column, | |
Qt::SortOrder | order, | |||
int | start, | |||
int | end | |||
) |
Definition at line 481 of file qtablewidget.cpp.
References QVector< T >::append(), Qt::AscendingOrder, QVector< T >::at(), QVector< T >::begin(), QAbstractItemModel::changePersistentIndexList(),columnCount(), columnItems(), compare(), QVector< T >::count(), emit, QVector< T >::end(), header(), i, QVector< T >::insert(), item(),itemGreaterThan(), itemLessThan(), j, QAbstractItemModel::layoutAboutToBeChanged(), QAbstractItemModel::layoutChanged(), QTest::newRow(),QAbstractItemModel::persistentIndexList(), qMax(), qStableSort(), QVector< T >::remove(), QVector< T >::reserve(), row, sortedInsertionIterator(),tableIndex(), tableItems, updateRowIndexes(), and verticalHeaderItems.
Referenced by QTableWidgetPrivate::_q_dataChanged().
00483 { 00484 int count = end - start + 1; 00485 QVector < QPair<QTableWidgetItem*,int> > sorting; 00486 sorting.reserve(count); 00487 for (int row = start; row <= end; ++row) { 00488 QTableWidgetItem *itm = item(row, column); 00489 if (itm == 0) { 00490 // no more sortable items (all 0-items are 00491 // at the end of the table when it is sorted) 00492 break; 00493 } 00494 sorting.append(QPair<QTableWidgetItem*,int>(itm, row)); 00495 } 00496 00497 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan); 00498 qStableSort(sorting.begin(), sorting.end(), compare); 00499 00500 QModelIndexList oldPersistentIndexes = persistentIndexList(); 00501 QModelIndexList newPersistentIndexes = oldPersistentIndexes; 00502 QVector<QTableWidgetItem*> newTable = tableItems; 00503 QVector<QTableWidgetItem*> newVertical = verticalHeaderItems; 00504 QVector<QTableWidgetItem*> colItems = columnItems(column); 00505 QVector<QTableWidgetItem*>::iterator vit = colItems.begin(); 00506 bool changed = false; 00507 for (int i = 0; i < sorting.count(); ++i) { 00508 int oldRow = sorting.at(i).second; 00509 QTableWidgetItem *item = colItems.at(oldRow); 00510 colItems.remove(oldRow); 00511 vit = sortedInsertionIterator(vit, colItems.end(), order, item); 00512 int newRow = qMax((int)(vit - colItems.begin()), 0); 00513 vit = colItems.insert(vit, item); 00514 if (newRow != oldRow) { 00515 changed = true; 00516 // move the items @ oldRow to newRow 00517 int cc = columnCount(); 00518 QVector<QTableWidgetItem*> rowItems(cc); 00519 for (int j = 0; j < cc; ++j) 00520 rowItems[j] = newTable.at(tableIndex(oldRow, j)); 00521 newTable.remove(tableIndex(oldRow, 0), cc); 00522 newTable.insert(tableIndex(newRow, 0), cc, 0); 00523 for (int j = 0; j < cc; ++j) 00524 newTable[tableIndex(newRow, j)] = rowItems.at(j); 00525 QTableWidgetItem *header = newVertical.at(oldRow); 00526 newVertical.remove(oldRow); 00527 newVertical.insert(newRow, header); 00528 // update persistent indexes 00529 updateRowIndexes(newPersistentIndexes, oldRow, newRow); 00530 // the index of the remaining rows may have changed 00531 for (int j = i + 1; j < sorting.count(); ++j) { 00532 int otherRow = sorting.at(j).second; 00533 if (oldRow < otherRow && newRow >= otherRow) 00534 --sorting[j].second; 00535 else if (oldRow > otherRow && newRow <= otherRow) 00536 ++sorting[j].second; 00537 } 00538 } 00539 } 00540 00541 if (changed) { 00542 emit layoutAboutToBeChanged(); 00543 tableItems = newTable; 00544 verticalHeaderItems = newVertical; 00545 changePersistentIndexList(oldPersistentIndexes, 00546 newPersistentIndexes); 00547 emit layoutChanged(); 00548 } 00549 }
Here is the call graph for this function:
QVector< QTableWidgetItem * > QTableModel::columnItems | ( | int | column | ) | const |
Definition at line 556 of file qtablewidget.cpp.
References QVector< T >::append(), item(), QVector< T >::reserve(), row, and rowCount().
Referenced by ensureSorted(), and setItem().
00557 { 00558 QVector<QTableWidgetItem*> items; 00559 int rc = rowCount(); 00560 items.reserve(rc); 00561 for (int row = 0; row < rc; ++row) { 00562 QTableWidgetItem *itm = item(row, column); 00563 if (itm == 0) { 00564 // no more sortable items (all 0-items are 00565 // at the end of the table when it is sorted) 00566 break; 00567 } 00568 items.append(itm); 00569 } 00570 return items; 00571 }
Here is the call graph for this function:
void QTableModel::updateRowIndexes | ( | QModelIndexList & | indexes, | |
int | movedFromRow, | |||
int | movedToRow | |||
) |
Definition at line 580 of file qtablewidget.cpp.
References QList< T >::begin(), QList< T >::end(), index(), and QTest::newRow().
Referenced by ensureSorted(), and setItem().
00582 { 00583 QModelIndexList::iterator it; 00584 for (it = indexes.begin(); it != indexes.end(); ++it) { 00585 int oldRow = (*it).row(); 00586 int newRow = oldRow; 00587 if (oldRow == movedFromRow) 00588 newRow = movedToRow; 00589 else if (movedFromRow < oldRow && movedToRow >= oldRow) 00590 newRow = oldRow - 1; 00591 else if (movedFromRow > oldRow && movedToRow <= oldRow) 00592 newRow = oldRow + 1; 00593 if (newRow != oldRow) 00594 *it = index(newRow, (*it).column(), (*it).parent()); 00595 } 00596 }
Here is the call graph for this function:
QVector< QTableWidgetItem * >::iterator QTableModel::sortedInsertionIterator | ( | const QVector< QTableWidgetItem * >::iterator & | begin, | |
const QVector< QTableWidgetItem * >::iterator & | end, | |||
Qt::SortOrder | order, | |||
QTableWidgetItem * | item | |||
) | [static] |
Definition at line 605 of file qtablewidget.cpp.
References Qt::AscendingOrder, item(), and qLowerBound().
Referenced by ensureSorted(), and setItem().
00609 { 00610 if (order == Qt::AscendingOrder) 00611 return qLowerBound(begin, end, item, QTableModelLessThan()); 00612 return qLowerBound(begin, end, item, QTableModelGreaterThan()); 00613 }
Here is the call graph for this function:
bool QTableModel::isValid | ( | const QModelIndex & | index | ) | const |
Definition at line 667 of file qtablewidget.cpp.
References QModelIndex::column(), QVector< T >::count(), horizontalHeaderItems, index(), QModelIndex::isValid(), QModelIndex::row(), andverticalHeaderItems.
Referenced by item().
00668 { 00669 return (index.isValid() 00670 && index.row() < verticalHeaderItems.count() 00671 && index.column() < horizontalHeaderItems.count()); 00672 }
Here is the call graph for this function:
long QTableModel::tableIndex | ( | int | row, | |
int | column | |||
) | const [inline] |
Definition at line 135 of file qtablewidget_p.h.
References QVector< T >::count(), and horizontalHeaderItems.
Referenced by ensureSorted(), insertColumns(), insertRows(), item(), removeColumns(), removeRows(), setItem(), sort(), and takeItem().
00136 { return (row * horizontalHeaderItems.count()) + column; }
Here is the call graph for this function:
void QTableModel::clear | ( | ) |
Definition at line 674 of file qtablewidget.cpp.
References QVector< T >::at(), clearContents(), QVector< T >::count(), horizontalHeaderItems, j, QTableWidgetItem::model, and verticalHeaderItems.
Referenced by ~QTableModel().
00675 { 00676 for (int j = 0; j < verticalHeaderItems.count(); ++j) { 00677 if (verticalHeaderItems.at(j)) { 00678 verticalHeaderItems.at(j)->model = 0; 00679 delete verticalHeaderItems.at(j); 00680 verticalHeaderItems[j] = 0; 00681 } 00682 } 00683 for (int k = 0; k < horizontalHeaderItems.count(); ++k) { 00684 if (horizontalHeaderItems.at(k)) { 00685 horizontalHeaderItems.at(k)->model = 0; 00686 delete horizontalHeaderItems.at(k); 00687 horizontalHeaderItems[k] = 0; 00688 } 00689 } 00690 clearContents(); 00691 }
Here is the call graph for this function:
void QTableModel::clearContents | ( | ) |
Definition at line 693 of file qtablewidget.cpp.
References QVector< T >::at(), QVector< T >::count(), i, QTableWidgetItem::model, QAbstractItemModel::reset(), and tableItems.
Referenced by clear().
00694 { 00695 for (int i = 0; i < tableItems.count(); ++i) { 00696 if (tableItems.at(i)) { 00697 tableItems.at(i)->model = 0; 00698 delete tableItems.at(i); 00699 tableItems[i] = 0; 00700 } 00701 } 00702 reset(); 00703 }
Here is the call graph for this function:
void QTableModel::itemChanged | ( | QTableWidgetItem * | item | ) |
Definition at line 705 of file qtablewidget.cpp.
References QAbstractItemModel::dataChanged(), emit, QTableWidgetItem::flags(), QAbstractItemModel::headerDataChanged(), Qt::Horizontal,horizontalHeaderItems, index(), QVector< T >::indexOf(), QModelIndex::isValid(), item(), ItemIsHeaderItem, row, Qt::Vertical, and verticalHeaderItems.
Referenced by QTableWidgetItem::setData(), and QTableWidgetItem::setFlags().
00706 { 00707 if (!item) 00708 return; 00709 if (item->flags() & ItemIsHeaderItem) { 00710 int row = verticalHeaderItems.indexOf(item); 00711 if (row >= 0) { 00712 emit headerDataChanged(Qt::Vertical, row, row); 00713 } else { 00714 int column = horizontalHeaderItems.indexOf(item); 00715 if (column >= 0) 00716 emit headerDataChanged(Qt::Horizontal, column, column); 00717 } 00718 } else { 00719 QModelIndex idx = index(item); 00720 if (idx.isValid()) 00721 emit dataChanged(idx, idx); 00722 } 00723 }
Here is the call graph for this function:
QTableWidgetItem * QTableModel::createItem | ( | ) | const |
Definition at line 725 of file qtablewidget.cpp.
References QTableWidgetItem::clone(), and prototype.
Referenced by setData().
00726 { 00727 return prototype ? prototype->clone() : new QTableWidgetItem; 00728 }
Here is the call graph for this function:
const QTableWidgetItem * QTableModel::itemPrototype | ( | ) | const |
Definition at line 730 of file qtablewidget.cpp.
References prototype.
00731 { 00732 return prototype; 00733 }
void QTableModel::setItemPrototype | ( | const QTableWidgetItem * | item | ) |
QStringList QTableModel::mimeTypes | ( | ) | const [virtual] |
Returns a list of MIME types that can be used to describe a list of model indexes.
-
See also:
- mimeData()
Reimplemented from QAbstractItemModel.
Definition at line 743 of file qtablewidget.cpp.
References QTableWidget::mimeTypes(), and QObject::parent().
00744 { 00745 const QTableWidget *view = ::qobject_cast<const QTableWidget*>(QObject::parent()); 00746 return (view ? view->mimeTypes() : QStringList()); 00747 }
Here is the call graph for this function:
QMimeData * QTableModel::mimeData | ( | const QModelIndexList & | indexes | ) | const [virtual] |
Returns an object that contains serialized items of data corresponding to the list of indexes specified. The formats used to describe the encoded data is obtained from the mimeTypes() function.
If the list of indexes is empty, or there are no supported MIME types, 0 is returned rather than a serialized empty list.
-
See also:
- mimeTypes(), dropMimeData()
Reimplemented from QAbstractItemModel.
Definition at line 754 of file qtablewidget.cpp.
References QList< T >::at(), cachedIndexes, QMimeData::clear(), QList< T >::count(), i, item(), QTableWidget::mimeData(), and QObject::parent().
00755 { 00756 QList<QTableWidgetItem*> items; 00757 for (int i = 0; i < indexes.count(); ++i) 00758 items << item(indexes.at(i)); 00759 const QTableWidget *view = ::qobject_cast<const QTableWidget*>(QObject::parent()); 00760 00761 // cachedIndexes is a little hack to avoid copying from QModelIndexList to 00762 // QList<QTreeWidgetItem*> and back again in the view 00763 cachedIndexes = indexes; 00764 QMimeData *mimeData = (view ? view->mimeData(items) : 0); 00765 cachedIndexes.clear(); 00766 return mimeData; 00767 }
Here is the call graph for this function:
bool QTableModel::dropMimeData | ( | const QMimeData * | data, | |
Qt::DropAction | action, | |||
int | row, | |||
int | column, | |||
const QModelIndex & | parent | |||
) | [virtual] |
Reimplemented from QAbstractTableModel.
Definition at line 769 of file qtablewidget.cpp.
References QModelIndex::column(), data(), QTableWidget::dropMimeData(), index(), QModelIndex::isValid(), QObject::parent(), QModelIndex::row(), androwCount().
00771 { 00772 if (index.isValid()) { 00773 row = index.row(); 00774 column = index.column(); 00775 }else if (row == -1 || column == -1) { // The user dropped outside the table. 00776 row = rowCount(); 00777 column = 0; 00778 } 00779 00780 QTableWidget *view = ::qobject_cast<QTableWidget*>(QObject::parent()); 00781 return (view ? view->dropMimeData(row, column, data, action) : false); 00782 }
Here is the call graph for this function:
Qt::DropActions QTableModel::supportedDropActions | ( | ) | const [virtual] |
-
Since:
- 4.2
The default implementation returns Qt::CopyAction. Reimplement this function if you wish to support additional actions. Note that you must also reimplement thedropMimeData() function to handle the additional operations.
-
See also:
- dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item Views}
Reimplemented from QAbstractItemModel.
Definition at line 784 of file qtablewidget.cpp.
References Qt::IgnoreAction, QObject::parent(), and QTableWidget::supportedDropActions().
00785 { 00786 const QTableWidget *view = ::qobject_cast<const QTableWidget*>(QObject::parent()); 00787 return (view ? view->supportedDropActions() : Qt::DropActions(Qt::IgnoreAction)); 00788 }
Here is the call graph for this function:
QMimeData * QTableModel::internalMimeData | ( | ) | const |
Definition at line 749 of file qtablewidget.cpp.
References cachedIndexes, and QAbstractItemModel::mimeData().
00750 { 00751 return QAbstractTableModel::mimeData(cachedIndexes); 00752 }
Here is the call graph for this function:
Member Data Documentation
const QTableWidgetItem* QTableModel::prototype [private] |
Definition at line 156 of file qtablewidget_p.h.
Referenced by createItem(), itemPrototype(), setItemPrototype(), and ~QTableModel().
QVector<QTableWidgetItem*> QTableModel::tableItems [private] |
Definition at line 157 of file qtablewidget_p.h.
Referenced by clearContents(), ensureSorted(), index(), insertColumns(), insertRows(), item(), removeColumns(), removeItem(), removeRows(),setItem(), sort(), and takeItem().
QVector<QTableWidgetItem*> QTableModel::verticalHeaderItems [private] |
Definition at line 158 of file qtablewidget_p.h.
Referenced by clear(), ensureSorted(), headerData(), insertColumns(), insertRows(), isValid(), itemChanged(), removeItem(), removeRows(),rowCount(), setHeaderData(), setItem(), setRowCount(), setVerticalHeaderItem(), takeVerticalHeaderItem(), and verticalHeaderItem().
Definition at line 159 of file qtablewidget_p.h.
Referenced by clear(), columnCount(), headerData(), horizontalHeaderItem(), insertColumns(), insertRows(), isValid(), itemChanged(),removeColumns(), removeItem(), setColumnCount(), setHeaderData(), setHorizontalHeaderItem(), tableIndex(), and takeHorizontalHeaderItem().
QModelIndexList QTableModel::cachedIndexes [mutable, private] |
Definition at line 162 of file qtablewidget_p.h.
Referenced by internalMimeData(), and mimeData().
The documentation for this class was generated from the following files:
- src/gui/itemviews/qtablewidget_p.h
- src/gui/itemviews/qtablewidget.cpp
Generated on Thu Mar 15 19:17:00 2007 for Qt 4.2 User's Guide by 1.5.1