From ebf6ff3f7695df2022d25f9e9198d37c699cbc94 Mon Sep 17 00:00:00 2001 From: Tannin Date: Mon, 8 Jun 2015 18:28:20 +0200 Subject: workaround to prevent crashes when toggling mods causes the filtered list to change --- src/modlist.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index 74aa542d..a7990132 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -23,6 +23,7 @@ along with Mod Organizer. If not, see . #include "installationtester.h" #include "qtgroupingproxy.h" #include "viewmarkingscrollbar.h" +#include "modlistsortproxy.h" #include #include #include @@ -1091,14 +1092,33 @@ bool ModList::deleteSelection(QAbstractItemView *itemView) bool ModList::toggleSelection(QAbstractItemView *itemView) { QAbstractItemModel *model = itemView->model(); + + // having a filter active when dataChanged is called caused a crash + // (at least with some Qt versions) + ModListSortProxy *filterModel = qobject_cast(model); + std::vector filter; + if (filterModel != nullptr) { + filter = filterModel->categoryFilter(); + filterModel->setCategoryFilter(std::vector()); + } + QItemSelectionModel *selectionModel = itemView->selectionModel(); for (QModelIndex idx : selectionModel->selectedRows()) { - int oldState = idx.data(Qt::CheckStateRole).toInt(); - model->setData(idx, oldState == Qt::Unchecked ? Qt::Checked - : Qt::Unchecked, - Qt::CheckStateRole); + int modId = idx.data(Qt::UserRole + 1).toInt(); + m_Profile->setModEnabled(modId, !m_Profile->modEnabled(modId)); + emit modlist_changed(idx, 0); + } + + m_Modified = true; + m_LastCheck.restart(); + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); + + if (filterModel != nullptr) { + filterModel->setCategoryFilter(filter); } + return true; } -- cgit v1.3.1