Reimplement item deletion
This commit is contained in:
+24
-17
@@ -28,7 +28,7 @@ import random
|
||||
|
||||
from collections.abc import Iterable, Iterator
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Literal, overload
|
||||
|
||||
from PyQt5.QtCore import QModelIndex
|
||||
|
||||
@@ -141,6 +141,29 @@ class NWTree:
|
||||
return False
|
||||
return True
|
||||
|
||||
def remove(self, tHandle: str) -> bool:
|
||||
"""Remove an item from the project tree."""
|
||||
if (node := self._nodes.get(tHandle)) and tHandle in self._items:
|
||||
index = self._model.indexFromNode(node)
|
||||
if index.isValid() and self._model.removeChild(index.parent(), index.row()):
|
||||
del self._nodes[tHandle]
|
||||
del self._items[tHandle]
|
||||
return True
|
||||
|
||||
@overload # pragma: no cover
|
||||
def create(
|
||||
self, label: str, parent: None, itemType: Literal[nwItemType.ROOT],
|
||||
itemClass: nwItemClass, pos: int = -1
|
||||
) -> str:
|
||||
pass
|
||||
|
||||
@overload # pragma: no cover
|
||||
def create(
|
||||
self, label: str, parent: str | None, itemType: nwItemType,
|
||||
itemClass: nwItemClass = nwItemClass.NO_CLASS, pos: int = -1
|
||||
) -> str | None:
|
||||
pass
|
||||
|
||||
def create(
|
||||
self, label: str, parent: str | None, itemType: nwItemType,
|
||||
itemClass: nwItemClass = nwItemClass.NO_CLASS, pos: int = -1,
|
||||
@@ -431,22 +454,6 @@ class NWTree:
|
||||
logger.error("No tree item with handle '%s'", str(tHandle))
|
||||
return None
|
||||
|
||||
def __delitem__(self, tHandle: str) -> None:
|
||||
"""Remove an item from the internal lists and dictionaries."""
|
||||
# if tHandle in self._order and tHandle in self._tree:
|
||||
# self._order.remove(tHandle)
|
||||
# del self._tree[tHandle]
|
||||
# else:
|
||||
# logger.warning("Failed to delete item '%s': item not found", tHandle)
|
||||
# return
|
||||
|
||||
# if tHandle in self._roots:
|
||||
# del self._roots[tHandle]
|
||||
# if tHandle == self._trash:
|
||||
# self._trash = None
|
||||
|
||||
return
|
||||
|
||||
def __contains__(self, tHandle: str) -> bool:
|
||||
"""Checks if a handle exists in the tree."""
|
||||
return tHandle in self._items
|
||||
|
||||
Reference in New Issue
Block a user