Started work on character multi-selection features.

-Added currentCharacters method, a list counterpart of currentCharacter.

-Replaced the connection for currentItemChanged with itemSelectionChanged. This is to accommodate for the bulk-changes when multiple characters are selected. The currentItemChanged method is now not called with a connection, but from the handleCharacterSelectionChanged method. The latter is called with the itemSelectionChanged connection.

-If no valid characters are selected, the tabPersos widget is disabled. This obviously breaks the functionality of bulk-adding info to characters. This will have to be fixed by only disabling the parts of the tabPersos widget that should not be affected with multiple selection operations.
This commit is contained in:
tntscreed 2023-03-05 14:14:58 +01:00
parent eaebfa9dfa
commit fc86ed5df6
2 changed files with 27 additions and 8 deletions

View file

@ -297,17 +297,26 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# CHARACTERS
###############################################################################
def changeCurrentCharacter(self, trash=None):
"""
def handleCharacterSelectionChanged(self):
selectedCharacters = self.lstCharacters.currentCharacters()
characterSelectionIsEmpty = True
for c in selectedCharacters:
if c is not None:
characterSelectionIsEmpty = False
@return:
"""
c = self.lstCharacters.currentCharacter()
if not c:
if characterSelectionIsEmpty:
self.tabPersos.setEnabled(False)
elif len(selectedCharacters)>1:
self.tabPersos.setEnabled(False)
else:
self.tabPersos.setEnabled(True)
self.changeCurrentCharacter()
def changeCurrentCharacter(self, trash=None):
c = self.lstCharacters.currentCharacter()
if c is None:
return
self.tabPersos.setEnabled(True)
index = c.index()
for w in [
@ -903,7 +912,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def makeUIConnections(self):
"Connections that have to be made once only, even when a new project is loaded."
self.lstCharacters.currentItemChanged.connect(self.changeCurrentCharacter, F.AUC)
self.lstCharacters.itemSelectionChanged.connect(self.handleCharacterSelectionChanged, F.AUC)
self.txtPlotFilter.textChanged.connect(self.lstPlots.setFilter, F.AUC)
self.lstPlots.currentItemChanged.connect(self.changeCurrentPlot, F.AUC)

View file

@ -213,6 +213,16 @@ class characterTreeView(QTreeWidget):
"""
ID = self.currentCharacterID()
return self._model.getCharacterByID(ID)
def currentCharacters(self):
"""
Returns the selected characters (when multiple are selected)
@return: List of Characters
"""
IDs = self.currentCharacterIDs()
characters = []
for ID in IDs:
characters.append(self._model.getCharacterByID(ID))
return characters
def getItemByID(self, ID):
for t in range(self.topLevelItemCount()):