Skip to content

Commit

Permalink
Highlight mods that contain selected files in data tab
Browse files Browse the repository at this point in the history
s
  • Loading branch information
JonathanFeenstra committed Dec 25, 2024
1 parent 91912f5 commit 357ba32
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/colortable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions src/datatab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -92,6 +104,8 @@ void DataTab::activated()
if (m_needUpdate) {
updateTree();
}
// update highlighted mods
ui.tree->selectionModel()->selectionChanged({}, {});
}

bool DataTab::isActive() const
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 9 additions & 21 deletions src/modlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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),
Expand All @@ -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();
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/modlistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -215,7 +215,7 @@ protected slots:
QPushButton* clearFilters;
QComboBox* filterSeparators;

// the plugin list (for highligths)
// the plugin list (for highlights)
PluginListView* pluginList;
};

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/pluginlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/pluginlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class PluginList : public QAbstractItemModel
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();

Expand Down
40 changes: 29 additions & 11 deletions src/pluginlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/pluginlistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 357ba32

Please sign in to comment.