From 15c5ffcb7695eacade7122fdaccf4931e3b1c891 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 9 Dec 2020 23:22:15 +0100 Subject: [PATCH] Break up another nested if statement --- nw/gui/projtree.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index a556b044..3e91cc2d 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -431,7 +431,7 @@ class GuiProjectTree(QTreeWidget): trItemS = self._getTreeItem(tHandle) nwItemS = self.theProject.projTree[tHandle] - if nwItemS is None: + if trItemS is None or nwItemS is None: return False wCount = int(trItemS.data(self.C_COUNT, Qt.UserRole)) @@ -582,18 +582,23 @@ class GuiProjectTree(QTreeWidget): properly reported to the function. """ tItem = self._getTreeItem(tHandle) - if tItem is not None: - tItem.setText(self.C_COUNT, f"{theCount:n}") - tItem.setData(self.C_COUNT, Qt.UserRole, int(theCount)) - pItem = tItem.parent() - if pItem is not None: - pCount = 0 - for i in range(pItem.childCount()): - pCount += int(pItem.child(i).data(self.C_COUNT, Qt.UserRole)) - pHandle = pItem.data(self.C_NAME, Qt.UserRole) + if tItem is None: + return - if not nDepth > nwConst.MAX_DEPTH + 1 and pHandle != "": - self.propagateCount(pHandle, pCount, nDepth+1) + tItem.setText(self.C_COUNT, f"{theCount:n}") + tItem.setData(self.C_COUNT, Qt.UserRole, int(theCount)) + + pItem = tItem.parent() + if pItem is None: + return + + pCount = 0 + for i in range(pItem.childCount()): + pCount += int(pItem.child(i).data(self.C_COUNT, Qt.UserRole)) + pHandle = pItem.data(self.C_NAME, Qt.UserRole) + + if not nDepth > nwConst.MAX_DEPTH + 1 and pHandle != "": + self.propagateCount(pHandle, pCount, nDepth+1) return