| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "taskmanager.h" |
| 6 | #include "transceiver/buildersender.h" |
| 7 | #include "common/common.h" |
| 8 | |
| 9 | TaskManager *TaskManager::instance() |
| 10 | { |
| 11 | static TaskManager ins; |
| 12 | return &ins; |
| 13 | } |
| 14 | |
| 15 | QListView *TaskManager::getView() const |
| 16 | { |
| 17 | return view; |
| 18 | } |
| 19 | |
| 20 | void TaskManager::clearTasks() |
| 21 | { |
| 22 | model->clearTasks(); |
| 23 | } |
| 24 | |
| 25 | TaskManager::TaskManager(QObject *parent) : QObject(parent) |
| 26 | { |
| 27 | view = new TaskView(); |
| 28 | model.reset(new TaskModel()); |
| 29 | view->setModel(model.get()); |
| 30 | auto tld = new TaskDelegate; |
| 31 | view->setItemDelegate(tld); |
| 32 | |
| 33 | view->setFrameStyle(QFrame::NoFrame); |
| 34 | view->setSelectionMode(QAbstractItemView::SingleSelection); |
| 35 | |
| 36 | connect(view->selectionModel(), &QItemSelectionModel::currentChanged, |
| 37 | tld, &TaskDelegate::currentChanged); |
| 38 | |
| 39 | connect(view->selectionModel(), &QItemSelectionModel::currentChanged, |
| 40 | this, &TaskManager::currentChanged); |
| 41 | connect(view, &QAbstractItemView::activated, |
| 42 | this, &TaskManager::triggerDefaultHandler); |
| 43 | } |
| 44 | |
| 45 | void TaskManager::slotAddTask(const Task &task, int linkedOutputLines, int skipLines) |
| 46 | { |
| 47 | Q_UNUSED(linkedOutputLines) |
| 48 | Q_UNUSED(skipLines) |
| 49 | |
| 50 | model->addTask(task); |
| 51 | } |
| 52 | |
| 53 | void TaskManager::currentChanged(const QModelIndex &index) |
| 54 | { |
| 55 | Q_UNUSED(index) |
| 56 | } |
| 57 | |
| 58 | void TaskManager::triggerDefaultHandler(const QModelIndex &index) |
| 59 | { |
| 60 | if (!index.isValid()) |
| 61 | return; |
| 62 | |
| 63 | Task task(model->task(index)); |
| 64 | if (task.isNull()) |
| 65 | return; |
| 66 | |
| 67 | if (task.file.exists()) { |
| 68 | editor.jumpToLine(task.file.toString(), task.movedLine); |
| 69 | } |
| 70 | } |
| 71 | |