Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status column to project outline #2088

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions novelwriter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class nwLabels:
nwOutline.LEVEL: QT_TRANSLATE_NOOP("Constant", "Level"),
nwOutline.LABEL: QT_TRANSLATE_NOOP("Constant", "Document"),
nwOutline.LINE: QT_TRANSLATE_NOOP("Constant", "Line"),
nwOutline.STATUS: QT_TRANSLATE_NOOP("Constant", "Status"),
nwOutline.CCOUNT: QT_TRANSLATE_NOOP("Constant", "Chars"),
nwOutline.WCOUNT: QT_TRANSLATE_NOOP("Constant", "Words"),
nwOutline.PCOUNT: QT_TRANSLATE_NOOP("Constant", "Pars"),
Expand Down
31 changes: 16 additions & 15 deletions novelwriter/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,22 @@ class nwOutline(Enum):
LEVEL = 1
LABEL = 2
LINE = 3
CCOUNT = 4
WCOUNT = 5
PCOUNT = 6
POV = 7
FOCUS = 8
CHAR = 9
PLOT = 10
TIME = 11
WORLD = 12
OBJECT = 13
ENTITY = 14
CUSTOM = 15
STORY = 16
MENTION = 17
SYNOP = 18
STATUS = 4
CCOUNT = 5
WCOUNT = 6
PCOUNT = 7
POV = 8
FOCUS = 9
CHAR = 10
PLOT = 11
TIME = 12
WORLD = 13
OBJECT = 14
ENTITY = 15
CUSTOM = 16
STORY = 17
MENTION = 18
SYNOP = 19


class nwBuildFmt(Enum):
Expand Down
13 changes: 11 additions & 2 deletions novelwriter/gui/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class GuiOutlineTree(QTreeWidget):
nwOutline.LEVEL: 40,
nwOutline.LABEL: 150,
nwOutline.LINE: 40,
nwOutline.STATUS: 100,
nwOutline.CCOUNT: 50,
nwOutline.WCOUNT: 50,
nwOutline.PCOUNT: 50,
Expand All @@ -340,6 +341,7 @@ class GuiOutlineTree(QTreeWidget):
nwOutline.LEVEL: True,
nwOutline.LABEL: False,
nwOutline.LINE: True,
nwOutline.STATUS: True,
nwOutline.CCOUNT: True,
nwOutline.WCOUNT: False,
nwOutline.PCOUNT: False,
Expand Down Expand Up @@ -471,8 +473,10 @@ def clearContent(self) -> None:

return

def refreshTree(self, rootHandle: str | None = None,
overRide: bool = False, novelChanged: bool = False) -> None:
def refreshTree(
self, rootHandle: str | None = None,
overRide: bool = False, novelChanged: bool = False
) -> None:
"""Called whenever the Outline tab is activated and controls
what data to load, and if necessary, force a rebuild of the
tree.
Expand Down Expand Up @@ -659,6 +663,7 @@ def _populateTree(self, rootHandle: str | None) -> None:
is fast and doesn't require a rebuild of the tree.
"""
logger.debug("Rebuilding Outline tree")
tStart = time()
self.clear()

if self._firstView:
Expand Down Expand Up @@ -691,6 +696,7 @@ def _populateTree(self, rootHandle: str | None) -> None:
nwItem = SHARED.project.tree[tHandle]
if iLevel == 0 or nwItem is None:
continue
sLabel, sIcon = nwItem.getImportStatus()

item = QTreeWidgetItem()
hDec = SHARED.theme.getHeaderDecoration(iLevel)
Expand All @@ -704,6 +710,8 @@ def _populateTree(self, rootHandle: str | None) -> None:
item.setIcon(self._colIdx[nwOutline.LABEL], self._dIcon[nwItem.mainHeading])
item.setText(self._colIdx[nwOutline.LABEL], nwItem.itemName)
item.setText(self._colIdx[nwOutline.LINE], f"{novIdx.line:n}")
item.setText(self._colIdx[nwOutline.STATUS], sLabel)
item.setIcon(self._colIdx[nwOutline.STATUS], sIcon)
item.setText(self._colIdx[nwOutline.SYNOP], novIdx.synopsis)
item.setText(self._colIdx[nwOutline.CCOUNT], f"{novIdx.charCount:n}")
item.setText(self._colIdx[nwOutline.WCOUNT], f"{novIdx.wordCount:n}")
Expand All @@ -728,6 +736,7 @@ def _populateTree(self, rootHandle: str | None) -> None:
self.addTopLevelItem(item)

self._lastBuild = time()
logger.debug("Project outline built in %.3f ms", 1000.0*(time() - tStart))

return

Expand Down
4 changes: 2 additions & 2 deletions tests/test_gui/test_gui_outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, projPath):

# Current Order
order = [outlineTree._colIdx[col] for col in outlineTree._treeOrder]
assert order == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
assert order == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

# Move 3 to 0
outlineTree._columnMoved(0, 3, 0)
order = [outlineTree._colIdx[col] for col in outlineTree._treeOrder]
assert order == [3, 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
assert order == [3, 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

# qtbot.stop()

Expand Down