| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef TASKMODEL_H |
| 6 | #define TASKMODEL_H |
| 7 | |
| 8 | #include "services/builder/task.h" |
| 9 | |
| 10 | #include <QAbstractItemModel> |
| 11 | #include <QFont> |
| 12 | |
| 13 | class TaskModel : public QAbstractItemModel |
| 14 | { |
| 15 | Q_OBJECT |
| 16 | public: |
| 17 | enum Roles { File = Qt::UserRole, Line, MovedLine, Description, FileNotFound, Type, Category, Icon, Task_t }; |
| 18 | |
| 19 | explicit TaskModel(QObject *parent = nullptr); |
| 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 | Task task(const QModelIndex &index) const; |
| 27 | |
| 28 | QList<Task> getTasks() const; |
| 29 | void addTask(const Task &task); |
| 30 | void removeTask(const Task &task); |
| 31 | void clearTasks(); |
| 32 | |
| 33 | int taskCount(); |
| 34 | |
| 35 | int sizeOfFile(const QFont &font); |
| 36 | int getSizeOfLineNumber(const QFont &font); |
| 37 | signals: |
| 38 | |
| 39 | public slots: |
| 40 | private: |
| 41 | |
| 42 | QFont fileMeasurementFont; |
| 43 | QFont lineMeasurementFont; |
| 44 | int maxSizeOfFileName = 0; |
| 45 | int lastMaxSizeIndex = 0; |
| 46 | int sizeOfLineNumber = 0; |
| 47 | |
| 48 | QList<Task> tasks; |
| 49 | }; |
| 50 | |
| 51 | #endif // TASKMODEL_H |
| 52 | |