| 1401 | } |
| 1402 | |
| 1403 | void |
| 1404 | TableView::dropEvent(QDropEvent* e) |
| 1405 | { |
| 1406 | // QTreeView::dropEvent(e); |
| 1407 | |
| 1408 | DropIndicatorPosition position = dropIndicatorPosition(); |
| 1409 | |
| 1410 | switch (position) { |
| 1411 | case QAbstractItemView::OnItem: |
| 1412 | case QAbstractItemView::OnViewport: |
| 1413 | default: |
| 1414 | |
| 1415 | return; |
| 1416 | |
| 1417 | case QAbstractItemView::AboveItem: |
| 1418 | case QAbstractItemView::BelowItem: |
| 1419 | break; |
| 1420 | } |
| 1421 | TableItem* into = itemAt( e->pos() ); |
| 1422 | |
| 1423 | if ( !into || _imp->draggedItems.empty() ) { |
| 1424 | return; |
| 1425 | } |
| 1426 | Q_EMIT aboutToDrop(); |
| 1427 | int targetRow = into->row(); |
| 1428 | |
| 1429 | //We only support full rows |
| 1430 | assert(selectionBehavior() == QAbstractItemView::SelectRows); |
| 1431 | |
| 1432 | ///Remove the items |
| 1433 | std::map<int, std::map<int, TableItem*> > rowMoved; |
| 1434 | for (std::list<TableItem*>::iterator it = _imp->draggedItems.begin(); it != _imp->draggedItems.end(); ++it) { |
| 1435 | rowMoved[(*it)->row()][(*it)->column()] = *it; |
| 1436 | TableItem* taken = _imp->model->takeItem( (*it)->row(), (*it)->column() ); |
| 1437 | assert(taken == *it); |
| 1438 | Q_UNUSED(taken); |
| 1439 | } |
| 1440 | /// remove the rows in reverse order so that indexes are still valid |
| 1441 | for (std::map<int, std::map<int, TableItem*> >::reverse_iterator it = rowMoved.rbegin(); it != rowMoved.rend(); ++it) { |
| 1442 | _imp->model->removeRows(it->first); |
| 1443 | if (it->first <= targetRow) { |
| 1444 | --targetRow; |
| 1445 | } |
| 1446 | } |
| 1447 | _imp->draggedItems.clear(); |
| 1448 | ///insert back at the correct position |
| 1449 | |
| 1450 | int nRows = _imp->model->rowCount(); |
| 1451 | switch (position) { |
| 1452 | case QAbstractItemView::AboveItem: { |
| 1453 | _imp->model->insertRows( targetRow, rowMoved.size() ); |
| 1454 | break; |
| 1455 | } |
| 1456 | case QAbstractItemView::BelowItem: { |
| 1457 | ++targetRow; |
| 1458 | if (targetRow > nRows) { |
| 1459 | targetRow = nRows; |
| 1460 | } |
nothing calls this directly
no test coverage detected