Commit 6f0fa511 authored by Daniel Teske's avatar Daniel Teske
Browse files

Make TaskMarks clickable and jump to the right task in the taskwindow



That means it is no longer possible to make bookmarks on lines with
errors or warnings by simply clicking. That's not nice.
It might be better to do something different, but let's see how the
feedback to this is.

Change-Id: I34788ff638ed49c21001d03cd60f992ffabd6153
Reviewed-by: default avatarhjk <qthjk@ovi.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 407e1eaa
......@@ -45,6 +45,9 @@ public:
: BaseTextMark(fileName, lineNumber), m_id(id), m_visible(visible)
{}
bool clickable() const;
void clicked();
void updateLineNumber(int lineNumber);
void removedFromEditor();
bool visible() const;
......@@ -69,6 +72,16 @@ bool TaskMark::visible() const
return m_visible;
}
bool TaskMark::clickable() const
{
return true;
}
void TaskMark::clicked()
{
ProjectExplorerPlugin::instance()->taskHub()->taskMarkClicked(m_id);
}
TaskHub::TaskHub()
: m_errorIcon(QLatin1String(":/projectexplorer/images/compile_error.png")),
m_warningIcon(QLatin1String(":/projectexplorer/images/compile_warning.png"))
......@@ -114,6 +127,11 @@ void TaskHub::updateTaskLineNumber(unsigned int id, int line)
emit taskLineNumberUpdated(id, line);
}
void TaskHub::taskMarkClicked(unsigned int id)
{
emit showTask(id);
}
void TaskHub::setCategoryVisibility(const Core::Id &categoryId, bool visible)
{
emit categoryVisibilityChanged(categoryId, visible);
......
......@@ -53,6 +53,7 @@ public:
void clearTasks(const Core::Id &categoryId = Core::Id());
void removeTask(const Task &task);
void updateTaskLineNumber(unsigned int id, int line);
void taskMarkClicked(unsigned int id);
void setCategoryVisibility(const Core::Id &categoryId, bool visible);
void popup(bool withFocus);
......@@ -67,6 +68,7 @@ signals:
void taskLineNumberUpdated(unsigned int id, int line);
void categoryVisibilityChanged(const Core::Id &categoryId, bool visible);
void popupRequested(bool withFocus);
void showTask(unsigned int id);
private:
const QIcon m_errorIcon;
const QIcon m_warningIcon;
......
......@@ -148,11 +148,18 @@ void TaskModel::removeTask(const Task &task)
}
}
int TaskModel::rowForId(unsigned int id)
{
QList<Task>::const_iterator it = qLowerBound(m_tasks.constBegin(), m_tasks.constEnd(), id, sortById);
if (it == m_tasks.constEnd())
return -1;
return it - m_tasks.constBegin();
}
void TaskModel::updateTaskLineNumber(unsigned int id, int line)
{
QList<Task>::iterator it = qLowerBound(m_tasks.begin(), m_tasks.end(), id, sortById);
QTC_ASSERT(it != m_tasks.end(), return)
int i = it - m_tasks.begin();
int i = rowForId(id);
QTC_ASSERT(i != -1, return)
if (m_tasks.at(i).taskId == id) {
m_tasks[i].movedLine = line;
emit dataChanged(index(i, 0), index(i, 0));
......@@ -444,6 +451,15 @@ void TaskFilterModel::handleReset()
invalidateFilter();
}
QModelIndex TaskFilterModel::mapFromSource(const QModelIndex &idx) const
{
updateMapping();
QList<int>::const_iterator it = qBinaryFind(m_mapping.constBegin(), m_mapping.constEnd(), idx.row());
if (it == m_mapping.constEnd())
return QModelIndex();
return index(it - m_mapping.constBegin(), 0);
}
QModelIndex TaskFilterModel::mapToSource(const QModelIndex &index) const
{
updateMapping();
......
......@@ -78,6 +78,7 @@ public:
bool hasFile(const QModelIndex &index) const;
int rowForId(unsigned int id);
private:
class CategoryData
......@@ -161,6 +162,7 @@ public:
bool hasFile(const QModelIndex &index) const
{ return m_sourceModel->hasFile(mapToSource(index)); }
QModelIndex mapFromSource(const QModelIndex &idx) const;
private slots:
void handleNewRows(const QModelIndex &index, int first, int last);
void handleRemovedRows(const QModelIndex &index, int first, int last);
......
......@@ -304,6 +304,8 @@ TaskWindow::TaskWindow(TaskHub *taskhub) : d(new TaskWindowPrivate)
this, SLOT(setCategoryVisibility(Core::Id,bool)));
connect(d->m_taskHub, SIGNAL(popupRequested(bool)),
this, SLOT(popup(bool)));
connect(d->m_taskHub, SIGNAL(showTask(uint)),
this, SLOT(showTask(uint)));
}
TaskWindow::~TaskWindow()
......@@ -388,6 +390,14 @@ void TaskWindow::updatedTaskLineNumber(unsigned int id, int line)
emit tasksChanged();
}
void TaskWindow::showTask(unsigned int id)
{
int sourceRow = d->m_model->rowForId(id);
QModelIndex sourceIdx = d->m_model->index(sourceRow, 0);
QModelIndex filterIdx = d->m_filter->mapFromSource(sourceIdx);
d->m_listview->setCurrentIndex(filterIdx);
}
void TaskWindow::triggerDefaultHandler(const QModelIndex &index)
{
if (!index.isValid())
......
......@@ -90,6 +90,7 @@ private slots:
void addTask(const ProjectExplorer::Task &task);
void removeTask(const ProjectExplorer::Task &task);
void updatedTaskLineNumber(unsigned int id, int line);
void showTask(unsigned int id);
void clearTasks(const Core::Id &categoryId);
void setCategoryVisibility(const Core::Id &categoryId, bool visible);
......
......@@ -4443,12 +4443,22 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
int n = d->extraAreaToggleMarkBlockNumber;
d->extraAreaToggleMarkBlockNumber = -1;
if (cursor.blockNumber() == n) {
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(cursor.block().userData())) {
foreach (ITextMark *mark, data->marks()) {
if (mark->clickable()) {
mark->clicked();
return;
}
}
}
int line = n + 1;
ITextEditor::MarkRequestKind kind;
if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
kind = ITextEditor::BookmarkRequest;
else
kind = ITextEditor::BreakpointRequest;
emit editor()->markRequested(editor(), line, kind);
}
}
......
......@@ -110,7 +110,8 @@ public:
enum MarkRequestKind {
BreakpointRequest,
BookmarkRequest
BookmarkRequest,
TaskMarkRequest
};
signals:
......
......@@ -84,3 +84,11 @@ double ITextMark::widthFactor() const
{
return 1.0;
}
bool ITextMark::clickable() const
{
return false;
}
void ITextMark::clicked()
{}
......@@ -75,6 +75,8 @@ public:
void setPriority(Priority prioriy);
virtual bool visible() const;
virtual double widthFactor() const;
virtual bool clickable() const;
virtual void clicked();
private:
int m_lineNumber;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment