forked from qt-creator/qt-creator
debugger: simplify handling of context menu actions of the Locals&Watchers view
This commit is contained in:
@@ -243,21 +243,6 @@ DebuggerSettings *DebuggerSettings::instance()
|
||||
//
|
||||
// Locals & Watchers
|
||||
//
|
||||
item = new SavedAction(instance);
|
||||
item->setTextPattern(tr("Watch Expression \"%1\""));
|
||||
instance->insertItem(WatchExpression, item);
|
||||
|
||||
item = new SavedAction(instance);
|
||||
item->setTextPattern(tr("Remove Watch Expression \"%1\""));
|
||||
instance->insertItem(RemoveWatchExpression, item);
|
||||
|
||||
item = new SavedAction(instance);
|
||||
item->setTextPattern(tr("Watch Expression \"%1\" in Separate Window"));
|
||||
instance->insertItem(WatchExpressionInWindow, item);
|
||||
|
||||
item = new SavedAction(instance);
|
||||
instance->insertItem(WatchPoint, item);
|
||||
|
||||
item = new SavedAction(instance);
|
||||
item->setSettingsKey(debugModeGroup, QLatin1String("ShowStandardNamespace"));
|
||||
item->setText(tr("Show \"std::\" Namespace in Types"));
|
||||
|
@@ -123,10 +123,6 @@ enum DebuggerActionCode
|
||||
CreateFullBacktrace,
|
||||
|
||||
// Watchers & Locals
|
||||
WatchExpression,
|
||||
WatchExpressionInWindow,
|
||||
RemoveWatchExpression,
|
||||
WatchPoint,
|
||||
ShowStdNamespace,
|
||||
ShowQtNamespace,
|
||||
|
||||
|
@@ -217,6 +217,8 @@ enum ModelRoles
|
||||
RequestClearCppCodeModelSnapshotRole,
|
||||
RequestAssignValueRole,
|
||||
RequestAssignTypeRole,
|
||||
RequestWatchExpressionRole,
|
||||
RequestRemoveWatchExpressionRole,
|
||||
|
||||
// Stack
|
||||
StackFrameAddressRole,
|
||||
|
@@ -253,7 +253,6 @@ public slots:
|
||||
void quitDebugger() { exitDebugger(); }
|
||||
|
||||
protected:
|
||||
friend class WatchHandler;
|
||||
void setState(DebuggerState state, bool forced = false);
|
||||
|
||||
private:
|
||||
|
@@ -1128,7 +1128,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, QString *er
|
||||
m_actions.reverseDirectionAction->setCheckable(false);
|
||||
theDebuggerAction(OperateByInstruction)->
|
||||
setProperty(Role, RequestOperatedByInstructionTriggeredRole);
|
||||
theDebuggerAction(WatchPoint)->setProperty(Role, RequestWatchPointRole);
|
||||
|
||||
connect(m_actions.continueAction, SIGNAL(triggered()), SLOT(onAction()));
|
||||
connect(m_actions.nextAction, SIGNAL(triggered()), SLOT(onAction()));
|
||||
@@ -1149,7 +1148,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, QString *er
|
||||
connect(m_actions.resetAction, SIGNAL(triggered()), SLOT(onAction()));
|
||||
connect(&m_statusTimer, SIGNAL(timeout()), SLOT(clearStatusMessage()));
|
||||
|
||||
connect(theDebuggerAction(WatchPoint), SIGNAL(triggered()), SLOT(onAction()));
|
||||
connect(theDebuggerAction(ExecuteCommand), SIGNAL(triggered()),
|
||||
SLOT(executeDebuggerCommand()));
|
||||
|
||||
|
@@ -3615,7 +3615,7 @@ void GdbEngine::handleWatchPoint(const GdbResponse &response)
|
||||
QString ns = m_dumperHelper.qtNamespace();
|
||||
QString type = ns.isEmpty() ? _("QWidget*") : _("'%1QWidget'*").arg(ns);
|
||||
QString exp = _("(*(%1)%2)").arg(type).arg(addr);
|
||||
theDebuggerAction(WatchExpression)->trigger(exp);
|
||||
watchHandler()->watchExpression(exp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -184,7 +184,7 @@ void WatchModel::endCycle()
|
||||
m_fetchTriggered.clear();
|
||||
emit enableUpdates(true);
|
||||
}
|
||||
|
||||
|
||||
DebuggerEngine *WatchModel::engine() const
|
||||
{
|
||||
return m_handler->m_engine;
|
||||
@@ -744,28 +744,49 @@ bool WatchModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||
plugin()->clearCppCodeModelSnapshot();
|
||||
return true;
|
||||
}
|
||||
|
||||
case RequestWatchPointRole: {
|
||||
engine()->watchPoint(value.toPoint());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
WatchItem &data = *watchItem(index);
|
||||
if (role == LocalsExpandedRole) {
|
||||
if (value.toBool()) {
|
||||
// Should already have been triggered by fetchMore()
|
||||
//QTC_ASSERT(m_handler->m_expandedINames.contains(data.iname), /**/);
|
||||
m_handler->m_expandedINames.insert(data.iname);
|
||||
} else {
|
||||
m_handler->m_expandedINames.remove(data.iname);
|
||||
|
||||
switch (role) {
|
||||
case LocalsExpandedRole:
|
||||
if (value.toBool()) {
|
||||
// Should already have been triggered by fetchMore()
|
||||
//QTC_ASSERT(m_handler->m_expandedINames.contains(data.iname), /**/);
|
||||
m_handler->m_expandedINames.insert(data.iname);
|
||||
} else {
|
||||
m_handler->m_expandedINames.remove(data.iname);
|
||||
}
|
||||
break;
|
||||
|
||||
case LocalsTypeFormatRole:
|
||||
m_handler->setFormat(data.type, value.toInt());
|
||||
engine()->updateWatchData(data);
|
||||
break;
|
||||
|
||||
case LocalsIndividualFormatRole: {
|
||||
const int format = value.toInt();
|
||||
if (format == -1) {
|
||||
m_handler->m_individualFormats.remove(data.addr);
|
||||
} else {
|
||||
m_handler->m_individualFormats[data.addr] = format;
|
||||
}
|
||||
engine()->updateWatchData(data);
|
||||
break;
|
||||
}
|
||||
} else if (role == LocalsTypeFormatRole) {
|
||||
m_handler->setFormat(data.type, value.toInt());
|
||||
engine()->updateWatchData(data);
|
||||
} else if (role == LocalsIndividualFormatRole) {
|
||||
const int format = value.toInt();
|
||||
if (format == -1) {
|
||||
m_handler->m_individualFormats.remove(data.addr);
|
||||
} else {
|
||||
m_handler->m_individualFormats[data.addr] = format;
|
||||
}
|
||||
engine()->updateWatchData(data);
|
||||
|
||||
case RequestRemoveWatchExpressionRole:
|
||||
m_handler->removeWatchExpression(value.toString());
|
||||
break;
|
||||
|
||||
case RequestWatchExpressionRole:
|
||||
m_handler->watchExpression(value.toString());
|
||||
break;
|
||||
}
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
@@ -1065,10 +1086,6 @@ WatchHandler::WatchHandler(DebuggerEngine *engine)
|
||||
m_watchers = new WatchModel(this, WatchersWatch);
|
||||
m_tooltips = new WatchModel(this, TooltipsWatch);
|
||||
|
||||
connect(theDebuggerAction(WatchExpression),
|
||||
SIGNAL(triggered()), this, SLOT(watchExpression()));
|
||||
connect(theDebuggerAction(RemoveWatchExpression),
|
||||
SIGNAL(triggered()), this, SLOT(removeWatchExpression()));
|
||||
connect(theDebuggerAction(ShowStdNamespace),
|
||||
SIGNAL(triggered()), this, SLOT(emitAllChanged()));
|
||||
connect(theDebuggerAction(ShowQtNamespace),
|
||||
@@ -1198,12 +1215,6 @@ void WatchHandler::removeData(const QByteArray &iname)
|
||||
model->destroyItem(item);
|
||||
}
|
||||
|
||||
void WatchHandler::watchExpression()
|
||||
{
|
||||
if (QAction *action = qobject_cast<QAction *>(sender()))
|
||||
watchExpression(action->data().toString());
|
||||
}
|
||||
|
||||
QByteArray WatchHandler::watcherName(const QByteArray &exp)
|
||||
{
|
||||
return "watch." + QByteArray::number(m_watcherNames[exp]);
|
||||
@@ -1323,12 +1334,6 @@ void WatchHandler::showEditValue(const WatchData &data)
|
||||
}
|
||||
}
|
||||
|
||||
void WatchHandler::removeWatchExpression()
|
||||
{
|
||||
if (QAction *action = qobject_cast<QAction *>(sender()))
|
||||
removeWatchExpression(action->data().toString());
|
||||
}
|
||||
|
||||
void WatchHandler::removeWatchExpression(const QString &exp0)
|
||||
{
|
||||
QByteArray exp = exp0.toLatin1();
|
||||
|
@@ -142,10 +142,8 @@ public:
|
||||
WatchModel *modelForIName(const QByteArray &iname) const;
|
||||
|
||||
void cleanup();
|
||||
Q_SLOT void watchExpression(); // Data passed in action->data().toString()
|
||||
Q_SLOT void watchExpression(const QString &exp);
|
||||
Q_SLOT void removeWatchExpression();
|
||||
Q_SLOT void removeWatchExpression(const QString &exp);
|
||||
void watchExpression(const QString &exp);
|
||||
void removeWatchExpression(const QString &exp);
|
||||
Q_SLOT void emitAllChanged();
|
||||
|
||||
void beginCycle(); // Called at begin of updateLocals() cycle
|
||||
|
@@ -99,8 +99,8 @@ public:
|
||||
model->setData(index, QString(exp + '=' + value), RequestAssignTypeRole);
|
||||
} else if (index.column() == 0) {
|
||||
// The watcher name column.
|
||||
theDebuggerAction(RemoveWatchExpression)->trigger(exp);
|
||||
theDebuggerAction(WatchExpression)->trigger(value);
|
||||
model->setData(index, exp, RequestRemoveWatchExpressionRole);
|
||||
model->setData(index, value, RequestWatchExpressionRole);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,14 +161,14 @@ void WatchWindow::keyPressEvent(QKeyEvent *ev)
|
||||
QModelIndex idx = currentIndex();
|
||||
QModelIndex idx1 = idx.sibling(idx.row(), 0);
|
||||
QString exp = idx1.data().toString();
|
||||
theDebuggerAction(RemoveWatchExpression)->trigger(exp);
|
||||
removeWatchExpression(exp);
|
||||
} else if (ev->key() == Qt::Key_Return
|
||||
&& ev->modifiers() == Qt::ControlModifier
|
||||
&& m_type == LocalsType) {
|
||||
QModelIndex idx = currentIndex();
|
||||
QModelIndex idx1 = idx.sibling(idx.row(), 0);
|
||||
QString exp = model()->data(idx1).toString();
|
||||
theDebuggerAction(WatchExpression)->trigger(exp);
|
||||
watchExpression(exp);
|
||||
}
|
||||
QTreeView::keyPressEvent(ev);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ void WatchWindow::dragMoveEvent(QDragMoveEvent *ev)
|
||||
void WatchWindow::dropEvent(QDropEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasFormat("text/plain")) {
|
||||
theDebuggerAction(WatchExpression)->trigger(ev->mimeData()->text());
|
||||
watchExpression(ev->mimeData()->text());
|
||||
//ev->acceptProposedAction();
|
||||
ev->setDropAction(Qt::CopyAction);
|
||||
ev->accept();
|
||||
@@ -313,13 +313,15 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
||||
const bool canSetWatchpoint = engineCapabilities & WatchpointCapability;
|
||||
if (canSetWatchpoint && address) {
|
||||
actSetWatchPointAtVariableAddress =
|
||||
new QAction(tr("Break on Changes at Object's Address (0x%1)").arg(address, 0, 16), &menu);
|
||||
new QAction(tr("Break on Changes at Object's Address (0x%1)")
|
||||
.arg(address, 0, 16), &menu);
|
||||
actSetWatchPointAtVariableAddress->setCheckable(true);
|
||||
actSetWatchPointAtVariableAddress->
|
||||
setChecked(mi0.data(LocalsIsWatchpointAtAddressRole).toBool());
|
||||
if (createPointerActions) {
|
||||
actSetWatchPointAtPointerValue =
|
||||
new QAction(tr("Break on Changes at Referenced Address (0x%1)").arg(pointerValue, 0, 16), &menu);
|
||||
new QAction(tr("Break on Changes at Referenced Address (0x%1)")
|
||||
.arg(pointerValue, 0, 16), &menu);
|
||||
actSetWatchPointAtPointerValue->setCheckable(true);
|
||||
actSetWatchPointAtPointerValue->
|
||||
setChecked(mi0.data(LocalsIsWatchpointAtPointerValueRole).toBool());
|
||||
@@ -330,16 +332,17 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
||||
actSetWatchPointAtVariableAddress->setEnabled(false);
|
||||
}
|
||||
|
||||
QAction *actWatchOrRemove;
|
||||
if (m_type == LocalsType) {
|
||||
actWatchOrRemove = theDebuggerAction(WatchExpression)->updatedAction(exp);
|
||||
actWatchOrRemove->setEnabled(canHandleWatches);
|
||||
} else {
|
||||
actWatchOrRemove = theDebuggerAction(RemoveWatchExpression)->updatedAction(exp);
|
||||
// Also for the case where the user cleared the expression.
|
||||
actWatchOrRemove->setEnabled(true);
|
||||
}
|
||||
menu.addAction(actWatchOrRemove);
|
||||
QAction *actWatchExpression =
|
||||
new QAction(tr("Watch Expression \"%1\"").arg(exp), &menu);
|
||||
actWatchExpression->setEnabled(canHandleWatches);
|
||||
|
||||
QAction *actRemoveWatchExpression =
|
||||
new QAction(tr("Remove Watch Expression \"%1\"").arg(exp), &menu);
|
||||
|
||||
if (m_type == LocalsType)
|
||||
menu.addAction(actWatchExpression);
|
||||
else
|
||||
menu.addAction(actRemoveWatchExpression);
|
||||
|
||||
menu.addAction(actInsertNewWatchItem);
|
||||
menu.addAction(actSelectWidgetToWatch);
|
||||
@@ -388,8 +391,7 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
||||
} else if (act == actAlwaysAdjustColumnWidth) {
|
||||
setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents);
|
||||
} else if (act == actInsertNewWatchItem) {
|
||||
theDebuggerAction(WatchExpression)
|
||||
->trigger(WatchHandler::watcherEditPlaceHolder());
|
||||
watchExpression(WatchHandler::watcherEditPlaceHolder());
|
||||
} else if (act == actOpenMemoryEditAtVariableAddress) {
|
||||
setModelData(RequestShowMemoryRole, address);
|
||||
} else if (act == actOpenMemoryEditAtPointerValue) {
|
||||
@@ -405,6 +407,10 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
||||
} else if (act == actSelectWidgetToWatch) {
|
||||
grabMouse(Qt::CrossCursor);
|
||||
m_grabbing = true;
|
||||
} else if (act == actWatchExpression) {
|
||||
watchExpression(exp);
|
||||
} else if (act == actRemoveWatchExpression) {
|
||||
removeWatchExpression(exp);
|
||||
} else if (act == actClearCodeModelSnapshot) {
|
||||
setModelData(RequestClearCppCodeModelSnapshotRole);
|
||||
} else if (act == clearTypeFormatAction) {
|
||||
@@ -446,7 +452,7 @@ bool WatchWindow::event(QEvent *ev)
|
||||
QMouseEvent *mev = static_cast<QMouseEvent *>(ev);
|
||||
m_grabbing = false;
|
||||
releaseMouse();
|
||||
theDebuggerAction(WatchPoint)->trigger(mapToGlobal(mev->pos()));
|
||||
setModelData(RequestWatchPointRole, mapToGlobal(mev->pos()));
|
||||
}
|
||||
return QTreeView::event(ev);
|
||||
}
|
||||
@@ -498,6 +504,16 @@ void WatchWindow::resetHelper(const QModelIndex &idx)
|
||||
}
|
||||
}
|
||||
|
||||
void WatchWindow::watchExpression(const QString &exp)
|
||||
{
|
||||
setModelData(RequestWatchExpressionRole, exp);
|
||||
}
|
||||
|
||||
void WatchWindow::removeWatchExpression(const QString &exp)
|
||||
{
|
||||
setModelData(RequestRemoveWatchExpressionRole, exp);
|
||||
}
|
||||
|
||||
void WatchWindow::setModelData
|
||||
(int role, const QVariant &value, const QModelIndex &index)
|
||||
{
|
||||
|
@@ -73,6 +73,8 @@ private:
|
||||
|
||||
void editItem(const QModelIndex &idx);
|
||||
void resetHelper(const QModelIndex &idx);
|
||||
void watchExpression(const QString &exp);
|
||||
void removeWatchExpression(const QString &exp);
|
||||
|
||||
void setModelData(int role, const QVariant &value = QVariant(),
|
||||
const QModelIndex &index = QModelIndex());
|
||||
|
Reference in New Issue
Block a user