From 5de173ba1ae9531aaca0c0f022a2b0dae1c09250 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Wed, 31 Oct 2018 17:05:05 -0500 Subject: Add send to top/bottom options for the plugin list --- src/pluginlist.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/pluginlist.h') diff --git a/src/pluginlist.h b/src/pluginlist.h index 03d6426a..009c9153 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -264,6 +264,16 @@ public slots: **/ void disableAll(); + /** + * @brief moves selected plugins to the top (lowest priority) + **/ + void sendToTop(const QItemSelectionModel *selectionModel); + + /** + * @brief moves selected plugins to the bottom (highest priority) + **/ + void sendToBottom(const QItemSelectionModel *selectionModel); + /** * @brief The currently managed game has changed * @param gamePlugin @@ -340,6 +350,8 @@ private: void fixPriorities(); + int findPluginByPriority(int priority); + private: std::vector m_ESPs; -- cgit v1.3.1 From 2c57899cf611056a8c5bae1f7f27c9a157df6f41 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Thu, 1 Nov 2018 17:58:49 -0500 Subject: Fix matching highlights for mod and plugin selections The selectionChanged event used before requires subtractive/additive logic to work correctly. A separate event is fired for each row and each column for each row that is selected or deselected. The previous logic assumed all of the selection was passed in at once. The logic has been changed to recalculate all highlights each time the event is fired. This is poorly optimized in regards to performance but makes the function work. --- src/mainwindow.cpp | 4 ++-- src/modlist.cpp | 5 +++-- src/modlist.h | 2 +- src/pluginlist.cpp | 11 +++++++---- src/pluginlist.h | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/pluginlist.h') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5b257977..752c5c76 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2341,13 +2341,13 @@ void MainWindow::modlistSelectionChanged(const QModelIndex ¤t, const QMode void MainWindow::modlistSelectionsChanged(const QItemSelection &selected) { - m_OrganizerCore.pluginList()->highlightPlugins(selected, *m_OrganizerCore.directoryStructure(), *m_OrganizerCore.currentProfile()); + m_OrganizerCore.pluginList()->highlightPlugins(ui->modList->selectionModel(), *m_OrganizerCore.directoryStructure(), *m_OrganizerCore.currentProfile()); ui->espList->verticalScrollBar()->repaint(); } void MainWindow::esplistSelectionsChanged(const QItemSelection &selected) { - m_OrganizerCore.modList()->highlightMods(selected, *m_OrganizerCore.directoryStructure()); + m_OrganizerCore.modList()->highlightMods(ui->espList->selectionModel(), *m_OrganizerCore.directoryStructure()); ui->modList->verticalScrollBar()->repaint(); } diff --git a/src/modlist.cpp b/src/modlist.cpp index 3f8fa0c0..539ba6fc 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -24,6 +24,7 @@ along with Mod Organizer. If not, see . #include "qtgroupingproxy.h" #include "viewmarkingscrollbar.h" #include "modlistsortproxy.h" +#include "pluginlist.h" #include "settings.h" #include "modinforegular.h" #include @@ -768,12 +769,12 @@ int ModList::timeElapsedSinceLastChecked() const return m_LastCheck.elapsed(); } -void ModList::highlightMods(const QItemSelection &selected, const MOShared::DirectoryEntry &directoryEntry) +void ModList::highlightMods(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry) { for (unsigned int i = 0; i < ModInfo::getNumMods(); ++i) { ModInfo::getByIndex(i)->setPluginSelected(false); } - for (QModelIndex idx : selected.indexes()) { + for (QModelIndex idx : selection->selectedRows(PluginList::COL_NAME)) { QString modName = idx.data().toString(); const MOShared::FileEntry::Ptr fileEntry = directoryEntry.findFile(modName.toStdWString()); diff --git a/src/modlist.h b/src/modlist.h index caad8c61..8de08da3 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -118,7 +118,7 @@ public: int timeElapsedSinceLastChecked() const; - void highlightMods(const QItemSelection &selected, const MOShared::DirectoryEntry &directoryEntry); + void highlightMods(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry); public: diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index d56a4bde..21e716d3 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see . #include "settings.h" #include "scopeguard.h" #include "modinfo.h" +#include "modlist.h" #include "viewmarkingscrollbar.h" #include #include @@ -119,14 +120,16 @@ QString PluginList::getColumnToolTip(int column) } } -void PluginList::highlightPlugins(const QItemSelection &selected, const MOShared::DirectoryEntry &directoryEntry, const Profile &profile) +void PluginList::highlightPlugins(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry, const Profile &profile) { for (auto &esp : m_ESPs) { esp.m_ModSelected = false; } - for (QModelIndex idx : selected.indexes()) { - ModInfo::Ptr selectedMod = ModInfo::getByIndex(idx.data(Qt::UserRole + 1).toInt()); - if (!selectedMod.isNull() && profile.modEnabled(idx.data(Qt::UserRole + 1).toInt())) { + for (QModelIndex idx : selection->selectedRows(ModList::COL_PRIORITY)) { + int modPriority = idx.data().toInt(); + int modIndex = profile.modIndexByPriority(modPriority); + ModInfo::Ptr selectedMod = ModInfo::getByIndex(modIndex); + if (!selectedMod.isNull() && profile.modEnabled(modIndex)) { QDir dir(selectedMod->absolutePath()); QStringList plugins = dir.entryList(QStringList() << "*.esp" << "*.esm" << "*.esl"); MOShared::FilesOrigin origin = directoryEntry.getOriginByName(selectedMod->internalName().toStdWString()); diff --git a/src/pluginlist.h b/src/pluginlist.h index 009c9153..f7817c37 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -206,7 +206,7 @@ public: static QString getColumnName(int column); static QString getColumnToolTip(int column); - void highlightPlugins(const QItemSelection &selected, const MOShared::DirectoryEntry &directoryEntry, const Profile &profile); + void highlightPlugins(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry, const Profile &profile); void refreshLoadOrder(); -- cgit v1.3.1 From a48a20f13fd20e599c2055752bae5065bce43700 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Sun, 4 Nov 2018 13:10:41 -0600 Subject: Add context menu option to send to a specific priority --- src/mainwindow.cpp | 84 ++++++++++++++++++++++++++++++++++++++---------------- src/mainwindow.h | 11 +++++-- src/pluginlist.cpp | 23 ++------------- src/pluginlist.h | 9 ++---- 4 files changed, 72 insertions(+), 55 deletions(-) (limited to 'src/pluginlist.h') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7c7d9c95..3d7cc13b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3683,6 +3683,26 @@ QMenu *MainWindow::modListContextMenu() return menu; } +QMenu *MainWindow::modSendToContextMenu() +{ + QMenu *menu = new QMenu(this); + menu->setTitle(tr("Send to")); + menu->addAction(tr("Top"), this, SLOT(sendSelectedModsToTop_clicked())); + menu->addAction(tr("Bottom"), this, SLOT(sendSelectedModsToBottom_clicked())); + menu->addAction(tr("Priority..."), this, SLOT(sendSelectedModsToPriority_clicked())); + return menu; +} + +QMenu *MainWindow::pluginSendToContextMenu() +{ + QMenu *menu = new QMenu(this); + menu->setTitle(tr("Send to")); + menu->addAction(tr("Top"), this, SLOT(sendSelectedPluginsToTop_clicked())); + menu->addAction(tr("Bottom"), this, SLOT(sendSelectedPluginsToBottom_clicked())); + menu->addAction(tr("Priority..."), this, SLOT(sendSelectedPluginsToPriority_clicked())); + return menu; +} + void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) { try { @@ -3726,16 +3746,14 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) menu->addAction(tr("Rename Separator..."), this, SLOT(renameMod_clicked())); menu->addAction(tr("Remove Separator..."), this, SLOT(removeMod_clicked())); menu->addSeparator(); - menu->addAction(tr("Send to Top"), this, SLOT(sendModToTop_clicked())); - menu->addAction(tr("Send to Bottom"), this, SLOT(sendModToBottom_clicked())); + menu->addMenu(modSendToContextMenu()); menu->addSeparator(); menu->addAction(tr("Select Color..."), this, SLOT(setColor_clicked())); if(info->getColor().isValid()) menu->addAction(tr("Reset Color"), this, SLOT(resetColor_clicked())); menu->addSeparator(); } else if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_FOREIGN) != flags.end()) { - menu->addAction(tr("Send to Top"), this, SLOT(sendModToTop_clicked())); - menu->addAction(tr("Send to Bottom"), this, SLOT(sendModToBottom_clicked())); + menu->addMenu(modSendToContextMenu()); } else { QMenu *addRemoveCategoriesMenu = new QMenu(tr("Change Categories")); populateMenuCategories(addRemoveCategoriesMenu, 0); @@ -3767,8 +3785,7 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) menu->addSeparator(); - menu->addAction(tr("Send to Top"), this, SLOT(sendModToTop_clicked())); - menu->addAction(tr("Send to Bottom"), this, SLOT(sendModToBottom_clicked())); + menu->addMenu(modSendToContextMenu()); menu->addSeparator(); @@ -4358,12 +4375,23 @@ void MainWindow::disableSelectedPlugins_clicked() void MainWindow::sendSelectedPluginsToTop_clicked() { - m_OrganizerCore.pluginList()->sendToTop(ui->espList->selectionModel()); + m_OrganizerCore.pluginList()->sendToPriority(ui->espList->selectionModel(), 0); } void MainWindow::sendSelectedPluginsToBottom_clicked() { - m_OrganizerCore.pluginList()->sendToBottom(ui->espList->selectionModel()); + m_OrganizerCore.pluginList()->sendToPriority(ui->espList->selectionModel(), INT_MAX); +} + +void MainWindow::sendSelectedPluginsToPriority_clicked() +{ + bool ok; + int newPriority = QInputDialog::getInt(this, + tr("Set Priority"), tr("Set the priority of the selected mods"), + 0, 0, INT_MAX, 1, &ok); + if (!ok) return; + + m_OrganizerCore.pluginList()->sendToPriority(ui->espList->selectionModel(), newPriority); } @@ -4993,8 +5021,7 @@ void MainWindow::on_espList_customContextMenuRequested(const QPoint &pos) menu.addSeparator(); - menu.addAction(tr("Send to top"), this, SLOT(sendSelectedPluginsToTop_clicked())); - menu.addAction(tr("Send to bottom"), this, SLOT(sendSelectedPluginsToBottom_clicked())); + menu.addMenu(pluginSendToContextMenu()); QItemSelection currentSelection = ui->espList->selectionModel()->selection(); bool hasLocked = false; @@ -5607,30 +5634,37 @@ void MainWindow::on_clearFiltersButton_clicked() deselectFilters(); } -void MainWindow::sendModToTop_clicked() +void MainWindow::sendSelectedModsToPriority(int newPriority) { QItemSelectionModel *selection = ui->modList->selectionModel(); if (selection->hasSelection() && selection->selectedRows().count() > 1) { std::vector modsToMove; for (QModelIndex idx : selection->selectedRows()) { - modsToMove.push_back(idx.data(Qt::UserRole + 1).toInt()); + modsToMove.push_back(idx.data().toInt()); } - m_OrganizerCore.modList()->changeModPriority(modsToMove, 0); + m_OrganizerCore.modList()->changeModPriority(modsToMove, newPriority); } else { - m_OrganizerCore.modList()->changeModPriority(m_ContextRow, 0); + m_OrganizerCore.modList()->changeModPriority(m_ContextRow, newPriority); } } -void MainWindow::sendModToBottom_clicked() +void MainWindow::sendSelectedModsToTop_clicked() { - QItemSelectionModel *selection = ui->modList->selectionModel(); - if (selection->hasSelection() && selection->selectedRows().count() > 1) { - std::vector modsToMove; - for (QModelIndex idx : selection->selectedRows()) { - modsToMove.push_back(idx.data(Qt::UserRole + 1).toInt()); - } - m_OrganizerCore.modList()->changeModPriority(modsToMove, INT_MAX); - } else { - m_OrganizerCore.modList()->changeModPriority(m_ContextRow, INT_MAX); - } + sendSelectedModsToPriority(0); +} + +void MainWindow::sendSelectedModsToBottom_clicked() +{ + sendSelectedModsToPriority(INT_MAX); +} + +void MainWindow::sendSelectedModsToPriority_clicked() +{ + bool ok; + int newPriority = QInputDialog::getInt(this, + tr("Set Priority"), tr("Set the priority of the selected mods"), + 0, 0, INT_MAX, 1, &ok); + if (!ok) return; + + sendSelectedModsToPriority(newPriority); } diff --git a/src/mainwindow.h b/src/mainwindow.h index c595575e..85b3fc2d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -278,6 +278,8 @@ private: QString queryRestore(const QString &filePath); QMenu *modListContextMenu(); + QMenu *modSendToContextMenu(); + QMenu *pluginSendToContextMenu(); QMenu *openFolderMenu(); @@ -294,6 +296,9 @@ private: bool registerWidgetState(const QString &name, QHeaderView *view, const char *oldSettingName = nullptr); + void sendSelectedModsToPriority(int newPriority); + void sendSelectedPluginsToPriority(int newPriority); + private: static const char *PATTERN_BACKUP_GLOB; @@ -423,8 +428,9 @@ private slots: void information_clicked(); void enableSelectedMods_clicked(); void disableSelectedMods_clicked(); - void sendModToTop_clicked(); - void sendModToBottom_clicked(); + void sendSelectedModsToTop_clicked(); + void sendSelectedModsToBottom_clicked(); + void sendSelectedModsToPriority_clicked(); // savegame context menu void deleteSavegame_clicked(); void fixMods_clicked(SaveGameInfo::MissingAssets const &missingAssets); @@ -441,6 +447,7 @@ private slots: void disableSelectedPlugins_clicked(); void sendSelectedPluginsToTop_clicked(); void sendSelectedPluginsToBottom_clicked(); + void sendSelectedPluginsToPriority_clicked(); void linkToolbar(); void linkDesktop(); diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 21e716d3..480cb014 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -359,7 +359,7 @@ void PluginList::disableAll() } } -void PluginList::sendToTop(const QItemSelectionModel *selectionModel) +void PluginList::sendToPriority(const QItemSelectionModel *selectionModel, int newPriority) { if (selectionModel->hasSelection()) { std::vector pluginsToMove; @@ -370,30 +370,11 @@ void PluginList::sendToTop(const QItemSelectionModel *selectionModel) } } if (pluginsToMove.size()) { - changePluginPriority(pluginsToMove, 0); - emit SIGNAL(displayPlugin(0)); + changePluginPriority(pluginsToMove, newPriority); } } } -void PluginList::sendToBottom(const QItemSelectionModel *selectionModel) -{ - if (selectionModel->hasSelection()) { - std::vector pluginsToMove; - for (auto row: selectionModel->selectedRows(COL_PRIORITY)) { - int rowIndex = findPluginByPriority(row.data().toInt()); - if (!m_ESPs[rowIndex].m_ForceEnabled) { - pluginsToMove.push_back(rowIndex); - } - } - if (pluginsToMove.size()) { - changePluginPriority(pluginsToMove, INT_MAX); - emit SIGNAL(displayPlugin(INT_MAX)); - } - } -} - - bool PluginList::isEnabled(const QString &name) { std::map::iterator iter = m_ESPsByName.find(name.toLower()); diff --git a/src/pluginlist.h b/src/pluginlist.h index f7817c37..228ccdec 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -265,14 +265,9 @@ public slots: void disableAll(); /** - * @brief moves selected plugins to the top (lowest priority) + * @brief moves selected plugins to specified priority **/ - void sendToTop(const QItemSelectionModel *selectionModel); - - /** - * @brief moves selected plugins to the bottom (highest priority) - **/ - void sendToBottom(const QItemSelectionModel *selectionModel); + void sendToPriority(const QItemSelectionModel *selectionModel, int priority); /** * @brief The currently managed game has changed -- cgit v1.3.1