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