From daf4ae44faee3e641a743cc9f4e0c56f016faad4 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sun, 1 Dec 2013 23:50:24 +0100 Subject: - added second context menu for changing categories that applies only changes to the selected mods instead of replacing the existing set of categories (thanks to Ross!) - bugfix: category filtering didn't work correctly when grouping was also active --- src/modlistsortproxy.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 888ecdb8..4d767230 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -220,7 +220,7 @@ bool ModListSortProxy::hasConflictFlag(const std::vector &flags) } -bool ModListSortProxy::filterMatches(ModInfo::Ptr info, bool enabled) const +bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const { if (!m_CurrentFilter.isEmpty() && !info->name().contains(m_CurrentFilter, Qt::CaseInsensitive)) { @@ -258,7 +258,7 @@ bool ModListSortProxy::filterMatches(ModInfo::Ptr info, bool enabled) const } -bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex&) const +bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex &parent) const { if (m_Profile == NULL) { return false; @@ -268,9 +268,25 @@ bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex&) const qWarning("invalid row idx %d", row); return false; } - bool modEnabled = m_Profile->modEnabled(row); - return filterMatches(ModInfo::getByIndex(row), modEnabled); + QModelIndex idx = sourceModel()->index(row, 0, parent); + if (!idx.isValid()) { + qDebug("invalid index"); + return false; + } + if (idx.isValid() && sourceModel()->hasChildren(idx)) { + for (int i = 0; i < sourceModel()->rowCount(idx); ++i) { + if (filterAcceptsRow(i, idx)) { + return true; + } + } + + return false; + } else { + bool modEnabled = idx.sibling(row, 0).data(Qt::CheckStateRole).toInt() == Qt::Checked; + unsigned int index = idx.data(Qt::UserRole + 1).toInt(); + return filterMatchesMod(ModInfo::getByIndex(index), modEnabled); + } } -- cgit v1.3.1