qtablewidget.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qtablewidget.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qtablewidget.h"-
41-
42#ifndef QT_NO_TABLEWIDGET-
43#include <qitemdelegate.h>-
44#include <qpainter.h>-
45#include <private/qtablewidget_p.h>-
46-
47#include <algorithm>-
48-
49QT_BEGIN_NAMESPACE-
50-
51QTableModel::QTableModel(int rows, int columns, QTableWidget *parent)-
52 : QAbstractTableModel(parent),-
53 prototype(0),-
54 tableItems(rows * columns, 0),-
55 verticalHeaderItems(rows, 0),-
56 horizontalHeaderItems(columns, 0)-
57{}
never executed: end of block
0
58-
59QTableModel::~QTableModel()-
60{-
61 clear();-
62 delete prototype;-
63}
never executed: end of block
0
64-
65bool QTableModel::insertRows(int row, int count, const QModelIndex &)-
66{-
67 if (count < 1 || row < 0 || row > verticalHeaderItems.count())
count < 1Description
TRUEnever evaluated
FALSEnever evaluated
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
row > vertical...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
68 return false;
never executed: return false;
0
69-
70 beginInsertRows(QModelIndex(), row, row + count - 1);-
71 int rc = verticalHeaderItems.count();-
72 int cc = horizontalHeaderItems.count();-
73 verticalHeaderItems.insert(row, count, 0);-
74 if (rc == 0)
rc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
75 tableItems.resize(cc * count);
never executed: tableItems.resize(cc * count);
0
76 else-
77 tableItems.insert(tableIndex(row, 0), cc * count, 0);
never executed: tableItems.insert(tableIndex(row, 0), cc * count, 0);
0
78 endInsertRows();-
79 return true;
never executed: return true;
0
80}-
81-
82bool QTableModel::insertColumns(int column, int count, const QModelIndex &)-
83{-
84 if (count < 1 || column < 0 || column > horizontalHeaderItems.count())
count < 1Description
TRUEnever evaluated
FALSEnever evaluated
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
column > horiz...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
85 return false;
never executed: return false;
0
86-
87 beginInsertColumns(QModelIndex(), column, column + count - 1);-
88 int rc = verticalHeaderItems.count();-
89 int cc = horizontalHeaderItems.count();-
90 horizontalHeaderItems.insert(column, count, 0);-
91 if (cc == 0)
cc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
92 tableItems.resize(rc * count);
never executed: tableItems.resize(rc * count);
0
93 else-
94 for (int row = 0; row < rc; ++row)
row < rcDescription
TRUEnever evaluated
FALSEnever evaluated
0
95 tableItems.insert(tableIndex(row, column), count, 0);
never executed: tableItems.insert(tableIndex(row, column), count, 0);
0
96 endInsertColumns();-
97 return true;
never executed: return true;
0
98}-
99-
100bool QTableModel::removeRows(int row, int count, const QModelIndex &)-
101{-
102 if (count < 1 || row < 0 || row + count > verticalHeaderItems.count())
count < 1Description
TRUEnever evaluated
FALSEnever evaluated
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
row + count > ...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
103 return false;
never executed: return false;
0
104-
105 beginRemoveRows(QModelIndex(), row, row + count - 1);-
106 int i = tableIndex(row, 0);-
107 int n = count * columnCount();-
108 QTableWidgetItem *oldItem = 0;-
109 for (int j = i; j < n + i; ++j) {
j < n + iDescription
TRUEnever evaluated
FALSEnever evaluated
0
110 oldItem = tableItems.at(j);-
111 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
112 oldItem->view = 0;
never executed: oldItem->view = 0;
0
113 delete oldItem;-
114 }
never executed: end of block
0
115 tableItems.remove(qMax(i, 0), n);-
116 for (int v = row; v < row + count; ++v) {
v < row + countDescription
TRUEnever evaluated
FALSEnever evaluated
0
117 oldItem = verticalHeaderItems.at(v);-
118 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
119 oldItem->view = 0;
never executed: oldItem->view = 0;
0
120 delete oldItem;-
121 }
never executed: end of block
0
122 verticalHeaderItems.remove(row, count);-
123 endRemoveRows();-
124 return true;
never executed: return true;
0
125}-
126-
127bool QTableModel::removeColumns(int column, int count, const QModelIndex &)-
128{-
129 if (count < 1 || column < 0 || column + count > horizontalHeaderItems.count())
count < 1Description
TRUEnever evaluated
FALSEnever evaluated
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
column + count...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
130 return false;
never executed: return false;
0
131-
132 beginRemoveColumns(QModelIndex(), column, column + count - 1);-
133 QTableWidgetItem *oldItem = 0;-
134 for (int row = rowCount() - 1; row >= 0; --row) {
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
135 int i = tableIndex(row, column);-
136 for (int j = i; j < i + count; ++j) {
j < i + countDescription
TRUEnever evaluated
FALSEnever evaluated
0
137 oldItem = tableItems.at(j);-
138 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
139 oldItem->view = 0;
never executed: oldItem->view = 0;
0
140 delete oldItem;-
141 }
never executed: end of block
0
142 tableItems.remove(i, count);-
143 }
never executed: end of block
0
144 for (int h=column; h<column+count; ++h) {
h<column+countDescription
TRUEnever evaluated
FALSEnever evaluated
0
145 oldItem = horizontalHeaderItems.at(h);-
146 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
147 oldItem->view = 0;
never executed: oldItem->view = 0;
0
148 delete oldItem;-
149 }
never executed: end of block
0
150 horizontalHeaderItems.remove(column, count);-
151 endRemoveColumns();-
152 return true;
never executed: return true;
0
153}-
154-
155void QTableModel::setItem(int row, int column, QTableWidgetItem *item)-
156{-
157 int i = tableIndex(row, column);-
158 if (i < 0 || i >= tableItems.count())
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
i >= tableItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
159 return;
never executed: return;
0
160 QTableWidgetItem *oldItem = tableItems.at(i);-
161 if (item == oldItem)
item == oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
162 return;
never executed: return;
0
163-
164 // remove old-
165 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
166 oldItem->view = 0;
never executed: oldItem->view = 0;
0
167 delete tableItems.at(i);-
168-
169 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent());-
170-
171 // set new-
172 if (item)
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
173 item->d->id = i;
never executed: item->d->id = i;
0
174 tableItems[i] = item;-
175-
176 if (view && view->isSortingEnabled()
viewDescription
TRUEnever evaluated
FALSEnever evaluated
view->isSortingEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
177 && view->horizontalHeader()->sortIndicatorSection() == column) {
view->horizont...on() == columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
178 // sorted insertion-
179 Qt::SortOrder order = view->horizontalHeader()->sortIndicatorOrder();-
180 QVector<QTableWidgetItem*> colItems = columnItems(column);-
181 if (row < colItems.count())
row < colItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
182 colItems.remove(row);
never executed: colItems.remove(row);
0
183 int sortedRow;-
184 if (item == 0) {
item == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
185 // move to after all non-0 (sortable) items-
186 sortedRow = colItems.count();-
187 } else {
never executed: end of block
0
188 QVector<QTableWidgetItem*>::iterator it;-
189 it = sortedInsertionIterator(colItems.begin(), colItems.end(), order, item);-
190 sortedRow = qMax((int)(it - colItems.begin()), 0);-
191 }
never executed: end of block
0
192 if (sortedRow != row) {
sortedRow != rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 emit layoutAboutToBeChanged();-
194 // move the items @ row to sortedRow-
195 int cc = columnCount();-
196 QVector<QTableWidgetItem*> rowItems(cc);-
197 for (int j = 0; j < cc; ++j)
j < ccDescription
TRUEnever evaluated
FALSEnever evaluated
0
198 rowItems[j] = tableItems.at(tableIndex(row, j));
never executed: rowItems[j] = tableItems.at(tableIndex(row, j));
0
199 tableItems.remove(tableIndex(row, 0), cc);-
200 tableItems.insert(tableIndex(sortedRow, 0), cc, 0);-
201 for (int j = 0; j < cc; ++j)
j < ccDescription
TRUEnever evaluated
FALSEnever evaluated
0
202 tableItems[tableIndex(sortedRow, j)] = rowItems.at(j);
never executed: tableItems[tableIndex(sortedRow, j)] = rowItems.at(j);
0
203 QTableWidgetItem *header = verticalHeaderItems.at(row);-
204 verticalHeaderItems.remove(row);-
205 verticalHeaderItems.insert(sortedRow, header);-
206 // update persistent indexes-
207 QModelIndexList oldPersistentIndexes = persistentIndexList();-
208 QModelIndexList newPersistentIndexes = oldPersistentIndexes;-
209 updateRowIndexes(newPersistentIndexes, row, sortedRow);-
210 changePersistentIndexList(oldPersistentIndexes,-
211 newPersistentIndexes);-
212-
213 emit layoutChanged();-
214 return;
never executed: return;
0
215 }-
216 }
never executed: end of block
0
217 QModelIndex idx = QAbstractTableModel::index(row, column);-
218 emit dataChanged(idx, idx);-
219}
never executed: end of block
0
220-
221QTableWidgetItem *QTableModel::takeItem(int row, int column)-
222{-
223 long i = tableIndex(row, column);-
224 QTableWidgetItem *itm = tableItems.value(i);-
225 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
226 itm->view = 0;-
227 itm->d->id = -1;-
228 tableItems[i] = 0;-
229 QModelIndex ind = index(itm);-
230 emit dataChanged(ind, ind);-
231 }
never executed: end of block
0
232 return itm;
never executed: return itm;
0
233}-
234-
235QTableWidgetItem *QTableModel::item(int row, int column) const-
236{-
237 return item(index(row, column));
never executed: return item(index(row, column));
0
238}-
239-
240QTableWidgetItem *QTableModel::item(const QModelIndex &index) const-
241{-
242 if (!isValid(index))
!isValid(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
243 return 0;
never executed: return 0;
0
244 return tableItems.at(tableIndex(index.row(), index.column()));
never executed: return tableItems.at(tableIndex(index.row(), index.column()));
0
245}-
246-
247void QTableModel::removeItem(QTableWidgetItem *item)-
248{-
249 int i = tableItems.indexOf(item);-
250 if (i != -1) {
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
251 tableItems[i] = 0;-
252 QModelIndex idx = index(item);-
253 emit dataChanged(idx, idx);-
254 return;
never executed: return;
0
255 }-
256-
257 i = verticalHeaderItems.indexOf(item);-
258-
259 if (i != -1) {
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
260 verticalHeaderItems[i] = 0;-
261 emit headerDataChanged(Qt::Vertical, i, i);-
262 return;
never executed: return;
0
263 }-
264 i = horizontalHeaderItems.indexOf(item);-
265 if (i != -1) {
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
266 horizontalHeaderItems[i] = 0;-
267 emit headerDataChanged(Qt::Horizontal, i, i);-
268 return;
never executed: return;
0
269 }-
270}
never executed: end of block
0
271-
272void QTableModel::setHorizontalHeaderItem(int section, QTableWidgetItem *item)-
273{-
274 if (section < 0 || section >= horizontalHeaderItems.count())
section < 0Description
TRUEnever evaluated
FALSEnever evaluated
section >= hor...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
275 return;
never executed: return;
0
276 QTableWidgetItem *oldItem = horizontalHeaderItems.at(section);-
277 if (item == oldItem)
item == oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
278 return;
never executed: return;
0
279-
280 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
281 oldItem->view = 0;
never executed: oldItem->view = 0;
0
282 delete oldItem;-
283-
284 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent());-
285-
286 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
287 item->view = view;-
288 item->itemFlags = Qt::ItemFlags(int(item->itemFlags)|ItemIsHeaderItem);-
289 }
never executed: end of block
0
290 horizontalHeaderItems[section] = item;-
291 emit headerDataChanged(Qt::Horizontal, section, section);-
292}
never executed: end of block
0
293-
294void QTableModel::setVerticalHeaderItem(int section, QTableWidgetItem *item)-
295{-
296 if (section < 0 || section >= verticalHeaderItems.count())
section < 0Description
TRUEnever evaluated
FALSEnever evaluated
section >= ver...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
297 return;
never executed: return;
0
298 QTableWidgetItem *oldItem = verticalHeaderItems.at(section);-
299 if (item == oldItem)
item == oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
300 return;
never executed: return;
0
301-
302 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
303 oldItem->view = 0;
never executed: oldItem->view = 0;
0
304 delete oldItem;-
305-
306 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent());-
307-
308 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
309 item->view = view;-
310 item->itemFlags = Qt::ItemFlags(int(item->itemFlags)|ItemIsHeaderItem);-
311 }
never executed: end of block
0
312 verticalHeaderItems[section] = item;-
313 emit headerDataChanged(Qt::Vertical, section, section);-
314}
never executed: end of block
0
315-
316QTableWidgetItem *QTableModel::takeHorizontalHeaderItem(int section)-
317{-
318 if (section < 0 || section >= horizontalHeaderItems.count())
section < 0Description
TRUEnever evaluated
FALSEnever evaluated
section >= hor...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
319 return 0;
never executed: return 0;
0
320 QTableWidgetItem *itm = horizontalHeaderItems.at(section);-
321 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
322 itm->view = 0;-
323 itm->itemFlags &= ~ItemIsHeaderItem;-
324 horizontalHeaderItems[section] = 0;-
325 }
never executed: end of block
0
326 return itm;
never executed: return itm;
0
327}-
328-
329QTableWidgetItem *QTableModel::takeVerticalHeaderItem(int section)-
330{-
331 if (section < 0 || section >= verticalHeaderItems.count())
section < 0Description
TRUEnever evaluated
FALSEnever evaluated
section >= ver...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
332 return 0;
never executed: return 0;
0
333 QTableWidgetItem *itm = verticalHeaderItems.at(section);-
334 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
335 itm->view = 0;-
336 itm->itemFlags &= ~ItemIsHeaderItem;-
337 verticalHeaderItems[section] = 0;-
338 }
never executed: end of block
0
339 return itm;
never executed: return itm;
0
340}-
341-
342QTableWidgetItem *QTableModel::horizontalHeaderItem(int section)-
343{-
344 return horizontalHeaderItems.value(section);
never executed: return horizontalHeaderItems.value(section);
0
345}-
346-
347QTableWidgetItem *QTableModel::verticalHeaderItem(int section)-
348{-
349 return verticalHeaderItems.value(section);
never executed: return verticalHeaderItems.value(section);
0
350}-
351-
352QModelIndex QTableModel::index(const QTableWidgetItem *item) const-
353{-
354 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
355 return QModelIndex();
never executed: return QModelIndex();
0
356 int i = -1;-
357 const int id = item->d->id;-
358 if (id >= 0 && id < tableItems.count() && tableItems.at(id) == item) {
id >= 0Description
TRUEnever evaluated
FALSEnever evaluated
id < tableItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
tableItems.at(id) == itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
359 i = id;-
360 } else { // we need to search for the item
never executed: end of block
0
361 i = tableItems.indexOf(const_cast<QTableWidgetItem*>(item));-
362 if (i == -1) // not found
i == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
363 return QModelIndex();
never executed: return QModelIndex();
0
364 }
never executed: end of block
0
365 int row = i / columnCount();-
366 int col = i % columnCount();-
367 return QAbstractTableModel::index(row, col);
never executed: return QAbstractTableModel::index(row, col);
0
368}-
369-
370void QTableModel::setRowCount(int rows)-
371{-
372 int rc = verticalHeaderItems.count();-
373 if (rows < 0 || rc == rows)
rows < 0Description
TRUEnever evaluated
FALSEnever evaluated
rc == rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
374 return;
never executed: return;
0
375 if (rc < rows)
rc < rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
376 insertRows(qMax(rc, 0), rows - rc);
never executed: insertRows(qMax(rc, 0), rows - rc);
0
377 else-
378 removeRows(qMax(rows, 0), rc - rows);
never executed: removeRows(qMax(rows, 0), rc - rows);
0
379}-
380-
381void QTableModel::setColumnCount(int columns)-
382{-
383 int cc = horizontalHeaderItems.count();-
384 if (columns < 0 || cc == columns)
columns < 0Description
TRUEnever evaluated
FALSEnever evaluated
cc == columnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
385 return;
never executed: return;
0
386 if (cc < columns)
cc < columnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
387 insertColumns(qMax(cc, 0), columns - cc);
never executed: insertColumns(qMax(cc, 0), columns - cc);
0
388 else-
389 removeColumns(qMax(columns, 0), cc - columns);
never executed: removeColumns(qMax(columns, 0), cc - columns);
0
390}-
391-
392int QTableModel::rowCount(const QModelIndex &parent) const-
393{-
394 return parent.isValid() ? 0 : verticalHeaderItems.count();
never executed: return parent.isValid() ? 0 : verticalHeaderItems.count();
0
395}-
396-
397int QTableModel::columnCount(const QModelIndex &parent) const-
398{-
399 return parent.isValid() ? 0 : horizontalHeaderItems.count();
never executed: return parent.isValid() ? 0 : horizontalHeaderItems.count();
0
400}-
401-
402QVariant QTableModel::data(const QModelIndex &index, int role) const-
403{-
404 QTableWidgetItem *itm = item(index);-
405 if (itm)
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
406 return itm->data(role);
never executed: return itm->data(role);
0
407 return QVariant();
never executed: return QVariant();
0
408}-
409-
410bool QTableModel::setData(const QModelIndex &index, const QVariant &value, int role)-
411{-
412 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
413 return false;
never executed: return false;
0
414-
415 QTableWidgetItem *itm = item(index);-
416 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
417 itm->setData(role, value);-
418 return true;
never executed: return true;
0
419 }-
420-
421 // don't create dummy table items for empty values-
422 if (!value.isValid())
!value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
423 return false;
never executed: return false;
0
424-
425 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent());-
426 if (!view)
!viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
427 return false;
never executed: return false;
0
428-
429 itm = createItem();-
430 itm->setData(role, value);-
431 view->setItem(index.row(), index.column(), itm);-
432 return true;
never executed: return true;
0
433}-
434-
435QMap<int, QVariant> QTableModel::itemData(const QModelIndex &index) const-
436{-
437 QMap<int, QVariant> roles;-
438 QTableWidgetItem *itm = item(index);-
439 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
440 for (int i = 0; i < itm->values.count(); ++i) {
i < itm->values.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
441 roles.insert(itm->values.at(i).role,-
442 itm->values.at(i).value);-
443 }
never executed: end of block
0
444 }
never executed: end of block
0
445 return roles;
never executed: return roles;
0
446}-
447-
448// reimplemented to ensure that only one dataChanged() signal is emitted-
449bool QTableModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)-
450{-
451 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
452 return false;
never executed: return false;
0
453-
454 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent());-
455 QTableWidgetItem *itm = item(index);-
456 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
457 itm->view = 0; // prohibits item from calling itemChanged()-
458 bool changed = false;-
459 for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) {
it != roles.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
460 if (itm->data(it.key()) != it.value()) {
itm->data(it.k... != it.value()Description
TRUEnever evaluated
FALSEnever evaluated
0
461 itm->setData(it.key(), it.value());-
462 changed = true;-
463 }
never executed: end of block
0
464 }
never executed: end of block
0
465 itm->view = view;-
466 if (changed)
changedDescription
TRUEnever evaluated
FALSEnever evaluated
0
467 itemChanged(itm);
never executed: itemChanged(itm);
0
468 return true;
never executed: return true;
0
469 }-
470-
471 if (!view)
!viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
472 return false;
never executed: return false;
0
473-
474 itm = createItem();-
475 for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it)
it != roles.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
476 itm->setData(it.key(), it.value());
never executed: itm->setData(it.key(), it.value());
0
477 view->setItem(index.row(), index.column(), itm);-
478 return true;
never executed: return true;
0
479}-
480-
481Qt::ItemFlags QTableModel::flags(const QModelIndex &index) const-
482{-
483 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
484 return Qt::ItemIsDropEnabled;
never executed: return Qt::ItemIsDropEnabled;
0
485 if (QTableWidgetItem *itm = item(index))
QTableWidgetIt... = item(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
486 return itm->flags();
never executed: return itm->flags();
0
487 return (Qt::ItemIsEditable
never executed: return (Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled);
0
488 |Qt::ItemIsSelectable
never executed: return (Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled);
0
489 |Qt::ItemIsUserCheckable
never executed: return (Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled);
0
490 |Qt::ItemIsEnabled
never executed: return (Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled);
0
491 |Qt::ItemIsDragEnabled
never executed: return (Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled);
0
492 |Qt::ItemIsDropEnabled);
never executed: return (Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled);
0
493}-
494-
495void QTableModel::sort(int column, Qt::SortOrder order)-
496{-
497 QVector<QPair<QTableWidgetItem*, int> > sortable;-
498 QVector<int> unsortable;-
499-
500 sortable.reserve(rowCount());-
501 unsortable.reserve(rowCount());-
502-
503 for (int row = 0; row < rowCount(); ++row) {
row < rowCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
504 if (QTableWidgetItem *itm = item(row, column))
QTableWidgetIt...m(row, column)Description
TRUEnever evaluated
FALSEnever evaluated
0
505 sortable.append(QPair<QTableWidgetItem*,int>(itm, row));
never executed: sortable.append(QPair<QTableWidgetItem*,int>(itm, row));
0
506 else-
507 unsortable.append(row);
never executed: unsortable.append(row);
0
508 }-
509-
510 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
order == Qt::AscendingOrderDescription
TRUEnever evaluated
FALSEnever evaluated
0
511 std::stable_sort(sortable.begin(), sortable.end(), compare);-
512-
513 QVector<QTableWidgetItem*> sorted_table(tableItems.count());-
514 QModelIndexList from;-
515 QModelIndexList to;-
516 const int numRows = rowCount();-
517 const int numColumns = columnCount();-
518 from.reserve(numRows * numColumns);-
519 to.reserve(numRows * numColumns);-
520 for (int i = 0; i < numRows; ++i) {
i < numRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
521 int r = (i < sortable.count()
i < sortable.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
522 ? sortable.at(i).second-
523 : unsortable.at(i - sortable.count()));-
524 for (int c = 0; c < numColumns; ++c) {
c < numColumnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
525 sorted_table[tableIndex(i, c)] = item(r, c);-
526 from.append(createIndex(r, c));-
527 to.append(createIndex(i, c));-
528 }
never executed: end of block
0
529 }
never executed: end of block
0
530-
531 emit layoutAboutToBeChanged();-
532-
533 tableItems = sorted_table;-
534 changePersistentIndexList(from, to); // ### slow-
535-
536 emit layoutChanged();-
537}
never executed: end of block
0
538-
539/*-
540 \internal-
541-
542 Ensures that rows in the interval [start, end] are-
543 sorted according to the contents of column \a column-
544 and the given sort \a order.-
545*/-
546void QTableModel::ensureSorted(int column, Qt::SortOrder order,-
547 int start, int end)-
548{-
549 int count = end - start + 1;-
550 QVector < QPair<QTableWidgetItem*,int> > sorting;-
551 sorting.reserve(count);-
552 for (int row = start; row <= end; ++row) {
row <= endDescription
TRUEnever evaluated
FALSEnever evaluated
0
553 QTableWidgetItem *itm = item(row, column);-
554 if (itm == 0) {
itm == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
555 // no more sortable items (all 0-items are-
556 // at the end of the table when it is sorted)-
557 break;
never executed: break;
0
558 }-
559 sorting.append(QPair<QTableWidgetItem*,int>(itm, row));-
560 }
never executed: end of block
0
561-
562 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
order == Qt::AscendingOrderDescription
TRUEnever evaluated
FALSEnever evaluated
0
563 std::stable_sort(sorting.begin(), sorting.end(), compare);-
564 QModelIndexList oldPersistentIndexes, newPersistentIndexes;-
565 QVector<QTableWidgetItem*> newTable = tableItems;-
566 QVector<QTableWidgetItem*> newVertical = verticalHeaderItems;-
567 QVector<QTableWidgetItem*> colItems = columnItems(column);-
568 QVector<QTableWidgetItem*>::iterator vit = colItems.begin();-
569 bool changed = false;-
570 for (int i = 0; i < sorting.count(); ++i) {
i < sorting.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
571 int oldRow = sorting.at(i).second;-
572 QTableWidgetItem *item = colItems.at(oldRow);-
573 colItems.remove(oldRow);-
574 vit = sortedInsertionIterator(vit, colItems.end(), order, item);-
575 int newRow = qMax((int)(vit - colItems.begin()), 0);-
576 if ((newRow < oldRow) && !(*item < *colItems.at(oldRow - 1)) && !(*colItems.at(oldRow - 1) < *item))
(newRow < oldRow)Description
TRUEnever evaluated
FALSEnever evaluated
!(*item < *col...t(oldRow - 1))Description
TRUEnever evaluated
FALSEnever evaluated
!(*colItems.at... - 1) < *item)Description
TRUEnever evaluated
FALSEnever evaluated
0
577 newRow = oldRow;
never executed: newRow = oldRow;
0
578 vit = colItems.insert(vit, item);-
579 if (newRow != oldRow) {
newRow != oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
580 if (!changed) {
!changedDescription
TRUEnever evaluated
FALSEnever evaluated
0
581 emit layoutAboutToBeChanged();-
582 oldPersistentIndexes = persistentIndexList();-
583 newPersistentIndexes = oldPersistentIndexes;-
584 changed = true;-
585 }
never executed: end of block
0
586 // move the items @ oldRow to newRow-
587 int cc = columnCount();-
588 QVector<QTableWidgetItem*> rowItems(cc);-
589 for (int j = 0; j < cc; ++j)
j < ccDescription
TRUEnever evaluated
FALSEnever evaluated
0
590 rowItems[j] = newTable.at(tableIndex(oldRow, j));
never executed: rowItems[j] = newTable.at(tableIndex(oldRow, j));
0
591 newTable.remove(tableIndex(oldRow, 0), cc);-
592 newTable.insert(tableIndex(newRow, 0), cc, 0);-
593 for (int j = 0; j < cc; ++j)
j < ccDescription
TRUEnever evaluated
FALSEnever evaluated
0
594 newTable[tableIndex(newRow, j)] = rowItems.at(j);
never executed: newTable[tableIndex(newRow, j)] = rowItems.at(j);
0
595 QTableWidgetItem *header = newVertical.at(oldRow);-
596 newVertical.remove(oldRow);-
597 newVertical.insert(newRow, header);-
598 // update persistent indexes-
599 updateRowIndexes(newPersistentIndexes, oldRow, newRow);-
600 // the index of the remaining rows may have changed-
601 for (int j = i + 1; j < sorting.count(); ++j) {
j < sorting.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
602 int otherRow = sorting.at(j).second;-
603 if (oldRow < otherRow && newRow >= otherRow)
oldRow < otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
newRow >= otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
604 --sorting[j].second;
never executed: --sorting[j].second;
0
605 else if (oldRow > otherRow && newRow <= otherRow)
oldRow > otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
newRow <= otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
606 ++sorting[j].second;
never executed: ++sorting[j].second;
0
607 }
never executed: end of block
0
608 }
never executed: end of block
0
609 }
never executed: end of block
0
610-
611 if (changed) {
changedDescription
TRUEnever evaluated
FALSEnever evaluated
0
612 tableItems = newTable;-
613 verticalHeaderItems = newVertical;-
614 changePersistentIndexList(oldPersistentIndexes,-
615 newPersistentIndexes);-
616 emit layoutChanged();-
617 }
never executed: end of block
0
618}
never executed: end of block
0
619-
620/*-
621 \internal-
622-
623 Returns the non-0 items in column \a column.-
624*/-
625QVector<QTableWidgetItem*> QTableModel::columnItems(int column) const-
626{-
627 QVector<QTableWidgetItem*> items;-
628 int rc = rowCount();-
629 items.reserve(rc);-
630 for (int row = 0; row < rc; ++row) {
row < rcDescription
TRUEnever evaluated
FALSEnever evaluated
0
631 QTableWidgetItem *itm = item(row, column);-
632 if (itm == 0) {
itm == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
633 // no more sortable items (all 0-items are-
634 // at the end of the table when it is sorted)-
635 break;
never executed: break;
0
636 }-
637 items.append(itm);-
638 }
never executed: end of block
0
639 return items;
never executed: return items;
0
640}-
641-
642/*-
643 \internal-
644-
645 Adjusts the row of each index in \a indexes if necessary, given-
646 that a row of items has been moved from row \a movedFrom to row-
647 \a movedTo.-
648*/-
649void QTableModel::updateRowIndexes(QModelIndexList &indexes,-
650 int movedFromRow, int movedToRow)-
651{-
652 QModelIndexList::iterator it;-
653 for (it = indexes.begin(); it != indexes.end(); ++it) {
it != indexes.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
654 int oldRow = (*it).row();-
655 int newRow = oldRow;-
656 if (oldRow == movedFromRow)
oldRow == movedFromRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
657 newRow = movedToRow;
never executed: newRow = movedToRow;
0
658 else if (movedFromRow < oldRow && movedToRow >= oldRow)
movedFromRow < oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
movedToRow >= oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
659 newRow = oldRow - 1;
never executed: newRow = oldRow - 1;
0
660 else if (movedFromRow > oldRow && movedToRow <= oldRow)
movedFromRow > oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
movedToRow <= oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
661 newRow = oldRow + 1;
never executed: newRow = oldRow + 1;
0
662 if (newRow != oldRow)
newRow != oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
663 *it = index(newRow, (*it).column(), (*it).parent());
never executed: *it = index(newRow, (*it).column(), (*it).parent());
0
664 }
never executed: end of block
0
665}
never executed: end of block
0
666-
667/*-
668 \internal-
669-
670 Returns an iterator to the item where \a item should be-
671 inserted in the interval (\a begin, \a end) according to-
672 the given sort \a order.-
673*/-
674QVector<QTableWidgetItem*>::iterator QTableModel::sortedInsertionIterator(-
675 const QVector<QTableWidgetItem*>::iterator &begin,-
676 const QVector<QTableWidgetItem*>::iterator &end,-
677 Qt::SortOrder order, QTableWidgetItem *item)-
678{-
679 if (order == Qt::AscendingOrder)
order == Qt::AscendingOrderDescription
TRUEnever evaluated
FALSEnever evaluated
0
680 return std::lower_bound(begin, end, item, QTableModelLessThan());
never executed: return std::lower_bound(begin, end, item, QTableModelLessThan());
0
681 return std::lower_bound(begin, end, item, QTableModelGreaterThan());
never executed: return std::lower_bound(begin, end, item, QTableModelGreaterThan());
0
682}-
683-
684bool QTableModel::itemLessThan(const QPair<QTableWidgetItem*,int> &left,-
685 const QPair<QTableWidgetItem*,int> &right)-
686{-
687 return *(left.first) < *(right.first);
never executed: return *(left.first) < *(right.first);
0
688}-
689-
690bool QTableModel::itemGreaterThan(const QPair<QTableWidgetItem*,int> &left,-
691 const QPair<QTableWidgetItem*,int> &right)-
692{-
693 return (*(right.first) < *(left .first));
never executed: return (*(right.first) < *(left .first));
0
694}-
695-
696QVariant QTableModel::headerData(int section, Qt::Orientation orientation, int role) const-
697{-
698 if (section < 0)
section < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
699 return QVariant();
never executed: return QVariant();
0
700-
701 QTableWidgetItem *itm = 0;-
702 if (orientation == Qt::Horizontal && section < horizontalHeaderItems.count())
orientation == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
section < hori...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
703 itm = horizontalHeaderItems.at(section);
never executed: itm = horizontalHeaderItems.at(section);
0
704 else if (orientation == Qt::Vertical && section < verticalHeaderItems.count())
orientation == Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
section < vert...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
705 itm = verticalHeaderItems.at(section);
never executed: itm = verticalHeaderItems.at(section);
0
706 else-
707 return QVariant(); // section is out of bounds
never executed: return QVariant();
0
708-
709 if (itm)
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
710 return itm->data(role);
never executed: return itm->data(role);
0
711 if (role == Qt::DisplayRole)
role == Qt::DisplayRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
712 return section + 1;
never executed: return section + 1;
0
713 return QVariant();
never executed: return QVariant();
0
714}-
715-
716bool QTableModel::setHeaderData(int section, Qt::Orientation orientation,-
717 const QVariant &value, int role)-
718{-
719 if (section < 0 ||
section < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
720 (orientation == Qt::Horizontal && horizontalHeaderItems.size() <= section) ||
orientation == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
horizontalHead...e() <= sectionDescription
TRUEnever evaluated
FALSEnever evaluated
0
721 (orientation == Qt::Vertical && verticalHeaderItems.size() <= section))
orientation == Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
verticalHeader...e() <= sectionDescription
TRUEnever evaluated
FALSEnever evaluated
0
722 return false;
never executed: return false;
0
723-
724 QTableWidgetItem *itm = 0;-
725 if (orientation == Qt::Horizontal)
orientation == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
726 itm = horizontalHeaderItems.at(section);
never executed: itm = horizontalHeaderItems.at(section);
0
727 else-
728 itm = verticalHeaderItems.at(section);
never executed: itm = verticalHeaderItems.at(section);
0
729 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
730 itm->setData(role, value);-
731 return true;
never executed: return true;
0
732 }-
733 return false;
never executed: return false;
0
734}-
735-
736bool QTableModel::isValid(const QModelIndex &index) const-
737{-
738 return (index.isValid()
never executed: return (index.isValid() && index.row() < verticalHeaderItems.count() && index.column() < horizontalHeaderItems.count());
0
739 && index.row() < verticalHeaderItems.count()
never executed: return (index.isValid() && index.row() < verticalHeaderItems.count() && index.column() < horizontalHeaderItems.count());
0
740 && index.column() < horizontalHeaderItems.count());
never executed: return (index.isValid() && index.row() < verticalHeaderItems.count() && index.column() < horizontalHeaderItems.count());
0
741}-
742-
743void QTableModel::clear()-
744{-
745 for (int j = 0; j < verticalHeaderItems.count(); ++j) {
j < verticalHe...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
746 if (verticalHeaderItems.at(j)) {
verticalHeaderItems.at(j)Description
TRUEnever evaluated
FALSEnever evaluated
0
747 verticalHeaderItems.at(j)->view = 0;-
748 delete verticalHeaderItems.at(j);-
749 verticalHeaderItems[j] = 0;-
750 }
never executed: end of block
0
751 }
never executed: end of block
0
752 for (int k = 0; k < horizontalHeaderItems.count(); ++k) {
k < horizontal...rItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
753 if (horizontalHeaderItems.at(k)) {
horizontalHeaderItems.at(k)Description
TRUEnever evaluated
FALSEnever evaluated
0
754 horizontalHeaderItems.at(k)->view = 0;-
755 delete horizontalHeaderItems.at(k);-
756 horizontalHeaderItems[k] = 0;-
757 }
never executed: end of block
0
758 }
never executed: end of block
0
759 clearContents();-
760}
never executed: end of block
0
761-
762void QTableModel::clearContents()-
763{-
764 beginResetModel();-
765 for (int i = 0; i < tableItems.count(); ++i) {
i < tableItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
766 if (tableItems.at(i)) {
tableItems.at(i)Description
TRUEnever evaluated
FALSEnever evaluated
0
767 tableItems.at(i)->view = 0;-
768 delete tableItems.at(i);-
769 tableItems[i] = 0;-
770 }
never executed: end of block
0
771 }
never executed: end of block
0
772 endResetModel();-
773}
never executed: end of block
0
774-
775void QTableModel::itemChanged(QTableWidgetItem *item)-
776{-
777 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
778 return;
never executed: return;
0
779 if (item->flags() & ItemIsHeaderItem) {
item->flags() ...emIsHeaderItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
780 int row = verticalHeaderItems.indexOf(item);-
781 if (row >= 0) {
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
782 emit headerDataChanged(Qt::Vertical, row, row);-
783 } else {
never executed: end of block
0
784 int column = horizontalHeaderItems.indexOf(item);-
785 if (column >= 0)
column >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
786 emit headerDataChanged(Qt::Horizontal, column, column);
never executed: headerDataChanged(Qt::Horizontal, column, column);
0
787 }
never executed: end of block
0
788 } else {-
789 QModelIndex idx = index(item);-
790 if (idx.isValid())
idx.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
791 emit dataChanged(idx, idx);
never executed: dataChanged(idx, idx);
0
792 }
never executed: end of block
0
793}-
794-
795QTableWidgetItem* QTableModel::createItem() const-
796{-
797 return prototype ? prototype->clone() : new QTableWidgetItem;
never executed: return prototype ? prototype->clone() : new QTableWidgetItem;
0
798}-
799-
800const QTableWidgetItem *QTableModel::itemPrototype() const-
801{-
802 return prototype;
never executed: return prototype;
0
803}-
804-
805void QTableModel::setItemPrototype(const QTableWidgetItem *item)-
806{-
807 if (prototype != item) {
prototype != itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
808 delete prototype;-
809 prototype = item;-
810 }
never executed: end of block
0
811}
never executed: end of block
0
812-
813QStringList QTableModel::mimeTypes() const-
814{-
815 const QTableWidget *view = qobject_cast<const QTableWidget*>(QObject::parent());-
816 return (view ? view->mimeTypes() : QStringList());
never executed: return (view ? view->mimeTypes() : QStringList());
0
817}-
818-
819QMimeData *QTableModel::internalMimeData() const-
820{-
821 return QAbstractTableModel::mimeData(cachedIndexes);
never executed: return QAbstractTableModel::mimeData(cachedIndexes);
0
822}-
823-
824QMimeData *QTableModel::mimeData(const QModelIndexList &indexes) const-
825{-
826 QList<QTableWidgetItem*> items;-
827 const int indexesCount = indexes.count();-
828 items.reserve(indexesCount);-
829 for (int i = 0; i < indexesCount; ++i)
i < indexesCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
830 items << item(indexes.at(i));
never executed: items << item(indexes.at(i));
0
831 const QTableWidget *view = qobject_cast<const QTableWidget*>(QObject::parent());-
832-
833 // cachedIndexes is a little hack to avoid copying from QModelIndexList to-
834 // QList<QTreeWidgetItem*> and back again in the view-
835 cachedIndexes = indexes;-
836 QMimeData *mimeData = (view ? view->mimeData(items) : 0);
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
837 cachedIndexes.clear();-
838 return mimeData;
never executed: return mimeData;
0
839}-
840-
841bool QTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action,-
842 int row , int column, const QModelIndex &index)-
843{-
844 if (index.isValid()) {
index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
845 row = index.row();-
846 column = index.column();-
847 }else if (row == -1 || column == -1) { // The user dropped outside the table.
never executed: end of block
row == -1Description
TRUEnever evaluated
FALSEnever evaluated
column == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
848 row = rowCount();-
849 column = 0;-
850 }
never executed: end of block
0
851-
852 QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent());-
853 return (view ? view->dropMimeData(row, column, data, action) : false);
never executed: return (view ? view->dropMimeData(row, column, data, action) : false);
0
854}-
855-
856Qt::DropActions QTableModel::supportedDropActions() const-
857{-
858 const QTableWidget *view = qobject_cast<const QTableWidget*>(QObject::parent());-
859 return (view ? view->supportedDropActions() : Qt::DropActions(Qt::IgnoreAction));
never executed: return (view ? view->supportedDropActions() : Qt::DropActions(Qt::IgnoreAction));
0
860}-
861-
862/*!-
863 \class QTableWidgetSelectionRange-
864-
865 \brief The QTableWidgetSelectionRange class provides a way to interact with-
866 selection in a model without using model indexes and a selection model.-
867-
868 \ingroup model-view-
869 \inmodule QtWidgets-
870-
871 The QTableWidgetSelectionRange class stores the top left and bottom-
872 right rows and columns of a selection range in a table. The-
873 selections in the table may consist of several selection ranges.-
874-
875 \note If the item within the selection range is marked as not selectable,-
876 e.g., \c{itemFlags() & Qt::ItemIsSelectable == 0} then it will not appear-
877 in the selection range.-
878-
879 \sa QTableWidget-
880*/-
881-
882/*!-
883 Constructs an table selection range, i.e. a range-
884 whose rowCount() and columnCount() are 0.-
885*/-
886QTableWidgetSelectionRange::QTableWidgetSelectionRange()-
887 : top(-1), left(-1), bottom(-2), right(-2)-
888{-
889}
never executed: end of block
0
890-
891/*!-
892 Constructs the table selection range from the given \a top, \a-
893 left, \a bottom and \a right table rows and columns.-
894-
895 \sa topRow(), leftColumn(), bottomRow(), rightColumn()-
896*/-
897QTableWidgetSelectionRange::QTableWidgetSelectionRange(int top, int left, int bottom, int right)-
898 : top(top), left(left), bottom(bottom), right(right)-
899{-
900}
never executed: end of block
0
901-
902/*!-
903 Constructs a the table selection range by copying the given \a-
904 other table selection range.-
905*/-
906QTableWidgetSelectionRange::QTableWidgetSelectionRange(const QTableWidgetSelectionRange &other)-
907 : top(other.top), left(other.left), bottom(other.bottom), right(other.right)-
908{-
909}
never executed: end of block
0
910-
911/*!-
912 Destroys the table selection range.-
913*/-
914QTableWidgetSelectionRange::~QTableWidgetSelectionRange()-
915{-
916}-
917-
918/*!-
919 \fn int QTableWidgetSelectionRange::topRow() const-
920-
921 Returns the top row of the range.-
922-
923 \sa bottomRow(), leftColumn(), rowCount()-
924*/-
925-
926/*!-
927 \fn int QTableWidgetSelectionRange::bottomRow() const-
928-
929 Returns the bottom row of the range.-
930-
931 \sa topRow(), rightColumn(), rowCount()-
932*/-
933-
934/*!-
935 \fn int QTableWidgetSelectionRange::leftColumn() const-
936-
937 Returns the left column of the range.-
938-
939 \sa rightColumn(), topRow(), columnCount()-
940*/-
941-
942/*!-
943 \fn int QTableWidgetSelectionRange::rightColumn() const-
944-
945 Returns the right column of the range.-
946-
947 \sa leftColumn(), bottomRow(), columnCount()-
948*/-
949-
950/*!-
951 \since 4.1-
952 \fn int QTableWidgetSelectionRange::rowCount() const-
953-
954 Returns the number of rows in the range.-
955-
956 This is equivalent to bottomRow() - topRow() + 1.-
957-
958 \sa columnCount(), topRow(), bottomRow()-
959*/-
960-
961/*!-
962 \since 4.1-
963 \fn int QTableWidgetSelectionRange::columnCount() const-
964-
965 Returns the number of columns in the range.-
966-
967 This is equivalent to rightColumn() - leftColumn() + 1.-
968-
969 \sa rowCount(), leftColumn(), rightColumn()-
970*/-
971-
972/*!-
973 \class QTableWidgetItem-
974 \brief The QTableWidgetItem class provides an item for use with the-
975 QTableWidget class.-
976-
977 \ingroup model-view-
978 \inmodule QtWidgets-
979-
980 Table items are used to hold pieces of information for table widgets.-
981 Items usually contain text, icons, or checkboxes-
982-
983 The QTableWidgetItem class is a convenience class that replaces the-
984 \c QTableItem class in Qt 3. It provides an item for use with-
985 the QTableWidget class.-
986-
987 Top-level items are constructed without a parent then inserted at the-
988 position specified by a pair of row and column numbers:-
989-
990 \snippet qtablewidget-using/mainwindow.cpp 3-
991-
992 Each item can have its own background brush which is set with-
993 the setBackground() function. The current background brush can be-
994 found with background().-
995 The text label for each item can be rendered with its own font and brush.-
996 These are specified with the setFont() and setForeground() functions,-
997 and read with font() and foreground().-
998-
999 By default, items are enabled, editable, selectable, checkable, and can be-
1000 used both as the source of a drag and drop operation and as a drop target.-
1001 Each item's flags can be changed by calling setFlags() with the appropriate-
1002 value (see \l{Qt::ItemFlags}). Checkable items can be checked and unchecked-
1003 with the setCheckState() function. The corresponding checkState() function-
1004 indicates whether the item is currently checked.-
1005-
1006 \section1 Subclassing-
1007-
1008 When subclassing QTableWidgetItem to provide custom items, it is possible to-
1009 define new types for them so that they can be distinguished from standard-
1010 items. The constructors for subclasses that require this feature need to-
1011 call the base class constructor with a new type value equal to or greater-
1012 than \l UserType.-
1013-
1014 \sa QTableWidget, {Model/View Programming}, QListWidgetItem, QTreeWidgetItem-
1015*/-
1016-
1017/*!-
1018 \fn int QTableWidgetItem::row() const-
1019 \since 4.2-
1020-
1021 Returns the row of the item in the table.-
1022 If the item is not in a table, this function will return -1.-
1023-
1024 \sa column()-
1025*/-
1026-
1027/*!-
1028 \fn int QTableWidgetItem::column() const-
1029 \since 4.2-
1030-
1031 Returns the column of the item in the table.-
1032 If the item is not in a table, this function will return -1.-
1033-
1034 \sa row()-
1035*/-
1036-
1037/*!-
1038 \fn void QTableWidgetItem::setSelected(bool select)-
1039 \since 4.2-
1040-
1041 Sets the selected state of the item to \a select.-
1042-
1043 \sa isSelected()-
1044*/-
1045-
1046/*!-
1047 \fn bool QTableWidgetItem::isSelected() const-
1048 \since 4.2-
1049-
1050 Returns \c true if the item is selected, otherwise returns \c false.-
1051-
1052 \sa setSelected()-
1053*/-
1054-
1055/*!-
1056 \fn QSize QTableWidgetItem::sizeHint() const-
1057 \since 4.1-
1058-
1059 Returns the size hint set for the table item.-
1060*/-
1061-
1062/*!-
1063 \fn void QTableWidgetItem::setSizeHint(const QSize &size)-
1064 \since 4.1-
1065-
1066 Sets the size hint for the table item to be \a size.-
1067 If no size hint is set, the item delegate will compute the-
1068 size hint based on the item data.-
1069*/-
1070-
1071/*!-
1072 \fn Qt::CheckState QTableWidgetItem::checkState() const-
1073-
1074 Returns the checked state of the table item.-
1075-
1076 \sa flags()-
1077*/-
1078-
1079/*!-
1080 \fn void QTableWidgetItem::setCheckState(Qt::CheckState state)-
1081-
1082 Sets the check state of the table item to be \a state.-
1083*/-
1084-
1085/*!-
1086 \fn QTableWidget *QTableWidgetItem::tableWidget() const-
1087-
1088 Returns the table widget that contains the item.-
1089*/-
1090-
1091/*!-
1092 \fn Qt::ItemFlags QTableWidgetItem::flags() const-
1093-
1094 Returns the flags used to describe the item. These determine whether-
1095 the item can be checked, edited, and selected.-
1096-
1097 \sa setFlags()-
1098*/-
1099-
1100/*!-
1101 \fn void QTableWidgetItem::setFlags(Qt::ItemFlags flags)-
1102-
1103 Sets the flags for the item to the given \a flags. These determine whether-
1104 the item can be selected or modified.-
1105-
1106 \sa flags()-
1107*/-
1108void QTableWidgetItem::setFlags(Qt::ItemFlags aflags)-
1109{-
1110 itemFlags = aflags;-
1111 if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0))
QTableModel *m...>model()) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1112 model->itemChanged(this);
never executed: model->itemChanged(this);
0
1113}
never executed: end of block
0
1114-
1115-
1116/*!-
1117 \fn QString QTableWidgetItem::text() const-
1118-
1119 Returns the item's text.-
1120-
1121 \sa setText()-
1122*/-
1123-
1124/*!-
1125 \fn void QTableWidgetItem::setText(const QString &text)-
1126-
1127 Sets the item's text to the \a text specified.-
1128-
1129 \sa text(), setFont(), setForeground()-
1130*/-
1131-
1132/*!-
1133 \fn QIcon QTableWidgetItem::icon() const-
1134-
1135 Returns the item's icon.-
1136-
1137 \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}-
1138*/-
1139-
1140/*!-
1141 \fn void QTableWidgetItem::setIcon(const QIcon &icon)-
1142-
1143 Sets the item's icon to the \a icon specified.-
1144-
1145 \sa icon(), setText(), {QAbstractItemView::iconSize}{iconSize}-
1146*/-
1147-
1148/*!-
1149 \fn QString QTableWidgetItem::statusTip() const-
1150-
1151 Returns the item's status tip.-
1152-
1153 \sa setStatusTip()-
1154*/-
1155-
1156/*!-
1157 \fn void QTableWidgetItem::setStatusTip(const QString &statusTip)-
1158-
1159 Sets the status tip for the table item to the text specified by-
1160 \a statusTip. QTableWidget mouse tracking needs to be enabled for this-
1161 feature to work.-
1162-
1163 \sa statusTip(), setToolTip(), setWhatsThis()-
1164*/-
1165-
1166/*!-
1167 \fn QString QTableWidgetItem::toolTip() const-
1168-
1169 Returns the item's tooltip.-
1170-
1171 \sa setToolTip()-
1172*/-
1173-
1174/*!-
1175 \fn void QTableWidgetItem::setToolTip(const QString &toolTip)-
1176-
1177 Sets the item's tooltip to the string specified by \a toolTip.-
1178-
1179 \sa toolTip(), setStatusTip(), setWhatsThis()-
1180*/-
1181-
1182/*!-
1183 \fn QString QTableWidgetItem::whatsThis() const-
1184-
1185 Returns the item's "What's This?" help.-
1186-
1187 \sa setWhatsThis()-
1188*/-
1189-
1190/*!-
1191 \fn void QTableWidgetItem::setWhatsThis(const QString &whatsThis)-
1192-
1193 Sets the item's "What's This?" help to the string specified by \a whatsThis.-
1194-
1195 \sa whatsThis(), setStatusTip(), setToolTip()-
1196*/-
1197-
1198/*!-
1199 \fn QFont QTableWidgetItem::font() const-
1200-
1201 Returns the font used to render the item's text.-
1202-
1203 \sa setFont()-
1204*/-
1205-
1206/*!-
1207 \fn void QTableWidgetItem::setFont(const QFont &font)-
1208-
1209 Sets the font used to display the item's text to the given \a font.-
1210-
1211 \sa font(), setText(), setForeground()-
1212*/-
1213-
1214/*!-
1215 \fn QColor QTableWidgetItem::backgroundColor() const-
1216 \obsolete-
1217-
1218 This function is deprecated. Use background() instead.-
1219*/-
1220-
1221/*!-
1222 \fn void QTableWidgetItem::setBackgroundColor(const QColor &color)-
1223 \obsolete-
1224-
1225 This function is deprecated. Use setBackground() instead.-
1226*/-
1227-
1228/*!-
1229 \fn QBrush QTableWidgetItem::background() const-
1230 \since 4.2-
1231-
1232 Returns the brush used to render the item's background.-
1233-
1234 \sa foreground()-
1235*/-
1236-
1237/*!-
1238 \fn void QTableWidgetItem::setBackground(const QBrush &brush)-
1239 \since 4.2-
1240-
1241 Sets the item's background brush to the specified \a brush.-
1242-
1243 \sa setForeground()-
1244*/-
1245-
1246/*!-
1247 \fn QColor QTableWidgetItem::textColor() const-
1248 \obsolete-
1249-
1250 This function is deprecated. Use foreground() instead.-
1251*/-
1252-
1253/*!-
1254 \fn void QTableWidgetItem::setTextColor(const QColor &color)-
1255 \obsolete-
1256-
1257 This function is deprecated. Use setForeground() instead.-
1258*/-
1259-
1260/*!-
1261 \fn QBrush QTableWidgetItem::foreground() const-
1262 \since 4.2-
1263-
1264 Returns the brush used to render the item's foreground (e.g. text).-
1265-
1266 \sa background()-
1267*/-
1268-
1269/*!-
1270 \fn void QTableWidgetItem::setForeground(const QBrush &brush)-
1271 \since 4.2-
1272-
1273 Sets the item's foreground brush to the specified \a brush.-
1274-
1275 \sa setBackground()-
1276*/-
1277-
1278/*!-
1279 \fn int QTableWidgetItem::textAlignment() const-
1280-
1281 Returns the text alignment for the item's text.-
1282-
1283 \sa Qt::Alignment-
1284*/-
1285-
1286/*!-
1287 \fn void QTableWidgetItem::setTextAlignment(int alignment)-
1288-
1289 Sets the text alignment for the item's text to the \a alignment-
1290 specified.-
1291-
1292 \sa Qt::Alignment-
1293*/-
1294-
1295/*!-
1296 Constructs a table item of the specified \a type that does not belong-
1297 to any table.-
1298-
1299 \sa type()-
1300*/-
1301QTableWidgetItem::QTableWidgetItem(int type)-
1302 : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)),-
1303 itemFlags(Qt::ItemIsEditable-
1304 |Qt::ItemIsSelectable-
1305 |Qt::ItemIsUserCheckable-
1306 |Qt::ItemIsEnabled-
1307 |Qt::ItemIsDragEnabled-
1308 |Qt::ItemIsDropEnabled)-
1309{-
1310}
never executed: end of block
0
1311-
1312/*!-
1313 Constructs a table item with the given \a text.-
1314-
1315 \sa type()-
1316*/-
1317QTableWidgetItem::QTableWidgetItem(const QString &text, int type)-
1318 : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)),-
1319 itemFlags(Qt::ItemIsEditable-
1320 |Qt::ItemIsSelectable-
1321 |Qt::ItemIsUserCheckable-
1322 |Qt::ItemIsEnabled-
1323 |Qt::ItemIsDragEnabled-
1324 |Qt::ItemIsDropEnabled)-
1325{-
1326 setData(Qt::DisplayRole, text);-
1327}
never executed: end of block
0
1328-
1329/*!-
1330 Constructs a table item with the given \a icon and \a text.-
1331-
1332 \sa type()-
1333*/-
1334QTableWidgetItem::QTableWidgetItem(const QIcon &icon, const QString &text, int type)-
1335 : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)),-
1336 itemFlags(Qt::ItemIsEditable-
1337 |Qt::ItemIsSelectable-
1338 |Qt::ItemIsUserCheckable-
1339 |Qt::ItemIsEnabled-
1340 |Qt::ItemIsDragEnabled-
1341 |Qt::ItemIsDropEnabled)-
1342{-
1343 setData(Qt::DecorationRole, icon);-
1344 setData(Qt::DisplayRole, text);-
1345}
never executed: end of block
0
1346-
1347/*!-
1348 Destroys the table item.-
1349*/-
1350QTableWidgetItem::~QTableWidgetItem()-
1351{-
1352 if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0))
QTableModel *m...>model()) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1353 model->removeItem(this);
never executed: model->removeItem(this);
0
1354 view = 0;-
1355 delete d;-
1356}
never executed: end of block
0
1357-
1358/*!-
1359 Creates a copy of the item.-
1360*/-
1361QTableWidgetItem *QTableWidgetItem::clone() const-
1362{-
1363 return new QTableWidgetItem(*this);
never executed: return new QTableWidgetItem(*this);
0
1364}-
1365-
1366/*!-
1367 Sets the item's data for the given \a role to the specified \a value.-
1368-
1369 \sa Qt::ItemDataRole, data()-
1370*/-
1371void QTableWidgetItem::setData(int role, const QVariant &value)-
1372{-
1373 bool found = false;-
1374 role = (role == Qt::EditRole ? Qt::DisplayRole : role);
role == Qt::EditRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1375 for (int i = 0; i < values.count(); ++i) {
i < values.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1376 if (values.at(i).role == role) {
values.at(i).role == roleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1377 if (values[i].value == value)
values[i].value == valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
1378 return;
never executed: return;
0
1379-
1380 values[i].value = value;-
1381 found = true;-
1382 break;
never executed: break;
0
1383 }-
1384 }
never executed: end of block
0
1385 if (!found)
!foundDescription
TRUEnever evaluated
FALSEnever evaluated
0
1386 values.append(QWidgetItemData(role, value));
never executed: values.append(QWidgetItemData(role, value));
0
1387 if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0))
QTableModel *m...>model()) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1388 model->itemChanged(this);
never executed: model->itemChanged(this);
0
1389}
never executed: end of block
0
1390-
1391/*!-
1392 Returns the item's data for the given \a role.-
1393*/-
1394QVariant QTableWidgetItem::data(int role) const-
1395{-
1396 role = (role == Qt::EditRole ? Qt::DisplayRole : role);
role == Qt::EditRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1397 for (const auto &value : values) {-
1398 if (value.role == role)
value.role == roleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1399 return value.value;
never executed: return value.value;
0
1400 }
never executed: end of block
0
1401 return QVariant();
never executed: return QVariant();
0
1402}-
1403-
1404/*!-
1405 Returns \c true if the item is less than the \a other item; otherwise returns-
1406 false.-
1407*/-
1408bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const-
1409{-
1410 const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole);-
1411 return QAbstractItemModelPrivate::variantLessThan(v1, v2);
never executed: return QAbstractItemModelPrivate::variantLessThan(v1, v2);
0
1412}-
1413-
1414#ifndef QT_NO_DATASTREAM-
1415-
1416/*!-
1417 Reads the item from stream \a in.-
1418-
1419 \sa write()-
1420*/-
1421void QTableWidgetItem::read(QDataStream &in)-
1422{-
1423 in >> values;-
1424}
never executed: end of block
0
1425-
1426/*!-
1427 Writes the item to stream \a out.-
1428-
1429 \sa read()-
1430*/-
1431void QTableWidgetItem::write(QDataStream &out) const-
1432{-
1433 out << values;-
1434}
never executed: end of block
0
1435-
1436/*!-
1437 \relates QTableWidgetItem-
1438-
1439 Reads a table widget item from stream \a in into \a item.-
1440-
1441 This operator uses QTableWidgetItem::read().-
1442-
1443 \sa {Serializing Qt Data Types}-
1444*/-
1445QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item)-
1446{-
1447 item.read(in);-
1448 return in;
never executed: return in;
0
1449}-
1450-
1451/*!-
1452 \relates QTableWidgetItem-
1453-
1454 Writes the table widget item \a item to stream \a out.-
1455-
1456 This operator uses QTableWidgetItem::write().-
1457-
1458 \sa {Serializing Qt Data Types}-
1459*/-
1460QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item)-
1461{-
1462 item.write(out);-
1463 return out;
never executed: return out;
0
1464}-
1465-
1466#endif // QT_NO_DATASTREAM-
1467-
1468/*!-
1469 \since 4.1-
1470-
1471 Constructs a copy of \a other. Note that type() and tableWidget()-
1472 are not copied.-
1473-
1474 This function is useful when reimplementing clone().-
1475-
1476 \sa data(), flags()-
1477*/-
1478QTableWidgetItem::QTableWidgetItem(const QTableWidgetItem &other)-
1479 : rtti(Type), values(other.values), view(0),-
1480 d(new QTableWidgetItemPrivate(this)),-
1481 itemFlags(other.itemFlags)-
1482{-
1483}
never executed: end of block
0
1484-
1485/*!-
1486 Assigns \a other's data and flags to this item. Note that type()-
1487 and tableWidget() are not copied.-
1488-
1489 This function is useful when reimplementing clone().-
1490-
1491 \sa data(), flags()-
1492*/-
1493QTableWidgetItem &QTableWidgetItem::operator=(const QTableWidgetItem &other)-
1494{-
1495 values = other.values;-
1496 itemFlags = other.itemFlags;-
1497 return *this;
never executed: return *this;
0
1498}-
1499-
1500/*!-
1501 \class QTableWidget-
1502 \brief The QTableWidget class provides an item-based table view with a default model.-
1503-
1504 \ingroup model-view-
1505 \inmodule QtWidgets-
1506-
1507 Table widgets provide standard table display facilities for applications.-
1508 The items in a QTableWidget are provided by QTableWidgetItem.-
1509-
1510 If you want a table that uses your own data model you should-
1511 use QTableView rather than this class.-
1512-
1513 Table widgets can be constructed with the required numbers of rows and-
1514 columns:-
1515-
1516 \snippet qtablewidget-using/mainwindow.cpp 0-
1517-
1518 Alternatively, tables can be constructed without a given size and resized-
1519 later:-
1520-
1521 \snippet qtablewidget-resizing/mainwindow.cpp 0-
1522 \snippet qtablewidget-resizing/mainwindow.cpp 1-
1523-
1524 Items are created ouside the table (with no parent widget) and inserted-
1525 into the table with setItem():-
1526-
1527 \snippet qtablewidget-resizing/mainwindow.cpp 2-
1528-
1529 If you want to enable sorting in your table widget, do so after you-
1530 have populated it with items, otherwise sorting may interfere with-
1531 the insertion order (see setItem() for details).-
1532-
1533 Tables can be given both horizontal and vertical headers. The simplest way-
1534 to create the headers is to supply a list of strings to the-
1535 setHorizontalHeaderLabels() and setVerticalHeaderLabels() functions. These-
1536 will provide simple textual headers for the table's columns and rows.-
1537 More sophisticated headers can be created from existing table items-
1538 that are usually constructed outside the table. For example, we can-
1539 construct a table item with an icon and aligned text, and use it as the-
1540 header for a particular column:-
1541-
1542 \snippet qtablewidget-using/mainwindow.cpp 2-
1543-
1544 The number of rows in the table can be found with rowCount(), and the-
1545 number of columns with columnCount(). The table can be cleared with the-
1546 clear() function.-
1547-
1548 \table 100%-
1549 \row \li \inlineimage windowsvista-tableview.png Screenshot of a Windows Vista style table widget-
1550 \li \inlineimage macintosh-tableview.png Screenshot of a Macintosh style table widget-
1551 \li \inlineimage fusion-tableview.png Screenshot of a Fusion style table widget-
1552 \row \li A \l{Windows Vista Style Widget Gallery}{Windows Vista style} table widget.-
1553 \li A \l{Macintosh Style Widget Gallery}{Macintosh style} table widget.-
1554 \li A \l{Fusion Style Widget Gallery}{Fusion style} table widget.-
1555 \endtable-
1556-
1557 \sa QTableWidgetItem, QTableView, {Model/View Programming}-
1558*/-
1559-
1560/*!-
1561 \property QTableWidget::rowCount-
1562 \brief the number of rows in the table-
1563-
1564 By default, for a table constructed without row and column counts,-
1565 this property contains a value of 0.-
1566*/-
1567-
1568/*!-
1569 \property QTableWidget::columnCount-
1570 \brief the number of columns in the table-
1571-
1572 By default, for a table constructed without row and column counts,-
1573 this property contains a value of 0.-
1574*/-
1575-
1576void QTableWidgetPrivate::setup()-
1577{-
1578 Q_Q(QTableWidget);-
1579 // view signals-
1580 QObject::connect(q, SIGNAL(pressed(QModelIndex)), q, SLOT(_q_emitItemPressed(QModelIndex)));-
1581 QObject::connect(q, SIGNAL(clicked(QModelIndex)), q, SLOT(_q_emitItemClicked(QModelIndex)));-
1582 QObject::connect(q, SIGNAL(doubleClicked(QModelIndex)),-
1583 q, SLOT(_q_emitItemDoubleClicked(QModelIndex)));-
1584 QObject::connect(q, SIGNAL(activated(QModelIndex)), q, SLOT(_q_emitItemActivated(QModelIndex)));-
1585 QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex)));-
1586 // model signals-
1587 QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),-
1588 q, SLOT(_q_emitItemChanged(QModelIndex)));-
1589 // selection signals-
1590 QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),-
1591 q, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex)));-
1592 QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),-
1593 q, SIGNAL(itemSelectionChanged()));-
1594 // sorting-
1595 QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),-
1596 q, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));-
1597 QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort()));-
1598}
never executed: end of block
0
1599-
1600void QTableWidgetPrivate::_q_emitItemPressed(const QModelIndex &index)-
1601{-
1602 Q_Q(QTableWidget);-
1603 if (QTableWidgetItem *item = tableModel()->item(index))
QTableWidgetIt...)->item(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
1604 emit q->itemPressed(item);
never executed: q->itemPressed(item);
0
1605 emit q->cellPressed(index.row(), index.column());-
1606}
never executed: end of block
0
1607-
1608void QTableWidgetPrivate::_q_emitItemClicked(const QModelIndex &index)-
1609{-
1610 Q_Q(QTableWidget);-
1611 if (QTableWidgetItem *item = tableModel()->item(index))
QTableWidgetIt...)->item(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
1612 emit q->itemClicked(item);
never executed: q->itemClicked(item);
0
1613 emit q->cellClicked(index.row(), index.column());-
1614}
never executed: end of block
0
1615-
1616void QTableWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index)-
1617{-
1618 Q_Q(QTableWidget);-
1619 if (QTableWidgetItem *item = tableModel()->item(index))
QTableWidgetIt...)->item(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
1620 emit q->itemDoubleClicked(item);
never executed: q->itemDoubleClicked(item);
0
1621 emit q->cellDoubleClicked(index.row(), index.column());-
1622}
never executed: end of block
0
1623-
1624void QTableWidgetPrivate::_q_emitItemActivated(const QModelIndex &index)-
1625{-
1626 Q_Q(QTableWidget);-
1627 if (QTableWidgetItem *item = tableModel()->item(index))
QTableWidgetIt...)->item(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
1628 emit q->itemActivated(item);
never executed: q->itemActivated(item);
0
1629 emit q->cellActivated(index.row(), index.column());-
1630}
never executed: end of block
0
1631-
1632void QTableWidgetPrivate::_q_emitItemEntered(const QModelIndex &index)-
1633{-
1634 Q_Q(QTableWidget);-
1635 if (QTableWidgetItem *item = tableModel()->item(index))
QTableWidgetIt...)->item(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
1636 emit q->itemEntered(item);
never executed: q->itemEntered(item);
0
1637 emit q->cellEntered(index.row(), index.column());-
1638}
never executed: end of block
0
1639-
1640void QTableWidgetPrivate::_q_emitItemChanged(const QModelIndex &index)-
1641{-
1642 Q_Q(QTableWidget);-
1643 if (QTableWidgetItem *item = tableModel()->item(index))
QTableWidgetIt...)->item(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
1644 emit q->itemChanged(item);
never executed: q->itemChanged(item);
0
1645 emit q->cellChanged(index.row(), index.column());-
1646}
never executed: end of block
0
1647-
1648void QTableWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex &current,-
1649 const QModelIndex &previous)-
1650{-
1651 Q_Q(QTableWidget);-
1652 QTableWidgetItem *currentItem = tableModel()->item(current);-
1653 QTableWidgetItem *previousItem = tableModel()->item(previous);-
1654 if (currentItem || previousItem)
currentItemDescription
TRUEnever evaluated
FALSEnever evaluated
previousItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1655 emit q->currentItemChanged(currentItem, previousItem);
never executed: q->currentItemChanged(currentItem, previousItem);
0
1656 emit q->currentCellChanged(current.row(), current.column(), previous.row(), previous.column());-
1657}
never executed: end of block
0
1658-
1659void QTableWidgetPrivate::_q_sort()-
1660{-
1661 if (sortingEnabled) {
sortingEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
1662 int column = horizontalHeader->sortIndicatorSection();-
1663 Qt::SortOrder order = horizontalHeader->sortIndicatorOrder();-
1664 model->sort(column, order);-
1665 }
never executed: end of block
0
1666}
never executed: end of block
0
1667-
1668void QTableWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,-
1669 const QModelIndex &bottomRight)-
1670{-
1671 if (sortingEnabled && topLeft.isValid() && bottomRight.isValid()) {
sortingEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
topLeft.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
bottomRight.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1672 int column = horizontalHeader->sortIndicatorSection();-
1673 if (column >= topLeft.column() && column <= bottomRight.column()) {
column >= topLeft.column()Description
TRUEnever evaluated
FALSEnever evaluated
column <= bottomRight.column()Description
TRUEnever evaluated
FALSEnever evaluated
0
1674 Qt::SortOrder order = horizontalHeader->sortIndicatorOrder();-
1675 tableModel()->ensureSorted(column, order, topLeft.row(), bottomRight.row());-
1676 }
never executed: end of block
0
1677 }
never executed: end of block
0
1678}
never executed: end of block
0
1679-
1680/*!-
1681 \fn void QTableWidget::itemPressed(QTableWidgetItem *item)-
1682-
1683 This signal is emitted whenever an item in the table is pressed.-
1684 The \a item specified is the item that was pressed.-
1685*/-
1686-
1687/*!-
1688 \fn void QTableWidget::itemClicked(QTableWidgetItem *item)-
1689-
1690 This signal is emitted whenever an item in the table is clicked.-
1691 The \a item specified is the item that was clicked.-
1692*/-
1693-
1694/*!-
1695 \fn void QTableWidget::itemDoubleClicked(QTableWidgetItem *item)-
1696-
1697 This signal is emitted whenever an item in the table is double-
1698 clicked. The \a item specified is the item that was double clicked.-
1699*/-
1700-
1701/*!-
1702 \fn void QTableWidget::itemActivated(QTableWidgetItem *item)-
1703-
1704 This signal is emitted when the specified \a item has been activated-
1705*/-
1706-
1707/*!-
1708 \fn void QTableWidget::itemEntered(QTableWidgetItem *item)-
1709-
1710 This signal is emitted when the mouse cursor enters an item. The-
1711 \a item is the item entered.-
1712-
1713 This signal is only emitted when mouseTracking is turned on, or when a-
1714 mouse button is pressed while moving into an item.-
1715*/-
1716-
1717/*!-
1718 \fn void QTableWidget::itemChanged(QTableWidgetItem *item)-
1719-
1720 This signal is emitted whenever the data of \a item has changed.-
1721*/-
1722-
1723/*!-
1724 \fn void QTableWidget::currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous)-
1725-
1726 This signal is emitted whenever the current item changes. The \a-
1727 previous item is the item that previously had the focus, \a-
1728 current is the new current item.-
1729*/-
1730-
1731/*!-
1732 \fn void QTableWidget::itemSelectionChanged()-
1733-
1734 This signal is emitted whenever the selection changes.-
1735-
1736 \sa selectedItems(), QTableWidgetItem::isSelected()-
1737*/-
1738-
1739-
1740/*!-
1741 \since 4.1-
1742 \fn void QTableWidget::cellPressed(int row, int column)-
1743-
1744 This signal is emitted whenever a cell in the table is pressed.-
1745 The \a row and \a column specified is the cell that was pressed.-
1746*/-
1747-
1748/*!-
1749 \since 4.1-
1750 \fn void QTableWidget::cellClicked(int row, int column)-
1751-
1752 This signal is emitted whenever a cell in the table is clicked.-
1753 The \a row and \a column specified is the cell that was clicked.-
1754*/-
1755-
1756/*!-
1757 \since 4.1-
1758 \fn void QTableWidget::cellDoubleClicked(int row, int column)-
1759-
1760 This signal is emitted whenever a cell in the table is double-
1761 clicked. The \a row and \a column specified is the cell that was-
1762 double clicked.-
1763*/-
1764-
1765/*!-
1766 \since 4.1-
1767 \fn void QTableWidget::cellActivated(int row, int column)-
1768-
1769 This signal is emitted when the cell specified by \a row and \a column-
1770 has been activated-
1771*/-
1772-
1773/*!-
1774 \since 4.1-
1775 \fn void QTableWidget::cellEntered(int row, int column)-
1776-
1777 This signal is emitted when the mouse cursor enters a cell. The-
1778 cell is specified by \a row and \a column.-
1779-
1780 This signal is only emitted when mouseTracking is turned on, or when a-
1781 mouse button is pressed while moving into an item.-
1782*/-
1783-
1784/*!-
1785 \since 4.1-
1786 \fn void QTableWidget::cellChanged(int row, int column)-
1787-
1788 This signal is emitted whenever the data of the item in the cell-
1789 specified by \a row and \a column has changed.-
1790*/-
1791-
1792/*!-
1793 \since 4.1-
1794 \fn void QTableWidget::currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)-
1795-
1796 This signal is emitted whenever the current cell changes. The cell-
1797 specified by \a previousRow and \a previousColumn is the cell that-
1798 previously had the focus, the cell specified by \a currentRow and \a-
1799 currentColumn is the new current cell.-
1800*/-
1801-
1802/*!-
1803 \since 4.3-
1804 \fn void QTableWidget::removeCellWidget(int row, int column)-
1805-
1806 Removes the widget set on the cell indicated by \a row and \a column.-
1807*/-
1808-
1809/*!-
1810 \fn QTableWidgetItem *QTableWidget::itemAt(int ax, int ay) const-
1811-
1812 Returns the item at the position equivalent to QPoint(\a{ax}, \a{ay}) in-
1813 the table widget's coordinate system, or returns 0 if the specified point-
1814 is not covered by an item in the table widget.-
1815-
1816 \sa item()-
1817*/-
1818-
1819/*!-
1820 \enum QTableWidgetItem::ItemType-
1821-
1822 This enum describes the types that are used to describe table widget items.-
1823-
1824 \value Type The default type for table widget items.-
1825 \value UserType The minimum value for custom types. Values below UserType are-
1826 reserved by Qt.-
1827-
1828 You can define new user types in QTableWidgetItem subclasses to ensure that-
1829 custom items are treated specially.-
1830-
1831 \sa type()-
1832*/-
1833-
1834/*!-
1835 \fn int QTableWidgetItem::type() const-
1836-
1837 Returns the type passed to the QTableWidgetItem constructor.-
1838*/-
1839-
1840/*!-
1841 Creates a new table view with the given \a parent.-
1842*/-
1843QTableWidget::QTableWidget(QWidget *parent)-
1844 : QTableView(*new QTableWidgetPrivate, parent)-
1845{-
1846 Q_D(QTableWidget);-
1847 QTableView::setModel(new QTableModel(0, 0, this));-
1848 d->setup();-
1849}
never executed: end of block
0
1850-
1851/*!-
1852 Creates a new table view with the given \a rows and \a columns, and with the given \a parent.-
1853*/-
1854QTableWidget::QTableWidget(int rows, int columns, QWidget *parent)-
1855 : QTableView(*new QTableWidgetPrivate, parent)-
1856{-
1857 Q_D(QTableWidget);-
1858 QTableView::setModel(new QTableModel(rows, columns, this));-
1859 d->setup();-
1860}
never executed: end of block
0
1861-
1862/*!-
1863 Destroys this QTableWidget.-
1864*/-
1865QTableWidget::~QTableWidget()-
1866{-
1867}-
1868-
1869/*!-
1870 Sets the number of rows in this table's model to \a rows. If-
1871 this is less than rowCount(), the data in the unwanted rows-
1872 is discarded.-
1873-
1874 \sa setColumnCount()-
1875*/-
1876void QTableWidget::setRowCount(int rows)-
1877{-
1878 Q_D(QTableWidget);-
1879 d->tableModel()->setRowCount(rows);-
1880}
never executed: end of block
0
1881-
1882/*!-
1883 Returns the number of rows.-
1884*/-
1885-
1886int QTableWidget::rowCount() const-
1887{-
1888 Q_D(const QTableWidget);-
1889 return d->model->rowCount();
never executed: return d->model->rowCount();
0
1890}-
1891-
1892/*!-
1893 Sets the number of columns in this table's model to \a columns. If-
1894 this is less than columnCount(), the data in the unwanted columns-
1895 is discarded.-
1896-
1897 \sa setRowCount()-
1898*/-
1899void QTableWidget::setColumnCount(int columns)-
1900{-
1901 Q_D(QTableWidget);-
1902 d->tableModel()->setColumnCount(columns);-
1903}
never executed: end of block
0
1904-
1905/*!-
1906 Returns the number of columns.-
1907*/-
1908-
1909int QTableWidget::columnCount() const-
1910{-
1911 Q_D(const QTableWidget);-
1912 return d->model->columnCount();
never executed: return d->model->columnCount();
0
1913}-
1914-
1915/*!-
1916 Returns the row for the \a item.-
1917*/-
1918int QTableWidget::row(const QTableWidgetItem *item) const-
1919{-
1920 Q_D(const QTableWidget);-
1921 return d->tableModel()->index(item).row();
never executed: return d->tableModel()->index(item).row();
0
1922}-
1923-
1924/*!-
1925 Returns the column for the \a item.-
1926*/-
1927int QTableWidget::column(const QTableWidgetItem *item) const-
1928{-
1929 Q_D(const QTableWidget);-
1930 return d->tableModel()->index(item).column();
never executed: return d->tableModel()->index(item).column();
0
1931}-
1932-
1933-
1934/*!-
1935 Returns the item for the given \a row and \a column if one has been set; otherwise-
1936 returns 0.-
1937-
1938 \sa setItem()-
1939*/-
1940QTableWidgetItem *QTableWidget::item(int row, int column) const-
1941{-
1942 Q_D(const QTableWidget);-
1943 return d->tableModel()->item(row, column);
never executed: return d->tableModel()->item(row, column);
0
1944}-
1945-
1946/*!-
1947 Sets the item for the given \a row and \a column to \a item.-
1948-
1949 The table takes ownership of the item.-
1950-
1951 Note that if sorting is enabled (see-
1952 \l{QTableView::sortingEnabled} {sortingEnabled}) and \a column is-
1953 the current sort column, the \a row will be moved to the sorted-
1954 position determined by \a item.-
1955-
1956 If you want to set several items of a particular row (say, by-
1957 calling setItem() in a loop), you may want to turn off sorting-
1958 before doing so, and turn it back on afterwards; this will allow-
1959 you to use the same \a row argument for all items in the same row-
1960 (i.e. setItem() will not move the row).-
1961-
1962 \sa item(), takeItem()-
1963*/-
1964void QTableWidget::setItem(int row, int column, QTableWidgetItem *item)-
1965{-
1966 Q_D(QTableWidget);-
1967 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1968 if (Q_UNLIKELY(item->view)) {
__builtin_expe...>view), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1969 qWarning("QTableWidget: cannot insert an item that is already owned by another QTableWidget");-
1970 } else {
never executed: end of block
0
1971 item->view = this;-
1972 d->tableModel()->setItem(row, column, item);-
1973 }
never executed: end of block
0
1974 } else {-
1975 delete takeItem(row, column);-
1976 }
never executed: end of block
0
1977}-
1978-
1979/*!-
1980 Removes the item at \a row and \a column from the table without deleting it.-
1981*/-
1982QTableWidgetItem *QTableWidget::takeItem(int row, int column)-
1983{-
1984 Q_D(QTableWidget);-
1985 QTableWidgetItem *item = d->tableModel()->takeItem(row, column);-
1986 if (item)
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1987 item->view = 0;
never executed: item->view = 0;
0
1988 return item;
never executed: return item;
0
1989}-
1990-
1991/*!-
1992 Returns the vertical header item for row \a row.-
1993*/-
1994QTableWidgetItem *QTableWidget::verticalHeaderItem(int row) const-
1995{-
1996 Q_D(const QTableWidget);-
1997 return d->tableModel()->verticalHeaderItem(row);
never executed: return d->tableModel()->verticalHeaderItem(row);
0
1998}-
1999-
2000/*!-
2001 Sets the vertical header item for row \a row to \a item.-
2002*/-
2003void QTableWidget::setVerticalHeaderItem(int row, QTableWidgetItem *item)-
2004{-
2005 Q_D(QTableWidget);-
2006 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2007 item->view = this;-
2008 d->tableModel()->setVerticalHeaderItem(row, item);-
2009 } else {
never executed: end of block
0
2010 delete takeVerticalHeaderItem(row);-
2011 }
never executed: end of block
0
2012}-
2013-
2014/*!-
2015 \since 4.1-
2016 Removes the vertical header item at \a row from the header without deleting it.-
2017*/-
2018QTableWidgetItem *QTableWidget::takeVerticalHeaderItem(int row)-
2019{-
2020 Q_D(QTableWidget);-
2021 QTableWidgetItem *itm = d->tableModel()->takeVerticalHeaderItem(row);-
2022 if (itm)
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
2023 itm->view = 0;
never executed: itm->view = 0;
0
2024 return itm;
never executed: return itm;
0
2025}-
2026-
2027/*!-
2028 Returns the horizontal header item for column, \a column, if one has been-
2029 set; otherwise returns 0.-
2030*/-
2031QTableWidgetItem *QTableWidget::horizontalHeaderItem(int column) const-
2032{-
2033 Q_D(const QTableWidget);-
2034 return d->tableModel()->horizontalHeaderItem(column);
never executed: return d->tableModel()->horizontalHeaderItem(column);
0
2035}-
2036-
2037/*!-
2038 Sets the horizontal header item for column \a column to \a item.-
2039 If necessary, the column count is increased to fit the item.-
2040 The previous header item (if there was one) is deleted.-
2041*/-
2042void QTableWidget::setHorizontalHeaderItem(int column, QTableWidgetItem *item)-
2043{-
2044 Q_D(QTableWidget);-
2045 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2046 item->view = this;-
2047 d->tableModel()->setHorizontalHeaderItem(column, item);-
2048 } else {
never executed: end of block
0
2049 delete takeHorizontalHeaderItem(column);-
2050 }
never executed: end of block
0
2051}-
2052-
2053/*!-
2054 \since 4.1-
2055 Removes the horizontal header item at \a column from the header without deleting it.-
2056*/-
2057QTableWidgetItem *QTableWidget::takeHorizontalHeaderItem(int column)-
2058{-
2059 Q_D(QTableWidget);-
2060 QTableWidgetItem *itm = d->tableModel()->takeHorizontalHeaderItem(column);-
2061 if (itm)
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
2062 itm->view = 0;
never executed: itm->view = 0;
0
2063 return itm;
never executed: return itm;
0
2064}-
2065-
2066/*!-
2067 Sets the vertical header labels using \a labels.-
2068*/-
2069void QTableWidget::setVerticalHeaderLabels(const QStringList &labels)-
2070{-
2071 Q_D(QTableWidget);-
2072 QTableModel *model = d->tableModel();-
2073 QTableWidgetItem *item = 0;-
2074 for (int i = 0; i < model->rowCount() && i < labels.count(); ++i) {
i < model->rowCount()Description
TRUEnever evaluated
FALSEnever evaluated
i < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2075 item = model->verticalHeaderItem(i);-
2076 if (!item) {
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2077 item = model->createItem();-
2078 setVerticalHeaderItem(i, item);-
2079 }
never executed: end of block
0
2080 item->setText(labels.at(i));-
2081 }
never executed: end of block
0
2082}
never executed: end of block
0
2083-
2084/*!-
2085 Sets the horizontal header labels using \a labels.-
2086*/-
2087void QTableWidget::setHorizontalHeaderLabels(const QStringList &labels)-
2088{-
2089 Q_D(QTableWidget);-
2090 QTableModel *model = d->tableModel();-
2091 QTableWidgetItem *item = 0;-
2092 for (int i = 0; i < model->columnCount() && i < labels.count(); ++i) {
i < model->columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
i < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2093 item = model->horizontalHeaderItem(i);-
2094 if (!item) {
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2095 item = model->createItem();-
2096 setHorizontalHeaderItem(i, item);-
2097 }
never executed: end of block
0
2098 item->setText(labels.at(i));-
2099 }
never executed: end of block
0
2100}
never executed: end of block
0
2101-
2102/*!-
2103 Returns the row of the current item.-
2104-
2105 \sa currentColumn(), setCurrentCell()-
2106*/-
2107int QTableWidget::currentRow() const-
2108{-
2109 return currentIndex().row();
never executed: return currentIndex().row();
0
2110}-
2111-
2112/*!-
2113 Returns the column of the current item.-
2114-
2115 \sa currentRow(), setCurrentCell()-
2116*/-
2117int QTableWidget::currentColumn() const-
2118{-
2119 return currentIndex().column();
never executed: return currentIndex().column();
0
2120}-
2121-
2122/*!-
2123 Returns the current item.-
2124-
2125 \sa setCurrentItem()-
2126*/-
2127QTableWidgetItem *QTableWidget::currentItem() const-
2128{-
2129 Q_D(const QTableWidget);-
2130 return d->tableModel()->item(currentIndex());
never executed: return d->tableModel()->item(currentIndex());
0
2131}-
2132-
2133/*!-
2134 Sets the current item to \a item.-
2135-
2136 Unless the selection mode is \l{QAbstractItemView::}{NoSelection},-
2137 the item is also selected.-
2138-
2139 \sa currentItem(), setCurrentCell()-
2140*/-
2141void QTableWidget::setCurrentItem(QTableWidgetItem *item)-
2142{-
2143 Q_D(QTableWidget);-
2144 setCurrentIndex(d->tableModel()->index(item));-
2145}
never executed: end of block
0
2146-
2147/*!-
2148 \since 4.4-
2149-
2150 Sets the current item to be \a item, using the given \a command.-
2151-
2152 \sa currentItem(), setCurrentCell()-
2153*/-
2154void QTableWidget::setCurrentItem(QTableWidgetItem *item, QItemSelectionModel::SelectionFlags command)-
2155{-
2156 Q_D(QTableWidget);-
2157 d->selectionModel->setCurrentIndex(d->tableModel()->index(item), command);-
2158}
never executed: end of block
0
2159-
2160/*!-
2161 \since 4.1-
2162-
2163 Sets the current cell to be the cell at position (\a row, \a-
2164 column).-
2165-
2166 Depending on the current \l{QAbstractItemView::SelectionMode}{selection mode},-
2167 the cell may also be selected.-
2168-
2169 \sa setCurrentItem(), currentRow(), currentColumn()-
2170*/-
2171void QTableWidget::setCurrentCell(int row, int column)-
2172{-
2173 setCurrentIndex(model()->index(row, column, QModelIndex()));-
2174}
never executed: end of block
0
2175-
2176/*!-
2177 \since 4.4-
2178-
2179 Sets the current cell to be the cell at position (\a row, \a-
2180 column), using the given \a command.-
2181-
2182 \sa setCurrentItem(), currentRow(), currentColumn()-
2183*/-
2184void QTableWidget::setCurrentCell(int row, int column, QItemSelectionModel::SelectionFlags command)-
2185{-
2186 Q_D(QTableWidget);-
2187 d->selectionModel->setCurrentIndex(model()->index(row, column, QModelIndex()), command);-
2188}
never executed: end of block
0
2189-
2190/*!-
2191 Sorts all the rows in the table widget based on \a column and \a order.-
2192*/-
2193void QTableWidget::sortItems(int column, Qt::SortOrder order)-
2194{-
2195 Q_D(QTableWidget);-
2196 d->model->sort(column, order);-
2197 horizontalHeader()->setSortIndicator(column, order);-
2198}
never executed: end of block
0
2199-
2200/*!-
2201 \internal-
2202*/-
2203void QTableWidget::setSortingEnabled(bool enable)-
2204{-
2205 QTableView::setSortingEnabled(enable);-
2206}
never executed: end of block
0
2207-
2208/*!-
2209 \internal-
2210*/-
2211bool QTableWidget::isSortingEnabled() const-
2212{-
2213 return QTableView::isSortingEnabled();
never executed: return QTableView::isSortingEnabled();
0
2214}-
2215-
2216/*!-
2217 Starts editing the \a item if it is editable.-
2218*/-
2219-
2220void QTableWidget::editItem(QTableWidgetItem *item)-
2221{-
2222 Q_D(QTableWidget);-
2223 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2224 return;
never executed: return;
0
2225 edit(d->tableModel()->index(item));-
2226}
never executed: end of block
0
2227-
2228/*!-
2229 Opens an editor for the give \a item. The editor remains open after editing.-
2230-
2231 \sa closePersistentEditor()-
2232*/-
2233void QTableWidget::openPersistentEditor(QTableWidgetItem *item)-
2234{-
2235 Q_D(QTableWidget);-
2236 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2237 return;
never executed: return;
0
2238 QModelIndex index = d->tableModel()->index(item);-
2239 QAbstractItemView::openPersistentEditor(index);-
2240}
never executed: end of block
0
2241-
2242/*!-
2243 Closes the persistent editor for \a item.-
2244-
2245 \sa openPersistentEditor()-
2246*/-
2247void QTableWidget::closePersistentEditor(QTableWidgetItem *item)-
2248{-
2249 Q_D(QTableWidget);-
2250 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2251 return;
never executed: return;
0
2252 QModelIndex index = d->tableModel()->index(item);-
2253 QAbstractItemView::closePersistentEditor(index);-
2254}
never executed: end of block
0
2255-
2256/*!-
2257 \since 4.1-
2258-
2259 Returns the widget displayed in the cell in the given \a row and \a column.-
2260-
2261 \note The table takes ownership of the widget.-
2262-
2263 \sa setCellWidget()-
2264*/-
2265QWidget *QTableWidget::cellWidget(int row, int column) const-
2266{-
2267 QModelIndex index = model()->index(row, column, QModelIndex());-
2268 return QAbstractItemView::indexWidget(index);
never executed: return QAbstractItemView::indexWidget(index);
0
2269}-
2270-
2271/*!-
2272 \since 4.1-
2273-
2274 Sets the given \a widget to be displayed in the cell in the given \a row-
2275 and \a column, passing the ownership of the widget to the table.-
2276-
2277 If cell widget A is replaced with cell widget B, cell widget A will be-
2278 deleted. For example, in the code snippet below, the QLineEdit object will-
2279 be deleted.-
2280-
2281 \snippet code/src_gui_itemviews_qtablewidget.cpp 0-
2282-
2283 \sa cellWidget()-
2284*/-
2285void QTableWidget::setCellWidget(int row, int column, QWidget *widget)-
2286{-
2287 QModelIndex index = model()->index(row, column, QModelIndex());-
2288 QAbstractItemView::setIndexWidget(index, widget);-
2289}
never executed: end of block
0
2290-
2291/*!-
2292 Returns \c true if the \a item is selected, otherwise returns \c false.-
2293-
2294 \obsolete-
2295-
2296 This function is deprecated. Use \l{QTableWidgetItem::isSelected()} instead.-
2297*/-
2298-
2299bool QTableWidget::isItemSelected(const QTableWidgetItem *item) const-
2300{-
2301 Q_D(const QTableWidget);-
2302 QModelIndex index = d->tableModel()->index(item);-
2303 return selectionModel()->isSelected(index);
never executed: return selectionModel()->isSelected(index);
0
2304}-
2305-
2306/*!-
2307 Selects or deselects \a item depending on \a select.-
2308-
2309 \obsolete-
2310-
2311 This function is deprecated. Use \l{QTableWidgetItem::setSelected()} instead.-
2312*/-
2313void QTableWidget::setItemSelected(const QTableWidgetItem *item, bool select)-
2314{-
2315 Q_D(QTableWidget);-
2316 QModelIndex index = d->tableModel()->index(item);-
2317 selectionModel()->select(index, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);-
2318}
never executed: end of block
0
2319-
2320/*!-
2321 Selects or deselects the \a range depending on \a select.-
2322*/-
2323void QTableWidget::setRangeSelected(const QTableWidgetSelectionRange &range, bool select)-
2324{-
2325 if (!model()->hasIndex(range.topRow(), range.leftColumn(), rootIndex()) ||
!model()->hasI..., rootIndex())Description
TRUEnever evaluated
FALSEnever evaluated
0
2326 !model()->hasIndex(range.bottomRow(), range.rightColumn(), rootIndex()))
!model()->hasI..., rootIndex())Description
TRUEnever evaluated
FALSEnever evaluated
0
2327 return;
never executed: return;
0
2328-
2329 QModelIndex topLeft = model()->index(range.topRow(), range.leftColumn(), rootIndex());-
2330 QModelIndex bottomRight = model()->index(range.bottomRow(), range.rightColumn(), rootIndex());-
2331-
2332 selectionModel()->select(QItemSelection(topLeft, bottomRight),-
2333 select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);-
2334}
never executed: end of block
0
2335-
2336/*!-
2337 Returns a list of all selected ranges.-
2338-
2339 \sa QTableWidgetSelectionRange-
2340*/-
2341-
2342QList<QTableWidgetSelectionRange> QTableWidget::selectedRanges() const-
2343{-
2344 const QList<QItemSelectionRange> ranges = selectionModel()->selection();-
2345 QList<QTableWidgetSelectionRange> result;-
2346 const int rangesCount = ranges.count();-
2347 result.reserve(rangesCount);-
2348 for (int i = 0; i < rangesCount; ++i)
i < rangesCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2349 result.append(QTableWidgetSelectionRange(ranges.at(i).top(),
never executed: result.append(QTableWidgetSelectionRange(ranges.at(i).top(), ranges.at(i).left(), ranges.at(i).bottom(), ranges.at(i).right()));
0
2350 ranges.at(i).left(),
never executed: result.append(QTableWidgetSelectionRange(ranges.at(i).top(), ranges.at(i).left(), ranges.at(i).bottom(), ranges.at(i).right()));
0
2351 ranges.at(i).bottom(),
never executed: result.append(QTableWidgetSelectionRange(ranges.at(i).top(), ranges.at(i).left(), ranges.at(i).bottom(), ranges.at(i).right()));
0
2352 ranges.at(i).right()));
never executed: result.append(QTableWidgetSelectionRange(ranges.at(i).top(), ranges.at(i).left(), ranges.at(i).bottom(), ranges.at(i).right()));
0
2353 return result;
never executed: return result;
0
2354}-
2355-
2356/*!-
2357 Returns a list of all selected items.-
2358-
2359 This function returns a list of pointers to the contents of the-
2360 selected cells. Use the selectedIndexes() function to retrieve the-
2361 complete selection \e including empty cells.-
2362-
2363 \sa selectedIndexes()-
2364*/-
2365-
2366QList<QTableWidgetItem*> QTableWidget::selectedItems() const-
2367{-
2368 Q_D(const QTableWidget);-
2369 const QModelIndexList indexes = selectionModel()->selectedIndexes();-
2370 QList<QTableWidgetItem*> items;-
2371 for (const auto &index : indexes) {-
2372 if (isIndexHidden(index))
isIndexHidden(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
2373 continue;
never executed: continue;
0
2374 QTableWidgetItem *item = d->tableModel()->item(index);-
2375 if (item)
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2376 items.append(item);
never executed: items.append(item);
0
2377 }
never executed: end of block
0
2378 return items;
never executed: return items;
0
2379}-
2380-
2381/*!-
2382 Finds items that matches the \a text using the given \a flags.-
2383*/-
2384-
2385QList<QTableWidgetItem*> QTableWidget::findItems(const QString &text, Qt::MatchFlags flags) const-
2386{-
2387 Q_D(const QTableWidget);-
2388 QModelIndexList indexes;-
2389 for (int column = 0; column < columnCount(); ++column)
column < columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
2390 indexes += d->model->match(model()->index(0, column, QModelIndex()),
never executed: indexes += d->model->match(model()->index(0, column, QModelIndex()), Qt::DisplayRole, text, -1, flags);
0
2391 Qt::DisplayRole, text, -1, flags);
never executed: indexes += d->model->match(model()->index(0, column, QModelIndex()), Qt::DisplayRole, text, -1, flags);
0
2392 QList<QTableWidgetItem*> items;-
2393 const int indexCount = indexes.size();-
2394 items.reserve(indexCount);-
2395 for (int i = 0; i < indexCount; ++i)
i < indexCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
2396 items.append(d->tableModel()->item(indexes.at(i)));
never executed: items.append(d->tableModel()->item(indexes.at(i)));
0
2397 return items;
never executed: return items;
0
2398}-
2399-
2400/*!-
2401 Returns the visual row of the given \a logicalRow.-
2402*/-
2403-
2404int QTableWidget::visualRow(int logicalRow) const-
2405{-
2406 return verticalHeader()->visualIndex(logicalRow);
never executed: return verticalHeader()->visualIndex(logicalRow);
0
2407}-
2408-
2409/*!-
2410 Returns the visual column of the given \a logicalColumn.-
2411*/-
2412-
2413int QTableWidget::visualColumn(int logicalColumn) const-
2414{-
2415 return horizontalHeader()->visualIndex(logicalColumn);
never executed: return horizontalHeader()->visualIndex(logicalColumn);
0
2416}-
2417-
2418/*!-
2419 \fn QTableWidgetItem *QTableWidget::itemAt(const QPoint &point) const-
2420-
2421 Returns a pointer to the item at the given \a point, or returns 0 if-
2422 \a point is not covered by an item in the table widget.-
2423-
2424 \sa item()-
2425*/-
2426-
2427QTableWidgetItem *QTableWidget::itemAt(const QPoint &p) const-
2428{-
2429 Q_D(const QTableWidget);-
2430 return d->tableModel()->item(indexAt(p));
never executed: return d->tableModel()->item(indexAt(p));
0
2431}-
2432-
2433/*!-
2434 Returns the rectangle on the viewport occupied by the item at \a item.-
2435*/-
2436QRect QTableWidget::visualItemRect(const QTableWidgetItem *item) const-
2437{-
2438 Q_D(const QTableWidget);-
2439 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2440 return QRect();
never executed: return QRect();
0
2441 QModelIndex index = d->tableModel()->index(const_cast<QTableWidgetItem*>(item));-
2442 Q_ASSERT(index.isValid());-
2443 return visualRect(index);
never executed: return visualRect(index);
0
2444}-
2445-
2446/*!-
2447 Scrolls the view if necessary to ensure that the \a item is visible.-
2448 The \a hint parameter specifies more precisely where the-
2449 \a item should be located after the operation.-
2450*/-
2451-
2452void QTableWidget::scrollToItem(const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint)-
2453{-
2454 Q_D(QTableWidget);-
2455 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2456 return;
never executed: return;
0
2457 QModelIndex index = d->tableModel()->index(const_cast<QTableWidgetItem*>(item));-
2458 Q_ASSERT(index.isValid());-
2459 QTableView::scrollTo(index, hint);-
2460}
never executed: end of block
0
2461-
2462/*!-
2463 Returns the item prototype used by the table.-
2464-
2465 \sa setItemPrototype()-
2466*/-
2467const QTableWidgetItem *QTableWidget::itemPrototype() const-
2468{-
2469 Q_D(const QTableWidget);-
2470 return d->tableModel()->itemPrototype();
never executed: return d->tableModel()->itemPrototype();
0
2471}-
2472-
2473/*!-
2474 Sets the item prototype for the table to the specified \a item.-
2475-
2476 The table widget will use the item prototype clone function when it needs-
2477 to create a new table item. For example when the user is editing-
2478 in an empty cell. This is useful when you have a QTableWidgetItem-
2479 subclass and want to make sure that QTableWidget creates instances of-
2480 your subclass.-
2481-
2482 The table takes ownership of the prototype.-
2483-
2484 \sa itemPrototype()-
2485*/-
2486void QTableWidget::setItemPrototype(const QTableWidgetItem *item)-
2487{-
2488 Q_D(QTableWidget);-
2489 d->tableModel()->setItemPrototype(item);-
2490}
never executed: end of block
0
2491-
2492/*!-
2493 Inserts an empty row into the table at \a row.-
2494*/-
2495void QTableWidget::insertRow(int row)-
2496{-
2497 Q_D(QTableWidget);-
2498 d->tableModel()->insertRows(row);-
2499}
never executed: end of block
0
2500-
2501/*!-
2502 Inserts an empty column into the table at \a column.-
2503*/-
2504void QTableWidget::insertColumn(int column)-
2505{-
2506 Q_D(QTableWidget);-
2507 d->tableModel()->insertColumns(column);-
2508}
never executed: end of block
0
2509-
2510/*!-
2511 Removes the row \a row and all its items from the table.-
2512*/-
2513void QTableWidget::removeRow(int row)-
2514{-
2515 Q_D(QTableWidget);-
2516 d->tableModel()->removeRows(row);-
2517}
never executed: end of block
0
2518-
2519/*!-
2520 Removes the column \a column and all its items from the table.-
2521*/-
2522void QTableWidget::removeColumn(int column)-
2523{-
2524 Q_D(QTableWidget);-
2525 d->tableModel()->removeColumns(column);-
2526}
never executed: end of block
0
2527-
2528/*!-
2529 Removes all items in the view.-
2530 This will also remove all selections and headers.-
2531 If you don't want to remove the headers, use-
2532 QTableWidget::clearContents().-
2533 The table dimensions stay the same.-
2534*/-
2535-
2536void QTableWidget::clear()-
2537{-
2538 Q_D(QTableWidget);-
2539 selectionModel()->clear();-
2540 d->tableModel()->clear();-
2541}
never executed: end of block
0
2542-
2543/*!-
2544 \since 4.2-
2545-
2546 Removes all items not in the headers from the view.-
2547 This will also remove all selections.-
2548 The table dimensions stay the same.-
2549*/-
2550void QTableWidget::clearContents()-
2551{-
2552 Q_D(QTableWidget);-
2553 selectionModel()->clear();-
2554 d->tableModel()->clearContents();-
2555}
never executed: end of block
0
2556-
2557/*!-
2558 Returns a list of MIME types that can be used to describe a list of-
2559 tablewidget items.-
2560-
2561 \sa mimeData()-
2562*/-
2563QStringList QTableWidget::mimeTypes() const-
2564{-
2565 return d_func()->tableModel()->QAbstractTableModel::mimeTypes();
never executed: return d_func()->tableModel()->QAbstractTableModel::mimeTypes();
0
2566}-
2567-
2568/*!-
2569 Returns an object that contains a serialized description of the specified-
2570 \a items. The format used to describe the items is obtained from the-
2571 mimeTypes() function.-
2572-
2573 If the list of items is empty, 0 is returned rather than a serialized-
2574 empty list.-
2575*/-
2576#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)-
2577QMimeData *QTableWidget::mimeData(const QList<QTableWidgetItem *> &items) const-
2578#else-
2579QMimeData *QTableWidget::mimeData(const QList<QTableWidgetItem*> items) const-
2580#endif-
2581{-
2582 Q_D(const QTableWidget);-
2583-
2584 QModelIndexList &cachedIndexes = d->tableModel()->cachedIndexes;-
2585-
2586 // if non empty, it's called from the model's own mimeData-
2587 if (cachedIndexes.isEmpty()) {
cachedIndexes.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2588 cachedIndexes.reserve(items.count());-
2589 foreach (QTableWidgetItem *item, items)-
2590 cachedIndexes << indexFromItem(item);
never executed: cachedIndexes << indexFromItem(item);
0
2591-
2592 QMimeData *result = d->tableModel()->internalMimeData();-
2593-
2594 cachedIndexes.clear();-
2595 return result;
never executed: return result;
0
2596 }-
2597-
2598 return d->tableModel()->internalMimeData();
never executed: return d->tableModel()->internalMimeData();
0
2599}-
2600-
2601/*!-
2602 Handles the \a data supplied by a drag and drop operation that ended with-
2603 the given \a action in the given \a row and \a column.-
2604 Returns \c true if the data and action can be handled by the model;-
2605 otherwise returns \c false.-
2606-
2607 \sa supportedDropActions()-
2608*/-
2609bool QTableWidget::dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action)-
2610{-
2611 QModelIndex idx;-
2612#ifndef QT_NO_DRAGANDDROP-
2613 if (dropIndicatorPosition() == QAbstractItemView::OnItem) {
dropIndicatorP...emView::OnItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2614 // QAbstractTableModel::dropMimeData will overwrite on the index if row == -1 and column == -1-
2615 idx = model()->index(row, column);-
2616 row = -1;-
2617 column = -1;-
2618 }
never executed: end of block
0
2619#endif-
2620 return d_func()->tableModel()->QAbstractTableModel::dropMimeData(data, action , row, column, idx);
never executed: return d_func()->tableModel()->QAbstractTableModel::dropMimeData(data, action , row, column, idx);
0
2621}-
2622-
2623/*!-
2624 Returns the drop actions supported by this view.-
2625-
2626 \sa Qt::DropActions-
2627*/-
2628Qt::DropActions QTableWidget::supportedDropActions() const-
2629{-
2630 return d_func()->tableModel()->QAbstractTableModel::supportedDropActions() | Qt::MoveAction;
never executed: return d_func()->tableModel()->QAbstractTableModel::supportedDropActions() | Qt::MoveAction;
0
2631}-
2632-
2633/*!-
2634 Returns a list of pointers to the items contained in the \a data object.-
2635 If the object was not created by a QTreeWidget in the same process, the list-
2636 is empty.-
2637-
2638*/-
2639QList<QTableWidgetItem*> QTableWidget::items(const QMimeData *data) const-
2640{-
2641 const QTableWidgetMimeData *twd = qobject_cast<const QTableWidgetMimeData*>(data);-
2642 if (twd)
twdDescription
TRUEnever evaluated
FALSEnever evaluated
0
2643 return twd->items;
never executed: return twd->items;
0
2644 return QList<QTableWidgetItem*>();
never executed: return QList<QTableWidgetItem*>();
0
2645}-
2646-
2647/*!-
2648 Returns the QModelIndex associated with the given \a item.-
2649*/-
2650-
2651QModelIndex QTableWidget::indexFromItem(QTableWidgetItem *item) const-
2652{-
2653 Q_D(const QTableWidget);-
2654 return d->tableModel()->index(item);
never executed: return d->tableModel()->index(item);
0
2655}-
2656-
2657/*!-
2658 Returns a pointer to the QTableWidgetItem associated with the given \a index.-
2659*/-
2660-
2661QTableWidgetItem *QTableWidget::itemFromIndex(const QModelIndex &index) const-
2662{-
2663 Q_D(const QTableWidget);-
2664 return d->tableModel()->item(index);
never executed: return d->tableModel()->item(index);
0
2665}-
2666-
2667/*!-
2668 \internal-
2669*/-
2670void QTableWidget::setModel(QAbstractItemModel * /*model*/)-
2671{-
2672 Q_ASSERT(!"QTableWidget::setModel() - Changing the model of the QTableWidget is not allowed.");-
2673}
never executed: end of block
0
2674-
2675/*! \reimp */-
2676bool QTableWidget::event(QEvent *e)-
2677{-
2678 return QTableView::event(e);
never executed: return QTableView::event(e);
0
2679}-
2680-
2681#ifndef QT_NO_DRAGANDDROP-
2682/*! \reimp */-
2683void QTableWidget::dropEvent(QDropEvent *event) {-
2684 Q_D(QTableWidget);-
2685 if (event->source() == this && (event->dropAction() == Qt::MoveAction ||
event->source() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
event->dropAct...Qt::MoveActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
2686 dragDropMode() == QAbstractItemView::InternalMove)) {
dragDropMode()...::InternalMoveDescription
TRUEnever evaluated
FALSEnever evaluated
0
2687 QModelIndex topIndex;-
2688 int col = -1;-
2689 int row = -1;-
2690 if (d->dropOn(event, &row, &col, &topIndex)) {
d->dropOn(even...ol, &topIndex)Description
TRUEnever evaluated
FALSEnever evaluated
0
2691 const QModelIndexList indexes = selectedIndexes();-
2692 int top = INT_MAX;-
2693 int left = INT_MAX;-
2694 for (const auto &index : indexes) {-
2695 top = qMin(index.row(), top);-
2696 left = qMin(index.column(), left);-
2697 }
never executed: end of block
0
2698-
2699 QList<QTableWidgetItem *> taken;-
2700 const int indexesCount = indexes.count();-
2701 taken.reserve(indexesCount);-
2702 for (const auto &index : indexes)-
2703 taken.append(takeItem(index.row(), index.column()));
never executed: taken.append(takeItem(index.row(), index.column()));
0
2704-
2705 for (const auto &index : indexes) {-
2706 int r = index.row() - top + topIndex.row();-
2707 int c = index.column() - left + topIndex.column();-
2708 setItem(r, c, taken.takeFirst());-
2709 }
never executed: end of block
0
2710-
2711 event->accept();-
2712 // Don't want QAbstractItemView to delete it because it was "moved" we already did it-
2713 event->setDropAction(Qt::CopyAction);-
2714 }
never executed: end of block
0
2715 }
never executed: end of block
0
2716-
2717 QTableView::dropEvent(event);-
2718}
never executed: end of block
0
2719#endif-
2720-
2721QT_END_NAMESPACE-
2722-
2723#include "moc_qtablewidget.cpp"-
2724#include "moc_qtablewidget_p.cpp"-
2725-
2726#endif // QT_NO_TABLEWIDGET-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9