From 06f8ab35198c9a758ff595da95f30e3a4ed721ac Mon Sep 17 00:00:00 2001 From: tntscreed Date: Tue, 7 Mar 2023 20:27:16 +0100 Subject: [PATCH] The bulk info managers is now completely functional. Also, a change has been made to the character tree view. Theoretically it shouldn't have any functional significance, but "addCharacterInfo" is used for adding info to only one character, so it makes sense to remove the old multi-selection info-adding functionality, even if it wouldn't ever be accessible. --- manuskript/mainWindow.py | 30 +++++++++++++++++++++--- manuskript/ui/views/characterTreeView.py | 5 ++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/manuskript/mainWindow.py b/manuskript/mainWindow.py index a4f7f8c..c2f7887 100644 --- a/manuskript/mainWindow.py +++ b/manuskript/mainWindow.py @@ -339,7 +339,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): bulkPersoInfoManagerUi.lblCharactersDynamic.setText(labelText) # Making the connections - self.setBulkInfoConnections(bulkPersoInfoManagerUi) + self.makeBulkInfoConnections(bulkPersoInfoManagerUi) elif enabled and self.BulkManageUi is not None: # If yet another character is selected, refresh the label labelText = "" @@ -355,10 +355,32 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.BulkManageUi = None self.bulkAffectedCharacters.clear() - def setBulkInfoConnections(self, bulkUi): + def makeBulkInfoConnections(self, bulkUi): # A lambda has to be used to pass in the argument bulkUi.btnPersoBulkAddInfo.clicked.connect(lambda: self.addBulkInfo(bulkUi)) bulkUi.btnPersoBulkRmInfo.clicked.connect(lambda: self.removeBulkInfo(bulkUi)) + bulkUi.btnPersoBulkApply.clicked.connect(lambda: self.applyBulkInfo(bulkUi)) + + def applyBulkInfo(self, bulkUi): + selectedItems = self.lstCharacters.currentCharacterIDs() + + # Get the data from the tableview + model = bulkUi.tableView.model() + if model.rowCount() == 0: + QMessageBox.warning(self, "No Entries!", "Please information to apply to the selected characters.") + return + + # Loop through each selected character and add the bulk info to them + for ID in selectedItems: + for row in range(model.rowCount()): + description = model.item(row, 0).text() + value = model.item(row, 1).text() + self.lstCharacters._model.addCharacterInfo(ID, description, value) + + QMessageBox.information(self, "Bulk Info Applied", "The bulk info has been applied to the selected characters.") + + #Remove all rows from the table + model.removeRows(0, model.rowCount()) def addBulkInfo(self, bulkUi): # Adds an item to the list charInfoDialog = QDialog() @@ -380,10 +402,12 @@ class MainWindow(QMainWindow, Ui_MainWindow): # Get the selected rows selection = bulkUi.tableView.selectionModel().selectedRows() - # Iterate over the rows and remove them + # Iterate over the rows and remove them (reversed, so the iteration is not affected) for index in reversed(selection): bulkUi.tableView.model().removeRow(index.row()) + + def saveCharacterTabs(self): tabsData = [] for i in range(self.tabPersos.count()): diff --git a/manuskript/ui/views/characterTreeView.py b/manuskript/ui/views/characterTreeView.py index 1cea219..c02b875 100644 --- a/manuskript/ui/views/characterTreeView.py +++ b/manuskript/ui/views/characterTreeView.py @@ -182,9 +182,8 @@ class characterTreeView(QTreeWidget): value = charInfoUi.valueLineEdit.text() # Add the character info with the input values - IDs = self.currentCharacterIDs() - for ID in IDs: - self._model.addCharacterInfo(ID, description, value) + ID = self.currentCharacterID() + self._model.addCharacterInfo(ID, description, value)