Remove TimelineTraceManager::State

This is redundant, now that we have registerFeatures().

Change-Id: Ia56c28b8892ab6da694570fe4b9ea5c96fe194f1
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Ulf Hermann
2018-04-20 18:06:38 +02:00
parent de006655e3
commit 1770c2ffe2
17 changed files with 94 additions and 195 deletions

View File

@@ -37,6 +37,8 @@
#include <QTimer>
#include <QPointer>
#include <functional>
namespace QmlProfiler {
namespace Internal {
@@ -72,17 +74,16 @@ QmlProfilerStateWidget::QmlProfilerStateWidget(QmlProfilerStateManager *stateMan
// profiler state
d->m_modelManager = modelManager;
connect(d->m_modelManager, &QmlProfilerModelManager::stateChanged,
this, &QmlProfilerStateWidget::update);
modelManager->registerFeatures(0, QmlProfilerModelManager::QmlEventLoader(),
std::bind(&QmlProfilerStateWidget::initialize, this),
std::bind(&QmlProfilerStateWidget::clear, this),
std::bind(&QmlProfilerStateWidget::clear, this));
d->m_profilerState = stateManager;
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
this, &QmlProfilerStateWidget::update);
connect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
this, &QmlProfilerStateWidget::update);
connect(&d->timer, &QTimer::timeout, this, &QmlProfilerStateWidget::updateDisplay);
d->timer.setInterval(1000);
update();
setVisible(false);
}
QmlProfilerStateWidget::~QmlProfilerStateWidget()
@@ -97,6 +98,16 @@ void QmlProfilerStateWidget::reposition()
move(parentWidget->width()/2 - width()/2, parentWidget->height()/3 - height()/2);
}
void QmlProfilerStateWidget::initialize()
{
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
this, &QmlProfilerStateWidget::updateDisplay);
connect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
this, &QmlProfilerStateWidget::updateDisplay);
d->timer.start();
updateDisplay();
}
void QmlProfilerStateWidget::showText(const QString &text)
{
setVisible(true);
@@ -105,69 +116,45 @@ void QmlProfilerStateWidget::showText(const QString &text)
reposition();
}
void QmlProfilerStateWidget::clear()
{
disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
this, &QmlProfilerStateWidget::updateDisplay);
disconnect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
this, &QmlProfilerStateWidget::updateDisplay);
d->timer.stop();
setVisible(false);
}
void QmlProfilerStateWidget::updateDisplay()
{
if (!d->m_modelManager || !d->m_profilerState) {
d->timer.stop();
setVisible(false);
return;
}
QTC_ASSERT(d->m_modelManager, return);
QTC_ASSERT(d->m_profilerState, return);
// When application is being profiled
if (d->m_profilerState->serverRecording()) {
// Heuristic to not show the number if the application will only send the events when it
// stops. The number is still > 0 then because we get some StartTrace etc.
uint numEvents = d->m_modelManager->numEvents();
const int numEvents = d->m_modelManager->numEvents();
showText(numEvents > 256 ? tr("Profiling application: %n events", nullptr, numEvents) :
tr("Profiling application"));
return;
}
QmlProfilerModelManager::State state = d->m_modelManager->state();
if (state == QmlProfilerModelManager::Done || state == QmlProfilerModelManager::Empty) {
} else if (d->m_modelManager->traceDuration() > 0 && d->m_modelManager->isEmpty()) {
// After profiling, there is an empty trace
if (d->m_modelManager->traceDuration() > 0 && d->m_modelManager->isEmpty()) {
showText(tr("No QML events recorded"));
return;
}
showText(tr("No QML events recorded"));
} else if (!d->m_modelManager->isEmpty()) {
// When datamodel is acquiring or processing data
// When datamodel is acquiring data
if (d->m_profilerState->currentState() != QmlProfilerStateManager::Idle) {
if (state == QmlProfilerModelManager::AcquiringData) {
// we don't know how much more, so progress numbers are strange here
showText(tr("Loading buffered data: %n events", nullptr,
d->m_modelManager->numEvents()));
} else if (state == QmlProfilerModelManager::ClearingData) {
// when starting a second recording from the same process without aggregation
showText(tr("Clearing old trace"));
}
} else if (state == QmlProfilerModelManager::AcquiringData) {
// we don't know how much more, so progress numbers are strange here
showText(tr("Loading buffered data: %n events", nullptr,
d->m_modelManager->numEvents()));
} else {
// Application died before all data could be read
showText(tr("Loading offline data: %n events", nullptr,
d->m_modelManager->numEvents()));
} else if (state == QmlProfilerModelManager::ClearingData) {
showText(tr("Clearing old trace"));
}
return;
} else if (state == QmlProfilerModelManager::AcquiringData) {
} else {
showText(tr("Waiting for data"));
return;
}
// There is a trace on view, hide this dialog
setVisible(false);
}
void QmlProfilerStateWidget::update()
{
QmlProfilerModelManager::State state = d->m_modelManager ? d->m_modelManager->state()
: QmlProfilerModelManager::Empty;
if (state == QmlProfilerModelManager::AcquiringData)
d->timer.start();
else
d->timer.stop();
updateDisplay();
}
} // namespace Internal