aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprofiler/qmlprofileractions.cpp
blob: 3fd754a4eb0a9f9b97bc63173a4901db02baef98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#include "qmlprofileractions.h"
#include "qmlprofilerconstants.h"
#include "qmlprofilertool.h"
#include "qmlprofilerstatemanager.h"
#include "qmlprofilermodelmanager.h"

#include <debugger/analyzer/analyzerconstants.h>

#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>

#include <QMenu>

namespace QmlProfiler {
namespace Internal {

using namespace Core;
using namespace Debugger::Constants;

QmlProfilerActions::QmlProfilerActions(QObject *parent) : QObject(parent)
{}

void QmlProfilerActions::attachToTool(QmlProfilerTool *tool)
{
    const QString description = tr("The QML Profiler can be used to find performance "
                                   "bottlenecks in applications using QML.");

    m_runAction = std::make_unique<QAction>(tr("QML Profiler"));
    m_runAction->setToolTip(description);
    QObject::connect(m_runAction.get(), &QAction::triggered,
                     tool, &QmlProfilerTool::profileStartupProject);

    QAction *toolStartAction = tool->startAction();
    QObject::connect(toolStartAction, &QAction::changed, this, [this, toolStartAction] {
        m_runAction->setEnabled(toolStartAction->isEnabled());
    });

    m_attachAction = std::make_unique<QAction>(tr("QML Profiler (Attach to Waiting Application)"));
    m_attachAction->setToolTip(description);
    QObject::connect(m_attachAction.get(), &QAction::triggered,
                     tool, &QmlProfilerTool::attachToWaitingApplication);

    m_loadQmlTrace = std::make_unique<QAction>(tr("Load QML Trace"));
    connect(m_loadQmlTrace.get(), &QAction::triggered,
            tool, &QmlProfilerTool::showLoadDialog, Qt::QueuedConnection);

    m_saveQmlTrace = std::make_unique<QAction>(tr("Save QML Trace"));
    connect(m_saveQmlTrace.get(), &QAction::triggered,
            tool, &QmlProfilerTool::showSaveDialog, Qt::QueuedConnection);

    QmlProfilerStateManager *stateManager = tool->stateManager();
    connect(stateManager, &QmlProfilerStateManager::serverRecordingChanged,
            this, [this, stateManager](bool recording) {
        m_loadQmlTrace->setEnabled(!recording);
    });
    m_loadQmlTrace->setEnabled(!stateManager->serverRecording());

    QmlProfilerModelManager *modelManager = tool->modelManager();
    connect(modelManager, &QmlProfilerModelManager::traceChanged,
            this, [this, modelManager] {
        m_saveQmlTrace->setEnabled(!modelManager->isEmpty());
    });
    m_saveQmlTrace->setEnabled(!modelManager->isEmpty());
}

void QmlProfilerActions::registerActions()
{
    m_options.reset(ActionManager::createMenu("Analyzer.Menu.QMLOptions"));
    m_options->menu()->setTitle(tr("QML Profiler Options"));
    m_options->menu()->setEnabled(true);
    ActionContainer *menu = ActionManager::actionContainer(M_DEBUG_ANALYZER);

    menu->addAction(ActionManager::registerAction(m_runAction.get(),
                                                  "QmlProfiler.Internal"),
                    Debugger::Constants::G_ANALYZER_TOOLS);
    menu->addAction(ActionManager::registerAction(m_attachAction.get(),
                                                  "QmlProfiler.AttachToWaitingApplication"),
                    Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);

    menu->addMenu(m_options.get(), G_ANALYZER_OPTIONS);
    m_options->addAction(ActionManager::registerAction(m_loadQmlTrace.get(),
                                                       Constants::QmlProfilerLoadActionId));
    m_options->addAction(ActionManager::registerAction(m_saveQmlTrace.get(),
                                                       Constants::QmlProfilerSaveActionId));
}

} // namespace Internal
} // namespace QmlProfiler