1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef TASKFILTERMODEL_H |
6 | #define TASKFILTERMODEL_H |
7 | |
8 | #include "taskmodel.h" |
9 | |
10 | namespace ReverseDebugger{ |
11 | namespace Internal { |
12 | |
13 | class TaskFilterModel : public QAbstractItemModel |
14 | { |
15 | Q_OBJECT |
16 | public: |
17 | TaskFilterModel(TaskModel *sourceModel, QObject *parent = nullptr); |
18 | |
19 | TaskModel *taskModel() { return sourceModel; } |
20 | |
21 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
22 | QModelIndex parent(const QModelIndex &child) const override; |
23 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
24 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
25 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
26 | |
27 | QList<QString> filteredCategories() const { return categoryIds; } |
28 | void setFilteredCategories(const QList<QString> &_categoryIds) { |
29 | categoryIds = _categoryIds; |
30 | invalidateFilter(); |
31 | } |
32 | void setSortType(int type) { |
33 | sortType = type; |
34 | invalidateFilter(); |
35 | } |
36 | void setEventTid(int _tid) { |
37 | //NOTE: tid filter can combine with event type filter |
38 | tid = _tid; |
39 | invalidateFilter(); |
40 | } |
41 | void setEventRange(int begin, int end) { |
42 | eventBegin = begin; |
43 | eventEnd = end; |
44 | eventIndexBegin = -1; |
45 | eventIndexEnd = -1; |
46 | invalidateFilter(); |
47 | } |
48 | void setEventIndexRange(int begin, int end) { |
49 | eventBegin = -1; |
50 | eventEnd = -1; |
51 | eventIndexBegin = begin; |
52 | eventIndexEnd = end; |
53 | invalidateFilter(); |
54 | } |
55 | |
56 | Task task(const QModelIndex &index) const |
57 | { return sourceModel->task(mapToSource(index)); } |
58 | |
59 | QModelIndex mapFromSource(const QModelIndex &idx) const; |
60 | signals: |
61 | |
62 | public slots: |
63 | |
64 | private: |
65 | void handleNewRows(const QModelIndex &index, int first, int last); |
66 | void handleRowsAboutToBeRemoved(const QModelIndex &index, int first, int last); |
67 | void handleDataChanged(const QModelIndex &top, const QModelIndex &bottom); |
68 | void handleReset(); |
69 | |
70 | QModelIndex mapToSource(const QModelIndex &index) const; |
71 | void invalidateFilter(); |
72 | void updateMapping() const; |
73 | bool filterAcceptsTask(const Task &task) const; |
74 | |
75 | int sortType = 0; |
76 | int tid = 0; |
77 | int eventBegin = 0; |
78 | int eventEnd = 0; |
79 | int eventIndexBegin = 0; |
80 | int eventIndexEnd = 0; |
81 | QList<QString> categoryIds; |
82 | |
83 | mutable QList<int> rowMapping; |
84 | |
85 | TaskModel *sourceModel = nullptr; |
86 | }; |
87 | |
88 | } // namespace Internal |
89 | } // namespace ReverseDebugger |
90 | |
91 | #endif // TASKFILTERMODEL_H |
92 | |