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>
This commit is contained in:
Ulf Hermann
2018-08-28 09:25:07 +02:00
parent 93a6dd0c67
commit 3008255bb5
3 changed files with 29 additions and 7 deletions

View File

@@ -30,6 +30,7 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <QPointer>
#include <QStringList> #include <QStringList>
#include <QVariant> #include <QVariant>
@@ -38,15 +39,13 @@ namespace Timeline {
class TimelineModelAggregator::TimelineModelAggregatorPrivate { class TimelineModelAggregator::TimelineModelAggregatorPrivate {
public: public:
QList <TimelineModel *> modelList; QList <TimelineModel *> modelList;
TimelineNotesModel *notesModel; QPointer<TimelineNotesModel> notesModel;
int currentModelId = 0; int currentModelId = 0;
}; };
TimelineModelAggregator::TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent) TimelineModelAggregator::TimelineModelAggregator(QObject *parent)
: QObject(parent), d_ptr(new TimelineModelAggregatorPrivate) : QObject(parent), d_ptr(new TimelineModelAggregatorPrivate)
{ {
Q_D(TimelineModelAggregator);
d->notesModel = notes;
} }
TimelineModelAggregator::~TimelineModelAggregator() TimelineModelAggregator::~TimelineModelAggregator()
@@ -129,6 +128,25 @@ TimelineNotesModel *TimelineModelAggregator::notes() const
return d->notesModel; 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() void TimelineModelAggregator::clear()
{ {
Q_D(TimelineModelAggregator); Q_D(TimelineModelAggregator);

View File

@@ -35,9 +35,9 @@ class TRACING_EXPORT TimelineModelAggregator : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(int height READ height NOTIFY heightChanged) Q_PROPERTY(int height READ height NOTIFY heightChanged)
Q_PROPERTY(QVariantList models READ models WRITE setModels NOTIFY modelsChanged) 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: public:
TimelineModelAggregator(TimelineNotesModel *notes = nullptr, QObject *parent = nullptr); TimelineModelAggregator(QObject *parent = nullptr);
~TimelineModelAggregator() override; ~TimelineModelAggregator() override;
int height() const; int height() const;
@@ -50,6 +50,8 @@ public:
void setModels(const QVariantList &models); void setModels(const QVariantList &models);
TimelineNotesModel *notes() const; TimelineNotesModel *notes() const;
void setNotes(TimelineNotesModel *notes);
void clear(); void clear();
int modelCount() const; int modelCount() const;
int modelIndexById(int modelId) const; int modelIndexById(int modelId) const;
@@ -62,6 +64,7 @@ public:
signals: signals:
void modelsChanged(); void modelsChanged();
void heightChanged(); void heightChanged();
void notesChanged();
void updateCursorPosition(); void updateCursorPosition();
private: private:

View File

@@ -145,7 +145,8 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManag
setLayout(groupLayout); setLayout(groupLayout);
d->m_viewContainer = container; 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; d->m_modelManager = modelManager;
QVariantList models; QVariantList models;