Commit 970264a8 authored by hjk's avatar hjk

Debugger: Operate tooltips on TextEditorWidgets, not TextEditor

Less indirection.

Change-Id: Ifbd7195e853d02bfd6562c817fc7f30079913faf
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 74f24c96
......@@ -447,19 +447,19 @@ void CdbEngine::syncVerboseLog(bool verboseLog)
postCommand(m_verboseLog ? QByteArray("!sym noisy") : QByteArray("!sym quiet"), 0);
}
bool CdbEngine::setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool CdbEngine::setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &contextIn)
{
if (debug)
qDebug() << Q_FUNC_INFO;
// Need a stopped debuggee and a cpp file in a valid frame
if (state() != InferiorStopOk || !isCppEditor(editor) || stackHandler()->currentIndex() < 0)
if (state() != InferiorStopOk || !isCppEditor(editorWidget) || stackHandler()->currentIndex() < 0)
return false;
// Determine expression and function
int line;
int column;
DebuggerToolTipContext context = contextIn;
QString exp = fixCppExpression(cppExpressionAt(editor, context.position, &line, &column, &context.function));
QString exp = fixCppExpression(cppExpressionAt(editorWidget, context.position, &line, &column, &context.function));
// Are we in the current stack frame
if (context.function.isEmpty() || exp.isEmpty() || context.function != stackHandler()->currentFrame().function)
return false;
......
......@@ -76,7 +76,7 @@ public:
// Factory function that returns 0 if the debug engine library cannot be found.
virtual bool setToolTipExpression(TextEditor::BaseTextEditor *editor,
virtual bool setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &ctx);
virtual void setupEngine();
virtual void setupInferior();
......
......@@ -1365,7 +1365,7 @@ DebuggerRunControl *DebuggerEngine::runControl() const
return d->runControl();
}
bool DebuggerEngine::setToolTipExpression(TextEditor::BaseTextEditor *,
bool DebuggerEngine::setToolTipExpression(TextEditor::BaseTextEditorWidget *,
const DebuggerToolTipContext &)
{
return false;
......
......@@ -46,7 +46,7 @@ class QMessageBox;
class QAbstractItemModel;
QT_END_NAMESPACE
namespace TextEditor { class BaseTextEditor; }
namespace TextEditor { class BaseTextEditorWidget; }
namespace Core { class IOptionsPage; }
namespace Debugger {
......@@ -144,7 +144,7 @@ public:
const DebuggerStartParameters &startParameters() const;
DebuggerStartParameters &startParameters();
virtual bool setToolTipExpression(TextEditor::BaseTextEditor *editor,
virtual bool setToolTipExpression(TextEditor::BaseTextEditorWidget *,
const Internal::DebuggerToolTipContext &);
virtual void updateWatchData(const Internal::WatchData &data,
......
......@@ -1105,7 +1105,7 @@ public slots:
exp = tc.selectedText();
} else {
int line, column;
exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
exp = cppExpressionAt(textEditor->editorWidget(), tc.position(), &line, &column);
}
if (currentEngine()->hasCapability(WatchComplexExpressionsCapability))
exp = removeObviousSideEffects(exp);
......
......@@ -489,7 +489,7 @@ public:
QList<QPointer<DebuggerToolTipWidget> > m_tooltips;
bool m_debugModeActive;
QPoint m_lastToolTipPoint;
Core::IEditor *m_lastToolTipEditor;
BaseTextEditorWidget *m_lastToolTipEditor;
};
static DebuggerToolTipManagerData *d = 0;
......@@ -1304,15 +1304,15 @@ void DebuggerToolTipManager::slotTooltipOverrideRequested
QTC_ASSERT(editor, return);
const int movedDistance = (point - d->m_lastToolTipPoint).manhattanLength();
if (d->m_lastToolTipEditor == editor && movedDistance < 25) {
if (d->m_lastToolTipEditor == editor->editorWidget() && movedDistance < 25) {
*handled = true;
return;
}
*handled = tryHandleToolTipOverride(editor, point, pos);
*handled = tryHandleToolTipOverride(editor->editorWidget(), point, pos);
if (*handled) {
d->m_lastToolTipEditor = editor;
d->m_lastToolTipEditor = editor->editorWidget();
d->m_lastToolTipPoint = point;
} else {
d->m_lastToolTipEditor = 0;
......@@ -1320,7 +1320,7 @@ void DebuggerToolTipManager::slotTooltipOverrideRequested
}
}
bool DebuggerToolTipManager::tryHandleToolTipOverride(BaseTextEditor *editor, const QPoint &point, int pos)
bool DebuggerToolTipManager::tryHandleToolTipOverride(BaseTextEditorWidget *editorWidget, const QPoint &point, int pos)
{
if (!boolSetting(UseToolTipsInMainEditor))
return false;
......@@ -1331,11 +1331,11 @@ bool DebuggerToolTipManager::tryHandleToolTipOverride(BaseTextEditor *editor, co
DebuggerToolTipContext context;
context.engineType = engine->objectName();
context.fileName = editor->document()->filePath();
context.fileName = editorWidget->textDocument()->filePath();
context.position = pos;
context.mousePosition = point;
editor->convertPosition(pos, &context.line, &context.column);
QString raw = cppExpressionAt(editor, context.position, &context.line, &context.column, &context.function);
editorWidget->convertPosition(pos, &context.line, &context.column);
QString raw = cppExpressionAt(editorWidget, context.position, &context.line, &context.column, &context.function);
context.expression = fixCppExpression(raw);
if (context.expression.isEmpty()) {
......@@ -1356,7 +1356,7 @@ bool DebuggerToolTipManager::tryHandleToolTipOverride(BaseTextEditor *editor, co
context.iname = "tooltip." + context.expression.toLatin1().toHex();
if (engine->setToolTipExpression(editor, context))
if (engine->setToolTipExpression(editorWidget, context))
return true;
// Other tooltip, close all in case mouse never entered the tooltip
......
......@@ -41,7 +41,7 @@ class QDebug;
QT_END_NAMESPACE
namespace Core { class IEditor; }
namespace TextEditor { class BaseTextEditor; }
namespace TextEditor { class BaseTextEditor; class BaseTextEditorWidget; }
namespace Debugger {
class DebuggerEngine;
......@@ -136,7 +136,7 @@ private slots:
const QPoint &point, int pos, bool *handled);
private:
bool tryHandleToolTipOverride(TextEditor::BaseTextEditor *editor,
bool tryHandleToolTipOverride(TextEditor::BaseTextEditorWidget *editorWidget,
const QPoint &point, int pos);
};
......
......@@ -3650,7 +3650,7 @@ void GdbEngine::resetLocation()
DebuggerEngine::resetLocation();
}
bool GdbEngine::setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool GdbEngine::setToolTipExpression(TextEditor::BaseTextEditorWidget *editor,
const DebuggerToolTipContext &context)
{
if (state() != InferiorStopOk || !isCppEditor(editor)) {
......
......@@ -407,7 +407,7 @@ protected:
//
// Watch specific stuff
//
virtual bool setToolTipExpression(TextEditor::BaseTextEditor *editor,
virtual bool setToolTipExpression(TextEditor::BaseTextEditorWidget *editor,
const DebuggerToolTipContext &);
virtual void assignValueInDebugger(const WatchData *data,
const QString &expr, const QVariant &value);
......
......@@ -837,9 +837,9 @@ void LldbEngine::resetLocation()
DebuggerEngine::resetLocation();
}
bool LldbEngine::setToolTipExpression(TextEditor::BaseTextEditor *editor, const DebuggerToolTipContext &context)
bool LldbEngine::setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget, const DebuggerToolTipContext &context)
{
if (state() != InferiorStopOk || !isCppEditor(editor)) {
if (state() != InferiorStopOk || !isCppEditor(editorWidget)) {
//qDebug() << "SUPPRESSING DEBUGGER TOOLTIP, INFERIOR NOT STOPPED "
// " OR NOT A CPPEDITOR";
return false;
......
......@@ -108,7 +108,7 @@ private:
void abortDebugger();
void resetLocation();
bool setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &);
void continueInferior();
......
......@@ -452,33 +452,21 @@ static WatchData m_toolTip;
static QPoint m_toolTipPos;
static QHash<QString, WatchData> m_toolTipCache;
bool PdbEngine::setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool PdbEngine::setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &ctx)
{
Q_UNUSED(editor)
if (state() != InferiorStopOk) {
//SDEBUG("SUPPRESSING DEBUGGER TOOLTIP, INFERIOR NOT STOPPED");
return false;
}
// Check mime type and get expression (borrowing some C++ - functions)
const QString javaPythonMimeType =
QLatin1String("application/javascript");
if (!editor->document() || editor->document()->mimeType() != javaPythonMimeType)
const QString javaPythonMimeType = QLatin1String("application/javascript");
if (editorWidget->textDocument()->mimeType() != javaPythonMimeType)
return false;
int line;
int column;
QString exp = cppExpressionAt(editor, ctx.position, &line, &column);
/*
if (m_toolTipCache.contains(exp)) {
const WatchData & data = m_toolTipCache[exp];
q->watchHandler()->removeChildren(data.iname);
insertData(data);
return;
}
*/
QString exp = cppExpressionAt(editorWidget, ctx.position, &line, &column);
QToolTip::hideText();
if (exp.isEmpty() || exp.startsWith(QLatin1Char('#'))) {
......
......@@ -75,7 +75,7 @@ private:
void shutdownInferior();
void shutdownEngine();
bool setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &);
void continueInferior();
......
......@@ -89,14 +89,15 @@ bool QmlCppEngine::canDisplayTooltip() const
return m_cppEngine->canDisplayTooltip() || m_qmlEngine->canDisplayTooltip();
}
bool QmlCppEngine::setToolTipExpression(TextEditor::BaseTextEditor *editor, const DebuggerToolTipContext &ctx)
bool QmlCppEngine::setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget, const DebuggerToolTipContext &ctx)
{
QTC_ASSERT(editor, return false);
QTC_ASSERT(editorWidget, return false);
bool success = false;
if (editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID)
success = m_cppEngine->setToolTipExpression(editor, ctx);
else if (editor->document()->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
success = m_qmlEngine->setToolTipExpression(editor, ctx);
Core::Id id = editorWidget->textDocument()->id();
if (id == CppEditor::Constants::CPPEDITOR_ID)
success = m_cppEngine->setToolTipExpression(editorWidget, ctx);
else if (id == QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
success = m_qmlEngine->setToolTipExpression(editorWidget, ctx);
return success;
}
......
......@@ -46,7 +46,7 @@ public:
~QmlCppEngine();
bool canDisplayTooltip() const;
bool setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &);
void updateWatchData(const WatchData &data,
const WatchUpdateFlags &flags);
......
......@@ -983,12 +983,12 @@ void QmlEngine::requestModuleSymbols(const QString &moduleName)
//
//////////////////////////////////////////////////////////////////////
bool QmlEngine::setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool QmlEngine::setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &ctx)
{
// This is processed by QML inspector, which has dependencies to
// the qml js editor. Makes life easier.
emit tooltipRequested(ctx.mousePosition, editor, ctx.position);
emit tooltipRequested(ctx.mousePosition, editorWidget, ctx.position);
return true;
}
......
......@@ -88,7 +88,7 @@ public:
signals:
void tooltipRequested(const QPoint &mousePos,
TextEditor::BaseTextEditor *editor, int cursorPos);
TextEditor::BaseTextEditorWidget *editorWidget, int cursorPos);
void aboutToNotifyInferiorSetupOk();
private slots:
......@@ -127,7 +127,7 @@ private:
void shutdownInferior();
void shutdownEngine();
bool setToolTipExpression(TextEditor::BaseTextEditor *editor,
bool setToolTipExpression(TextEditor::BaseTextEditorWidget *editorWidget,
const DebuggerToolTipContext &);
void continueInferior();
......
......@@ -313,17 +313,14 @@ bool getUninitializedVariables(const CPlusPlus::Snapshot &snapshot,
// Editor tooltip support
bool isCppEditor(Core::IEditor *editor)
bool isCppEditor(TextEditor::BaseTextEditorWidget *editorWidget)
{
const Core::IDocument *document= editor->document();
if (!document)
return false;
const TextEditor::BaseTextDocument *document = editorWidget->textDocument();
return CppTools::ProjectFile::classify(document->filePath()) != CppTools::ProjectFile::Unclassified;
}
// Return the Cpp expression, and, if desired, the function
QString cppExpressionAt(TextEditor::BaseTextEditor *editor, int pos,
QString cppExpressionAt(TextEditor::BaseTextEditorWidget *editorWidget, int pos,
int *line, int *column, QString *function /* = 0 */)
{
using namespace CppTools;
......@@ -331,18 +328,12 @@ QString cppExpressionAt(TextEditor::BaseTextEditor *editor, int pos,
if (function)
function->clear();
const QPlainTextEdit *plaintext = qobject_cast<QPlainTextEdit*>(editor->widget());
if (!plaintext)
return QString();
QTextCursor tc = plaintext->textCursor();
QTextCursor tc = editorWidget->textCursor();
QString expr = tc.selectedText();
CppModelManager *modelManager = CppModelManager::instance();
if (expr.isEmpty() && modelManager) {
QTextDocument *doc = plaintext->document();
QTC_ASSERT(doc, return QString());
tc.setPosition(pos);
const QChar ch = doc->characterAt(pos);
const QChar ch = editorWidget->characterAt(pos);
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
tc.movePosition(QTextCursor::EndOfWord);
......@@ -357,10 +348,8 @@ QString cppExpressionAt(TextEditor::BaseTextEditor *editor, int pos,
}
if (function && !expr.isEmpty())
if (const Core::IDocument *document= editor->document())
if (modelManager)
*function = AbstractEditorSupport::functionAt(modelManager,
document->filePath(), *line, *column);
*function = AbstractEditorSupport::functionAt(modelManager,
editorWidget->textDocument()->filePath(), *line, *column);
return expr;
}
......
......@@ -32,16 +32,15 @@
#include <QString>
namespace TextEditor { class BaseTextEditor; }
namespace Core { class IEditor; }
namespace TextEditor { class BaseTextEditorWidget; }
namespace CPlusPlus { class Snapshot; }
namespace Debugger {
namespace Internal {
// Editor tooltip support
bool isCppEditor(Core::IEditor *editor);
QString cppExpressionAt(TextEditor::BaseTextEditor *editor, int pos,
bool isCppEditor(TextEditor::BaseTextEditorWidget *editorWidget);
QString cppExpressionAt(TextEditor::BaseTextEditorWidget *editorWidget, int pos,
int *line, int *column, QString *function = 0);
QString fixCppExpression(const QString &exp);
QString cppFunctionAt(const QString &fileName, int line);
......
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