Improve novel extra data column
This commit is contained in:
@@ -332,16 +332,16 @@ class IndexHeading:
|
|||||||
refs = {x: [] for x in nwKeyWords.VALID_KEYS}
|
refs = {x: [] for x in nwKeyWords.VALID_KEYS}
|
||||||
for tag, types in self._refs.items():
|
for tag, types in self._refs.items():
|
||||||
for keyword in types:
|
for keyword in types:
|
||||||
if keyword in refs:
|
if keyword in refs and (name := self._tags.tagName(tag)):
|
||||||
refs[keyword].append(self._tags.tagName(tag))
|
refs[keyword].append(name)
|
||||||
return refs
|
return refs
|
||||||
|
|
||||||
def getReferencesByKeyword(self, keyword: str) -> list[str]:
|
def getReferencesByKeyword(self, keyword: str) -> list[str]:
|
||||||
"""Extract all references for this heading."""
|
"""Extract all references for this heading."""
|
||||||
refs = []
|
refs = []
|
||||||
for tag, types in self._refs.items():
|
for tag, types in self._refs.items():
|
||||||
if keyword in types:
|
if keyword in types and (name := self._tags.tagName(tag)):
|
||||||
refs.append(self._tags.tagName(tag))
|
refs.append(name)
|
||||||
return refs
|
return refs
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ R_TIP = Qt.ItemDataRole.ToolTipRole
|
|||||||
R_HANDLE = 0xff01
|
R_HANDLE = 0xff01
|
||||||
R_KEY = 0xff02
|
R_KEY = 0xff02
|
||||||
|
|
||||||
T_NodeData = str | tuple[str, str] | QIcon | QPixmap | Qt.AlignmentFlag | None
|
T_NodeData = str | QIcon | QPixmap | Qt.AlignmentFlag | None
|
||||||
|
|
||||||
|
|
||||||
class NovelModel(QAbstractTableModel):
|
class NovelModel(QAbstractTableModel):
|
||||||
@@ -210,19 +210,19 @@ class NovelModel(QAbstractTableModel):
|
|||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
def _generateEntry(self, handle: str, key: str, heading: IndexHeading) -> dict:
|
def _generateEntry(self, handle: str, key: str, head: IndexHeading) -> dict[int, T_NodeData]:
|
||||||
"""Generate a cache entry."""
|
"""Generate a cache entry."""
|
||||||
iLevel = nwStyles.H_LEVEL.get(heading.level, 0)
|
iLevel = nwStyles.H_LEVEL.get(head.level, 0)
|
||||||
data = {}
|
data = {}
|
||||||
data[C_FACTOR*0 | R_TIP] = heading.title
|
data[C_FACTOR*0 | R_TIP] = head.title
|
||||||
data[C_FACTOR*0 | R_TEXT] = heading.title
|
data[C_FACTOR*0 | R_TEXT] = head.title
|
||||||
data[C_FACTOR*0 | R_ICON] = SHARED.theme.getHeaderDecoration(iLevel)
|
data[C_FACTOR*0 | R_ICON] = SHARED.theme.getHeaderDecoration(iLevel)
|
||||||
data[C_FACTOR*1 | R_TEXT] = f"{heading.mainCount:n}"
|
data[C_FACTOR*1 | R_TEXT] = f"{head.mainCount:n}"
|
||||||
data[C_FACTOR*1 | R_ALIGN] = QtAlignRight
|
data[C_FACTOR*1 | R_ALIGN] = QtAlignRight
|
||||||
if self._columns == 3:
|
if self._columns == 3:
|
||||||
data[C_FACTOR*2 | R_ICON] = self._more
|
data[C_FACTOR*2 | R_ICON] = self._more
|
||||||
else:
|
else:
|
||||||
if self._extraKey and (refs := heading.getReferencesByKeyword(self._extraKey)):
|
if self._extraKey and (refs := head.getReferencesByKeyword(self._extraKey)):
|
||||||
text = ", ".join(refs)
|
text = ", ".join(refs)
|
||||||
data[C_FACTOR*2 | R_TEXT] = text
|
data[C_FACTOR*2 | R_TEXT] = text
|
||||||
data[C_FACTOR*2 | R_TIP] = f"<b>{self._extraLabel}:</b> {text}"
|
data[C_FACTOR*2 | R_TIP] = f"<b>{self._extraLabel}:</b> {text}"
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ from novelwriter.extensions.modified import NIconToolButton, NTreeView
|
|||||||
from novelwriter.extensions.novelselector import NovelSelector
|
from novelwriter.extensions.novelselector import NovelSelector
|
||||||
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
|
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
|
||||||
from novelwriter.types import (
|
from novelwriter.types import (
|
||||||
QtHeaderFixed, QtHeaderStretch, QtHeaderToContents, QtScrollAlwaysOff,
|
QtHeaderStretch, QtHeaderToContents, QtScrollAlwaysOff, QtScrollAsNeeded,
|
||||||
QtScrollAsNeeded, QtSizeExpanding
|
QtSizeExpanding
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -481,12 +481,10 @@ class GuiNovelTree(NTreeView):
|
|||||||
header.setMinimumSectionSize(SHARED.theme.baseIconHeight + 6)
|
header.setMinimumSectionSize(SHARED.theme.baseIconHeight + 6)
|
||||||
header.setSectionResizeMode(0, QtHeaderStretch)
|
header.setSectionResizeMode(0, QtHeaderStretch)
|
||||||
header.setSectionResizeMode(1, QtHeaderToContents)
|
header.setSectionResizeMode(1, QtHeaderToContents)
|
||||||
if model.columns == 3:
|
header.setSectionResizeMode(2, QtHeaderToContents)
|
||||||
header.setSectionResizeMode(2, QtHeaderToContents)
|
if model.columns == 4:
|
||||||
elif model.columns == 4:
|
|
||||||
header.setSectionResizeMode(2, QtHeaderFixed)
|
|
||||||
header.setSectionResizeMode(3, QtHeaderToContents)
|
header.setSectionResizeMode(3, QtHeaderToContents)
|
||||||
header.resizeSection(2, int(self._lastColSize * vp.width()))
|
header.setMaximumSectionSize(int(self._lastColSize * vp.width()))
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user