Debugger[CDB]: Show expandable tooltips.

By setting a filter model on the locals model.
Prepare infrastructure for filter models for pinneable
tooltips in debuggertooltips.
This commit is contained in:
Friedemann Kleint
2011-01-25 13:59:25 +01:00
parent b19521603c
commit bc30185bed
3 changed files with 48 additions and 3 deletions

View File

@@ -440,9 +440,11 @@ void CdbEngine::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEd
if (!(exp.at(0).isLetter() || exp.at(0) == QLatin1Char('_'))) if (!(exp.at(0).isLetter() || exp.at(0) == QLatin1Char('_')))
return; return;
const QByteArray iname = QByteArray(localsPrefixC) + exp.toAscii(); const QByteArray iname = QByteArray(localsPrefixC) + exp.toAscii();
if (const WatchData *data = watchHandler()->findItem(iname)) { const QModelIndex index = watchHandler()->itemIndex(iname);
QToolTip::hideText(); if (index.isValid()) {
QToolTip::showText(mousePos, data->toToolTip()); showDebuggerToolTip(mousePos, watchHandler()->modelForIName(iname), index.row());
} else {
hideDebuggerToolTip();
} }
} }

View File

@@ -33,6 +33,8 @@
#include "debuggertooltip.h" #include "debuggertooltip.h"
#include <utils/qtcassert.h>
#include <QtCore/QtDebug> #include <QtCore/QtDebug>
#include <QtCore/QPointer> #include <QtCore/QPointer>
@@ -42,6 +44,7 @@
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QScrollBar> #include <QtGui/QScrollBar>
#include <QtGui/QTreeView> #include <QtGui/QTreeView>
#include <QtGui/QSortFilterProxyModel>
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
@@ -177,6 +180,9 @@ void ToolTipWidget::run(const QPoint &point, const QModelIndex &index)
QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model()); QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model());
move(point); move(point);
setModel(model); setModel(model);
// Track changes in filter models.
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(computeSize()), Qt::QueuedConnection);
computeSize(); computeSize();
setRootIsDecorated(model->hasChildren(index)); 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) void hideDebuggerToolTip(int delay)
{ {
Q_UNUSED(delay) Q_UNUSED(delay)

View File

@@ -39,12 +39,15 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QModelIndex; class QModelIndex;
class QPoint; class QPoint;
class QAbstractItemModel;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
void showDebuggerToolTip(const QPoint &point, const QModelIndex &rootIndex); 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); void hideDebuggerToolTip(int delay = 0);
} // namespace Internal } // namespace Internal