From 1173b0f656daa89a0cd5c069dbdcf5a010708167 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Mon, 28 Sep 2009 11:52:00 +0200
Subject: [PATCH] debugger: fix color of changed register values.

Was broken since 1e7cee620.
---
 src/plugins/debugger/registerhandler.cpp | 8 +++-----
 src/plugins/debugger/registerhandler.h   | 3 ++-
 src/plugins/debugger/registerwindow.cpp  | 8 +++++++-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/plugins/debugger/registerhandler.cpp b/src/plugins/debugger/registerhandler.cpp
index 6419bbf2b8a..cbff586239b 100644
--- a/src/plugins/debugger/registerhandler.cpp
+++ b/src/plugins/debugger/registerhandler.cpp
@@ -67,8 +67,6 @@ int RegisterHandler::columnCount(const QModelIndex &parent) const
 
 QVariant RegisterHandler::data(const QModelIndex &index, int role) const
 {
-    static const QVariant red = QColor(200, 0, 0);
-
     if (role == RegisterNumberBaseRole)
         return m_base;
 
@@ -78,7 +76,7 @@ QVariant RegisterHandler::data(const QModelIndex &index, int role) const
     const Register &reg = m_registers.at(index.row());
 
     if (role == RegisterAddressRole) {
-        // return some address associated with the register
+        // Return some address associated with the register.
         bool ok = true;
         qulonglong value = reg.value.toULongLong(&ok, 0);
         return ok ? QString::fromLatin1("0x") + QString::number(value, 16) : QVariant();
@@ -100,8 +98,8 @@ QVariant RegisterHandler::data(const QModelIndex &index, int role) const
     if (role == Qt::TextAlignmentRole && index.column() == 1)
         return Qt::AlignRight;
 
-    if (role == Qt::TextColorRole && reg.changed && index.column() == 1)
-        return red;
+    if (role == RegisterChangedRole)
+        return reg.changed;
     
     return QVariant();
 }
diff --git a/src/plugins/debugger/registerhandler.h b/src/plugins/debugger/registerhandler.h
index c2766dd6466..d7f16d04637 100644
--- a/src/plugins/debugger/registerhandler.h
+++ b/src/plugins/debugger/registerhandler.h
@@ -38,7 +38,8 @@ namespace Internal {
 enum RegisterRole
 {
     RegisterNumberBaseRole = Qt::UserRole, // Currently used number base
-    RegisterAddressRole                   // Start value for opening memory view
+    RegisterAddressRole,                   // Start value for opening memory view
+    RegisterChangedRole                    // Used for painting changed values 
 };
 
 class Register
diff --git a/src/plugins/debugger/registerwindow.cpp b/src/plugins/debugger/registerwindow.cpp
index 51fb69ff522..13c7a537c2a 100644
--- a/src/plugins/debugger/registerwindow.cpp
+++ b/src/plugins/debugger/registerwindow.cpp
@@ -105,6 +105,10 @@ public:
         const QModelIndex &index) const
     {
         if (index.column() == 1) {
+            bool paintRed = index.data(RegisterChangedRole).toBool();
+            QPen oldPen = painter->pen();
+            if (paintRed)
+                painter->setPen(QColor(200, 0, 0));
             // FIXME: performance? this changes only on real font changes.
             QFontMetrics fm(option.font);
             int charWidth = fm.width(QLatin1Char('x'));
@@ -112,7 +116,7 @@ public:
                 charWidth = qMax(charWidth, fm.width(QLatin1Char(i)));
             for (int i = 'a'; i <= 'f'; ++i)
                 charWidth = qMax(charWidth, fm.width(QLatin1Char(i)));
-            QString str = index.model()->data(index, Qt::DisplayRole).toString();
+            QString str = index.data(Qt::DisplayRole).toString();
             int x = option.rect.x();
             for (int i = 0; i < str.size(); ++i) {
                 QRect r = option.rect;
@@ -121,6 +125,8 @@ public:
                 x += charWidth;
                 painter->drawText(r, Qt::AlignHCenter, QString(str.at(i)));
             }
+            if (paintRed)
+                painter->setPen(oldPen);
         } else {
             QItemDelegate::paint(painter, option, index);
         }
-- 
GitLab