mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-14 09:52:27 +12:00
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:
parent
517559e7fa
commit
06e35cd969
|
@ -948,9 +948,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
# Characters
|
||||
self.lstCharacters.setCharactersModel(self.mdlCharacter)
|
||||
self.tblPersoInfos.setModel(self.mdlCharacter)
|
||||
|
||||
self.btnAddPerso.clicked.connect(self.mdlCharacter.addCharacter, F.AUC)
|
||||
|
||||
self.btnAddPerso.clicked.connect(self.lstCharacters.addCharacter, F.AUC)
|
||||
try:
|
||||
self.btnRmPerso.clicked.connect(self.lstCharacters.removeCharacter, F.AUC)
|
||||
|
||||
|
|
|
@ -165,12 +165,13 @@ class characterModel(QAbstractItemModel):
|
|||
# ADDING / REMOVING
|
||||
###############################################################################
|
||||
|
||||
def addCharacter(self):
|
||||
def addCharacter(self, importance = 0):
|
||||
"""
|
||||
Creates a new character
|
||||
@param importance: the importance level of 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.characters.append(c)
|
||||
self.endInsertRows()
|
||||
|
@ -228,7 +229,7 @@ class characterModel(QAbstractItemModel):
|
|||
###############################################################################
|
||||
|
||||
class Character():
|
||||
def __init__(self, model, name="No name"):
|
||||
def __init__(self, model, name="No name", importance = 0):
|
||||
self._model = model
|
||||
self.lastPath = ""
|
||||
|
||||
|
@ -236,7 +237,7 @@ class Character():
|
|||
self._data[C.name.value] = name
|
||||
self.assignUniqueID()
|
||||
self.assignRandomColor()
|
||||
self._data[C.importance.value] = "0"
|
||||
self._data[C.importance.value] = str(importance)
|
||||
self._data[C.pov.value] = "True"
|
||||
|
||||
self.infos = []
|
||||
|
|
|
@ -29,6 +29,8 @@ class characterTreeView(QTreeWidget):
|
|||
self._rootItem = QTreeWidgetItem()
|
||||
self.insertTopLevelItem(0, self._rootItem)
|
||||
|
||||
self.importanceMap = {self.tr("Main"):2, self.tr("Secondary"):1, self.tr("Minor"):0}
|
||||
|
||||
def setCharactersModel(self, model):
|
||||
self._model = model
|
||||
self._model.dataChanged.connect(self.updateMaybe)
|
||||
|
@ -86,11 +88,9 @@ class characterTreeView(QTreeWidget):
|
|||
self.clear()
|
||||
characters = self._model.getCharactersByImportance()
|
||||
|
||||
h = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]
|
||||
|
||||
for i in range(3):
|
||||
for i, importanceLevel in enumerate(self.importanceMap):
|
||||
# Create category item
|
||||
cat = QTreeWidgetItem(self, [h[i]])
|
||||
cat = QTreeWidgetItem(self, [importanceLevel])
|
||||
cat.setBackground(0, QBrush(QColor(S.highlightLight)))
|
||||
cat.setForeground(0, QBrush(QColor(S.highlightedTextDark)))
|
||||
cat.setTextAlignment(0, Qt.AlignCenter)
|
||||
|
@ -119,6 +119,24 @@ class characterTreeView(QTreeWidget):
|
|||
self.expandAll()
|
||||
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):
|
||||
"""
|
||||
Removes selected character.
|
||||
|
|
Loading…
Reference in a new issue