summaryrefslogtreecommitdiffstats
path: root/src/scripttools/debugging/qscriptdebugger.cpp
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-06-12 13:32:20 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-06-12 13:32:20 (GMT)
commit5f287af53d146e76a11f23c889d9591d9c0b7b65 (patch)
tree08c2b9ae8260358a8d03621856d7d03fbda776dc /src/scripttools/debugging/qscriptdebugger.cpp
parentc9bddb70cb4804672cedb23dbfb3ca13724f0e68 (diff)
downloadQt-5f287af53d146e76a11f23c889d9591d9c0b7b65.zip
Qt-5f287af53d146e76a11f23c889d9591d9c0b7b65.tar.gz
Qt-5f287af53d146e76a11f23c889d9591d9c0b7b65.tar.bz2
make debugger's tooltip handling asynchronous
Needed for remote debugging.
Diffstat (limited to 'src/scripttools/debugging/qscriptdebugger.cpp')
-rw-r--r--src/scripttools/debugging/qscriptdebugger.cpp86
1 files changed, 46 insertions, 40 deletions
diff --git a/src/scripttools/debugging/qscriptdebugger.cpp b/src/scripttools/debugging/qscriptdebugger.cpp
index ce43572..d83a1d0 100644
--- a/src/scripttools/debugging/qscriptdebugger.cpp
+++ b/src/scripttools/debugging/qscriptdebugger.cpp
@@ -94,6 +94,7 @@
#include <QtGui/qevent.h>
#include <QtGui/qicon.h>
#include <QtGui/qinputdialog.h>
+#include <QtGui/qtooltip.h>
QT_BEGIN_NAMESPACE
typedef QPair<QList<qint64>, QList<qint64> > QScriptScriptsDelta;
@@ -171,8 +172,8 @@ public:
QScriptCompletionTaskInterface *createCompletionTask(
const QString &contents, int cursorPosition, int frameIndex, int options);
- QString toolTip(int frameIndex, int lineNumber,
- const QStringList &path);
+ void showToolTip(const QPoint &pos, int frameIndex,
+ int lineNumber, const QStringList &path);
static QPixmap pixmap(const QString &path);
@@ -633,11 +634,49 @@ bool QScriptDebuggerPrivate::debuggerEvent(const QScriptDebuggerEvent &event)
return !interactive;
}
+class QScriptToolTipJob : public QScriptDebuggerCommandSchedulerJob
+{
+public:
+ QScriptToolTipJob(const QPoint &pos, int frameIndex,
+ int lineNumber, const QStringList &path,
+ QScriptDebuggerCommandSchedulerInterface *scheduler)
+ : QScriptDebuggerCommandSchedulerJob(scheduler), m_pos(pos),
+ m_frameIndex(frameIndex), m_lineNumber(lineNumber), m_path(path)
+ {}
+
+ void start()
+ {
+ QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this);
+ frontend.scheduleGetPropertyExpressionValue(m_frameIndex, m_lineNumber, m_path);
+ }
+ void handleResponse(const QScriptDebuggerResponse &response, int /*commandId*/)
+ {
+ QString tip = response.result().toString();
+ if (tip.indexOf(QLatin1Char('\n')) != -1) {
+ QStringList lines = tip.split(QLatin1Char('\n'));
+ int lineCount = lines.size();
+ if (lineCount > 5) {
+ lines = lines.mid(0, 5);
+ lines.append(QString::fromLatin1("(... %0 more lines ...)").arg(lineCount - 5));
+ }
+ tip = lines.join(QLatin1String("\n"));
+ }
+ QToolTip::showText(m_pos, tip);
+ finish();
+ }
+
+private:
+ QPoint m_pos;
+ int m_frameIndex;
+ int m_lineNumber;
+ QStringList m_path;
+};
+
/*!
\reimp
*/
-QString QScriptDebuggerPrivate::toolTip(int frameIndex, int lineNumber,
- const QStringList &path)
+void QScriptDebuggerPrivate::showToolTip(const QPoint &pos, int frameIndex,
+ int lineNumber, const QStringList &path)
{
if (frameIndex == -1) {
if (stackWidget)
@@ -645,40 +684,8 @@ QString QScriptDebuggerPrivate::toolTip(int frameIndex, int lineNumber,
else
frameIndex = console->currentFrameIndex();
}
- // ### cheating for now, need to use async API
- QScriptEngineDebuggerFrontend *edf = static_cast<QScriptEngineDebuggerFrontend*>(frontend);
- QScriptDebuggerBackend *backend = edf->backend();
- QScriptContext *ctx = backend->context(frameIndex);
- if (!ctx || path.isEmpty())
- return QString();
- QScriptContextInfo ctxInfo(ctx);
- if (ctx->callee().isValid()
- && ((lineNumber < ctxInfo.functionStartLineNumber())
- || (lineNumber > ctxInfo.functionEndLineNumber()))) {
- return QString();
- }
- QScriptValueList objects;
- int pathIndex = 0;
- if (path.at(0) == QLatin1String("this")) {
- objects.append(ctx->thisObject());
- ++pathIndex;
- } else {
- objects << ctx->scopeChain();
- }
- for (int i = 0; i < objects.size(); ++i) {
- QScriptValue val = objects.at(i);
- for (int j = pathIndex; val.isValid() && (j < path.size()); ++j) {
- val = val.property(path.at(j));
- }
- if (val.isValid()) {
- bool hadException = (ctx->state() == QScriptContext::ExceptionState);
- QString str = val.toString();
- if (!hadException && backend->engine()->hasUncaughtException())
- backend->engine()->clearExceptions();
- return str;
- }
- }
- return QString();
+ QScriptDebuggerJob *job = new QScriptToolTipJob(pos, frameIndex, lineNumber, path, this);
+ scheduleJob(job);
}
/*!
@@ -1072,7 +1079,7 @@ class LoadLocalsJob : public QScriptDebuggerCommandSchedulerJob
public:
LoadLocalsJob(QScriptDebuggerPrivate *debugger, int frameIndex)
: QScriptDebuggerCommandSchedulerJob(debugger),
- m_debugger(debugger), m_frameIndex(frameIndex), m_state(0) {}
+ m_debugger(debugger), m_frameIndex(frameIndex) {}
void start()
{
@@ -1104,7 +1111,6 @@ public:
private:
QScriptDebuggerPrivate *m_debugger;
int m_frameIndex;
- int m_state;
};
class EmitStoppedSignalJob : public QScriptDebuggerJob