aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprofiler/qmlprofilertracefile.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-02-17 14:25:24 +0100
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-02-26 16:19:27 +0000
commitd2892026c8eb979c046b14095f82f4f69218717f (patch)
treef792256151ece9859b87a4a213540feb4336adc6 /src/plugins/qmlprofiler/qmlprofilertracefile.cpp
parent5515d0308e1a38b7b5a5665a2e3fd6bd92626c5b (diff)
QmlProfiler: fix progress bar visibilty for loading traces
Move the main part of the loading work into a background thread and show the standard progress indicator for the "reading file" part of the load operation. The load operation can be canceled now. Change-Id: I4cb3b762072ab4a0665dcf9d4a39d6d6630d22e8 Task-number: QTCREATORBUG-11822 Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmlprofiler/qmlprofilertracefile.cpp')
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertracefile.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/plugins/qmlprofiler/qmlprofilertracefile.cpp b/src/plugins/qmlprofiler/qmlprofilertracefile.cpp
index 8b85d23da4..d92bb738d6 100644
--- a/src/plugins/qmlprofiler/qmlprofilertracefile.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertracefile.cpp
@@ -122,7 +122,8 @@ static QString qmlTypeAsString(Message message, RangeType rangeType)
QmlProfilerFileReader::QmlProfilerFileReader(QObject *parent) :
QObject(parent),
- m_v8Model(0)
+ m_v8Model(0),
+ m_future(0)
{
}
@@ -136,8 +137,18 @@ void QmlProfilerFileReader::setQmlDataModel(QmlProfilerDataModel *dataModel)
m_qmlModel = dataModel;
}
+void QmlProfilerFileReader::setFuture(QFutureInterface<void> *future)
+{
+ m_future = future;
+}
+
bool QmlProfilerFileReader::load(QIODevice *device)
{
+ if (m_future) {
+ m_future->setProgressRange(0, qMin(device->size(), qint64(INT_MAX)));
+ m_future->setProgressValue(0);
+ }
+
QXmlStreamReader stream(device);
bool validVersion = true;
@@ -145,6 +156,8 @@ bool QmlProfilerFileReader::load(QIODevice *device)
qint64 traceEnd = -1;
while (validVersion && !stream.atEnd() && !stream.hasError()) {
+ if (isCanceled())
+ return false;
QXmlStreamReader::TokenType token = stream.readNext();
const QStringRef elementName = stream.name();
switch (token) {
@@ -179,7 +192,7 @@ bool QmlProfilerFileReader::load(QIODevice *device)
if (elementName == _("v8profile")) {
if (m_v8Model)
- m_v8Model->load(stream);
+ m_v8Model->load(stream, m_future);
break;
}
@@ -217,12 +230,16 @@ void QmlProfilerFileReader::loadEventData(QXmlStreamReader &stream)
const QmlProfilerDataModel::QmlEventTypeData defaultEvent = event;
while (!stream.atEnd() && !stream.hasError()) {
+ if (isCanceled())
+ return;
+
QXmlStreamReader::TokenType token = stream.readNext();
const QStringRef elementName = stream.name();
switch (token) {
case QXmlStreamReader::StartElement: {
if (elementName == _("event")) {
+ progress(stream.device());
event = defaultEvent;
const QXmlStreamAttributes attributes = stream.attributes();
@@ -322,12 +339,16 @@ void QmlProfilerFileReader::loadProfilerDataModel(QXmlStreamReader &stream)
QTC_ASSERT(stream.name() == _("profilerDataModel"), return);
while (!stream.atEnd() && !stream.hasError()) {
+ if (isCanceled())
+ return;
+
QXmlStreamReader::TokenType token = stream.readNext();
const QStringRef elementName = stream.name();
switch (token) {
case QXmlStreamReader::StartElement: {
if (elementName == _("range")) {
+ progress(stream.device());
QmlProfilerDataModel::QmlEventData range = { -1, 0, 0, 0, 0, 0, 0, 0 };
const QXmlStreamAttributes attributes = stream.attributes();
@@ -389,12 +410,16 @@ void QmlProfilerFileReader::loadNoteData(QXmlStreamReader &stream)
{
QmlProfilerDataModel::QmlEventNoteData currentNote;
while (!stream.atEnd() && !stream.hasError()) {
+ if (isCanceled())
+ return;
+
QXmlStreamReader::TokenType token = stream.readNext();
const QStringRef elementName = stream.name();
switch (token) {
case QXmlStreamReader::StartElement: {
if (elementName == _("note")) {
+ progress(stream.device());
QXmlStreamAttributes attrs = stream.attributes();
currentNote.startTime = attrs.value(_("startTime")).toString().toLongLong();
currentNote.duration = attrs.value(_("duration")).toString().toLongLong();
@@ -420,6 +445,19 @@ void QmlProfilerFileReader::loadNoteData(QXmlStreamReader &stream)
}
}
+void QmlProfilerFileReader::progress(QIODevice *device)
+{
+ if (!m_future)
+ return;
+
+ m_future->setProgressValue(qMin(device->pos(), qint64(INT_MAX)));
+}
+
+bool QmlProfilerFileReader::isCanceled() const
+{
+ return m_future && m_future->isCanceled();
+}
+
QmlProfilerFileWriter::QmlProfilerFileWriter(QObject *parent) :
QObject(parent),
m_startTime(0),