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

View File

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

View File

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

View File

@@ -255,7 +255,7 @@ QVariant TaskModel::data(const QModelIndex &index, int role) const
else if (role == TaskModel::Category)
return m_tasks.at(index.row()).category.uniqueIdentifier();
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)
return QVariant::fromValue(task(index));
return QVariant();