forked from qt-creator/qt-creator
Debugger: Modernize WatchWindow action handling
Change-Id: I4b3356a85d0e6127939a1a10d0432fc488ab098c Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -69,14 +69,6 @@
|
|||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
|
||||||
//#define USE_WATCH_MODEL_TEST 1
|
|
||||||
|
|
||||||
#if USE_WATCH_MODEL_TEST
|
|
||||||
#include <modeltest.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QModelIndex)
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// WatchDelegate
|
// WatchDelegate
|
||||||
@@ -86,8 +78,6 @@ Q_DECLARE_METATYPE(QModelIndex)
|
|||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
const char CurrentIndex[] = "CurrentIndex";
|
|
||||||
|
|
||||||
class WatchDelegate : public QItemDelegate
|
class WatchDelegate : public QItemDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -470,10 +460,8 @@ WatchTreeView::WatchTreeView(WatchType type)
|
|||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
setDropIndicatorShown(true);
|
setDropIndicatorShown(true);
|
||||||
|
|
||||||
connect(this, SIGNAL(expanded(QModelIndex)),
|
connect(this, &QTreeView::expanded, this, &WatchTreeView::expandNode);
|
||||||
SLOT(expandNode(QModelIndex)));
|
connect(this, &QTreeView::collapsed, this, &WatchTreeView::collapseNode);
|
||||||
connect(this, SIGNAL(collapsed(QModelIndex)),
|
|
||||||
SLOT(collapseNode(QModelIndex)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchTreeView::expandNode(const QModelIndex &idx)
|
void WatchTreeView::expandNode(const QModelIndex &idx)
|
||||||
@@ -601,28 +589,23 @@ void WatchTreeView::fillFormatMenu(QMenu *formatMenu, const QModelIndex &mi)
|
|||||||
formatMenu->addAction(tr("Treat All Characters as Printable"));
|
formatMenu->addAction(tr("Treat All Characters as Printable"));
|
||||||
showUnprintableUnicode->setCheckable(true);
|
showUnprintableUnicode->setCheckable(true);
|
||||||
showUnprintableUnicode->setChecked(unprintableBase == 0);
|
showUnprintableUnicode->setChecked(unprintableBase == 0);
|
||||||
showUnprintableUnicode->setData(0);
|
|
||||||
showUnprintableEscape =
|
showUnprintableEscape =
|
||||||
formatMenu->addAction(tr("Show Unprintable Characters as Escape Sequences"));
|
formatMenu->addAction(tr("Show Unprintable Characters as Escape Sequences"));
|
||||||
showUnprintableEscape->setCheckable(true);
|
showUnprintableEscape->setCheckable(true);
|
||||||
showUnprintableEscape->setChecked(unprintableBase == -1);
|
showUnprintableEscape->setChecked(unprintableBase == -1);
|
||||||
showUnprintableEscape->setData(-1);
|
|
||||||
showUnprintableOctal =
|
showUnprintableOctal =
|
||||||
formatMenu->addAction(tr("Show Unprintable Characters as Octal"));
|
formatMenu->addAction(tr("Show Unprintable Characters as Octal"));
|
||||||
showUnprintableOctal->setCheckable(true);
|
showUnprintableOctal->setCheckable(true);
|
||||||
showUnprintableOctal->setChecked(unprintableBase == 8);
|
showUnprintableOctal->setChecked(unprintableBase == 8);
|
||||||
showUnprintableOctal->setData(8);
|
|
||||||
showUnprintableHexadecimal =
|
showUnprintableHexadecimal =
|
||||||
formatMenu->addAction(tr("Show Unprintable Characters as Hexadecimal"));
|
formatMenu->addAction(tr("Show Unprintable Characters as Hexadecimal"));
|
||||||
showUnprintableHexadecimal->setCheckable(true);
|
showUnprintableHexadecimal->setCheckable(true);
|
||||||
showUnprintableHexadecimal->setChecked(unprintableBase == 16);
|
showUnprintableHexadecimal->setChecked(unprintableBase == 16);
|
||||||
showUnprintableHexadecimal->setData(16);
|
|
||||||
|
|
||||||
connect(showUnprintableUnicode, SIGNAL(triggered()), SLOT(onShowUnprintable()));
|
|
||||||
connect(showUnprintableEscape, SIGNAL(triggered()), SLOT(onShowUnprintable()));
|
|
||||||
connect(showUnprintableOctal, SIGNAL(triggered()), SLOT(onShowUnprintable()));
|
|
||||||
connect(showUnprintableHexadecimal, SIGNAL(triggered()), SLOT(onShowUnprintable()));
|
|
||||||
|
|
||||||
|
connect(showUnprintableUnicode, &QAction::triggered, [this] { showUnprintable(0); });
|
||||||
|
connect(showUnprintableEscape, &QAction::triggered, [this] { showUnprintable(-1); });
|
||||||
|
connect(showUnprintableOctal, &QAction::triggered, [this] { showUnprintable(8); });
|
||||||
|
connect(showUnprintableHexadecimal, &QAction::triggered, [this] { showUnprintable(16); });
|
||||||
|
|
||||||
const QString spacer = QLatin1String(" ");
|
const QString spacer = QLatin1String(" ");
|
||||||
formatMenu->addSeparator();
|
formatMenu->addSeparator();
|
||||||
@@ -637,19 +620,22 @@ void WatchTreeView::fillFormatMenu(QMenu *formatMenu, const QModelIndex &mi)
|
|||||||
QAction *clearIndividualFormatAction = formatMenu->addAction(spacer + msg);
|
QAction *clearIndividualFormatAction = formatMenu->addAction(spacer + msg);
|
||||||
clearIndividualFormatAction->setCheckable(true);
|
clearIndividualFormatAction->setCheckable(true);
|
||||||
clearIndividualFormatAction->setChecked(individualFormat == AutomaticFormat);
|
clearIndividualFormatAction->setChecked(individualFormat == AutomaticFormat);
|
||||||
connect(clearIndividualFormatAction, SIGNAL(triggered()),
|
connect(clearIndividualFormatAction, &QAction::triggered, [this] {
|
||||||
SLOT(onClearIndividualFormat()));
|
const QModelIndexList active = activeRows();
|
||||||
|
foreach (const QModelIndex &idx, active)
|
||||||
|
setModelData(LocalsIndividualFormatRole, AutomaticFormat, idx);
|
||||||
|
});
|
||||||
|
|
||||||
for (int i = 0; i != alternativeFormats.size(); ++i) {
|
for (int i = 0; i != alternativeFormats.size(); ++i) {
|
||||||
const QString display = spacer + alternativeFormats.at(i).display;
|
const QString display = spacer + alternativeFormats.at(i).display;
|
||||||
const int format = alternativeFormats.at(i).format;
|
const int format = alternativeFormats.at(i).format;
|
||||||
QAction *act = new QAction(display, formatMenu);
|
QAction *act = new QAction(display, formatMenu);
|
||||||
act->setData(format);
|
|
||||||
act->setCheckable(true);
|
act->setCheckable(true);
|
||||||
act->setChecked(format == individualFormat);
|
act->setChecked(format == individualFormat);
|
||||||
act->setProperty(CurrentIndex, QVariant::fromValue(mi));
|
|
||||||
formatMenu->addAction(act);
|
formatMenu->addAction(act);
|
||||||
connect(act, SIGNAL(triggered()), SLOT(onIndividualFormatChange()));
|
connect(act, &QAction::triggered, [this, act, format, mi] {
|
||||||
|
setModelData(LocalsIndividualFormatRole, format, mi);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
formatMenu->addSeparator();
|
formatMenu->addSeparator();
|
||||||
@@ -659,58 +645,30 @@ void WatchTreeView::fillFormatMenu(QMenu *formatMenu, const QModelIndex &mi)
|
|||||||
QAction *clearTypeFormatAction = formatMenu->addAction(spacer + tr("Automatic"));
|
QAction *clearTypeFormatAction = formatMenu->addAction(spacer + tr("Automatic"));
|
||||||
clearTypeFormatAction->setCheckable(true);
|
clearTypeFormatAction->setCheckable(true);
|
||||||
clearTypeFormatAction->setChecked(typeFormat == AutomaticFormat);
|
clearTypeFormatAction->setChecked(typeFormat == AutomaticFormat);
|
||||||
connect(clearTypeFormatAction, SIGNAL(triggered()), SLOT(onClearTypeFormat()));
|
connect(clearTypeFormatAction, &QAction::triggered, [this] {
|
||||||
|
const QModelIndexList active = activeRows();
|
||||||
|
foreach (const QModelIndex &idx, active)
|
||||||
|
setModelData(LocalsTypeFormatRole, AutomaticFormat, idx);
|
||||||
|
});
|
||||||
|
|
||||||
for (int i = 0; i != alternativeFormats.size(); ++i) {
|
for (int i = 0; i != alternativeFormats.size(); ++i) {
|
||||||
const QString display = spacer + alternativeFormats.at(i).display;
|
const QString display = spacer + alternativeFormats.at(i).display;
|
||||||
QAction *act = new QAction(display, formatMenu);
|
QAction *act = new QAction(display, formatMenu);
|
||||||
const int format = alternativeFormats.at(i).format;
|
const int format = alternativeFormats.at(i).format;
|
||||||
act->setData(format);
|
|
||||||
act->setCheckable(true);
|
act->setCheckable(true);
|
||||||
act->setChecked(format == typeFormat);
|
act->setChecked(format == typeFormat);
|
||||||
act->setProperty(CurrentIndex, QVariant::fromValue(mi));
|
|
||||||
formatMenu->addAction(act);
|
formatMenu->addAction(act);
|
||||||
connect(act, SIGNAL(triggered()), SLOT(onTypeFormatChange()));
|
connect(act, &QAction::triggered, [this, act, format, mi] {
|
||||||
|
setModelData(LocalsTypeFormatRole, format, mi);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchTreeView::onClearTypeFormat()
|
void WatchTreeView::showUnprintable(int base)
|
||||||
{
|
{
|
||||||
const QModelIndexList active = activeRows();
|
|
||||||
foreach (const QModelIndex &idx, active)
|
|
||||||
setModelData(LocalsTypeFormatRole, AutomaticFormat, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WatchTreeView::onClearIndividualFormat()
|
|
||||||
{
|
|
||||||
const QModelIndexList active = activeRows();
|
|
||||||
foreach (const QModelIndex &idx, active)
|
|
||||||
setModelData(LocalsIndividualFormatRole, AutomaticFormat, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WatchTreeView::onShowUnprintable()
|
|
||||||
{
|
|
||||||
QAction *act = qobject_cast<QAction *>(sender());
|
|
||||||
QTC_ASSERT(act, return);
|
|
||||||
DebuggerEngine *engine = currentEngine();
|
DebuggerEngine *engine = currentEngine();
|
||||||
WatchHandler *handler = engine->watchHandler();
|
WatchHandler *handler = engine->watchHandler();
|
||||||
handler->setUnprintableBase(act->data().toInt());
|
handler->setUnprintableBase(base);
|
||||||
}
|
|
||||||
|
|
||||||
void WatchTreeView::onTypeFormatChange()
|
|
||||||
{
|
|
||||||
QAction *act = qobject_cast<QAction *>(sender());
|
|
||||||
QTC_ASSERT(act, return);
|
|
||||||
QModelIndex idx = act->property(CurrentIndex).value<QModelIndex>();
|
|
||||||
setModelData(LocalsTypeFormatRole, act->data(), idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WatchTreeView::onIndividualFormatChange()
|
|
||||||
{
|
|
||||||
QAction *act = qobject_cast<QAction *>(sender());
|
|
||||||
QTC_ASSERT(act, return);
|
|
||||||
QModelIndex idx = act->property(CurrentIndex).value<QModelIndex>();
|
|
||||||
setModelData(LocalsIndividualFormatRole, act->data(), idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev)
|
void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev)
|
||||||
@@ -992,14 +950,14 @@ void WatchTreeView::setModel(QAbstractItemModel *model)
|
|||||||
header()->hide();
|
header()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(model, SIGNAL(layoutChanged()), SLOT(resetHelper()));
|
auto watchModel = qobject_cast<WatchModelBase *>(model);
|
||||||
connect(model, SIGNAL(currentIndexRequested(QModelIndex)),
|
QTC_ASSERT(watchModel, return);
|
||||||
SLOT(setCurrentIndex(QModelIndex)));
|
connect(model, &QAbstractItemModel::layoutChanged,
|
||||||
connect(model, SIGNAL(itemIsExpanded(QModelIndex)),
|
this, &WatchTreeView::resetHelper);
|
||||||
SLOT(handleItemIsExpanded(QModelIndex)));
|
connect(watchModel, &WatchModelBase::currentIndexRequested,
|
||||||
#if USE_WATCH_MODEL_TEST
|
this, &QAbstractItemView::setCurrentIndex);
|
||||||
(void) new ModelTest(&m_filter, this);
|
connect(watchModel, &WatchModelBase::itemIsExpanded,
|
||||||
#endif
|
this, &WatchTreeView::handleItemIsExpanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchTreeView::rowActivated(const QModelIndex &index)
|
void WatchTreeView::rowActivated(const QModelIndex &index)
|
||||||
@@ -1103,8 +1061,8 @@ public:
|
|||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
connect(m_buttons, SIGNAL(accepted()), m_lineEdit, SLOT(onEditingFinished()));
|
connect(m_buttons, SIGNAL(accepted()), m_lineEdit, SLOT(onEditingFinished()));
|
||||||
connect(m_buttons, SIGNAL(accepted()), SLOT(accept()));
|
connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
connect(m_buttons, SIGNAL(rejected()), SLOT(reject()));
|
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
connect(m_hint, SIGNAL(linkActivated(QString)),
|
connect(m_hint, SIGNAL(linkActivated(QString)),
|
||||||
Core::HelpManager::instance(), SLOT(handleHelpRequest(QString)));
|
Core::HelpManager::instance(), SLOT(handleHelpRequest(QString)));
|
||||||
}
|
}
|
||||||
|
@@ -67,20 +67,13 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void currentIndexChanged(const QModelIndex ¤tIndex);
|
void currentIndexChanged(const QModelIndex ¤tIndex);
|
||||||
|
|
||||||
private slots:
|
private:
|
||||||
void resetHelper();
|
void resetHelper();
|
||||||
void expandNode(const QModelIndex &idx);
|
void expandNode(const QModelIndex &idx);
|
||||||
void collapseNode(const QModelIndex &idx);
|
void collapseNode(const QModelIndex &idx);
|
||||||
void adjustSlider();
|
void adjustSlider();
|
||||||
|
|
||||||
void onClearIndividualFormat();
|
void showUnprintable(int base);
|
||||||
void onClearTypeFormat();
|
|
||||||
void onShowUnprintable();
|
|
||||||
|
|
||||||
void onTypeFormatChange();
|
|
||||||
void onIndividualFormatChange();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void doItemsLayout();
|
void doItemsLayout();
|
||||||
void keyPressEvent(QKeyEvent *ev);
|
void keyPressEvent(QKeyEvent *ev);
|
||||||
void contextMenuEvent(QContextMenuEvent *ev);
|
void contextMenuEvent(QContextMenuEvent *ev);
|
||||||
|
Reference in New Issue
Block a user