From c8fa68fe9ae15d0efd3039ba370674fbc4d21685 Mon Sep 17 00:00:00 2001
From: hjk <hjk121@nokiamail.com>
Date: Sun, 13 Oct 2013 22:29:22 +0200
Subject: [PATCH] Debugger: Offer base changes for all integral looking values.

Change-Id: I166a452a9d067285467b346a4ef5d4de646d3a31
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
---
 src/plugins/debugger/watchhandler.cpp | 32 ++++++++++++++++++---------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index bd40997ce8d..03958d9bd22 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -508,6 +508,25 @@ static int formatToIntegerBase(int format)
     return 10;
 }
 
+static bool isIntegralValue(const QString &value)
+{
+    if (value.startsWith(QLatin1Char('-')))
+        return isIntegralValue(value.mid(1));
+
+    bool ok;
+    value.toULongLong(&ok, 10);
+    if (ok)
+        return true;
+    value.toULongLong(&ok, 16);
+    if (ok)
+        return true;
+    value.toULongLong(&ok, 8);
+    if (ok)
+        return true;
+
+    return false;
+}
+
 template <class IntType> QString reformatInteger(IntType value, int format)
 {
     switch (format) {
@@ -623,14 +642,7 @@ QString WatchModel::formattedValue(const WatchData &data) const
         return value;
     }
 
-    if (isIntType(data.type)) {
-        if (value.isEmpty())
-            return value;
-        // Do not reformat booleans (reported as 'true, false').
-        const QChar firstChar = value.at(0);
-        if (!firstChar.isDigit() && firstChar != QLatin1Char('-'))
-            return value;
-
+    if (isIntegralValue(value)) {
         // Append quoted, printable character also for decimal.
         const int format = itemFormat(data);
         if (data.type.endsWith("char")) {
@@ -1225,9 +1237,7 @@ QStringList WatchModel::typeFormatList(const WatchData &data) const
             << tr("Latin1 string")
             << tr("UTF8 string")
             << tr("Local 8bit string");
-    bool ok = false;
-    (void)data.value.toULongLong(&ok, 0);
-    if ((isIntType(data.type) && data.type != "bool") || ok)
+    if (isIntegralValue(data.value))
         return QStringList()
             << tr("Decimal")
             << tr("Hexadecimal")
-- 
GitLab