File indexing completed on 2024-05-05 04:53:42
0001 /* 0002 SPDX-FileCopyrightText: 2017 Nicolas Carion 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "profilefilter.hpp" 0007 #include "../profilemodel.hpp" 0008 #include "../profilerepository.hpp" 0009 #include "profiletreemodel.hpp" 0010 0011 ProfileFilter::ProfileFilter(QObject *parent) 0012 : QSortFilterProxyModel(parent) 0013 , m_interlaced_value() 0014 , m_fps_value() 0015 { 0016 m_interlaced_enabled = m_fps_enabled = false; 0017 } 0018 0019 void ProfileFilter::setFilterInterlaced(bool enabled, bool interlaced) 0020 { 0021 m_interlaced_enabled = enabled; 0022 m_interlaced_value = interlaced; 0023 invalidateFilter(); 0024 } 0025 0026 bool ProfileFilter::filterInterlaced(std::unique_ptr<ProfileModel> &ptr) const 0027 { 0028 return !m_interlaced_enabled || ptr->progressive() != m_interlaced_value; 0029 } 0030 0031 void ProfileFilter::setFilterFps(bool enabled, double fps) 0032 { 0033 m_fps_enabled = enabled; 0034 m_fps_value = fps; 0035 invalidateFilter(); 0036 } 0037 0038 bool ProfileFilter::filterFps(std::unique_ptr<ProfileModel> &ptr) const 0039 { 0040 return !m_fps_enabled || qFuzzyCompare(ptr->fps(), m_fps_value); 0041 } 0042 0043 bool ProfileFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const 0044 { 0045 if (sourceParent == QModelIndex()) { 0046 // In that case, we have a category. We hide it if it does not have children. 0047 QModelIndex category = sourceModel()->index(sourceRow, 0, sourceParent); 0048 bool accepted = false; 0049 for (int i = 0; i < sourceModel()->rowCount(category) && !accepted; ++i) { 0050 accepted = filterAcceptsRow(i, category); 0051 } 0052 return accepted; 0053 } 0054 QModelIndex row = sourceModel()->index(sourceRow, 0, sourceParent); 0055 QString profile_path = static_cast<ProfileTreeModel *>(sourceModel())->getProfile(row); 0056 if (profile_path.isEmpty()) { 0057 return true; 0058 } 0059 0060 std::unique_ptr<ProfileModel> &profile = ProfileRepository::get()->getProfile(profile_path); 0061 0062 return filterInterlaced(profile) && filterFps(profile); 0063 } 0064 0065 bool ProfileFilter::isVisible(const QModelIndex &sourceIndex) 0066 { 0067 auto parent = sourceModel()->parent(sourceIndex); 0068 return filterAcceptsRow(sourceIndex.row(), parent); 0069 }