From 058d76fca8a6abf56d6ff0a9ccf5e1df22b7a369 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Wed, 26 May 2010 11:57:39 +0200
Subject: [PATCH] TaskWindow: Fix warnings about leaking X11 pixmap data.

Attach icons to TaskModel.
Reviewed-by: Daniel Molkentin <daniel.molkentin@nokia.com>
---
 src/plugins/projectexplorer/taskwindow.cpp    | 51 ++++++++++---------
 src/plugins/projectexplorer/taskwindow.h      |  5 +-
 .../wizards/targetsetuppage.cpp               | 14 +++--
 3 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/src/plugins/projectexplorer/taskwindow.cpp b/src/plugins/projectexplorer/taskwindow.cpp
index c74e94dd060..fb289419386 100644
--- a/src/plugins/projectexplorer/taskwindow.cpp
+++ b/src/plugins/projectexplorer/taskwindow.cpp
@@ -53,27 +53,12 @@
 #include <QtGui/QMenu>
 
 namespace {
-
 const int TASK_ICON_SIZE = 16;
 const int TASK_ICON_MARGIN = 2;
-
-const QIcon ERROR_ICON(":/projectexplorer/images/compile_error.png");
-const QIcon WARNING_ICON(":/projectexplorer/images/compile_warning.png");
-
 }
 
 namespace ProjectExplorer {
 
-QIcon Task::icon() const
-{
-    if (type == ProjectExplorer::Task::Error)
-        return ERROR_ICON;
-    else if (type == ProjectExplorer::Task::Warning)
-        return WARNING_ICON;
-    else
-        return QIcon();
-}
-
 namespace Internal {
 
 class TaskView : public QListView
@@ -141,6 +126,8 @@ public:
 
     enum Roles { File = Qt::UserRole, Line, Description, FileNotFound, Type, Category, Icon, Task_t };
 
+    QIcon taskTypeIcon(Task::TaskType t) const;
+
 private:
     QHash<QString,QString> m_categories; // category id -> display name
     QList<Task> m_tasks;   // all tasks (in order of insertion)
@@ -148,8 +135,8 @@ private:
 
     QHash<QString,bool> m_fileNotFound;
     int m_maxSizeOfFileName;
-    QIcon m_errorIcon;
-    QIcon m_warningIcon;
+    const QIcon m_errorIcon;
+    const QIcon m_warningIcon;
 };
 
 class TaskFilterModel : public QSortFilterProxyModel
@@ -224,11 +211,24 @@ void TaskView::keyPressEvent(QKeyEvent *e)
 // TaskModel
 /////
 
-TaskModel::TaskModel()
+TaskModel::TaskModel() :
+    m_maxSizeOfFileName(0),
+    m_errorIcon(QLatin1String(":/projectexplorer/images/compile_error.png")),
+    m_warningIcon(QLatin1String(":/projectexplorer/images/compile_warning.png"))
 {
-    m_maxSizeOfFileName = 0;
-    m_errorIcon = QIcon(":/projectexplorer/images/compile_error.png");
-    m_warningIcon = QIcon(":/projectexplorer/images/compile_warning.png");
+}
+
+QIcon TaskModel::taskTypeIcon(Task::TaskType t) const
+{
+    switch (t) {
+    case Task::Warning:
+        return m_warningIcon;
+    case Task::Error:
+        return m_errorIcon;
+    case Task::Unknown:
+        break;
+    }
+    return QIcon();
 }
 
 void TaskModel::addCategory(const QString &categoryId, const QString &categoryName)
@@ -353,7 +353,7 @@ QVariant TaskModel::data(const QModelIndex &index, int role) const
     } else if (role == TaskModel::Category) {
         return m_tasks.at(index.row()).category;
     } else if (role == TaskModel::Icon) {
-        return m_tasks.at(index.row()).icon();
+        return taskTypeIcon(m_tasks.at(index.row()).type);
     } else if (role == TaskModel::Task_t) {
         return QVariant::fromValue(m_tasks.at(index.row()));
     }
@@ -495,7 +495,7 @@ TaskWindow::TaskWindow()
     connect(m_listview, SIGNAL(clicked(QModelIndex)),
             this, SLOT(showTaskInFile(QModelIndex)));
 
-    m_filterWarningsButton = createFilterButton(WARNING_ICON,
+    m_filterWarningsButton = createFilterButton(taskTypeIcon(Task::Warning),
                                                 tr("Show Warnings"),
                                                 this, SLOT(setShowWarnings(bool)));
 
@@ -771,6 +771,11 @@ void TaskWindow::updateActions()
     m_copyAction->setEnabled(m_model->tasks().count() > 0);
 }
 
+QIcon TaskWindow::taskTypeIcon(Task::TaskType t) const
+{
+    return m_model->taskTypeIcon(t);
+}
+
 /////
 // Delegate
 /////
diff --git a/src/plugins/projectexplorer/taskwindow.h b/src/plugins/projectexplorer/taskwindow.h
index 656f9940944..1d6df98e20e 100644
--- a/src/plugins/projectexplorer/taskwindow.h
+++ b/src/plugins/projectexplorer/taskwindow.h
@@ -86,9 +86,6 @@ struct PROJECTEXPLORER_EXPORT Task {
     // doesn't work if you split it up, nor are our parsers
     // anywhere near being that good
     QList<QTextLayout::FormatRange> formats;
-
-    /// Get the icon used to represent this task
-    QIcon icon() const;
 };
 
 class PROJECTEXPLORER_EXPORT TaskWindow : public Core::IOutputPane
@@ -128,6 +125,8 @@ public:
     void goToNext();
     void goToPrev();
 
+    QIcon taskTypeIcon(Task::TaskType t) const;
+
 signals:
     void tasksChanged();
 
diff --git a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
index dfe383e3fa0..edb1a8a3235 100644
--- a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
+++ b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
@@ -35,6 +35,9 @@
 #include "qt4projectmanagerconstants.h"
 #include "qt4target.h"
 
+#include <utils/qtcassert.h>
+#include <extensionsystem/pluginmanager.h>
+
 #include <QtGui/QFileDialog>
 #include <QtGui/QHeaderView>
 #include <QtGui/QLabel>
@@ -442,21 +445,26 @@ QPair<QIcon, QString> TargetSetupPage::reportIssues(Qt4ProjectManager::QtVersion
     if (m_proFilePath.isEmpty())
         return qMakePair(QIcon(), QString());
 
+    const ProjectExplorer::TaskWindow *taskWindow = ExtensionSystem::PluginManager::instance()
+                                              ->getObject<ProjectExplorer::TaskWindow>();
+    QTC_ASSERT(taskWindow, return qMakePair(QIcon(), QString()));
+
     QList<ProjectExplorer::Task> issues = version->reportIssues(m_proFilePath);
 
+
     QString text;
     QIcon icon;
-    foreach (const ProjectExplorer::Task t, issues) {
+    foreach (const ProjectExplorer::Task &t, issues) {
         if (!text.isEmpty())
             text.append(QLatin1String("<br>"));
         // set severity:
         QString severity;
         if (t.type == ProjectExplorer::Task::Error) {
-            icon = t.icon();
+            icon = taskWindow->taskTypeIcon(t.type);
             severity = tr("<b>Error:</b> ", "Severity is Task::Error");
         } else if (t.type == ProjectExplorer::Task::Warning) {
                if (icon.isNull())
-                   icon = t.icon();
+                   icon = taskWindow->taskTypeIcon(t.type);
                severity = tr("<b>Warning:</b> ", "Severity is Task::Warning");
         }
         text.append(severity + t.description);
-- 
GitLab