Clean up outline view code
This commit is contained in:
@@ -62,7 +62,7 @@ class NovelSelector(QComboBox):
|
|||||||
# Methods
|
# Methods
|
||||||
##
|
##
|
||||||
|
|
||||||
def setHandle(self, tHandle: str, blockSignal: bool = True) -> None:
|
def setHandle(self, tHandle: str | None, blockSignal: bool = True) -> None:
|
||||||
"""Set the currently selected handle."""
|
"""Set the currently selected handle."""
|
||||||
self._blockSignal = blockSignal
|
self._blockSignal = blockSignal
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
|
|||||||
+143
-165
@@ -59,8 +59,8 @@ class GuiOutlineView(QWidget):
|
|||||||
loadDocumentTagRequest = pyqtSignal(str, Enum)
|
loadDocumentTagRequest = pyqtSignal(str, Enum)
|
||||||
openDocumentRequest = pyqtSignal(str, Enum, str, bool)
|
openDocumentRequest = pyqtSignal(str, Enum, str, bool)
|
||||||
|
|
||||||
def __init__(self, mainGui):
|
def __init__(self, parent: QWidget) -> None:
|
||||||
super().__init__(parent=mainGui)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
# Build GUI
|
# Build GUI
|
||||||
self.outlineTree = GuiOutlineTree(self)
|
self.outlineTree = GuiOutlineTree(self)
|
||||||
@@ -98,38 +98,33 @@ class GuiOutlineView(QWidget):
|
|||||||
# Methods
|
# Methods
|
||||||
##
|
##
|
||||||
|
|
||||||
def updateTheme(self):
|
def updateTheme(self) -> None:
|
||||||
"""Update theme elements.
|
"""Update theme elements."""
|
||||||
"""
|
|
||||||
self.outlineBar.updateTheme()
|
self.outlineBar.updateTheme()
|
||||||
self.refreshTree()
|
self.refreshTree()
|
||||||
return
|
return
|
||||||
|
|
||||||
def initSettings(self):
|
def initSettings(self) -> None:
|
||||||
"""Initialise GUI elements that depend on specific settings.
|
"""Initialise GUI elements that depend on specific settings."""
|
||||||
"""
|
|
||||||
self.outlineTree.initSettings()
|
self.outlineTree.initSettings()
|
||||||
self.outlineData.initSettings()
|
self.outlineData.initSettings()
|
||||||
return
|
return
|
||||||
|
|
||||||
def refreshTree(self):
|
def refreshTree(self) -> None:
|
||||||
"""Refresh the current tree.
|
"""Refresh the current tree."""
|
||||||
"""
|
|
||||||
self.outlineTree.refreshTree(rootHandle=SHARED.project.data.getLastHandle("outline"))
|
self.outlineTree.refreshTree(rootHandle=SHARED.project.data.getLastHandle("outline"))
|
||||||
return
|
return
|
||||||
|
|
||||||
def clearOutline(self):
|
def clearOutline(self) -> None:
|
||||||
"""Clear project-related GUI content.
|
"""Clear project-related GUI content."""
|
||||||
"""
|
|
||||||
self.outlineData.clearDetails()
|
self.outlineData.clearDetails()
|
||||||
self.outlineBar.setEnabled(False)
|
self.outlineBar.setEnabled(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
def openProjectTasks(self):
|
def openProjectTasks(self) -> None:
|
||||||
"""Run open project tasks.
|
"""Run open project tasks."""
|
||||||
"""
|
|
||||||
lastOutline = SHARED.project.data.getLastHandle("outline")
|
lastOutline = SHARED.project.data.getLastHandle("outline")
|
||||||
if not (lastOutline in SHARED.project.tree or lastOutline is None):
|
if not (lastOutline is None or lastOutline in SHARED.project.tree):
|
||||||
lastOutline = SHARED.project.tree.findRoot(nwItemClass.NOVEL)
|
lastOutline = SHARED.project.tree.findRoot(nwItemClass.NOVEL)
|
||||||
|
|
||||||
logger.debug("Setting outline tree to root item '%s'", lastOutline)
|
logger.debug("Setting outline tree to root item '%s'", lastOutline)
|
||||||
@@ -141,23 +136,23 @@ class GuiOutlineView(QWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def closeProjectTasks(self):
|
def closeProjectTasks(self) -> None:
|
||||||
|
"""Run closing project tasks."""
|
||||||
self.outlineTree.closeProjectTasks()
|
self.outlineTree.closeProjectTasks()
|
||||||
self.outlineData.updateClasses()
|
self.outlineData.updateClasses()
|
||||||
self.clearOutline()
|
self.clearOutline()
|
||||||
return
|
return
|
||||||
|
|
||||||
def splitSizes(self):
|
def splitSizes(self) -> list[int]:
|
||||||
|
"""Get the sizes of the splitter widget."""
|
||||||
return self.splitOutline.sizes()
|
return self.splitOutline.sizes()
|
||||||
|
|
||||||
def setTreeFocus(self):
|
def setTreeFocus(self) -> None:
|
||||||
"""Set the focus to the tree widget.
|
"""Set the focus to the tree widget."""
|
||||||
"""
|
|
||||||
return self.outlineTree.setFocus()
|
return self.outlineTree.setFocus()
|
||||||
|
|
||||||
def treeHasFocus(self):
|
def treeHasFocus(self) -> bool:
|
||||||
"""Check if the outline tree has focus.
|
"""Check if the outline tree has focus."""
|
||||||
"""
|
|
||||||
return self.outlineTree.hasFocus()
|
return self.outlineTree.hasFocus()
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -165,9 +160,8 @@ class GuiOutlineView(QWidget):
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def updateRootItem(self, tHandle):
|
def updateRootItem(self, tHandle: str) -> None:
|
||||||
"""Should be called whenever a root folders changes.
|
"""Handle tasks whenever a root folders changes."""
|
||||||
"""
|
|
||||||
self.outlineBar.populateNovelList()
|
self.outlineBar.populateNovelList()
|
||||||
self.outlineData.updateClasses()
|
self.outlineData.updateClasses()
|
||||||
return
|
return
|
||||||
@@ -177,7 +171,7 @@ class GuiOutlineView(QWidget):
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _updateMenuColumns(self):
|
def _updateMenuColumns(self) -> None:
|
||||||
"""Trigger an update of the toggled state of the column menu
|
"""Trigger an update of the toggled state of the column menu
|
||||||
checkboxes whenever a signal is received that the hidden state
|
checkboxes whenever a signal is received that the hidden state
|
||||||
of columns has changed.
|
of columns has changed.
|
||||||
@@ -186,18 +180,16 @@ class GuiOutlineView(QWidget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def _tagClicked(self, link):
|
def _tagClicked(self, link: str) -> None:
|
||||||
"""Capture the click of a tag in the details panel.
|
"""Capture the click of a tag in the details panel."""
|
||||||
"""
|
|
||||||
if link:
|
if link:
|
||||||
self.loadDocumentTagRequest.emit(link, nwDocMode.VIEW)
|
self.loadDocumentTagRequest.emit(link, nwDocMode.VIEW)
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def _rootItemChanged(self, handle):
|
def _rootItemChanged(self, tHandle) -> None:
|
||||||
"""The root novel handle has changed or needs to be refreshed.
|
"""Handle root novel changed or needs to be refreshed."""
|
||||||
"""
|
self.outlineTree.refreshTree(rootHandle=(tHandle or None), overRide=True)
|
||||||
self.outlineTree.refreshTree(rootHandle=(handle or None), overRide=True)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiOutlineView
|
# END Class GuiOutlineView
|
||||||
@@ -208,8 +200,8 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
loadNovelRootRequest = pyqtSignal(str)
|
loadNovelRootRequest = pyqtSignal(str)
|
||||||
viewColumnToggled = pyqtSignal(bool, Enum)
|
viewColumnToggled = pyqtSignal(bool, Enum)
|
||||||
|
|
||||||
def __init__(self, theOutline):
|
def __init__(self, outlineView: GuiOutlineView) -> None:
|
||||||
super().__init__(parent=theOutline)
|
super().__init__(parent=outlineView)
|
||||||
|
|
||||||
logger.debug("Create: GuiOutlineToolBar")
|
logger.debug("Create: GuiOutlineToolBar")
|
||||||
|
|
||||||
@@ -221,7 +213,7 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
self.setContentsMargins(0, 0, 0, 0)
|
self.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
stretch = QWidget(self)
|
stretch = QWidget(self)
|
||||||
stretch.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
stretch.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||||
|
|
||||||
# Novel Selector
|
# Novel Selector
|
||||||
self.novelLabel = QLabel(self.tr("Outline of"))
|
self.novelLabel = QLabel(self.tr("Outline of"))
|
||||||
@@ -243,7 +235,7 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
|
|
||||||
self.tbColumns = QToolButton(self)
|
self.tbColumns = QToolButton(self)
|
||||||
self.tbColumns.setMenu(self.mColumns)
|
self.tbColumns.setMenu(self.mColumns)
|
||||||
self.tbColumns.setPopupMode(QToolButton.InstantPopup)
|
self.tbColumns.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup)
|
||||||
|
|
||||||
# Assemble
|
# Assemble
|
||||||
self.addWidget(self.novelLabel)
|
self.addWidget(self.novelLabel)
|
||||||
@@ -263,32 +255,26 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
# Methods
|
# Methods
|
||||||
##
|
##
|
||||||
|
|
||||||
def updateTheme(self):
|
def updateTheme(self) -> None:
|
||||||
"""Update theme elements.
|
"""Update theme elements."""
|
||||||
"""
|
|
||||||
self.setStyleSheet("QToolBar {border: 0px;}")
|
self.setStyleSheet("QToolBar {border: 0px;}")
|
||||||
|
|
||||||
self.novelValue.updateList(includeAll=True)
|
self.novelValue.updateList(includeAll=True)
|
||||||
self.aRefresh.setIcon(SHARED.theme.getIcon("refresh"))
|
self.aRefresh.setIcon(SHARED.theme.getIcon("refresh"))
|
||||||
self.tbColumns.setIcon(SHARED.theme.getIcon("menu"))
|
self.tbColumns.setIcon(SHARED.theme.getIcon("menu"))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def populateNovelList(self):
|
def populateNovelList(self) -> None:
|
||||||
"""Reload the content of the novel list.
|
"""Reload the content of the novel list."""
|
||||||
"""
|
|
||||||
self.novelValue.updateList(includeAll=True)
|
self.novelValue.updateList(includeAll=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
def setCurrentRoot(self, rootHandle):
|
def setCurrentRoot(self, rootHandle: str | None) -> None:
|
||||||
"""Set the current active root handle.
|
"""Set the current active root handle."""
|
||||||
"""
|
|
||||||
self.novelValue.setHandle(rootHandle)
|
self.novelValue.setHandle(rootHandle)
|
||||||
return
|
return
|
||||||
|
|
||||||
def setColumnHiddenState(self, hiddenState):
|
def setColumnHiddenState(self, hiddenState: dict[nwOutline, bool]) -> None:
|
||||||
"""Forward the change of column hidden states to the menu.
|
"""Forward the change of column hidden states to the menu."""
|
||||||
"""
|
|
||||||
self.mColumns.setHiddenState(hiddenState)
|
self.mColumns.setHiddenState(hiddenState)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -297,16 +283,14 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def _novelValueChanged(self, tHandle):
|
def _novelValueChanged(self, tHandle: str) -> None:
|
||||||
"""Emit a signal containing the handle of the selected item.
|
"""Emit a signal containing the handle of the selected item."""
|
||||||
"""
|
|
||||||
self.loadNovelRootRequest.emit(tHandle)
|
self.loadNovelRootRequest.emit(tHandle)
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _refreshRequested(self):
|
def _refreshRequested(self) -> None:
|
||||||
"""Emit a signal containing the handle of the selected item.
|
"""Emit a signal containing the handle of the selected item."""
|
||||||
"""
|
|
||||||
self.loadNovelRootRequest.emit(self.novelValue.handle)
|
self.loadNovelRootRequest.emit(self.novelValue.handle)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -361,7 +345,7 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
hiddenStateChanged = pyqtSignal()
|
hiddenStateChanged = pyqtSignal()
|
||||||
activeItemChanged = pyqtSignal(str, str)
|
activeItemChanged = pyqtSignal(str, str)
|
||||||
|
|
||||||
def __init__(self, outlineView):
|
def __init__(self, outlineView: GuiOutlineView) -> None:
|
||||||
super().__init__(parent=outlineView)
|
super().__init__(parent=outlineView)
|
||||||
|
|
||||||
logger.debug("Create: GuiOutlineTree")
|
logger.debug("Create: GuiOutlineTree")
|
||||||
@@ -369,9 +353,9 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
self.outlineView = outlineView
|
self.outlineView = outlineView
|
||||||
|
|
||||||
self.setUniformRowHeights(True)
|
self.setUniformRowHeights(True)
|
||||||
self.setFrameStyle(QFrame.NoFrame)
|
self.setFrameStyle(QFrame.Shape.NoFrame)
|
||||||
self.setSelectionBehavior(QAbstractItemView.SelectRows)
|
self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
||||||
self.setSelectionMode(QAbstractItemView.SingleSelection)
|
self.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
|
||||||
self.setExpandsOnDoubleClick(False)
|
self.setExpandsOnDoubleClick(False)
|
||||||
self.setDragEnabled(False)
|
self.setDragEnabled(False)
|
||||||
self.itemDoubleClicked.connect(self._treeDoubleClick)
|
self.itemDoubleClicked.connect(self._treeDoubleClick)
|
||||||
@@ -431,23 +415,19 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
# Methods
|
# Methods
|
||||||
##
|
##
|
||||||
|
|
||||||
def initSettings(self):
|
def initSettings(self) -> None:
|
||||||
"""Set or update outline settings.
|
"""Set or update outline settings."""
|
||||||
"""
|
|
||||||
# Scroll bars
|
|
||||||
if CONFIG.hideVScroll:
|
if CONFIG.hideVScroll:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||||
|
|
||||||
if CONFIG.hideHScroll:
|
if CONFIG.hideHScroll:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def clearContent(self):
|
def clearContent(self) -> None:
|
||||||
"""Clear the tree and header and set the default values for the
|
"""Clear the tree and header and set the default values for the
|
||||||
columns arrays.
|
columns arrays.
|
||||||
"""
|
"""
|
||||||
@@ -455,10 +435,10 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
self.setColumnCount(1)
|
self.setColumnCount(1)
|
||||||
self.setHeaderLabel(trConst(nwLabels.OUTLINE_COLS[nwOutline.TITLE]))
|
self.setHeaderLabel(trConst(nwLabels.OUTLINE_COLS[nwOutline.TITLE]))
|
||||||
|
|
||||||
self._treeOrder = []
|
self._treeOrder: list[nwOutline] = []
|
||||||
self._colWidth = {}
|
self._colWidth: dict[nwOutline, int] = {}
|
||||||
self._colHidden = {}
|
self._colHidden: dict[nwOutline, bool] = {}
|
||||||
self._colIdx = {}
|
self._colIdx: dict[nwOutline, int] = {}
|
||||||
self._treeNCols = 0
|
self._treeNCols = 0
|
||||||
|
|
||||||
for hItem in nwOutline:
|
for hItem in nwOutline:
|
||||||
@@ -470,7 +450,8 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def refreshTree(self, rootHandle=None, overRide=False, novelChanged=False):
|
def refreshTree(self, rootHandle: str | None = None,
|
||||||
|
overRide: bool = False, novelChanged: bool = False) -> None:
|
||||||
"""Called whenever the Outline tab is activated and controls
|
"""Called whenever the Outline tab is activated and controls
|
||||||
what data to load, and if necessary, force a rebuild of the
|
what data to load, and if necessary, force a rebuild of the
|
||||||
tree.
|
tree.
|
||||||
@@ -494,15 +475,14 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def closeProjectTasks(self):
|
def closeProjectTasks(self) -> None:
|
||||||
"""Called before a project is closed.
|
"""Called before a project is closed."""
|
||||||
"""
|
|
||||||
self._saveHeaderState()
|
self._saveHeaderState()
|
||||||
self.clearContent()
|
self.clearContent()
|
||||||
self._firstView = True
|
self._firstView = True
|
||||||
return
|
return
|
||||||
|
|
||||||
def getSelectedHandle(self):
|
def getSelectedHandle(self) -> tuple[str | None, str | None]:
|
||||||
"""Get the currently selected handle. If multiple items are
|
"""Get the currently selected handle. If multiple items are
|
||||||
selected, return the first.
|
selected, return the first.
|
||||||
"""
|
"""
|
||||||
@@ -518,7 +498,7 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot("QTreeWidgetItem*", int)
|
@pyqtSlot("QTreeWidgetItem*", int)
|
||||||
def _treeDoubleClick(self, tItem, tCol):
|
def _treeDoubleClick(self, tItem: QTreeWidgetItem, tCol: int) -> None:
|
||||||
"""Extract the handle and line number of the title double-
|
"""Extract the handle and line number of the title double-
|
||||||
clicked, and send it to the main gui class for opening in the
|
clicked, and send it to the main gui class for opening in the
|
||||||
document editor.
|
document editor.
|
||||||
@@ -530,7 +510,7 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _itemSelected(self):
|
def _itemSelected(self) -> None:
|
||||||
"""Extract the handle and line number of the currently selected
|
"""Extract the handle and line number of the currently selected
|
||||||
title, and send it to the details panel.
|
title, and send it to the details panel.
|
||||||
"""
|
"""
|
||||||
@@ -542,7 +522,7 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(int, int, int)
|
@pyqtSlot(int, int, int)
|
||||||
def _columnMoved(self, logIdx, oldVisualIdx, newVisualIdx):
|
def _columnMoved(self, logIdx: int, oldVisualIdx: int, newVisualIdx: int) -> None:
|
||||||
"""Make sure the order array is up to date with the actual order
|
"""Make sure the order array is up to date with the actual order
|
||||||
of the columns.
|
of the columns.
|
||||||
"""
|
"""
|
||||||
@@ -551,12 +531,12 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(bool, Enum)
|
@pyqtSlot(bool, Enum)
|
||||||
def menuColumnToggled(self, isChecked, theItem):
|
def menuColumnToggled(self, isChecked: bool, hItem: nwOutline) -> None:
|
||||||
"""Receive the changes to column visibility forwarded by the
|
"""Receive the changes to column visibility forwarded by the
|
||||||
column selection menu.
|
column selection menu.
|
||||||
"""
|
"""
|
||||||
if theItem in self._colIdx:
|
if hItem in self._colIdx:
|
||||||
self.setColumnHidden(self._colIdx[theItem], not isChecked)
|
self.setColumnHidden(self._colIdx[hItem], not isChecked)
|
||||||
self._saveHeaderState()
|
self._saveHeaderState()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -600,7 +580,7 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _saveHeaderState(self):
|
def _saveHeaderState(self) -> None:
|
||||||
"""Save the state of the main tree header, that is, column
|
"""Save the state of the main tree header, that is, column
|
||||||
order, column width and column hidden state. We don't want to
|
order, column width and column hidden state. We don't want to
|
||||||
save the current width of hidden columns though. This preserves
|
save the current width of hidden columns though. This preserves
|
||||||
@@ -627,7 +607,7 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _populateTree(self, rootHandle):
|
def _populateTree(self, rootHandle: str | None) -> None:
|
||||||
"""Build the tree based on the project index, and the header
|
"""Build the tree based on the project index, and the header
|
||||||
based on the defined constants, default values and user selected
|
based on the defined constants, default values and user selected
|
||||||
width, order and hidden state. All columns are populated, even
|
width, order and hidden state. All columns are populated, even
|
||||||
@@ -653,22 +633,25 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
|
|
||||||
headItem = self.headerItem()
|
headItem = self.headerItem()
|
||||||
if isinstance(headItem, QTreeWidgetItem):
|
if isinstance(headItem, QTreeWidgetItem):
|
||||||
headItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignRight)
|
headItem.setTextAlignment(
|
||||||
headItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
|
self._colIdx[nwOutline.CCOUNT], Qt.AlignmentFlag.AlignRight)
|
||||||
headItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
|
headItem.setTextAlignment(
|
||||||
|
self._colIdx[nwOutline.WCOUNT], Qt.AlignmentFlag.AlignRight)
|
||||||
|
headItem.setTextAlignment(
|
||||||
|
self._colIdx[nwOutline.PCOUNT], Qt.AlignmentFlag.AlignRight)
|
||||||
|
|
||||||
novStruct = SHARED.project.index.novelStructure(rootHandle=rootHandle, skipExcl=True)
|
novStruct = SHARED.project.index.novelStructure(rootHandle=rootHandle, skipExcl=True)
|
||||||
for _, tHandle, sTitle, novIdx in novStruct:
|
for _, tHandle, sTitle, novIdx in novStruct:
|
||||||
|
|
||||||
iLevel = nwHeaders.H_LEVEL.get(novIdx.level, 0)
|
iLevel = nwHeaders.H_LEVEL.get(novIdx.level, 0)
|
||||||
if iLevel == 0:
|
nwItem = SHARED.project.tree[tHandle]
|
||||||
|
if iLevel == 0 or nwItem is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
trItem = QTreeWidgetItem()
|
trItem = QTreeWidgetItem()
|
||||||
nwItem = SHARED.project.tree[tHandle]
|
|
||||||
hDec = SHARED.theme.getHeaderDecoration(iLevel)
|
hDec = SHARED.theme.getHeaderDecoration(iLevel)
|
||||||
|
|
||||||
trItem.setData(self._colIdx[nwOutline.TITLE], Qt.DecorationRole, hDec)
|
trItem.setData(self._colIdx[nwOutline.TITLE], Qt.ItemDataRole.DecorationRole, hDec)
|
||||||
trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title)
|
trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title)
|
||||||
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle)
|
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle)
|
||||||
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle)
|
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle)
|
||||||
@@ -681,9 +664,9 @@ class GuiOutlineTree(QTreeWidget):
|
|||||||
trItem.setText(self._colIdx[nwOutline.CCOUNT], f"{novIdx.charCount:n}")
|
trItem.setText(self._colIdx[nwOutline.CCOUNT], f"{novIdx.charCount:n}")
|
||||||
trItem.setText(self._colIdx[nwOutline.WCOUNT], f"{novIdx.wordCount:n}")
|
trItem.setText(self._colIdx[nwOutline.WCOUNT], f"{novIdx.wordCount:n}")
|
||||||
trItem.setText(self._colIdx[nwOutline.PCOUNT], f"{novIdx.paraCount:n}")
|
trItem.setText(self._colIdx[nwOutline.PCOUNT], f"{novIdx.paraCount:n}")
|
||||||
trItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignRight)
|
trItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignmentFlag.AlignRight)
|
||||||
trItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
|
trItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignmentFlag.AlignRight)
|
||||||
trItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
|
trItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignmentFlag.AlignRight)
|
||||||
|
|
||||||
refs = SHARED.project.index.getReferences(tHandle, sTitle)
|
refs = SHARED.project.index.getReferences(tHandle, sTitle)
|
||||||
trItem.setText(self._colIdx[nwOutline.POV], ", ".join(refs[nwKeyWords.POV_KEY]))
|
trItem.setText(self._colIdx[nwOutline.POV], ", ".join(refs[nwKeyWords.POV_KEY]))
|
||||||
@@ -709,8 +692,8 @@ class GuiOutlineHeaderMenu(QMenu):
|
|||||||
|
|
||||||
columnToggled = pyqtSignal(bool, Enum)
|
columnToggled = pyqtSignal(bool, Enum)
|
||||||
|
|
||||||
def __init__(self, theOutline):
|
def __init__(self, outlineToolBar: GuiOutlineToolBar) -> None:
|
||||||
super().__init__(parent=theOutline)
|
super().__init__(parent=outlineToolBar)
|
||||||
|
|
||||||
self.acceptToggle = True
|
self.acceptToggle = True
|
||||||
|
|
||||||
@@ -731,7 +714,7 @@ class GuiOutlineHeaderMenu(QMenu):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def setHiddenState(self, hiddenState):
|
def setHiddenState(self, hiddenState: dict[nwOutline, bool]) -> None:
|
||||||
"""Overwrite the checked state of the columns as the inverse of
|
"""Overwrite the checked state of the columns as the inverse of
|
||||||
the hidden state. Skip the TITLE column as it cannot be hidden.
|
the hidden state. Skip the TITLE column as it cannot be hidden.
|
||||||
"""
|
"""
|
||||||
@@ -760,12 +743,12 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
|
|
||||||
itemTagClicked = pyqtSignal(str)
|
itemTagClicked = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, theOutline):
|
def __init__(self, outlineView: GuiOutlineView) -> None:
|
||||||
super().__init__(parent=theOutline)
|
super().__init__(parent=outlineView)
|
||||||
|
|
||||||
logger.debug("Create: GuiOutlineDetails")
|
logger.debug("Create: GuiOutlineDetails")
|
||||||
|
|
||||||
self.theOutline = theOutline
|
self.outlineView = outlineView
|
||||||
|
|
||||||
# Sizes
|
# Sizes
|
||||||
minTitle = 30*SHARED.theme.textNWidth
|
minTitle = 30*SHARED.theme.textNWidth
|
||||||
@@ -878,23 +861,26 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
|
|
||||||
# Selected Item Details
|
# Selected Item Details
|
||||||
self.mainGroup = QGroupBox(self.tr("Title Details"), self)
|
self.mainGroup = QGroupBox(self.tr("Title Details"), self)
|
||||||
self.mainForm = QGridLayout()
|
self.mainForm = QGridLayout()
|
||||||
self.mainGroup.setLayout(self.mainForm)
|
self.mainGroup.setLayout(self.mainForm)
|
||||||
|
|
||||||
self.mainForm.addWidget(self.titleLabel, 0, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
topLeft = Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft
|
||||||
self.mainForm.addWidget(self.titleValue, 0, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
topRight = Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignRight
|
||||||
self.mainForm.addWidget(self.cCLabel, 0, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
|
||||||
self.mainForm.addWidget(self.cCValue, 0, 3, 1, 1, Qt.AlignTop | Qt.AlignRight)
|
self.mainForm.addWidget(self.titleLabel, 0, 0, 1, 1, topLeft)
|
||||||
self.mainForm.addWidget(self.fileLabel, 1, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.titleValue, 0, 1, 1, 1, topLeft)
|
||||||
self.mainForm.addWidget(self.fileValue, 1, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.cCLabel, 0, 2, 1, 1, topLeft)
|
||||||
self.mainForm.addWidget(self.wCLabel, 1, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.cCValue, 0, 3, 1, 1, topRight)
|
||||||
self.mainForm.addWidget(self.wCValue, 1, 3, 1, 1, Qt.AlignTop | Qt.AlignRight)
|
self.mainForm.addWidget(self.fileLabel, 1, 0, 1, 1, topLeft)
|
||||||
self.mainForm.addWidget(self.itemLabel, 2, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.fileValue, 1, 1, 1, 1, topLeft)
|
||||||
self.mainForm.addWidget(self.itemValue, 2, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.wCLabel, 1, 2, 1, 1, topLeft)
|
||||||
self.mainForm.addWidget(self.pCLabel, 2, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.wCValue, 1, 3, 1, 1, topRight)
|
||||||
self.mainForm.addWidget(self.pCValue, 2, 3, 1, 1, Qt.AlignTop | Qt.AlignRight)
|
self.mainForm.addWidget(self.itemLabel, 2, 0, 1, 1, topLeft)
|
||||||
self.mainForm.addWidget(self.synopLabel, 3, 0, 1, 4, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.itemValue, 2, 1, 1, 1, topLeft)
|
||||||
self.mainForm.addLayout(self.synopLWrap, 4, 0, 1, 4, Qt.AlignTop | Qt.AlignLeft)
|
self.mainForm.addWidget(self.pCLabel, 2, 2, 1, 1, topLeft)
|
||||||
|
self.mainForm.addWidget(self.pCValue, 2, 3, 1, 1, topRight)
|
||||||
|
self.mainForm.addWidget(self.synopLabel, 3, 0, 1, 4, topLeft)
|
||||||
|
self.mainForm.addLayout(self.synopLWrap, 4, 0, 1, 4, topLeft)
|
||||||
|
|
||||||
self.mainForm.setColumnStretch(1, 1)
|
self.mainForm.setColumnStretch(1, 1)
|
||||||
self.mainForm.setRowStretch(4, 1)
|
self.mainForm.setRowStretch(4, 1)
|
||||||
@@ -906,24 +892,24 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
self.tagsForm = QGridLayout()
|
self.tagsForm = QGridLayout()
|
||||||
self.tagsGroup.setLayout(self.tagsForm)
|
self.tagsGroup.setLayout(self.tagsForm)
|
||||||
|
|
||||||
self.tagsForm.addWidget(self.povKeyLabel, 0, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.povKeyLabel, 0, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.povKeyLWrap, 0, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.povKeyLWrap, 0, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.focKeyLabel, 1, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.focKeyLabel, 1, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.focKeyLWrap, 1, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.focKeyLWrap, 1, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.chrKeyLabel, 2, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.chrKeyLabel, 2, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.chrKeyLWrap, 2, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.chrKeyLWrap, 2, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.pltKeyLabel, 3, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.pltKeyLabel, 3, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.pltKeyLWrap, 3, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.pltKeyLWrap, 3, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.timKeyLabel, 4, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.timKeyLabel, 4, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.timKeyLWrap, 4, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.timKeyLWrap, 4, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.wldKeyLabel, 5, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.wldKeyLabel, 5, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.wldKeyLWrap, 5, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.wldKeyLWrap, 5, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.objKeyLabel, 6, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.objKeyLabel, 6, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.objKeyLWrap, 6, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.objKeyLWrap, 6, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.entKeyLabel, 7, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.entKeyLabel, 7, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.entKeyLWrap, 7, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.entKeyLWrap, 7, 1, 1, 1, topLeft)
|
||||||
self.tagsForm.addWidget(self.cstKeyLabel, 8, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addWidget(self.cstKeyLabel, 8, 0, 1, 1, topLeft)
|
||||||
self.tagsForm.addLayout(self.cstKeyLWrap, 8, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft)
|
self.tagsForm.addLayout(self.cstKeyLWrap, 8, 1, 1, 1, topLeft)
|
||||||
|
|
||||||
self.tagsForm.setColumnStretch(1, 1)
|
self.tagsForm.setColumnStretch(1, 1)
|
||||||
self.tagsForm.setRowStretch(8, 1)
|
self.tagsForm.setRowStretch(8, 1)
|
||||||
@@ -939,10 +925,10 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
self.outerWidget.setLayout(self.outerBox)
|
self.outerWidget.setLayout(self.outerBox)
|
||||||
self.setWidget(self.outerWidget)
|
self.setWidget(self.outerWidget)
|
||||||
|
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||||
self.setWidgetResizable(True)
|
self.setWidgetResizable(True)
|
||||||
self.setFrameStyle(QFrame.NoFrame)
|
self.setFrameStyle(QFrame.Shape.NoFrame)
|
||||||
|
|
||||||
self.initSettings()
|
self.initSettings()
|
||||||
|
|
||||||
@@ -950,27 +936,21 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def initSettings(self):
|
def initSettings(self) -> None:
|
||||||
"""Set or update outline settings.
|
"""Set or update outline settings."""
|
||||||
"""
|
|
||||||
# Scroll bars
|
|
||||||
if CONFIG.hideVScroll:
|
if CONFIG.hideVScroll:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||||
|
|
||||||
if CONFIG.hideHScroll:
|
if CONFIG.hideHScroll:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||||
|
|
||||||
self.updateClasses()
|
self.updateClasses()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def clearDetails(self):
|
def clearDetails(self) -> None:
|
||||||
"""Clear all the data labels.
|
"""Clear all the data labels."""
|
||||||
"""
|
|
||||||
self.titleLabel.setText("<b>%s</b>" % self.tr("Title"))
|
self.titleLabel.setText("<b>%s</b>" % self.tr("Title"))
|
||||||
self.titleValue.setText("")
|
self.titleValue.setText("")
|
||||||
self.fileValue.setText("")
|
self.fileValue.setText("")
|
||||||
@@ -996,7 +976,7 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def showItem(self, tHandle, sTitle):
|
def showItem(self, tHandle: str, sTitle: str) -> bool:
|
||||||
"""Update the content of the tree with the given handle and line
|
"""Update the content of the tree with the given handle and line
|
||||||
number pointing to a header.
|
number pointing to a header.
|
||||||
"""
|
"""
|
||||||
@@ -1041,9 +1021,8 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def updateClasses(self):
|
def updateClasses(self) -> None:
|
||||||
"""Update the visibility status of class details.
|
"""Update the visibility status of class details."""
|
||||||
"""
|
|
||||||
usedClasses = SHARED.project.tree.rootClasses()
|
usedClasses = SHARED.project.tree.rootClasses()
|
||||||
|
|
||||||
pltVisible = nwItemClass.PLOT in usedClasses
|
pltVisible = nwItemClass.PLOT in usedClasses
|
||||||
@@ -1069,9 +1048,8 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _formatTags(refs, key):
|
def _formatTags(refs: dict[str, list[str]], key: str) -> str:
|
||||||
"""Convert a list of tags into a list of clickable tag links.
|
"""Convert a list of tags into a list of clickable tag links."""
|
||||||
"""
|
|
||||||
return ", ".join(
|
return ", ".join(
|
||||||
[f"<a href='{tag}'>{tag}</a>" for tag in refs.get(key, [])]
|
[f"<a href='{tag}'>{tag}</a>" for tag in refs.get(key, [])]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user