diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2018-08-28 09:25:07 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-08-28 08:36:45 +0000 |
commit | 3008255bb54819f1549066667cbbe3265af1bc15 (patch) | |
tree | 2a02b468614c1843bc8f0bff862cca5b9d5a1c85 /src | |
parent | 93a6dd0c6705c23ebe81753c7774bfdab61f9824 (diff) |
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 <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/tracing/timelinemodelaggregator.cpp | 26 | ||||
-rw-r--r-- | src/libs/tracing/timelinemodelaggregator.h | 7 | ||||
-rw-r--r-- | src/plugins/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 30636356ae..5b8c34855b 100644 --- a/src/libs/tracing/timelinemodelaggregator.cpp +++ b/src/libs/tracing/timelinemodelaggregator.cpp @@ -30,6 +30,7 @@ #include <utils/algorithm.h> +#include <QPointer> #include <QStringList> #include <QVariant> @@ -38,15 +39,13 @@ namespace Timeline { class TimelineModelAggregator::TimelineModelAggregatorPrivate { public: QList <TimelineModel *> modelList; - TimelineNotesModel *notesModel; + QPointer<TimelineNotesModel> 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 af8250467c..8a04a0ed48 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 7e7d77bfb9..50f6030d0f 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; |