taskhub.cpp 4.71 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

32
#include <coreplugin/ioutputpane.h>
33
#include <utils/qtcassert.h>
dt's avatar
dt committed
34 35 36

using namespace ProjectExplorer;

37
TaskHub *m_instance = 0;
38

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

48
    bool isClickable() const;
49 50
    void clicked();

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

void TaskMark::updateLineNumber(int lineNumber)
{
60
    TaskHub::updateTaskLineNumber(m_id, lineNumber);
61
    BaseTextMark::updateLineNumber(lineNumber);
62 63
}

64 65
void TaskMark::updateFileName(const QString &fileName)
{
66
    TaskHub::updateTaskFileName(m_id, fileName);
67 68 69
    BaseTextMark::updateFileName(fileName);
}

70 71
void TaskMark::removedFromEditor()
{
72
    TaskHub::updateTaskLineNumber(m_id, -1);
73 74
}

75
bool TaskMark::isClickable() const
76 77 78 79 80 81
{
    return true;
}

void TaskMark::clicked()
{
82
    TaskHub::taskMarkClicked(m_id);
83 84
}

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

TaskHub::~TaskHub()
{
96
    m_instance = 0;
dt's avatar
dt committed
97 98
}

hjk's avatar
hjk committed
99
void TaskHub::addCategory(Core::Id categoryId, const QString &displayName, bool visible)
dt's avatar
dt committed
100
{
101
    QTC_CHECK(!displayName.isEmpty());
102
    emit m_instance->categoryAdded(categoryId, displayName, visible);
dt's avatar
dt committed
103 104
}

105
QObject *TaskHub::instance()
106 107 108 109
{
    return m_instance;
}

110 111 112 113 114
void TaskHub::addTask(Task::TaskType type, const QString &description, Core::Id category, const Utils::FileName &file, int line)
{
    addTask(Task(type, description, file, line, category));
}

115
void TaskHub::addTask(Task task)
dt's avatar
dt committed
116
{
117
    if (task.line != -1 && !task.file.isEmpty()) {
118 119
        bool visible = (task.type == Task::Warning || task.type == Task::Error);
        TaskMark *mark = new TaskMark(task.taskId, task.file.toString(), task.line, visible);
Petar Perisin's avatar
Petar Perisin committed
120
        mark->setIcon(task.icon);
121
        mark->setPriority(TextEditor::ITextMark::LowPriority);
122
        task.addMark(mark);
123
        emit m_instance->taskAdded(task);
124 125
        mark->init();
    } else {
126
        emit m_instance->taskAdded(task);
127
    }
dt's avatar
dt committed
128 129
}

hjk's avatar
hjk committed
130
void TaskHub::clearTasks(Core::Id categoryId)
dt's avatar
dt committed
131
{
132
    emit m_instance->tasksCleared(categoryId);
dt's avatar
dt committed
133 134 135 136
}

void TaskHub::removeTask(const Task &task)
{
137
    emit m_instance->taskRemoved(task);
dt's avatar
dt committed
138 139
}

140 141
void TaskHub::updateTaskFileName(unsigned int id, const QString &fileName)
{
142
    emit m_instance->taskFileNameUpdated(id, fileName);
143 144
}

145 146
void TaskHub::updateTaskLineNumber(unsigned int id, int line)
{
147
    emit m_instance->taskLineNumberUpdated(id, line);
148 149
}

150 151
void TaskHub::taskMarkClicked(unsigned int id)
{
152
    emit m_instance->showTask(id);
153 154
}

155 156
void TaskHub::showTaskInEditor(unsigned int id)
{
157
    emit m_instance->openTask(id);
158 159
}

160
void TaskHub::setCategoryVisibility(const Core::Id &categoryId, bool visible)
161
{
162
    emit m_instance->categoryVisibilityChanged(categoryId, visible);
163 164
}

165
void TaskHub::requestPopup()
166
{
167
    emit m_instance->popupRequested(Core::IOutputPane::NoModeSwitch);
168 169
}