diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index 1e5fe3528e2..efe58d0a057 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -440,9 +440,11 @@ void CdbEngine::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEd if (!(exp.at(0).isLetter() || exp.at(0) == QLatin1Char('_'))) return; const QByteArray iname = QByteArray(localsPrefixC) + exp.toAscii(); - if (const WatchData *data = watchHandler()->findItem(iname)) { - QToolTip::hideText(); - QToolTip::showText(mousePos, data->toToolTip()); + const QModelIndex index = watchHandler()->itemIndex(iname); + if (index.isValid()) { + showDebuggerToolTip(mousePos, watchHandler()->modelForIName(iname), index.row()); + } else { + hideDebuggerToolTip(); } } diff --git a/src/plugins/debugger/debuggertooltip.cpp b/src/plugins/debugger/debuggertooltip.cpp index caead02dc1a..ab65d8b417d 100644 --- a/src/plugins/debugger/debuggertooltip.cpp +++ b/src/plugins/debugger/debuggertooltip.cpp @@ -33,6 +33,8 @@ #include "debuggertooltip.h" +#include + #include #include @@ -42,6 +44,7 @@ #include #include #include +#include namespace Debugger { namespace Internal { @@ -177,6 +180,9 @@ void ToolTipWidget::run(const QPoint &point, const QModelIndex &index) QAbstractItemModel *model = const_cast(index.model()); move(point); setModel(model); + // Track changes in filter models. + connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), + this, SLOT(computeSize()), Qt::QueuedConnection); computeSize(); setRootIsDecorated(model->hasChildren(index)); } @@ -201,6 +207,40 @@ void showDebuggerToolTip(const QPoint &point, const QModelIndex &index) } } +// Model for tooltips filtering a local variable using the locals model. +class ToolTipRowFilterModel : public QSortFilterProxyModel +{ +public: + // Index points the variable to be filtered. + explicit ToolTipRowFilterModel(QAbstractItemModel *model, int row, QObject *parent = 0); + virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + +private: + const int m_row; +}; + +ToolTipRowFilterModel::ToolTipRowFilterModel(QAbstractItemModel *model, int row, QObject *parent) : + QSortFilterProxyModel(parent), m_row(row) +{ + setSourceModel(model); +} + +bool ToolTipRowFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + // Match on row for top level, else pass through. + return sourceParent.isValid() || sourceRow == m_row; +} + +// Show tooltip filtering a row of a source model. +void showDebuggerToolTip(const QPoint &point, QAbstractItemModel *model, int row) +{ + // Create a filter model parented on the widget to display column + ToolTipRowFilterModel *filterModel = new ToolTipRowFilterModel(model, row); + showDebuggerToolTip(point, filterModel->index(0, 0)); + QTC_ASSERT(theToolTipWidget, return; ) + filterModel->setParent(theToolTipWidget); +} + void hideDebuggerToolTip(int delay) { Q_UNUSED(delay) diff --git a/src/plugins/debugger/debuggertooltip.h b/src/plugins/debugger/debuggertooltip.h index 2b4f63e0872..9e7fec0ca0e 100644 --- a/src/plugins/debugger/debuggertooltip.h +++ b/src/plugins/debugger/debuggertooltip.h @@ -39,12 +39,15 @@ QT_BEGIN_NAMESPACE class QModelIndex; class QPoint; +class QAbstractItemModel; QT_END_NAMESPACE namespace Debugger { namespace Internal { void showDebuggerToolTip(const QPoint &point, const QModelIndex &rootIndex); +// Show tooltip filtering a row of a source model. +void showDebuggerToolTip(const QPoint &point, QAbstractItemModel *model, int row); void hideDebuggerToolTip(int delay = 0); } // namespace Internal