MCPcopy Create free account
hub / github.com/MrKepzie/Natron / dropEvent

Method dropEvent

Gui/TableModelView.cpp:1379–1455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1377}
1378
1379void
1380TableView::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 }

Callers

nothing calls this directly

Calls 12

emptyMethod · 0.80
columnMethod · 0.80
takeItemMethod · 0.80
removeRowsMethod · 0.80
insertRowsMethod · 0.80
setItemMethod · 0.80
rowMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
rowCountMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected