From ba7fdb314bd63320dd47ced85f20a28c0dded985 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 29 Apr 2025 21:26:13 +0200 Subject: [PATCH] Add a main count setting and use it for the project tree --- novelwriter/core/item.py | 4 ++++ novelwriter/core/itemmodel.py | 2 +- tests/test_core/test_core_item.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py index ca3ce498..1dd17e47 100644 --- a/novelwriter/core/item.py +++ b/novelwriter/core/item.py @@ -164,6 +164,10 @@ class NWItem: def paraCount(self) -> int: return self._paraCount + @property + def mainCount(self) -> int: + return self._charCount if CONFIG.useCharCount else self._wordCount + @property def initCount(self) -> int: return self._initCount diff --git a/novelwriter/core/itemmodel.py b/novelwriter/core/itemmodel.py index 6fb2580a..8acdd463 100644 --- a/novelwriter/core/itemmodel.py +++ b/novelwriter/core/itemmodel.py @@ -162,7 +162,7 @@ class ProjectNode: def updateCount(self, propagate: bool = True) -> None: """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}" if propagate and (parent := self._parent): parent.updateCount() diff --git a/tests/test_core/test_core_item.py b/tests/test_core/test_core_item.py index 395db6da..ad93f7db 100644 --- a/tests/test_core/test_core_item.py +++ b/tests/test_core/test_core_item.py @@ -26,6 +26,7 @@ import pytest from PyQt6.QtGui import QIcon +from novelwriter import CONFIG from novelwriter.core.item import NWItem from novelwriter.core.project import NWProject from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType @@ -168,6 +169,15 @@ def testCoreItem_Setters(mockGUI, mockRnd, fncPath): item.setParaCount(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 item.setCursorPos(None) assert item.cursorPos == 0