Skip to content

Commit f8340e1

Browse files
Highlight mods that contain selected files in data tab (#2179)
1 parent 110014b commit f8340e1

File tree

11 files changed

+69
-48
lines changed

11 files changed

+69
-48
lines changed

src/colortable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ void ColorTable::load(Settings& s)
233233
});
234234

235235
addColor(
236-
QObject::tr("Mod contains selected plugin"), QColor(0, 0, 255, 64),
236+
QObject::tr("Mod contains selected file"), QColor(0, 0, 255, 64),
237237
[this] {
238-
return m_settings->colors().modlistContainsPlugin();
238+
return m_settings->colors().modlistContainsFile();
239239
},
240240
[this](auto&& v) {
241-
m_settings->colors().setModlistContainsPlugin(v);
241+
m_settings->colors().setModlistContainsFile(v);
242242
});
243243

244244
addColor(

src/datatab.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "filetree.h"
33
#include "filetreemodel.h"
44
#include "messagedialog.h"
5+
#include "modelutils.h"
56
#include "organizercore.h"
67
#include "settings.h"
78
#include "ui_mainwindow.h"
@@ -57,6 +58,17 @@ DataTab::DataTab(OrganizerCore& core, PluginContainer& pc, QWidget* parent,
5758
onHiddenFiles();
5859
});
5960

61+
connect(ui.tree->selectionModel(), &QItemSelectionModel::selectionChanged, [=] {
62+
const auto* fileTreeModel = m_filetree->model();
63+
const auto& selectedIndexList = MOShared::indexViewToModel(
64+
ui.tree->selectionModel()->selectedRows(), fileTreeModel);
65+
std::set<QString> mods;
66+
for (auto& idx : selectedIndexList) {
67+
mods.insert(fileTreeModel->itemFromIndex(idx)->mod());
68+
}
69+
mwui->modList->setHighlightedMods(mods);
70+
});
71+
6072
connect(m_filetree.get(), &FileTree::executablesChanged, this,
6173
&DataTab::executablesChanged);
6274

@@ -92,6 +104,8 @@ void DataTab::activated()
92104
if (m_needUpdate) {
93105
updateTree();
94106
}
107+
// update highlighted mods
108+
ui.tree->selectionModel()->selectionChanged({}, {});
95109
}
96110

97111
bool DataTab::isActive() const

src/mainwindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,7 @@ void MainWindow::on_tabWidget_currentChanged(int index)
22402240
QWidget* currentWidget = ui->tabWidget->widget(index);
22412241
if (currentWidget == ui->espTab) {
22422242
m_OrganizerCore.refreshESPList();
2243+
ui->espList->activated();
22432244
} else if (currentWidget == ui->bsaTab) {
22442245
m_OrganizerCore.refreshBSAList();
22452246
} else if (currentWidget == ui->dataTab) {

src/modlistview.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#include "modlistversiondelegate.h"
2828
#include "modlistviewactions.h"
2929
#include "organizercore.h"
30-
#include "shared/directoryentry.h"
31-
#include "shared/fileentry.h"
32-
#include "shared/filesorigin.h"
3330

3431
using namespace MOBase;
3532
using namespace MOShared;
@@ -1101,7 +1098,7 @@ void ModListView::refreshMarkersAndPlugins()
11011098

11021099
setOverwriteMarkers(indexes);
11031100

1104-
// highligth plugins
1101+
// highlight plugins
11051102
std::vector<unsigned int> modIndices;
11061103
for (auto& idx : indexes) {
11071104
modIndices.push_back(idx.data(ModList::IndexRole).toInt());
@@ -1110,22 +1107,13 @@ void ModListView::refreshMarkersAndPlugins()
11101107
ui.pluginList->verticalScrollBar()->repaint();
11111108
}
11121109

1113-
void ModListView::setHighlightedMods(const std::vector<unsigned int>& pluginIndices)
1110+
void ModListView::setHighlightedMods(const std::set<QString>& modNames)
11141111
{
11151112
m_markers.highlight.clear();
1116-
auto& directoryEntry = *m_core->directoryStructure();
1117-
for (auto idx : pluginIndices) {
1118-
QString pluginName = m_core->pluginList()->getName(idx);
1119-
1120-
const MOShared::FileEntryPtr fileEntry =
1121-
directoryEntry.findFile(pluginName.toStdWString());
1122-
if (fileEntry.get() != nullptr) {
1123-
QString originName = QString::fromStdWString(
1124-
directoryEntry.getOriginByID(fileEntry->getOrigin()).getName());
1125-
const auto index = ModInfo::getIndex(originName);
1126-
if (index != UINT_MAX) {
1127-
m_markers.highlight.insert(index);
1128-
}
1113+
for (const auto& modName : modNames) {
1114+
const auto index = ModInfo::getIndex(modName);
1115+
if (index != UINT_MAX) {
1116+
m_markers.highlight.insert(index);
11291117
}
11301118
}
11311119
dataChanged(model()->index(0, 0),
@@ -1136,7 +1124,7 @@ void ModListView::setHighlightedMods(const std::vector<unsigned int>& pluginIndi
11361124
QColor ModListView::markerColor(const QModelIndex& index) const
11371125
{
11381126
unsigned int modIndex = index.data(ModList::IndexRole).toInt();
1139-
bool highligth = m_markers.highlight.find(modIndex) != m_markers.highlight.end();
1127+
bool highlight = m_markers.highlight.find(modIndex) != m_markers.highlight.end();
11401128
bool overwrite = m_markers.overwrite.find(modIndex) != m_markers.overwrite.end();
11411129
bool archiveOverwrite =
11421130
m_markers.archiveOverwrite.find(modIndex) != m_markers.archiveOverwrite.end();
@@ -1149,8 +1137,8 @@ QColor ModListView::markerColor(const QModelIndex& index) const
11491137
bool archiveLooseOverwritten = m_markers.archiveLooseOverwritten.find(modIndex) !=
11501138
m_markers.archiveLooseOverwritten.end();
11511139

1152-
if (highligth) {
1153-
return Settings::instance().colors().modlistContainsPlugin();
1140+
if (highlight) {
1141+
return Settings::instance().colors().modlistContainsFile();
11541142
} else if (overwritten || archiveLooseOverwritten) {
11551143
return Settings::instance().colors().modlistOverwritingLoose();
11561144
} else if (overwrite || archiveLooseOverwrite) {

src/modlistview.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public slots:
138138

139139
// set highligth markers
140140
//
141-
void setHighlightedMods(const std::vector<unsigned int>& pluginIndices);
141+
void setHighlightedMods(const std::set<QString>& modNames);
142142

143143
protected:
144144
// map from/to the view indexes to the model
@@ -215,7 +215,7 @@ protected slots:
215215
QPushButton* clearFilters;
216216
QComboBox* filterSeparators;
217217

218-
// the plugin list (for highligths)
218+
// the plugin list (for highlights)
219219
PluginListView* pluginList;
220220
};
221221

@@ -265,7 +265,7 @@ protected slots:
265265
void onModInstalled(const QString& modName);
266266
void onModFilterActive(bool filterActive);
267267

268-
// refresh the overwrite markers and the highligthed plugins from
268+
// refresh the overwrite markers and the highlighted plugins from
269269
// the current selection
270270
//
271271
void refreshMarkersAndPlugins();

src/pluginlist.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,14 @@ void PluginList::highlightPlugins(const std::vector<unsigned int>& modIndices,
161161
this->columnCount() - 1));
162162
}
163163

164-
void PluginList::highlightMasters(
165-
const std::vector<unsigned int>& selectedPluginIndices)
164+
void PluginList::highlightMasters(const QModelIndexList& selectedPluginIndices)
166165
{
167166
for (auto& esp : m_ESPs) {
168167
esp.isMasterOfSelectedPlugin = false;
169168
}
170169

171170
for (const auto& pluginIndex : selectedPluginIndices) {
172-
const ESPInfo& plugin = m_ESPs[pluginIndex];
171+
const ESPInfo& plugin = m_ESPs[pluginIndex.row()];
173172
for (const auto& master : plugin.masters) {
174173
const auto iter = m_ESPsByName.find(master);
175174
if (iter != m_ESPsByName.end()) {

src/pluginlist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class PluginList : public QAbstractItemModel
222222
void highlightPlugins(const std::vector<unsigned int>& modIndices,
223223
const MOShared::DirectoryEntry& directoryEntry);
224224

225-
void highlightMasters(const std::vector<unsigned int>& selectedPluginIndices);
225+
void highlightMasters(const QModelIndexList& selectedPluginIndices);
226226

227227
void refreshLoadOrder();
228228

src/pluginlistview.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include "organizercore.h"
1717
#include "pluginlistcontextmenu.h"
1818
#include "pluginlistsortproxy.h"
19+
#include "shared/directoryentry.h"
20+
#include "shared/fileentry.h"
21+
#include "shared/filesorigin.h"
1922
#include "ui_mainwindow.h"
2023

2124
using namespace MOBase;
@@ -30,6 +33,12 @@ PluginListView::PluginListView(QWidget* parent)
3033
installEventFilter(new CopyEventFilter(this));
3134
}
3235

36+
void PluginListView::activated()
37+
{
38+
// update highlighted mods
39+
selectionModel()->selectionChanged({}, {});
40+
}
41+
3342
int PluginListView::sortColumn() const
3443
{
3544
return m_sortProxy ? m_sortProxy->sortColumn() : -1;
@@ -259,17 +268,26 @@ void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow*
259268
&PluginListSortProxy::updateFilter);
260269
connect(ui.filter, &QLineEdit::textChanged, this, &PluginListView::onFilterChanged);
261270

262-
// highligth mod list when selected
263-
connect(selectionModel(), &QItemSelectionModel::selectionChanged,
264-
[=](auto&& selected) {
265-
std::vector<unsigned int> pluginIndices;
266-
for (auto& idx : indexViewToModel(selectionModel()->selectedRows())) {
267-
pluginIndices.push_back(idx.row());
268-
}
269-
mwui->modList->setHighlightedMods(pluginIndices);
270-
m_core->pluginList()->highlightMasters(pluginIndices);
271-
verticalScrollBar()->repaint();
272-
});
271+
// highlight mod list when selected
272+
connect(selectionModel(), &QItemSelectionModel::selectionChanged, [=] {
273+
std::set<QString> mods;
274+
auto& directoryEntry = *m_core->directoryStructure();
275+
auto pluginIndices = indexViewToModel(selectionModel()->selectedRows());
276+
for (auto& idx : pluginIndices) {
277+
QString pluginName = m_core->pluginList()->getName(idx.row());
278+
279+
const MOShared::FileEntryPtr fileEntry =
280+
directoryEntry.findFile(pluginName.toStdWString());
281+
if (fileEntry.get() != nullptr) {
282+
QString originName = QString::fromStdWString(
283+
directoryEntry.getOriginByID(fileEntry->getOrigin()).getName());
284+
mods.insert(originName);
285+
}
286+
}
287+
mwui->modList->setHighlightedMods(mods);
288+
m_core->pluginList()->highlightMasters(pluginIndices);
289+
verticalScrollBar()->repaint();
290+
});
273291

274292
// using a lambda here to avoid storing the mod list actions
275293
connect(this, &QTreeView::customContextMenuRequested, [=](auto&& pos) {

src/pluginlistview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class PluginListView : public QTreeView
2121
public:
2222
explicit PluginListView(QWidget* parent = nullptr);
2323

24+
void activated();
2425
void setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow* mwui);
2526

2627
// the column by which the plugin list is currently sorted

src/settings.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,15 +1265,15 @@ void ColorSettings::setModlistOverwritingArchive(const QColor& c)
12651265
set(m_Settings, "Settings", "overwritingArchiveFilesColor", c);
12661266
}
12671267

1268-
QColor ColorSettings::modlistContainsPlugin() const
1268+
QColor ColorSettings::modlistContainsFile() const
12691269
{
1270-
return get<QColor>(m_Settings, "Settings", "containsPluginColor",
1270+
return get<QColor>(m_Settings, "Settings", "containsFileColor",
12711271
QColor(0, 0, 255, 64));
12721272
}
12731273

1274-
void ColorSettings::setModlistContainsPlugin(const QColor& c)
1274+
void ColorSettings::setModlistContainsFile(const QColor& c)
12751275
{
1276-
set(m_Settings, "Settings", "containsPluginColor", c);
1276+
set(m_Settings, "Settings", "containsFileColor", c);
12771277
}
12781278

12791279
QColor ColorSettings::pluginListContained() const

0 commit comments

Comments
 (0)