summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com>2025-01-02 08:52:38 +0100
committerGitHub <noreply@github.com>2025-01-02 08:52:38 +0100
commitf8340e16201c214eef5327c4e810432e12b23805 (patch)
tree88814d5d1d5d8413adc72e4e83990ed986e6a144
parent110014bf5eb1df045790204836e8d0d44fcea1e2 (diff)
Highlight mods that contain selected files in data tab (#2179)
-rw-r--r--src/colortable.cpp6
-rw-r--r--src/datatab.cpp14
-rw-r--r--src/mainwindow.cpp1
-rw-r--r--src/modlistview.cpp30
-rw-r--r--src/modlistview.h6
-rw-r--r--src/pluginlist.cpp5
-rw-r--r--src/pluginlist.h2
-rw-r--r--src/pluginlistview.cpp40
-rw-r--r--src/pluginlistview.h1
-rw-r--r--src/settings.cpp8
-rw-r--r--src/settings.h4
11 files changed, 69 insertions, 48 deletions
diff --git a/src/colortable.cpp b/src/colortable.cpp
index 43a4dabd..121df708 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 dc8419cf..e4d0a215 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<QString> 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 04ea7543..8c91083b 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 81e87c5e..8cfd8b42 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<unsigned int> 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<unsigned int>& pluginIndices)
+void ModListView::setHighlightedMods(const std::set<QString>& 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<unsigned int>& 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 f4b4e398..364e044c 100644
--- a/src/modlistview.h
+++ b/src/modlistview.h
@@ -138,7 +138,7 @@ public slots:
// set highligth markers
//
- void setHighlightedMods(const std::vector<unsigned int>& pluginIndices);
+ void setHighlightedMods(const std::set<QString>& modNames);
protected:
// map from/to the view indexes to the model
@@ -215,7 +215,7 @@ private: // private structures
QPushButton* clearFilters;
QComboBox* filterSeparators;
- // the plugin list (for highligths)
+ // the plugin list (for highlights)
PluginListView* pluginList;
};
@@ -265,7 +265,7 @@ private: // private functions
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 04d4462a..eaf47b3a 100644
--- a/src/pluginlist.cpp
+++ b/src/pluginlist.cpp
@@ -161,15 +161,14 @@ void PluginList::highlightPlugins(const std::vector<unsigned int>& modIndices,
this->columnCount() - 1));
}
-void PluginList::highlightMasters(
- const std::vector<unsigned int>& 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 9a741d41..30837fb1 100644
--- a/src/pluginlist.h
+++ b/src/pluginlist.h
@@ -222,7 +222,7 @@ public:
void highlightPlugins(const std::vector<unsigned int>& modIndices,
const MOShared::DirectoryEntry& directoryEntry);
- void highlightMasters(const std::vector<unsigned int>& selectedPluginIndices);
+ void highlightMasters(const QModelIndexList& selectedPluginIndices);
void refreshLoadOrder();
diff --git a/src/pluginlistview.cpp b/src/pluginlistview.cpp
index 5a4e7efa..371e742c 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<unsigned int> 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<QString> 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 642976e3..eea7665c 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 d88311eb..ef1785b1 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<QColor>(m_Settings, "Settings", "containsPluginColor",
+ return get<QColor>(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 c4be0d7b..000f85c3 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -251,8 +251,8 @@ public:
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);