summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/scripttools/debugging/qscriptdebugger.cpp86
-rw-r--r--src/scripttools/debugging/qscriptdebuggercodewidget.cpp13
-rw-r--r--src/scripttools/debugging/qscriptdebuggercommand.cpp10
-rw-r--r--src/scripttools/debugging/qscriptdebuggercommand_p.h3
-rw-r--r--src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp41
-rw-r--r--src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp6
-rw-r--r--src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend_p.h2
-rw-r--r--src/scripttools/debugging/qscripttooltipproviderinterface_p.h5
8 files changed, 110 insertions, 56 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
diff --git a/src/scripttools/debugging/qscriptdebuggercodewidget.cpp b/src/scripttools/debugging/qscriptdebuggercodewidget.cpp
index 14ce0fe..b2f1dec 100644
--- a/src/scripttools/debugging/qscriptdebuggercodewidget.cpp
+++ b/src/scripttools/debugging/qscriptdebuggercodewidget.cpp
@@ -49,7 +49,6 @@
#include <QtCore/qdebug.h>
#include <QtGui/qboxlayout.h>
#include <QtGui/qstackedwidget.h>
-#include <QtGui/qtooltip.h>
QT_BEGIN_NAMESPACE
@@ -197,17 +196,7 @@ void QScriptDebuggerCodeWidgetPrivate::_q_onScriptsChanged()
void QScriptDebuggerCodeWidgetPrivate::_q_onToolTipRequest(
const QPoint &pos, int lineNumber, const QStringList &path)
{
- QString tip = toolTipProvider->toolTip(/*frameIndex=*/-1, lineNumber, path);
- 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(pos, tip);
+ toolTipProvider->showToolTip(pos, /*frameIndex=*/-1, lineNumber, path);
}
QScriptDebuggerCodeWidget::QScriptDebuggerCodeWidget(QWidget *parent)
diff --git a/src/scripttools/debugging/qscriptdebuggercommand.cpp b/src/scripttools/debugging/qscriptdebuggercommand.cpp
index c40bfc4..3ceb0d5 100644
--- a/src/scripttools/debugging/qscriptdebuggercommand.cpp
+++ b/src/scripttools/debugging/qscriptdebuggercommand.cpp
@@ -558,6 +558,16 @@ QScriptDebuggerCommand QScriptDebuggerCommand::contextsCheckpoint()
return cmd;
}
+QScriptDebuggerCommand QScriptDebuggerCommand::getPropertyExpressionValue(
+ int contextIndex, int lineNumber, const QStringList &path)
+{
+ QScriptDebuggerCommand cmd(GetPropertyExpressionValue);
+ cmd.setContextIndex(contextIndex);
+ cmd.setLineNumber(lineNumber);
+ cmd.setAttribute(UserAttribute, path);
+ return cmd;
+}
+
QScriptDebuggerCommand QScriptDebuggerCommand::newScriptObjectSnapshotCommand()
{
QScriptDebuggerCommand cmd(NewScriptObjectSnapshot);
diff --git a/src/scripttools/debugging/qscriptdebuggercommand_p.h b/src/scripttools/debugging/qscriptdebuggercommand_p.h
index 260e3ec..6cfdec5 100644
--- a/src/scripttools/debugging/qscriptdebuggercommand_p.h
+++ b/src/scripttools/debugging/qscriptdebuggercommand_p.h
@@ -106,6 +106,7 @@ public:
GetActivationObject,
GetScopeChain,
ContextsCheckpoint,
+ GetPropertyExpressionValue,
NewScriptObjectSnapshot,
ScriptObjectSnapshotCapture,
@@ -229,6 +230,8 @@ public:
static QScriptDebuggerCommand getActivationObjectCommand(int contextIndex);
static QScriptDebuggerCommand getScopeChainCommand(int contextIndex);
static QScriptDebuggerCommand contextsCheckpoint();
+ static QScriptDebuggerCommand getPropertyExpressionValue(int contextIndex, int lineNumber,
+ const QStringList &path);
static QScriptDebuggerCommand newScriptObjectSnapshotCommand();
static QScriptDebuggerCommand scriptObjectSnapshotCaptureCommand(int id, const QScriptDebuggerValue &object);
diff --git a/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp b/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp
index 1be8c5f..ce9aa03 100644
--- a/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp
+++ b/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp
@@ -105,8 +105,8 @@ QScriptDebuggerCommandExecutor::~QScriptDebuggerCommandExecutor()
Applies the given \a command to the given \a backend.
*/
QScriptDebuggerResponse QScriptDebuggerCommandExecutor::execute(
- QScriptDebuggerBackend *backend,
- const QScriptDebuggerCommand &command)
+ QScriptDebuggerBackend *backend,
+ const QScriptDebuggerCommand &command)
{
QScriptDebuggerResponse response;
switch (command.type()) {
@@ -300,6 +300,43 @@ QScriptDebuggerResponse QScriptDebuggerCommandExecutor::execute(
response.setResult(qVariantFromValue(backend->contextsCheckpoint()));
} break;
+ case QScriptDebuggerCommand::GetPropertyExpressionValue: {
+ QScriptContext *ctx = backend->context(command.contextIndex());
+ int lineNumber = command.lineNumber();
+ QVariant attr = command.attribute(QScriptDebuggerCommand::UserAttribute);
+ QStringList path = attr.toStringList();
+ if (!ctx || path.isEmpty())
+ break;
+ QScriptContextInfo ctxInfo(ctx);
+ if (ctx->callee().isValid()
+ && ((lineNumber < ctxInfo.functionStartLineNumber())
+ || (lineNumber > ctxInfo.functionEndLineNumber()))) {
+ break;
+ }
+ 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();
+ response.setResult(str);
+ break;
+ }
+ }
+ } break;
+
case QScriptDebuggerCommand::NewScriptObjectSnapshot: {
int id = backend->newScriptObjectSnapshot();
response.setResult(id);
diff --git a/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp b/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp
index 1e20ab4..a181711 100644
--- a/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp
+++ b/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp
@@ -251,6 +251,12 @@ int QScriptDebuggerCommandSchedulerFrontend::scheduleContextsCheckpoint()
return scheduleCommand(QScriptDebuggerCommand::contextsCheckpoint());
}
+int QScriptDebuggerCommandSchedulerFrontend::scheduleGetPropertyExpressionValue(
+ int contextIndex, int lineNumber, const QStringList &path)
+{
+ return scheduleCommand(QScriptDebuggerCommand::getPropertyExpressionValue(contextIndex, lineNumber, path));
+}
+
int QScriptDebuggerCommandSchedulerFrontend::scheduleEvaluate(int contextIndex,
const QString &program,
const QString &fileName,
diff --git a/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend_p.h b/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend_p.h
index ed9cbf9..ff9c570 100644
--- a/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend_p.h
+++ b/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend_p.h
@@ -109,6 +109,8 @@ public:
int scheduleGetActivationObject(int contextIndex);
int scheduleGetScopeChain(int contextIndex);
int scheduleContextsCheckpoint();
+ int scheduleGetPropertyExpressionValue(int contextIndex, int lineNumber,
+ const QStringList &path);
// iteration
int scheduleNewScriptValueIterator(const QScriptDebuggerValue &object);
diff --git a/src/scripttools/debugging/qscripttooltipproviderinterface_p.h b/src/scripttools/debugging/qscripttooltipproviderinterface_p.h
index 0a273d9..463f087 100644
--- a/src/scripttools/debugging/qscripttooltipproviderinterface_p.h
+++ b/src/scripttools/debugging/qscripttooltipproviderinterface_p.h
@@ -57,6 +57,7 @@
QT_BEGIN_NAMESPACE
+class QPoint;
class QStringList;
class Q_AUTOTEST_EXPORT QScriptToolTipProviderInterface
@@ -64,8 +65,8 @@ class Q_AUTOTEST_EXPORT QScriptToolTipProviderInterface
public:
virtual ~QScriptToolTipProviderInterface() {}
- virtual QString toolTip(int frameIndex, int lineNumber,
- const QStringList &path) = 0;
+ virtual void showToolTip(const QPoint &pos, int frameIndex,
+ int lineNumber, const QStringList &path) = 0;
};
QT_END_NAMESPACE