aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/analyzerbase/ianalyzertool.h
blob: cc260260c3da947130c343191297d0ff10f769bd (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
** 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.
**
****************************************************************************/

#ifndef IANALYZERTOOL_H
#define IANALYZERTOOL_H

#include "analyzerbase_global.h"
#include "analyzerconstants.h"

#include <coreplugin/id.h>
#include <projectexplorer/projectexplorerconstants.h>

#include <QObject>
#include <QAction>

#include <functional>

namespace ProjectExplorer { class RunConfiguration; }

namespace Analyzer {

class AnalyzerStartParameters;
class AnalyzerRunControl;

/**
 * The mode in which this tool should preferably be run
 *
 * Debugging tools which try to show stack traces as close as possible to what the source code
 * looks like will prefer SymbolsMode. Profiling tools which need optimized code for realistic
 * performance, but still want to show analytical output that depends on debug symbols, will prefer
 * ProfileMode.
 */
enum ToolMode {
    DebugMode     = 0x1,
    ProfileMode   = 0x2,
    ReleaseMode   = 0x4,
    SymbolsMode   = DebugMode   | ProfileMode,
    OptimizedMode = ProfileMode | ReleaseMode,
    AnyMode       = DebugMode   | ProfileMode | ReleaseMode
};
Q_DECLARE_FLAGS(ToolModes, ToolMode)

/**
 * This class represents an analyzation action, i.e. a tool that runs in a specific mode.
 *
*/

class ANALYZER_EXPORT AnalyzerAction : public QAction
{
    Q_OBJECT

public:
    explicit AnalyzerAction(QObject *parent = 0);

public:
    Core::Id menuGroup() const { return m_menuGroup; }
    void setMenuGroup(Core::Id menuGroup) { m_menuGroup = menuGroup; }

    Core::Id actionId() const { return m_actionId; }
    void setActionId(Core::Id id) { m_actionId = id; }

    Core::Id toolId() const { return m_toolId; }
    void setToolId(Core::Id id) { m_toolId = id; }
    void setToolMode(QFlags<ToolMode> mode) { m_toolMode = mode; }

    Core::Id runMode() const { return m_runMode; }
    void setRunMode(Core::Id mode) { m_runMode = mode; }
    bool isRunnable(QString *reason = 0) const;

    /// Creates all widgets used by the tool.
    /// Returns a control widget which will be shown in the status bar when
    /// this tool is selected.
    typedef std::function<QWidget *()> WidgetCreator;
    QWidget *createWidget() const { return m_widgetCreator(); }
    void setWidgetCreator(const WidgetCreator &creator) { m_widgetCreator = creator; }

    /// Returns a new engine for the given start parameters.
    /// Called each time the tool is launched.
    typedef std::function<AnalyzerRunControl *(const AnalyzerStartParameters &,
        ProjectExplorer::RunConfiguration *runConfiguration, Core::Id runMode)> RunControlCreator;
    RunControlCreator runControlCreator() const { return m_runControlCreator; }
    void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; }

    typedef std::function<bool()> ToolPreparer;
    ToolPreparer toolPreparer() const { return m_toolPreparer; }
    void setToolPreparer(const ToolPreparer &toolPreparer) { m_toolPreparer = toolPreparer; }

    void startTool();

    /// This is only used for setups not using the startup project.
    typedef std::function<void()> ToolStarter;
    void setCustomToolStarter(const ToolStarter &toolStarter) { m_customToolStarter = toolStarter; }

protected:
    Core::Id m_menuGroup;
    Core::Id m_actionId;
    Core::Id m_toolId;
    QFlags<ToolMode> m_toolMode;
    Core::Id m_runMode;
    WidgetCreator m_widgetCreator;
    RunControlCreator m_runControlCreator;
    ToolStarter m_customToolStarter;
    ToolPreparer m_toolPreparer;
};

} // namespace Analyzer

#endif // IANALYZERTOOL_H