ProjectExplorer: Delay task icon creation

Parsers can change the initial task type when accumulating output, and
then the original icon would no longer match.
To the user, the problem manifested itself by a missing error symbol in
the issues pane and a missing text marker in the editor.
Fix this by delaying creation of the icon until it is used.

Change-Id: I5349f21c6c0d9bc39a5000ceb33faf88ea62eeac
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-09-04 18:08:45 +02:00
parent 568cd8066e
commit 9c99aa223d
4 changed files with 14 additions and 6 deletions

View File

@@ -67,7 +67,7 @@ Task::Task(TaskType type_, const QString &description,
const QIcon &icon, Options options) : const QIcon &icon, Options options) :
taskId(s_nextId), type(type_), options(options), summary(description), taskId(s_nextId), type(type_), options(options), summary(description),
line(line_), movedLine(line_), category(category_), line(line_), movedLine(line_), category(category_),
icon(icon.isNull() ? taskTypeIcon(type_) : icon) m_icon(icon)
{ {
++s_nextId; ++s_nextId;
setFile(file_); setFile(file_);
@@ -108,7 +108,7 @@ void Task::clear()
line = -1; line = -1;
movedLine = -1; movedLine = -1;
category = Utils::Id(); category = Utils::Id();
icon = QIcon(); m_icon = QIcon();
formats.clear(); formats.clear();
m_mark.clear(); m_mark.clear();
} }
@@ -133,6 +133,13 @@ QString Task::description() const
return desc; return desc;
} }
QIcon Task::icon() const
{
if (m_icon.isNull())
m_icon = taskTypeIcon(type);
return m_icon;
}
// //
// functions // functions
// //

View File

@@ -74,6 +74,7 @@ public:
void clear(); void clear();
void setFile(const Utils::FilePath &file); void setFile(const Utils::FilePath &file);
QString description() const; QString description() const;
QIcon icon() const;
unsigned int taskId = 0; unsigned int taskId = 0;
TaskType type = Unknown; TaskType type = Unknown;
@@ -85,7 +86,6 @@ public:
int line = -1; int line = -1;
int movedLine = -1; // contains a line number if the line was moved in the editor int movedLine = -1; // contains a line number if the line was moved in the editor
Utils::Id category; Utils::Id category;
QIcon icon;
// Having a container of QTextLayout::FormatRange in Task isn't that great // Having a container of QTextLayout::FormatRange in Task isn't that great
// It would be cleaner to split up the text into // It would be cleaner to split up the text into
@@ -101,6 +101,7 @@ private:
void setMark(TextEditor::TextMark *mark); void setMark(TextEditor::TextMark *mark);
QSharedPointer<TextEditor::TextMark> m_mark; QSharedPointer<TextEditor::TextMark> m_mark;
mutable QIcon m_icon;
static unsigned int s_nextId; static unsigned int s_nextId;
friend class TaskHub; friend class TaskHub;

View File

@@ -78,8 +78,8 @@ public:
} else { } else {
setToolTip(task.description()); setToolTip(task.description());
} }
setIcon(task.icon); setIcon(task.icon());
setVisible(!task.icon.isNull()); setVisible(!task.icon().isNull());
} }
bool isClickable() const override; bool isClickable() const override;

View File

@@ -255,7 +255,7 @@ QVariant TaskModel::data(const QModelIndex &index, int role) const
else if (role == TaskModel::Category) else if (role == TaskModel::Category)
return m_tasks.at(index.row()).category.uniqueIdentifier(); return m_tasks.at(index.row()).category.uniqueIdentifier();
else if (role == TaskModel::Icon) else if (role == TaskModel::Icon)
return m_tasks.at(index.row()).icon; return m_tasks.at(index.row()).icon();
else if (role == TaskModel::Task_t) else if (role == TaskModel::Task_t)
return QVariant::fromValue(task(index)); return QVariant::fromValue(task(index));
return QVariant(); return QVariant();