From 1322a73efdcb53f18c9bbf8d9855b36e72c5107b Mon Sep 17 00:00:00 2001
From: Christiaan Janssen <christiaan.janssen@nokia.com>
Date: Wed, 15 Feb 2012 17:26:41 +0100
Subject: [PATCH] QmlProfiler: read trace when application ended by the user

This patch avoids showing the "use the stop button" if the
application dies but the trace data was sent in time.

Note: with the current implementation in Qt5, the application
sometimes closes before all data could be sent.  That happens
with any non-trivial qml application.

Change-Id: Ie7b1568b2d69320d1887587dccac40a4b4d4d788
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
---
 src/plugins/qmlprofiler/qml/MainView.qml      |  3 +++
 src/plugins/qmlprofiler/qml/StatusDisplay.qml | 19 ++++++++++++++++++-
 src/plugins/qmlprofiler/qmlprofilerengine.cpp |  8 +++++++-
 src/plugins/qmlprofiler/qmlprofilerengine.h   |  1 +
 src/plugins/qmlprofiler/qmlprofilertool.cpp   |  1 +
 src/plugins/qmlprofiler/tracewindow.cpp       |  6 ++++++
 src/plugins/qmlprofiler/tracewindow.h         |  1 +
 7 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/plugins/qmlprofiler/qml/MainView.qml b/src/plugins/qmlprofiler/qml/MainView.qml
index 6aa07199669..9fc2e8e44ed 100644
--- a/src/plugins/qmlprofiler/qml/MainView.qml
+++ b/src/plugins/qmlprofiler/qml/MainView.qml
@@ -77,6 +77,8 @@ Rectangle {
     signal changeToolTip(string text)
     signal updateVerticalScroll(int newPosition)
 
+    property bool applicationDied : false
+
     // ***** connections with external objects
     Connections {
         target: zoomControl
@@ -149,6 +151,7 @@ Rectangle {
     function clearData() {
         view.clearData();
         dataAvailable = false;
+        applicationDied = false;
         eventCount = 0;
         hideRangeDetails();
         selectionRangeMode = false;
diff --git a/src/plugins/qmlprofiler/qml/StatusDisplay.qml b/src/plugins/qmlprofiler/qml/StatusDisplay.qml
index f02aec121e9..d4507a37d63 100644
--- a/src/plugins/qmlprofiler/qml/StatusDisplay.qml
+++ b/src/plugins/qmlprofiler/qml/StatusDisplay.qml
@@ -99,7 +99,7 @@ Item {
         // loading data
         State {
             name: "loading"
-            when: (!root.dataAvailable) && (root.eventCount > 0)
+            when: (!root.dataAvailable) && (root.eventCount > 0) && !root.applicationDied
             PropertyChanges {
                 target: statusDisplay
                 visible: true
@@ -110,6 +110,23 @@ Item {
                 text: qsTr("Loading data")
             }
 
+            PropertyChanges {
+                target: progressBar
+                visible: true
+            }
+        },
+        // application died
+        State {
+            name: "deadApp"
+            when: (!root.dataAvailable) && (root.eventCount > 0) && root.applicationDied
+            PropertyChanges {
+                target: statusDisplay
+                visible: true
+            }
+            PropertyChanges {
+                target: statusText
+                text: qsTr("Application stopped before loading all data")
+            }
             PropertyChanges {
                 target: progressBar
                 visible: true
diff --git a/src/plugins/qmlprofiler/qmlprofilerengine.cpp b/src/plugins/qmlprofiler/qmlprofilerengine.cpp
index 6a835ac52aa..b6bc249a476 100644
--- a/src/plugins/qmlprofiler/qmlprofilerengine.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilerengine.cpp
@@ -80,6 +80,7 @@ public:
     AbstractQmlProfilerRunner *m_runner;
     bool m_running;
     bool m_fetchingData;
+    bool m_hasData;
     bool m_fetchDataFromStart;
     bool m_delayedDelete;
     QTimer m_noDebugOutputTimer;
@@ -209,6 +210,7 @@ bool QmlProfilerEngine::start()
 
     if (d->m_fetchDataFromStart) {
         d->m_fetchingData = true;
+        d->m_hasData = false;
     }
 
     emit starting(this);
@@ -236,8 +238,9 @@ void QmlProfilerEngine::stopped()
         d->m_fetchDataFromStart = d->m_fetchingData;
 
     // user feedback
-    if (d->m_running && d->m_fetchingData) {
+    if (d->m_running && d->m_fetchingData && !d->m_hasData) {
         showNonmodalWarning(tr("Application finished before loading profiled data.\n Please use the stop button instead."));
+        emit applicationDied();
     }
 
     d->m_running = false;
@@ -250,6 +253,8 @@ void QmlProfilerEngine::stopped()
 void QmlProfilerEngine::setFetchingData(bool b)
 {
     d->m_fetchingData = b;
+    if (d->m_running && b)
+        d->m_hasData = false;
     if (!d->m_running)
         d->m_fetchDataFromStart = b;
 }
@@ -259,6 +264,7 @@ void QmlProfilerEngine::dataReceived()
     if (d->m_delayedDelete)
         finishProcess();
     d->m_delayedDelete = false;
+    d->m_hasData = true;
 }
 
 void QmlProfilerEngine::finishProcess()
diff --git a/src/plugins/qmlprofiler/qmlprofilerengine.h b/src/plugins/qmlprofiler/qmlprofilerengine.h
index 017ffd050ba..9969d2a3a7f 100644
--- a/src/plugins/qmlprofiler/qmlprofilerengine.h
+++ b/src/plugins/qmlprofiler/qmlprofilerengine.h
@@ -55,6 +55,7 @@ signals:
     void stopRecording();
     void timeUpdate();
     void recordingChanged(bool recording);
+    void applicationDied();
 
 public slots:
     bool start();
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp
index 6d8c5979d77..82dce535296 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp
@@ -376,6 +376,7 @@ IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp
     connect(engine, SIGNAL(starting(const Analyzer::IAnalyzerEngine*)), this, SLOT(setAppIsRunning()));
     connect(engine, SIGNAL(finished()), this, SLOT(setAppIsStopped()));
     connect(this, SIGNAL(cancelRun()), engine, SLOT(finishProcess()));
+    connect(engine, SIGNAL(applicationDied()), d->m_traceWindow, SLOT(applicationDied()));
     emit fetchingData(d->m_recordButton->isChecked());
 
     return engine;
diff --git a/src/plugins/qmlprofiler/tracewindow.cpp b/src/plugins/qmlprofiler/tracewindow.cpp
index 2c35537801d..6a4f3817fb4 100644
--- a/src/plugins/qmlprofiler/tracewindow.cpp
+++ b/src/plugins/qmlprofiler/tracewindow.cpp
@@ -639,5 +639,11 @@ void TraceWindow::firstDataReceived()
     }
 }
 
+void TraceWindow::applicationDied()
+{
+    if (m_mainView->rootObject())
+        m_mainView->rootObject()->setProperty("applicationDied",QVariant(true));
+}
+
 } // namespace Internal
 } // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tracewindow.h b/src/plugins/qmlprofiler/tracewindow.h
index df2d3fe27f4..85acd2ad687 100644
--- a/src/plugins/qmlprofiler/tracewindow.h
+++ b/src/plugins/qmlprofiler/tracewindow.h
@@ -133,6 +133,7 @@ private slots:
     void eventListStateChanged();
     void manageTraceStart(qint64 traceStart);
     void firstDataReceived();
+    void applicationDied();
     void correctTimer();
 
 signals:
-- 
GitLab