disable dragging of unsupported items

This commit is contained in:
Damien Elmes 2021-01-30 21:32:25 +10:00
parent 4579740df6
commit 18f0b78716

View File

@ -175,15 +175,19 @@ class SidebarModel(QAbstractItemModel):
def supportedDropActions(self): def supportedDropActions(self):
return Qt.MoveAction return Qt.MoveAction
def flags(self, index): def flags(self, index: QModelIndex):
if not index.isValid(): if not index.isValid():
return Qt.ItemIsEnabled return Qt.ItemIsEnabled
return ( flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
Qt.ItemIsEnabled
| Qt.ItemIsSelectable item: SidebarItem = index.internalPointer()
| Qt.ItemIsDragEnabled if item.item_type in (
| Qt.ItemIsDropEnabled SidebarItemType.DECK,
) SidebarItemType.DECK_ROOT,
):
flags |= Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled
return flags
# Helpers # Helpers
###################################################################### ######################################################################
@ -353,10 +357,12 @@ class SidebarTreeView(QTreeView):
return self._handle_drag_drop_decks(sources, target) return self._handle_drag_drop_decks(sources, target)
return False return False
def _handle_drag_drop_decks(self, sources: List[SidebarItem], target: SidebarItem) -> bool: def _handle_drag_drop_decks(
source_ids = [source.id self, sources: List[SidebarItem], target: SidebarItem
for source in sources ) -> bool:
if source.item_type == SidebarItemType.DECK] source_ids = [
source.id for source in sources if source.item_type == SidebarItemType.DECK
]
if not source_ids: if not source_ids:
return False return False
@ -364,8 +370,9 @@ class SidebarTreeView(QTreeView):
fut.result() fut.result()
self.refresh() self.refresh()
self.mw.taskman.with_progress(lambda: self.col.decks.drag_drop_decks(source_ids, target.id), self.mw.taskman.with_progress(
on_done) lambda: self.col.decks.drag_drop_decks(source_ids, target.id), on_done
)
return True return True
def onClickCurrent(self) -> None: def onClickCurrent(self) -> None: