1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "taskhub.h"
#include <coreplugin/ioutputpane.h>
#include <utils/qtcassert.h>
#include <utils/threadutils.h>
#include <QGuiApplication>
using namespace Utils;
namespace ProjectExplorer {
static QList<Id> s_registeredCategories;
TaskHub::TaskHub()
{
qRegisterMetaType<ProjectExplorer::Task>("ProjectExplorer::Task");
qRegisterMetaType<Tasks >("Tasks");
}
TaskHub::~TaskHub() = default;
void TaskHub::addCategory(const TaskCategory &category)
{
QTC_CHECK(!category.displayName.isEmpty());
QTC_ASSERT(!s_registeredCategories.contains(category.id), return);
s_registeredCategories.push_back(category.id);
emit taskHub().categoryAdded(category);
}
void TaskHub::addTask(Task::TaskType type, const QString &description, Utils::Id category)
{
addTask<Task>(type, description, Utils::FilePath(), -1, category);
}
void TaskHub::addTask(Task task)
{
if (!isMainThread()) {
QMetaObject::invokeMethod(qApp, [task = std::move(task)] {
TaskHub::addTask(task);
});
return;
}
bool popUp = false;
if (task.type() == Task::DisruptingError) {
popUp = true;
task.setType(Task::Error);
}
QTC_ASSERT(s_registeredCategories.contains(task.category()), return);
QTC_ASSERT(!task.description().isEmpty(), return);
QTC_ASSERT(!task.isNull(), return);
QTC_ASSERT(!task.hasMark(), return);
if (task.file().isEmpty() || task.line() <= 0)
task.setLine(-1);
emit taskHub().taskAdded(task);
if (popUp)
requestPopup();
}
void TaskHub::clearTasks(Id categoryId)
{
QTC_ASSERT(!categoryId.isValid() || s_registeredCategories.contains(categoryId), return);
emit taskHub().tasksCleared(categoryId);
}
void TaskHub::removeTask(const Task &task)
{
emit taskHub().taskRemoved(task);
}
void TaskHub::clearAndRemoveTask(Task &task)
{
if (!task.isNull()) {
removeTask(task);
task.clear();
}
}
void TaskHub::updateTaskFilePath(const Task &task, const FilePath &filePath)
{
emit taskHub().taskFilePathUpdated(task, filePath);
}
void TaskHub::updateTaskLineNumber(const Task &task, int line)
{
emit taskHub().taskLineNumberUpdated(task, line);
}
void TaskHub::taskMarkClicked(const Task &task)
{
emit taskHub().showTask(task);
}
void TaskHub::showTaskInEditor(const Task &task)
{
emit taskHub().openTask(task);
}
void TaskHub::setCategoryVisibility(Id categoryId, bool visible)
{
QTC_ASSERT(s_registeredCategories.contains(categoryId), return);
emit taskHub().categoryVisibilityChanged(categoryId, visible);
}
void TaskHub::requestPopup()
{
emit taskHub().popupRequested(Core::IOutputPane::NoModeSwitch);
}
TaskHub &taskHub()
{
static TaskHub theTaskHub;
return theTaskHub;
}
} // namespace ProjectExplorer
|