forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -406,27 +406,33 @@ void QmlProfilerModelManager::setFilename(const QString &filename)
|
||||
|
||||
void QmlProfilerModelManager::load()
|
||||
{
|
||||
QString filename = d->fileName;
|
||||
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
emit error(tr("Could not open %1 for reading.").arg(filename));
|
||||
QFile *file = new QFile(d->fileName, this);
|
||||
if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
emit error(tr("Could not open %1 for reading.").arg(d->fileName));
|
||||
delete file;
|
||||
emit loadFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
// erase current
|
||||
clear();
|
||||
|
||||
setState(QmlProfilerDataState::AcquiringData);
|
||||
|
||||
QmlProfilerFileReader reader;
|
||||
connect(&reader, SIGNAL(error(QString)), this, SIGNAL(error(QString)));
|
||||
reader.setV8DataModel(d->v8Model);
|
||||
reader.setQmlDataModel(d->model);
|
||||
reader.load(&file);
|
||||
QFuture<void> result = QtConcurrent::run<void>([this, file] (QFutureInterface<void> &future) {
|
||||
QmlProfilerFileReader reader;
|
||||
reader.setFuture(&future);
|
||||
connect(&reader, &QmlProfilerFileReader::error, this, &QmlProfilerModelManager::error);
|
||||
reader.setV8DataModel(d->v8Model);
|
||||
reader.setQmlDataModel(d->model);
|
||||
reader.load(file);
|
||||
file->close();
|
||||
file->deleteLater();
|
||||
|
||||
complete();
|
||||
// The completion step uses the old progress display widget for now.
|
||||
complete();
|
||||
QMetaObject::invokeMethod(this, "loadFinished", Qt::QueuedConnection);
|
||||
});
|
||||
|
||||
Core::ProgressManager::addTask(result, tr("Loading Trace Data"), Constants::TASK_LOAD);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user