QmlProfiler: show a warning if unsaved notes are to be discarded

Change-Id: I5152f0eefd1f0beec2b0f4fc9e27fedeb3bf7a14
Task-number: QTCREATORBUG-13318
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2014-11-03 14:19:26 +01:00
committed by Ulf Hermann
parent 55c24db5f8
commit 99f4b6353d
5 changed files with 73 additions and 5 deletions

View File

@@ -38,6 +38,7 @@
#include "qmlprofilermodelmanager.h"
#include "qmlprofilerdetailsrewriter.h"
#include "timelinerenderer.h"
#include "notesmodel.h"
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
@@ -272,7 +273,10 @@ QWidget *QmlProfilerTool::createWidgets()
d->m_clearButton->setIcon(QIcon(QLatin1String(":/qmlprofiler/clean_pane_small.png")));
d->m_clearButton->setToolTip(tr("Discard data"));
connect(d->m_clearButton,SIGNAL(clicked()), this, SLOT(clearData()));
connect(d->m_clearButton, &QAbstractButton::clicked, [this](){
if (checkForUnsavedNotes())
clearData();
});
layout->addWidget(d->m_clearButton);
@@ -324,7 +328,16 @@ void QmlProfilerTool::populateFileFinder(QString projectDirectory, QString activ
void QmlProfilerTool::recordingButtonChanged(bool recording)
{
d->m_profilerState->setClientRecording(recording);
if (recording && d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
if (checkForUnsavedNotes()) {
clearData(); // clear right away, before the application starts
d->m_profilerState->setClientRecording(true);
} else {
d->m_recordButton->setChecked(false);
}
} else {
d->m_profilerState->setClientRecording(recording);
}
}
void QmlProfilerTool::setRecording(bool recording)
@@ -447,6 +460,13 @@ static void startRemoteTool(IAnalyzerTool *tool, StartMode mode)
void QmlProfilerTool::startTool(StartMode mode)
{
if (d->m_recordButton->isChecked()) {
if (!checkForUnsavedNotes())
return;
else
clearData(); // clear right away to suppress second warning on server recording change
}
// Make sure mode is shown.
AnalyzerManager::showMode();
@@ -499,6 +519,9 @@ void QmlProfilerTool::showSaveDialog()
void QmlProfilerTool::showLoadDialog()
{
if (!checkForUnsavedNotes())
return;
if (ModeManager::currentMode()->id() != MODE_ANALYZE)
AnalyzerManager::showMode();
@@ -514,6 +537,22 @@ void QmlProfilerTool::showLoadDialog()
}
}
/*!
Checks if we have unsaved notes. If so, shows a warning dialog. Returns true if we can continue
with a potentially destructive operation and discard the warnings, or false if not. We don't
want to show a save/discard dialog here because that will often result in a confusing series of
different dialogs: first "save" and then immediately "load" or "connect".
*/
bool QmlProfilerTool::checkForUnsavedNotes()
{
if (!d->m_profilerModelManager->notesModel()->isModified())
return true;
return QMessageBox::warning(QApplication::activeWindow(), tr("QML Profiler"),
tr("You are about to discard the profiling data, including unsaved "
"notes. Do you want to continue?"),
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes;
}
void QmlProfilerTool::clientsDisconnected()
{
// If the application stopped by itself, check if we have all the data
@@ -646,13 +685,25 @@ void QmlProfilerTool::clientRecordingChanged()
void QmlProfilerTool::serverRecordingChanged()
{
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
setRecording(d->m_profilerState->serverRecording());
// clear the old data each time we start a new profiling session
if (d->m_profilerState->serverRecording()) {
// We cannot stop it here, so we cannot give the usual yes/no dialog. Show a dialog
// offering to immediately save the data instead.
if (d->m_profilerModelManager->notesModel()->isModified() &&
QMessageBox::warning(QApplication::activeWindow(), tr("QML Profiler"),
tr("Starting a new profiling session will discard the "
"previous data, including unsaved notes.\nDo you want "
"to save the data first?"),
QMessageBox::Save, QMessageBox::Discard) ==
QMessageBox::Save)
showSaveDialog();
setRecording(true);
d->m_clearButton->setEnabled(false);
clearData();
d->m_profilerModelManager->prepareForWriting();
} else {
setRecording(false);
d->m_clearButton->setEnabled(true);
}
} else {