taskhub.cpp 4.58 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
dt's avatar
dt committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
dt's avatar
dt committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
dt's avatar
dt committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
dt's avatar
dt committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
dt's avatar
dt committed
29
30

#include "taskhub.h"
31
#include "projectexplorer.h"
32
#include <coreplugin/ioutputpane.h>
dt's avatar
dt committed
33
34
35

using namespace ProjectExplorer;

36
37
38
class TaskMark : public TextEditor::BaseTextMark
{
public:
39
    TaskMark(unsigned int id, const QString &fileName, int lineNumber, bool visible)
40
41
42
43
        : BaseTextMark(fileName, lineNumber), m_id(id)
    {
        setVisible(visible);
    }
44

45
    bool isClickable() const;
46
47
    void clicked();

48
    void updateFileName(const QString &fileName);
49
50
51
52
53
54
55
56
    void updateLineNumber(int lineNumber);
    void removedFromEditor();
private:
    unsigned int m_id;
};

void TaskMark::updateLineNumber(int lineNumber)
{
hjk's avatar
hjk committed
57
    ProjectExplorerPlugin::taskHub()->updateTaskLineNumber(m_id, lineNumber);
58
    BaseTextMark::updateLineNumber(lineNumber);
59
60
}

61
62
void TaskMark::updateFileName(const QString &fileName)
{
hjk's avatar
hjk committed
63
    ProjectExplorerPlugin::taskHub()->updateTaskFileName(m_id, fileName);
64
65
66
    BaseTextMark::updateFileName(fileName);
}

67
68
void TaskMark::removedFromEditor()
{
hjk's avatar
hjk committed
69
    ProjectExplorerPlugin::taskHub()->updateTaskLineNumber(m_id, -1);
70
71
}

72
bool TaskMark::isClickable() const
73
74
75
76
77
78
{
    return true;
}

void TaskMark::clicked()
{
hjk's avatar
hjk committed
79
    ProjectExplorerPlugin::taskHub()->taskMarkClicked(m_id);
80
81
}

dt's avatar
dt committed
82
83
84
85
86
87
88
89
90
91
92
93
94
TaskHub::TaskHub()
    : m_errorIcon(QLatin1String(":/projectexplorer/images/compile_error.png")),
      m_warningIcon(QLatin1String(":/projectexplorer/images/compile_warning.png"))
{
    qRegisterMetaType<ProjectExplorer::Task>("ProjectExplorer::Task");
    qRegisterMetaType<QList<ProjectExplorer::Task> >("QList<ProjectExplorer::Task>");
}

TaskHub::~TaskHub()
{

}

hjk's avatar
hjk committed
95
void TaskHub::addCategory(Core::Id categoryId, const QString &displayName, bool visible)
dt's avatar
dt committed
96
{
97
    emit categoryAdded(categoryId, displayName, visible);
dt's avatar
dt committed
98
99
}

100
void TaskHub::addTask(Task task)
dt's avatar
dt committed
101
{
102
    if (task.line != -1 && !task.file.isEmpty()) {
103
104
        bool visible = (task.type == Task::Warning || task.type == Task::Error);
        TaskMark *mark = new TaskMark(task.taskId, task.file.toString(), task.line, visible);
105
        mark->setIcon(taskTypeIcon(task.type));
106
        mark->setPriority(TextEditor::ITextMark::LowPriority);
107
        task.addMark(mark);
108
109
110
111
        emit taskAdded(task);
        mark->init();
    } else {
        emit taskAdded(task);
112
    }
dt's avatar
dt committed
113
114
}

hjk's avatar
hjk committed
115
void TaskHub::clearTasks(Core::Id categoryId)
dt's avatar
dt committed
116
117
118
119
120
121
122
123
124
{
    emit tasksCleared(categoryId);
}

void TaskHub::removeTask(const Task &task)
{
    emit taskRemoved(task);
}

125
126
127
128
129
void TaskHub::updateTaskFileName(unsigned int id, const QString &fileName)
{
    emit taskFileNameUpdated(id, fileName);
}

130
131
132
133
134
void TaskHub::updateTaskLineNumber(unsigned int id, int line)
{
    emit taskLineNumberUpdated(id, line);
}

135
136
137
138
139
void TaskHub::taskMarkClicked(unsigned int id)
{
    emit showTask(id);
}

140
141
142
143
144
void TaskHub::showTaskInEditor(unsigned int id)
{
    emit openTask(id);
}

145
void TaskHub::setCategoryVisibility(const Core::Id &categoryId, bool visible)
146
147
148
149
{
    emit categoryVisibilityChanged(categoryId, visible);
}

150
void TaskHub::requestPopup()
151
{
152
    emit popupRequested(Core::IOutputPane::NoModeSwitch);
153
154
}

dt's avatar
dt committed
155
156
157
158
159
160
161
162
163
164
165
166
167
QIcon TaskHub::taskTypeIcon(Task::TaskType t) const
{
    switch (t) {
    case Task::Warning:
        return m_warningIcon;
    case Task::Error:
        return m_errorIcon;
    case Task::Unknown:
        break;
    }
    return QIcon();
}