From 3008255bb54819f1549066667cbbe3265af1bc15 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 28 Aug 2018 09:25:07 +0200 Subject: [PATCH] Tracing: Make notes in TimelineModelAggregator mutable When the notes model is deleted, it becomes null. The notes model belongs to TimelineTraceManager, not to TimelineModelAggregator. Change-Id: I0ef9312620e08c06d31bc65976a887af0ca90c33 Reviewed-by: Christian Kandeler --- src/libs/tracing/timelinemodelaggregator.cpp | 26 ++++++++++++++++--- src/libs/tracing/timelinemodelaggregator.h | 7 +++-- .../qmlprofiler/qmlprofilertraceview.cpp | 3 ++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/libs/tracing/timelinemodelaggregator.cpp b/src/libs/tracing/timelinemodelaggregator.cpp index 30636356aec..5b8c34855bc 100644 --- a/src/libs/tracing/timelinemodelaggregator.cpp +++ b/src/libs/tracing/timelinemodelaggregator.cpp @@ -30,6 +30,7 @@ #include +#include #include #include @@ -38,15 +39,13 @@ namespace Timeline { class TimelineModelAggregator::TimelineModelAggregatorPrivate { public: QList modelList; - TimelineNotesModel *notesModel; + QPointer notesModel; int currentModelId = 0; }; -TimelineModelAggregator::TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent) +TimelineModelAggregator::TimelineModelAggregator(QObject *parent) : QObject(parent), d_ptr(new TimelineModelAggregatorPrivate) { - Q_D(TimelineModelAggregator); - d->notesModel = notes; } TimelineModelAggregator::~TimelineModelAggregator() @@ -129,6 +128,25 @@ TimelineNotesModel *TimelineModelAggregator::notes() const return d->notesModel; } +void TimelineModelAggregator::setNotes(TimelineNotesModel *notes) +{ + Q_D(TimelineModelAggregator); + if (d->notesModel == notes) + return; + + if (d->notesModel) { + disconnect(d->notesModel, &QObject::destroyed, + this, &TimelineModelAggregator::notesChanged); + } + + d->notesModel = notes; + + if (d->notesModel) + connect(d->notesModel, &QObject::destroyed, this, &TimelineModelAggregator::notesChanged); + + emit notesChanged(); +} + void TimelineModelAggregator::clear() { Q_D(TimelineModelAggregator); diff --git a/src/libs/tracing/timelinemodelaggregator.h b/src/libs/tracing/timelinemodelaggregator.h index af8250467c9..8a04a0ed48a 100644 --- a/src/libs/tracing/timelinemodelaggregator.h +++ b/src/libs/tracing/timelinemodelaggregator.h @@ -35,9 +35,9 @@ class TRACING_EXPORT TimelineModelAggregator : public QObject Q_OBJECT Q_PROPERTY(int height READ height NOTIFY heightChanged) Q_PROPERTY(QVariantList models READ models WRITE setModels NOTIFY modelsChanged) - Q_PROPERTY(Timeline::TimelineNotesModel *notes READ notes CONSTANT) + Q_PROPERTY(Timeline::TimelineNotesModel *notes READ notes WRITE setNotes NOTIFY notesChanged) public: - TimelineModelAggregator(TimelineNotesModel *notes = nullptr, QObject *parent = nullptr); + TimelineModelAggregator(QObject *parent = nullptr); ~TimelineModelAggregator() override; int height() const; @@ -50,6 +50,8 @@ public: void setModels(const QVariantList &models); TimelineNotesModel *notes() const; + void setNotes(TimelineNotesModel *notes); + void clear(); int modelCount() const; int modelIndexById(int modelId) const; @@ -62,6 +64,7 @@ public: signals: void modelsChanged(); void heightChanged(); + void notesChanged(); void updateCursorPosition(); private: diff --git a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp index 7e7d77bfb93..50f6030d0f2 100644 --- a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp @@ -145,7 +145,8 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManag setLayout(groupLayout); d->m_viewContainer = container; - d->m_modelProxy = new Timeline::TimelineModelAggregator(modelManager->notesModel(), this); + d->m_modelProxy = new Timeline::TimelineModelAggregator(this); + d->m_modelProxy->setNotes(modelManager->notesModel()); d->m_modelManager = modelManager; QVariantList models;