| 476 | } |
| 477 | |
| 478 | bool ModList::renameMod(int index, const QString& newName) |
| 479 | { |
| 480 | QString nameFixed = newName; |
| 481 | if (!fixDirectoryName(nameFixed) || nameFixed.isEmpty()) { |
| 482 | MessageDialog::showMessage(tr("Invalid name"), nullptr); |
| 483 | return false; |
| 484 | } |
| 485 | |
| 486 | if (ModList::allMods().contains(nameFixed, Qt::CaseInsensitive) && |
| 487 | nameFixed.toLower() != ModInfo::getByIndex(index)->name().toLower()) { |
| 488 | MessageDialog::showMessage(tr("Name is already in use by another mod"), nullptr); |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | ModInfo::Ptr modInfo = ModInfo::getByIndex(index); |
| 493 | QString oldName = modInfo->name(); |
| 494 | if (nameFixed != oldName) { |
| 495 | // before we rename, ensure there is no scheduled asynchronous to rewrite |
| 496 | m_Profile->cancelModlistWrite(); |
| 497 | |
| 498 | if (modInfo->setName(nameFixed)) { |
| 499 | // Notice there is a good chance that setName() updated the modinfo indexes |
| 500 | // the modRenamed() call will refresh the indexes in the current profile |
| 501 | // and update the modlists in all profiles |
| 502 | emit modRenamed(oldName, nameFixed); |
| 503 | } |
| 504 | |
| 505 | // invalidate the currently displayed state of this list |
| 506 | notifyChange(-1); |
| 507 | } |
| 508 | return true; |
| 509 | } |
| 510 | |
| 511 | bool ModList::setData(const QModelIndex& index, const QVariant& value, int role) |
| 512 | { |
no test coverage detected