Block drag and drop for ROOT items on the widget level, and drop the TRASH item type

This commit is contained in:
Veronica Berglyd Olsen
2022-04-23 16:57:13 +02:00
parent d96c8ddf85
commit bd5a14b18e
7 changed files with 18 additions and 35 deletions
+4 -18
View File
@@ -762,31 +762,18 @@ class GuiProjectTree(QTreeWidget):
drop is allowed or not. Disallowed drops are cancelled.
"""
sHandle = self.getSelectedHandle()
dIndex = self.indexAt(theEvent.pos())
if sHandle is None or not dIndex.isValid():
if sHandle is None:
logger.error("Invalid drag and drop event")
return
sItem = self._getTreeItem(sHandle)
dItem = self.itemFromIndex(dIndex)
dHandle = dItem.data(self.C_NAME, Qt.UserRole)
snItem = self.theProject.projTree[sHandle]
dnItem = self.theProject.projTree[dHandle]
if snItem.itemType == nwItemType.ROOT or dnItem is None:
logger.debug("Drag'n'drop of item '%s' not accepted", sHandle)
theEvent.ignore()
self.theParent.makeAlert(self.tr(
"The item cannot be moved to that location."
), nwAlert.ERROR)
return
logger.debug("Drag'n'drop of item '%s' accepted", sHandle)
self.propagateCount(sHandle, 0)
QTreeWidget.dropEvent(self, theEvent)
self._postItemMove(sHandle)
# Record undo information
sItem = self._getTreeItem(sHandle)
pItem = sItem.parent()
pIndex = 0
if pItem is not None:
@@ -895,8 +882,7 @@ class GuiProjectTree(QTreeWidget):
self._treeMap[tHandle] = newItem
if pHandle is None:
if nwItem.itemType == nwItemType.ROOT:
self.addTopLevelItem(newItem)
elif nwItem.itemType == nwItemType.TRASH:
newItem.setFlags(newItem.flags() ^ Qt.ItemIsDragEnabled)
self.addTopLevelItem(newItem)
else:
self.theParent.makeAlert(self.tr(
-3
View File
@@ -639,9 +639,6 @@ class GuiIcons:
iconName = "proj_scene"
elif tLayout == nwItemLayout.NOTE:
iconName = "proj_note"
elif tType == nwItemType.TRASH:
iconName = nwLabels.CLASS_ICON[tClass]
if iconName is None:
return QIcon()