From 70ddfaadbfdf3999eea0fe50f7cdac3675e5f019 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Fri, 14 Dec 2018 17:26:37 -0600 Subject: Expand mod list search edit to work on categories, nexus IDs, and notes --- src/modlistsortproxy.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 9adaa511..b5f1ee5c 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -39,10 +39,6 @@ ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent) , m_FilterActive(false) , m_FilterMode(FILTER_AND) { - m_EnabledColumns.set(ModList::COL_FLAGS); - m_EnabledColumns.set(ModList::COL_NAME); - m_EnabledColumns.set(ModList::COL_VERSION); - m_EnabledColumns.set(ModList::COL_PRIORITY); setDynamicSortFilter(true); // this seems to work without dynamicsortfilter // but I don't know why. This should be necessary } @@ -340,8 +336,53 @@ bool ModListSortProxy::filterMatchesModOr(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)) { + bool display = true; + if (!m_CurrentFilter.isEmpty()) { + display = false; + + // Search by name + if (!display && + m_EnabledColumns[ModList::COL_NAME] && + info->name().contains(m_CurrentFilter, Qt::CaseInsensitive)) { + display = true; + } + + // Search by notes + if (!display && + m_EnabledColumns[ModList::COL_NOTES] && + info->comments().contains(m_CurrentFilter, Qt::CaseInsensitive)) { + display = true; + } + + // Search by Nexus ID + if (!display && + m_EnabledColumns[ModList::COL_MODID]) { + bool ok; + int filterID = m_CurrentFilter.toInt(&ok); + if (ok) { + int modID = info->getNexusID(); + while (modID > 0) { + if (modID == filterID) { + display = true; + break; + } + modID = (int)(modID / 10); + } + } + } + + // Search by categories + if (!display && + m_EnabledColumns[ModList::COL_CATEGORY]) { + for (auto category : info->categories()) { + if (category.contains(m_CurrentFilter, Qt::CaseInsensitive)) { + display = true; + break; + } + } + } + } + if (!display) { return false; } @@ -352,6 +393,11 @@ bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const } } +void ModListSortProxy::setColumnVisible(int column, bool visible) +{ + m_EnabledColumns[column] = visible; +} + void ModListSortProxy::setFilterMode(ModListSortProxy::FilterMode mode) { if (m_FilterMode != mode) { -- cgit v1.3.1 From fcff329c1e5529bbceaf46592c30cd87dc6a6f44 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Sun, 23 Dec 2018 00:55:54 -0600 Subject: Add sorting for the notes column --- src/modlistsortproxy.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index b5f1ee5c..833e16c3 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -214,9 +214,25 @@ bool ModListSortProxy::lessThan(const QModelIndex &left, lt = comp < 0; } } break; + case ModList::COL_NOTES: { + QString leftComments = leftMod->comments(); + QString rightComments = rightMod->comments(); + if (leftComments != rightComments) { + if (leftComments.isEmpty()) { + lt = sortOrder() == Qt::DescendingOrder; + } else if (rightComments.isEmpty()) { + lt = sortOrder() == Qt::AscendingOrder; + } else { + lt = leftComments < rightComments; + } + } + } break; case ModList::COL_PRIORITY: { // nop, already compared by priority } break; + default: { + qWarning() << "Sorting is not defined for column " << left.column(); + } break; } return lt; } -- cgit v1.3.1