Logic mostly based on OBS's source-tree dropEvent() with a few modifications regarding group handling
| 994 | // Logic mostly based on OBS's source-tree dropEvent() with a few modifications |
| 995 | // regarding group handling |
| 996 | void MacroTree::dropEvent(QDropEvent *event) |
| 997 | { |
| 998 | if (event->source() != this) { |
| 999 | QListView::dropEvent(event); |
| 1000 | return; |
| 1001 | } |
| 1002 | |
| 1003 | MacroTreeModel *mtm = GetModel(); |
| 1004 | auto &items = mtm->_macros; |
| 1005 | QModelIndexList indices = selectedIndexes(); |
| 1006 | |
| 1007 | DropIndicatorPosition indicator = dropIndicatorPosition(); |
| 1008 | int row = indexAt(event->position().toPoint()).row(); |
| 1009 | bool emptyDrop = row == -1; |
| 1010 | |
| 1011 | if (emptyDrop) { |
| 1012 | if (items.empty()) { |
| 1013 | QListView::dropEvent(event); |
| 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | row = mtm->rowCount(QModelIndex()) - 1; |
| 1018 | indicator = QAbstractItemView::BelowItem; |
| 1019 | } |
| 1020 | |
| 1021 | // Store destination group if moving to a group |
| 1022 | Macro *dropItem = items[ModelIndexToMacroIndex(row, items)] |
| 1023 | .get(); // Item being dropped on |
| 1024 | bool itemIsGroup = dropItem->IsGroup(); |
| 1025 | Macro *dropGroup = itemIsGroup ? dropItem : dropItem->Parent().get(); |
| 1026 | |
| 1027 | // Not a group if moving above the group |
| 1028 | if (indicator == QAbstractItemView::AboveItem && itemIsGroup) { |
| 1029 | dropGroup = nullptr; |
| 1030 | } |
| 1031 | if (emptyDrop) { |
| 1032 | dropGroup = nullptr; |
| 1033 | } |
| 1034 | |
| 1035 | // Remember to remove list items if dropping on collapsed group |
| 1036 | bool dropOnCollapsed = false; |
| 1037 | if (dropGroup) { |
| 1038 | dropOnCollapsed = dropGroup->IsCollapsed(); |
| 1039 | } |
| 1040 | |
| 1041 | if (indicator == QAbstractItemView::BelowItem || |
| 1042 | indicator == QAbstractItemView::OnItem || |
| 1043 | indicator == QAbstractItemView::OnViewport) |
| 1044 | row++; |
| 1045 | |
| 1046 | if (row < 0 || row > (int)items.size()) { |
| 1047 | QListView::dropEvent(event); |
| 1048 | return; |
| 1049 | } |
| 1050 | |
| 1051 | // Determine if any base group is selected |
| 1052 | bool hasGroups = false; |
| 1053 | for (int i = 0; i < indices.size(); i++) { |
nothing calls this directly
no test coverage detected