Merge pull request #522 from vkbo/issue521_move_item_crash

Issue 521: Move Tree Item Crash
This commit is contained in:
Veronica K. Berglyd Olsen
2020-12-09 23:27:22 +01:00
committed by GitHub
+43 -38
View File
@@ -286,36 +286,36 @@ class GuiProjectTree(QTreeWidget):
logger.error("No project open") logger.error("No project open")
return False return False
hasFocus = qApp.focusWidget() == self or not self.mainConf.showGUI if qApp.focusWidget() != self and self.mainConf.showGUI:
if hasFocus and self.theParent.hasProject: return False
tHandle = self.getSelectedHandle() tHandle = self.getSelectedHandle()
tItem = self._getTreeItem(tHandle) tItem = self._getTreeItem(tHandle)
pItem = tItem.parent() if tItem is None:
if pItem is None: return False
tIndex = self.indexOfTopLevelItem(tItem)
nChild = self.topLevelItemCount()
nIndex = tIndex + nStep
if nIndex < 0 or nIndex >= nChild:
return False
cItem = self.takeTopLevelItem(tIndex)
self.insertTopLevelItem(nIndex, cItem)
else: pItem = tItem.parent()
tIndex = pItem.indexOfChild(tItem) if pItem is None:
nChild = pItem.childCount() tIndex = self.indexOfTopLevelItem(tItem)
nIndex = tIndex + nStep nChild = self.topLevelItemCount()
if nIndex < 0 or nIndex >= nChild: nIndex = tIndex + nStep
return False if nIndex < 0 or nIndex >= nChild:
cItem = pItem.takeChild(tIndex) return False
pItem.insertChild(nIndex, cItem) cItem = self.takeTopLevelItem(tIndex)
self.insertTopLevelItem(nIndex, cItem)
self.clearSelection()
cItem.setSelected(True)
self._setTreeChanged(True)
else: else:
return False tIndex = pItem.indexOfChild(tItem)
nChild = pItem.childCount()
nIndex = tIndex + nStep
if nIndex < 0 or nIndex >= nChild:
return False
cItem = pItem.takeChild(tIndex)
pItem.insertChild(nIndex, cItem)
self.clearSelection()
cItem.setSelected(True)
self._setTreeChanged(True)
return True return True
@@ -431,7 +431,7 @@ class GuiProjectTree(QTreeWidget):
trItemS = self._getTreeItem(tHandle) trItemS = self._getTreeItem(tHandle)
nwItemS = self.theProject.projTree[tHandle] nwItemS = self.theProject.projTree[tHandle]
if nwItemS is None: if trItemS is None or nwItemS is None:
return False return False
wCount = int(trItemS.data(self.C_COUNT, Qt.UserRole)) wCount = int(trItemS.data(self.C_COUNT, Qt.UserRole))
@@ -582,18 +582,23 @@ class GuiProjectTree(QTreeWidget):
properly reported to the function. properly reported to the function.
""" """
tItem = self._getTreeItem(tHandle) tItem = self._getTreeItem(tHandle)
if tItem is not None: if tItem is None:
tItem.setText(self.C_COUNT, f"{theCount:n}") return
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 not nDepth > nwConst.MAX_DEPTH + 1 and pHandle != "": tItem.setText(self.C_COUNT, f"{theCount:n}")
self.propagateCount(pHandle, pCount, nDepth+1) 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 return