Commit 1ee8d0fb authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Improve error and progress handling for loading and saving

* Clear the trace and send the loadingFinished() signal when loading
  fails or is canceled. loadingFinished() re-enables the UI, which is
  in fact important.

* Check more consistently for whether the operation was canceled and
  add a separate signal for that.

* When saving fails or is canceled, remove the half-written file.

* Don't try to guess the number of events for progress reporting when
  saving. Use the event timestamps and start/end time instead.

* Properly initialize the progress range in all cases.

* Drop the bool return value from the load methods. Nobody uses that.

* Send loadFinished() only after loading a file, not every time we
  reach the Done state.

Change-Id: I507f11c667e20534ea335e84798de11aa06fb6f2
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Ulf Hermann's avatarUlf Hermann <ulf.hermann@qt.io>
parent 07f4ae62
......@@ -369,8 +369,6 @@ void QmlProfilerModelManager::processingDone()
d->notesModel->loadData();
setState(Done);
emit loadFinished();
}
void QmlProfilerModelManager::save(const QString &filename)
......@@ -394,6 +392,24 @@ void QmlProfilerModelManager::save(const QString &filename)
connect(writer, &QObject::destroyed, this, &QmlProfilerModelManager::saveFinished,
Qt::QueuedConnection);
connect(writer, &QmlProfilerFileWriter::error, this, [this, file](const QString &message) {
file->close();
file->remove();
delete file;
emit error(message);
}, Qt::QueuedConnection);
connect(writer, &QmlProfilerFileWriter::success, this, [this, file]() {
file->close();
delete file;
}, Qt::QueuedConnection);
connect(writer, &QmlProfilerFileWriter::canceled, this, [this, file]() {
file->close();
file->remove();
delete file;
}, Qt::QueuedConnection);
QFuture<void> result = Utils::runAsync([file, writer] (QFutureInterface<void> &future) {
writer->setFuture(&future);
if (file->fileName().endsWith(QLatin1String(Constants::QtdFileExtension)))
......@@ -401,7 +417,6 @@ void QmlProfilerModelManager::save(const QString &filename)
else
writer->saveQzt(file);
writer->deleteLater();
file->deleteLater();
});
Core::ProgressManager::addTask(result, tr("Saving Trace Data"), Constants::TASK_SAVE,
......@@ -423,10 +438,8 @@ void QmlProfilerModelManager::load(const QString &filename)
setState(AcquiringData);
QmlProfilerFileReader *reader = new QmlProfilerFileReader(this);
connect(reader, &QmlProfilerFileReader::error, this, [this, reader](const QString &message) {
delete reader;
emit error(message);
}, Qt::QueuedConnection);
connect(reader, &QObject::destroyed, this, &QmlProfilerModelManager::loadFinished,
Qt::QueuedConnection);
connect(reader, &QmlProfilerFileReader::typesLoaded,
this, &QmlProfilerModelManager::addEventTypes);
......@@ -444,6 +457,17 @@ void QmlProfilerModelManager::load(const QString &filename)
acquiringDone();
}, Qt::QueuedConnection);
connect(reader, &QmlProfilerFileReader::error, this, [this, reader](const QString &message) {
clear();
delete reader;
emit error(message);
}, Qt::QueuedConnection);
connect(reader, &QmlProfilerFileReader::canceled, this, [this, reader]() {
clear();
delete reader;
}, Qt::QueuedConnection);
QFuture<void> result = Utils::runAsync([isQtd, file, reader] (QFutureInterface<void> &future) {
reader->setFuture(&future);
if (isQtd)
......
......@@ -51,8 +51,8 @@ public:
void setFuture(QFutureInterface<void> *future);
bool loadQtd(QIODevice *device);
bool loadQzt(QIODevice *device);
void loadQtd(QIODevice *device);
void loadQzt(QIODevice *device);
quint64 loadedFeatures() const;
......@@ -65,6 +65,7 @@ signals:
void qmlEventsLoaded(const QVector<QmlProfiler::QmlEvent> &event);
void error(const QString &error);
void success();
void canceled();
private:
void loadEventTypes(QXmlStreamReader &reader);
......@@ -96,16 +97,26 @@ public:
void saveQtd(QIODevice *device);
void saveQzt(QFile *file);
signals:
void error(const QString &error);
void success();
void canceled();
private:
void calculateMeasuredTime();
void incrementProgress();
void updateProgress(qint64 timestamp);
bool isCanceled() const;
enum ProgressValues {
ProgressTypes = -128,
ProgressNotes = -32,
ProgressEvents = 1024,
ProgressTotal = ProgressEvents - ProgressTypes - ProgressNotes
};
qint64 m_startTime, m_endTime, m_measuredTime;
QFutureInterface<void> *m_future;
const QmlProfilerDataModel *m_model;
QVector<QmlNote> m_notes;
int m_newProgressValue;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment