diff options
Diffstat (limited to 'src/modlistsortproxy.cpp')
| -rw-r--r-- | src/modlistsortproxy.cpp | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index bef3c387..d649996f 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -37,7 +37,6 @@ ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent) , m_CurrentFilter()
, m_FilterActive(false)
, m_FilterMode(FILTER_AND)
- , m_BeingInvalidated(false)
{
m_EnabledColumns.set(ModList::COL_FLAGS);
m_EnabledColumns.set(ModList::COL_NAME);
@@ -54,7 +53,9 @@ 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);
}
@@ -62,22 +63,26 @@ void ModListSortProxy::setCategoryFilter(const std::vector<int> &categories) {
m_CategoryFilter = categories;
updateFilterActive();
- this->invalidate();
+ invalidate();
+}
+
+void ModListSortProxy::setContentFilter(const std::vector<int> &content)
+{
+ m_ContentFilter = content;
+ updateFilterActive();
+ invalidate();
}
Qt::ItemFlags ModListSortProxy::flags(const QModelIndex &modelIndex) const
{
Qt::ItemFlags flags = sourceModel()->flags(mapToSource(modelIndex));
-/* if (sortColumn() != ModList::COL_PRIORITY) {
- flags &= ~Qt::ItemIsDragEnabled;
- }*/
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 +93,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 +133,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)
@@ -174,10 +197,9 @@ void ModListSortProxy::updateFilter(const QString &filter) {
m_CurrentFilter = filter;
updateFilterActive();
- // workaround because qt throws a fit if, as a result of this invalidation, another invalidate is called
- m_BeingInvalidated = true;
- invalidateFilter();
- m_BeingInvalidated = false;
+ // using invalidateFilter here should be enough but that crashes the application? WTF?
+ // invalidateFilter();
+ invalidate();
}
bool ModListSortProxy::hasConflictFlag(const std::vector<ModInfo::EFlag> &flags) const
@@ -228,6 +250,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 +292,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 +310,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 +324,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;
}
|
