Commit 2d79bdc2 authored by hjk's avatar hjk Committed by hjk

Debugger: Remove some uses of semi-global currentEngine()

Make use of recent TreeModel improvements in various
tool views, push more operations into the engine-
owned data models, specifically context menu creation.

Change-Id: I479c97102b9fb81611c6461c6df1cec59295179a
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
Reviewed-by: default avatarhjk <hjk@qt.io>
parent 84f1466b
......@@ -248,6 +248,7 @@ BaseTreeView::BaseTreeView(QWidget *parent)
setSelectionMode(QAbstractItemView::ExtendedSelection);
setUniformRowHeights(true);
setItemDelegate(new BaseTreeViewDelegate(this));
setAlternatingRowColors(false);
QHeaderView *h = header();
h->setDefaultAlignment(Qt::AlignLeft);
......@@ -303,6 +304,13 @@ void BaseTreeView::setModel(QAbstractItemModel *m)
connect(model(), c[i].qsignal, c[i].receiver, c[i].qslot);
}
d->restoreState();
QVariant delegateBlob = m->data(QModelIndex(), ItemDelegateRole);
if (delegateBlob.isValid()) {
auto delegate = delegateBlob.value<QAbstractItemDelegate *>();
delegate->setParent(this);
setItemDelegate(delegate);
}
}
}
......@@ -314,6 +322,44 @@ void BaseTreeView::mousePressEvent(QMouseEvent *ev)
d->toggleColumnWidth(columnAt(ev->x()));
}
void BaseTreeView::contextMenuEvent(QContextMenuEvent *ev)
{
QPoint pos = ev->pos();
QModelIndex index = indexAt(pos);
if (!model()->setData(index, describeEvent(ev, pos, index), ItemViewEventRole))
TreeView::contextMenuEvent(ev);
}
void BaseTreeView::keyPressEvent(QKeyEvent *ev)
{
if (!model()->setData(QModelIndex(), describeEvent(ev), ItemViewEventRole))
TreeView::keyPressEvent(ev);
}
void BaseTreeView::dragEnterEvent(QDragEnterEvent *ev)
{
if (!model()->setData(QModelIndex(), describeEvent(ev), ItemViewEventRole))
TreeView::dragEnterEvent(ev);
}
void BaseTreeView::dropEvent(QDropEvent *ev)
{
if (!model()->setData(QModelIndex(), describeEvent(ev), ItemViewEventRole))
TreeView::dropEvent(ev);
}
void BaseTreeView::dragMoveEvent(QDragMoveEvent *ev)
{
if (!model()->setData(QModelIndex(), describeEvent(ev), ItemViewEventRole))
TreeView::dragMoveEvent(ev);
}
void BaseTreeView::mouseDoubleClickEvent(QMouseEvent *ev)
{
if (!model()->setData(QModelIndex(), describeEvent(ev), ItemViewEventRole))
TreeView::mouseDoubleClickEvent(ev);
}
void BaseTreeView::showEvent(QShowEvent *ev)
{
emit aboutToShow();
......@@ -346,6 +392,35 @@ void BaseTreeView::hideProgressIndicator()
d->m_progressIndicator->hide();
}
QVariant BaseTreeView::describeEvent(QEvent *ev, const QPoint &pos, const QModelIndex &idx)
{
ItemViewEvent event;
event.m_view = this;
event.m_event = ev;
event.m_pos = pos;
event.m_index = idx;
QItemSelectionModel *selection = selectionModel();
event.m_selectedRows = selection->selectedRows();
if (event.m_selectedRows.isEmpty()) {
QModelIndex current = selection->currentIndex();
if (current.isValid())
event.m_selectedRows.append(current);
}
return QVariant::fromValue(event);
}
void BaseTreeView::rowActivated(const QModelIndex &index)
{
model()->setData(index, QVariant(), ItemActivatedRole);
}
void BaseTreeView::rowClicked(const QModelIndex &index)
{
model()->setData(index, QVariant(), ItemClickedRole);
}
void BaseTreeView::setSettings(QSettings *settings, const QByteArray &key)
{
QTC_ASSERT(!d->m_settings, qDebug() << "DUPLICATED setSettings" << key);
......@@ -354,16 +429,9 @@ void BaseTreeView::setSettings(QSettings *settings, const QByteArray &key)
d->readSettings();
}
QModelIndexList BaseTreeView::activeRows() const
QModelIndexList ItemViewEvent::currentOrSelectedRows() const
{
QItemSelectionModel *selection = selectionModel();
QModelIndexList indices = selection->selectedRows();
if (indices.isEmpty()) {
QModelIndex current = selection->currentIndex();
if (current.isValid())
indices.append(current);
}
return indices;
return m_selectedRows.isEmpty() ? QModelIndexList() << m_index : m_selectedRows;
}
} // namespace Utils
......
......@@ -42,20 +42,31 @@ class QTCREATOR_UTILS_EXPORT BaseTreeView : public TreeView
Q_OBJECT
public:
enum { ExtraIndicesForColumnWidth = 12734 };
enum {
ExtraIndicesForColumnWidth = 12734,
ItemViewEventRole = Qt::UserRole + 12735,
ItemActivatedRole,
ItemClickedRole,
ItemDelegateRole,
};
BaseTreeView(QWidget *parent = 0);
~BaseTreeView();
void setSettings(QSettings *settings, const QByteArray &key);
QModelIndexList activeRows() const;
virtual void rowActivated(const QModelIndex &) {}
virtual void rowClicked(const QModelIndex &) {}
void setModel(QAbstractItemModel *model) override;
void mousePressEvent(QMouseEvent *ev) override;
void contextMenuEvent(QContextMenuEvent *ev) override;
void showEvent(QShowEvent *ev) override;
void keyPressEvent(QKeyEvent *ev) override;
void dragEnterEvent(QDragEnterEvent *ev) override;
void dropEvent(QDropEvent *ev) override;
void dragMoveEvent(QDragMoveEvent *ev) override;
void mouseDoubleClickEvent(QMouseEvent *ev) override;
void showProgressIndicator();
void hideProgressIndicator();
......@@ -63,11 +74,70 @@ public:
signals:
void aboutToShow();
public slots:
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
private:
QVariant describeEvent(QEvent *ev,
const QPoint &pos = QPoint(),
const QModelIndex &idx = QModelIndex());
void rowActivated(const QModelIndex &index);
void rowClicked(const QModelIndex &index);
Internal::BaseTreeViewPrivate *d;
};
template <typename Event> struct EventCode;
template <> struct EventCode<QDragEnterEvent> { enum { code = QEvent::DragEnter }; };
template <> struct EventCode<QDragLeaveEvent> { enum { code = QEvent::DragLeave }; };
template <> struct EventCode<QDragMoveEvent> { enum { code = QEvent::DragMove }; };
template <> struct EventCode<QDropEvent> { enum { code = QEvent::Drop }; };
template <> struct EventCode<QContextMenuEvent> { enum { code = QEvent::ContextMenu }; };
template <> struct EventCode<QMouseEvent> { enum { code = QEvent::MouseButtonPress }; };
template <> struct EventCode<QKeyEvent> { enum { code = QEvent::KeyPress }; };
template <class T> T *checkEventType(QEvent *ev)
{
const int cc = EventCode<T>::code;
const int tt = ev->type();
if (cc == tt)
return static_cast<T *>(ev);
if (cc == QEvent::MouseButtonPress) {
if (tt == QEvent::MouseButtonDblClick || tt == QEvent::MouseButtonRelease || tt == QEvent::MouseMove)
return static_cast<T *>(ev);
}
if (cc == QEvent::KeyPress && tt == QEvent::KeyRelease)
return static_cast<T *>(ev);
return nullptr;
}
class QTCREATOR_UTILS_EXPORT ItemViewEvent
{
public:
ItemViewEvent() {}
template <class T> T *as() const {
return checkEventType<T>(m_event);
}
template <class T> T *as(QEvent::Type t) const {
return m_event->type() == t ? as<T>() : nullptr;
}
QEvent::Type type() const { return m_event->type(); }
BaseTreeView *view() const { return m_view; }
QPoint pos() const { return m_pos; }
QPoint globalPos() const { return m_view->mapToGlobal(m_pos); }
QModelIndex index() const { return m_index; }
QModelIndexList selectedRows() const { return m_selectedRows; }
QModelIndexList currentOrSelectedRows() const;
private:
friend class BaseTreeView;
QEvent *m_event = nullptr;
BaseTreeView *m_view = nullptr;
QPoint m_pos;
QModelIndex m_index;
QModelIndexList m_selectedRows;
};
} // namespace Utils
Q_DECLARE_METATYPE(Utils::ItemViewEvent);
This diff is collapsed.
......@@ -33,6 +33,8 @@
#include <QCoreApplication>
#include <QPointer>
namespace Utils { class ItemViewEvent; }
namespace Debugger {
namespace Internal {
......@@ -157,7 +159,9 @@ inline uint qHash(const Debugger::Internal::Breakpoint &b) { return b.hash(); }
typedef QList<Breakpoint> Breakpoints;
class BreakHandler : public Utils::LeveledTreeModel<Utils::TreeItem, BreakpointItem, LocationItem>
using BreakModel = Utils::LeveledTreeModel<Utils::TypedTreeItem<BreakpointItem>, BreakpointItem, LocationItem>;
class BreakHandler : public BreakModel
{
Q_OBJECT
......@@ -200,8 +204,15 @@ public:
void setWatchpointAtExpression(const QString &exp);
Breakpoint breakpointById(BreakpointModelId id) const;
void editBreakpoint(Breakpoint bp, QWidget *parent);
private:
QVariant data(const QModelIndex &idx, int role) const override;
bool setData(const QModelIndex &idx, const QVariant &value, int role) override;
void timerEvent(QTimerEvent *event) override;
bool contextMenuEvent(const Utils::ItemViewEvent &ev);
friend class BreakpointItem;
friend class Breakpoint;
......@@ -209,12 +220,17 @@ private:
void saveBreakpoints();
void appendBreakpointInternal(const BreakpointParameters &data);
void deleteBreakpoints(const Breakpoints &bps);
void deleteAllBreakpoints();
void setBreakpointsEnabled(const Breakpoints &bps, bool enabled);
void addBreakpoint();
void editBreakpoints(const Breakpoints &bps, QWidget *parent);
Q_SLOT void changeLineNumberFromMarkerHelper(Debugger::Internal::BreakpointModelId id);
Q_SLOT void deletionHelper(Debugger::Internal::BreakpointModelId id);
void scheduleSynchronization();
void timerEvent(QTimerEvent *event);
int m_syncTimerId;
};
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2016 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.
**
****************************************************************************/
#pragma once
#include "breakhandler.h"
#include <utils/basetreeview.h>
namespace Debugger {
namespace Internal {
class BreakTreeView : public Utils::BaseTreeView
{
Q_OBJECT
public:
BreakTreeView();
static void editBreakpoint(Breakpoint bp, QWidget *parent);
private:
void rowActivated(const QModelIndex &index);
void contextMenuEvent(QContextMenuEvent *ev);
void keyPressEvent(QKeyEvent *ev);
void mouseDoubleClickEvent(QMouseEvent *ev);
void showAddressColumn(bool on);
void deleteBreakpoints(const Breakpoints &bps);
void deleteAllBreakpoints();
void addBreakpoint();
void editBreakpoints(const Breakpoints &bps);
void associateBreakpoint(const Breakpoints &bps, int thread);
void setBreakpointsEnabled(const Breakpoints &bps, bool enabled);
};
} // namespace Internal
} // namespace Debugger
......@@ -14,7 +14,6 @@ CONFIG += exceptions
HEADERS += \
breakhandler.h \
breakpoint.h \
breakwindow.h \
commonoptionspage.h \
debugger_global.h \
debuggeractions.h \
......@@ -40,22 +39,18 @@ HEADERS += \
logwindow.h \
memoryagent.h \
moduleshandler.h \
moduleswindow.h \
outputcollector.h \
procinterrupt.h \
registerhandler.h \
registerwindow.h \
snapshothandler.h \
snapshotwindow.h \
sourceagent.h \
sourcefileshandler.h \
sourcefileswindow.h \
sourceutils.h \
stackframe.h \
stackhandler.h \
stackwindow.h \
terminal.h \
threadswindow.h \
watchhandler.h \
watchutils.h \
watchwindow.h \
......@@ -74,7 +69,6 @@ HEADERS += \
SOURCES += \
breakhandler.cpp \
breakpoint.cpp \
breakwindow.cpp \
commonoptionspage.cpp \
debuggeractions.cpp \
debuggerdialogs.cpp \
......@@ -95,21 +89,17 @@ SOURCES += \
logwindow.cpp \
memoryagent.cpp \
moduleshandler.cpp \
moduleswindow.cpp \
outputcollector.cpp \
procinterrupt.cpp \
registerhandler.cpp \
registerwindow.cpp \
snapshothandler.cpp \
snapshotwindow.cpp \
sourceagent.cpp \
sourcefileshandler.cpp \
sourcefileswindow.cpp \
sourceutils.cpp \
stackhandler.cpp \
stackwindow.cpp \
threadshandler.cpp \
threadswindow.cpp \
terminal.cpp \
watchdata.cpp \
watchhandler.cpp \
......
......@@ -43,7 +43,6 @@ Project {
files: [
"breakhandler.cpp", "breakhandler.h",
"breakpoint.cpp", "breakpoint.h",
"breakwindow.cpp", "breakwindow.h",
"commonoptionspage.cpp", "commonoptionspage.h",
"debugger.qrc",
"debugger_global.h",
......@@ -76,16 +75,13 @@ Project {
"memoryagent.cpp", "memoryagent.h",
"memoryview.cpp", "memoryview.h",
"moduleshandler.cpp", "moduleshandler.h",
"moduleswindow.cpp", "moduleswindow.h",
"outputcollector.cpp", "outputcollector.h",
"procinterrupt.cpp", "procinterrupt.h",
"registerhandler.cpp", "registerhandler.h",
"registerwindow.cpp", "registerwindow.h",
"snapshothandler.cpp", "snapshothandler.h",
"snapshotwindow.cpp", "snapshotwindow.h",
"sourceagent.cpp", "sourceagent.h",
"sourcefileshandler.cpp", "sourcefileshandler.h",
"sourcefileswindow.cpp", "sourcefileswindow.h",
"sourceutils.cpp", "sourceutils.h",
"stackframe.cpp", "stackframe.h",
"stackhandler.cpp", "stackhandler.h",
......@@ -93,7 +89,6 @@ Project {
"terminal.cpp", "terminal.h",
"threaddata.h",
"threadshandler.cpp", "threadshandler.h",
"threadswindow.cpp", "threadswindow.h",
"watchdata.cpp", "watchdata.h",
"watchdelegatewidgets.cpp", "watchdelegatewidgets.h",
"watchhandler.cpp", "watchhandler.h",
......
......@@ -32,10 +32,14 @@
#include <QObject>
#include <QSharedPointer>
#include <functional>
QT_BEGIN_NAMESPACE
class QIcon;
class QMessageBox;
class QWidget;
class QMenu;
class QAction;
QT_END_NAMESPACE
namespace CPlusPlus { class Snapshot; }
......@@ -107,5 +111,12 @@ QMessageBox *showMessageBox(int icon, const QString &title,
bool isReverseDebuggingEnabled();
QAction *addAction(QMenu *menu, const QString &display, bool on,
const std::function<void()> &onTriggered = {});
QAction *addAction(QMenu *menu, const QString &d1, const QString &d2, bool on,
const std::function<void()> &onTriggered);
QAction *addCheckableAction(QMenu *menu, const QString &display, bool on, bool checked,
const std::function<void()> &onTriggered);
} // namespace Internal
} // namespace Debugger
......@@ -174,23 +174,15 @@ class DebuggerEnginePrivate : public QObject
public:
DebuggerEnginePrivate(DebuggerEngine *engine, const DebuggerRunParameters &sp)
: m_engine(engine),
m_masterEngine(0),
m_runControl(0),
m_runParameters(sp),
m_state(DebuggerNotReady),
m_lastGoodState(DebuggerNotReady),
m_targetState(DebuggerNotReady),
m_remoteSetupState(RemoteSetupNone),
m_inferiorPid(0),
m_modulesHandler(engine),
m_registerHandler(engine),
m_sourceFilesHandler(),
m_sourceFilesHandler(engine),
m_stackHandler(engine),
m_threadsHandler(),
m_threadsHandler(engine),
m_watchHandler(engine),
m_disassemblerAgent(engine),
m_memoryAgent(engine),
m_isStateDebugging(false)
m_memoryAgent(engine)
{
connect(&m_locationTimer, &QTimer::timeout,
this, &DebuggerEnginePrivate::resetLocation);
......@@ -298,26 +290,26 @@ public:
{ return m_masterEngine ? m_masterEngine->runControl() : m_runControl; }
void setRemoteSetupState(RemoteSetupState state);
DebuggerEngine *m_engine; // Not owned.
DebuggerEngine *m_masterEngine; // Not owned
DebuggerRunControl *m_runControl; // Not owned.
DebuggerEngine *m_engine = nullptr; // Not owned.
DebuggerEngine *m_masterEngine = nullptr; // Not owned
DebuggerRunControl *m_runControl = nullptr; // Not owned.
DebuggerRunParameters m_runParameters;
// The current state.
DebuggerState m_state;
DebuggerState m_state = DebuggerNotReady;
// The state we had before something unexpected happend.
DebuggerState m_lastGoodState;
DebuggerState m_lastGoodState = DebuggerNotReady;
// The state we are aiming for.
DebuggerState m_targetState;
DebuggerState m_targetState = DebuggerNotReady;
// State of RemoteSetup signal/slots.
RemoteSetupState m_remoteSetupState;
RemoteSetupState m_remoteSetupState = RemoteSetupNone;
Terminal m_terminal;
qint64 m_inferiorPid;
qint64 m_inferiorPid = 0;
ModulesHandler m_modulesHandler;
RegisterHandler m_registerHandler;
......@@ -332,7 +324,7 @@ public:
QScopedPointer<LocationMark> m_locationMark;
QTimer m_locationTimer;
bool m_isStateDebugging;
bool m_isStateDebugging = false;
Utils::FileInProjectFinder m_fileFinder;
QString m_qtNamespace;
......
......@@ -75,23 +75,10 @@ enum ModelRoles
// Locals and Watchers
LocalsINameRole,
LocalsEditTypeRole, // A QVariant::type describing the item
LocalsIntegerBaseRole, // Number base 16, 10, 8, 2
LocalsNameRole,
LocalsExpressionRole,
LocalsRawExpressionRole,
LocalsExpandedRole, // The preferred expanded state to the view
LocalsRawTypeRole, // Raw type name
LocalsTypeRole, // Display type name
LocalsTypeFormatListRole,
LocalsTypeFormatRole, // Used to communicate alternative formats to the view
LocalsIndividualFormatRole,
LocalsObjectAddressRole, // Memory address of variable as quint64
LocalsSizeRole, // Size of variable as quint
LocalsRawValueRole, // Unformatted value as string
LocalsPointerAddressRole, // Address of (undereferenced) pointer as quint64
LocalsIsWatchpointAtObjectAddressRole,
LocalsIsWatchpointAtPointerAddressRole,
// Snapshots
SnapshotCapabilityRole
......
......@@ -43,17 +43,12 @@
#include "debuggerkitinformation.h"
#include "memoryagent.h"
#include "breakhandler.h"
#include "breakwindow.h"
#include "disassemblerlines.h"
#include "logwindow.h"
#include "moduleswindow.h"
#include "moduleshandler.h"
#include "registerwindow.h"
#include "snapshotwindow.h"
#include "stackhandler.h"
#include "stackwindow.h"
#include "sourcefileswindow.h"
#include "threadswindow.h"
#include "watchhandler.h"
#include "watchwindow.h"
#include "watchutils.h"
......@@ -463,6 +458,30 @@ static void setProxyAction(ProxyAction *proxy, Id id)
proxy->setIcon(visibleStartIcon(id, true));
}
QAction *addAction(QMenu *menu, const QString &display, bool on,
const std::function<void()> &onTriggered)
{
QAction *act = menu->addAction(display);
act->setEnabled(on);
QObject::connect(act, &QAction::triggered, onTriggered);
return act;
};
QAction *addAction(QMenu *menu, const QString &d1, const QString &d2, bool on,
const std::function<void()> &onTriggered)
{
return on ? addAction(menu, d1, true, onTriggered) : addAction(menu, d2, false);
};
QAction *addCheckableAction(QMenu *menu, const QString &display, bool on, bool checked,
const std::function<void()> &onTriggered)
{
QAction *act = addAction(menu, display, on, onTriggered);
act->setCheckable(true);
act->setChecked(checked);
return act;
}
///////////////////////////////////////////////////////////////////////
//
// DummyEngine
......@@ -547,15 +566,15 @@ public:
///////////////////////////////////////////////////////////////////////
static QWidget *addSearch(BaseTreeView *treeView, const QString &title,
const char *objectName)
const QString &objectName)
{
QAction *act = action(UseAlternatingRowColors);
treeView->setAlternatingRowColors(act->isChecked());
QObject::connect(act, &QAction::toggled,
treeView, &BaseTreeView::setAlternatingRowColorsHelper);
treeView, &BaseTreeView::setAlternatingRowColors);