summaryrefslogtreecommitdiff
path: root/src/modlistsortproxy.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2015-03-09 12:34:34 +0100
committerTannin <devnull@localhost>2015-03-09 12:34:34 +0100
commit7a1ae9b0f1560c9eda32e032796fbb3fd56ff236 (patch)
treedea71435ac1042cb008fcd9f7b1ec57e6ea91227 /src/modlistsortproxy.cpp
parentd45ebf134819e1559718681becca9c4139fb7151 (diff)
parentdb2954e8eb41da715b9e7d79a72e225797401413 (diff)
Merge with branch1.2
Diffstat (limited to 'src/modlistsortproxy.cpp')
-rw-r--r--src/modlistsortproxy.cpp46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index bef3c387..d62fe00a 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -54,7 +54,7 @@ void ModListSortProxy::setProfile(Profile *profile)
void ModListSortProxy::updateFilterActive()
{
- m_FilterActive = (m_CategoryFilter.size() > 0) || !m_CurrentFilter.isEmpty();
+ m_FilterActive = (m_CategoryFilter.size() > 0) || (m_ContentFilter.size() > 0) || !m_CurrentFilter.isEmpty();
emit filterActive(m_FilterActive);
}
@@ -65,6 +65,13 @@ void ModListSortProxy::setCategoryFilter(const std::vector<int> &categories)
this->invalidate();
}
+void ModListSortProxy::setContentFilter(const std::vector<int> &content)
+{
+ m_ContentFilter = content;
+ updateFilterActive();
+ this->invalidate();
+}
+
Qt::ItemFlags ModListSortProxy::flags(const QModelIndex &modelIndex) const
{
Qt::ItemFlags flags = sourceModel()->flags(mapToSource(modelIndex));
@@ -74,10 +81,9 @@ Qt::ItemFlags ModListSortProxy::flags(const QModelIndex &modelIndex) const
return flags;
}
-
void ModListSortProxy::enableAllVisible()
{
- if (m_Profile == NULL) return;
+ if (m_Profile == nullptr) return;
for (int i = 0; i < this->rowCount(); ++i) {
int modID = mapToSource(index(i, 0)).data(Qt::UserRole + 1).toInt();
@@ -88,7 +94,7 @@ void ModListSortProxy::enableAllVisible()
void ModListSortProxy::disableAllVisible()
{
- if (m_Profile == NULL) return;
+ if (m_Profile == nullptr) return;
for (int i = 0; i < this->rowCount(); ++i) {
int modID = mapToSource(index(i, 0)).data(Qt::UserRole + 1).toInt();
@@ -128,6 +134,24 @@ bool ModListSortProxy::lessThan(const QModelIndex &left,
if (leftMod->getFlags().size() != rightMod->getFlags().size())
lt = leftMod->getFlags().size() < rightMod->getFlags().size();
} break;
+ case ModList::COL_CONTENT: {
+ std::vector<ModInfo::EContent> lContent = leftMod->getContents();
+ std::vector<ModInfo::EContent> rContent = rightMod->getContents();
+ if (lContent.size() != rContent.size()) {
+ lt = lContent.size() < rContent.size();
+ }
+
+ int lValue = 0;
+ int rValue = 0;
+ for (ModInfo::EContent content : lContent) {
+ lValue += 2 << (unsigned int)content;
+ }
+ for (ModInfo::EContent content : rContent) {
+ rValue += 2 << (unsigned int)content;
+ }
+
+ lt = lValue < rValue;
+ } break;
case ModList::COL_NAME: {
int comp = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
if (comp != 0)
@@ -228,6 +252,11 @@ bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) cons
} break;
}
}
+
+ foreach (int content, m_ContentFilter) {
+ if (!info->hasContent(static_cast<ModInfo::EContent>(content))) return false;
+ }
+
return true;
}
@@ -265,6 +294,11 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const
} break;
}
}
+
+ foreach (int content, m_ContentFilter) {
+ if (info->hasContent(static_cast<ModInfo::EContent>(content))) return true;
+ }
+
return false;
}
@@ -278,7 +312,7 @@ bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const
if (m_FilterMode == FILTER_AND) {
return filterMatchesModAnd(info, enabled);
} else {
- return (m_CategoryFilter.size() == 0) || filterMatchesModOr(info, enabled);
+ return filterMatchesModOr(info, enabled);
}
}
@@ -292,7 +326,7 @@ void ModListSortProxy::setFilterMode(ModListSortProxy::FilterMode mode)
bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex &parent) const
{
- if (m_Profile == NULL) {
+ if (m_Profile == nullptr) {
return false;
}