Commit ddb87272 authored by Ulf Hermann's avatar Ulf Hermann
Browse files

QmlProfiler: Eliminate QmlProfilerDataState



This class is only accessible through the model manager and there is no
real point in keeping it separate.

Change-Id: I575d47c08aa8f6731d44739f9604072b95fd1dcd
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent f373c679
......@@ -131,9 +131,9 @@ void QmlProfilerEventsModelProxy::limitToRange(qint64 rangeStart, qint64 rangeEn
void QmlProfilerEventsModelProxy::dataChanged()
{
if (d->modelManager->state() == QmlProfilerDataState::ProcessingData)
if (d->modelManager->state() == QmlProfilerModelManager::ProcessingData)
loadData();
else if (d->modelManager->state() == QmlProfilerDataState::ClearingData)
else if (d->modelManager->state() == QmlProfilerModelManager::ClearingData)
clear();
}
......
......@@ -59,49 +59,6 @@ static const char *ProfileFeatureNames[QmlDebug::MaximumProfileFeature] = {
QT_TRANSLATE_NOOP("MainView", "Input Events")
};
QmlProfilerDataState::QmlProfilerDataState(QmlProfilerModelManager *modelManager, QObject *parent)
: QObject(parent), m_state(Empty), m_modelManager(modelManager)
{
connect(this, SIGNAL(error(QString)), m_modelManager, SIGNAL(error(QString)));
connect(this, SIGNAL(stateChanged()), m_modelManager, SIGNAL(stateChanged()));
}
void QmlProfilerDataState::setState(QmlProfilerDataState::State state)
{
// It's not an error, we are continuously calling "AcquiringData" for example
if (m_state == state)
return;
switch (state) {
case ClearingData:
QTC_ASSERT(m_state == Done || m_state == Empty || m_state == AcquiringData, /**/);
break;
case Empty:
// if it's not empty, complain but go on
QTC_ASSERT(m_modelManager->isEmpty(), /**/);
break;
case AcquiringData:
// we're not supposed to receive new data while processing older data
QTC_ASSERT(m_state != ProcessingData, return);
break;
case ProcessingData:
QTC_ASSERT(m_state == AcquiringData, return);
break;
case Done:
QTC_ASSERT(m_state == ProcessingData || m_state == Empty, return);
break;
default:
emit error(tr("Trying to set unknown state in events list."));
break;
}
m_state = state;
emit stateChanged();
return;
}
/////////////////////////////////////////////////////////////////////
QmlProfilerTraceTime::QmlProfilerTraceTime(QObject *parent) :
QObject(parent), m_startTime(-1), m_endTime(-1)
......@@ -173,7 +130,7 @@ public:
QmlProfilerDataModel *model;
QmlProfilerNotesModel *notesModel;
QmlProfilerDataState *dataState;
QmlProfilerModelManager::State state;
QmlProfilerTraceTime *traceTime;
QVector <double> partialCounts;
......@@ -196,7 +153,7 @@ QmlProfilerModelManager::QmlProfilerModelManager(Utils::FileInProjectFinder *fin
d->visibleFeatures = 0;
d->recordedFeatures = 0;
d->model = new QmlProfilerDataModel(finder, this);
d->dataState = new QmlProfilerDataState(this, this);
d->state = Empty;
d->traceTime = new QmlProfilerTraceTime(this);
d->notesModel = new QmlProfilerNotesModel(this);
d->notesModel->setModelManager(this);
......@@ -336,7 +293,7 @@ void QmlProfilerModelManager::addQmlEvent(QmlDebug::Message message,
if (d->traceTime->startTime() == -1)
d->traceTime->setTime(startTime, startTime + d->traceTime->duration());
QTC_ASSERT(state() == QmlProfilerDataState::AcquiringData, /**/);
QTC_ASSERT(state() == AcquiringData, /**/);
d->model->addQmlEvent(message, rangeType, detailType, startTime, length, data, location,
ndata1, ndata2, ndata3, ndata4, ndata5);
}
......@@ -344,22 +301,22 @@ void QmlProfilerModelManager::addQmlEvent(QmlDebug::Message message,
void QmlProfilerModelManager::complete()
{
switch (state()) {
case QmlProfilerDataState::ProcessingData:
case ProcessingData:
// Load notes after the timeline models have been initialized.
d->notesModel->loadData();
setState(QmlProfilerDataState::Done);
setState(Done);
emit loadFinished();
break;
case QmlProfilerDataState::AcquiringData:
case AcquiringData:
// Make sure the trace fits into the time span.
d->traceTime->increaseEndTime(d->model->lastTimeMark());
setState(QmlProfilerDataState::ProcessingData);
setState(ProcessingData);
d->model->complete();
break;
case QmlProfilerDataState::Empty:
setState(QmlProfilerDataState::Done);
case Empty:
setState(Done);
break;
case QmlProfilerDataState::Done:
case Done:
break;
default:
emit error(tr("Unexpected complete signal in data model."));
......@@ -406,7 +363,7 @@ void QmlProfilerModelManager::load(const QString &filename)
}
clear();
setState(QmlProfilerDataState::AcquiringData);
setState(AcquiringData);
QFuture<void> result = QtConcurrent::run<void>([this, file] (QFutureInterface<void> &future) {
QmlProfilerFileReader reader;
......@@ -427,19 +384,47 @@ void QmlProfilerModelManager::load(const QString &filename)
}
void QmlProfilerModelManager::setState(QmlProfilerDataState::State state)
void QmlProfilerModelManager::setState(QmlProfilerModelManager::State state)
{
d->dataState->setState(state);
// It's not an error, we are continuously calling "AcquiringData" for example
if (d->state == state)
return;
switch (state) {
case ClearingData:
QTC_ASSERT(d->state == Done || d->state == Empty || d->state == AcquiringData, /**/);
break;
case Empty:
// if it's not empty, complain but go on
QTC_ASSERT(isEmpty(), /**/);
break;
case AcquiringData:
// we're not supposed to receive new data while processing older data
QTC_ASSERT(d->state != ProcessingData, return);
break;
case ProcessingData:
QTC_ASSERT(d->state == AcquiringData, return);
break;
case Done:
QTC_ASSERT(d->state == ProcessingData || d->state == Empty, return);
break;
default:
emit error(tr("Trying to set unknown state in events list."));
break;
}
d->state = state;
emit stateChanged();
}
QmlProfilerDataState::State QmlProfilerModelManager::state() const
QmlProfilerModelManager::State QmlProfilerModelManager::state() const
{
return d->dataState->state();
return d->state;
}
void QmlProfilerModelManager::clear()
{
setState(QmlProfilerDataState::ClearingData);
setState(ClearingData);
for (int i = 0; i < d->partialCounts.count(); i++)
d->partialCounts[i] = 0;
d->progress = 0;
......@@ -450,12 +435,12 @@ void QmlProfilerModelManager::clear()
setVisibleFeatures(0);
setRecordedFeatures(0);
setState(QmlProfilerDataState::Empty);
setState(Empty);
}
void QmlProfilerModelManager::prepareForWriting()
{
setState(QmlProfilerDataState::AcquiringData);
setState(AcquiringData);
}
} // namespace QmlProfiler
......@@ -46,35 +46,6 @@ class QmlProfilerNotesModel;
namespace Internal {
class QmlProfilerDataState : public QObject
{
Q_OBJECT
public:
enum State {
Empty,
AcquiringData,
ProcessingData,
ClearingData,
Done
};
explicit QmlProfilerDataState(QmlProfilerModelManager *modelManager, QObject *parent = 0);
~QmlProfilerDataState() {}
State state() const { return m_state; }
signals:
void stateChanged();
void error(const QString &error);
private:
void setState(State state);
State m_state;
QmlProfilerModelManager *m_modelManager;
friend class QmlProfiler::QmlProfilerModelManager;
};
class QMLPROFILER_EXPORT QmlProfilerTraceTime : public QObject
{
Q_OBJECT
......@@ -110,11 +81,18 @@ class QMLPROFILER_EXPORT QmlProfilerModelManager : public QObject
{
Q_OBJECT
public:
enum State {
Empty,
AcquiringData,
ProcessingData,
ClearingData,
Done
};
explicit QmlProfilerModelManager(Utils::FileInProjectFinder *finder, QObject *parent = 0);
~QmlProfilerModelManager();
QmlProfilerDataState::State state() const;
State state() const;
QmlProfilerTraceTime *traceTime() const;
QmlProfilerDataModel *qmlModel() const;
QmlProfilerNotesModel *notesModel() const;
......@@ -162,8 +140,7 @@ public slots:
void load(const QString &filename);
private:
void setState(QmlProfilerDataState::State state);
void setState(State state);
private:
class QmlProfilerModelManagerPrivate;
......
......@@ -193,8 +193,8 @@ void QmlProfilerStateWidget::updateDisplay()
return;
}
QmlProfilerDataState::State state = d->m_modelManager->state();
if (state == QmlProfilerDataState::Done || state == QmlProfilerDataState::Empty) {
QmlProfilerModelManager::State state = d->m_modelManager->state();
if (state == QmlProfilerModelManager::Done || state == QmlProfilerModelManager::Empty) {
// After profiling, there is an empty trace
if (d->m_modelManager->traceTime()->duration() > 0 &&
(d->m_modelManager->isEmpty() || d->m_modelManager->progress() == 0)) {
......@@ -208,7 +208,7 @@ void QmlProfilerStateWidget::updateDisplay()
else // Application died before all data could be read
showText(tr("Application stopped before loading all data"), true);
return;
} else if (state == QmlProfilerDataState::AcquiringData) {
} else if (state == QmlProfilerModelManager::AcquiringData) {
showText(tr("Waiting for data"));
return;
}
......
......@@ -102,11 +102,11 @@ void QmlProfilerTimelineModel::dataChanged()
{
switch (m_modelManager->state()) {
case QmlProfilerDataState::Done:
case QmlProfilerModelManager::Done:
loadData();
emit emptyChanged();
break;
case QmlProfilerDataState::ClearingData:
case QmlProfilerModelManager::ClearingData:
clear();
break;
default:
......
......@@ -420,8 +420,8 @@ void QmlProfilerTool::updateTimeDisplay()
if (d->m_profilerState->serverRecording() &&
d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
seconds = d->m_recordingElapsedTime.elapsed() / 1000.0;
} else if (d->m_profilerModelManager->state() != QmlProfilerDataState::Empty &&
d->m_profilerModelManager->state() != QmlProfilerDataState::ClearingData) {
} else if (d->m_profilerModelManager->state() != QmlProfilerModelManager::Empty &&
d->m_profilerModelManager->state() != QmlProfilerModelManager::ClearingData) {
seconds = d->m_profilerModelManager->traceTime()->duration() / 1.0e9;
}
QString timeString = QString::number(seconds,'f',1);
......@@ -609,7 +609,7 @@ void QmlProfilerTool::clientsDisconnected()
{
// If the application stopped by itself, check if we have all the data
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppDying) {
if (d->m_profilerModelManager->state() == QmlProfilerDataState::AcquiringData)
if (d->m_profilerModelManager->state() == QmlProfilerModelManager::AcquiringData)
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppKilled);
else
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppStopped);
......@@ -668,16 +668,16 @@ void QmlProfilerTool::setRecordedFeatures(quint64 features)
void QmlProfilerTool::profilerDataModelStateChanged()
{
switch (d->m_profilerModelManager->state()) {
case QmlProfilerDataState::Empty :
case QmlProfilerModelManager::Empty :
break;
case QmlProfilerDataState::ClearingData :
case QmlProfilerModelManager::ClearingData :
clearDisplay();
break;
case QmlProfilerDataState::AcquiringData :
case QmlProfilerDataState::ProcessingData :
case QmlProfilerModelManager::AcquiringData :
case QmlProfilerModelManager::ProcessingData :
// nothing to be done for these two
break;
case QmlProfilerDataState::Done :
case QmlProfilerModelManager::Done :
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppStopRequested)
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppReadyToStop);
showSaveOption();
......
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