Fix enable/disable all message.

This commit is contained in:
Mikaël Capelle
2021-01-24 11:09:12 +01:00
parent 54744c04b2
commit ab820c1b0a
3 changed files with 119 additions and 105 deletions
+44 -59
View File
@@ -471,67 +471,52 @@ void ModListView::onModFilterActive(bool filterActive)
}
}
void ModListView::updateModCount()
ModListView::ModCounters ModListView::counters() const
{
int activeCount = 0;
int visActiveCount = 0;
int backupCount = 0;
int visBackupCount = 0;
int foreignCount = 0;
int visForeignCount = 0;
int separatorCount = 0;
int visSeparatorCount = 0;
int regularCount = 0;
int visRegularCount = 0;
QStringList allMods = m_core->modList()->allMods();
ModCounters c;
auto hasFlag = [](std::vector<ModInfo::EFlag> flags, ModInfo::EFlag filter) {
return std::find(flags.begin(), flags.end(), filter) != flags.end();
};
bool isEnabled;
bool isVisible;
for (QString mod : allMods) {
int modIndex = ModInfo::getIndex(mod);
ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
std::vector<ModInfo::EFlag> modFlags = modInfo->getFlags();
isEnabled = m_core->currentProfile()->modEnabled(modIndex);
isVisible = m_sortProxy->filterMatchesMod(modInfo, isEnabled);
for (auto flag : modFlags) {
switch (flag) {
case ModInfo::FLAG_BACKUP: backupCount++;
if (isVisible)
visBackupCount++;
break;
case ModInfo::FLAG_FOREIGN: foreignCount++;
if (isVisible)
visForeignCount++;
break;
case ModInfo::FLAG_SEPARATOR: separatorCount++;
if (isVisible)
visSeparatorCount++;
break;
}
for (unsigned int index = 0; index < ModInfo::getNumMods(); ++index) {
auto info = ModInfo::getByIndex(index);
const auto flags = info->getFlags();
const bool enabled = m_core->currentProfile()->modEnabled(index);
const bool visible = m_sortProxy->filterMatchesMod(info, enabled);
if (info->isBackup()) {
c.backup++;
if (visible) c.visible.backup++;
}
if (!hasFlag(modFlags, ModInfo::FLAG_BACKUP) &&
!hasFlag(modFlags, ModInfo::FLAG_FOREIGN) &&
!hasFlag(modFlags, ModInfo::FLAG_SEPARATOR) &&
!hasFlag(modFlags, ModInfo::FLAG_OVERWRITE)) {
if (isEnabled) {
activeCount++;
if (isVisible)
visActiveCount++;
else if (info->isForeign()) {
c.foreign++;
if (visible) c.visible.foreign++;
}
else if (info->isSeparator()) {
c.separator++;
if (visible) c.visible.separator++;
}
else if (!info->isOverwrite()) {
c.regular++;
if (visible) c.visible.regular++;
if (enabled) {
c.active++;
if (visible) c.visible.active++;
}
if (isVisible)
visRegularCount++;
regularCount++;
}
}
ui.counter->display(visActiveCount);
return c;
}
void ModListView::updateModCount()
{
const auto c = counters();
ui.counter->display(c.visible.active);
ui.counter->setToolTip(tr("<table cellspacing=\"5\">"
"<tr><th>Type</th><th>All</th><th>Visible</th>"
"<tr><td>Enabled mods:&emsp;</td><td align=right>%1 / %2</td><td align=right>%3 / %4</td></tr>"
@@ -539,16 +524,16 @@ void ModListView::updateModCount()
"<tr><td>Mod backups:&emsp;</td><td align=right>%7</td><td align=right>%8</td></tr>"
"<tr><td>Separators:&emsp;</td><td align=right>%9</td><td align=right>%10</td></tr>"
"</table>")
.arg(activeCount)
.arg(regularCount)
.arg(visActiveCount)
.arg(visRegularCount)
.arg(foreignCount)
.arg(visForeignCount)
.arg(backupCount)
.arg(visBackupCount)
.arg(separatorCount)
.arg(visSeparatorCount)
.arg(c.active)
.arg(c.regular)
.arg(c.visible.active)
.arg(c.visible.regular)
.arg(c.foreign)
.arg(c.visible.foreign)
.arg(c.backup)
.arg(c.visible.backup)
.arg(c.separator)
.arg(c.visible.separator)
);
}
+68 -45
View File
@@ -131,9 +131,6 @@ public slots:
protected:
friend class ModListContextMenu;
friend class ModListViewActions;
// map from/to the view indexes to the model
//
QModelIndex indexModelToView(const QModelIndex& index) const;
@@ -183,14 +180,74 @@ protected slots:
void commitData(QWidget* editor) override;
private:
private: // friend classes
friend class ModConflictIconDelegate;
friend class ModFlagIconDelegate;
friend class ModContentIconDelegate;
friend class ModFlagIconDelegate;
friend class ModListContextMenu;
friend class ModListStyledItemDelegate;
friend class ModListViewActions;
friend class ModListViewMarkingScrollBar;
private: // private structures
struct ModListViewUi {
// the group by combo box
QComboBox* groupBy;
// the mod counter
QLCDNumber* counter;
// filters related
QLineEdit* filter;
QLabel* currentCategory;
QPushButton* clearFilters;
QComboBox* filterSeparators;
// the plugin list (for highligths)
PluginListView* pluginList;
};
struct MarkerInfos {
// conflicts
std::set<unsigned int> overwrite;
std::set<unsigned int> overwritten;
std::set<unsigned int> archiveOverwrite;
std::set<unsigned int> archiveOverwritten;
std::set<unsigned int> archiveLooseOverwrite;
std::set<unsigned int> archiveLooseOverwritten;
// selected plugins
std::set<unsigned int> highlight;
};
struct ModCounters {
int active = 0;
int backup = 0;
int foreign = 0;
int separator = 0;
int regular = 0;
struct {
int active = 0;
int backup = 0;
int foreign = 0;
int separator = 0;
int regular = 0;
} visible;
};
// index in the groupby combo
//
enum GroupBy {
NONE = 0,
CATEGORY = 1,
NEXUS_ID = 2
};
private: // private functions
void onModPrioritiesChanged(const QModelIndexList& indices);
void onModInstalled(const QString& modName);
void onModFilterActive(bool filterActive);
@@ -229,6 +286,10 @@ private:
QList<QString> contentsIcons(const QModelIndex& index, bool* forceCompact = nullptr) const;
QString contentsTooltip(const QModelIndex& index) const;
// compute the counters for mods according to the current filter
//
ModCounters counters() const;
// get/set the selected items on the view, this method return/take indices
// from the mod list model, not the view, so it's safe to restore
//
@@ -244,33 +305,7 @@ private:
//
void updateGroupByProxy();
// index in the groupby combo
//
enum GroupBy {
NONE = 0,
CATEGORY = 1,
NEXUS_ID = 2
};
private:
struct ModListViewUi
{
// the group by combo box
QComboBox* groupBy;
// the mod counter
QLCDNumber* counter;
// filters related
QLineEdit* filter;
QLabel* currentCategory;
QPushButton* clearFilters;
QComboBox* filterSeparators;
// the plugin list (for highligths)
PluginListView* pluginList;
};
public: // member variables
OrganizerCore* m_core;
std::unique_ptr<FilterList> m_filters;
@@ -291,19 +326,7 @@ private:
// losing them on model reset
std::map<QAbstractItemModel*, std::set<QString>> m_collapsed;
struct MarkerInfos {
// conflicts
std::set<unsigned int> overwrite;
std::set<unsigned int> overwritten;
std::set<unsigned int> archiveOverwrite;
std::set<unsigned int> archiveOverwritten;
std::set<unsigned int> archiveLooseOverwrite;
std::set<unsigned int> archiveLooseOverwritten;
// selected plugins
std::set<unsigned int> highlight;
} m_markers;
MarkerInfos m_markers;
ViewMarkingScrollBar* m_scrollbar;
bool m_inDragMoveEvent = false;
+7 -1
View File
@@ -207,10 +207,16 @@ void ModListViewActions::createSeparator(const QModelIndex& index) const
void ModListViewActions::setAllMatchingModsEnabled(bool enabled) const
{
// number of mods to enable / disable
const auto counters = m_view->counters();
const auto count = enabled ?
counters.visible.regular - counters.visible.active : counters.visible.active;
// retrieve visible mods from the model view
const auto allIndex = m_view->indexViewToModel(flatIndex(m_view->model()));
const QString message = enabled ?
tr("Really enable %1 mod(s)?") : tr("Really disable %1 mod(s)?");
if (QMessageBox::question(m_parent, tr("Confirm"), message.arg(allIndex.size()),
if (QMessageBox::question(m_parent, tr("Confirm"), message.arg(count),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
m_core.modList()->setActive(allIndex, enabled);
}