|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2004-2018 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 */ |
|
18 |
|
19 /** |
|
20 * @file |
|
21 * @brief ThemeFilterProxyModel class implementation |
|
22 */ |
|
23 |
|
24 #include "ThemeModel.h" |
|
25 #include "ThemeFilterProxyModel.h" |
|
26 |
|
27 ThemeFilterProxyModel::ThemeFilterProxyModel(QObject *parent) |
|
28 : QSortFilterProxyModel(parent) |
|
29 { |
|
30 isFilteringDLC = false; |
|
31 isFilteringHidden = false; |
|
32 } |
|
33 |
|
34 bool ThemeFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const |
|
35 { |
|
36 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); |
|
37 bool searchOkay = true; |
|
38 if(!filterRegExp().isEmpty()) |
|
39 { |
|
40 // Check regular expression set by the theme chooser search |
|
41 QString name = index.data(ThemeModel::ActualNameRole).toString(); |
|
42 int in = filterRegExp().indexIn(name); |
|
43 searchOkay = in != -1; |
|
44 } |
|
45 |
|
46 if(isFilteringDLC || isFilteringHidden) |
|
47 { |
|
48 bool isDLC = index.data(ThemeModel::IsDlcRole).toBool(); |
|
49 bool isHidden = index.data(ThemeModel::IsHiddenRole).toBool(); |
|
50 |
|
51 return ( ((isFilteringDLC && !isDLC) || !isFilteringDLC) && |
|
52 ((isFilteringHidden && !isHidden) || !isFilteringHidden) ) && |
|
53 searchOkay; |
|
54 } |
|
55 else |
|
56 { |
|
57 return searchOkay; |
|
58 } |
|
59 } |
|
60 |
|
61 void ThemeFilterProxyModel::setFilterDLC(bool enable) |
|
62 { |
|
63 isFilteringDLC = enable; |
|
64 invalidateFilter(); |
|
65 } |
|
66 |
|
67 void ThemeFilterProxyModel::setFilterHidden(bool enable) |
|
68 { |
|
69 isFilteringHidden = enable; |
|
70 invalidateFilter(); |
|
71 } |