Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qtablewidget.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | QTableModel::QTableModel(int rows, int columns, QTableWidget *parent) | - | ||||||||||||
9 | : QAbstractTableModel(parent), | - | ||||||||||||
10 | prototype(0), | - | ||||||||||||
11 | tableItems(rows * columns, 0), | - | ||||||||||||
12 | verticalHeaderItems(rows, 0), | - | ||||||||||||
13 | horizontalHeaderItems(columns, 0) | - | ||||||||||||
14 | {} | - | ||||||||||||
15 | - | |||||||||||||
16 | QTableModel::~QTableModel() | - | ||||||||||||
17 | { | - | ||||||||||||
18 | clear(); | - | ||||||||||||
19 | delete prototype; | - | ||||||||||||
20 | } | - | ||||||||||||
21 | - | |||||||||||||
22 | bool QTableModel::insertRows(int row, int count, const QModelIndex &) | - | ||||||||||||
23 | { | - | ||||||||||||
24 | if (count < 1 || row < 0 || row > verticalHeaderItems.count()) | - | ||||||||||||
25 | return false; | - | ||||||||||||
26 | - | |||||||||||||
27 | beginInsertRows(QModelIndex(), row, row + count - 1); | - | ||||||||||||
28 | int rc = verticalHeaderItems.count(); | - | ||||||||||||
29 | int cc = horizontalHeaderItems.count(); | - | ||||||||||||
30 | verticalHeaderItems.insert(row, count, 0); | - | ||||||||||||
31 | if (rc == 0) | - | ||||||||||||
32 | tableItems.resize(cc * count); | - | ||||||||||||
33 | else | - | ||||||||||||
34 | tableItems.insert(tableIndex(row, 0), cc * count, 0); | - | ||||||||||||
35 | endInsertRows(); | - | ||||||||||||
36 | return true; | - | ||||||||||||
37 | } | - | ||||||||||||
38 | - | |||||||||||||
39 | bool QTableModel::insertColumns(int column, int count, const QModelIndex &) | - | ||||||||||||
40 | { | - | ||||||||||||
41 | if (count < 1 || column < 0 || column > horizontalHeaderItems.count()) | - | ||||||||||||
42 | return false; | - | ||||||||||||
43 | - | |||||||||||||
44 | beginInsertColumns(QModelIndex(), column, column + count - 1); | - | ||||||||||||
45 | int rc = verticalHeaderItems.count(); | - | ||||||||||||
46 | int cc = horizontalHeaderItems.count(); | - | ||||||||||||
47 | horizontalHeaderItems.insert(column, count, 0); | - | ||||||||||||
48 | if (cc == 0) | - | ||||||||||||
49 | tableItems.resize(rc * count); | - | ||||||||||||
50 | else | - | ||||||||||||
51 | for (int row = 0; row < rc; ++row) | - | ||||||||||||
52 | tableItems.insert(tableIndex(row, column), count, 0); | - | ||||||||||||
53 | endInsertColumns(); | - | ||||||||||||
54 | return true; | - | ||||||||||||
55 | } | - | ||||||||||||
56 | - | |||||||||||||
57 | bool QTableModel::removeRows(int row, int count, const QModelIndex &) | - | ||||||||||||
58 | { | - | ||||||||||||
59 | if (count < 1 || row < 0 || row + count > verticalHeaderItems.count()) | - | ||||||||||||
60 | return false; | - | ||||||||||||
61 | - | |||||||||||||
62 | beginRemoveRows(QModelIndex(), row, row + count - 1); | - | ||||||||||||
63 | int i = tableIndex(row, 0); | - | ||||||||||||
64 | int n = count * columnCount(); | - | ||||||||||||
65 | QTableWidgetItem *oldItem = 0; | - | ||||||||||||
66 | for (int j = i; j < n + i; ++j) { | - | ||||||||||||
67 | oldItem = tableItems.at(j); | - | ||||||||||||
68 | if (oldItem) | - | ||||||||||||
69 | oldItem->view = 0; | - | ||||||||||||
70 | delete oldItem; | - | ||||||||||||
71 | } | - | ||||||||||||
72 | tableItems.remove(qMax(i, 0), n); | - | ||||||||||||
73 | for (int v = row; v < row + count; ++v) { | - | ||||||||||||
74 | oldItem = verticalHeaderItems.at(v); | - | ||||||||||||
75 | if (oldItem) | - | ||||||||||||
76 | oldItem->view = 0; | - | ||||||||||||
77 | delete oldItem; | - | ||||||||||||
78 | } | - | ||||||||||||
79 | verticalHeaderItems.remove(row, count); | - | ||||||||||||
80 | endRemoveRows(); | - | ||||||||||||
81 | return true; | - | ||||||||||||
82 | } | - | ||||||||||||
83 | - | |||||||||||||
84 | bool QTableModel::removeColumns(int column, int count, const QModelIndex &) | - | ||||||||||||
85 | { | - | ||||||||||||
86 | if (count < 1 || column < 0 || column + count > horizontalHeaderItems.count()) | - | ||||||||||||
87 | return false; | - | ||||||||||||
88 | - | |||||||||||||
89 | beginRemoveColumns(QModelIndex(), column, column + count - 1); | - | ||||||||||||
90 | QTableWidgetItem *oldItem = 0; | - | ||||||||||||
91 | for (int row = rowCount() - 1; row >= 0; --row) { | - | ||||||||||||
92 | int i = tableIndex(row, column); | - | ||||||||||||
93 | for (int j = i; j < i + count; ++j) { | - | ||||||||||||
94 | oldItem = tableItems.at(j); | - | ||||||||||||
95 | if (oldItem) | - | ||||||||||||
96 | oldItem->view = 0; | - | ||||||||||||
97 | delete oldItem; | - | ||||||||||||
98 | } | - | ||||||||||||
99 | tableItems.remove(i, count); | - | ||||||||||||
100 | } | - | ||||||||||||
101 | for (int h=column; h<column+count; ++h) { | - | ||||||||||||
102 | oldItem = horizontalHeaderItems.at(h); | - | ||||||||||||
103 | if (oldItem) | - | ||||||||||||
104 | oldItem->view = 0; | - | ||||||||||||
105 | delete oldItem; | - | ||||||||||||
106 | } | - | ||||||||||||
107 | horizontalHeaderItems.remove(column, count); | - | ||||||||||||
108 | endRemoveColumns(); | - | ||||||||||||
109 | return true; | - | ||||||||||||
110 | } | - | ||||||||||||
111 | - | |||||||||||||
112 | void QTableModel::setItem(int row, int column, QTableWidgetItem *item) | - | ||||||||||||
113 | { | - | ||||||||||||
114 | int i = tableIndex(row, column); | - | ||||||||||||
115 | if (i < 0 || i >= tableItems.count()) | - | ||||||||||||
116 | return; | - | ||||||||||||
117 | QTableWidgetItem *oldItem = tableItems.at(i); | - | ||||||||||||
118 | if (item == oldItem) | - | ||||||||||||
119 | return; | - | ||||||||||||
120 | - | |||||||||||||
121 | - | |||||||||||||
122 | if (oldItem) | - | ||||||||||||
123 | oldItem->view = 0; | - | ||||||||||||
124 | delete tableItems.at(i); | - | ||||||||||||
125 | - | |||||||||||||
126 | QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); | - | ||||||||||||
127 | - | |||||||||||||
128 | - | |||||||||||||
129 | if (item) | - | ||||||||||||
130 | item->d->id = i; | - | ||||||||||||
131 | tableItems[i] = item; | - | ||||||||||||
132 | - | |||||||||||||
133 | if (view && view->isSortingEnabled() | - | ||||||||||||
134 | && view->horizontalHeader()->sortIndicatorSection() == column) { | - | ||||||||||||
135 | - | |||||||||||||
136 | Qt::SortOrder order = view->horizontalHeader()->sortIndicatorOrder(); | - | ||||||||||||
137 | QVector<QTableWidgetItem*> colItems = columnItems(column); | - | ||||||||||||
138 | if (row < colItems.count()) | - | ||||||||||||
139 | colItems.remove(row); | - | ||||||||||||
140 | int sortedRow; | - | ||||||||||||
141 | if (item == 0) { | - | ||||||||||||
142 | - | |||||||||||||
143 | sortedRow = colItems.count(); | - | ||||||||||||
144 | } else { | - | ||||||||||||
145 | QVector<QTableWidgetItem*>::iterator it; | - | ||||||||||||
146 | it = sortedInsertionIterator(colItems.begin(), colItems.end(), order, item); | - | ||||||||||||
147 | sortedRow = qMax((int)(it - colItems.begin()), 0); | - | ||||||||||||
148 | } | - | ||||||||||||
149 | if (sortedRow != row) { | - | ||||||||||||
150 | layoutAboutToBeChanged(); | - | ||||||||||||
151 | - | |||||||||||||
152 | int cc = columnCount(); | - | ||||||||||||
153 | QVector<QTableWidgetItem*> rowItems(cc); | - | ||||||||||||
154 | for (int j = 0; j < cc; ++j) | - | ||||||||||||
155 | rowItems[j] = tableItems.at(tableIndex(row, j)); | - | ||||||||||||
156 | tableItems.remove(tableIndex(row, 0), cc); | - | ||||||||||||
157 | tableItems.insert(tableIndex(sortedRow, 0), cc, 0); | - | ||||||||||||
158 | for (int j = 0; j < cc; ++j) | - | ||||||||||||
159 | tableItems[tableIndex(sortedRow, j)] = rowItems.at(j); | - | ||||||||||||
160 | QTableWidgetItem *header = verticalHeaderItems.at(row); | - | ||||||||||||
161 | verticalHeaderItems.remove(row); | - | ||||||||||||
162 | verticalHeaderItems.insert(sortedRow, header); | - | ||||||||||||
163 | - | |||||||||||||
164 | QModelIndexList oldPersistentIndexes = persistentIndexList(); | - | ||||||||||||
165 | QModelIndexList newPersistentIndexes = oldPersistentIndexes; | - | ||||||||||||
166 | updateRowIndexes(newPersistentIndexes, row, sortedRow); | - | ||||||||||||
167 | changePersistentIndexList(oldPersistentIndexes, | - | ||||||||||||
168 | newPersistentIndexes); | - | ||||||||||||
169 | - | |||||||||||||
170 | layoutChanged(); | - | ||||||||||||
171 | return; | - | ||||||||||||
172 | } | - | ||||||||||||
173 | } | - | ||||||||||||
174 | QModelIndex idx = QAbstractTableModel::index(row, column); | - | ||||||||||||
175 | dataChanged(idx, idx); | - | ||||||||||||
176 | } | - | ||||||||||||
177 | - | |||||||||||||
178 | QTableWidgetItem *QTableModel::takeItem(int row, int column) | - | ||||||||||||
179 | { | - | ||||||||||||
180 | long i = tableIndex(row, column); | - | ||||||||||||
181 | QTableWidgetItem *itm = tableItems.value(i); | - | ||||||||||||
182 | if (itm) { | - | ||||||||||||
183 | itm->view = 0; | - | ||||||||||||
184 | itm->d->id = -1; | - | ||||||||||||
185 | tableItems[i] = 0; | - | ||||||||||||
186 | QModelIndex ind = index(itm); | - | ||||||||||||
187 | dataChanged(ind, ind); | - | ||||||||||||
188 | } | - | ||||||||||||
189 | return itm; | - | ||||||||||||
190 | } | - | ||||||||||||
191 | - | |||||||||||||
192 | QTableWidgetItem *QTableModel::item(int row, int column) const | - | ||||||||||||
193 | { | - | ||||||||||||
194 | return item(index(row, column)); | - | ||||||||||||
195 | } | - | ||||||||||||
196 | - | |||||||||||||
197 | QTableWidgetItem *QTableModel::item(const QModelIndex &index) const | - | ||||||||||||
198 | { | - | ||||||||||||
199 | if (!isValid(index)) | - | ||||||||||||
200 | return 0; | - | ||||||||||||
201 | return tableItems.at(tableIndex(index.row(), index.column())); | - | ||||||||||||
202 | } | - | ||||||||||||
203 | - | |||||||||||||
204 | void QTableModel::removeItem(QTableWidgetItem *item) | - | ||||||||||||
205 | { | - | ||||||||||||
206 | int i = tableItems.indexOf(item); | - | ||||||||||||
207 | if (i != -1) { | - | ||||||||||||
208 | tableItems[i] = 0; | - | ||||||||||||
209 | QModelIndex idx = index(item); | - | ||||||||||||
210 | dataChanged(idx, idx); | - | ||||||||||||
211 | return; | - | ||||||||||||
212 | } | - | ||||||||||||
213 | - | |||||||||||||
214 | i = verticalHeaderItems.indexOf(item); | - | ||||||||||||
215 | - | |||||||||||||
216 | if (i != -1) { | - | ||||||||||||
217 | verticalHeaderItems[i] = 0; | - | ||||||||||||
218 | headerDataChanged(Qt::Vertical, i, i); | - | ||||||||||||
219 | return; | - | ||||||||||||
220 | } | - | ||||||||||||
221 | i = horizontalHeaderItems.indexOf(item); | - | ||||||||||||
222 | if (i != -1) { | - | ||||||||||||
223 | horizontalHeaderItems[i] = 0; | - | ||||||||||||
224 | headerDataChanged(Qt::Horizontal, i, i); | - | ||||||||||||
225 | return; | - | ||||||||||||
226 | } | - | ||||||||||||
227 | } | - | ||||||||||||
228 | - | |||||||||||||
229 | void QTableModel::setHorizontalHeaderItem(int section, QTableWidgetItem *item) | - | ||||||||||||
230 | { | - | ||||||||||||
231 | if (section < 0 || section >= horizontalHeaderItems.count()) | - | ||||||||||||
232 | return; | - | ||||||||||||
233 | QTableWidgetItem *oldItem = horizontalHeaderItems.at(section); | - | ||||||||||||
234 | if (item == oldItem) | - | ||||||||||||
235 | return; | - | ||||||||||||
236 | - | |||||||||||||
237 | if (oldItem) | - | ||||||||||||
238 | oldItem->view = 0; | - | ||||||||||||
239 | delete oldItem; | - | ||||||||||||
240 | - | |||||||||||||
241 | QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); | - | ||||||||||||
242 | - | |||||||||||||
243 | if (item) { | - | ||||||||||||
244 | item->view = view; | - | ||||||||||||
245 | item->itemFlags = Qt::ItemFlags(int(item->itemFlags)|ItemIsHeaderItem); | - | ||||||||||||
246 | } | - | ||||||||||||
247 | horizontalHeaderItems[section] = item; | - | ||||||||||||
248 | headerDataChanged(Qt::Horizontal, section, section); | - | ||||||||||||
249 | } | - | ||||||||||||
250 | - | |||||||||||||
251 | void QTableModel::setVerticalHeaderItem(int section, QTableWidgetItem *item) | - | ||||||||||||
252 | { | - | ||||||||||||
253 | if (section < 0 || section >= verticalHeaderItems.count()) | - | ||||||||||||
254 | return; | - | ||||||||||||
255 | QTableWidgetItem *oldItem = verticalHeaderItems.at(section); | - | ||||||||||||
256 | if (item == oldItem) | - | ||||||||||||
257 | return; | - | ||||||||||||
258 | - | |||||||||||||
259 | if (oldItem) | - | ||||||||||||
260 | oldItem->view = 0; | - | ||||||||||||
261 | delete oldItem; | - | ||||||||||||
262 | - | |||||||||||||
263 | QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); | - | ||||||||||||
264 | - | |||||||||||||
265 | if (item) { | - | ||||||||||||
266 | item->view = view; | - | ||||||||||||
267 | item->itemFlags = Qt::ItemFlags(int(item->itemFlags)|ItemIsHeaderItem); | - | ||||||||||||
268 | } | - | ||||||||||||
269 | verticalHeaderItems[section] = item; | - | ||||||||||||
270 | headerDataChanged(Qt::Vertical, section, section); | - | ||||||||||||
271 | } | - | ||||||||||||
272 | - | |||||||||||||
273 | QTableWidgetItem *QTableModel::takeHorizontalHeaderItem(int section) | - | ||||||||||||
274 | { | - | ||||||||||||
275 | if (section < 0 || section >= horizontalHeaderItems.count()) | - | ||||||||||||
276 | return 0; | - | ||||||||||||
277 | QTableWidgetItem *itm = horizontalHeaderItems.at(section); | - | ||||||||||||
278 | if (itm) { | - | ||||||||||||
279 | itm->view = 0; | - | ||||||||||||
280 | itm->itemFlags &= ~ItemIsHeaderItem; | - | ||||||||||||
281 | horizontalHeaderItems[section] = 0; | - | ||||||||||||
282 | } | - | ||||||||||||
283 | return itm; | - | ||||||||||||
284 | } | - | ||||||||||||
285 | - | |||||||||||||
286 | QTableWidgetItem *QTableModel::takeVerticalHeaderItem(int section) | - | ||||||||||||
287 | { | - | ||||||||||||
288 | if (section < 0 || section >= verticalHeaderItems.count()) | - | ||||||||||||
289 | return 0; | - | ||||||||||||
290 | QTableWidgetItem *itm = verticalHeaderItems.at(section); | - | ||||||||||||
291 | if (itm) { | - | ||||||||||||
292 | itm->view = 0; | - | ||||||||||||
293 | itm->itemFlags &= ~ItemIsHeaderItem; | - | ||||||||||||
294 | verticalHeaderItems[section] = 0; | - | ||||||||||||
295 | } | - | ||||||||||||
296 | return itm; | - | ||||||||||||
297 | } | - | ||||||||||||
298 | - | |||||||||||||
299 | QTableWidgetItem *QTableModel::horizontalHeaderItem(int section) | - | ||||||||||||
300 | { | - | ||||||||||||
301 | return horizontalHeaderItems.value(section); | - | ||||||||||||
302 | } | - | ||||||||||||
303 | - | |||||||||||||
304 | QTableWidgetItem *QTableModel::verticalHeaderItem(int section) | - | ||||||||||||
305 | { | - | ||||||||||||
306 | return verticalHeaderItems.value(section); | - | ||||||||||||
307 | } | - | ||||||||||||
308 | - | |||||||||||||
309 | QModelIndex QTableModel::index(const QTableWidgetItem *item) const | - | ||||||||||||
310 | { | - | ||||||||||||
311 | if (!item) | - | ||||||||||||
312 | return QModelIndex(); | - | ||||||||||||
313 | int i = -1; | - | ||||||||||||
314 | const int id = item->d->id; | - | ||||||||||||
315 | if (id >= 0 && id < tableItems.count() && tableItems.at(id) == item) { | - | ||||||||||||
316 | i = id; | - | ||||||||||||
317 | } else { | - | ||||||||||||
318 | i = tableItems.indexOf(const_cast<QTableWidgetItem*>(item)); | - | ||||||||||||
319 | if (i == -1) | - | ||||||||||||
320 | return QModelIndex(); | - | ||||||||||||
321 | } | - | ||||||||||||
322 | int row = i / columnCount(); | - | ||||||||||||
323 | int col = i % columnCount(); | - | ||||||||||||
324 | return QAbstractTableModel::index(row, col); | - | ||||||||||||
325 | } | - | ||||||||||||
326 | - | |||||||||||||
327 | void QTableModel::setRowCount(int rows) | - | ||||||||||||
328 | { | - | ||||||||||||
329 | int rc = verticalHeaderItems.count(); | - | ||||||||||||
330 | if (rows < 0 || rc == rows) | - | ||||||||||||
331 | return; | - | ||||||||||||
332 | if (rc < rows) | - | ||||||||||||
333 | insertRows(qMax(rc, 0), rows - rc); | - | ||||||||||||
334 | else | - | ||||||||||||
335 | removeRows(qMax(rows, 0), rc - rows); | - | ||||||||||||
336 | } | - | ||||||||||||
337 | - | |||||||||||||
338 | void QTableModel::setColumnCount(int columns) | - | ||||||||||||
339 | { | - | ||||||||||||
340 | int cc = horizontalHeaderItems.count(); | - | ||||||||||||
341 | if (columns < 0 || cc == columns) | - | ||||||||||||
342 | return; | - | ||||||||||||
343 | if (cc < columns) | - | ||||||||||||
344 | insertColumns(qMax(cc, 0), columns - cc); | - | ||||||||||||
345 | else | - | ||||||||||||
346 | removeColumns(qMax(columns, 0), cc - columns); | - | ||||||||||||
347 | } | - | ||||||||||||
348 | - | |||||||||||||
349 | int QTableModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||
350 | { | - | ||||||||||||
351 | return parent.isValid() ? 0 : verticalHeaderItems.count(); | - | ||||||||||||
352 | } | - | ||||||||||||
353 | - | |||||||||||||
354 | int QTableModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||
355 | { | - | ||||||||||||
356 | return parent.isValid() ? 0 : horizontalHeaderItems.count(); | - | ||||||||||||
357 | } | - | ||||||||||||
358 | - | |||||||||||||
359 | QVariant QTableModel::data(const QModelIndex &index, int role) const | - | ||||||||||||
360 | { | - | ||||||||||||
361 | QTableWidgetItem *itm = item(index); | - | ||||||||||||
362 | if (itm) | - | ||||||||||||
363 | return itm->data(role); | - | ||||||||||||
364 | return QVariant(); | - | ||||||||||||
365 | } | - | ||||||||||||
366 | - | |||||||||||||
367 | bool QTableModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||
368 | { | - | ||||||||||||
369 | if (!index.isValid()) | - | ||||||||||||
370 | return false; | - | ||||||||||||
371 | - | |||||||||||||
372 | QTableWidgetItem *itm = item(index); | - | ||||||||||||
373 | if (itm) { | - | ||||||||||||
374 | itm->setData(role, value); | - | ||||||||||||
375 | return true; | - | ||||||||||||
376 | } | - | ||||||||||||
377 | - | |||||||||||||
378 | - | |||||||||||||
379 | if (!value.isValid()) | - | ||||||||||||
380 | return false; | - | ||||||||||||
381 | - | |||||||||||||
382 | QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); | - | ||||||||||||
383 | if (!view) | - | ||||||||||||
384 | return false; | - | ||||||||||||
385 | - | |||||||||||||
386 | itm = createItem(); | - | ||||||||||||
387 | itm->setData(role, value); | - | ||||||||||||
388 | view->setItem(index.row(), index.column(), itm); | - | ||||||||||||
389 | return true; | - | ||||||||||||
390 | } | - | ||||||||||||
391 | - | |||||||||||||
392 | QMap<int, QVariant> QTableModel::itemData(const QModelIndex &index) const | - | ||||||||||||
393 | { | - | ||||||||||||
394 | QMap<int, QVariant> roles; | - | ||||||||||||
395 | QTableWidgetItem *itm = item(index); | - | ||||||||||||
396 | if (itm) { | - | ||||||||||||
397 | for (int i = 0; i < itm->values.count(); ++i) { | - | ||||||||||||
398 | roles.insert(itm->values.at(i).role, | - | ||||||||||||
399 | itm->values.at(i).value); | - | ||||||||||||
400 | } | - | ||||||||||||
401 | } | - | ||||||||||||
402 | return roles; | - | ||||||||||||
403 | } | - | ||||||||||||
404 | - | |||||||||||||
405 | - | |||||||||||||
406 | bool QTableModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) | - | ||||||||||||
407 | { | - | ||||||||||||
408 | if (!index.isValid()) | - | ||||||||||||
409 | return false; | - | ||||||||||||
410 | - | |||||||||||||
411 | QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); | - | ||||||||||||
412 | QTableWidgetItem *itm = item(index); | - | ||||||||||||
413 | if (itm) { | - | ||||||||||||
414 | itm->view = 0; | - | ||||||||||||
415 | bool changed = false; | - | ||||||||||||
416 | for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) { | - | ||||||||||||
417 | if (itm->data(it.key()) != it.value()) { | - | ||||||||||||
418 | itm->setData(it.key(), it.value()); | - | ||||||||||||
419 | changed = true; | - | ||||||||||||
420 | } | - | ||||||||||||
421 | } | - | ||||||||||||
422 | itm->view = view; | - | ||||||||||||
423 | if (changed) | - | ||||||||||||
424 | itemChanged(itm); | - | ||||||||||||
425 | return true; | - | ||||||||||||
426 | } | - | ||||||||||||
427 | - | |||||||||||||
428 | if (!view) | - | ||||||||||||
429 | return false; | - | ||||||||||||
430 | - | |||||||||||||
431 | itm = createItem(); | - | ||||||||||||
432 | for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) | - | ||||||||||||
433 | itm->setData(it.key(), it.value()); | - | ||||||||||||
434 | view->setItem(index.row(), index.column(), itm); | - | ||||||||||||
435 | return true; | - | ||||||||||||
436 | } | - | ||||||||||||
437 | - | |||||||||||||
438 | Qt::ItemFlags QTableModel::flags(const QModelIndex &index) const | - | ||||||||||||
439 | { | - | ||||||||||||
440 | if (!index.isValid()) | - | ||||||||||||
441 | return Qt::ItemIsDropEnabled; | - | ||||||||||||
442 | if (QTableWidgetItem *itm = item(index)) | - | ||||||||||||
443 | return itm->flags(); | - | ||||||||||||
444 | return (Qt::ItemIsEditable | - | ||||||||||||
445 | |Qt::ItemIsSelectable | - | ||||||||||||
446 | |Qt::ItemIsUserCheckable | - | ||||||||||||
447 | |Qt::ItemIsEnabled | - | ||||||||||||
448 | |Qt::ItemIsDragEnabled | - | ||||||||||||
449 | |Qt::ItemIsDropEnabled); | - | ||||||||||||
450 | } | - | ||||||||||||
451 | - | |||||||||||||
452 | void QTableModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||
453 | { | - | ||||||||||||
454 | QVector<QPair<QTableWidgetItem*, int> > sortable; | - | ||||||||||||
455 | QVector<int> unsortable; | - | ||||||||||||
456 | - | |||||||||||||
457 | sortable.reserve(rowCount()); | - | ||||||||||||
458 | unsortable.reserve(rowCount()); | - | ||||||||||||
459 | - | |||||||||||||
460 | for (int row = 0; row < rowCount(); ++row) { | - | ||||||||||||
461 | if (QTableWidgetItem *itm = item(row, column)) | - | ||||||||||||
462 | sortable.append(QPair<QTableWidgetItem*,int>(itm, row)); | - | ||||||||||||
463 | else | - | ||||||||||||
464 | unsortable.append(row); | - | ||||||||||||
465 | } | - | ||||||||||||
466 | - | |||||||||||||
467 | LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan); | - | ||||||||||||
468 | std::stable_sort(sortable.begin(), sortable.end(), compare); | - | ||||||||||||
469 | - | |||||||||||||
470 | QVector<QTableWidgetItem*> sorted_table(tableItems.count()); | - | ||||||||||||
471 | QModelIndexList from; | - | ||||||||||||
472 | QModelIndexList to; | - | ||||||||||||
473 | const int numRows = rowCount(); | - | ||||||||||||
474 | const int numColumns = columnCount(); | - | ||||||||||||
475 | from.reserve(numRows * numColumns); | - | ||||||||||||
476 | to.reserve(numRows * numColumns); | - | ||||||||||||
477 | for (int i = 0; i < numRows; ++i) { | - | ||||||||||||
478 | int r = (i < sortable.count() | - | ||||||||||||
479 | ? sortable.at(i).second | - | ||||||||||||
480 | : unsortable.at(i - sortable.count())); | - | ||||||||||||
481 | for (int c = 0; c < numColumns; ++c) { | - | ||||||||||||
482 | sorted_table[tableIndex(i, c)] = item(r, c); | - | ||||||||||||
483 | from.append(createIndex(r, c)); | - | ||||||||||||
484 | to.append(createIndex(i, c)); | - | ||||||||||||
485 | } | - | ||||||||||||
486 | } | - | ||||||||||||
487 | - | |||||||||||||
488 | layoutAboutToBeChanged(); | - | ||||||||||||
489 | - | |||||||||||||
490 | tableItems = sorted_table; | - | ||||||||||||
491 | changePersistentIndexList(from, to); | - | ||||||||||||
492 | - | |||||||||||||
493 | layoutChanged(); | - | ||||||||||||
494 | } | - | ||||||||||||
495 | void QTableModel::ensureSorted(int column, Qt::SortOrder order, | - | ||||||||||||
496 | int start, int end) | - | ||||||||||||
497 | { | - | ||||||||||||
498 | int count = end - start + 1; | - | ||||||||||||
499 | QVector < QPair<QTableWidgetItem*,int> > sorting; | - | ||||||||||||
500 | sorting.reserve(count); | - | ||||||||||||
501 | for (int row = start; row <= end; ++row) { | - | ||||||||||||
502 | QTableWidgetItem *itm = item(row, column); | - | ||||||||||||
503 | if (itm == 0) { | - | ||||||||||||
504 | - | |||||||||||||
505 | - | |||||||||||||
506 | break; | - | ||||||||||||
507 | } | - | ||||||||||||
508 | sorting.append(QPair<QTableWidgetItem*,int>(itm, row)); | - | ||||||||||||
509 | } | - | ||||||||||||
510 | - | |||||||||||||
511 | LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan); | - | ||||||||||||
512 | std::stable_sort(sorting.begin(), sorting.end(), compare); | - | ||||||||||||
513 | QModelIndexList oldPersistentIndexes, newPersistentIndexes; | - | ||||||||||||
514 | QVector<QTableWidgetItem*> newTable = tableItems; | - | ||||||||||||
515 | QVector<QTableWidgetItem*> newVertical = verticalHeaderItems; | - | ||||||||||||
516 | QVector<QTableWidgetItem*> colItems = columnItems(column); | - | ||||||||||||
517 | QVector<QTableWidgetItem*>::iterator vit = colItems.begin(); | - | ||||||||||||
518 | bool changed = false; | - | ||||||||||||
519 | for (int i = 0; i < sorting.count(); ++i) { | - | ||||||||||||
520 | int oldRow = sorting.at(i).second; | - | ||||||||||||
521 | QTableWidgetItem *item = colItems.at(oldRow); | - | ||||||||||||
522 | colItems.remove(oldRow); | - | ||||||||||||
523 | vit = sortedInsertionIterator(vit, colItems.end(), order, item); | - | ||||||||||||
524 | int newRow = qMax((int)(vit - colItems.begin()), 0); | - | ||||||||||||
525 | if ((newRow < oldRow) && !(*item < *colItems.at(oldRow - 1)) && !(*colItems.at(oldRow - 1) < *item)) | - | ||||||||||||
526 | newRow = oldRow; | - | ||||||||||||
527 | vit = colItems.insert(vit, item); | - | ||||||||||||
528 | if (newRow != oldRow) { | - | ||||||||||||
529 | if (!changed) { | - | ||||||||||||
530 | layoutAboutToBeChanged(); | - | ||||||||||||
531 | oldPersistentIndexes = persistentIndexList(); | - | ||||||||||||
532 | newPersistentIndexes = oldPersistentIndexes; | - | ||||||||||||
533 | changed = true; | - | ||||||||||||
534 | } | - | ||||||||||||
535 | - | |||||||||||||
536 | int cc = columnCount(); | - | ||||||||||||
537 | QVector<QTableWidgetItem*> rowItems(cc); | - | ||||||||||||
538 | for (int j = 0; j < cc; ++j) | - | ||||||||||||
539 | rowItems[j] = newTable.at(tableIndex(oldRow, j)); | - | ||||||||||||
540 | newTable.remove(tableIndex(oldRow, 0), cc); | - | ||||||||||||
541 | newTable.insert(tableIndex(newRow, 0), cc, 0); | - | ||||||||||||
542 | for (int j = 0; j < cc; ++j) | - | ||||||||||||
543 | newTable[tableIndex(newRow, j)] = rowItems.at(j); | - | ||||||||||||
544 | QTableWidgetItem *header = newVertical.at(oldRow); | - | ||||||||||||
545 | newVertical.remove(oldRow); | - | ||||||||||||
546 | newVertical.insert(newRow, header); | - | ||||||||||||
547 | - | |||||||||||||
548 | updateRowIndexes(newPersistentIndexes, oldRow, newRow); | - | ||||||||||||
549 | - | |||||||||||||
550 | for (int j = i + 1; j < sorting.count(); ++j) { | - | ||||||||||||
551 | int otherRow = sorting.at(j).second; | - | ||||||||||||
552 | if (oldRow < otherRow && newRow >= otherRow) | - | ||||||||||||
553 | --sorting[j].second; | - | ||||||||||||
554 | else if (oldRow > otherRow && newRow <= otherRow) | - | ||||||||||||
555 | ++sorting[j].second; | - | ||||||||||||
556 | } | - | ||||||||||||
557 | } | - | ||||||||||||
558 | } | - | ||||||||||||
559 | - | |||||||||||||
560 | if (changed) { | - | ||||||||||||
561 | tableItems = newTable; | - | ||||||||||||
562 | verticalHeaderItems = newVertical; | - | ||||||||||||
563 | changePersistentIndexList(oldPersistentIndexes, | - | ||||||||||||
564 | newPersistentIndexes); | - | ||||||||||||
565 | layoutChanged(); | - | ||||||||||||
566 | } | - | ||||||||||||
567 | } | - | ||||||||||||
568 | - | |||||||||||||
569 | - | |||||||||||||
570 | - | |||||||||||||
571 | - | |||||||||||||
572 | - | |||||||||||||
573 | - | |||||||||||||
574 | QVector<QTableWidgetItem*> QTableModel::columnItems(int column) const | - | ||||||||||||
575 | { | - | ||||||||||||
576 | QVector<QTableWidgetItem*> items; | - | ||||||||||||
577 | int rc = rowCount(); | - | ||||||||||||
578 | items.reserve(rc); | - | ||||||||||||
579 | for (int row = 0; row < rc; ++row) { | - | ||||||||||||
580 | QTableWidgetItem *itm = item(row, column); | - | ||||||||||||
581 | if (itm == 0) { | - | ||||||||||||
582 | - | |||||||||||||
583 | - | |||||||||||||
584 | break; | - | ||||||||||||
585 | } | - | ||||||||||||
586 | items.append(itm); | - | ||||||||||||
587 | } | - | ||||||||||||
588 | return items; | - | ||||||||||||
589 | } | - | ||||||||||||
590 | void QTableModel::updateRowIndexes(QModelIndexList &indexes, | - | ||||||||||||
591 | int movedFromRow, int movedToRow) | - | ||||||||||||
592 | { | - | ||||||||||||
593 | QModelIndexList::iterator it; | - | ||||||||||||
594 | for (it = indexes.begin(); it != indexes.end(); ++it) { | - | ||||||||||||
595 | int oldRow = (*it).row(); | - | ||||||||||||
596 | int newRow = oldRow; | - | ||||||||||||
597 | if (oldRow == movedFromRow) | - | ||||||||||||
598 | newRow = movedToRow; | - | ||||||||||||
599 | else if (movedFromRow < oldRow && movedToRow >= oldRow) | - | ||||||||||||
600 | newRow = oldRow - 1; | - | ||||||||||||
601 | else if (movedFromRow > oldRow && movedToRow <= oldRow) | - | ||||||||||||
602 | newRow = oldRow + 1; | - | ||||||||||||
603 | if (newRow != oldRow) | - | ||||||||||||
604 | *it = index(newRow, (*it).column(), (*it).parent()); | - | ||||||||||||
605 | } | - | ||||||||||||
606 | } | - | ||||||||||||
607 | QVector<QTableWidgetItem*>::iterator QTableModel::sortedInsertionIterator( | - | ||||||||||||
608 | const QVector<QTableWidgetItem*>::iterator &begin, | - | ||||||||||||
609 | const QVector<QTableWidgetItem*>::iterator &end, | - | ||||||||||||
610 | Qt::SortOrder order, QTableWidgetItem *item) | - | ||||||||||||
611 | { | - | ||||||||||||
612 | if (order == Qt::AscendingOrder) | - | ||||||||||||
613 | return std::lower_bound(begin, end, item, QTableModelLessThan()); | - | ||||||||||||
614 | return std::lower_bound(begin, end, item, QTableModelGreaterThan()); | - | ||||||||||||
615 | } | - | ||||||||||||
616 | - | |||||||||||||
617 | bool QTableModel::itemLessThan(const QPair<QTableWidgetItem*,int> &left, | - | ||||||||||||
618 | const QPair<QTableWidgetItem*,int> &right) | - | ||||||||||||
619 | { | - | ||||||||||||
620 | return *(left.first) < *(right.first); | - | ||||||||||||
621 | } | - | ||||||||||||
622 | - | |||||||||||||
623 | bool QTableModel::itemGreaterThan(const QPair<QTableWidgetItem*,int> &left, | - | ||||||||||||
624 | const QPair<QTableWidgetItem*,int> &right) | - | ||||||||||||
625 | { | - | ||||||||||||
626 | return (*(right.first) < *(left .first)); | - | ||||||||||||
627 | } | - | ||||||||||||
628 | - | |||||||||||||
629 | QVariant QTableModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||
630 | { | - | ||||||||||||
631 | if (section < 0) | - | ||||||||||||
632 | return QVariant(); | - | ||||||||||||
633 | - | |||||||||||||
634 | QTableWidgetItem *itm = 0; | - | ||||||||||||
635 | if (orientation == Qt::Horizontal && section < horizontalHeaderItems.count()) | - | ||||||||||||
636 | itm = horizontalHeaderItems.at(section); | - | ||||||||||||
637 | else if (orientation == Qt::Vertical && section < verticalHeaderItems.count()) | - | ||||||||||||
638 | itm = verticalHeaderItems.at(section); | - | ||||||||||||
639 | else | - | ||||||||||||
640 | return QVariant(); | - | ||||||||||||
641 | - | |||||||||||||
642 | if (itm) | - | ||||||||||||
643 | return itm->data(role); | - | ||||||||||||
644 | if (role == Qt::DisplayRole) | - | ||||||||||||
645 | return section + 1; | - | ||||||||||||
646 | return QVariant(); | - | ||||||||||||
647 | } | - | ||||||||||||
648 | - | |||||||||||||
649 | bool QTableModel::setHeaderData(int section, Qt::Orientation orientation, | - | ||||||||||||
650 | const QVariant &value, int role) | - | ||||||||||||
651 | { | - | ||||||||||||
652 | if (section < 0 || | - | ||||||||||||
653 | (orientation == Qt::Horizontal && horizontalHeaderItems.size() <= section) || | - | ||||||||||||
654 | (orientation == Qt::Vertical && verticalHeaderItems.size() <= section)) | - | ||||||||||||
655 | return false; | - | ||||||||||||
656 | - | |||||||||||||
657 | QTableWidgetItem *itm = 0; | - | ||||||||||||
658 | if (orientation == Qt::Horizontal) | - | ||||||||||||
659 | itm = horizontalHeaderItems.at(section); | - | ||||||||||||
660 | else | - | ||||||||||||
661 | itm = verticalHeaderItems.at(section); | - | ||||||||||||
662 | if (itm) { | - | ||||||||||||
663 | itm->setData(role, value); | - | ||||||||||||
664 | return true; | - | ||||||||||||
665 | } | - | ||||||||||||
666 | return false; | - | ||||||||||||
667 | } | - | ||||||||||||
668 | - | |||||||||||||
669 | bool QTableModel::isValid(const QModelIndex &index) const | - | ||||||||||||
670 | { | - | ||||||||||||
671 | return (index.isValid() | - | ||||||||||||
672 | && index.row() < verticalHeaderItems.count() | - | ||||||||||||
673 | && index.column() < horizontalHeaderItems.count()); | - | ||||||||||||
674 | } | - | ||||||||||||
675 | - | |||||||||||||
676 | void QTableModel::clear() | - | ||||||||||||
677 | { | - | ||||||||||||
678 | for (int j = 0; j < verticalHeaderItems.count(); ++j) { | - | ||||||||||||
679 | if (verticalHeaderItems.at(j)) { | - | ||||||||||||
680 | verticalHeaderItems.at(j)->view = 0; | - | ||||||||||||
681 | delete verticalHeaderItems.at(j); | - | ||||||||||||
682 | verticalHeaderItems[j] = 0; | - | ||||||||||||
683 | } | - | ||||||||||||
684 | } | - | ||||||||||||
685 | for (int k = 0; k < horizontalHeaderItems.count(); ++k) { | - | ||||||||||||
686 | if (horizontalHeaderItems.at(k)) { | - | ||||||||||||
687 | horizontalHeaderItems.at(k)->view = 0; | - | ||||||||||||
688 | delete horizontalHeaderItems.at(k); | - | ||||||||||||
689 | horizontalHeaderItems[k] = 0; | - | ||||||||||||
690 | } | - | ||||||||||||
691 | } | - | ||||||||||||
692 | clearContents(); | - | ||||||||||||
693 | } | - | ||||||||||||
694 | - | |||||||||||||
695 | void QTableModel::clearContents() | - | ||||||||||||
696 | { | - | ||||||||||||
697 | beginResetModel(); | - | ||||||||||||
698 | for (int i = 0; i < tableItems.count(); ++i) { | - | ||||||||||||
699 | if (tableItems.at(i)) { | - | ||||||||||||
700 | tableItems.at(i)->view = 0; | - | ||||||||||||
701 | delete tableItems.at(i); | - | ||||||||||||
702 | tableItems[i] = 0; | - | ||||||||||||
703 | } | - | ||||||||||||
704 | } | - | ||||||||||||
705 | endResetModel(); | - | ||||||||||||
706 | } | - | ||||||||||||
707 | - | |||||||||||||
708 | void QTableModel::itemChanged(QTableWidgetItem *item) | - | ||||||||||||
709 | { | - | ||||||||||||
710 | if (!item) | - | ||||||||||||
711 | return; | - | ||||||||||||
712 | if (item->flags() & ItemIsHeaderItem) { | - | ||||||||||||
713 | int row = verticalHeaderItems.indexOf(item); | - | ||||||||||||
714 | if (row >= 0) { | - | ||||||||||||
715 | headerDataChanged(Qt::Vertical, row, row); | - | ||||||||||||
716 | } else { | - | ||||||||||||
717 | int column = horizontalHeaderItems.indexOf(item); | - | ||||||||||||
718 | if (column >= 0) | - | ||||||||||||
719 | headerDataChanged(Qt::Horizontal, column, column); | - | ||||||||||||
720 | } | - | ||||||||||||
721 | } else { | - | ||||||||||||
722 | QModelIndex idx = index(item); | - | ||||||||||||
723 | if (idx.isValid()) | - | ||||||||||||
724 | dataChanged(idx, idx); | - | ||||||||||||
725 | } | - | ||||||||||||
726 | } | - | ||||||||||||
727 | - | |||||||||||||
728 | QTableWidgetItem* QTableModel::createItem() const | - | ||||||||||||
729 | { | - | ||||||||||||
730 | return prototype ? prototype->clone() : new QTableWidgetItem; | - | ||||||||||||
731 | } | - | ||||||||||||
732 | - | |||||||||||||
733 | const QTableWidgetItem *QTableModel::itemPrototype() const | - | ||||||||||||
734 | { | - | ||||||||||||
735 | return prototype; | - | ||||||||||||
736 | } | - | ||||||||||||
737 | - | |||||||||||||
738 | void QTableModel::setItemPrototype(const QTableWidgetItem *item) | - | ||||||||||||
739 | { | - | ||||||||||||
740 | if (prototype != item) { | - | ||||||||||||
741 | delete prototype; | - | ||||||||||||
742 | prototype = item; | - | ||||||||||||
743 | } | - | ||||||||||||
744 | } | - | ||||||||||||
745 | - | |||||||||||||
746 | QStringList QTableModel::mimeTypes() const | - | ||||||||||||
747 | { | - | ||||||||||||
748 | const QTableWidget *view = qobject_cast<const QTableWidget*>(QObject::parent()); | - | ||||||||||||
749 | return (view ? view->mimeTypes() : QStringList()); | - | ||||||||||||
750 | } | - | ||||||||||||
751 | - | |||||||||||||
752 | QMimeData *QTableModel::internalMimeData() const | - | ||||||||||||
753 | { | - | ||||||||||||
754 | return QAbstractTableModel::mimeData(cachedIndexes); | - | ||||||||||||
755 | } | - | ||||||||||||
756 | - | |||||||||||||
757 | QMimeData *QTableModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||
758 | { | - | ||||||||||||
759 | QList<QTableWidgetItem*> items; | - | ||||||||||||
760 | const int indexesCount = indexes.count(); | - | ||||||||||||
761 | items.reserve(indexesCount); | - | ||||||||||||
762 | for (int i = 0; i < indexesCount; ++i) | - | ||||||||||||
763 | items << item(indexes.at(i)); | - | ||||||||||||
764 | const QTableWidget *view = qobject_cast<const QTableWidget*>(QObject::parent()); | - | ||||||||||||
765 | - | |||||||||||||
766 | - | |||||||||||||
767 | - | |||||||||||||
768 | cachedIndexes = indexes; | - | ||||||||||||
769 | QMimeData *mimeData = (view ? view->mimeData(items) : 0); | - | ||||||||||||
770 | cachedIndexes.clear(); | - | ||||||||||||
771 | return mimeData; | - | ||||||||||||
772 | } | - | ||||||||||||
773 | - | |||||||||||||
774 | bool QTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||
775 | int row , int column, const QModelIndex &index) | - | ||||||||||||
776 | { | - | ||||||||||||
777 | if (index.isValid()) { | - | ||||||||||||
778 | row = index.row(); | - | ||||||||||||
779 | column = index.column(); | - | ||||||||||||
780 | }else if (row == -1 || column == -1) { | - | ||||||||||||
781 | row = rowCount(); | - | ||||||||||||
782 | column = 0; | - | ||||||||||||
783 | } | - | ||||||||||||
784 | - | |||||||||||||
785 | QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); | - | ||||||||||||
786 | return (view ? view->dropMimeData(row, column, data, action) : false); | - | ||||||||||||
787 | } | - | ||||||||||||
788 | - | |||||||||||||
789 | Qt::DropActions QTableModel::supportedDropActions() const | - | ||||||||||||
790 | { | - | ||||||||||||
791 | const QTableWidget *view = qobject_cast<const QTableWidget*>(QObject::parent()); | - | ||||||||||||
792 | return (view ? view->supportedDropActions() : Qt::DropActions(Qt::IgnoreAction)); | - | ||||||||||||
793 | } | - | ||||||||||||
794 | QTableWidgetSelectionRange::QTableWidgetSelectionRange() | - | ||||||||||||
795 | : top(-1), left(-1), bottom(-2), right(-2) | - | ||||||||||||
796 | { | - | ||||||||||||
797 | } | - | ||||||||||||
798 | - | |||||||||||||
799 | - | |||||||||||||
800 | - | |||||||||||||
801 | - | |||||||||||||
802 | - | |||||||||||||
803 | - | |||||||||||||
804 | - | |||||||||||||
805 | QTableWidgetSelectionRange::QTableWidgetSelectionRange(int top, int left, int bottom, int right) | - | ||||||||||||
806 | : top(top), left(left), bottom(bottom), right(right) | - | ||||||||||||
807 | { | - | ||||||||||||
808 | } | - | ||||||||||||
809 | - | |||||||||||||
810 | - | |||||||||||||
811 | - | |||||||||||||
812 | - | |||||||||||||
813 | - | |||||||||||||
814 | QTableWidgetSelectionRange::QTableWidgetSelectionRange(const QTableWidgetSelectionRange &other) | - | ||||||||||||
815 | : top(other.top), left(other.left), bottom(other.bottom), right(other.right) | - | ||||||||||||
816 | { | - | ||||||||||||
817 | } | - | ||||||||||||
818 | - | |||||||||||||
819 | - | |||||||||||||
820 | - | |||||||||||||
821 | - | |||||||||||||
822 | QTableWidgetSelectionRange::~QTableWidgetSelectionRange() | - | ||||||||||||
823 | { | - | ||||||||||||
824 | } | - | ||||||||||||
825 | void QTableWidgetItem::setFlags(Qt::ItemFlags aflags) | - | ||||||||||||
826 | { | - | ||||||||||||
827 | itemFlags = aflags; | - | ||||||||||||
828 | if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0)) | - | ||||||||||||
829 | model->itemChanged(this); | - | ||||||||||||
830 | } | - | ||||||||||||
831 | QTableWidgetItem::QTableWidgetItem(int type) | - | ||||||||||||
832 | : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)), | - | ||||||||||||
833 | itemFlags(Qt::ItemIsEditable | - | ||||||||||||
834 | |Qt::ItemIsSelectable | - | ||||||||||||
835 | |Qt::ItemIsUserCheckable | - | ||||||||||||
836 | |Qt::ItemIsEnabled | - | ||||||||||||
837 | |Qt::ItemIsDragEnabled | - | ||||||||||||
838 | |Qt::ItemIsDropEnabled) | - | ||||||||||||
839 | { | - | ||||||||||||
840 | } | - | ||||||||||||
841 | - | |||||||||||||
842 | - | |||||||||||||
843 | - | |||||||||||||
844 | - | |||||||||||||
845 | - | |||||||||||||
846 | - | |||||||||||||
847 | QTableWidgetItem::QTableWidgetItem(const QString &text, int type) | - | ||||||||||||
848 | : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)), | - | ||||||||||||
849 | itemFlags(Qt::ItemIsEditable | - | ||||||||||||
850 | |Qt::ItemIsSelectable | - | ||||||||||||
851 | |Qt::ItemIsUserCheckable | - | ||||||||||||
852 | |Qt::ItemIsEnabled | - | ||||||||||||
853 | |Qt::ItemIsDragEnabled | - | ||||||||||||
854 | |Qt::ItemIsDropEnabled) | - | ||||||||||||
855 | { | - | ||||||||||||
856 | setData(Qt::DisplayRole, text); | - | ||||||||||||
857 | } | - | ||||||||||||
858 | - | |||||||||||||
859 | - | |||||||||||||
860 | - | |||||||||||||
861 | - | |||||||||||||
862 | - | |||||||||||||
863 | - | |||||||||||||
864 | QTableWidgetItem::QTableWidgetItem(const QIcon &icon, const QString &text, int type) | - | ||||||||||||
865 | : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)), | - | ||||||||||||
866 | itemFlags(Qt::ItemIsEditable | - | ||||||||||||
867 | |Qt::ItemIsSelectable | - | ||||||||||||
868 | |Qt::ItemIsUserCheckable | - | ||||||||||||
869 | |Qt::ItemIsEnabled | - | ||||||||||||
870 | |Qt::ItemIsDragEnabled | - | ||||||||||||
871 | |Qt::ItemIsDropEnabled) | - | ||||||||||||
872 | { | - | ||||||||||||
873 | setData(Qt::DecorationRole, icon); | - | ||||||||||||
874 | setData(Qt::DisplayRole, text); | - | ||||||||||||
875 | } | - | ||||||||||||
876 | - | |||||||||||||
877 | - | |||||||||||||
878 | - | |||||||||||||
879 | - | |||||||||||||
880 | QTableWidgetItem::~QTableWidgetItem() | - | ||||||||||||
881 | { | - | ||||||||||||
882 | if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0)) | - | ||||||||||||
883 | model->removeItem(this); | - | ||||||||||||
884 | view = 0; | - | ||||||||||||
885 | delete d; | - | ||||||||||||
886 | } | - | ||||||||||||
887 | - | |||||||||||||
888 | - | |||||||||||||
889 | - | |||||||||||||
890 | - | |||||||||||||
891 | QTableWidgetItem *QTableWidgetItem::clone() const | - | ||||||||||||
892 | { | - | ||||||||||||
893 | return new QTableWidgetItem(*this); | - | ||||||||||||
894 | } | - | ||||||||||||
895 | - | |||||||||||||
896 | - | |||||||||||||
897 | - | |||||||||||||
898 | - | |||||||||||||
899 | - | |||||||||||||
900 | - | |||||||||||||
901 | void QTableWidgetItem::setData(int role, const QVariant &value) | - | ||||||||||||
902 | { | - | ||||||||||||
903 | bool found = false; | - | ||||||||||||
904 | role = (role == Qt::EditRole ? Qt::DisplayRole : role); | - | ||||||||||||
905 | for (int i = 0; i < values.count(); ++i) { | - | ||||||||||||
906 | if (values.at(i).role == role) { | - | ||||||||||||
907 | if (values[i].value == value) | - | ||||||||||||
908 | return; | - | ||||||||||||
909 | - | |||||||||||||
910 | values[i].value = value; | - | ||||||||||||
911 | found = true; | - | ||||||||||||
912 | break; | - | ||||||||||||
913 | } | - | ||||||||||||
914 | } | - | ||||||||||||
915 | if (!found) | - | ||||||||||||
916 | values.append(QWidgetItemData(role, value)); | - | ||||||||||||
917 | if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0)) | - | ||||||||||||
918 | model->itemChanged(this); | - | ||||||||||||
919 | } | - | ||||||||||||
920 | - | |||||||||||||
921 | - | |||||||||||||
922 | - | |||||||||||||
923 | - | |||||||||||||
924 | QVariant QTableWidgetItem::data(int role) const | - | ||||||||||||
925 | { | - | ||||||||||||
926 | role = (role == Qt::EditRole
| 0 | ||||||||||||
927 | for (int i = 0; i <const auto &value : values.count(); ++i) { | - | ||||||||||||
928 | if (valuesvalue
| 0 | ||||||||||||
929 | return never executed: valuesvalue.at(i).value;return value.value; never executed: return value.value; | 0 | ||||||||||||
930 | } never executed: end of block | 0 | ||||||||||||
931 | return never executed: QVariant();return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||
932 | } | - | ||||||||||||
933 | - | |||||||||||||
934 | - | |||||||||||||
935 | - | |||||||||||||
936 | - | |||||||||||||
937 | - | |||||||||||||
938 | bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const | - | ||||||||||||
939 | { | - | ||||||||||||
940 | const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole); | - | ||||||||||||
941 | return QAbstractItemModelPrivate::variantLessThan(v1, v2); | - | ||||||||||||
942 | } | - | ||||||||||||
943 | void QTableWidgetItem::read(QDataStream &in) | - | ||||||||||||
944 | { | - | ||||||||||||
945 | in >> values; | - | ||||||||||||
946 | } | - | ||||||||||||
947 | - | |||||||||||||
948 | - | |||||||||||||
949 | - | |||||||||||||
950 | - | |||||||||||||
951 | - | |||||||||||||
952 | - | |||||||||||||
953 | void QTableWidgetItem::write(QDataStream &out) const | - | ||||||||||||
954 | { | - | ||||||||||||
955 | out << values; | - | ||||||||||||
956 | } | - | ||||||||||||
957 | QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item) | - | ||||||||||||
958 | { | - | ||||||||||||
959 | item.read(in); | - | ||||||||||||
960 | return in; | - | ||||||||||||
961 | } | - | ||||||||||||
962 | QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item) | - | ||||||||||||
963 | { | - | ||||||||||||
964 | item.write(out); | - | ||||||||||||
965 | return out; | - | ||||||||||||
966 | } | - | ||||||||||||
967 | QTableWidgetItem::QTableWidgetItem(const QTableWidgetItem &other) | - | ||||||||||||
968 | : rtti(Type), values(other.values), view(0), | - | ||||||||||||
969 | d(new QTableWidgetItemPrivate(this)), | - | ||||||||||||
970 | itemFlags(other.itemFlags) | - | ||||||||||||
971 | { | - | ||||||||||||
972 | } | - | ||||||||||||
973 | QTableWidgetItem &QTableWidgetItem::operator=(const QTableWidgetItem &other) | - | ||||||||||||
974 | { | - | ||||||||||||
975 | values = other.values; | - | ||||||||||||
976 | itemFlags = other.itemFlags; | - | ||||||||||||
977 | return *this; | - | ||||||||||||
978 | } | - | ||||||||||||
979 | void QTableWidgetPrivate::setup() | - | ||||||||||||
980 | { | - | ||||||||||||
981 | QTableWidget * const q = q_func(); | - | ||||||||||||
982 | - | |||||||||||||
983 | QObject::connect(q, qFlagLocation("2""pressed(QModelIndex)" "\0" __FILE__ ":" "1573""1580"), q, qFlagLocation("1""_q_emitItemPressed(QModelIndex)" "\0" __FILE__ ":" "1573""1580")); | - | ||||||||||||
984 | QObject::connect(q, qFlagLocation("2""clicked(QModelIndex)" "\0" __FILE__ ":" "1574""1581"), q, qFlagLocation("1""_q_emitItemClicked(QModelIndex)" "\0" __FILE__ ":" "1574""1581")); | - | ||||||||||||
985 | QObject::connect(q, qFlagLocation("2""doubleClicked(QModelIndex)" "\0" __FILE__ ":" "1575""1582"), | - | ||||||||||||
986 | q, qFlagLocation("1""_q_emitItemDoubleClicked(QModelIndex)" "\0" __FILE__ ":" "1576""1583")); | - | ||||||||||||
987 | QObject::connect(q, qFlagLocation("2""activated(QModelIndex)" "\0" __FILE__ ":" "1577""1584"), q, qFlagLocation("1""_q_emitItemActivated(QModelIndex)" "\0" __FILE__ ":" "1577""1584")); | - | ||||||||||||
988 | QObject::connect(q, qFlagLocation("2""entered(QModelIndex)" "\0" __FILE__ ":" "1578""1585"), q, qFlagLocation("1""_q_emitItemEntered(QModelIndex)" "\0" __FILE__ ":" "1578""1585")); | - | ||||||||||||
989 | - | |||||||||||||
990 | QObject::connect(model, qFlagLocation("2""dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1580""1587"), | - | ||||||||||||
991 | q, qFlagLocation("1""_q_emitItemChanged(QModelIndex)" "\0" __FILE__ ":" "1581""1588")); | - | ||||||||||||
992 | - | |||||||||||||
993 | QObject::connect(q->selectionModel(), qFlagLocation("2""currentChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1583""1590"), | - | ||||||||||||
994 | q, qFlagLocation("1""_q_emitCurrentItemChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1584""1591")); | - | ||||||||||||
995 | QObject::connect(q->selectionModel(), qFlagLocation("2""selectionChanged(QItemSelection,QItemSelection)" "\0" __FILE__ ":" "1585""1592"), | - | ||||||||||||
996 | q, qFlagLocation("2""itemSelectionChanged()" "\0" __FILE__ ":" "1586""1593")); | - | ||||||||||||
997 | - | |||||||||||||
998 | QObject::connect(model, qFlagLocation("2""dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1588""1595"), | - | ||||||||||||
999 | q, qFlagLocation("1""_q_dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "1589""1596")); | - | ||||||||||||
1000 | QObject::connect(model, qFlagLocation("2""columnsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "1590""1597"), q, qFlagLocation("1""_q_sort()" "\0" __FILE__ ":" "1590""1597")); | - | ||||||||||||
1001 | } | - | ||||||||||||
1002 | - | |||||||||||||
1003 | void QTableWidgetPrivate::_q_emitItemPressed(const QModelIndex &index) | - | ||||||||||||
1004 | { | - | ||||||||||||
1005 | QTableWidget * const q = q_func(); | - | ||||||||||||
1006 | if (QTableWidgetItem *item = tableModel()->item(index)) | - | ||||||||||||
1007 | q->itemPressed(item); | - | ||||||||||||
1008 | q->cellPressed(index.row(), index.column()); | - | ||||||||||||
1009 | } | - | ||||||||||||
1010 | - | |||||||||||||
1011 | void QTableWidgetPrivate::_q_emitItemClicked(const QModelIndex &index) | - | ||||||||||||
1012 | { | - | ||||||||||||
1013 | QTableWidget * const q = q_func(); | - | ||||||||||||
1014 | if (QTableWidgetItem *item = tableModel()->item(index)) | - | ||||||||||||
1015 | q->itemClicked(item); | - | ||||||||||||
1016 | q->cellClicked(index.row(), index.column()); | - | ||||||||||||
1017 | } | - | ||||||||||||
1018 | - | |||||||||||||
1019 | void QTableWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index) | - | ||||||||||||
1020 | { | - | ||||||||||||
1021 | QTableWidget * const q = q_func(); | - | ||||||||||||
1022 | if (QTableWidgetItem *item = tableModel()->item(index)) | - | ||||||||||||
1023 | q->itemDoubleClicked(item); | - | ||||||||||||
1024 | q->cellDoubleClicked(index.row(), index.column()); | - | ||||||||||||
1025 | } | - | ||||||||||||
1026 | - | |||||||||||||
1027 | void QTableWidgetPrivate::_q_emitItemActivated(const QModelIndex &index) | - | ||||||||||||
1028 | { | - | ||||||||||||
1029 | QTableWidget * const q = q_func(); | - | ||||||||||||
1030 | if (QTableWidgetItem *item = tableModel()->item(index)) | - | ||||||||||||
1031 | q->itemActivated(item); | - | ||||||||||||
1032 | q->cellActivated(index.row(), index.column()); | - | ||||||||||||
1033 | } | - | ||||||||||||
1034 | - | |||||||||||||
1035 | void QTableWidgetPrivate::_q_emitItemEntered(const QModelIndex &index) | - | ||||||||||||
1036 | { | - | ||||||||||||
1037 | QTableWidget * const q = q_func(); | - | ||||||||||||
1038 | if (QTableWidgetItem *item = tableModel()->item(index)) | - | ||||||||||||
1039 | q->itemEntered(item); | - | ||||||||||||
1040 | q->cellEntered(index.row(), index.column()); | - | ||||||||||||
1041 | } | - | ||||||||||||
1042 | - | |||||||||||||
1043 | void QTableWidgetPrivate::_q_emitItemChanged(const QModelIndex &index) | - | ||||||||||||
1044 | { | - | ||||||||||||
1045 | QTableWidget * const q = q_func(); | - | ||||||||||||
1046 | if (QTableWidgetItem *item = tableModel()->item(index)) | - | ||||||||||||
1047 | q->itemChanged(item); | - | ||||||||||||
1048 | q->cellChanged(index.row(), index.column()); | - | ||||||||||||
1049 | } | - | ||||||||||||
1050 | - | |||||||||||||
1051 | void QTableWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, | - | ||||||||||||
1052 | const QModelIndex &previous) | - | ||||||||||||
1053 | { | - | ||||||||||||
1054 | QTableWidget * const q = q_func(); | - | ||||||||||||
1055 | QTableWidgetItem *currentItem = tableModel()->item(current); | - | ||||||||||||
1056 | QTableWidgetItem *previousItem = tableModel()->item(previous); | - | ||||||||||||
1057 | if (currentItem || previousItem) | - | ||||||||||||
1058 | q->currentItemChanged(currentItem, previousItem); | - | ||||||||||||
1059 | q->currentCellChanged(current.row(), current.column(), previous.row(), previous.column()); | - | ||||||||||||
1060 | } | - | ||||||||||||
1061 | - | |||||||||||||
1062 | void QTableWidgetPrivate::_q_sort() | - | ||||||||||||
1063 | { | - | ||||||||||||
1064 | if (sortingEnabled) { | - | ||||||||||||
1065 | int column = horizontalHeader->sortIndicatorSection(); | - | ||||||||||||
1066 | Qt::SortOrder order = horizontalHeader->sortIndicatorOrder(); | - | ||||||||||||
1067 | model->sort(column, order); | - | ||||||||||||
1068 | } | - | ||||||||||||
1069 | } | - | ||||||||||||
1070 | - | |||||||||||||
1071 | void QTableWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, | - | ||||||||||||
1072 | const QModelIndex &bottomRight) | - | ||||||||||||
1073 | { | - | ||||||||||||
1074 | if (sortingEnabled && topLeft.isValid() && bottomRight.isValid()) { | - | ||||||||||||
1075 | int column = horizontalHeader->sortIndicatorSection(); | - | ||||||||||||
1076 | if (column >= topLeft.column() && column <= bottomRight.column()) { | - | ||||||||||||
1077 | Qt::SortOrder order = horizontalHeader->sortIndicatorOrder(); | - | ||||||||||||
1078 | tableModel()->ensureSorted(column, order, topLeft.row(), bottomRight.row()); | - | ||||||||||||
1079 | } | - | ||||||||||||
1080 | } | - | ||||||||||||
1081 | } | - | ||||||||||||
1082 | QTableWidget::QTableWidget(QWidget *parent) | - | ||||||||||||
1083 | : QTableView(*new QTableWidgetPrivate, parent) | - | ||||||||||||
1084 | { | - | ||||||||||||
1085 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1086 | QTableView::setModel(new QTableModel(0, 0, this)); | - | ||||||||||||
1087 | d->setup(); | - | ||||||||||||
1088 | } | - | ||||||||||||
1089 | - | |||||||||||||
1090 | - | |||||||||||||
1091 | - | |||||||||||||
1092 | - | |||||||||||||
1093 | QTableWidget::QTableWidget(int rows, int columns, QWidget *parent) | - | ||||||||||||
1094 | : QTableView(*new QTableWidgetPrivate, parent) | - | ||||||||||||
1095 | { | - | ||||||||||||
1096 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1097 | QTableView::setModel(new QTableModel(rows, columns, this)); | - | ||||||||||||
1098 | d->setup(); | - | ||||||||||||
1099 | } | - | ||||||||||||
1100 | - | |||||||||||||
1101 | - | |||||||||||||
1102 | - | |||||||||||||
1103 | - | |||||||||||||
1104 | QTableWidget::~QTableWidget() | - | ||||||||||||
1105 | { | - | ||||||||||||
1106 | } | - | ||||||||||||
1107 | void QTableWidget::setRowCount(int rows) | - | ||||||||||||
1108 | { | - | ||||||||||||
1109 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1110 | d->tableModel()->setRowCount(rows); | - | ||||||||||||
1111 | } | - | ||||||||||||
1112 | - | |||||||||||||
1113 | - | |||||||||||||
1114 | - | |||||||||||||
1115 | - | |||||||||||||
1116 | - | |||||||||||||
1117 | int QTableWidget::rowCount() const | - | ||||||||||||
1118 | { | - | ||||||||||||
1119 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1120 | return d->model->rowCount(); | - | ||||||||||||
1121 | } | - | ||||||||||||
1122 | void QTableWidget::setColumnCount(int columns) | - | ||||||||||||
1123 | { | - | ||||||||||||
1124 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1125 | d->tableModel()->setColumnCount(columns); | - | ||||||||||||
1126 | } | - | ||||||||||||
1127 | - | |||||||||||||
1128 | - | |||||||||||||
1129 | - | |||||||||||||
1130 | - | |||||||||||||
1131 | - | |||||||||||||
1132 | int QTableWidget::columnCount() const | - | ||||||||||||
1133 | { | - | ||||||||||||
1134 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1135 | return d->model->columnCount(); | - | ||||||||||||
1136 | } | - | ||||||||||||
1137 | - | |||||||||||||
1138 | - | |||||||||||||
1139 | - | |||||||||||||
1140 | - | |||||||||||||
1141 | int QTableWidget::row(const QTableWidgetItem *item) const | - | ||||||||||||
1142 | { | - | ||||||||||||
1143 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1144 | return d->tableModel()->index(item).row(); | - | ||||||||||||
1145 | } | - | ||||||||||||
1146 | - | |||||||||||||
1147 | - | |||||||||||||
1148 | - | |||||||||||||
1149 | - | |||||||||||||
1150 | int QTableWidget::column(const QTableWidgetItem *item) const | - | ||||||||||||
1151 | { | - | ||||||||||||
1152 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1153 | return d->tableModel()->index(item).column(); | - | ||||||||||||
1154 | } | - | ||||||||||||
1155 | QTableWidgetItem *QTableWidget::item(int row, int column) const | - | ||||||||||||
1156 | { | - | ||||||||||||
1157 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1158 | return d->tableModel()->item(row, column); | - | ||||||||||||
1159 | } | - | ||||||||||||
1160 | void QTableWidget::setItem(int row, int column, QTableWidgetItem *item) | - | ||||||||||||
1161 | { | - | ||||||||||||
1162 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1163 | if (item
| 0 | ||||||||||||
1164 | if (__builtin_expect(!!(
| 0 | ||||||||||||
1165 | QMessageLogger(__FILE__, 19621969, __PRETTY_FUNCTION__).warning("QTableWidget: cannot insert an item that is already owned by another QTableWidget"); | - | ||||||||||||
1166 | } never executed: else {end of block | 0 | ||||||||||||
1167 | item->view = this; | - | ||||||||||||
1168 | d->tableModel()->setItem(row, column, item); | - | ||||||||||||
1169 | } never executed: end of block | 0 | ||||||||||||
1170 | } else { | - | ||||||||||||
1171 | delete takeItem(row, column); | - | ||||||||||||
1172 | } never executed: end of block | 0 | ||||||||||||
1173 | } | - | ||||||||||||
1174 | - | |||||||||||||
1175 | - | |||||||||||||
1176 | - | |||||||||||||
1177 | - | |||||||||||||
1178 | QTableWidgetItem *QTableWidget::takeItem(int row, int column) | - | ||||||||||||
1179 | { | - | ||||||||||||
1180 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1181 | QTableWidgetItem *item = d->tableModel()->takeItem(row, column); | - | ||||||||||||
1182 | if (item) | - | ||||||||||||
1183 | item->view = 0; | - | ||||||||||||
1184 | return item; | - | ||||||||||||
1185 | } | - | ||||||||||||
1186 | - | |||||||||||||
1187 | - | |||||||||||||
1188 | - | |||||||||||||
1189 | - | |||||||||||||
1190 | QTableWidgetItem *QTableWidget::verticalHeaderItem(int row) const | - | ||||||||||||
1191 | { | - | ||||||||||||
1192 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1193 | return d->tableModel()->verticalHeaderItem(row); | - | ||||||||||||
1194 | } | - | ||||||||||||
1195 | - | |||||||||||||
1196 | - | |||||||||||||
1197 | - | |||||||||||||
1198 | - | |||||||||||||
1199 | void QTableWidget::setVerticalHeaderItem(int row, QTableWidgetItem *item) | - | ||||||||||||
1200 | { | - | ||||||||||||
1201 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1202 | if (item) { | - | ||||||||||||
1203 | item->view = this; | - | ||||||||||||
1204 | d->tableModel()->setVerticalHeaderItem(row, item); | - | ||||||||||||
1205 | } else { | - | ||||||||||||
1206 | delete takeVerticalHeaderItem(row); | - | ||||||||||||
1207 | } | - | ||||||||||||
1208 | } | - | ||||||||||||
1209 | - | |||||||||||||
1210 | - | |||||||||||||
1211 | - | |||||||||||||
1212 | - | |||||||||||||
1213 | - | |||||||||||||
1214 | QTableWidgetItem *QTableWidget::takeVerticalHeaderItem(int row) | - | ||||||||||||
1215 | { | - | ||||||||||||
1216 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1217 | QTableWidgetItem *itm = d->tableModel()->takeVerticalHeaderItem(row); | - | ||||||||||||
1218 | if (itm) | - | ||||||||||||
1219 | itm->view = 0; | - | ||||||||||||
1220 | return itm; | - | ||||||||||||
1221 | } | - | ||||||||||||
1222 | - | |||||||||||||
1223 | - | |||||||||||||
1224 | - | |||||||||||||
1225 | - | |||||||||||||
1226 | - | |||||||||||||
1227 | QTableWidgetItem *QTableWidget::horizontalHeaderItem(int column) const | - | ||||||||||||
1228 | { | - | ||||||||||||
1229 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1230 | return d->tableModel()->horizontalHeaderItem(column); | - | ||||||||||||
1231 | } | - | ||||||||||||
1232 | - | |||||||||||||
1233 | - | |||||||||||||
1234 | - | |||||||||||||
1235 | - | |||||||||||||
1236 | - | |||||||||||||
1237 | - | |||||||||||||
1238 | void QTableWidget::setHorizontalHeaderItem(int column, QTableWidgetItem *item) | - | ||||||||||||
1239 | { | - | ||||||||||||
1240 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1241 | if (item) { | - | ||||||||||||
1242 | item->view = this; | - | ||||||||||||
1243 | d->tableModel()->setHorizontalHeaderItem(column, item); | - | ||||||||||||
1244 | } else { | - | ||||||||||||
1245 | delete takeHorizontalHeaderItem(column); | - | ||||||||||||
1246 | } | - | ||||||||||||
1247 | } | - | ||||||||||||
1248 | - | |||||||||||||
1249 | - | |||||||||||||
1250 | - | |||||||||||||
1251 | - | |||||||||||||
1252 | - | |||||||||||||
1253 | QTableWidgetItem *QTableWidget::takeHorizontalHeaderItem(int column) | - | ||||||||||||
1254 | { | - | ||||||||||||
1255 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1256 | QTableWidgetItem *itm = d->tableModel()->takeHorizontalHeaderItem(column); | - | ||||||||||||
1257 | if (itm) | - | ||||||||||||
1258 | itm->view = 0; | - | ||||||||||||
1259 | return itm; | - | ||||||||||||
1260 | } | - | ||||||||||||
1261 | - | |||||||||||||
1262 | - | |||||||||||||
1263 | - | |||||||||||||
1264 | - | |||||||||||||
1265 | void QTableWidget::setVerticalHeaderLabels(const QStringList &labels) | - | ||||||||||||
1266 | { | - | ||||||||||||
1267 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1268 | QTableModel *model = d->tableModel(); | - | ||||||||||||
1269 | QTableWidgetItem *item = 0; | - | ||||||||||||
1270 | for (int i = 0; i < model->rowCount() && i < labels.count(); ++i) { | - | ||||||||||||
1271 | item = model->verticalHeaderItem(i); | - | ||||||||||||
1272 | if (!item) { | - | ||||||||||||
1273 | item = model->createItem(); | - | ||||||||||||
1274 | setVerticalHeaderItem(i, item); | - | ||||||||||||
1275 | } | - | ||||||||||||
1276 | item->setText(labels.at(i)); | - | ||||||||||||
1277 | } | - | ||||||||||||
1278 | } | - | ||||||||||||
1279 | - | |||||||||||||
1280 | - | |||||||||||||
1281 | - | |||||||||||||
1282 | - | |||||||||||||
1283 | void QTableWidget::setHorizontalHeaderLabels(const QStringList &labels) | - | ||||||||||||
1284 | { | - | ||||||||||||
1285 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1286 | QTableModel *model = d->tableModel(); | - | ||||||||||||
1287 | QTableWidgetItem *item = 0; | - | ||||||||||||
1288 | for (int i = 0; i < model->columnCount() && i < labels.count(); ++i) { | - | ||||||||||||
1289 | item = model->horizontalHeaderItem(i); | - | ||||||||||||
1290 | if (!item) { | - | ||||||||||||
1291 | item = model->createItem(); | - | ||||||||||||
1292 | setHorizontalHeaderItem(i, item); | - | ||||||||||||
1293 | } | - | ||||||||||||
1294 | item->setText(labels.at(i)); | - | ||||||||||||
1295 | } | - | ||||||||||||
1296 | } | - | ||||||||||||
1297 | - | |||||||||||||
1298 | - | |||||||||||||
1299 | - | |||||||||||||
1300 | - | |||||||||||||
1301 | - | |||||||||||||
1302 | - | |||||||||||||
1303 | int QTableWidget::currentRow() const | - | ||||||||||||
1304 | { | - | ||||||||||||
1305 | return currentIndex().row(); | - | ||||||||||||
1306 | } | - | ||||||||||||
1307 | - | |||||||||||||
1308 | - | |||||||||||||
1309 | - | |||||||||||||
1310 | - | |||||||||||||
1311 | - | |||||||||||||
1312 | - | |||||||||||||
1313 | int QTableWidget::currentColumn() const | - | ||||||||||||
1314 | { | - | ||||||||||||
1315 | return currentIndex().column(); | - | ||||||||||||
1316 | } | - | ||||||||||||
1317 | - | |||||||||||||
1318 | - | |||||||||||||
1319 | - | |||||||||||||
1320 | - | |||||||||||||
1321 | - | |||||||||||||
1322 | - | |||||||||||||
1323 | QTableWidgetItem *QTableWidget::currentItem() const | - | ||||||||||||
1324 | { | - | ||||||||||||
1325 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1326 | return d->tableModel()->item(currentIndex()); | - | ||||||||||||
1327 | } | - | ||||||||||||
1328 | void QTableWidget::setCurrentItem(QTableWidgetItem *item) | - | ||||||||||||
1329 | { | - | ||||||||||||
1330 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1331 | setCurrentIndex(d->tableModel()->index(item)); | - | ||||||||||||
1332 | } | - | ||||||||||||
1333 | void QTableWidget::setCurrentItem(QTableWidgetItem *item, QItemSelectionModel::SelectionFlags command) | - | ||||||||||||
1334 | { | - | ||||||||||||
1335 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1336 | d->selectionModel->setCurrentIndex(d->tableModel()->index(item), command); | - | ||||||||||||
1337 | } | - | ||||||||||||
1338 | void QTableWidget::setCurrentCell(int row, int column) | - | ||||||||||||
1339 | { | - | ||||||||||||
1340 | setCurrentIndex(model()->index(row, column, QModelIndex())); | - | ||||||||||||
1341 | } | - | ||||||||||||
1342 | void QTableWidget::setCurrentCell(int row, int column, QItemSelectionModel::SelectionFlags command) | - | ||||||||||||
1343 | { | - | ||||||||||||
1344 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1345 | d->selectionModel->setCurrentIndex(model()->index(row, column, QModelIndex()), command); | - | ||||||||||||
1346 | } | - | ||||||||||||
1347 | - | |||||||||||||
1348 | - | |||||||||||||
1349 | - | |||||||||||||
1350 | - | |||||||||||||
1351 | void QTableWidget::sortItems(int column, Qt::SortOrder order) | - | ||||||||||||
1352 | { | - | ||||||||||||
1353 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1354 | d->model->sort(column, order); | - | ||||||||||||
1355 | horizontalHeader()->setSortIndicator(column, order); | - | ||||||||||||
1356 | } | - | ||||||||||||
1357 | - | |||||||||||||
1358 | - | |||||||||||||
1359 | - | |||||||||||||
1360 | - | |||||||||||||
1361 | void QTableWidget::setSortingEnabled(bool enable) | - | ||||||||||||
1362 | { | - | ||||||||||||
1363 | QTableView::setSortingEnabled(enable); | - | ||||||||||||
1364 | } | - | ||||||||||||
1365 | - | |||||||||||||
1366 | - | |||||||||||||
1367 | - | |||||||||||||
1368 | - | |||||||||||||
1369 | bool QTableWidget::isSortingEnabled() const | - | ||||||||||||
1370 | { | - | ||||||||||||
1371 | return QTableView::isSortingEnabled(); | - | ||||||||||||
1372 | } | - | ||||||||||||
1373 | - | |||||||||||||
1374 | - | |||||||||||||
1375 | - | |||||||||||||
1376 | - | |||||||||||||
1377 | - | |||||||||||||
1378 | void QTableWidget::editItem(QTableWidgetItem *item) | - | ||||||||||||
1379 | { | - | ||||||||||||
1380 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1381 | if (!item) | - | ||||||||||||
1382 | return; | - | ||||||||||||
1383 | edit(d->tableModel()->index(item)); | - | ||||||||||||
1384 | } | - | ||||||||||||
1385 | - | |||||||||||||
1386 | - | |||||||||||||
1387 | - | |||||||||||||
1388 | - | |||||||||||||
1389 | - | |||||||||||||
1390 | - | |||||||||||||
1391 | void QTableWidget::openPersistentEditor(QTableWidgetItem *item) | - | ||||||||||||
1392 | { | - | ||||||||||||
1393 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1394 | if (!item) | - | ||||||||||||
1395 | return; | - | ||||||||||||
1396 | QModelIndex index = d->tableModel()->index(item); | - | ||||||||||||
1397 | QAbstractItemView::openPersistentEditor(index); | - | ||||||||||||
1398 | } | - | ||||||||||||
1399 | - | |||||||||||||
1400 | - | |||||||||||||
1401 | - | |||||||||||||
1402 | - | |||||||||||||
1403 | - | |||||||||||||
1404 | - | |||||||||||||
1405 | void QTableWidget::closePersistentEditor(QTableWidgetItem *item) | - | ||||||||||||
1406 | { | - | ||||||||||||
1407 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1408 | if (!item) | - | ||||||||||||
1409 | return; | - | ||||||||||||
1410 | QModelIndex index = d->tableModel()->index(item); | - | ||||||||||||
1411 | QAbstractItemView::closePersistentEditor(index); | - | ||||||||||||
1412 | } | - | ||||||||||||
1413 | QWidget *QTableWidget::cellWidget(int row, int column) const | - | ||||||||||||
1414 | { | - | ||||||||||||
1415 | QModelIndex index = model()->index(row, column, QModelIndex()); | - | ||||||||||||
1416 | return QAbstractItemView::indexWidget(index); | - | ||||||||||||
1417 | } | - | ||||||||||||
1418 | void QTableWidget::setCellWidget(int row, int column, QWidget *widget) | - | ||||||||||||
1419 | { | - | ||||||||||||
1420 | QModelIndex index = model()->index(row, column, QModelIndex()); | - | ||||||||||||
1421 | QAbstractItemView::setIndexWidget(index, widget); | - | ||||||||||||
1422 | } | - | ||||||||||||
1423 | bool QTableWidget::isItemSelected(const QTableWidgetItem *item) const | - | ||||||||||||
1424 | { | - | ||||||||||||
1425 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1426 | QModelIndex index = d->tableModel()->index(item); | - | ||||||||||||
1427 | return selectionModel()->isSelected(index); | - | ||||||||||||
1428 | } | - | ||||||||||||
1429 | void QTableWidget::setItemSelected(const QTableWidgetItem *item, bool select) | - | ||||||||||||
1430 | { | - | ||||||||||||
1431 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1432 | QModelIndex index = d->tableModel()->index(item); | - | ||||||||||||
1433 | selectionModel()->select(index, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect); | - | ||||||||||||
1434 | } | - | ||||||||||||
1435 | - | |||||||||||||
1436 | - | |||||||||||||
1437 | - | |||||||||||||
1438 | - | |||||||||||||
1439 | void QTableWidget::setRangeSelected(const QTableWidgetSelectionRange &range, bool select) | - | ||||||||||||
1440 | { | - | ||||||||||||
1441 | if (!model()->hasIndex(range.topRow(), range.leftColumn(), rootIndex()) || | - | ||||||||||||
1442 | !model()->hasIndex(range.bottomRow(), range.rightColumn(), rootIndex())) | - | ||||||||||||
1443 | return; | - | ||||||||||||
1444 | - | |||||||||||||
1445 | QModelIndex topLeft = model()->index(range.topRow(), range.leftColumn(), rootIndex()); | - | ||||||||||||
1446 | QModelIndex bottomRight = model()->index(range.bottomRow(), range.rightColumn(), rootIndex()); | - | ||||||||||||
1447 | - | |||||||||||||
1448 | selectionModel()->select(QItemSelection(topLeft, bottomRight), | - | ||||||||||||
1449 | select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect); | - | ||||||||||||
1450 | } | - | ||||||||||||
1451 | - | |||||||||||||
1452 | - | |||||||||||||
1453 | - | |||||||||||||
1454 | - | |||||||||||||
1455 | - | |||||||||||||
1456 | - | |||||||||||||
1457 | - | |||||||||||||
1458 | QList<QTableWidgetSelectionRange> QTableWidget::selectedRanges() const | - | ||||||||||||
1459 | { | - | ||||||||||||
1460 | const QList<QItemSelectionRange> ranges = selectionModel()->selection(); | - | ||||||||||||
1461 | QList<QTableWidgetSelectionRange> result; | - | ||||||||||||
1462 | const int rangesCount = ranges.count(); | - | ||||||||||||
1463 | result.reserve(rangesCount); | - | ||||||||||||
1464 | for (int i = 0; i < rangesCount; ++i) | - | ||||||||||||
1465 | result.append(QTableWidgetSelectionRange(ranges.at(i).top(), | - | ||||||||||||
1466 | ranges.at(i).left(), | - | ||||||||||||
1467 | ranges.at(i).bottom(), | - | ||||||||||||
1468 | ranges.at(i).right())); | - | ||||||||||||
1469 | return result; | - | ||||||||||||
1470 | } | - | ||||||||||||
1471 | QList<QTableWidgetItem*> QTableWidget::selectedItems() const | - | ||||||||||||
1472 | { | - | ||||||||||||
1473 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1474 | const QModelIndexList indexes = selectionModel()->selectedIndexes(); | - | ||||||||||||
1475 | QList<QTableWidgetItem*> items; | - | ||||||||||||
1476 | for (int i = 0; i <const auto &index : indexes.count(); ++i) { | - | ||||||||||||
1477 | QModelIndex index = indexes.at(i);if (isIndexHidden(index)
| 0 | ||||||||||||
1478 | continue; never executed: continue; | 0 | ||||||||||||
1479 | QTableWidgetItem *item = d->tableModel()->item(index); | - | ||||||||||||
1480 | if (item
| 0 | ||||||||||||
1481 | items.append(item); never executed: items.append(item); | 0 | ||||||||||||
1482 | } never executed: end of block | 0 | ||||||||||||
1483 | return never executed: items;return items; never executed: return items; | 0 | ||||||||||||
1484 | } | - | ||||||||||||
1485 | - | |||||||||||||
1486 | - | |||||||||||||
1487 | - | |||||||||||||
1488 | - | |||||||||||||
1489 | - | |||||||||||||
1490 | QList<QTableWidgetItem*> QTableWidget::findItems(const QString &text, Qt::MatchFlags flags) const | - | ||||||||||||
1491 | { | - | ||||||||||||
1492 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1493 | QModelIndexList indexes; | - | ||||||||||||
1494 | for (int column = 0; column < columnCount(); ++column) | - | ||||||||||||
1495 | indexes += d->model->match(model()->index(0, column, QModelIndex()), | - | ||||||||||||
1496 | Qt::DisplayRole, text, -1, flags); | - | ||||||||||||
1497 | QList<QTableWidgetItem*> items; | - | ||||||||||||
1498 | const int indexCount = indexes.size(); | - | ||||||||||||
1499 | items.reserve(indexCount); | - | ||||||||||||
1500 | for (int i = 0; i < indexCount; ++i) | - | ||||||||||||
1501 | items.append(d->tableModel()->item(indexes.at(i))); | - | ||||||||||||
1502 | return items; | - | ||||||||||||
1503 | } | - | ||||||||||||
1504 | - | |||||||||||||
1505 | - | |||||||||||||
1506 | - | |||||||||||||
1507 | - | |||||||||||||
1508 | - | |||||||||||||
1509 | int QTableWidget::visualRow(int logicalRow) const | - | ||||||||||||
1510 | { | - | ||||||||||||
1511 | return verticalHeader()->visualIndex(logicalRow); | - | ||||||||||||
1512 | } | - | ||||||||||||
1513 | - | |||||||||||||
1514 | - | |||||||||||||
1515 | - | |||||||||||||
1516 | - | |||||||||||||
1517 | - | |||||||||||||
1518 | int QTableWidget::visualColumn(int logicalColumn) const | - | ||||||||||||
1519 | { | - | ||||||||||||
1520 | return horizontalHeader()->visualIndex(logicalColumn); | - | ||||||||||||
1521 | } | - | ||||||||||||
1522 | QTableWidgetItem *QTableWidget::itemAt(const QPoint &p) const | - | ||||||||||||
1523 | { | - | ||||||||||||
1524 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1525 | return d->tableModel()->item(indexAt(p)); | - | ||||||||||||
1526 | } | - | ||||||||||||
1527 | - | |||||||||||||
1528 | - | |||||||||||||
1529 | - | |||||||||||||
1530 | - | |||||||||||||
1531 | QRect QTableWidget::visualItemRect(const QTableWidgetItem *item) const | - | ||||||||||||
1532 | { | - | ||||||||||||
1533 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1534 | if (!item) | - | ||||||||||||
1535 | return QRect(); | - | ||||||||||||
1536 | QModelIndex index = d->tableModel()->index(const_cast<QTableWidgetItem*>(item)); | - | ||||||||||||
1537 | ((!(index.isValid())) ? qt_assert("index.isValid()",__FILE__,24362442) : qt_noop()); | - | ||||||||||||
1538 | return visualRect(index); | - | ||||||||||||
1539 | } | - | ||||||||||||
1540 | - | |||||||||||||
1541 | - | |||||||||||||
1542 | - | |||||||||||||
1543 | - | |||||||||||||
1544 | - | |||||||||||||
1545 | - | |||||||||||||
1546 | - | |||||||||||||
1547 | void QTableWidget::scrollToItem(const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint) | - | ||||||||||||
1548 | { | - | ||||||||||||
1549 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1550 | if (!item) | - | ||||||||||||
1551 | return; | - | ||||||||||||
1552 | QModelIndex index = d->tableModel()->index(const_cast<QTableWidgetItem*>(item)); | - | ||||||||||||
1553 | ((!(index.isValid())) ? qt_assert("index.isValid()",__FILE__,24522458) : qt_noop()); | - | ||||||||||||
1554 | QTableView::scrollTo(index, hint); | - | ||||||||||||
1555 | } | - | ||||||||||||
1556 | - | |||||||||||||
1557 | - | |||||||||||||
1558 | - | |||||||||||||
1559 | - | |||||||||||||
1560 | - | |||||||||||||
1561 | - | |||||||||||||
1562 | const QTableWidgetItem *QTableWidget::itemPrototype() const | - | ||||||||||||
1563 | { | - | ||||||||||||
1564 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1565 | return d->tableModel()->itemPrototype(); | - | ||||||||||||
1566 | } | - | ||||||||||||
1567 | void QTableWidget::setItemPrototype(const QTableWidgetItem *item) | - | ||||||||||||
1568 | { | - | ||||||||||||
1569 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1570 | d->tableModel()->setItemPrototype(item); | - | ||||||||||||
1571 | } | - | ||||||||||||
1572 | - | |||||||||||||
1573 | - | |||||||||||||
1574 | - | |||||||||||||
1575 | - | |||||||||||||
1576 | void QTableWidget::insertRow(int row) | - | ||||||||||||
1577 | { | - | ||||||||||||
1578 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1579 | d->tableModel()->insertRows(row); | - | ||||||||||||
1580 | } | - | ||||||||||||
1581 | - | |||||||||||||
1582 | - | |||||||||||||
1583 | - | |||||||||||||
1584 | - | |||||||||||||
1585 | void QTableWidget::insertColumn(int column) | - | ||||||||||||
1586 | { | - | ||||||||||||
1587 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1588 | d->tableModel()->insertColumns(column); | - | ||||||||||||
1589 | } | - | ||||||||||||
1590 | - | |||||||||||||
1591 | - | |||||||||||||
1592 | - | |||||||||||||
1593 | - | |||||||||||||
1594 | void QTableWidget::removeRow(int row) | - | ||||||||||||
1595 | { | - | ||||||||||||
1596 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1597 | d->tableModel()->removeRows(row); | - | ||||||||||||
1598 | } | - | ||||||||||||
1599 | - | |||||||||||||
1600 | - | |||||||||||||
1601 | - | |||||||||||||
1602 | - | |||||||||||||
1603 | void QTableWidget::removeColumn(int column) | - | ||||||||||||
1604 | { | - | ||||||||||||
1605 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1606 | d->tableModel()->removeColumns(column); | - | ||||||||||||
1607 | } | - | ||||||||||||
1608 | void QTableWidget::clear() | - | ||||||||||||
1609 | { | - | ||||||||||||
1610 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1611 | selectionModel()->clear(); | - | ||||||||||||
1612 | d->tableModel()->clear(); | - | ||||||||||||
1613 | } | - | ||||||||||||
1614 | void QTableWidget::clearContents() | - | ||||||||||||
1615 | { | - | ||||||||||||
1616 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1617 | selectionModel()->clear(); | - | ||||||||||||
1618 | d->tableModel()->clearContents(); | - | ||||||||||||
1619 | } | - | ||||||||||||
1620 | - | |||||||||||||
1621 | - | |||||||||||||
1622 | - | |||||||||||||
1623 | - | |||||||||||||
1624 | - | |||||||||||||
1625 | - | |||||||||||||
1626 | - | |||||||||||||
1627 | QStringList QTableWidget::mimeTypes() const | - | ||||||||||||
1628 | { | - | ||||||||||||
1629 | return d_func()->tableModel()->QAbstractTableModel::mimeTypes(); | - | ||||||||||||
1630 | } | - | ||||||||||||
1631 | QMimeData *QTableWidget::mimeData(const QList<QTableWidgetItem*> items) const | - | ||||||||||||
1632 | - | |||||||||||||
1633 | { | - | ||||||||||||
1634 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1635 | - | |||||||||||||
1636 | QModelIndexList &cachedIndexes = d->tableModel()->cachedIndexes; | - | ||||||||||||
1637 | - | |||||||||||||
1638 | - | |||||||||||||
1639 | if (cachedIndexes.isEmpty()) { | - | ||||||||||||
1640 | cachedIndexes.reserve(items.count()); | - | ||||||||||||
1641 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(items)>::type> _container_((items)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QTableWidgetItem *item = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||
1642 | cachedIndexes << indexFromItem(item); | - | ||||||||||||
1643 | - | |||||||||||||
1644 | QMimeData *result = d->tableModel()->internalMimeData(); | - | ||||||||||||
1645 | - | |||||||||||||
1646 | cachedIndexes.clear(); | - | ||||||||||||
1647 | return result; | - | ||||||||||||
1648 | } | - | ||||||||||||
1649 | - | |||||||||||||
1650 | return d->tableModel()->internalMimeData(); | - | ||||||||||||
1651 | } | - | ||||||||||||
1652 | bool QTableWidget::dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action) | - | ||||||||||||
1653 | { | - | ||||||||||||
1654 | QModelIndex idx; | - | ||||||||||||
1655 | - | |||||||||||||
1656 | if (dropIndicatorPosition() == QAbstractItemView::OnItem) { | - | ||||||||||||
1657 | - | |||||||||||||
1658 | idx = model()->index(row, column); | - | ||||||||||||
1659 | row = -1; | - | ||||||||||||
1660 | column = -1; | - | ||||||||||||
1661 | } | - | ||||||||||||
1662 | - | |||||||||||||
1663 | return d_func()->tableModel()->QAbstractTableModel::dropMimeData(data, action , row, column, idx); | - | ||||||||||||
1664 | } | - | ||||||||||||
1665 | - | |||||||||||||
1666 | - | |||||||||||||
1667 | - | |||||||||||||
1668 | - | |||||||||||||
1669 | - | |||||||||||||
1670 | - | |||||||||||||
1671 | Qt::DropActions QTableWidget::supportedDropActions() const | - | ||||||||||||
1672 | { | - | ||||||||||||
1673 | return d_func()->tableModel()->QAbstractTableModel::supportedDropActions() | Qt::MoveAction; | - | ||||||||||||
1674 | } | - | ||||||||||||
1675 | - | |||||||||||||
1676 | - | |||||||||||||
1677 | - | |||||||||||||
1678 | - | |||||||||||||
1679 | - | |||||||||||||
1680 | - | |||||||||||||
1681 | - | |||||||||||||
1682 | QList<QTableWidgetItem*> QTableWidget::items(const QMimeData *data) const | - | ||||||||||||
1683 | { | - | ||||||||||||
1684 | const QTableWidgetMimeData *twd = qobject_cast<const QTableWidgetMimeData*>(data); | - | ||||||||||||
1685 | if (twd) | - | ||||||||||||
1686 | return twd->items; | - | ||||||||||||
1687 | return QList<QTableWidgetItem*>(); | - | ||||||||||||
1688 | } | - | ||||||||||||
1689 | - | |||||||||||||
1690 | - | |||||||||||||
1691 | - | |||||||||||||
1692 | - | |||||||||||||
1693 | - | |||||||||||||
1694 | QModelIndex QTableWidget::indexFromItem(QTableWidgetItem *item) const | - | ||||||||||||
1695 | { | - | ||||||||||||
1696 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1697 | return d->tableModel()->index(item); | - | ||||||||||||
1698 | } | - | ||||||||||||
1699 | - | |||||||||||||
1700 | - | |||||||||||||
1701 | - | |||||||||||||
1702 | - | |||||||||||||
1703 | - | |||||||||||||
1704 | QTableWidgetItem *QTableWidget::itemFromIndex(const QModelIndex &index) const | - | ||||||||||||
1705 | { | - | ||||||||||||
1706 | const QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1707 | return d->tableModel()->item(index); | - | ||||||||||||
1708 | } | - | ||||||||||||
1709 | - | |||||||||||||
1710 | - | |||||||||||||
1711 | - | |||||||||||||
1712 | - | |||||||||||||
1713 | void QTableWidget::setModel(QAbstractItemModel * ) | - | ||||||||||||
1714 | { | - | ||||||||||||
1715 | ((!(!"QTableWidget::setModel() - Changing the model of the QTableWidget is not allowed.")) ? qt_assert("!\"QTableWidget::setModel() - Changing the model of the QTableWidget is not allowed.\"",__FILE__,26662672) : qt_noop()); | - | ||||||||||||
1716 | } | - | ||||||||||||
1717 | - | |||||||||||||
1718 | - | |||||||||||||
1719 | bool QTableWidget::event(QEvent *e) | - | ||||||||||||
1720 | { | - | ||||||||||||
1721 | return QTableView::event(e); | - | ||||||||||||
1722 | } | - | ||||||||||||
1723 | - | |||||||||||||
1724 | - | |||||||||||||
1725 | - | |||||||||||||
1726 | void QTableWidget::dropEvent(QDropEvent *event) { | - | ||||||||||||
1727 | QTableWidgetPrivate * const d = d_func(); | - | ||||||||||||
1728 | if (event->source() == this
| 0 | ||||||||||||
1729 | dragDropMode() == QAbstractItemView::InternalMove
| 0 | ||||||||||||
1730 | QModelIndex topIndex; | - | ||||||||||||
1731 | int col = -1; | - | ||||||||||||
1732 | int row = -1; | - | ||||||||||||
1733 | if (d->dropOn(event, &row, &col, &topIndex)
| 0 | ||||||||||||
1734 | const QModelIndexList indexes = selectedIndexes(); | - | ||||||||||||
1735 | int top = 2147483647; | - | ||||||||||||
1736 | int left = 2147483647; | - | ||||||||||||
1737 | for (int i = 0; i <const auto &index : indexes.count(); ++i) { | - | ||||||||||||
1738 | top = qMin(indexesindex.at(i).row(), top); | - | ||||||||||||
1739 | left = qMin(indexesindex.at(i).column(), left); | - | ||||||||||||
1740 | } never executed: end of block | 0 | ||||||||||||
1741 | - | |||||||||||||
1742 | QList<QTableWidgetItem *> taken; | - | ||||||||||||
1743 | const int indexesCount = indexes.count(); | - | ||||||||||||
1744 | taken.reserve(indexesCount); | - | ||||||||||||
1745 | for (int i = 0; i < indexesCount; ++iconst auto &index : indexes) | - | ||||||||||||
1746 | taken.append(takeItem(indexesindex.at(i).row(), indexesindex.at(i).column())); never executed: taken.append(takeItem(index.row(), index.column())); | 0 | ||||||||||||
1747 | - | |||||||||||||
1748 | for (int i = 0; i <const auto &index : indexes.count(); ++i) {QModelIndex index = indexes.at(i); | - | ||||||||||||
1749 | int r = index.row() - top + topIndex.row(); | - | ||||||||||||
1750 | int c = index.column() - left + topIndex.column(); | - | ||||||||||||
1751 | setItem(r, c, taken.takeFirst()); | - | ||||||||||||
1752 | } never executed: end of block | 0 | ||||||||||||
1753 | - | |||||||||||||
1754 | event->accept(); | - | ||||||||||||
1755 | - | |||||||||||||
1756 | event->setDropAction(Qt::CopyAction); | - | ||||||||||||
1757 | } never executed: end of block | 0 | ||||||||||||
1758 | } never executed: end of block | 0 | ||||||||||||
1759 | - | |||||||||||||
1760 | QTableView::dropEvent(event); | - | ||||||||||||
1761 | } never executed: end of block | 0 | ||||||||||||
1762 | - | |||||||||||||
1763 | - | |||||||||||||
1764 | - | |||||||||||||
1765 | - | |||||||||||||
Switch to Source code | Preprocessed file |