diff options
author | TheKodeToad <TheKodeToad@proton.me> | 2023-06-05 20:49:47 +0100 |
---|---|---|
committer | TheKodeToad <TheKodeToad@proton.me> | 2023-06-05 22:47:42 +0100 |
commit | 961285d6abad3e70a0ab748007349ef67632f138 (patch) | |
tree | dad36fe7b0527886b2d0ca8a3a1254976b87f4f3 /launcher/VersionProxyModel.cpp | |
parent | e1b37f3cd3d9383dcc70d0d7fac29f8158fbc379 (diff) | |
download | PrismLauncher-961285d6abad3e70a0ab748007349ef67632f138.tar.gz PrismLauncher-961285d6abad3e70a0ab748007349ef67632f138.tar.bz2 PrismLauncher-961285d6abad3e70a0ab748007349ef67632f138.zip |
Add a search bar to version lists
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher/VersionProxyModel.cpp')
-rw-r--r-- | launcher/VersionProxyModel.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/launcher/VersionProxyModel.cpp b/launcher/VersionProxyModel.cpp index 6aba268d..d5d14c24 100644 --- a/launcher/VersionProxyModel.cpp +++ b/launcher/VersionProxyModel.cpp @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> + * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -54,9 +55,14 @@ public: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { const auto &filters = m_parent->filters(); + const QString &search = m_parent->search(); + const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); + + if (!search.isEmpty() && !sourceModel()->data(idx, BaseVersionList::VersionRole).toString().contains(search)) + return false; + for (auto it = filters.begin(); it != filters.end(); ++it) { - auto idx = sourceModel()->index(source_row, 0, source_parent); auto data = sourceModel()->data(idx, it.key()); auto match = data.toString(); if(!it.value()->accepts(match)) @@ -431,6 +437,7 @@ QModelIndex VersionProxyModel::getVersion(const QString& version) const void VersionProxyModel::clearFilters() { m_filters.clear(); + m_search.clear(); filterModel->filterChanged(); } @@ -440,11 +447,21 @@ void VersionProxyModel::setFilter(const BaseVersionList::ModelRoles column, Filt filterModel->filterChanged(); } +void VersionProxyModel::setSearch(const QString &search) { + m_search = search; + filterModel->filterChanged(); +} + const VersionProxyModel::FilterMap &VersionProxyModel::filters() const { return m_filters; } +const QString &VersionProxyModel::search() const +{ + return m_search; +} + void VersionProxyModel::sourceAboutToBeReset() { beginResetModel(); |