Add a main count setting and use it for the project tree

This commit is contained in:
Veronica Berglyd Olsen
2025-04-29 21:26:13 +02:00
parent da84d40cd5
commit ba7fdb314b
3 changed files with 15 additions and 1 deletions
+4
View File
@@ -164,6 +164,10 @@ class NWItem:
def paraCount(self) -> int: def paraCount(self) -> int:
return self._paraCount return self._paraCount
@property
def mainCount(self) -> int:
return self._charCount if CONFIG.useCharCount else self._wordCount
@property @property
def initCount(self) -> int: def initCount(self) -> int:
return self._initCount return self._initCount
+1 -1
View File
@@ -162,7 +162,7 @@ class ProjectNode:
def updateCount(self, propagate: bool = True) -> None: def updateCount(self, propagate: bool = True) -> None:
"""Update counts, and propagate upwards in the tree.""" """Update counts, and propagate upwards in the tree."""
self._count = self._item.wordCount + sum(c._count for c in self._children) # noqa: SLF001 self._count = self._item.mainCount + sum(c._count for c in self._children) # noqa: SLF001
self._cache[C_COUNT_TEXT] = f"{self._count:n}" self._cache[C_COUNT_TEXT] = f"{self._count:n}"
if propagate and (parent := self._parent): if propagate and (parent := self._parent):
parent.updateCount() parent.updateCount()
+10
View File
@@ -26,6 +26,7 @@ import pytest
from PyQt6.QtGui import QIcon from PyQt6.QtGui import QIcon
from novelwriter import CONFIG
from novelwriter.core.item import NWItem from novelwriter.core.item import NWItem
from novelwriter.core.project import NWProject from novelwriter.core.project import NWProject
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
@@ -168,6 +169,15 @@ def testCoreItem_Setters(mockGUI, mockRnd, fncPath):
item.setParaCount(1) item.setParaCount(1)
assert item.paraCount == 1 assert item.paraCount == 1
# MainCount
item.setWordCount(123)
item.setCharCount(1234)
CONFIG.useCharCount = False
assert item.mainCount == 123
CONFIG.useCharCount = True
assert item.mainCount == 1234
CONFIG.useCharCount = False
# CursorPos # CursorPos
item.setCursorPos(None) item.setCursorPos(None)
assert item.cursorPos == 0 assert item.cursorPos == 0