debugger: simplify handling of context menu actions of the Locals&Watchers view

This commit is contained in:
hjk
2010-06-23 15:13:51 +02:00
parent bb0f033b92
commit a25fd01a10
10 changed files with 83 additions and 82 deletions

View File

@@ -243,21 +243,6 @@ DebuggerSettings *DebuggerSettings::instance()
// //
// Locals & Watchers // 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 = new SavedAction(instance);
item->setSettingsKey(debugModeGroup, QLatin1String("ShowStandardNamespace")); item->setSettingsKey(debugModeGroup, QLatin1String("ShowStandardNamespace"));
item->setText(tr("Show \"std::\" Namespace in Types")); item->setText(tr("Show \"std::\" Namespace in Types"));

View File

@@ -123,10 +123,6 @@ enum DebuggerActionCode
CreateFullBacktrace, CreateFullBacktrace,
// Watchers & Locals // Watchers & Locals
WatchExpression,
WatchExpressionInWindow,
RemoveWatchExpression,
WatchPoint,
ShowStdNamespace, ShowStdNamespace,
ShowQtNamespace, ShowQtNamespace,

View File

@@ -217,6 +217,8 @@ enum ModelRoles
RequestClearCppCodeModelSnapshotRole, RequestClearCppCodeModelSnapshotRole,
RequestAssignValueRole, RequestAssignValueRole,
RequestAssignTypeRole, RequestAssignTypeRole,
RequestWatchExpressionRole,
RequestRemoveWatchExpressionRole,
// Stack // Stack
StackFrameAddressRole, StackFrameAddressRole,

View File

@@ -253,7 +253,6 @@ public slots:
void quitDebugger() { exitDebugger(); } void quitDebugger() { exitDebugger(); }
protected: protected:
friend class WatchHandler;
void setState(DebuggerState state, bool forced = false); void setState(DebuggerState state, bool forced = false);
private: private:

View File

@@ -1128,7 +1128,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, QString *er
m_actions.reverseDirectionAction->setCheckable(false); m_actions.reverseDirectionAction->setCheckable(false);
theDebuggerAction(OperateByInstruction)-> theDebuggerAction(OperateByInstruction)->
setProperty(Role, RequestOperatedByInstructionTriggeredRole); setProperty(Role, RequestOperatedByInstructionTriggeredRole);
theDebuggerAction(WatchPoint)->setProperty(Role, RequestWatchPointRole);
connect(m_actions.continueAction, SIGNAL(triggered()), SLOT(onAction())); connect(m_actions.continueAction, SIGNAL(triggered()), SLOT(onAction()));
connect(m_actions.nextAction, 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_actions.resetAction, SIGNAL(triggered()), SLOT(onAction()));
connect(&m_statusTimer, SIGNAL(timeout()), SLOT(clearStatusMessage())); connect(&m_statusTimer, SIGNAL(timeout()), SLOT(clearStatusMessage()));
connect(theDebuggerAction(WatchPoint), SIGNAL(triggered()), SLOT(onAction()));
connect(theDebuggerAction(ExecuteCommand), SIGNAL(triggered()), connect(theDebuggerAction(ExecuteCommand), SIGNAL(triggered()),
SLOT(executeDebuggerCommand())); SLOT(executeDebuggerCommand()));

View File

@@ -3615,7 +3615,7 @@ void GdbEngine::handleWatchPoint(const GdbResponse &response)
QString ns = m_dumperHelper.qtNamespace(); QString ns = m_dumperHelper.qtNamespace();
QString type = ns.isEmpty() ? _("QWidget*") : _("'%1QWidget'*").arg(ns); QString type = ns.isEmpty() ? _("QWidget*") : _("'%1QWidget'*").arg(ns);
QString exp = _("(*(%1)%2)").arg(type).arg(addr); QString exp = _("(*(%1)%2)").arg(type).arg(addr);
theDebuggerAction(WatchExpression)->trigger(exp); watchHandler()->watchExpression(exp);
} }
} }

View File

@@ -184,7 +184,7 @@ void WatchModel::endCycle()
m_fetchTriggered.clear(); m_fetchTriggered.clear();
emit enableUpdates(true); emit enableUpdates(true);
} }
DebuggerEngine *WatchModel::engine() const DebuggerEngine *WatchModel::engine() const
{ {
return m_handler->m_engine; return m_handler->m_engine;
@@ -744,28 +744,49 @@ bool WatchModel::setData(const QModelIndex &index, const QVariant &value, int ro
plugin()->clearCppCodeModelSnapshot(); plugin()->clearCppCodeModelSnapshot();
return true; return true;
} }
case RequestWatchPointRole: {
engine()->watchPoint(value.toPoint());
return true;
}
} }
WatchItem &data = *watchItem(index); WatchItem &data = *watchItem(index);
if (role == LocalsExpandedRole) {
if (value.toBool()) { switch (role) {
// Should already have been triggered by fetchMore() case LocalsExpandedRole:
//QTC_ASSERT(m_handler->m_expandedINames.contains(data.iname), /**/); if (value.toBool()) {
m_handler->m_expandedINames.insert(data.iname); // Should already have been triggered by fetchMore()
} else { //QTC_ASSERT(m_handler->m_expandedINames.contains(data.iname), /**/);
m_handler->m_expandedINames.remove(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()); case RequestRemoveWatchExpressionRole:
engine()->updateWatchData(data); m_handler->removeWatchExpression(value.toString());
} else if (role == LocalsIndividualFormatRole) { break;
const int format = value.toInt();
if (format == -1) { case RequestWatchExpressionRole:
m_handler->m_individualFormats.remove(data.addr); m_handler->watchExpression(value.toString());
} else { break;
m_handler->m_individualFormats[data.addr] = format;
}
engine()->updateWatchData(data);
} }
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
@@ -1065,10 +1086,6 @@ WatchHandler::WatchHandler(DebuggerEngine *engine)
m_watchers = new WatchModel(this, WatchersWatch); m_watchers = new WatchModel(this, WatchersWatch);
m_tooltips = new WatchModel(this, TooltipsWatch); 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), connect(theDebuggerAction(ShowStdNamespace),
SIGNAL(triggered()), this, SLOT(emitAllChanged())); SIGNAL(triggered()), this, SLOT(emitAllChanged()));
connect(theDebuggerAction(ShowQtNamespace), connect(theDebuggerAction(ShowQtNamespace),
@@ -1198,12 +1215,6 @@ void WatchHandler::removeData(const QByteArray &iname)
model->destroyItem(item); model->destroyItem(item);
} }
void WatchHandler::watchExpression()
{
if (QAction *action = qobject_cast<QAction *>(sender()))
watchExpression(action->data().toString());
}
QByteArray WatchHandler::watcherName(const QByteArray &exp) QByteArray WatchHandler::watcherName(const QByteArray &exp)
{ {
return "watch." + QByteArray::number(m_watcherNames[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) void WatchHandler::removeWatchExpression(const QString &exp0)
{ {
QByteArray exp = exp0.toLatin1(); QByteArray exp = exp0.toLatin1();

View File

@@ -142,10 +142,8 @@ public:
WatchModel *modelForIName(const QByteArray &iname) const; WatchModel *modelForIName(const QByteArray &iname) const;
void cleanup(); void cleanup();
Q_SLOT void watchExpression(); // Data passed in action->data().toString() void watchExpression(const QString &exp);
Q_SLOT void watchExpression(const QString &exp); void removeWatchExpression(const QString &exp);
Q_SLOT void removeWatchExpression();
Q_SLOT void removeWatchExpression(const QString &exp);
Q_SLOT void emitAllChanged(); Q_SLOT void emitAllChanged();
void beginCycle(); // Called at begin of updateLocals() cycle void beginCycle(); // Called at begin of updateLocals() cycle

View File

@@ -99,8 +99,8 @@ public:
model->setData(index, QString(exp + '=' + value), RequestAssignTypeRole); model->setData(index, QString(exp + '=' + value), RequestAssignTypeRole);
} else if (index.column() == 0) { } else if (index.column() == 0) {
// The watcher name column. // The watcher name column.
theDebuggerAction(RemoveWatchExpression)->trigger(exp); model->setData(index, exp, RequestRemoveWatchExpressionRole);
theDebuggerAction(WatchExpression)->trigger(value); model->setData(index, value, RequestWatchExpressionRole);
} }
} }
@@ -161,14 +161,14 @@ void WatchWindow::keyPressEvent(QKeyEvent *ev)
QModelIndex idx = currentIndex(); QModelIndex idx = currentIndex();
QModelIndex idx1 = idx.sibling(idx.row(), 0); QModelIndex idx1 = idx.sibling(idx.row(), 0);
QString exp = idx1.data().toString(); QString exp = idx1.data().toString();
theDebuggerAction(RemoveWatchExpression)->trigger(exp); removeWatchExpression(exp);
} else if (ev->key() == Qt::Key_Return } else if (ev->key() == Qt::Key_Return
&& ev->modifiers() == Qt::ControlModifier && ev->modifiers() == Qt::ControlModifier
&& m_type == LocalsType) { && m_type == LocalsType) {
QModelIndex idx = currentIndex(); QModelIndex idx = currentIndex();
QModelIndex idx1 = idx.sibling(idx.row(), 0); QModelIndex idx1 = idx.sibling(idx.row(), 0);
QString exp = model()->data(idx1).toString(); QString exp = model()->data(idx1).toString();
theDebuggerAction(WatchExpression)->trigger(exp); watchExpression(exp);
} }
QTreeView::keyPressEvent(ev); QTreeView::keyPressEvent(ev);
} }
@@ -194,7 +194,7 @@ void WatchWindow::dragMoveEvent(QDragMoveEvent *ev)
void WatchWindow::dropEvent(QDropEvent *ev) void WatchWindow::dropEvent(QDropEvent *ev)
{ {
if (ev->mimeData()->hasFormat("text/plain")) { if (ev->mimeData()->hasFormat("text/plain")) {
theDebuggerAction(WatchExpression)->trigger(ev->mimeData()->text()); watchExpression(ev->mimeData()->text());
//ev->acceptProposedAction(); //ev->acceptProposedAction();
ev->setDropAction(Qt::CopyAction); ev->setDropAction(Qt::CopyAction);
ev->accept(); ev->accept();
@@ -313,13 +313,15 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
const bool canSetWatchpoint = engineCapabilities & WatchpointCapability; const bool canSetWatchpoint = engineCapabilities & WatchpointCapability;
if (canSetWatchpoint && address) { if (canSetWatchpoint && address) {
actSetWatchPointAtVariableAddress = 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->setCheckable(true);
actSetWatchPointAtVariableAddress-> actSetWatchPointAtVariableAddress->
setChecked(mi0.data(LocalsIsWatchpointAtAddressRole).toBool()); setChecked(mi0.data(LocalsIsWatchpointAtAddressRole).toBool());
if (createPointerActions) { if (createPointerActions) {
actSetWatchPointAtPointerValue = 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->setCheckable(true);
actSetWatchPointAtPointerValue-> actSetWatchPointAtPointerValue->
setChecked(mi0.data(LocalsIsWatchpointAtPointerValueRole).toBool()); setChecked(mi0.data(LocalsIsWatchpointAtPointerValueRole).toBool());
@@ -330,16 +332,17 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
actSetWatchPointAtVariableAddress->setEnabled(false); actSetWatchPointAtVariableAddress->setEnabled(false);
} }
QAction *actWatchOrRemove; QAction *actWatchExpression =
if (m_type == LocalsType) { new QAction(tr("Watch Expression \"%1\"").arg(exp), &menu);
actWatchOrRemove = theDebuggerAction(WatchExpression)->updatedAction(exp); actWatchExpression->setEnabled(canHandleWatches);
actWatchOrRemove->setEnabled(canHandleWatches);
} else { QAction *actRemoveWatchExpression =
actWatchOrRemove = theDebuggerAction(RemoveWatchExpression)->updatedAction(exp); new QAction(tr("Remove Watch Expression \"%1\"").arg(exp), &menu);
// Also for the case where the user cleared the expression.
actWatchOrRemove->setEnabled(true); if (m_type == LocalsType)
} menu.addAction(actWatchExpression);
menu.addAction(actWatchOrRemove); else
menu.addAction(actRemoveWatchExpression);
menu.addAction(actInsertNewWatchItem); menu.addAction(actInsertNewWatchItem);
menu.addAction(actSelectWidgetToWatch); menu.addAction(actSelectWidgetToWatch);
@@ -388,8 +391,7 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
} else if (act == actAlwaysAdjustColumnWidth) { } else if (act == actAlwaysAdjustColumnWidth) {
setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents); setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents);
} else if (act == actInsertNewWatchItem) { } else if (act == actInsertNewWatchItem) {
theDebuggerAction(WatchExpression) watchExpression(WatchHandler::watcherEditPlaceHolder());
->trigger(WatchHandler::watcherEditPlaceHolder());
} else if (act == actOpenMemoryEditAtVariableAddress) { } else if (act == actOpenMemoryEditAtVariableAddress) {
setModelData(RequestShowMemoryRole, address); setModelData(RequestShowMemoryRole, address);
} else if (act == actOpenMemoryEditAtPointerValue) { } else if (act == actOpenMemoryEditAtPointerValue) {
@@ -405,6 +407,10 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
} else if (act == actSelectWidgetToWatch) { } else if (act == actSelectWidgetToWatch) {
grabMouse(Qt::CrossCursor); grabMouse(Qt::CrossCursor);
m_grabbing = true; m_grabbing = true;
} else if (act == actWatchExpression) {
watchExpression(exp);
} else if (act == actRemoveWatchExpression) {
removeWatchExpression(exp);
} else if (act == actClearCodeModelSnapshot) { } else if (act == actClearCodeModelSnapshot) {
setModelData(RequestClearCppCodeModelSnapshotRole); setModelData(RequestClearCppCodeModelSnapshotRole);
} else if (act == clearTypeFormatAction) { } else if (act == clearTypeFormatAction) {
@@ -446,7 +452,7 @@ bool WatchWindow::event(QEvent *ev)
QMouseEvent *mev = static_cast<QMouseEvent *>(ev); QMouseEvent *mev = static_cast<QMouseEvent *>(ev);
m_grabbing = false; m_grabbing = false;
releaseMouse(); releaseMouse();
theDebuggerAction(WatchPoint)->trigger(mapToGlobal(mev->pos())); setModelData(RequestWatchPointRole, mapToGlobal(mev->pos()));
} }
return QTreeView::event(ev); 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 void WatchWindow::setModelData
(int role, const QVariant &value, const QModelIndex &index) (int role, const QVariant &value, const QModelIndex &index)
{ {

View File

@@ -73,6 +73,8 @@ private:
void editItem(const QModelIndex &idx); void editItem(const QModelIndex &idx);
void resetHelper(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(), void setModelData(int role, const QVariant &value = QVariant(),
const QModelIndex &index = QModelIndex()); const QModelIndex &index = QModelIndex());