Commit 5992c744 authored by hjk's avatar hjk

Debugger: Robustify L&E context menu handling

Keep strings in lambdas instead of WatchItem pointers that
might get deleted while the menu is open.

Change-Id: Iec65924696da9754ffbbbb833ae0db990598c8e3
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent f572f7da
...@@ -1755,8 +1755,9 @@ QMenu *WatchModel::createFormatMenu(WatchItem *item) ...@@ -1755,8 +1755,9 @@ QMenu *WatchModel::createFormatMenu(WatchItem *item)
const DisplayFormats alternativeFormats = typeFormatList(item); const DisplayFormats alternativeFormats = typeFormatList(item);
const QString iname = item->iname;
const int typeFormat = theTypeFormats.value(stripForFormat(item->type), AutomaticFormat); const int typeFormat = theTypeFormats.value(stripForFormat(item->type), AutomaticFormat);
const int individualFormat = theIndividualFormats.value(item->iname, AutomaticFormat); const int individualFormat = theIndividualFormats.value(iname, AutomaticFormat);
auto addBaseChangeAction = [this, menu](const QString &text, int base) { auto addBaseChangeAction = [this, menu](const QString &text, int base) {
addCheckableAction(menu, text, true, theUnprintableBase == base, [this, base] { addCheckableAction(menu, text, true, theUnprintableBase == base, [this, base] {
...@@ -1775,26 +1776,26 @@ QMenu *WatchModel::createFormatMenu(WatchItem *item) ...@@ -1775,26 +1776,26 @@ QMenu *WatchModel::createFormatMenu(WatchItem *item)
const QString spacer = " "; const QString spacer = " ";
menu->addSeparator(); menu->addSeparator();
addAction(menu, tr("Change Display for Object Named \"%1\":").arg(item->name), false); addAction(menu, tr("Change Display for Object Named \"%1\":").arg(iname), false);
QString msg = (individualFormat == AutomaticFormat && typeFormat != AutomaticFormat) QString msg = (individualFormat == AutomaticFormat && typeFormat != AutomaticFormat)
? tr("Use Format for Type (Currently %1)").arg(nameForFormat(typeFormat)) ? tr("Use Format for Type (Currently %1)").arg(nameForFormat(typeFormat))
: QString(tr("Use Display Format Based on Type") + ' '); : QString(tr("Use Display Format Based on Type") + ' ');
addCheckableAction(menu, spacer + msg, true, individualFormat == AutomaticFormat, addCheckableAction(menu, spacer + msg, true, individualFormat == AutomaticFormat,
[this, item] { [this, iname] {
// FIXME: Extend to multi-selection. // FIXME: Extend to multi-selection.
//const QModelIndexList active = activeRows(); //const QModelIndexList active = activeRows();
//foreach (const QModelIndex &idx, active) //foreach (const QModelIndex &idx, active)
// setModelData(LocalsIndividualFormatRole, AutomaticFormat, idx); // setModelData(LocalsIndividualFormatRole, AutomaticFormat, idx);
setIndividualFormat(item->iname, AutomaticFormat); setIndividualFormat(iname, AutomaticFormat);
m_engine->updateLocals(); m_engine->updateLocals();
}); });
for (int format : alternativeFormats) { for (int format : alternativeFormats) {
addCheckableAction(menu, spacer + nameForFormat(format), true, format == individualFormat, addCheckableAction(menu, spacer + nameForFormat(format), true, format == individualFormat,
[this, act, format, item] { [this, act, format, iname] {
setIndividualFormat(item->iname, format); setIndividualFormat(iname, format);
m_engine->updateLocals(); m_engine->updateLocals();
}); });
} }
...@@ -1803,18 +1804,18 @@ QMenu *WatchModel::createFormatMenu(WatchItem *item) ...@@ -1803,18 +1804,18 @@ QMenu *WatchModel::createFormatMenu(WatchItem *item)
addAction(menu, tr("Change Display for Type \"%1\":").arg(item->type), false); addAction(menu, tr("Change Display for Type \"%1\":").arg(item->type), false);
addCheckableAction(menu, spacer + tr("Automatic"), true, typeFormat == AutomaticFormat, addCheckableAction(menu, spacer + tr("Automatic"), true, typeFormat == AutomaticFormat,
[this, item] { [this, iname] {
//const QModelIndexList active = activeRows(); //const QModelIndexList active = activeRows();
//foreach (const QModelIndex &idx, active) //foreach (const QModelIndex &idx, active)
// setModelData(LocalsTypeFormatRole, AutomaticFormat, idx); // setModelData(LocalsTypeFormatRole, AutomaticFormat, idx);
setTypeFormat(item->iname, AutomaticFormat); setTypeFormat(iname, AutomaticFormat);
m_engine->updateLocals(); m_engine->updateLocals();
}); });
for (int format : alternativeFormats) { for (int format : alternativeFormats) {
addCheckableAction(menu, spacer + nameForFormat(format), true, format == typeFormat, addCheckableAction(menu, spacer + nameForFormat(format), true, format == typeFormat,
[this, act, format, item] { [this, act, format, iname] {
setTypeFormat(item->iname, format); setTypeFormat(iname, format);
m_engine->updateLocals(); m_engine->updateLocals();
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment