forked from qt-creator/qt-creator
Task, adjust line numbers while editing
Change-Id: Id2aa3b6f25a17416bb8ea601b6f5dd0de45f5375 Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
@@ -57,7 +57,7 @@ bool ShowInEditorTaskHandler::canHandle(const ProjectExplorer::Task &task)
|
||||
void ShowInEditorTaskHandler::handle(const ProjectExplorer::Task &task)
|
||||
{
|
||||
QFileInfo fi(task.file.toFileInfo());
|
||||
TextEditor::BaseTextEditorWidget::openEditorAt(fi.canonicalFilePath(), task.line);
|
||||
TextEditor::BaseTextEditorWidget::openEditorAt(fi.canonicalFilePath(), task.movedLine);
|
||||
}
|
||||
|
||||
QAction *ShowInEditorTaskHandler::createAction(QObject *parent)
|
||||
|
||||
@@ -51,11 +51,16 @@ Task::Task() : taskId(0), type(Unknown), line(-1)
|
||||
Task::Task(TaskType type_, const QString &description_,
|
||||
const Utils::FileName &file_, int line_, const Core::Id &category_) :
|
||||
taskId(s_nextId), type(type_), description(description_),
|
||||
file(file_), line(line_), category(category_)
|
||||
file(file_), line(line_), movedLine(line_), category(category_)
|
||||
{
|
||||
++s_nextId;
|
||||
}
|
||||
|
||||
void Task::addMark(TextEditor::BaseTextMark *mark)
|
||||
{
|
||||
m_mark = QSharedPointer<TextEditor::BaseTextMark>(mark);
|
||||
}
|
||||
|
||||
bool Task::isNull() const
|
||||
{ return taskId == 0; }
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "projectexplorer_export.h"
|
||||
|
||||
#include <coreplugin/id.h>
|
||||
#include <texteditor/basetextmark.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QtCore/QMetaType>
|
||||
@@ -65,7 +66,9 @@ public:
|
||||
QString description;
|
||||
Utils::FileName file;
|
||||
int line;
|
||||
int movedLine; // contains a line number if the line was moved in the editor
|
||||
Core::Id category;
|
||||
void addMark(TextEditor::BaseTextMark *mark);
|
||||
|
||||
// Having a QList<QTextLayout::FormatRange> in Task isn't that great
|
||||
// It would be cleaner to split up the text into
|
||||
@@ -77,6 +80,7 @@ public:
|
||||
// anywhere near being that good
|
||||
QList<QTextLayout::FormatRange> formats;
|
||||
private:
|
||||
QSharedPointer<TextEditor::BaseTextMark> m_mark;
|
||||
static unsigned int s_nextId;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,10 +31,36 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "taskhub.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "projectexplorer.h"
|
||||
#include <texteditor/basetextmark.h>
|
||||
#include <QtCore/QMetaType>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
class TaskMark : public TextEditor::BaseTextMark
|
||||
{
|
||||
public:
|
||||
TaskMark(unsigned int id)
|
||||
: m_id(id)
|
||||
{}
|
||||
|
||||
void updateLineNumber(int lineNumber);
|
||||
void removedFromEditor();
|
||||
private:
|
||||
unsigned int m_id;
|
||||
};
|
||||
|
||||
void TaskMark::updateLineNumber(int lineNumber)
|
||||
{
|
||||
ProjectExplorerPlugin::instance()->taskHub()->updateTaskLineNumber(m_id, lineNumber);
|
||||
}
|
||||
|
||||
void TaskMark::removedFromEditor()
|
||||
{
|
||||
ProjectExplorerPlugin::instance()->taskHub()->updateTaskLineNumber(m_id, -1);
|
||||
}
|
||||
|
||||
TaskHub::TaskHub()
|
||||
: m_errorIcon(QLatin1String(":/projectexplorer/images/compile_error.png")),
|
||||
m_warningIcon(QLatin1String(":/projectexplorer/images/compile_warning.png"))
|
||||
@@ -53,8 +79,16 @@ void TaskHub::addCategory(const Core::Id &categoryId, const QString &displayName
|
||||
emit categoryAdded(categoryId, displayName, visible);
|
||||
}
|
||||
|
||||
void TaskHub::addTask(const Task &task)
|
||||
void TaskHub::addTask(Task task)
|
||||
{
|
||||
if (task.line != -1 && !task.file.isEmpty()) {
|
||||
TaskMark *mark = new TaskMark(task.taskId);
|
||||
mark->setIcon(taskTypeIcon(task.type));
|
||||
mark->setLocation(task.file.toString(), task.line);
|
||||
mark->setPriority(TextEditor::ITextMark::HighPriority);
|
||||
task.addMark(mark);
|
||||
}
|
||||
|
||||
emit taskAdded(task);
|
||||
}
|
||||
|
||||
@@ -68,6 +102,11 @@ void TaskHub::removeTask(const Task &task)
|
||||
emit taskRemoved(task);
|
||||
}
|
||||
|
||||
void TaskHub::updateTaskLineNumber(unsigned int id, int line)
|
||||
{
|
||||
emit taskLineNumberUpdated(id, line);
|
||||
}
|
||||
|
||||
void TaskHub::setCategoryVisibility(const Core::Id &categoryId, bool visible)
|
||||
{
|
||||
emit categoryVisibilityChanged(categoryId, visible);
|
||||
|
||||
@@ -49,9 +49,10 @@ public:
|
||||
virtual ~TaskHub();
|
||||
|
||||
void addCategory(const Core::Id &categoryId, const QString &displayName, bool visible = true);
|
||||
void addTask(const Task &task);
|
||||
void addTask(Task task);
|
||||
void clearTasks(const Core::Id &categoryId = Core::Id());
|
||||
void removeTask(const Task &task);
|
||||
void updateTaskLineNumber(unsigned int id, int line);
|
||||
void setCategoryVisibility(const Core::Id &categoryId, bool visible);
|
||||
|
||||
void popup(bool withFocus);
|
||||
@@ -63,6 +64,7 @@ signals:
|
||||
void taskAdded(const ProjectExplorer::Task &task);
|
||||
void taskRemoved(const ProjectExplorer::Task &task);
|
||||
void tasksCleared(const Core::Id &categoryId);
|
||||
void taskLineNumberUpdated(unsigned int id, int line);
|
||||
void categoryVisibilityChanged(const Core::Id &categoryId, bool visible);
|
||||
void popupRequested(bool withFocus);
|
||||
private:
|
||||
|
||||
@@ -141,6 +141,17 @@ void TaskModel::removeTask(const Task &task)
|
||||
}
|
||||
}
|
||||
|
||||
void TaskModel::updateTaskLineNumber(unsigned int id, int line)
|
||||
{
|
||||
for (int i = 0; i < m_tasks.count(); ++i) {
|
||||
if (m_tasks.at(i).taskId == id) {
|
||||
m_tasks[i].movedLine = line;
|
||||
emit dataChanged(index(i, 0), index(i, 0));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskModel::clearTasks(const Core::Id &categoryId)
|
||||
{
|
||||
if (categoryId.uniqueIdentifier() == 0) {
|
||||
@@ -216,10 +227,9 @@ QVariant TaskModel::data(const QModelIndex &index, int role) const
|
||||
if (role == TaskModel::File) {
|
||||
return m_tasks.at(index.row()).file.toString();
|
||||
} else if (role == TaskModel::Line) {
|
||||
if (m_tasks.at(index.row()).line <= 0)
|
||||
return QVariant();
|
||||
else
|
||||
return m_tasks.at(index.row()).line;
|
||||
return m_tasks.at(index.row()).line;
|
||||
} else if (role == TaskModel::MovedLine) {
|
||||
return m_tasks.at(index.row()).movedLine;
|
||||
} else if (role == TaskModel::Description) {
|
||||
return m_tasks.at(index.row()).description;
|
||||
} else if (role == TaskModel::FileNotFound) {
|
||||
|
||||
@@ -62,12 +62,13 @@ public:
|
||||
void addTask(const Task &task);
|
||||
void removeTask(const Task &task);
|
||||
void clearTasks(const Core::Id &categoryId = Core::Id());
|
||||
void updateTaskLineNumber(unsigned int id, int line);
|
||||
|
||||
int sizeOfFile(const QFont &font);
|
||||
int sizeOfLineNumber(const QFont &font);
|
||||
void setFileNotFound(const QModelIndex &index, bool b);
|
||||
|
||||
enum Roles { File = Qt::UserRole, Line, Description, FileNotFound, Type, Category, Icon, Task_t };
|
||||
enum Roles { File = Qt::UserRole, Line, MovedLine, Description, FileNotFound, Type, Category, Icon, Task_t };
|
||||
|
||||
QIcon taskTypeIcon(Task::TaskType t) const;
|
||||
|
||||
|
||||
@@ -296,6 +296,8 @@ TaskWindow::TaskWindow(TaskHub *taskhub) : d(new TaskWindowPrivate)
|
||||
this, SLOT(addTask(ProjectExplorer::Task)));
|
||||
connect(d->m_taskHub, SIGNAL(taskRemoved(ProjectExplorer::Task)),
|
||||
this, SLOT(removeTask(ProjectExplorer::Task)));
|
||||
connect(d->m_taskHub, SIGNAL(taskLineNumberUpdated(uint,int)),
|
||||
this, SLOT(updatedTaskLineNumber(uint,int)));
|
||||
connect(d->m_taskHub, SIGNAL(tasksCleared(Core::Id)),
|
||||
this, SLOT(clearTasks(Core::Id)));
|
||||
connect(d->m_taskHub, SIGNAL(categoryVisibilityChanged(Core::Id,bool)),
|
||||
@@ -380,6 +382,12 @@ void TaskWindow::removeTask(const Task &task)
|
||||
navigateStateChanged();
|
||||
}
|
||||
|
||||
void TaskWindow::updatedTaskLineNumber(unsigned int id, int line)
|
||||
{
|
||||
d->m_model->updateTaskLineNumber(id, line);
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
||||
void TaskWindow::triggerDefaultHandler(const QModelIndex &index)
|
||||
{
|
||||
if (!index.isValid())
|
||||
@@ -788,7 +796,28 @@ void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
}
|
||||
|
||||
// Paint LineArea
|
||||
QString lineText = index.data(TaskModel::Line).toString();
|
||||
int line = index.data(TaskModel::Line).toInt();
|
||||
int movedLine = index.data(TaskModel::MovedLine).toInt();
|
||||
QString lineText;
|
||||
|
||||
if (line == -1) {
|
||||
// No line information at all
|
||||
} else if (movedLine == -1) {
|
||||
// removed the line, but we had line information, show the line in ()
|
||||
QFont f = painter->font();
|
||||
f.setItalic(true);
|
||||
painter->setFont(f);
|
||||
lineText = "(" + QString::number(line) + ")";
|
||||
} else if (movedLine != line) {
|
||||
// The line was moved
|
||||
QFont f = painter->font();
|
||||
f.setItalic(true);
|
||||
painter->setFont(f);
|
||||
lineText = QString::number(movedLine);
|
||||
} else {
|
||||
lineText = QString::number(line);
|
||||
}
|
||||
|
||||
painter->setClipRect(positions.lineArea());
|
||||
const int realLineWidth = fm.width(lineText);
|
||||
painter->drawText(positions.lineAreaRight() - realLineWidth, positions.top() + fm.ascent(), lineText);
|
||||
|
||||
@@ -89,6 +89,7 @@ private slots:
|
||||
void addCategory(const Core::Id &categoryId, const QString &displayName, bool visible);
|
||||
void addTask(const ProjectExplorer::Task &task);
|
||||
void removeTask(const ProjectExplorer::Task &task);
|
||||
void updatedTaskLineNumber(unsigned int id, int line);
|
||||
void clearTasks(const Core::Id &categoryId);
|
||||
void setCategoryVisibility(const Core::Id &categoryId, bool visible);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ void VcsAnnotateTaskHandler::handle(const ProjectExplorer::Task &task)
|
||||
Core::IVersionControl *vc = Core::ICore::vcsManager()->findVersionControlForDirectory(fi.absolutePath());
|
||||
Q_ASSERT(vc);
|
||||
Q_ASSERT(vc->supportsOperation(Core::IVersionControl::AnnotateOperation));
|
||||
vc->vcsAnnotate(fi.absoluteFilePath(), task.line);
|
||||
vc->vcsAnnotate(fi.absoluteFilePath(), task.movedLine);
|
||||
}
|
||||
|
||||
QAction *VcsAnnotateTaskHandler::createAction(QObject *parent)
|
||||
|
||||
Reference in New Issue
Block a user