| 1377 | } |
| 1378 | |
| 1379 | void |
| 1380 | TableView::dropEvent(QDropEvent* e) |
| 1381 | { |
| 1382 | // QTreeView::dropEvent(e); |
| 1383 | |
| 1384 | DropIndicatorPosition position = dropIndicatorPosition(); |
| 1385 | |
| 1386 | switch (position) { |
| 1387 | case QAbstractItemView::OnItem: |
| 1388 | case QAbstractItemView::OnViewport: |
| 1389 | default: |
| 1390 | |
| 1391 | return; |
| 1392 | |
| 1393 | case QAbstractItemView::AboveItem: |
| 1394 | case QAbstractItemView::BelowItem: |
| 1395 | break; |
| 1396 | } |
| 1397 | TableItem* into = itemAt( e->pos() ); |
| 1398 | |
| 1399 | if ( !into || _imp->draggedItems.empty() ) { |
| 1400 | return; |
| 1401 | } |
| 1402 | Q_EMIT aboutToDrop(); |
| 1403 | int targetRow = into->row(); |
| 1404 | |
| 1405 | //We only support full rows |
| 1406 | assert(selectionBehavior() == QAbstractItemView::SelectRows); |
| 1407 | |
| 1408 | ///Remove the items |
| 1409 | std::map<int, std::map<int, TableItem*> > rowMoved; |
| 1410 | for (std::list<TableItem*>::iterator it = _imp->draggedItems.begin(); it != _imp->draggedItems.end(); ++it) { |
| 1411 | rowMoved[(*it)->row()][(*it)->column()] = *it; |
| 1412 | TableItem* taken = _imp->model->takeItem( (*it)->row(), (*it)->column() ); |
| 1413 | assert(taken == *it); |
| 1414 | Q_UNUSED(taken); |
| 1415 | } |
| 1416 | /// remove the rows in reverse order so that indexes are still valid |
| 1417 | for (std::map<int, std::map<int, TableItem*> >::reverse_iterator it = rowMoved.rbegin(); it != rowMoved.rend(); ++it) { |
| 1418 | _imp->model->removeRows(it->first); |
| 1419 | if (it->first <= targetRow) { |
| 1420 | --targetRow; |
| 1421 | } |
| 1422 | } |
| 1423 | _imp->draggedItems.clear(); |
| 1424 | ///insert back at the correct position |
| 1425 | |
| 1426 | int nRows = _imp->model->rowCount(); |
| 1427 | switch (position) { |
| 1428 | case QAbstractItemView::AboveItem: { |
| 1429 | _imp->model->insertRows( targetRow, rowMoved.size() ); |
| 1430 | break; |
| 1431 | } |
| 1432 | case QAbstractItemView::BelowItem: { |
| 1433 | ++targetRow; |
| 1434 | if (targetRow > nRows) { |
| 1435 | targetRow = nRows; |
| 1436 | } |
nothing calls this directly
no test coverage detected