Clones importance setting.

When creating a new character, sets an appropriate importance level.
* If a character is selected, the new character has the same importance level.
* If a top-level importance level is selected, the new character has that level
* Otherwise, the importance level is zero
This commit is contained in:
bentleyjoakes 2020-05-31 22:33:14 +02:00
parent 517559e7fa
commit 06e35cd969
3 changed files with 28 additions and 11 deletions

View file

@ -948,9 +948,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Characters # Characters
self.lstCharacters.setCharactersModel(self.mdlCharacter) self.lstCharacters.setCharactersModel(self.mdlCharacter)
self.tblPersoInfos.setModel(self.mdlCharacter) self.tblPersoInfos.setModel(self.mdlCharacter)
self.btnAddPerso.clicked.connect(self.lstCharacters.addCharacter, F.AUC)
self.btnAddPerso.clicked.connect(self.mdlCharacter.addCharacter, F.AUC)
try: try:
self.btnRmPerso.clicked.connect(self.lstCharacters.removeCharacter, F.AUC) self.btnRmPerso.clicked.connect(self.lstCharacters.removeCharacter, F.AUC)

View file

@ -165,12 +165,13 @@ class characterModel(QAbstractItemModel):
# ADDING / REMOVING # ADDING / REMOVING
############################################################################### ###############################################################################
def addCharacter(self): def addCharacter(self, importance = 0):
""" """
Creates a new character Creates a new character
@param importance: the importance level of the character
@return: the character @return: the character
""" """
c = Character(model=self, name=self.tr("New character")) c = Character(model=self, name=self.tr("New character"), importance = importance)
self.beginInsertRows(QModelIndex(), len(self.characters), len(self.characters)) self.beginInsertRows(QModelIndex(), len(self.characters), len(self.characters))
self.characters.append(c) self.characters.append(c)
self.endInsertRows() self.endInsertRows()
@ -228,7 +229,7 @@ class characterModel(QAbstractItemModel):
############################################################################### ###############################################################################
class Character(): class Character():
def __init__(self, model, name="No name"): def __init__(self, model, name="No name", importance = 0):
self._model = model self._model = model
self.lastPath = "" self.lastPath = ""
@ -236,7 +237,7 @@ class Character():
self._data[C.name.value] = name self._data[C.name.value] = name
self.assignUniqueID() self.assignUniqueID()
self.assignRandomColor() self.assignRandomColor()
self._data[C.importance.value] = "0" self._data[C.importance.value] = str(importance)
self._data[C.pov.value] = "True" self._data[C.pov.value] = "True"
self.infos = [] self.infos = []

View file

@ -29,6 +29,8 @@ class characterTreeView(QTreeWidget):
self._rootItem = QTreeWidgetItem() self._rootItem = QTreeWidgetItem()
self.insertTopLevelItem(0, self._rootItem) self.insertTopLevelItem(0, self._rootItem)
self.importanceMap = {self.tr("Main"):2, self.tr("Secondary"):1, self.tr("Minor"):0}
def setCharactersModel(self, model): def setCharactersModel(self, model):
self._model = model self._model = model
self._model.dataChanged.connect(self.updateMaybe) self._model.dataChanged.connect(self.updateMaybe)
@ -86,11 +88,9 @@ class characterTreeView(QTreeWidget):
self.clear() self.clear()
characters = self._model.getCharactersByImportance() characters = self._model.getCharactersByImportance()
h = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")] for i, importanceLevel in enumerate(self.importanceMap):
for i in range(3):
# Create category item # Create category item
cat = QTreeWidgetItem(self, [h[i]]) cat = QTreeWidgetItem(self, [importanceLevel])
cat.setBackground(0, QBrush(QColor(S.highlightLight))) cat.setBackground(0, QBrush(QColor(S.highlightLight)))
cat.setForeground(0, QBrush(QColor(S.highlightedTextDark))) cat.setForeground(0, QBrush(QColor(S.highlightedTextDark)))
cat.setTextAlignment(0, Qt.AlignCenter) cat.setTextAlignment(0, Qt.AlignCenter)
@ -119,6 +119,24 @@ class characterTreeView(QTreeWidget):
self.expandAll() self.expandAll()
self._updating = False self._updating = False
def addCharacter(self):
curr_item = self.currentItem()
curr_importance = 0
# check if an item is selected
if curr_item is not None:
if curr_item.parent() is None:
# this is a top-level category, so find its importance
# get the current text, then look up the importance level
text = curr_item.text(0)
curr_importance = self.importanceMap[text]
else:
# get the importance from the currently-highlighted character
curr_character = self.currentCharacter()
curr_importance = curr_character.importance()
self._model.addCharacter(importance=curr_importance)
def removeCharacter(self): def removeCharacter(self):
""" """
Removes selected character. Removes selected character.