1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7#include "event_man.h"
8
9#include <QAbstractItemModel>
10#include <QFont>
11
12namespace ReverseDebugger {
13namespace Internal {
14
15class Task
16{
17public:
18 Task() = default;
19 Task(const QString &description, const QString &category, const EventEntry *event);
20
21 bool isNull() const;
22 void clear();
23
24 uint taskId = 0;
25 const EventEntry *event = nullptr;
26 QString category;
27 QString description;
28
29private:
30 static uint s_nextId;
31};
32
33bool operator==(const Task &t1, const Task &t2);
34bool operator<(const Task &a, const Task &b);
35uint qHash(const Task &task);
36
37class TaskModel : public QAbstractItemModel
38{
39 Q_OBJECT
40
41 class CategoryData
42 {
43 public:
44 CategoryData()
45 : count(0) {}
46
47 void addTask(const Task &task)
48 {
49 Q_UNUSED(task);
50 ++count;
51 }
52
53 void removeTask(const Task &task)
54 {
55 Q_UNUSED(task);
56 --count;
57 }
58
59 void clear()
60 {
61 count = 0;
62 }
63
64 QString displayName;
65 int count = 0;
66 };
67
68public:
69 enum Roles { Result = Qt::UserRole,
70 Description,
71 ExtraInfo,
72 Time,
73 Duration,
74 Return,
75 Tid,
76 ThreadNum,
77 Type,
78 Category,
79 Icon,
80 };
81
82 explicit TaskModel(QObject *parent = nullptr);
83
84 void setTimelinePtr(void *timeline);
85 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
86 QModelIndex parent(const QModelIndex &child) const override;
87 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
88 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
89 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
90 Task task(int index) const;
91 Task task(const QModelIndex &index) const;
92
93 QList<QString> categoryIds() const;
94 QString categoryDisplayName(const QString &categoryId) const;
95 void addCategory(const QString &categoryId, const QString &categoryName);
96
97 QList<Task> tasks(const QString &categoryId = "") const;
98 void addTask(const Task &task);
99 void removeTask(const Task &task);
100 void clearTasks(const QString &categoryId = "");
101 int getSizeOfLineNumber(const QFont &font);
102
103 int taskCount(const QString &categoryId);
104 int rowForId(unsigned int id);
105signals:
106
107public slots:
108
109private:
110 QHash<QString, CategoryData> categories; // category id to data
111 QList<Task> allTasks; // all tasks (in order of id)
112
113 int sizeOfLineNumber = 0;
114 QFont fileMeasurementFont;
115 QFont lineMeasurementFont;
116 void *timeline = nullptr;
117};
118
119} // namespace Internal
120} // namespace ReverseDebugger
121