Commit 11a2d3dc authored by hjk's avatar hjk

Debugger: Consolidate Debugger view creation

Change-Id: I43353911c7c0c8250ee2bccddcf5fdccf04d457c
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 8d04a3aa
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "basewindow.h"
#include "debuggeractions.h"
#include "debuggercore.h"
#include <aggregation/aggregate.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/find/treeviewfind.h>
#include <utils/savedaction.h>
#include <utils/basetreeview.h>
#include <QVBoxLayout>
namespace Debugger {
namespace Internal {
BaseWindow::BaseWindow(QTreeView *treeView, QWidget *parent)
: QWidget(parent), m_treeView(treeView)
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
m_treeView->setAlternatingRowColors(act->isChecked());
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
if (Utils::BaseTreeView *tv = qobject_cast<Utils::BaseTreeView *>(m_treeView)) {
act = debuggerCore()->action(AlwaysAdjustColumnWidths);
tv->setAlwaysAdjustColumns(act->isChecked());
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlwaysAdjustColumns(bool)));
}
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
vbox->setSpacing(0);
vbox->addWidget(m_treeView);
vbox->addWidget(new Core::FindToolBarPlaceHolder(this));
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(m_treeView);
agg->add(new Core::TreeViewFind(m_treeView));
}
} // namespace Internal
} // namespace Debugger
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef DEBUGGER_BASEWINDOW_H
#define DEBUGGER_BASEWINDOW_H
#include <QTreeView>
namespace Debugger {
namespace Internal {
class BaseWindow : public QWidget
{
Q_OBJECT
public:
explicit BaseWindow(QTreeView *treeView, QWidget *parent = 0);
void setModel(QAbstractItemModel *model) { m_treeView->setModel(model); }
QHeaderView *header() const { return m_treeView->header(); }
QAbstractItemModel *model() const { return m_treeView->model(); }
QTreeView *treeView() const { return m_treeView; }
private:
QTreeView *m_treeView;
};
} // namespace Internal
} // namespace Debugger
#endif // DEBUGGER_BASEWINDOW_H
......@@ -674,8 +674,7 @@ MultiBreakPointsDialog::MultiBreakPointsDialog(QWidget *parent) :
//
///////////////////////////////////////////////////////////////////////
BreakTreeView::BreakTreeView(QWidget *parent)
: BaseTreeView(parent)
BreakTreeView::BreakTreeView()
{
setWindowIcon(QIcon(QLatin1String(":/debugger/images/debugger_breakpoints.png")));
setSelectionMode(QAbstractItemView::ExtendedSelection);
......@@ -952,12 +951,6 @@ void BreakTreeView::rowActivated(const QModelIndex &index)
breakHandler()->gotoLocation(breakHandler()->findBreakpointByIndex(index));
}
BreakWindow::BreakWindow()
: BaseWindow(new BreakTreeView)
{
setWindowTitle(tr("Breakpoints"));
}
} // namespace Internal
} // namespace Debugger
......
......@@ -31,7 +31,6 @@
#define DEBUGGER_BREAKWINDOW_H
#include "breakpoint.h"
#include "basewindow.h"
#include <utils/basetreeview.h>
namespace Debugger {
......@@ -42,7 +41,7 @@ class BreakTreeView : public Utils::BaseTreeView
Q_OBJECT
public:
explicit BreakTreeView(QWidget *parent = 0);
BreakTreeView();
static void editBreakpoint(BreakpointModelId id, QWidget *parent);
void setModel(QAbstractItemModel *model);
......@@ -64,14 +63,6 @@ private:
void setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled);
};
class BreakWindow : public BaseWindow
{
Q_OBJECT
public:
BreakWindow();
};
} // namespace Internal
} // namespace Debugger
......
......@@ -13,7 +13,6 @@ QT += gui \
CONFIG += exceptions
HEADERS += \
basewindow.h \
breakhandler.h \
breakpoint.h \
breakpointmarker.h \
......@@ -76,7 +75,6 @@ HEADERS += \
unstartedappwatcherdialog.h
SOURCES += \
basewindow.cpp \
breakhandler.cpp \
breakpoint.cpp \
breakpointmarker.cpp \
......
......@@ -28,7 +28,6 @@ QtcPlugin {
Group {
name: "General"
files: [
"basewindow.cpp", "basewindow.h",
"breakhandler.cpp", "breakhandler.h",
"breakpoint.cpp", "breakpoint.h",
"breakpointmarker.cpp", "breakpointmarker.h",
......
......@@ -41,6 +41,7 @@ QT_BEGIN_NAMESPACE
class QIcon;
class QMessageBox;
class QWidget;
class QTreeView;
QT_END_NAMESPACE
namespace CPlusPlus { class Snapshot; }
......@@ -122,6 +123,8 @@ public:
virtual DebuggerToolTipManager *toolTipManager() const = 0;
virtual QSharedPointer<GlobalDebuggerOptions> globalDebuggerOptions() const = 0;
static QTreeView *inspectorView();
public slots:
virtual void attachExternalApplication(ProjectExplorer::RunControl *rc) = 0;
};
......
......@@ -101,11 +101,13 @@
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <utils/basetreeview.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <utils/proxyaction.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <utils/statuslabel.h>
#include <utils/styledbar.h>
#include <utils/winutils.h>
#include <QApplication>
......@@ -121,6 +123,11 @@
#include <QToolButton>
#include <QtPlugin>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <aggregation/aggregate.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/find/treeviewfind.h>
#ifdef WITH_TESTS
#include <QTest>
......@@ -526,6 +533,36 @@ public:
//
///////////////////////////////////////////////////////////////////////
static QWidget *addSearch(BaseTreeView *treeView, const QString &title, const char *objectName)
{
QWidget *widget = new QWidget;
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
treeView->setAlternatingRowColors(act->isChecked());
QObject::connect(act, SIGNAL(toggled(bool)),
treeView, SLOT(setAlternatingRowColorsHelper(bool)));
act = debuggerCore()->action(AlwaysAdjustColumnWidths);
treeView->setAlwaysAdjustColumns(act->isChecked());
QObject::connect(act, SIGNAL(toggled(bool)),
treeView, SLOT(setAlwaysAdjustColumns(bool)));
QVBoxLayout *vbox = new QVBoxLayout(widget);
vbox->setMargin(0);
vbox->setSpacing(0);
vbox->addWidget(treeView);
vbox->addWidget(new Core::FindToolBarPlaceHolder(widget));
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(treeView);
agg->add(new Core::TreeViewFind(treeView));
widget->setObjectName(QLatin1String(objectName));
widget->setWindowTitle(title);
return widget;
}
static QString executableForPid(qint64 pid)
{
foreach (const DeviceProcessItem &p, DeviceProcessList::localProcesses())
......@@ -817,8 +854,8 @@ public slots:
void updateWatchersHeader(int section, int, int newSize)
{
m_watchersWindow->header()->resizeSection(section, newSize);
m_returnWindow->header()->resizeSection(section, newSize);
m_watchersView->header()->resizeSection(section, newSize);
m_returnView->header()->resizeSection(section, newSize);
}
......@@ -1240,18 +1277,30 @@ public:
StatusLabel *m_statusLabel;
QComboBox *m_threadBox;
BaseWindow *m_breakWindow;
BaseTreeView *m_breakView;
BaseTreeView *m_returnView;
BaseTreeView *m_localsView;
BaseTreeView *m_watchersView;
BaseTreeView *m_inspectorView;
BaseTreeView *m_registerView;
BaseTreeView *m_modulesView;
BaseTreeView *m_snapshotView;
BaseTreeView *m_sourceFilesView;
BaseTreeView *m_stackView;
BaseTreeView *m_threadsView;
QWidget *m_breakWindow;
BreakHandler *m_breakHandler;
WatchWindow *m_returnWindow;
WatchWindow *m_localsWindow;
WatchWindow *m_watchersWindow;
WatchWindow *m_inspectorWindow;
BaseWindow *m_registerWindow;
BaseWindow *m_modulesWindow;
BaseWindow *m_snapshotWindow;
BaseWindow *m_sourceFilesWindow;
BaseWindow *m_stackWindow;
BaseWindow *m_threadsWindow;
QWidget *m_returnWindow;
QWidget *m_localsWindow;
QWidget *m_watchersWindow;
QWidget *m_inspectorWindow;
QWidget *m_registerWindow;
QWidget *m_modulesWindow;
QWidget *m_snapshotWindow;
QWidget *m_sourceFilesWindow;
QWidget *m_stackWindow;
QWidget *m_threadsWindow;
LogWindow *m_logWindow;
LocalsAndExpressionsWindow *m_localsAndExpressionsWindow;
......@@ -2097,15 +2146,15 @@ void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine)
m_currentEngine->resetLocation();
m_currentEngine = engine;
m_localsWindow->setModel(engine->watchModel());
m_modulesWindow->setModel(engine->modulesModel());
m_registerWindow->setModel(engine->registerModel());
m_returnWindow->setModel(engine->watchModel());
m_sourceFilesWindow->setModel(engine->sourceFilesModel());
m_stackWindow->setModel(engine->stackModel());
m_threadsWindow->setModel(engine->threadsModel());
m_watchersWindow->setModel(engine->watchModel());
m_inspectorWindow->setModel(engine->watchModel());
m_localsView->setModel(engine->watchModel());
m_modulesView->setModel(engine->modulesModel());
m_registerView->setModel(engine->registerModel());
m_returnView->setModel(engine->watchModel());
m_sourceFilesView->setModel(engine->sourceFilesModel());
m_stackView->setModel(engine->stackModel());
m_threadsView->setModel(engine->threadsModel());
m_watchersView->setModel(engine->watchModel());
m_inspectorView->setModel(engine->watchModel());
mainWindow()->setEngineDebugLanguages(engine->startParameters().languages);
}
......@@ -2239,8 +2288,8 @@ void DebuggerPluginPrivate::updateWatchersWindow(bool showWatch, bool showReturn
void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
{
QTC_ASSERT(engine, return);
QTC_ASSERT(m_watchersWindow->model(), return);
QTC_ASSERT(m_returnWindow->model(), return);
QTC_ASSERT(m_watchersView->model(), return);
QTC_ASSERT(m_returnView->model(), return);
QTC_ASSERT(!engine->isSlaveEngine(), return);
m_threadBox->setCurrentIndex(engine->threadsHandler()->currentThreadIndex());
......@@ -2539,6 +2588,11 @@ QVariant DebuggerCore::sessionValue(const QByteArray &key)
return SessionManager::value(QString::fromUtf8(key));
}
QTreeView *DebuggerCore::inspectorView()
{
return theDebuggerCore->m_inspectorView;
}
void DebuggerPluginPrivate::openTextEditor(const QString &titlePattern0,
const QString &contents)
{
......@@ -2741,40 +2795,49 @@ void DebuggerPluginPrivate::extensionsInitialized()
m_statusLabel = new StatusLabel;
m_breakHandler = new BreakHandler;
m_breakWindow = new BreakWindow;
m_breakWindow->setObjectName(QLatin1String(DOCKWIDGET_BREAK));
m_breakWindow->setModel(m_breakHandler->model());
m_modulesWindow = new ModulesWindow;
m_modulesWindow->setObjectName(QLatin1String(DOCKWIDGET_MODULES));
m_logWindow = new LogWindow;
m_logWindow->setObjectName(QLatin1String(DOCKWIDGET_OUTPUT));
m_registerWindow = new RegisterWindow;
m_registerWindow->setObjectName(QLatin1String(DOCKWIDGET_REGISTER));
m_stackWindow = new StackWindow;
m_stackWindow->setObjectName(QLatin1String(DOCKWIDGET_STACK));
m_sourceFilesWindow = new SourceFilesWindow;
m_sourceFilesWindow->setObjectName(QLatin1String(DOCKWIDGET_SOURCE_FILES));
m_threadsWindow = new ThreadsWindow;
m_threadsWindow->setObjectName(QLatin1String(DOCKWIDGET_THREADS));
m_returnWindow = new WatchWindow(ReturnType);
m_returnWindow->setObjectName(QLatin1String("CppDebugReturn"));
m_localsWindow = new WatchWindow(LocalsType);
m_localsWindow->setObjectName(QLatin1String("CppDebugLocals"));
m_watchersWindow = new WatchWindow(WatchersType);
m_watchersWindow->setObjectName(QLatin1String("CppDebugWatchers"));
m_inspectorWindow = new WatchWindow(InspectType);
m_inspectorWindow->setObjectName(QLatin1String("Inspector"));
m_breakHandler = new BreakHandler;
m_breakView = new BreakTreeView;
m_breakView->setModel(m_breakHandler->model());
m_breakWindow = addSearch(m_breakView, tr("Breakpoints"), DOCKWIDGET_BREAK);
m_modulesView = new ModulesTreeView;
m_modulesWindow = addSearch(m_modulesView, tr("Modules"), DOCKWIDGET_MODULES);
m_registerView = new RegisterTreeView;
m_registerWindow = addSearch(m_registerView, tr("Registers"), DOCKWIDGET_REGISTER);
m_stackView = new StackTreeView;
m_stackWindow = addSearch(m_stackView, tr("Stack"), DOCKWIDGET_STACK);
m_sourceFilesView = new SourceFilesTreeView;
m_sourceFilesWindow = addSearch(m_sourceFilesView, tr("Source Files"), DOCKWIDGET_SOURCE_FILES);
m_threadsView = new ThreadsTreeView;
m_threadsWindow = addSearch(m_threadsView, tr("Threads"), DOCKWIDGET_THREADS);
m_returnView = new WatchTreeView(ReturnType);
m_returnWindow = addSearch(m_returnView, tr("Locals and Expressions"), "CppDebugReturn");
m_localsView = new WatchTreeView(LocalsType);
m_localsWindow = addSearch(m_localsView, tr("Locals and Expressions"), "CppDebugLocals");
m_watchersView = new WatchTreeView(WatchersType);
m_watchersWindow = addSearch(m_watchersView, tr("Locals and Expressions"), "CppDebugWatchers");
m_inspectorView = new WatchTreeView(InspectType);
m_inspectorWindow = addSearch(m_inspectorView, tr("Locals and Expressions"), "Inspector");
// Snapshot
m_snapshotHandler = new SnapshotHandler;
m_snapshotWindow = new SnapshotWindow(m_snapshotHandler);
m_snapshotWindow->setObjectName(QLatin1String(DOCKWIDGET_SNAPSHOTS));
m_snapshotWindow->setModel(m_snapshotHandler->model());
m_snapshotView = new SnapshotTreeView(m_snapshotHandler);
m_snapshotView->setModel(m_snapshotHandler->model());
m_snapshotWindow = addSearch(m_snapshotView, tr("Snapshots"), DOCKWIDGET_SNAPSHOTS);
// Watchers
connect(m_localsWindow->header(), SIGNAL(sectionResized(int,int,int)),
connect(m_localsView->header(), SIGNAL(sectionResized(int,int,int)),
SLOT(updateWatchersHeader(int,int,int)), Qt::QueuedConnection);
QAction *act = 0;
......
......@@ -53,8 +53,7 @@
namespace Debugger {
namespace Internal {
ModulesTreeView::ModulesTreeView(QWidget *parent)
: BaseTreeView(parent)
ModulesTreeView::ModulesTreeView()
{
setSortingEnabled(true);
......@@ -175,11 +174,5 @@ void ModulesTreeView::contextMenuEvent(QContextMenuEvent *ev)
QProcess::startDetached(QLatin1String("depends"), QStringList(fileName));
}
ModulesWindow::ModulesWindow()
: BaseWindow(new ModulesTreeView)
{
setWindowTitle(tr("Modules"));
}
} // namespace Internal
} // namespace Debugger
......@@ -30,7 +30,6 @@
#ifndef DEBUGGER_MODULESWINDOW_H
#define DEBUGGER_MODULESWINDOW_H
#include "basewindow.h"
#include <utils/basetreeview.h>
namespace Debugger {
......@@ -41,7 +40,7 @@ class ModulesTreeView : public Utils::BaseTreeView
Q_OBJECT
public:
explicit ModulesTreeView(QWidget *parent = 0);
ModulesTreeView();
private slots:
void moduleActivated(const QModelIndex &index);
......@@ -50,14 +49,6 @@ private:
void contextMenuEvent(QContextMenuEvent *ev);
};
class ModulesWindow : public BaseWindow
{
Q_OBJECT
public:
ModulesWindow();
};
} // namespace Internal
} // namespace Debugger
......
......@@ -80,6 +80,11 @@ using namespace AST;
namespace Debugger {
namespace Internal {
static QTreeView *inspectorTreeView()
{
return DebuggerCore::inspectorView();
}
class ASTWalker : public Visitor
{
public:
......@@ -1359,15 +1364,6 @@ bool QmlEngine::adjustBreakpointLineAndColumn(
return success;
}
WatchTreeView *QmlEngine::inspectorTreeView() const
{
DebuggerMainWindow *dw = qobject_cast<DebuggerMainWindow *>(debuggerCore()->mainWindow());
LocalsAndExpressionsWindow *leW = qobject_cast<LocalsAndExpressionsWindow *>(
dw->dockWidget(_(DOCKWIDGET_WATCHERS))->widget());
WatchWindow *inspectorWindow = qobject_cast<WatchWindow *>(leW->inspectorWidget());
return qobject_cast<WatchTreeView *>(inspectorWindow->treeView());
}
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &sp)
{
return new QmlEngine(sp);
......
......@@ -184,8 +184,6 @@ private:
bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
quint32 *column, bool *valid);
WatchTreeView *inspectorTreeView() const;
QmlAdapter m_adapter;
QmlInspectorAdapter m_inspectorAdapter;
ProjectExplorer::ApplicationLauncher m_applicationLauncher;
......
......@@ -157,8 +157,7 @@ public:
//
///////////////////////////////////////////////////////////////////////
RegisterTreeView::RegisterTreeView(QWidget *parent)
: BaseTreeView(parent)
RegisterTreeView::RegisterTreeView()
{
setItemDelegate(new RegisterDelegate(this));
}
......@@ -267,11 +266,5 @@ void RegisterTreeView::reloadRegisters()
currentEngine()->reloadRegisters();
}
RegisterWindow::RegisterWindow()
: BaseWindow(new RegisterTreeView)
{
setWindowTitle(tr("Registers"));
}
} // namespace Internal
} // namespace Debugger
......@@ -30,7 +30,6 @@
#ifndef DEBUGGER_REGISTERWINDOW_H
#define DEBUGGER_REGISTERWINDOW_H
#include "basewindow.h"
#include <utils/basetreeview.h>
namespace Debugger {
......@@ -41,7 +40,7 @@ class RegisterTreeView : public Utils::BaseTreeView
Q_OBJECT
public:
explicit RegisterTreeView(QWidget *parent = 0);
RegisterTreeView();
public slots:
void reloadRegisters();
......@@ -50,14 +49,6 @@ private:
void contextMenuEvent(QContextMenuEvent *ev);
};
class RegisterWindow : public BaseWindow
{
Q_OBJECT
public:
RegisterWindow();
};
} // namespace Internal
} // namespace Debugger
......
......@@ -30,7 +30,6 @@
#ifndef DEBUGGER_SNAPSHOTWINDOW_H
#define DEBUGGER_SNAPSHOTWINDOW_H
#include "basewindow.h"
#include <utils/basetreeview.h>
namespace Debugger {
......@@ -54,17 +53,6 @@ private:
SnapshotHandler *m_snapshotHandler;
};
class SnapshotWindow : public BaseWindow
{
Q_OBJECT
public:
explicit SnapshotWindow(SnapshotHandler *handler)
: BaseWindow(new SnapshotTreeView(handler))
{
setWindowTitle(tr("Snapshots"));
}
};