2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "taskwindow.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2009-11-11 09:54:13 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-01-23 13:03:36 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2008-12-03 21:50:31 +01:00
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
2010-01-08 13:10:04 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <texteditor/basetexteditor.h>
|
2009-11-11 09:54:13 +01:00
|
|
|
#include <texteditor/itexteditor.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QDir>
|
2009-11-11 09:54:13 +01:00
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
|
#include <QtGui/QClipboard>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QKeyEvent>
|
|
|
|
|
#include <QtGui/QListView>
|
|
|
|
|
#include <QtGui/QPainter>
|
2009-11-11 09:54:13 +01:00
|
|
|
#include <QtGui/QStyledItemDelegate>
|
2009-07-16 12:11:32 +02:00
|
|
|
#include <QtGui/QSortFilterProxyModel>
|
2009-11-11 09:54:13 +01:00
|
|
|
|
2010-02-19 13:06:28 +01:00
|
|
|
namespace {
|
|
|
|
|
const int TASK_ICON_SIZE = 16;
|
|
|
|
|
const int TASK_ICON_MARGIN = 2;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class TaskView : public QListView
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TaskView(QWidget *parent = 0);
|
|
|
|
|
~TaskView();
|
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
|
void keyPressEvent(QKeyEvent *e);
|
|
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
class TaskDelegate : public QStyledItemDelegate
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
TaskDelegate(QObject * parent = 0);
|
|
|
|
|
~TaskDelegate();
|
|
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
|
|
|
|
|
|
|
|
// TaskView uses this method if the size of the taskview changes
|
|
|
|
|
void emitSizeHintChanged(const QModelIndex &index);
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void generateGradientPixmap(int width, int height, QColor color, bool selected) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
class TaskWindowContext : public Core::IContext
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TaskWindowContext(QWidget *widget);
|
|
|
|
|
virtual QList<int> context() const;
|
|
|
|
|
virtual QWidget *widget();
|
|
|
|
|
private:
|
|
|
|
|
QWidget *m_taskList;
|
|
|
|
|
QList<int> m_context;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TaskModel : public QAbstractItemModel
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// Model stuff
|
|
|
|
|
TaskModel();
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
QModelIndex parent(const QModelIndex &child) const;
|
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
2009-11-11 09:54:13 +01:00
|
|
|
|
2009-11-11 12:36:44 +01:00
|
|
|
QStringList categoryIds() const;
|
|
|
|
|
QString categoryDisplayName(const QString &categoryId) const;
|
2009-11-11 09:54:13 +01:00
|
|
|
void addCategory(const QString &categoryId, const QString &categoryName);
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
QList<Task> tasks(const QString &categoryId = QString()) const;
|
|
|
|
|
void addTask(const Task &task);
|
2009-11-11 09:54:13 +01:00
|
|
|
void clearTasks(const QString &categoryId = QString());
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int sizeOfFile();
|
|
|
|
|
int sizeOfLineNumber();
|
|
|
|
|
void setFileNotFound(const QModelIndex &index, bool b);
|
|
|
|
|
|
2009-11-11 12:36:44 +01:00
|
|
|
enum Roles { File = Qt::UserRole, Line, Description, FileNotFound, Type, Category };
|
2009-03-27 13:37:24 +01:00
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
QIcon iconFor(Task::TaskType type);
|
2009-11-11 09:54:13 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
2009-11-11 09:54:13 +01:00
|
|
|
QHash<QString,QString> m_categories; // category id -> display name
|
2010-03-12 13:53:00 +01:00
|
|
|
QList<Task> m_tasks; // all tasks (in order of insertion)
|
|
|
|
|
QMap<QString,QList<Task> > m_tasksInCategory; // categoryId->tasks
|
2009-11-11 09:54:13 +01:00
|
|
|
|
|
|
|
|
QHash<QString,bool> m_fileNotFound;
|
2008-12-02 12:01:29 +01:00
|
|
|
int m_maxSizeOfFileName;
|
2009-03-27 13:37:24 +01:00
|
|
|
QIcon m_errorIcon;
|
|
|
|
|
QIcon m_warningIcon;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
class TaskFilterModel : public QSortFilterProxyModel
|
2009-07-16 12:11:32 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TaskFilterModel(TaskModel *sourceModel, QObject *parent = 0);
|
|
|
|
|
|
|
|
|
|
TaskModel *taskModel() const;
|
|
|
|
|
|
|
|
|
|
bool filterIncludesUnknowns() const { return m_includeUnknowns; }
|
|
|
|
|
void setFilterIncludesUnknowns(bool b) { m_includeUnknowns = b; invalidateFilter(); }
|
|
|
|
|
|
|
|
|
|
bool filterIncludesWarnings() const { return m_includeWarnings; }
|
|
|
|
|
void setFilterIncludesWarnings(bool b) { m_includeWarnings = b; invalidateFilter(); }
|
|
|
|
|
|
|
|
|
|
bool filterIncludesErrors() const { return m_includeErrors; }
|
|
|
|
|
void setFilterIncludesErrors(bool b) { m_includeErrors = b; invalidateFilter(); }
|
|
|
|
|
|
2009-11-11 12:36:44 +01:00
|
|
|
QStringList filteredCategories() const { return m_categoryIds; }
|
|
|
|
|
void setFilteredCategories(const QStringList &categoryIds) { m_categoryIds = categoryIds; invalidateFilter(); }
|
|
|
|
|
|
2009-07-16 12:11:32 +02:00
|
|
|
protected:
|
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_includeUnknowns;
|
|
|
|
|
bool m_includeWarnings;
|
|
|
|
|
bool m_includeErrors;
|
2009-11-11 12:36:44 +01:00
|
|
|
QStringList m_categoryIds;
|
2009-07-16 12:11:32 +02:00
|
|
|
};
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
} // Internal
|
|
|
|
|
} // ProjectExplorer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
////
|
|
|
|
|
// TaskView
|
|
|
|
|
////
|
|
|
|
|
|
|
|
|
|
TaskView::TaskView(QWidget *parent)
|
|
|
|
|
: QListView(parent)
|
|
|
|
|
{
|
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskView::~TaskView()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskView::resizeEvent(QResizeEvent *e)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(e)
|
2008-12-02 12:01:29 +01:00
|
|
|
static_cast<TaskDelegate *>(itemDelegate())->emitSizeHintChanged(selectionModel()->currentIndex());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskView::keyPressEvent(QKeyEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (!e->modifiers() && e->key() == Qt::Key_Return) {
|
|
|
|
|
emit activated(currentIndex());
|
|
|
|
|
e->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QListView::keyPressEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
// TaskModel
|
|
|
|
|
/////
|
|
|
|
|
|
|
|
|
|
TaskModel::TaskModel()
|
|
|
|
|
{
|
|
|
|
|
m_maxSizeOfFileName = 0;
|
2009-03-27 13:37:24 +01:00
|
|
|
m_errorIcon = QIcon(":/projectexplorer/images/compile_error.png");
|
|
|
|
|
m_warningIcon = QIcon(":/projectexplorer/images/compile_warning.png");
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
void TaskModel::addCategory(const QString &categoryId, const QString &categoryName)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(!categoryId.isEmpty());
|
|
|
|
|
m_categories.insert(categoryId, categoryName);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
QList<Task> TaskModel::tasks(const QString &categoryId) const
|
2009-11-11 09:54:13 +01:00
|
|
|
{
|
|
|
|
|
if (categoryId.isEmpty()) {
|
|
|
|
|
return m_tasks;
|
|
|
|
|
} else {
|
|
|
|
|
return m_tasksInCategory.value(categoryId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
void TaskModel::addTask(const Task &task)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
Q_ASSERT(m_categories.keys().contains(task.category));
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
QList<Task> tasksInCategory = m_tasksInCategory.value(task.category);
|
2009-11-11 09:54:13 +01:00
|
|
|
tasksInCategory.append(task);
|
|
|
|
|
m_tasksInCategory.insert(task.category, tasksInCategory);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
beginInsertRows(QModelIndex(), m_tasks.size(), m_tasks.size());
|
|
|
|
|
m_tasks.append(task);
|
2008-12-02 12:01:29 +01:00
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
|
|
QFont font;
|
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
|
QString filename = task.file;
|
2010-02-01 12:43:56 +01:00
|
|
|
const int pos = filename.lastIndexOf(QLatin1Char('/'));
|
2008-12-02 12:01:29 +01:00
|
|
|
if (pos != -1)
|
2009-11-11 09:54:13 +01:00
|
|
|
filename = task.file.mid(pos +1);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_maxSizeOfFileName = qMax(m_maxSizeOfFileName, fm.width(filename));
|
|
|
|
|
}
|
2009-11-11 09:54:13 +01:00
|
|
|
//
|
|
|
|
|
//void TaskModel::removeTask(const ITaskWindow::Task &task)
|
|
|
|
|
//{
|
|
|
|
|
// Q_ASSERT(m_tasks.contains(task));
|
|
|
|
|
// int index = m_tasks.indexOf(task);
|
|
|
|
|
// beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
|
// m_tasks.removeAt(index);
|
|
|
|
|
// endRemoveRows();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
void TaskModel::clearTasks(const QString &categoryId)
|
|
|
|
|
{
|
|
|
|
|
if (categoryId.isEmpty()) {
|
|
|
|
|
if (m_tasks.size() == 0)
|
|
|
|
|
return;
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, m_tasks.size() -1);
|
|
|
|
|
m_tasks.clear();
|
|
|
|
|
m_tasksInCategory.clear();
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
m_maxSizeOfFileName = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// TODO: Optimize this for consecutive rows
|
2010-03-12 13:53:00 +01:00
|
|
|
foreach (const Task &task, m_tasksInCategory.value(categoryId)) {
|
2009-11-11 09:54:13 +01:00
|
|
|
int index = m_tasks.indexOf(task);
|
|
|
|
|
Q_ASSERT(index >= 0);
|
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
m_tasks.removeAt(index);
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
QList<Task> tasksInCategory = m_tasksInCategory.value(categoryId);
|
2009-11-11 09:54:13 +01:00
|
|
|
tasksInCategory.removeOne(task);
|
|
|
|
|
m_tasksInCategory.insert(categoryId, tasksInCategory);
|
|
|
|
|
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// what to do with m_maxSizeOfFileName ?
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QModelIndex TaskModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent.isValid())
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
return createIndex(row, column, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex TaskModel::parent(const QModelIndex &child) const
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(child)
|
2008-12-02 12:01:29 +01:00
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
return parent.isValid() ? 0 : m_tasks.count();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant TaskModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
if (!index.isValid() || index.row() >= m_tasks.size() || index.column() != 0)
|
2008-12-02 12:01:29 +01:00
|
|
|
return QVariant();
|
|
|
|
|
|
2009-11-11 14:08:48 +01:00
|
|
|
if (role == TaskModel::File) {
|
2009-11-11 09:54:13 +01:00
|
|
|
return m_tasks.at(index.row()).file;
|
2009-11-11 14:08:48 +01:00
|
|
|
} else if (role == TaskModel::Line) {
|
|
|
|
|
if (m_tasks.at(index.row()).line <= 0)
|
|
|
|
|
return QVariant();
|
|
|
|
|
else
|
|
|
|
|
return m_tasks.at(index.row()).line;
|
|
|
|
|
} else if (role == TaskModel::Description) {
|
2009-11-11 09:54:13 +01:00
|
|
|
return m_tasks.at(index.row()).description;
|
2009-11-11 14:08:48 +01:00
|
|
|
} else if (role == TaskModel::FileNotFound) {
|
2009-11-11 09:54:13 +01:00
|
|
|
return m_fileNotFound.value(m_tasks.at(index.row()).file);
|
2009-11-11 14:08:48 +01:00
|
|
|
} else if (role == TaskModel::Type) {
|
2009-11-11 09:54:13 +01:00
|
|
|
return (int)m_tasks.at(index.row()).type;
|
2009-11-11 14:08:48 +01:00
|
|
|
} else if (role == TaskModel::Category) {
|
2009-11-11 12:36:44 +01:00
|
|
|
return m_tasks.at(index.row()).category;
|
2009-11-11 14:08:48 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 12:36:44 +01:00
|
|
|
QStringList TaskModel::categoryIds() const
|
|
|
|
|
{
|
|
|
|
|
return m_categories.keys();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TaskModel::categoryDisplayName(const QString &categoryId) const
|
|
|
|
|
{
|
|
|
|
|
return m_categories.value(categoryId);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
QIcon TaskModel::iconFor(Task::TaskType type)
|
2009-03-27 13:37:24 +01:00
|
|
|
{
|
2010-03-12 13:53:00 +01:00
|
|
|
if (type == Task::Error)
|
2009-03-27 13:37:24 +01:00
|
|
|
return m_errorIcon;
|
2010-03-12 13:53:00 +01:00
|
|
|
else if (type == Task::Warning)
|
2009-03-27 13:37:24 +01:00
|
|
|
return m_warningIcon;
|
|
|
|
|
else
|
2010-03-10 12:08:34 +01:00
|
|
|
return QIcon();
|
2009-03-27 13:37:24 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int TaskModel::sizeOfFile()
|
|
|
|
|
{
|
|
|
|
|
return m_maxSizeOfFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::sizeOfLineNumber()
|
|
|
|
|
{
|
|
|
|
|
QFont font;
|
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
|
return fm.width("8888");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskModel::setFileNotFound(const QModelIndex &idx, bool b)
|
|
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
if (idx.isValid() && idx.row() < m_tasks.size()) {
|
|
|
|
|
m_fileNotFound.insert(m_tasks[idx.row()].file, b);
|
2008-12-02 12:01:29 +01:00
|
|
|
emit dataChanged(idx, idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 12:11:32 +02:00
|
|
|
/////
|
|
|
|
|
// TaskFilterModel
|
|
|
|
|
/////
|
|
|
|
|
|
|
|
|
|
TaskFilterModel::TaskFilterModel(TaskModel *sourceModel, QObject *parent)
|
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
|
{
|
|
|
|
|
setSourceModel(sourceModel);
|
|
|
|
|
setDynamicSortFilter(true);
|
|
|
|
|
m_includeUnknowns = m_includeWarnings = m_includeErrors = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskModel *TaskFilterModel::taskModel() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<TaskModel*>(sourceModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
|
{
|
2009-11-11 12:36:44 +01:00
|
|
|
bool accept = true;
|
|
|
|
|
|
2009-07-16 12:11:32 +02:00
|
|
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
2010-03-12 13:53:00 +01:00
|
|
|
Task::TaskType type = Task::TaskType(index.data(TaskModel::Type).toInt());
|
2009-07-16 12:11:32 +02:00
|
|
|
switch (type) {
|
2010-03-12 13:53:00 +01:00
|
|
|
case Task::Unknown:
|
2009-11-11 12:36:44 +01:00
|
|
|
accept = m_includeUnknowns;
|
|
|
|
|
break;
|
2010-03-12 13:53:00 +01:00
|
|
|
case Task::Warning:
|
2009-11-11 12:36:44 +01:00
|
|
|
accept = m_includeWarnings;
|
|
|
|
|
break;
|
2010-03-12 13:53:00 +01:00
|
|
|
case Task::Error:
|
2009-11-11 12:36:44 +01:00
|
|
|
accept = m_includeErrors;
|
|
|
|
|
break;
|
2009-07-16 12:11:32 +02:00
|
|
|
}
|
|
|
|
|
|
2009-11-11 12:36:44 +01:00
|
|
|
const QString &categoryId = index.data(TaskModel::Category).toString();
|
|
|
|
|
if (m_categoryIds.contains(categoryId))
|
|
|
|
|
accept = false;
|
|
|
|
|
|
|
|
|
|
return accept;
|
2009-07-16 12:11:32 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/////
|
|
|
|
|
// TaskWindow
|
|
|
|
|
/////
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
static QToolButton *createFilterButton(Task::TaskType type,
|
2009-07-16 12:11:32 +02:00
|
|
|
const QString &toolTip, TaskModel *model,
|
|
|
|
|
QObject *receiver, const char *slot)
|
|
|
|
|
{
|
|
|
|
|
QToolButton *button = new QToolButton;
|
|
|
|
|
button->setIcon(model->iconFor(type));
|
|
|
|
|
button->setToolTip(toolTip);
|
|
|
|
|
button->setCheckable(true);
|
|
|
|
|
button->setChecked(true);
|
|
|
|
|
button->setAutoRaise(true);
|
|
|
|
|
button->setEnabled(true);
|
|
|
|
|
QObject::connect(button, SIGNAL(toggled(bool)), receiver, slot);
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
TaskWindow::TaskWindow()
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_model = new TaskModel;
|
2009-07-16 12:11:32 +02:00
|
|
|
m_filter = new TaskFilterModel(m_model);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_listview = new TaskView;
|
|
|
|
|
|
2009-07-16 12:11:32 +02:00
|
|
|
m_listview->setModel(m_filter);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_listview->setFrameStyle(QFrame::NoFrame);
|
2008-12-09 17:04:50 +01:00
|
|
|
m_listview->setWindowTitle(tr("Build Issues"));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_listview->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
TaskDelegate *tld = new TaskDelegate(this);
|
|
|
|
|
m_listview->setItemDelegate(tld);
|
|
|
|
|
m_listview->setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
|
2008-12-03 21:50:31 +01:00
|
|
|
m_listview->setContextMenuPolicy(Qt::ActionsContextMenu);
|
2009-01-30 17:09:09 +01:00
|
|
|
m_listview->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2008-12-03 21:50:31 +01:00
|
|
|
|
|
|
|
|
m_taskWindowContext = new TaskWindowContext(m_listview);
|
2009-01-20 11:52:04 +01:00
|
|
|
core->addContextObject(m_taskWindowContext);
|
2008-12-03 21:50:31 +01:00
|
|
|
|
|
|
|
|
m_copyAction = new QAction(QIcon(Core::Constants::ICON_COPY), tr("&Copy"), this);
|
2010-01-08 13:10:04 +01:00
|
|
|
Core::Command *command = core->actionManager()->
|
2008-12-03 21:50:31 +01:00
|
|
|
registerAction(m_copyAction, Core::Constants::COPY, m_taskWindowContext->context());
|
2010-01-08 13:10:04 +01:00
|
|
|
m_listview->addAction(command->action());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(m_listview->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
|
|
|
|
tld, SLOT(currentChanged(const QModelIndex &, const QModelIndex &)));
|
|
|
|
|
|
|
|
|
|
connect(m_listview, SIGNAL(activated(const QModelIndex &)),
|
|
|
|
|
this, SLOT(showTaskInFile(const QModelIndex &)));
|
|
|
|
|
connect(m_listview, SIGNAL(clicked(const QModelIndex &)),
|
|
|
|
|
this, SLOT(showTaskInFile(const QModelIndex &)));
|
|
|
|
|
|
2008-12-03 21:50:31 +01:00
|
|
|
connect(m_copyAction, SIGNAL(triggered()), SLOT(copy()));
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
m_filterWarningsButton = createFilterButton(Task::Warning,
|
2009-07-16 12:11:32 +02:00
|
|
|
tr("Show Warnings"), m_model,
|
|
|
|
|
this, SLOT(setShowWarnings(bool)));
|
|
|
|
|
|
2009-11-11 12:36:44 +01:00
|
|
|
m_categoriesMenu = new QMenu;
|
|
|
|
|
connect(m_categoriesMenu, SIGNAL(aboutToShow()), this, SLOT(updateCategoriesMenu()));
|
|
|
|
|
connect(m_categoriesMenu, SIGNAL(triggered(QAction*)), this, SLOT(filterCategoryTriggered(QAction*)));
|
|
|
|
|
|
|
|
|
|
m_categoriesButton = new QToolButton;
|
2009-11-16 12:41:24 +01:00
|
|
|
m_categoriesButton->setIcon(QIcon(":/projectexplorer/images/filtericon.png"));
|
2009-11-11 12:36:44 +01:00
|
|
|
m_categoriesButton->setToolTip(tr("Filter by categories"));
|
|
|
|
|
m_categoriesButton->setAutoRaise(true);
|
|
|
|
|
m_categoriesButton->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
|
m_categoriesButton->setMenu(m_categoriesMenu);
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
qRegisterMetaType<ProjectExplorer::Task>("ProjectExplorer::Task");
|
|
|
|
|
qRegisterMetaType<QList<ProjectExplorer::Task> >("QList<ProjectExplorer::Task>");
|
2009-11-12 15:54:45 +01:00
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
updateActions();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskWindow::~TaskWindow()
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ICore::instance()->removeContextObject(m_taskWindowContext);
|
2009-07-16 12:11:32 +02:00
|
|
|
delete m_filterWarningsButton;
|
2008-12-02 12:01:29 +01:00
|
|
|
delete m_listview;
|
2009-07-16 12:11:32 +02:00
|
|
|
delete m_filter;
|
2008-12-02 12:01:29 +01:00
|
|
|
delete m_model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QWidget*> TaskWindow::toolBarWidgets() const
|
|
|
|
|
{
|
2009-11-11 12:36:44 +01:00
|
|
|
return QList<QWidget*>() << m_filterWarningsButton << m_categoriesButton;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *TaskWindow::outputWidget(QWidget *)
|
|
|
|
|
{
|
|
|
|
|
return m_listview;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
void TaskWindow::clearTasks(const QString &categoryId)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
m_model->clearTasks(categoryId);
|
|
|
|
|
|
|
|
|
|
updateActions();
|
2008-12-02 12:01:29 +01:00
|
|
|
emit tasksChanged();
|
2009-04-30 12:50:52 +02:00
|
|
|
navigateStateChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskWindow::visibilityChanged(bool /* b */)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
void TaskWindow::addCategory(const QString &categoryId, const QString &displayName)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(!categoryId.isEmpty());
|
|
|
|
|
m_model->addCategory(categoryId, displayName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskWindow::addTask(const Task &task)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
m_model->addTask(task);
|
|
|
|
|
|
|
|
|
|
updateActions();
|
2008-12-02 12:01:29 +01:00
|
|
|
emit tasksChanged();
|
2009-11-11 09:54:13 +01:00
|
|
|
navigateStateChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskWindow::showTaskInFile(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return;
|
|
|
|
|
QString file = index.data(TaskModel::File).toString();
|
|
|
|
|
int line = index.data(TaskModel::Line).toInt();
|
|
|
|
|
if (file.isEmpty() || line == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
2009-03-12 11:25:29 +01:00
|
|
|
QFileInfo fi(file);
|
|
|
|
|
if (fi.exists()) {
|
|
|
|
|
TextEditor::BaseTextEditor::openEditorAt(fi.canonicalFilePath(), line);
|
2008-12-02 17:57:50 +01:00
|
|
|
Core::EditorManager::instance()->ensureEditorManagerVisible();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
else
|
|
|
|
|
m_model->setFileNotFound(index, true);
|
|
|
|
|
m_listview->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
|
|
|
|
|
m_listview->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-03 21:50:31 +01:00
|
|
|
void TaskWindow::copy()
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_listview->selectionModel()->currentIndex();
|
|
|
|
|
QString file = index.data(TaskModel::File).toString();
|
|
|
|
|
QString line = index.data(TaskModel::Line).toString();
|
|
|
|
|
QString description = index.data(TaskModel::Description).toString();
|
|
|
|
|
QString type;
|
|
|
|
|
switch (index.data(TaskModel::Type).toInt()) {
|
2010-03-12 13:53:00 +01:00
|
|
|
case Task::Error:
|
2008-12-03 21:50:31 +01:00
|
|
|
type = "error: ";
|
|
|
|
|
break;
|
2010-03-12 13:53:00 +01:00
|
|
|
case Task::Warning:
|
2008-12-03 21:50:31 +01:00
|
|
|
type = "warning: ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(file + ':' + line + ": " + type + description);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 12:11:32 +02:00
|
|
|
void TaskWindow::setShowWarnings(bool show)
|
|
|
|
|
{
|
|
|
|
|
m_filter->setFilterIncludesWarnings(show);
|
|
|
|
|
m_filter->setFilterIncludesUnknowns(show); // "Unknowns" are often associated with warnings
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 12:36:44 +01:00
|
|
|
void TaskWindow::updateCategoriesMenu()
|
|
|
|
|
{
|
|
|
|
|
m_categoriesMenu->clear();
|
|
|
|
|
|
|
|
|
|
const QStringList filteredCategories = m_filter->filteredCategories();
|
|
|
|
|
|
|
|
|
|
foreach (const QString &categoryId, m_model->categoryIds()) {
|
|
|
|
|
const QString categoryName = m_model->categoryDisplayName(categoryId);
|
|
|
|
|
|
|
|
|
|
QAction *action = new QAction(m_categoriesMenu);
|
|
|
|
|
action->setCheckable(true);
|
|
|
|
|
action->setText(categoryName);
|
|
|
|
|
action->setData(categoryId);
|
|
|
|
|
action->setChecked(!filteredCategories.contains(categoryId));
|
|
|
|
|
|
|
|
|
|
m_categoriesMenu->addAction(action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskWindow::filterCategoryTriggered(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
QString categoryId = action->data().toString();
|
|
|
|
|
Q_ASSERT(!categoryId.isEmpty());
|
|
|
|
|
|
|
|
|
|
QStringList categories = m_filter->filteredCategories();
|
|
|
|
|
Q_ASSERT(m_filter->filteredCategories().contains(categoryId) == action->isChecked());
|
|
|
|
|
|
|
|
|
|
if (action->isChecked()) {
|
|
|
|
|
categories.removeOne(categoryId);
|
|
|
|
|
} else {
|
|
|
|
|
categories.append(categoryId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_filter->setFilteredCategories(categories);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
int TaskWindow::taskCount(const QString &categoryId) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
return m_model->tasks(categoryId).count();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
int TaskWindow::errorTaskCount(const QString &categoryId) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-11 09:54:13 +01:00
|
|
|
int errorTaskCount = 0;
|
|
|
|
|
|
|
|
|
|
foreach (const Task &task, m_model->tasks(categoryId)) {
|
2010-03-12 13:53:00 +01:00
|
|
|
if (task.type == Task::Error)
|
2009-11-11 09:54:13 +01:00
|
|
|
++ errorTaskCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errorTaskCount;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskWindow::priorityInStatusBar() const
|
|
|
|
|
{
|
|
|
|
|
return 90;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
void TaskWindow::clearContents()
|
|
|
|
|
{
|
|
|
|
|
clearTasks();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool TaskWindow::hasFocus()
|
|
|
|
|
{
|
|
|
|
|
return m_listview->hasFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskWindow::canFocus()
|
|
|
|
|
{
|
2009-07-16 12:11:32 +02:00
|
|
|
return m_filter->rowCount();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskWindow::setFocus()
|
|
|
|
|
{
|
2009-07-16 12:11:32 +02:00
|
|
|
if (m_filter->rowCount()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
m_listview->setFocus();
|
|
|
|
|
if (m_listview->currentIndex() == QModelIndex()) {
|
2009-07-16 12:11:32 +02:00
|
|
|
m_listview->setCurrentIndex(m_filter->index(0,0, QModelIndex()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-30 12:50:52 +02:00
|
|
|
bool TaskWindow::canNext()
|
|
|
|
|
{
|
2009-07-16 12:11:32 +02:00
|
|
|
return m_filter->rowCount();
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskWindow::canPrevious()
|
|
|
|
|
{
|
2009-07-16 12:11:32 +02:00
|
|
|
return m_filter->rowCount();
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskWindow::goToNext()
|
|
|
|
|
{
|
2009-07-16 12:11:32 +02:00
|
|
|
if (!m_filter->rowCount())
|
2009-04-30 12:50:52 +02:00
|
|
|
return;
|
|
|
|
|
QModelIndex currentIndex = m_listview->currentIndex();
|
|
|
|
|
if (currentIndex.isValid()) {
|
|
|
|
|
int row = currentIndex.row() + 1;
|
2009-07-16 12:11:32 +02:00
|
|
|
if (row == m_filter->rowCount())
|
2009-04-30 12:50:52 +02:00
|
|
|
row = 0;
|
2009-07-16 12:11:32 +02:00
|
|
|
currentIndex = m_filter->index(row, 0);
|
2009-04-30 12:50:52 +02:00
|
|
|
} else {
|
2009-07-16 12:11:32 +02:00
|
|
|
currentIndex = m_filter->index(0, 0);
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
m_listview->setCurrentIndex(currentIndex);
|
|
|
|
|
showTaskInFile(currentIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskWindow::goToPrev()
|
|
|
|
|
{
|
2009-07-16 12:11:32 +02:00
|
|
|
if (!m_filter->rowCount())
|
2009-04-30 12:50:52 +02:00
|
|
|
return;
|
|
|
|
|
QModelIndex currentIndex = m_listview->currentIndex();
|
|
|
|
|
if (currentIndex.isValid()) {
|
|
|
|
|
int row = currentIndex.row() -1;
|
|
|
|
|
if (row < 0)
|
2009-07-16 12:11:32 +02:00
|
|
|
row = m_filter->rowCount() - 1;
|
|
|
|
|
currentIndex = m_filter->index(row, 0);
|
2009-04-30 12:50:52 +02:00
|
|
|
} else {
|
2009-07-16 12:11:32 +02:00
|
|
|
currentIndex = m_filter->index(m_filter->rowCount()-1, 0);
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
m_listview->setCurrentIndex(currentIndex);
|
|
|
|
|
showTaskInFile(currentIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskWindow::canNavigate()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
void TaskWindow::updateActions()
|
|
|
|
|
{
|
|
|
|
|
m_copyAction->setEnabled(m_model->tasks().count() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/////
|
|
|
|
|
// Delegate
|
|
|
|
|
/////
|
|
|
|
|
|
|
|
|
|
TaskDelegate::TaskDelegate(QObject *parent)
|
|
|
|
|
: QStyledItemDelegate(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskDelegate::~TaskDelegate()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize TaskDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QStyleOptionViewItemV4 opt = option;
|
|
|
|
|
initStyleOption(&opt, index);
|
|
|
|
|
|
|
|
|
|
QFontMetrics fm(option.font);
|
2009-03-27 13:37:24 +01:00
|
|
|
int fontHeight = fm.height();
|
|
|
|
|
int fontLeading = fm.leading();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QSize s;
|
|
|
|
|
s.setWidth(option.rect.width());
|
|
|
|
|
const QAbstractItemView * view = qobject_cast<const QAbstractItemView *>(opt.widget);
|
2009-07-16 12:11:32 +02:00
|
|
|
TaskModel *model = static_cast<TaskFilterModel *>(view->model())->taskModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
int width = opt.rect.width() - model->sizeOfFile() - model->sizeOfLineNumber() - 12 - 22;
|
|
|
|
|
if (view->selectionModel()->currentIndex() == index) {
|
|
|
|
|
QString description = index.data(TaskModel::Description).toString();
|
|
|
|
|
// Layout the description
|
2009-03-27 13:37:24 +01:00
|
|
|
int leading = fontLeading;
|
2008-12-02 12:01:29 +01:00
|
|
|
int height = 0;
|
|
|
|
|
QTextLayout tl(description);
|
|
|
|
|
tl.beginLayout();
|
2008-12-09 11:07:24 +01:00
|
|
|
while (true) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QTextLine line = tl.createLine();
|
|
|
|
|
if (!line.isValid())
|
|
|
|
|
break;
|
|
|
|
|
line.setLineWidth(width);
|
|
|
|
|
height += leading;
|
|
|
|
|
line.setPosition(QPoint(0, height));
|
|
|
|
|
height += static_cast<int>(line.height());
|
|
|
|
|
}
|
|
|
|
|
tl.endLayout();
|
|
|
|
|
|
2009-03-27 13:37:24 +01:00
|
|
|
s.setHeight(height + leading + fontHeight + 3);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2009-03-27 13:37:24 +01:00
|
|
|
s.setHeight(fontHeight + 3);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-02-19 13:06:28 +01:00
|
|
|
if (s.height() < TASK_ICON_SIZE + 2 * TASK_ICON_MARGIN)
|
|
|
|
|
s.setHeight(TASK_ICON_SIZE + 2 * TASK_ICON_MARGIN);
|
2008-12-02 12:01:29 +01:00
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskDelegate::emitSizeHintChanged(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
emit sizeHintChanged(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskDelegate::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
|
{
|
|
|
|
|
emit sizeHintChanged(current);
|
|
|
|
|
emit sizeHintChanged(previous);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QStyleOptionViewItemV4 opt = option;
|
|
|
|
|
initStyleOption(&opt, index);
|
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
|
|
QFontMetrics fm(opt.font);
|
|
|
|
|
QColor backgroundColor;
|
|
|
|
|
QColor textColor;
|
|
|
|
|
|
|
|
|
|
const QAbstractItemView * view = qobject_cast<const QAbstractItemView *>(opt.widget);
|
|
|
|
|
bool selected = view->selectionModel()->currentIndex() == index;
|
|
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
|
painter->setBrush(opt.palette.highlight().color());
|
|
|
|
|
backgroundColor = opt.palette.highlight().color();
|
|
|
|
|
} else {
|
|
|
|
|
painter->setBrush(opt.palette.background().color());
|
|
|
|
|
backgroundColor = opt.palette.background().color();
|
|
|
|
|
}
|
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
|
painter->drawRect(opt.rect);
|
|
|
|
|
|
|
|
|
|
// Set Text Color
|
|
|
|
|
if (selected)
|
|
|
|
|
textColor = opt.palette.highlightedText().color();
|
|
|
|
|
else
|
|
|
|
|
textColor = opt.palette.text().color();
|
|
|
|
|
|
|
|
|
|
painter->setPen(textColor);
|
|
|
|
|
|
2009-07-16 12:11:32 +02:00
|
|
|
TaskModel *model = static_cast<TaskFilterModel *>(view->model())->taskModel();
|
2010-03-12 13:53:00 +01:00
|
|
|
Task::TaskType type = Task::TaskType(index.data(TaskModel::Type).toInt());
|
2009-03-27 13:37:24 +01:00
|
|
|
QIcon icon = model->iconFor(type);
|
2010-02-19 13:06:28 +01:00
|
|
|
painter->drawPixmap(TASK_ICON_MARGIN, opt.rect.top() + TASK_ICON_MARGIN, icon.pixmap(TASK_ICON_SIZE, TASK_ICON_SIZE));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int width = opt.rect.width() - model->sizeOfFile() - model->sizeOfLineNumber() - 12 - 22;
|
2010-01-29 21:33:57 +01:00
|
|
|
if (!selected) {
|
2008-12-02 12:01:29 +01:00
|
|
|
// in small mode we lay out differently
|
|
|
|
|
QString bottom = index.data(TaskModel::Description).toString();
|
|
|
|
|
painter->drawText(22, 2 + opt.rect.top() + fm.ascent(), bottom);
|
|
|
|
|
if (fm.width(bottom) > width) {
|
|
|
|
|
// draw a gradient to mask the text
|
|
|
|
|
int gwidth = opt.rect.right() - width;
|
|
|
|
|
QLinearGradient lg(QPoint(width, 0), QPoint(width+gwidth, 0));
|
|
|
|
|
QColor c = backgroundColor;
|
|
|
|
|
c.setAlpha(0);
|
|
|
|
|
lg.setColorAt(0, c);
|
|
|
|
|
lg.setColorAt(20.0/gwidth, backgroundColor);
|
|
|
|
|
painter->fillRect(width, 2 + opt.rect.top(), gwidth, fm.height() + 1, lg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2008-12-03 21:50:31 +01:00
|
|
|
// Description
|
2008-12-02 12:01:29 +01:00
|
|
|
QString description = index.data(TaskModel::Description).toString();
|
|
|
|
|
// Layout the description
|
|
|
|
|
int leading = fm.leading();
|
|
|
|
|
int height = 0;
|
|
|
|
|
QTextLayout tl(description);
|
|
|
|
|
tl.beginLayout();
|
2008-12-09 11:07:24 +01:00
|
|
|
while (true) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QTextLine line = tl.createLine();
|
|
|
|
|
if (!line.isValid())
|
|
|
|
|
break;
|
|
|
|
|
line.setLineWidth(width);
|
|
|
|
|
height += leading;
|
|
|
|
|
line.setPosition(QPoint(0, height));
|
|
|
|
|
height += static_cast<int>(line.height());
|
|
|
|
|
}
|
|
|
|
|
tl.endLayout();
|
|
|
|
|
tl.draw(painter, QPoint(22, 2 + opt.rect.top()));
|
|
|
|
|
//painter->drawText(22, 2 + opt.rect.top() + fm.ascent(), description);
|
|
|
|
|
|
|
|
|
|
QColor mix;
|
|
|
|
|
mix.setRgb( static_cast<int>(0.7 * textColor.red() + 0.3 * backgroundColor.red()),
|
|
|
|
|
static_cast<int>(0.7 * textColor.green() + 0.3 * backgroundColor.green()),
|
|
|
|
|
static_cast<int>(0.7 * textColor.blue() + 0.3 * backgroundColor.blue()));
|
|
|
|
|
painter->setPen(mix);
|
|
|
|
|
|
2009-04-15 16:34:37 +02:00
|
|
|
const QString directory = QDir::toNativeSeparators(index.data(TaskModel::File).toString());
|
2008-12-02 12:01:29 +01:00
|
|
|
int secondBaseLine = 2 + fm.ascent() + opt.rect.top() + height + leading; //opt.rect.top() + fm.ascent() + fm.height() + 6;
|
|
|
|
|
if (index.data(TaskModel::FileNotFound).toBool()) {
|
|
|
|
|
QString fileNotFound = tr("File not found: %1").arg(directory);
|
|
|
|
|
painter->setPen(Qt::red);
|
|
|
|
|
painter->drawText(22, secondBaseLine, fileNotFound);
|
|
|
|
|
} else {
|
|
|
|
|
painter->drawText(22, secondBaseLine, directory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->setPen(textColor);
|
|
|
|
|
// Assemble string for the right side
|
|
|
|
|
// just filename + linenumer
|
|
|
|
|
QString file = index.data(TaskModel::File).toString();
|
2010-02-01 12:43:56 +01:00
|
|
|
const int pos = file.lastIndexOf(QLatin1Char('/'));
|
2008-12-02 12:01:29 +01:00
|
|
|
if (pos != -1)
|
|
|
|
|
file = file.mid(pos +1);
|
|
|
|
|
painter->drawText(width + 22 + 4, 2 + opt.rect.top() + fm.ascent(), file);
|
|
|
|
|
|
|
|
|
|
QString topRight = index.data(TaskModel::Line).toString();
|
|
|
|
|
painter->drawText(opt.rect.right() - fm.width(topRight) - 6 , 2 + opt.rect.top() + fm.ascent(), topRight);
|
|
|
|
|
// Separator lines
|
|
|
|
|
painter->setPen(QColor::fromRgb(150,150,150));
|
|
|
|
|
painter->drawLine(0, opt.rect.bottom(), opt.rect.right(), opt.rect.bottom());
|
|
|
|
|
painter->restore();
|
|
|
|
|
}
|
2008-12-03 21:50:31 +01:00
|
|
|
|
|
|
|
|
TaskWindowContext::TaskWindowContext(QWidget *widget)
|
2009-01-30 14:32:28 +01:00
|
|
|
: Core::IContext(widget), m_taskList(widget)
|
2008-12-03 21:50:31 +01:00
|
|
|
{
|
2009-01-21 15:52:34 +01:00
|
|
|
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
|
|
|
|
|
m_context << uidm->uniqueIdentifier(Core::Constants::C_PROBLEM_PANE);
|
2008-12-03 21:50:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<int> TaskWindowContext::context() const
|
|
|
|
|
{
|
|
|
|
|
return m_context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *TaskWindowContext::widget()
|
|
|
|
|
{
|
|
|
|
|
return m_taskList;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 09:54:13 +01:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// functions
|
|
|
|
|
//
|
2010-03-12 13:53:00 +01:00
|
|
|
bool ProjectExplorer::operator==(const Task &t1, const Task &t2)
|
2009-11-11 09:54:13 +01:00
|
|
|
{
|
|
|
|
|
return t1.type == t2.type
|
|
|
|
|
&& t1.line == t2.line
|
|
|
|
|
&& t1.description == t2.description
|
|
|
|
|
&& t1.file == t2.file
|
|
|
|
|
&& t1.category == t2.category;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
uint ProjectExplorer::qHash(const Task &task)
|
2009-11-11 09:54:13 +01:00
|
|
|
{
|
|
|
|
|
return qHash(task.file) + task.line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "taskwindow.moc"
|