OSDN Git Service

QmlProfiler: Store type of event as string instead of number
authorKai Koehne <kai.koehne@nokia.com>
Fri, 26 Aug 2011 09:37:45 +0000 (11:37 +0200)
committerKai Koehne <kai.koehne@nokia.com>
Fri, 26 Aug 2011 10:42:07 +0000 (12:42 +0200)
This makes the .qtp files slightly more readable.

Change-Id: I2642cf9b7ff43730559088c6ac710545e2b2a47e
Reviewed-on: http://codereview.qt.nokia.com/3654
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
src/libs/qmljsdebugclient/qmlprofilereventlist.cpp
src/libs/qmljsdebugclient/qmlprofilereventtypes.h

index a64caa7..51c6fc9 100644 (file)
 
 namespace QmlJsDebugClient {
 
+namespace Constants {
+const char *const TYPE_PAINTING_STR = "Painting";
+const char *const TYPE_COMPILING_STR = "Compiling";
+const char *const TYPE_CREATING_STR = "Creating";
+const char *const TYPE_BINDING_STR = "Binding";
+const char *const TYPE_HANDLINGSIGNAL_STR = "HandlingSignal";
+}
+
 #define MIN_LEVEL 1
 
 // description
@@ -103,6 +111,52 @@ bool compareStartIndexes(const QmlEventEndTimeData &t1, const QmlEventEndTimeDat
     return t1.startTimeIndex < t2.startTimeIndex;
 }
 
+QString qmlEventType(QmlEventType typeEnum)
+{
+    switch (typeEnum) {
+    case Painting:
+        return QLatin1String(Constants::TYPE_PAINTING_STR);
+        break;
+    case Compiling:
+        return QLatin1String(Constants::TYPE_COMPILING_STR);
+        break;
+    case Creating:
+        return QLatin1String(Constants::TYPE_CREATING_STR);
+        break;
+    case Binding:
+        return QLatin1String(Constants::TYPE_BINDING_STR);
+        break;
+    case HandlingSignal:
+        return QLatin1String(Constants::TYPE_HANDLINGSIGNAL_STR);
+        break;
+    default:
+        return QString::number((int)typeEnum);
+    }
+}
+
+QmlEventType qmlEventType(const QString &typeString)
+{
+    if (typeString == QLatin1String(Constants::TYPE_PAINTING_STR)) {
+        return Painting;
+    } else if (typeString == QLatin1String(Constants::TYPE_COMPILING_STR)) {
+        return Compiling;
+    } else if (typeString == QLatin1String(Constants::TYPE_CREATING_STR)) {
+        return Creating;
+    } else if (typeString == QLatin1String(Constants::TYPE_BINDING_STR)) {
+        return Binding;
+    } else if (typeString == QLatin1String(Constants::TYPE_HANDLINGSIGNAL_STR)) {
+        return HandlingSignal;
+    } else {
+        bool isNumber = false;
+        int type = typeString.toUInt(&isNumber);
+        if (isNumber) {
+            return (QmlEventType)type;
+        } else {
+            return MaximumQmlEventType;
+        }
+    }
+}
+
 class QmlProfilerEventList::QmlProfilerEventListPrivate
 {
 public:
@@ -625,7 +679,7 @@ void QmlProfilerEventList::save(const QString &filename)
         stream.writeStartElement("event");
         stream.writeAttribute("index", QString::number(d->m_eventDescriptions.keys().indexOf(eventData->location)));
         stream.writeTextElement("displayname", eventData->displayname);
-        stream.writeTextElement("type", QString::number(eventData->eventType));
+        stream.writeTextElement("type", qmlEventType(eventData->eventType));
         if (!eventData->filename.isEmpty()) {
             stream.writeTextElement("filename", eventData->filename);
             stream.writeTextElement("line", QString::number(eventData->line));
@@ -743,7 +797,7 @@ void QmlProfilerEventList::load()
                     break;
                 }
                 if (elementName == "type") {
-                    currentEvent->eventType = QmlJsDebugClient::QmlEventType(readData.toInt());
+                    currentEvent->eventType = qmlEventType(readData);
                     break;
                 }
                 if (elementName == "filename") {
index fb4805c..0ec8ffb 100644 (file)
@@ -33,6 +33,8 @@
 #ifndef QMLPROFILEREVENTTYPES_H
 #define QMLPROFILEREVENTTYPES_H
 
+#include <QtCore/QString>
+
 namespace QmlJsDebugClient {
 
 enum QmlEventType {
@@ -45,6 +47,9 @@ enum QmlEventType {
     MaximumQmlEventType
 };
 
+QString qmlEventType(QmlEventType typeEnum);
+QmlEventType qmlEventType(const QString &typeString);
+
 } // namespace QmlJsDebugClient
 
 #endif //QMLPROFILEREVENTTYPES_H