Commit 1650aaae authored by hjk's avatar hjk Committed by David Schulz
Browse files

Debugger: Fold GdbToolTipContext into DebuggerToolTipIndex



Change-Id: Iee9201daa8d42ee4231895b1c78387acbc7caaac
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent f50ffd61
......@@ -479,9 +479,9 @@ bool CdbEngine::setToolTipExpression(const QPoint &mousePos,
const WatchData *localVariable = watchHandler()->findCppLocalVariable(exp);
if (!localVariable)
return false;
context.iname = localVariable->iname;
DebuggerToolTipWidget *tw = new DebuggerToolTipWidget;
tw->setContext(context);
tw->setIname(localVariable->iname);
tw->acquireEngine(this);
DebuggerToolTipManager::showToolTip(mousePos, tw);
return true;
......
......@@ -741,6 +741,7 @@ DebuggerToolTipWidget *DebuggerToolTipWidget::loadSessionDataI(QXmlStreamReader
offset.setX(attributes.value(offsetXAttribute).toString().toInt());
if (attributes.hasAttribute(offsetYAttribute))
offset.setY(attributes.value(offsetYAttribute).toString().toInt());
context.mousePosition = offset;
const QStringRef className = attributes.value(QLatin1String(toolTipClassAttributeC));
const QString engineType = attributes.value(QLatin1String(engineTypeAttributeC)).toString();
......@@ -762,8 +763,6 @@ DebuggerToolTipWidget *DebuggerToolTipWidget::loadSessionDataI(QXmlStreamReader
rc->setEngineType(engineType);
rc->doLoadSessionData(r);
rc->setCreationDate(creationDate);
if (!offset.isNull())
rc->setOffset(offset);
rc->pin();
} else {
qWarning("Unable to create debugger tool tip widget of class %s", qPrintable(className.toString()));
......@@ -949,7 +948,7 @@ void DebuggerToolTipWidget::doAcquireEngine(DebuggerEngine *engine)
// Create a filter model on the debugger's model and switch to it.
QAbstractItemModel *model = engine->watchModel();
TooltipFilterModel *filterModel =
new TooltipFilterModel(model, m_iname);
new TooltipFilterModel(model, m_context.iname);
swapModel(filterModel);
}
......@@ -958,7 +957,7 @@ QAbstractItemModel *DebuggerToolTipWidget::swapModel(QAbstractItemModel *newMode
QAbstractItemModel *oldModel = m_treeView->swapModel(newModel);
// When looking at some 'this.m_foo.x', expand all items
if (newModel) {
if (const int level = m_iname.count('.')) {
if (const int level = m_context.iname.count('.')) {
QModelIndex index = newModel->index(0, 0);
for (int i = 0; i < level && index.isValid(); i++, index = index.child(0, 0))
m_treeView->setExpanded(index, true);
......@@ -1019,9 +1018,9 @@ void DebuggerToolTipWidget::doSaveSessionData(QXmlStreamWriter &w) const
{
w.writeStartElement(QLatin1String(treeElementC));
QXmlStreamAttributes attributes;
if (!m_expression.isEmpty())
attributes.append(QLatin1String(treeExpressionAttributeC), m_expression);
attributes.append(QLatin1String(treeInameAttributeC), QLatin1String(m_iname));
if (!m_context.expression.isEmpty())
attributes.append(QLatin1String(treeExpressionAttributeC), m_context.expression);
attributes.append(QLatin1String(treeInameAttributeC), QLatin1String(m_context.iname));
w.writeAttributes(attributes);
if (QAbstractItemModel *model = m_treeView->model()) {
XmlWriterTreeModelVisitor v(model, w);
......@@ -1036,11 +1035,11 @@ void DebuggerToolTipWidget::doLoadSessionData(QXmlStreamReader &r)
return;
// Restore data to default model and show that.
const QXmlStreamAttributes attributes = r.attributes();
m_iname = attributes.value(QLatin1String(treeInameAttributeC)).toString().toLatin1();
m_expression = attributes.value(QLatin1String(treeExpressionAttributeC)).toString();
m_context.iname = attributes.value(QLatin1String(treeInameAttributeC)).toString().toLatin1();
m_context.expression = attributes.value(QLatin1String(treeExpressionAttributeC)).toString();
if (debugToolTips)
qDebug() << "DebuggerTreeViewToolTipWidget::doLoadSessionData() " << m_debuggerModel << m_iname;
setObjectName(QLatin1String("DebuggerTreeViewToolTipWidget: ") + QLatin1String(m_iname));
qDebug() << "DebuggerTreeViewToolTipWidget::doLoadSessionData() " << m_debuggerModel << m_context.iname;
setObjectName(QLatin1String("DebuggerTreeViewToolTipWidget: ") + QLatin1String(m_context.iname));
restoreTreeModel(r, m_defaultModel);
r.readNext(); // Skip </tree>
m_treeView->swapModel(m_defaultModel);
......@@ -1465,15 +1464,13 @@ void DebuggerToolTipManager::slotTooltipOverrideRequested(ITextEditor *editor,
}
DebuggerToolTipManager::ExpressionInamePairs
DebuggerToolTipManager::treeWidgetExpressions(const QString &fileName,
const QString &engineType,
const QString &function)
DebuggerToolTipContexts DebuggerToolTipManager::treeWidgetExpressions
(const QString &fileName, const QString &engineType, const QString &function)
{
ExpressionInamePairs rc;
DebuggerToolTipContexts rc;
foreach (const QPointer<DebuggerToolTipWidget> &tw, d->m_tooltips) {
if (!tw.isNull() && tw->matches(fileName, engineType, function))
rc.push_back(ExpressionInamePair(tw->expression(), tw->iname()));
rc.push_back(tw->context());
}
if (debugToolTips)
qDebug() << "DebuggerToolTipManager::treeWidgetExpressions"
......
......@@ -75,8 +75,15 @@ public:
int line;
int column;
QString function; //!< Optional function. This must be set by the engine as it is language-specific.
QPoint mousePosition;
QString expression;
QByteArray iname;
};
typedef QList<DebuggerToolTipContext> DebuggerToolTipContexts;
QDebug operator<<(QDebug, const DebuggerToolTipContext &);
class DebuggerToolTipTreeView;
......@@ -108,17 +115,8 @@ public:
QDate creationDate() const { return m_creationDate; }
void setCreationDate(const QDate &d) { m_creationDate = d; }
QPoint offset() const { return m_offset; }
void setOffset(const QPoint &o) { m_offset = o; }
static DebuggerToolTipWidget *loadSessionData(QXmlStreamReader &r);
QByteArray iname() const { return m_iname; }
void setIname(const QByteArray &e) { m_iname = e; }
QString expression() const { return m_expression; }
void setExpression(const QString &e) { m_expression = e; }
static QString treeModelClipboardContents(const QAbstractItemModel *m);
public slots:
......@@ -160,8 +158,6 @@ private:
static void restoreTreeModel(QXmlStreamReader &r, QStandardItemModel *m);
int m_debuggerModel;
QString m_expression;
QByteArray m_iname;
DebuggerToolTipTreeView *m_treeView;
QStandardItemModel *m_defaultModel;
......@@ -192,9 +188,6 @@ class DebuggerToolTipManager : public QObject
Q_OBJECT
public:
typedef QPair<QString, QByteArray> ExpressionInamePair;
typedef QList<ExpressionInamePair> ExpressionInamePairs;
explicit DebuggerToolTipManager(QObject *parent = 0);
~DebuggerToolTipManager();
......@@ -202,7 +195,7 @@ public:
static bool hasToolTips();
// Collect all expressions of DebuggerTreeViewToolTipWidget
static ExpressionInamePairs treeWidgetExpressions(const QString &fileName,
static DebuggerToolTipContexts treeWidgetExpressions(const QString &fileName,
const QString &engineType = QString(),
const QString &function= QString());
......
......@@ -91,17 +91,6 @@ using namespace Utils;
namespace Debugger {
namespace Internal {
class GdbToolTipContext : public DebuggerToolTipContext
{
public:
GdbToolTipContext(const DebuggerToolTipContext &c) :
DebuggerToolTipContext(c) {}
QPoint mousePosition;
QString expression;
QByteArray iname;
};
enum { debugPending = 0 };
#define PENDING_DEBUG(s) do { if (debugPending) qDebug() << s; } while (0)
......@@ -3979,8 +3968,6 @@ void GdbEngine::showToolTip()
}
DebuggerToolTipWidget *tw = new DebuggerToolTipWidget;
tw->setIname(m_toolTipContext->iname);
tw->setExpression(m_toolTipContext->expression);
tw->setContext(*m_toolTipContext);
tw->acquireEngine(this);
DebuggerToolTipManager::showToolTip(m_toolTipContext->mousePosition, tw);
......@@ -4031,7 +4018,7 @@ bool GdbEngine::setToolTipExpression(const QPoint &mousePos,
return true;
}
m_toolTipContext.reset(new GdbToolTipContext(context));
m_toolTipContext.reset(new DebuggerToolTipContext(context));
m_toolTipContext->mousePosition = mousePos;
m_toolTipContext->expression = exp;
m_toolTipContext->iname = iname;
......
......@@ -50,7 +50,6 @@ class DebugInfoTask;
class DebugInfoTaskHandler;
class GdbResponse;
class GdbMi;
class GdbToolTipContext;
class WatchData;
class DisassemblerAgentCookie;
......@@ -655,7 +654,7 @@ protected:
static QByteArray tooltipIName(const QString &exp);
QString tooltipExpression() const;
QScopedPointer<GdbToolTipContext> m_toolTipContext;
QScopedPointer<DebuggerToolTipContext> m_toolTipContext;
// For short-circuiting stack and thread list evaluation.
bool m_stackNeeded;
......
......@@ -62,34 +62,35 @@ void GdbEngine::updateLocalsPython(const UpdateParameters &params)
const QString fileName = stackHandler()->currentFrame().file;
const QString function = stackHandler()->currentFrame().function;
if (!fileName.isEmpty()) {
typedef DebuggerToolTipManager::ExpressionInamePair ExpressionInamePair;
typedef DebuggerToolTipManager::ExpressionInamePairs ExpressionInamePairs;
// Re-create tooltip items that are not filters on existing local variables in
// the tooltip model.
ExpressionInamePairs toolTips =
DebuggerToolTipContexts toolTips =
DebuggerToolTipManager::treeWidgetExpressions(fileName, objectName(), function);
const QString currentExpression = tooltipExpression();
if (!currentExpression.isEmpty()) {
int currentIndex = -1;
for (int i = 0; i < toolTips.size(); ++i) {
if (toolTips.at(i).first == currentExpression) {
if (toolTips.at(i).expression == currentExpression) {
currentIndex = i;
break;
}
}
if (currentIndex < 0)
toolTips.push_back(ExpressionInamePair(currentExpression, tooltipIName(currentExpression)));
if (currentIndex < 0) {
DebuggerToolTipContext context;
context.expression = currentExpression;
context.iname = tooltipIName(currentExpression);
toolTips.push_back(context);
}
}
foreach (const ExpressionInamePair &p, toolTips) {
if (p.second.startsWith("tooltip")) {
foreach (const DebuggerToolTipContext &p, toolTips) {
if (p.iname.startsWith("tooltip")) {
if (!watchers.isEmpty())
watchers += "##";
watchers += p.first.toLatin1();
watchers += p.expression.toLatin1();
watchers += '#';
watchers += p.second;
watchers += p.iname;
}
}
}
......
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