Debugger: Tighten Perspective interface

Pass id in constructor, so it can be const.

Change-Id: Id33fe19c4416109af8aa05a3ed0a09918eeb5cdf
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2018-08-13 09:34:47 +02:00
parent 1d68e08359
commit 1567679b81
8 changed files with 49 additions and 64 deletions

View File

@@ -269,7 +269,7 @@ ClangTidyClazyTool::ClangTidyClazyTool()
const QString toolTip = tr("Clang-Tidy and Clazy use a customized Clang executable from the "
"Clang project to search for errors and warnings.");
auto perspective = new Perspective(tr("Clang-Tidy and Clazy"));
auto perspective = new Perspective(ClangTidyClazyPerspectiveId, tr("Clang-Tidy and Clazy"));
perspective->addWindow(m_diagnosticView, Perspective::SplitVertical, nullptr);
action = new QAction(tr("Clang-Tidy and Clazy..."), this);
@@ -289,7 +289,7 @@ ClangTidyClazyTool::ClangTidyClazyTool()
perspective->addToolbarWidget(m_filterLineEdit);
perspective->addToolbarWidget(m_applyFixitsButton);
Debugger::registerPerspective(ClangTidyClazyPerspectiveId, perspective);
Debugger::registerPerspective(perspective);
updateRunActions();

View File

@@ -62,7 +62,7 @@ DEBUGGER_EXPORT bool wantRunTool(ToolMode toolMode, const QString &toolName);
DEBUGGER_EXPORT void showCannotStartDialog(const QString &toolName);
// Register a tool for a given start mode.
DEBUGGER_EXPORT void registerPerspective(const QByteArray &perspectiveId, Utils::Perspective *perspective);
DEBUGGER_EXPORT void registerPerspective(Utils::Perspective *perspective);
DEBUGGER_EXPORT void destroyDynamicPerspective(const QByteArray &perspectiveId);
DEBUGGER_EXPORT void setPerspectiveEnabled(const QByteArray &perspectiveId, bool enable);

View File

@@ -102,10 +102,9 @@ DebuggerMainWindow::~DebuggerMainWindow()
delete perspective;
}
void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, Perspective *perspective)
void DebuggerMainWindow::registerPerspective(Perspective *perspective)
{
m_perspectives.append(perspective);
perspective->m_id = perspectiveId;
QByteArray parentPerspective = perspective->parentPerspective();
// Add "main" perspectives to the chooser.
if (parentPerspective.isEmpty()) {
@@ -481,6 +480,13 @@ void DebuggerMainWindow::savePerspectiveHelper(const Perspective *perspective)
settings->setValue(QLatin1String(LAST_PERSPECTIVE_KEY), perspective->m_id);
}
// Perspective
Perspective::Perspective(const QByteArray &id, const QString &name)
: m_id(id), m_name(name)
{
}
Perspective::~Perspective()
{
for (const ToolbarOperation &op : m_toolbarOperations) {
@@ -501,11 +507,6 @@ QString Perspective::name() const
return m_name;
}
void Perspective::setName(const QString &name)
{
m_name = name;
}
void Perspective::setAboutToActivateCallback(const Perspective::Callback &cb)
{
m_aboutToActivateCallback = cb;
@@ -563,11 +564,6 @@ QWidget *Perspective::centralWidget() const
return m_centralWidget;
}
Perspective::Perspective(const QString &name)
: m_name(name)
{
}
void Perspective::addWindow(QWidget *widget, OperationType type, QWidget *anchorWidget,
bool visibleByDefault, Qt::DockWidgetArea area)
{

View File

@@ -51,8 +51,7 @@ class DEBUGGER_EXPORT Perspective
public:
enum OperationType { SplitVertical, SplitHorizontal, AddToTab, Raise };
Perspective() = default;
explicit Perspective(const QString &name);
explicit Perspective(const QByteArray &id, const QString &name);
~Perspective();
void setCentralWidget(QWidget *centralWidget);
@@ -69,7 +68,6 @@ public:
QWidget *centralWidget() const;
QString name() const;
void setName(const QString &name);
using Callback = std::function<void()>;
void setAboutToActivateCallback(const Callback &cb);
@@ -104,7 +102,7 @@ private:
QIcon icon;
};
QByteArray m_id;
const QByteArray m_id;
QString m_name;
QByteArray m_parentPerspective;
QVector<Operation> m_operations;
@@ -121,7 +119,7 @@ public:
DebuggerMainWindow();
~DebuggerMainWindow() override;
void registerPerspective(const QByteArray &perspectiveId, Perspective *perspective);
void registerPerspective(Perspective *perspective);
void destroyDynamicPerspective(Perspective *perspective);
void resetCurrentPerspective();

View File

@@ -1828,45 +1828,37 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
// qmlToolbar.addAction(qmlSelectDummyAction, Icons::SELECT_TOOLBAR.icon());
// qmlToolbar.addWidget(new StyledSeparator);
auto createBasePerspective = [this] {
auto perspective = new Perspective("Debugger");
perspective->addWindow(m_stackWindow, Perspective::SplitVertical, nullptr);
perspective->addWindow(m_breakWindow, Perspective::SplitHorizontal, m_stackWindow);
perspective->addWindow(m_threadsWindow, Perspective::AddToTab, m_breakWindow, false);
perspective->addWindow(m_modulesWindow, Perspective::AddToTab, m_threadsWindow, false);
perspective->addWindow(m_sourceFilesWindow, Perspective::AddToTab, m_modulesWindow, false);
perspective->addWindow(m_snapshotWindow, Perspective::AddToTab, m_sourceFilesWindow, false);
perspective->addWindow(m_localsAndInspectorWindow, Perspective::AddToTab, nullptr, true,
Qt::RightDockWidgetArea);
perspective->addWindow(m_watchersWindow, Perspective::AddToTab, m_localsAndInspectorWindow, true,
Qt::RightDockWidgetArea);
perspective->addWindow(m_logWindow, Perspective::AddToTab, nullptr, false, Qt::TopDockWidgetArea);
perspective->addWindow(m_breakWindow, Perspective::Raise, nullptr);
auto perspective = new Perspective("Debugger", tr("Debugger"));
perspective->addWindow(m_stackWindow, Perspective::SplitVertical, nullptr);
perspective->addWindow(m_breakWindow, Perspective::SplitHorizontal, m_stackWindow);
perspective->addWindow(m_threadsWindow, Perspective::AddToTab, m_breakWindow, false);
perspective->addWindow(m_modulesWindow, Perspective::AddToTab, m_threadsWindow, false);
perspective->addWindow(m_sourceFilesWindow, Perspective::AddToTab, m_modulesWindow, false);
perspective->addWindow(m_snapshotWindow, Perspective::AddToTab, m_sourceFilesWindow, false);
perspective->addWindow(m_localsAndInspectorWindow, Perspective::AddToTab, nullptr, true,
Qt::RightDockWidgetArea);
perspective->addWindow(m_watchersWindow, Perspective::AddToTab, m_localsAndInspectorWindow, true,
Qt::RightDockWidgetArea);
perspective->addWindow(m_logWindow, Perspective::AddToTab, nullptr, false, Qt::TopDockWidgetArea);
perspective->addWindow(m_breakWindow, Perspective::Raise, nullptr);
perspective->addWindow(m_registerWindow, Perspective::AddToTab, m_snapshotWindow, false);
perspective->addToolbarAction(m_visibleStartAction);
perspective->addToolbarAction(ActionManager::command(Constants::STOP)->action(), Icons::DEBUG_EXIT_SMALL_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::NEXT)->action(), Icons::STEP_OVER_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::STEP)->action(), Icons::STEP_INTO_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::STEPOUT)->action(), Icons::STEP_OUT_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::RESET)->action(), Icons::RESTART_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::OPERATE_BY_INSTRUCTION)->action());
perspective->addToolbarAction(m_visibleStartAction);
perspective->addToolbarAction(ActionManager::command(Constants::STOP)->action(), Icons::DEBUG_EXIT_SMALL_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::NEXT)->action(), Icons::STEP_OVER_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::STEP)->action(), Icons::STEP_INTO_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::STEPOUT)->action(), Icons::STEP_OUT_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::RESET)->action(), Icons::RESTART_TOOLBAR.icon());
perspective->addToolbarAction(ActionManager::command(Constants::OPERATE_BY_INSTRUCTION)->action());
if (isReverseDebuggingEnabled())
perspective->addToolbarWidget(m_reverseToolButton);
if (isReverseDebuggingEnabled())
perspective->addToolbarWidget(m_reverseToolButton);
perspective->addToolbarSeparator();
perspective->addToolbarWidget(m_threadLabel);
perspective->addToolbarWidget(m_threadBox);
perspective->addToolbarSeparator();
perspective->addToolbarWidget(m_threadLabel);
perspective->addToolbarWidget(m_threadBox);
return perspective;
};
Perspective *cppPerspective = createBasePerspective();
cppPerspective->setName(tr("Debugger"));
cppPerspective->addWindow(m_registerWindow, Perspective::AddToTab, m_snapshotWindow, false);
Debugger::registerPerspective(CppPerspectiveId, cppPerspective);
Debugger::registerPerspective(perspective);
// Perspective *qmlPerspective = createBasePerspective();
// qmlPerspective->setName(tr("QML Debugger"));
@@ -3510,9 +3502,9 @@ QAction *createStopAction()
return action;
}
void registerPerspective(const QByteArray &perspectiveId, Perspective *perspective)
void registerPerspective(Perspective *perspective)
{
dd->m_mainWindow->registerPerspective(perspectiveId, perspective);
dd->m_mainWindow->registerPerspective(perspective);
}
void setPerspectiveEnabled(const QByteArray &perspectiveId, bool enabled)

View File

@@ -61,8 +61,7 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent,
new QmlProfilerStateWidget(m_profilerState, m_profilerModelManager, m_traceView);
m_perspective = new Utils::Perspective;
m_perspective->setName(tr("QML Profiler"));
m_perspective = new Utils::Perspective(Constants::QmlProfilerPerspectiveId, tr("QML Profiler"));
auto prepareEventsView = [this](QmlProfilerEventsView *view) {
connect(view, &QmlProfilerEventsView::typeSelected,
@@ -95,7 +94,7 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent,
m_perspective->addWindow(m_statisticsView, Perspective::AddToTab, anchor);
m_perspective->addWindow(anchor, Perspective::Raise, nullptr);
Debugger::registerPerspective(Constants::QmlProfilerPerspectiveId, m_perspective);
Debugger::registerPerspective(m_perspective);
}
QmlProfilerViewManager::~QmlProfilerViewManager()

View File

@@ -419,7 +419,7 @@ CallgrindTool::CallgrindTool()
this, &CallgrindTool::setCostEvent);
updateEventCombo();
auto perspective = new Perspective(tr("Callgrind"));
auto perspective = new Perspective(CallgrindPerspectiveId, tr("Callgrind"));
perspective->addToolbarAction(m_startAction);
perspective->addToolbarAction(m_stopAction);
perspective->addToolbarAction(m_loadExternalLogFile);
@@ -510,7 +510,7 @@ CallgrindTool::CallgrindTool()
perspective->addWindow(m_callersView, Perspective::SplitHorizontal, m_calleesView);
perspective->addWindow(m_visualization, Perspective::SplitVertical, nullptr,
false, Qt::RightDockWidgetArea);
Debugger::registerPerspective(CallgrindPerspectiveId, perspective);
Debugger::registerPerspective(perspective);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
this, &CallgrindTool::updateRunActions);

View File

@@ -556,7 +556,7 @@ MemcheckTool::MemcheckTool()
m_errorView->setObjectName(QLatin1String("Valgrind.MemcheckTool.ErrorView"));
m_errorView->setWindowTitle(tr("Memory Issues"));
auto perspective = new Perspective(tr("Memcheck"));
auto perspective = new Perspective(MemcheckPerspectiveId, tr("Memcheck"));
perspective->addWindow(m_errorView, Perspective::SplitVertical, nullptr);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
@@ -690,7 +690,7 @@ MemcheckTool::MemcheckTool()
perspective->addToolbarAction(m_goBack);
perspective->addToolbarAction(m_goNext);
perspective->addToolbarWidget(filterButton);
Debugger::registerPerspective(MemcheckPerspectiveId, perspective);
Debugger::registerPerspective(perspective);
updateFromSettings();
maybeActiveRunConfigurationChanged();