QmlProfiler: Prevent interaction with buttons while loading data

You could trigger invalid states by pressing the recording button
while the profiler was waiting for data to be loaded from the
application or by pressing the "stop" button twice. Now the buttons
are disabled when they don't make any sense. In particular you cannot
clear, change features, filter the display while recording and you
cannot toggle the recording while loading. Pressing the "stop" button
twice will cancel the loading now, similar to what happens if you
first disable recording and then stop while the data is loaded.

Change-Id: Ie5133f4bed76593dedc9763b778a2c5c17187543
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2015-10-20 12:48:26 +02:00
parent 88c5b47e53
commit bd22de47e7
4 changed files with 46 additions and 12 deletions

View File

@@ -393,9 +393,6 @@ void QmlProfilerTool::setRecording(bool recording)
} else {
d->m_recordingTimer.stop();
}
d->m_recordButton->menu()->setEnabled(!recording);
} else {
d->m_recordButton->menu()->setEnabled(true);
}
}
@@ -451,6 +448,14 @@ void QmlProfilerTool::clearDisplay()
updateTimeDisplay();
}
void QmlProfilerTool::setButtonsEnabled(bool enable)
{
d->m_clearButton->setEnabled(enable);
d->m_displayFeaturesButton->setEnabled(enable);
d->m_searchButton->setEnabled(enable);
d->m_recordFeaturesMenu->setEnabled(enable);
}
bool QmlProfilerTool::prepareTool()
{
if (d->m_recordButton->isChecked()) {
@@ -625,7 +630,8 @@ void QmlProfilerTool::restoreFeatureVisibility()
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_profilerState->currentState() == QmlProfilerStateManager::AppDying ||
d->m_profilerState->currentState() == QmlProfilerStateManager::Idle) {
if (d->m_profilerModelManager->state() == QmlProfilerModelManager::AcquiringData) {
showNonmodalWarning(tr("Application finished before loading profiled data.\n"
"Please use the stop button instead."));
@@ -633,7 +639,8 @@ void QmlProfilerTool::clientsDisconnected()
}
// ... and return to the "base" state
d->m_profilerState->setCurrentState(QmlProfilerStateManager::Idle);
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppDying)
d->m_profilerState->setCurrentState(QmlProfilerStateManager::Idle);
}
// If the connection is closed while the app is still running, no special action is needed
}
@@ -687,13 +694,21 @@ void QmlProfilerTool::profilerDataModelStateChanged()
{
switch (d->m_profilerModelManager->state()) {
case QmlProfilerModelManager::Empty :
d->m_recordButton->setEnabled(true);
setButtonsEnabled(true);
break;
case QmlProfilerModelManager::ClearingData :
d->m_recordButton->setEnabled(false);
setButtonsEnabled(false);
clearDisplay();
break;
case QmlProfilerModelManager::AcquiringData :
d->m_recordButton->setEnabled(true); // Press recording button to stop recording
setButtonsEnabled(false); // Other buttons disabled
break;
case QmlProfilerModelManager::ProcessingData :
// nothing to be done for these two
d->m_recordButton->setEnabled(false);
setButtonsEnabled(false);
break;
case QmlProfilerModelManager::Done :
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppStopRequested)
@@ -701,6 +716,8 @@ void QmlProfilerTool::profilerDataModelStateChanged()
showSaveOption();
updateTimeDisplay();
restoreFeatureVisibility();
d->m_recordButton->setEnabled(true);
setButtonsEnabled(true);
break;
default:
break;
@@ -749,6 +766,11 @@ void QmlProfilerTool::profilerStateChanged()
// when the app finishes, set recording display to client status
setRecording(d->m_profilerState->clientRecording());
break;
case QmlProfilerStateManager::AppStopRequested:
// Don't allow toggling the recording while data is loaded when application quits
if (d->m_profilerState->serverRecording())
d->m_recordButton->setEnabled(false);
break;
default:
// no special action needed for other states
break;
@@ -781,15 +803,14 @@ void QmlProfilerTool::serverRecordingChanged()
showSaveDialog();
setRecording(true);
d->m_clearButton->setEnabled(false);
clearData();
d->m_profilerModelManager->prepareForWriting();
} else {
setRecording(false);
d->m_clearButton->setEnabled(true);
// changes back once loading is finished, see profilerDataModelStateChanged()
d->m_recordButton->setEnabled(false);
}
} else {
d->m_clearButton->setEnabled(true);
}
}