From 581d065d7a9b52d3beddecb95d4353dbb81b5bb4 Mon Sep 17 00:00:00 2001 From: TheBloke Date: Sat, 12 Jul 2014 11:15:34 +0100 Subject: savegameList: A few cleanups and minor code improvements - Slight improvements over previous commits, using more appropriate methods and removing some unnecessary code. No functional changes. --- src/mainwindow.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 344173d4..fc0f8aa1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3889,22 +3889,23 @@ void MainWindow::deleteSavegame_clicked() if (!selection->hasSelection()) return; - int selectedCount = selection->selectedRows().count(); QString savesMsgLabel; QRegExp saveSuffix(".ess$"); QStringList deleteFiles; - foreach (QModelIndex idx, selection->selectedRows()) { + foreach (QModelIndex idx, selection->selectedIndexes()) { QString name = idx.data().toString(); - QString filename = idx.data(Qt::UserRole).toString(); + SaveGame *save = new SaveGame(this, idx.data(Qt::UserRole).toString()); - SaveGame *save = new SaveGame(this, filename); savesMsgLabel += "
  • " + name.replace(saveSuffix, "") + "
  • "; + deleteFiles << save->saveFiles(); } + bool multipleRows = (selection->selectedIndexes().count() > 1); + if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following save%1?

    Removed saves will be sent to the Recycle Bin.") - .arg((selectedCount > 1) ? "s" : "") + .arg((multipleRows) ? "s" : "") .arg(savesMsgLabel), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { shellDelete(deleteFiles, true); // recycle bin delete. @@ -3914,12 +3915,10 @@ void MainWindow::deleteSavegame_clicked() void MainWindow::fixMods_clicked() { - QItemSelectionModel *selection = ui->savegameList->selectionModel(); + QListWidgetItem *selectedItem = ui->savegameList->currentItem(); - if (!selection->hasSelection() || selection->selectedRows().count() > 1) - return; // Count should never be > 1 because of condition on context menu; check again just for safety. - - QListWidgetItem *selectedItem = ui->savegameList->item(selection->selectedRows().first().row()); + if (selectedItem == NULL) + return; // if required, parse the save game if (selectedItem->data(Qt::UserRole).isNull()) { @@ -4017,7 +4016,7 @@ void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) if ( selectedCount == 0) { return; - } else if (currentSelection.count() == 1) + } else if (selectedCount == 1) enableFixMods = true; QMenu menu; -- cgit v1.3.1