From 357ba322c8b976bb48032970b79ccf5079d31d34 Mon Sep 17 00:00:00 2001 From: Jonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com> Date: Tue, 24 Dec 2024 21:15:07 +0100 Subject: [PATCH] Highlight mods that contain selected files in data tab s --- src/colortable.cpp | 6 +++--- src/datatab.cpp | 14 ++++++++++++++ src/mainwindow.cpp | 1 + src/modlistview.cpp | 30 +++++++++--------------------- src/modlistview.h | 6 +++--- src/pluginlist.cpp | 5 ++--- src/pluginlist.h | 2 +- src/pluginlistview.cpp | 40 +++++++++++++++++++++++++++++----------- src/pluginlistview.h | 1 + src/settings.cpp | 8 ++++---- src/settings.h | 4 ++-- 11 files changed, 69 insertions(+), 48 deletions(-) diff --git a/src/colortable.cpp b/src/colortable.cpp index 43a4dabd2..121df708d 100644 --- a/src/colortable.cpp +++ b/src/colortable.cpp @@ -233,12 +233,12 @@ void ColorTable::load(Settings& s) }); addColor( - QObject::tr("Mod contains selected plugin"), QColor(0, 0, 255, 64), + QObject::tr("Mod contains selected file"), QColor(0, 0, 255, 64), [this] { - return m_settings->colors().modlistContainsPlugin(); + return m_settings->colors().modlistContainsFile(); }, [this](auto&& v) { - m_settings->colors().setModlistContainsPlugin(v); + m_settings->colors().setModlistContainsFile(v); }); addColor( diff --git a/src/datatab.cpp b/src/datatab.cpp index dc8419cf1..e4d0a2155 100644 --- a/src/datatab.cpp +++ b/src/datatab.cpp @@ -2,6 +2,7 @@ #include "filetree.h" #include "filetreemodel.h" #include "messagedialog.h" +#include "modelutils.h" #include "organizercore.h" #include "settings.h" #include "ui_mainwindow.h" @@ -57,6 +58,17 @@ DataTab::DataTab(OrganizerCore& core, PluginContainer& pc, QWidget* parent, onHiddenFiles(); }); + connect(ui.tree->selectionModel(), &QItemSelectionModel::selectionChanged, [=] { + const auto* fileTreeModel = m_filetree->model(); + const auto& selectedIndexList = MOShared::indexViewToModel( + ui.tree->selectionModel()->selectedRows(), fileTreeModel); + std::set mods; + for (auto& idx : selectedIndexList) { + mods.insert(fileTreeModel->itemFromIndex(idx)->mod()); + } + mwui->modList->setHighlightedMods(mods); + }); + connect(m_filetree.get(), &FileTree::executablesChanged, this, &DataTab::executablesChanged); @@ -92,6 +104,8 @@ void DataTab::activated() if (m_needUpdate) { updateTree(); } + // update highlighted mods + ui.tree->selectionModel()->selectionChanged({}, {}); } bool DataTab::isActive() const diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 04ea75439..8c91083bf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2240,6 +2240,7 @@ void MainWindow::on_tabWidget_currentChanged(int index) QWidget* currentWidget = ui->tabWidget->widget(index); if (currentWidget == ui->espTab) { m_OrganizerCore.refreshESPList(); + ui->espList->activated(); } else if (currentWidget == ui->bsaTab) { m_OrganizerCore.refreshBSAList(); } else if (currentWidget == ui->dataTab) { diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 81e87c5ee..8cfd8b420 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -27,9 +27,6 @@ #include "modlistversiondelegate.h" #include "modlistviewactions.h" #include "organizercore.h" -#include "shared/directoryentry.h" -#include "shared/fileentry.h" -#include "shared/filesorigin.h" using namespace MOBase; using namespace MOShared; @@ -1101,7 +1098,7 @@ void ModListView::refreshMarkersAndPlugins() setOverwriteMarkers(indexes); - // highligth plugins + // highlight plugins std::vector modIndices; for (auto& idx : indexes) { modIndices.push_back(idx.data(ModList::IndexRole).toInt()); @@ -1110,22 +1107,13 @@ void ModListView::refreshMarkersAndPlugins() ui.pluginList->verticalScrollBar()->repaint(); } -void ModListView::setHighlightedMods(const std::vector& pluginIndices) +void ModListView::setHighlightedMods(const std::set& modNames) { m_markers.highlight.clear(); - auto& directoryEntry = *m_core->directoryStructure(); - for (auto idx : pluginIndices) { - QString pluginName = m_core->pluginList()->getName(idx); - - const MOShared::FileEntryPtr fileEntry = - directoryEntry.findFile(pluginName.toStdWString()); - if (fileEntry.get() != nullptr) { - QString originName = QString::fromStdWString( - directoryEntry.getOriginByID(fileEntry->getOrigin()).getName()); - const auto index = ModInfo::getIndex(originName); - if (index != UINT_MAX) { - m_markers.highlight.insert(index); - } + for (const auto& modName : modNames) { + const auto index = ModInfo::getIndex(modName); + if (index != UINT_MAX) { + m_markers.highlight.insert(index); } } dataChanged(model()->index(0, 0), @@ -1136,7 +1124,7 @@ void ModListView::setHighlightedMods(const std::vector& pluginIndi QColor ModListView::markerColor(const QModelIndex& index) const { unsigned int modIndex = index.data(ModList::IndexRole).toInt(); - bool highligth = m_markers.highlight.find(modIndex) != m_markers.highlight.end(); + bool highlight = m_markers.highlight.find(modIndex) != m_markers.highlight.end(); bool overwrite = m_markers.overwrite.find(modIndex) != m_markers.overwrite.end(); bool archiveOverwrite = m_markers.archiveOverwrite.find(modIndex) != m_markers.archiveOverwrite.end(); @@ -1149,8 +1137,8 @@ QColor ModListView::markerColor(const QModelIndex& index) const bool archiveLooseOverwritten = m_markers.archiveLooseOverwritten.find(modIndex) != m_markers.archiveLooseOverwritten.end(); - if (highligth) { - return Settings::instance().colors().modlistContainsPlugin(); + if (highlight) { + return Settings::instance().colors().modlistContainsFile(); } else if (overwritten || archiveLooseOverwritten) { return Settings::instance().colors().modlistOverwritingLoose(); } else if (overwrite || archiveLooseOverwrite) { diff --git a/src/modlistview.h b/src/modlistview.h index f4b4e3988..364e044ca 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -138,7 +138,7 @@ public slots: // set highligth markers // - void setHighlightedMods(const std::vector& pluginIndices); + void setHighlightedMods(const std::set& modNames); protected: // map from/to the view indexes to the model @@ -215,7 +215,7 @@ protected slots: QPushButton* clearFilters; QComboBox* filterSeparators; - // the plugin list (for highligths) + // the plugin list (for highlights) PluginListView* pluginList; }; @@ -265,7 +265,7 @@ protected slots: void onModInstalled(const QString& modName); void onModFilterActive(bool filterActive); - // refresh the overwrite markers and the highligthed plugins from + // refresh the overwrite markers and the highlighted plugins from // the current selection // void refreshMarkersAndPlugins(); diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 04d4462a3..eaf47b3ae 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -161,15 +161,14 @@ void PluginList::highlightPlugins(const std::vector& modIndices, this->columnCount() - 1)); } -void PluginList::highlightMasters( - const std::vector& selectedPluginIndices) +void PluginList::highlightMasters(const QModelIndexList& selectedPluginIndices) { for (auto& esp : m_ESPs) { esp.isMasterOfSelectedPlugin = false; } for (const auto& pluginIndex : selectedPluginIndices) { - const ESPInfo& plugin = m_ESPs[pluginIndex]; + const ESPInfo& plugin = m_ESPs[pluginIndex.row()]; for (const auto& master : plugin.masters) { const auto iter = m_ESPsByName.find(master); if (iter != m_ESPsByName.end()) { diff --git a/src/pluginlist.h b/src/pluginlist.h index 9a741d413..30837fb10 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -222,7 +222,7 @@ class PluginList : public QAbstractItemModel void highlightPlugins(const std::vector& modIndices, const MOShared::DirectoryEntry& directoryEntry); - void highlightMasters(const std::vector& selectedPluginIndices); + void highlightMasters(const QModelIndexList& selectedPluginIndices); void refreshLoadOrder(); diff --git a/src/pluginlistview.cpp b/src/pluginlistview.cpp index 5a4e7efa8..371e742c6 100644 --- a/src/pluginlistview.cpp +++ b/src/pluginlistview.cpp @@ -16,6 +16,9 @@ #include "organizercore.h" #include "pluginlistcontextmenu.h" #include "pluginlistsortproxy.h" +#include "shared/directoryentry.h" +#include "shared/fileentry.h" +#include "shared/filesorigin.h" #include "ui_mainwindow.h" using namespace MOBase; @@ -30,6 +33,12 @@ PluginListView::PluginListView(QWidget* parent) installEventFilter(new CopyEventFilter(this)); } +void PluginListView::activated() +{ + // update highlighted mods + selectionModel()->selectionChanged({}, {}); +} + int PluginListView::sortColumn() const { return m_sortProxy ? m_sortProxy->sortColumn() : -1; @@ -259,17 +268,26 @@ void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow* &PluginListSortProxy::updateFilter); connect(ui.filter, &QLineEdit::textChanged, this, &PluginListView::onFilterChanged); - // highligth mod list when selected - connect(selectionModel(), &QItemSelectionModel::selectionChanged, - [=](auto&& selected) { - std::vector pluginIndices; - for (auto& idx : indexViewToModel(selectionModel()->selectedRows())) { - pluginIndices.push_back(idx.row()); - } - mwui->modList->setHighlightedMods(pluginIndices); - m_core->pluginList()->highlightMasters(pluginIndices); - verticalScrollBar()->repaint(); - }); + // highlight mod list when selected + connect(selectionModel(), &QItemSelectionModel::selectionChanged, [=] { + std::set mods; + auto& directoryEntry = *m_core->directoryStructure(); + auto pluginIndices = indexViewToModel(selectionModel()->selectedRows()); + for (auto& idx : pluginIndices) { + QString pluginName = m_core->pluginList()->getName(idx.row()); + + const MOShared::FileEntryPtr fileEntry = + directoryEntry.findFile(pluginName.toStdWString()); + if (fileEntry.get() != nullptr) { + QString originName = QString::fromStdWString( + directoryEntry.getOriginByID(fileEntry->getOrigin()).getName()); + mods.insert(originName); + } + } + mwui->modList->setHighlightedMods(mods); + m_core->pluginList()->highlightMasters(pluginIndices); + verticalScrollBar()->repaint(); + }); // using a lambda here to avoid storing the mod list actions connect(this, &QTreeView::customContextMenuRequested, [=](auto&& pos) { diff --git a/src/pluginlistview.h b/src/pluginlistview.h index 642976e3c..eea7665c8 100644 --- a/src/pluginlistview.h +++ b/src/pluginlistview.h @@ -21,6 +21,7 @@ class PluginListView : public QTreeView public: explicit PluginListView(QWidget* parent = nullptr); + void activated(); void setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow* mwui); // the column by which the plugin list is currently sorted diff --git a/src/settings.cpp b/src/settings.cpp index d88311ebe..ef1785b16 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1265,15 +1265,15 @@ void ColorSettings::setModlistOverwritingArchive(const QColor& c) set(m_Settings, "Settings", "overwritingArchiveFilesColor", c); } -QColor ColorSettings::modlistContainsPlugin() const +QColor ColorSettings::modlistContainsFile() const { - return get(m_Settings, "Settings", "containsPluginColor", + return get(m_Settings, "Settings", "containsFileColor", QColor(0, 0, 255, 64)); } -void ColorSettings::setModlistContainsPlugin(const QColor& c) +void ColorSettings::setModlistContainsFile(const QColor& c) { - set(m_Settings, "Settings", "containsPluginColor", c); + set(m_Settings, "Settings", "containsFileColor", c); } QColor ColorSettings::pluginListContained() const diff --git a/src/settings.h b/src/settings.h index c4be0d7bc..000f85c3c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -251,8 +251,8 @@ class ColorSettings QColor modlistOverwritingArchive() const; void setModlistOverwritingArchive(const QColor& c); - QColor modlistContainsPlugin() const; - void setModlistContainsPlugin(const QColor& c); + QColor modlistContainsFile() const; + void setModlistContainsFile(const QColor& c); QColor pluginListContained() const; void setPluginListContained(const QColor& c);