| 634 | } |
| 635 | |
| 636 | void ModListViewActions::sendModsToSeparator(const QModelIndexList& indexes) const |
| 637 | { |
| 638 | QStringList separators; |
| 639 | const auto& ibp = m_core.currentProfile()->getAllIndexesByPriority(); |
| 640 | for (const auto& [priority, index] : ibp) { |
| 641 | if (index < ModInfo::getNumMods()) { |
| 642 | ModInfo::Ptr modInfo = ModInfo::getByIndex(index); |
| 643 | if (modInfo->isSeparator()) { |
| 644 | separators << modInfo->name().chopped( |
| 645 | 10); // chops the "_separator" away from the name |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | // in descending order, reverse the separator |
| 651 | if (m_view->sortOrder() == Qt::DescendingOrder) { |
| 652 | std::reverse(separators.begin(), separators.end()); |
| 653 | } |
| 654 | |
| 655 | ListDialog dialog(m_parent); |
| 656 | dialog.setWindowTitle("Select a separator..."); |
| 657 | dialog.setChoices(separators); |
| 658 | |
| 659 | if (dialog.exec() != QDialog::Accepted) { |
| 660 | return; |
| 661 | } |
| 662 | |
| 663 | const QString result = dialog.getChoice(); |
| 664 | if (result.isEmpty()) { |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | const auto sepPriority = |
| 669 | m_core.currentProfile()->getModPriority(ModInfo::getIndex(result + "_separator")); |
| 670 | |
| 671 | auto isSeparator = [](const auto& p) { |
| 672 | return ModInfo::getByIndex(p.second)->isSeparator(); |
| 673 | }; |
| 674 | |
| 675 | // start right after/before the current priority and look for the next |
| 676 | // separator |
| 677 | int priority = -1; |
| 678 | if (m_view->sortOrder() == Qt::AscendingOrder) { |
| 679 | auto it = std::find_if(ibp.find(sepPriority + 1), ibp.end(), isSeparator); |
| 680 | if (it != ibp.end()) { |
| 681 | priority = it->first; |
| 682 | } else { |
| 683 | priority = Profile::MaximumPriority; |
| 684 | } |
| 685 | } else { |
| 686 | auto it = std::find_if(--std::reverse_iterator{ibp.find(sepPriority - 1)}, |
| 687 | ibp.rend(), isSeparator); |
| 688 | if (it != ibp.rend()) { |
| 689 | priority = it->first + 1; |
| 690 | } else { |
| 691 | // create "before" priority 0, i.e. at the end in descending priority. |
| 692 | priority = Profile::MinimumPriority; |
| 693 | } |
no test coverage detected