Drop the hidden column in the project tree that holds the item handle, and use the data setting instead

This commit is contained in:
Veronica K. B. Olsen
2020-06-02 09:23:23 +02:00
parent afdd07b6e9
commit 2bd2c81eae
2 changed files with 15 additions and 16 deletions
+14 -15
View File
@@ -47,7 +47,6 @@ class GuiDocTree(QTreeWidget):
C_COUNT = 1
C_EXPORT = 2
C_FLAGS = 3
C_HANDLE = 4
def __init__(self, theParent, theProject):
QTreeWidget.__init__(self, theParent)
@@ -69,9 +68,8 @@ class GuiDocTree(QTreeWidget):
self.setIconSize(QSize(iPx, iPx))
self.setExpandsOnDoubleClick(True)
self.setIndentation(iPx)
self.setColumnCount(5)
self.setHeaderLabels(["Label", "Words", "Inc", "Flags", "Handle"])
self.hideColumn(self.C_HANDLE)
self.setColumnCount(4)
self.setHeaderLabels(["Label", "Words", "Inc", "Flags"])
treeHead = self.headerItem()
treeHead.setTextAlignment(self.C_COUNT, Qt.AlignRight)
@@ -479,7 +477,7 @@ class GuiDocTree(QTreeWidget):
pCount = 0
for i in range(pItem.childCount()):
pCount += int(pItem.child(i).text(self.C_COUNT))
pHandle = pItem.text(self.C_HANDLE)
pHandle = pItem.data(self.C_NAME, Qt.UserRole)
if not nDepth > 200 and pHandle != "":
self.propagateCount(pHandle, pCount, nDepth+1)
return
@@ -521,17 +519,17 @@ class GuiDocTree(QTreeWidget):
if len(selItem) == 0:
return None
if isinstance(selItem[0], QTreeWidgetItem):
return selItem[0].text(self.C_HANDLE)
return selItem[0].data(self.C_NAME, Qt.UserRole)
return None
def getSelectedHandles(self):
"""Return a list of all currently selected item handles.
"""
selItems = self.selectedItems()
selItems = self.selectedItems()
selHandles = []
for n in range(len(selItems)):
if isinstance(selItems[n], QTreeWidgetItem):
selHandles.append(selItems[n].text(self.C_HANDLE))
selHandles.append(selItems[n].data(self.C_NAME, Qt.UserRole))
return selHandles
def setSelectedHandle(self, tHandle):
@@ -563,8 +561,8 @@ class GuiDocTree(QTreeWidget):
"""This is a recursive function returning all items in a tree
starting at a given QTreeWidgetItem.
"""
tHandle = theItem.text(self.C_HANDLE)
nwItem = self.theProject.projTree[tHandle]
tHandle = theItem.data(self.C_NAME, Qt.UserRole)
nwItem = self.theProject.projTree[tHandle]
nwItem.setExpanded(theItem.isExpanded())
nwItem.setOrder(theIndex)
theList.append(tHandle)
@@ -585,7 +583,6 @@ class GuiDocTree(QTreeWidget):
newItem.setText(self.C_COUNT, "0")
newItem.setText(self.C_EXPORT, "")
newItem.setText(self.C_FLAGS, "")
newItem.setText(self.C_HANDLE, tHandle)
newItem.setTextAlignment(self.C_NAME, Qt.AlignLeft | Qt.AlignVCenter)
newItem.setTextAlignment(self.C_COUNT, Qt.AlignRight | Qt.AlignVCenter)
@@ -596,6 +593,8 @@ class GuiDocTree(QTreeWidget):
newItem.setFont(self.C_COUNT, self.theTheme.guiFont)
newItem.setFont(self.C_FLAGS, self.theTheme.guiFont)
newItem.setData(self.C_NAME, Qt.UserRole, tHandle)
self.theMap[tHandle] = newItem
if pHandle is None:
if nwItem.itemType == nwItemType.ROOT:
@@ -649,10 +648,10 @@ class GuiDocTree(QTreeWidget):
newItem.setText(self.C_COUNT, "")
newItem.setText(self.C_EXPORT, "")
newItem.setText(self.C_FLAGS, "")
newItem.setText(self.C_HANDLE, "")
self.addTopLevelItem(newItem)
self.orphRoot = newItem
newItem.setExpanded(True)
newItem.setData(self.C_NAME, "")
newItem.setIcon(self.C_NAME, self.theTheme.getIcon("warning"))
return
@@ -677,7 +676,7 @@ class GuiDocTree(QTreeWidget):
logger.error("Failed to find new parent item of %s" % tHandle)
return False
pHandle = trItemP.text(self.C_HANDLE)
pHandle = trItemP.data(self.C_NAME, Qt.UserRole)
wC = int(trItemS.text(self.C_COUNT))
self.propagateCount(tHandle, -wC)
nwItemS.setParent(pHandle)
@@ -702,7 +701,7 @@ class GuiDocTree(QTreeWidget):
if trItemP is None:
logger.error("Failed to find new parent item of %s" % tHandle)
return
pHandle = trItemP.text(self.C_HANDLE)
pHandle = trItemP.data(self.C_NAME, Qt.UserRole)
nwItemS.setParent(pHandle)
self.setTreeItemValues(tHandle)
self.theProject.setProjectChanged(True)
@@ -737,7 +736,7 @@ class GuiDocTree(QTreeWidget):
return
dItem = self.itemFromIndex(dIndex)
dHandle = dItem.text(self.C_HANDLE)
dHandle = dItem.data(self.C_NAME, Qt.UserRole)
snItem = self.theProject.projTree[sHandle]
dnItem = self.theProject.projTree[dHandle]
if dnItem is None:
+1 -1
View File
@@ -1022,7 +1022,7 @@ class GuiMain(QMainWindow):
"""The user double-clicked an item in the tree. If it is a file,
we open it. Otherwise, we do nothing.
"""
tHandle = tItem.text(self.treeView.C_HANDLE)
tHandle = tItem.data(self.treeView.C_NAME, Qt.UserRole)
logger.verbose("User double clicked tree item with handle %s" % tHandle)
nwItem = self.theProject.projTree[tHandle]
if nwItem is not None: