Re-implement word counters
This commit is contained in:
@@ -110,7 +110,6 @@ class GuiDocEditor(QPlainTextEdit):
|
||||
|
||||
# Custom Signals
|
||||
closeEditorRequest = pyqtSignal()
|
||||
docCountsChanged = pyqtSignal(str, int, int, int)
|
||||
docTextChanged = pyqtSignal(str, float)
|
||||
editedStatusChanged = pyqtSignal(bool)
|
||||
itemHandleChanged = pyqtSignal(str)
|
||||
@@ -1281,7 +1280,7 @@ class GuiDocEditor(QPlainTextEdit):
|
||||
self._nwItem.setCharCount(cCount)
|
||||
self._nwItem.setWordCount(wCount)
|
||||
self._nwItem.setParaCount(pCount)
|
||||
self.docCountsChanged.emit(self._docHandle, cCount, wCount, pCount)
|
||||
self._nwItem.notifyToRefresh()
|
||||
self.docFooter.updateWordCount(wCount, False)
|
||||
return
|
||||
|
||||
|
||||
@@ -67,7 +67,6 @@ class GuiProjectView(QWidget):
|
||||
|
||||
# Signals triggered when the meta data values of items change
|
||||
rootFolderChanged = pyqtSignal(str)
|
||||
wordCountsChanged = pyqtSignal()
|
||||
|
||||
# Signals for user interaction with the project tree
|
||||
selectedItemChanged = pyqtSignal(str)
|
||||
@@ -241,13 +240,6 @@ class GuiProjectView(QWidget):
|
||||
self.projTree.newTreeItem(nwItemType.FILE, copyDoc=tHandle)
|
||||
return
|
||||
|
||||
@pyqtSlot(str, int, int, int)
|
||||
def updateCounts(self, tHandle: str, cCount: int, wCount: int, pCount: int) -> None:
|
||||
"""Slot for updating the word count of a specific item."""
|
||||
self.projTree.propagateCount(tHandle, wCount, countChildren=True)
|
||||
self.wordCountsChanged.emit()
|
||||
return
|
||||
|
||||
@pyqtSlot(str)
|
||||
def updateRootItem(self, tHandle: str) -> None:
|
||||
"""Process root item changes."""
|
||||
@@ -1067,45 +1059,6 @@ class GuiProjectTree(QTreeView):
|
||||
# self.setTreeItemValues(nwItem)
|
||||
return
|
||||
|
||||
def propagateCount(self, tHandle: str, newCount: int, countChildren: bool = False) -> None:
|
||||
"""Recursive function setting the word count for a given item,
|
||||
and propagating that count upwards in the tree until reaching a
|
||||
root item. This function is more efficient than recalculating
|
||||
everything each time the word count is updated, but is also
|
||||
prone to diverging from the true values if the counts are not
|
||||
properly reported to the function.
|
||||
"""
|
||||
# tItem = self._getTreeItem(tHandle)
|
||||
# if tItem is None:
|
||||
# return
|
||||
|
||||
# if countChildren:
|
||||
# for i in range(tItem.childCount()):
|
||||
# newCount += int(tItem.child(i).data(self.C_DATA, self.D_WORDS))
|
||||
|
||||
# tItem.setText(self.C_COUNT, f"{newCount:n}")
|
||||
# tItem.setData(self.C_DATA, self.D_WORDS, int(newCount))
|
||||
|
||||
# pItem = tItem.parent()
|
||||
# if pItem is None:
|
||||
# return
|
||||
|
||||
# pCount = 0
|
||||
# pHandle = None
|
||||
# for i in range(pItem.childCount()):
|
||||
# pCount += int(pItem.child(i).data(self.C_DATA, self.D_WORDS))
|
||||
# pHandle = pItem.data(self.C_DATA, self.D_HANDLE)
|
||||
|
||||
# if pHandle:
|
||||
# if SHARED.project.tree.checkType(pHandle, nwItemType.FILE):
|
||||
# # A file has an internal word count we need to account
|
||||
# # for, but a folder always has 0 words on its own.
|
||||
# pCount += SHARED.project.index.getCounts(pHandle)[1]
|
||||
|
||||
# self.propagateCount(pHandle, pCount, countChildren=False)
|
||||
|
||||
return
|
||||
|
||||
|
||||
class _UpdatableMenu(QMenu):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user