From 210e780cc381c033088c0b7286102be15c065f90 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 9 Dec 2013 12:16:58 +0100 Subject: [PATCH] QmlProfiler: Deduplicate dataChanged() slot in timeline models. The same code was repeated all over the place. Change-Id: I70a8caa46c91a7b55fd7eecac32cdc53b5d94cfb Reviewed-by: Kai Koehne --- .../qmlprofiler/abstracttimelinemodel.cpp | 19 +++++++++++++++++++ .../qmlprofiler/abstracttimelinemodel.h | 7 +++++++ .../qmlprofilerpainteventsmodelproxy.cpp | 14 -------------- .../qmlprofilerpainteventsmodelproxy.h | 2 -- .../qmlprofilertimelinemodelproxy.cpp | 14 -------------- .../qmlprofilertimelinemodelproxy.h | 2 -- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/plugins/qmlprofiler/abstracttimelinemodel.cpp b/src/plugins/qmlprofiler/abstracttimelinemodel.cpp index 6df98dbbd6d..ae5972cebd0 100644 --- a/src/plugins/qmlprofiler/abstracttimelinemodel.cpp +++ b/src/plugins/qmlprofiler/abstracttimelinemodel.cpp @@ -79,5 +79,24 @@ int AbstractTimelineModel::getBindingLoopDest(int index) const return -1; } +void AbstractTimelineModel::dataChanged() +{ + switch (m_modelManager->state()) { + case QmlProfilerDataState::ProcessingData: + loadData(); + break; + case QmlProfilerDataState::Empty: + clear(); + break; + default: + break; + } + + emit stateChanged(); + emit dataAvailable(); + emit emptyChanged(); + emit expandedChanged(); +} + } diff --git a/src/plugins/qmlprofiler/abstracttimelinemodel.h b/src/plugins/qmlprofiler/abstracttimelinemodel.h index 0efcd606316..8ee6c51eba1 100644 --- a/src/plugins/qmlprofiler/abstracttimelinemodel.h +++ b/src/plugins/qmlprofiler/abstracttimelinemodel.h @@ -79,6 +79,10 @@ public: virtual int getEventType(int index) const = 0; virtual int getEventCategory(int index) const = 0; virtual int getEventRow(int index) const = 0; + + virtual void loadData() = 0; + virtual void clear() = 0; + Q_INVOKABLE virtual qint64 getDuration(int index) const = 0; Q_INVOKABLE virtual qint64 getStartTime(int index) const = 0; Q_INVOKABLE virtual qint64 getEndTime(int index) const = 0; @@ -106,6 +110,9 @@ signals: protected: QmlProfilerModelManager *m_modelManager; int m_modelId; + +protected slots: + void dataChanged(); }; } diff --git a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp index 9cc160b1a57..6735844af1e 100644 --- a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp @@ -118,20 +118,6 @@ void PaintEventsModelProxy::clear() m_modelManager->modelProxyCountUpdated(m_modelId, 0, 1); } -void PaintEventsModelProxy::dataChanged() -{ - if (m_modelManager->state() == QmlProfilerDataState::ProcessingData) - loadData(); - - if (m_modelManager->state() == QmlProfilerDataState::Empty) - clear(); - - emit stateChanged(); - emit dataAvailable(); - emit emptyChanged(); - emit expandedChanged(); -} - bool compareStartTimes(const PaintEventsModelProxy::QmlPaintEventData &t1, const PaintEventsModelProxy::QmlPaintEventData &t2) { return t1.startTime < t2.startTime; diff --git a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h index 4be60850ef8..a5108a397bd 100644 --- a/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h +++ b/src/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.h @@ -108,8 +108,6 @@ public: private slots: bool eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const; -protected slots: - void dataChanged(); private: class PaintEventsModelProxyPrivate; diff --git a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp index e6a280aadd2..3368404de59 100644 --- a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp @@ -130,20 +130,6 @@ void BasicTimelineModel::clear() m_modelManager->modelProxyCountUpdated(m_modelId, 0, 1); } -void BasicTimelineModel::dataChanged() -{ - if (m_modelManager->state() == QmlProfilerDataState::ProcessingData) - loadData(); - - if (m_modelManager->state() == QmlProfilerDataState::Empty) - clear(); - - emit stateChanged(); - emit dataAvailable(); - emit emptyChanged(); - emit expandedChanged(); -} - void BasicTimelineModel::BasicTimelineModelPrivate::prepare() { categorySpan.clear(); diff --git a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h index 3ffcf707ff5..ace89143fd4 100644 --- a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h +++ b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.h @@ -131,8 +131,6 @@ public: private slots: bool eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const; -protected slots: - void dataChanged(); private: class BasicTimelineModelPrivate;