From 25d351fa0a52849720f7ed2c8b64f2fe1df55b26 Mon Sep 17 00:00:00 2001 From: Aurindam Jana <aurindam.jana@nokia.com> Date: Wed, 16 Nov 2011 17:06:00 +0100 Subject: [PATCH] QMLProfiler: Menu entries to load/save QML trace Added 'QML Profiler Options' menu to 'Analyze' menu to load and save QML traces. Change-Id: I468fbcfdf355a1caaa0d53b118f0b8b505cedefb Reviewed-by: hjk <qthjk@ovi.com> Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com> --- src/plugins/analyzerbase/analyzerconstants.h | 2 + src/plugins/analyzerbase/analyzermanager.cpp | 12 ++++ src/plugins/analyzerbase/analyzermanager.h | 1 + src/plugins/qmlprofiler/qmlprofilertool.cpp | 66 ++++++++++++++++---- src/plugins/qmlprofiler/qmlprofilertool.h | 1 + 5 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/plugins/analyzerbase/analyzerconstants.h b/src/plugins/analyzerbase/analyzerconstants.h index 3a4c9b32354..3280e61f955 100644 --- a/src/plugins/analyzerbase/analyzerconstants.h +++ b/src/plugins/analyzerbase/analyzerconstants.h @@ -62,10 +62,12 @@ const char C_ANALYZEMODE[] = "Analyzer.AnalyzeMode"; // Menu. const char M_DEBUG_ANALYZER[] = "Analyzer.Menu.StartAnalyzer"; +const char M_DEBUG_ANALYZER_QML_OPTIONS[] = "Analyzer.Menu.QMLOptions"; const char G_ANALYZER_CONTROL[] = "Menu.Group.Analyzer.Control"; const char G_ANALYZER_TOOLS[] = "Menu.Group.Analyzer.Tools"; const char G_ANALYZER_REMOTE_TOOLS[] = "Menu.Group.Analyzer.RemoteTools"; +const char G_ANALYZER_OPTIONS[] = "Menu.Group.Analyzer.Options"; // Manager controls. const char ANALYZER_CONTROL_START_ICON[] = ":/images/analyzer_start_small.png"; diff --git a/src/plugins/analyzerbase/analyzermanager.cpp b/src/plugins/analyzerbase/analyzermanager.cpp index 1e8d3238493..ef517e3b51b 100644 --- a/src/plugins/analyzerbase/analyzermanager.cpp +++ b/src/plugins/analyzerbase/analyzermanager.cpp @@ -278,6 +278,7 @@ void AnalyzerManagerPrivate::setupActions() m_menu->appendGroup(Constants::G_ANALYZER_CONTROL); m_menu->appendGroup(Constants::G_ANALYZER_TOOLS); m_menu->appendGroup(Constants::G_ANALYZER_REMOTE_TOOLS); + m_menu->appendGroup(Constants::G_ANALYZER_OPTIONS); Core::ActionContainer *menubar = am->actionContainer(Core::Constants::MENU_BAR); @@ -307,6 +308,12 @@ void AnalyzerManagerPrivate::setupActions() command = am->registerAction(separatorAction2, "Menu.Action.Analyzer.Tools.Separator2", globalcontext); m_menu->addAction(command, Constants::G_ANALYZER_REMOTE_TOOLS); + + QAction *separatorAction3 = new QAction(m_menu); + separatorAction3->setSeparator(true); + command = am->registerAction(separatorAction3, + "Menu.Action.Analyzer.Tools.Separator3", globalcontext); + m_menu->addAction(command, Constants::G_ANALYZER_OPTIONS); } void AnalyzerManagerPrivate::delayedInit() @@ -846,6 +853,11 @@ QDockWidget *AnalyzerManager::createDockWidget(IAnalyzerTool *tool, const QStrin return dockWidget; } +IAnalyzerTool *AnalyzerManager::currentSelectedTool() +{ + return m_instance->d->m_currentTool; +} + void AnalyzerManager::selectTool(IAnalyzerTool *tool, StartMode mode) { m_instance->d->selectTool(tool, mode); diff --git a/src/plugins/analyzerbase/analyzermanager.h b/src/plugins/analyzerbase/analyzermanager.h index 18dc9566054..30e987e1b60 100644 --- a/src/plugins/analyzerbase/analyzermanager.h +++ b/src/plugins/analyzerbase/analyzermanager.h @@ -82,6 +82,7 @@ public: static Utils::FancyMainWindow *mainWindow(); static void showMode(); + static IAnalyzerTool *currentSelectedTool(); static void selectTool(IAnalyzerTool *tool, StartMode mode); static void startTool(IAnalyzerTool *tool, StartMode mode); static void stopTool(); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index a676fd1a833..71d7ea915cd 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -67,6 +67,11 @@ #include <coreplugin/icore.h> #include <coreplugin/messagemanager.h> #include <coreplugin/helpmanager.h> +#include <coreplugin/modemanager.h> +#include <coreplugin/imode.h> +#include <coreplugin/actionmanager/command.h> +#include <coreplugin/actionmanager/actionmanager.h> +#include <coreplugin/actionmanager/actioncontainer.h> #include <qt4projectmanager/qt4buildconfiguration.h> #include <qt4projectmanager/qt-s60/s60deployconfiguration.h> @@ -83,7 +88,10 @@ #include <QtGui/QFileDialog> #include <QtGui/QMenu> +using namespace Core; +using namespace Core::Constants; using namespace Analyzer; +using namespace Analyzer::Constants; using namespace QmlProfiler::Internal; using namespace QmlJsDebugClient; using namespace ProjectExplorer; @@ -119,6 +127,7 @@ public: quint64 m_tcpPort; QString m_ostDevice; QString m_sysroot; + QAction *m_saveQmlTrace; }; QmlProfilerTool::QmlProfilerTool(QObject *parent) @@ -142,6 +151,27 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent) qmlRegisterType<CanvasImage>(); qmlRegisterType<CanvasGradient>(); qmlRegisterType<TimelineView>("Monitor", 1, 0,"TimelineView"); + + Command *command = 0; + const Context globalContext(C_GLOBAL); + ActionManager *am = ICore::instance()->actionManager(); + + ActionContainer *menu = am->actionContainer(M_DEBUG_ANALYZER); + ActionContainer *options = am->createMenu(M_DEBUG_ANALYZER_QML_OPTIONS); + options->menu()->setTitle(tr("QML Profiler Options")); + menu->addMenu(options, G_ANALYZER_OPTIONS); + options->menu()->setEnabled(true); + + QAction *act = new QAction(tr("Load QML Trace"), options); + command = am->registerAction(act, "Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.LoadQMLTrace", globalContext); + connect(act, SIGNAL(triggered()), this, SLOT(showLoadDialog())); + options->addAction(command); + + act = d->m_saveQmlTrace = new QAction(tr("Save QML Trace"), options); + d->m_saveQmlTrace->setEnabled(false); + command = am->registerAction(act, "Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.SaveQMLTrace", globalContext); + connect(act, SIGNAL(triggered()), this, SLOT(showSaveDialog())); + options->addAction(command); } QmlProfilerTool::~QmlProfilerTool() @@ -312,7 +342,7 @@ IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp connect(d->m_traceWindow, SIGNAL(viewUpdated()), engine, SLOT(dataReceived())); connect(this, SIGNAL(connectionFailed()), engine, SLOT(finishProcess())); connect(this, SIGNAL(fetchingData(bool)), engine, SLOT(setFetchingData(bool))); - connect(engine, SIGNAL(starting(const Analyzer::IAnalyzerEngine*)), this, SLOT(setAppIsRunning())); + connect(engine, SIGNAL(starting(const IAnalyzerEngine*)), this, SLOT(setAppIsRunning())); connect(engine, SIGNAL(finished()), this, SLOT(setAppIsStopped())); connect(this, SIGNAL(cancelRun()), engine, SLOT(finishProcess())); emit fetchingData(d->m_recordButton->isChecked()); @@ -337,6 +367,7 @@ QWidget *QmlProfilerTool::createWidgets() connect(d->m_traceWindow, SIGNAL(timeChanged(qreal)), this, SLOT(updateTimer(qreal))); connect(d->m_traceWindow, SIGNAL(contextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); connect(d->m_traceWindow->getEventList(), SIGNAL(error(QString)), this, SLOT(showErrorDialog(QString))); + connect(d->m_traceWindow->getEventList(), SIGNAL(dataReady()), this, SLOT(showSaveOption())); d->m_eventsView = new QmlProfilerEventsWidget(d->m_traceWindow->getEventList(), mw); connect(d->m_eventsView, SIGNAL(gotoSourceLocation(QString,int)), this, SLOT(gotoSourceLocation(QString,int))); @@ -493,8 +524,8 @@ void QmlProfilerTool::gotoSourceLocation(const QString &fileUrl, int lineNumber) if (!fileInfo.exists() || !fileInfo.isReadable()) return; - Core::EditorManager *editorManager = Core::EditorManager::instance(); - Core::IEditor *editor = editorManager->openEditor(projectFileName); + EditorManager *editorManager = EditorManager::instance(); + IEditor *editor = editorManager->openEditor(projectFileName); TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor); if (textEditor) { @@ -532,7 +563,7 @@ static void startRemoteTool(IAnalyzerTool *tool, StartMode mode) QString sysroot; { - QSettings *settings = Core::ICore::instance()->settings(); + QSettings *settings = ICore::instance()->settings(); host = settings->value(QLatin1String("AnalyzerQmlAttachDialog/host"), QLatin1String("localhost")).toString(); port = settings->value(QLatin1String("AnalyzerQmlAttachDialog/port"), 3768).toInt(); @@ -580,7 +611,7 @@ void QmlProfilerTool::tryToConnect() d->m_connectionTimer.stop(); d->m_connectionAttempts = 0; - Core::ICore * const core = Core::ICore::instance(); + ICore * const core = ICore::instance(); QMessageBox *infoBox = new QMessageBox(core->mainWindow()); infoBox->setIcon(QMessageBox::Critical); infoBox->setWindowTitle(tr("Qt Creator")); @@ -665,20 +696,25 @@ void QmlProfilerTool::startTool(StartMode mode) void QmlProfilerTool::logStatus(const QString &msg) { - Core::MessageManager *messageManager = Core::MessageManager::instance(); + MessageManager *messageManager = MessageManager::instance(); messageManager->printToOutputPane(msg, false); } void QmlProfilerTool::logError(const QString &msg) { // TODO: Rather show errors in the application ouput - Core::MessageManager *messageManager = Core::MessageManager::instance(); + MessageManager *messageManager = MessageManager::instance(); messageManager->printToOutputPane(msg, true); } +void QmlProfilerTool::showSaveOption() +{ + d->m_saveQmlTrace->setEnabled(d->m_traceWindow->getEventList()->count()); +} + void QmlProfilerTool::showSaveDialog() { - Core::ICore *core = Core::ICore::instance(); + ICore *core = ICore::instance(); QString filename = QFileDialog::getSaveFileName(core->mainWindow(), tr("Save QML Trace"), QString(), tr("QML traces (*%1)").arg(TraceFileExtension)); if (!filename.isEmpty()) { if (!filename.endsWith(QLatin1String(TraceFileExtension))) @@ -689,19 +725,25 @@ void QmlProfilerTool::showSaveDialog() void QmlProfilerTool::showLoadDialog() { - Core::ICore *core = Core::ICore::instance(); + if (ModeManager::instance()->currentMode()->id() != QLatin1String(MODE_ANALYZE)) + AnalyzerManager::showMode(); + + if (AnalyzerManager::currentSelectedTool() != this) + AnalyzerManager::selectTool(this, StartRemote); + + ICore *core = ICore::instance(); QString filename = QFileDialog::getOpenFileName(core->mainWindow(), tr("Load QML Trace"), QString(), tr("QML traces (*%1)").arg(TraceFileExtension)); if (!filename.isEmpty()) { // delayed load (prevent graphical artifacts due to long load time) - d->m_traceWindow->getEventList()->setFilename(filename); + d->m_traceWindow->getEventList()->load(filename); QTimer::singleShot(100, d->m_traceWindow->getEventList(), SLOT(load())); } } void QmlProfilerTool::showErrorDialog(const QString &error) { - Core::ICore *core = Core::ICore::instance(); + ICore *core = ICore::instance(); QMessageBox *errorDialog = new QMessageBox(core->mainWindow()); errorDialog->setIcon(QMessageBox::Warning); errorDialog->setWindowTitle(tr("QML Profiler")); @@ -721,7 +763,7 @@ void QmlProfilerTool::retryMessageBoxFinished(int result) break; } case QMessageBox::Help: { - Core::HelpManager *helpManager = Core::HelpManager::instance(); + HelpManager *helpManager = HelpManager::instance(); helpManager->handleHelpRequest("qthelp://com.nokia.qtcreator/doc/creator-debugging-qml.html"); // fall through } diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h index 9c90f7f22ac..545c5e85d47 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.h +++ b/src/plugins/qmlprofiler/qmlprofilertool.h @@ -92,6 +92,7 @@ signals: private slots: void tryToConnect(); void connectionStateChanged(); + void showSaveOption(); void showSaveDialog(); void showLoadDialog(); void showErrorDialog(const QString &error); -- GitLab