From 7fd81029ce2f67aa7a6555858dfed7d6ac58c4e3 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Tue, 22 Jan 2019 14:59:07 -0600 Subject: Reduce file I/O operations when enabling/disabling multiple mods --- src/modlist.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index 58fe95d5..cc15a111 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -527,7 +527,7 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role) m_Profile->setModEnabled(modID, enabled); m_Modified = true; m_LastCheck.restart(); - emit modlist_changed(index, role); + emit modlistChanged(index, role); } result = true; emit dataChanged(index, index); @@ -562,7 +562,7 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role) int newID = value.toInt(&ok); if (ok) { info->setNexusID(newID); - emit modlist_changed(index, role); + emit modlistChanged(index, role); result = true; } else { result = false; @@ -1283,12 +1283,24 @@ bool ModList::toggleSelection(QAbstractItemView *itemView) QItemSelectionModel *selectionModel = itemView->selectionModel(); + QList modsToEnable; + QList modsToDisable; + QModelIndexList dirtyMods; for (QModelIndex idx : selectionModel->selectedRows()) { int modId = idx.data(Qt::UserRole + 1).toInt(); - m_Profile->setModEnabled(modId, !m_Profile->modEnabled(modId)); - emit modlist_changed(idx, 0); + if (m_Profile->modEnabled(modId)) { + modsToDisable.append(modId); + dirtyMods.append(idx); + } else { + modsToEnable.append(modId); + dirtyMods.append(idx); + } } + m_Profile->setModsEnabled(modsToEnable, modsToDisable); + + emit modlistChanged(dirtyMods, 0); + m_Modified = true; m_LastCheck.restart(); @@ -1331,13 +1343,12 @@ bool ModList::eventFilter(QObject *obj, QEvent *event) void ModList::enableSelected(const QItemSelectionModel *selectionModel) { if (selectionModel->hasSelection()) { - bool dirty = false; + QList modsToEnable; for (auto row : selectionModel->selectedRows(COL_PRIORITY)) { int modID = m_Profile->modIndexByPriority(row.data().toInt()); - if (!m_Profile->modEnabled(modID)) { - m_Profile->setModEnabled(modID, true); - } + modsToEnable.append(modID); } + m_Profile->setModsEnabled(modsToEnable, QList()); } } @@ -1345,14 +1356,11 @@ void ModList::enableSelected(const QItemSelectionModel *selectionModel) void ModList::disableSelected(const QItemSelectionModel *selectionModel) { if (selectionModel->hasSelection()) { - bool dirty = false; + QList modsToDisable; for (auto row : selectionModel->selectedRows(COL_PRIORITY)) { int modID = m_Profile->modIndexByPriority(row.data().toInt()); - if (m_Profile->modEnabled(modID)) { - m_Profile->setModEnabled(modID, false); - } + modsToDisable.append(modID); } - - + m_Profile->setModsEnabled(QList(), modsToDisable); } } -- cgit v1.3.1