Tighten up the item class (#937)

* Protect the attributes of the NWItem class
* Fix test coverage
* Add a type checker function to the tree class
This commit is contained in:
Veronica Berglyd Olsen
2021-12-31 16:25:20 +01:00
committed by GitHub
parent af3d0d2eb0
commit 6ac9e1aec4
14 changed files with 255 additions and 183 deletions
+1 -5
View File
@@ -159,14 +159,10 @@ class GuiDocViewer(QTextBrowser):
def loadText(self, tHandle, updateHistory=True):
"""Load text into the viewer from an item handle.
"""
tItem = self.theProject.projTree[tHandle]
if tItem is None:
if not self.theProject.projTree.checkType(tHandle, nwItemType.FILE):
logger.warning("Item not found")
return False
if tItem.itemType != nwItemType.FILE:
return False
logger.debug("Generating preview for item '%s'", tHandle)
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
+2 -6
View File
@@ -1051,16 +1051,12 @@ class GuiProjectTree(QTreeWidget):
def _emitItemChange(self, tHandle):
"""Emit an item change signal for a given handle.
"""
nwItem = self.theProject.projTree[tHandle]
if nwItem is None:
return
if nwItem.itemType == nwItemType.FILE:
if self.theProject.projTree.checkType(tHandle, nwItemType.FILE):
nwItem = self.theProject.projTree[tHandle]
if nwItem.itemClass == nwItemClass.NOVEL:
self.novelItemChanged.emit()
else:
self.noteItemChanged.emit()
return
def _recordLastMove(self, srcItem, parItem, parIndex):