1 | #pragma once |
2 | |
3 | /**************************************************************************************** |
4 | ** GitQlient is an application to manage and operate one or several Git repositories. With |
5 | ** GitQlient you will be able to add commits, branches and manage all the options Git provides. |
6 | ** Copyright (C) 2021 Francesc Martinez |
7 | ** |
8 | ** LinkedIn: www.linkedin.com/in/cescmm/ |
9 | ** Web: www.francescmm.com |
10 | ** |
11 | ** This program is free software; you can redistribute it and/or |
12 | ** modify it under the terms of the GNU Lesser General Public |
13 | ** License as published by the Free Software Foundation; either |
14 | ** version 2 of the License, or (at your option) any later version. |
15 | ** |
16 | ** This program is distributed in the hope that it will be useful, |
17 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | ** Lesser General Public License for more details. |
20 | ** |
21 | ** You should have received a copy of the GNU Lesser General Public |
22 | ** License along with this library; if not, write to the Free Software |
23 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | ***************************************************************************************/ |
25 | |
26 | #include <QSortFilterProxyModel> |
27 | |
28 | /** |
29 | * @brief The ShaFilterProxyModel class is an overload of the QSortFilterProxyModel that takes a list of shas to act as |
30 | * a filter between a view and a QAbstractiItemModel. |
31 | * |
32 | */ |
33 | class ShaFilterProxyModel : public QSortFilterProxyModel |
34 | { |
35 | Q_OBJECT |
36 | |
37 | public: |
38 | /** |
39 | * @brief Default constructor. |
40 | * |
41 | * @param parent The parent widget if needed. |
42 | */ |
43 | explicit ShaFilterProxyModel(QObject *parent = nullptr); |
44 | |
45 | /** |
46 | * @brief Sets the list of accepted SHAs that will be shown in the source model. |
47 | * |
48 | * @param acceptedShaList The SHAs list. |
49 | */ |
50 | void setAcceptedSha(const QStringList &acceptedShaList) { mAcceptedShas = acceptedShaList; } |
51 | /** |
52 | * @brief Starts the reset of the model |
53 | * |
54 | */ |
55 | void beginResetModel() { QSortFilterProxyModel::beginResetModel(); } |
56 | /** |
57 | * @brief Ends the reset of the model. |
58 | * |
59 | */ |
60 | void endResetModel() { QSortFilterProxyModel::endResetModel(); } |
61 | |
62 | protected: |
63 | /** |
64 | * @brief This method is the actual filter functionality. Given the source row and the source index it retrieves the |
65 | * sha and checks if it's among the accepted SHAs in the list. |
66 | * |
67 | * @param sourceRow The source row number. |
68 | * @param sourceParent The source index. |
69 | * @return bool Returns true if the source row should be shown in the view. |
70 | */ |
71 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; |
72 | |
73 | private: |
74 | /** |
75 | * @brief mAcceptedShas List of accepted shas. |
76 | */ |
77 | QStringList mAcceptedShas; |
78 | }; |
79 | |