diff options
Diffstat (limited to 'src/scripttools')
62 files changed, 938 insertions, 534 deletions
diff --git a/src/scripttools/debugging/debugging.pri b/src/scripttools/debugging/debugging.pri index fa39e83..2082fd0 100644 --- a/src/scripttools/debugging/debugging.pri +++ b/src/scripttools/debugging/debugging.pri @@ -111,7 +111,8 @@ SOURCES += \ $$PWD/qscriptbreakpointswidget.cpp \ $$PWD/qscriptbreakpointsmodel.cpp \ $$PWD/qscripterrorlogwidgetinterface.cpp \ - $$PWD/qscripterrorlogwidget.cpp + $$PWD/qscripterrorlogwidget.cpp \ + $$PWD/qscriptdebuggerstandardwidgetfactory.cpp HEADERS += \ $$PWD/qscriptdebuggerconsolewidgetinterface_p_p.h \ @@ -148,7 +149,8 @@ HEADERS += \ $$PWD/qscripterrorlogwidgetinterface_p_p.h \ $$PWD/qscripterrorlogwidgetinterface_p.h \ $$PWD/qscripterrorlogwidget_p.h \ - $$PWD/qscriptdebuggerwidgetfactoryinterface_p.h + $$PWD/qscriptdebuggerwidgetfactoryinterface_p.h \ + $$PWD/qscriptdebuggerstandardwidgetfactory_p.h SOURCES += \ $$PWD/qscriptenginedebugger.cpp diff --git a/src/scripttools/debugging/qscriptbreakpointdata.cpp b/src/scripttools/debugging/qscriptbreakpointdata.cpp index 1255072..2889df0 100644 --- a/src/scripttools/debugging/qscriptbreakpointdata.cpp +++ b/src/scripttools/debugging/qscriptbreakpointdata.cpp @@ -136,7 +136,6 @@ QScriptBreakpointData::QScriptBreakpointData(const QScriptBreakpointData &other) */ QScriptBreakpointData::~QScriptBreakpointData() { - delete d_ptr; } /*! @@ -355,7 +354,7 @@ bool QScriptBreakpointData::operator!=(const QScriptBreakpointData &other) const */ QDataStream &operator<<(QDataStream &out, const QScriptBreakpointData &data) { - const QScriptBreakpointDataPrivate *d = data.d_ptr; + const QScriptBreakpointDataPrivate *d = data.d_ptr.data(); out << d->scriptId; out << d->fileName; out << d->lineNumber; @@ -377,7 +376,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptBreakpointData &data) */ QDataStream &operator>>(QDataStream &in, QScriptBreakpointData &data) { - QScriptBreakpointDataPrivate *d = data.d_ptr; + QScriptBreakpointDataPrivate *d = data.d_ptr.data(); in >> d->scriptId; in >> d->fileName; in >> d->lineNumber; diff --git a/src/scripttools/debugging/qscriptbreakpointdata_p.h b/src/scripttools/debugging/qscriptbreakpointdata_p.h index 966fd41..c02719b 100644 --- a/src/scripttools/debugging/qscriptbreakpointdata_p.h +++ b/src/scripttools/debugging/qscriptbreakpointdata_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qmap.h> QT_BEGIN_NAMESPACE @@ -114,7 +114,7 @@ public: bool operator!=(const QScriptBreakpointData &other) const; private: - QScriptBreakpointDataPrivate *d_ptr; + QScopedPointer<QScriptBreakpointDataPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptBreakpointData) }; diff --git a/src/scripttools/debugging/qscriptcompletiontask.cpp b/src/scripttools/debugging/qscriptcompletiontask.cpp index a212700..83cb484 100644 --- a/src/scripttools/debugging/qscriptcompletiontask.cpp +++ b/src/scripttools/debugging/qscriptcompletiontask.cpp @@ -44,12 +44,10 @@ #include "qscriptdebuggerconsole_p.h" #include "qscriptdebuggerconsolecommand_p.h" #include "qscriptdebuggerconsolecommandmanager_p.h" - -#include "qscriptenginedebuggerfrontend_p.h" // ### kill -#include "qscriptdebuggerbackend_p.h" // ### kill -#include <QtScript/qscriptcontext.h> -#include <QtScript/qscriptvalue.h> -#include <QtScript/qscriptvalueiterator.h> +#include "qscriptdebuggercommandschedulerjob_p.h" +#include "qscriptdebuggercommandschedulerfrontend_p.h" +#include "qscriptdebuggerjobschedulerinterface_p.h" +#include "qscriptdebuggerresponse_p.h" #include "private/qobject_p.h" @@ -67,16 +65,19 @@ public: ~QScriptCompletionTaskPrivate(); void completeScriptExpression(); + void emitFinished(); QString contents; int cursorPosition; int frameIndex; - QScriptDebuggerFrontend *frontend; + QScriptDebuggerCommandSchedulerInterface *commandScheduler; + QScriptDebuggerJobSchedulerInterface *jobScheduler; QScriptDebuggerConsole *console; }; QScriptCompletionTaskPrivate::QScriptCompletionTaskPrivate() - : cursorPosition(0), frameIndex(0), frontend(0), console(0) + : cursorPosition(0), frameIndex(0), commandScheduler(0), + jobScheduler(0), console(0) { } @@ -84,28 +85,33 @@ QScriptCompletionTaskPrivate::~QScriptCompletionTaskPrivate() { } -QScriptCompletionTask::QScriptCompletionTask( - const QString &contents, int cursorPosition, - int frameIndex, QScriptDebuggerFrontend *frontend, - QScriptDebuggerConsole *console, - QObject *parent) - : QScriptCompletionTaskInterface( - *new QScriptCompletionTaskPrivate, parent) +class QScriptCompleteExpressionJob : public QScriptDebuggerCommandSchedulerJob { - Q_D(QScriptCompletionTask); - d->contents = contents; - d->cursorPosition = cursorPosition; - if ((frameIndex == -1) && console) - d->frameIndex = console->currentFrameIndex(); - else - d->frameIndex = frameIndex; - d->frontend = frontend; - d->console = console; -} +public: + QScriptCompleteExpressionJob(int frameIndex, const QStringList &path, + QScriptCompletionTaskPrivate *task, + QScriptDebuggerCommandSchedulerInterface *scheduler) + : QScriptDebuggerCommandSchedulerJob(scheduler), + m_frameIndex(frameIndex), m_path(path), m_task(task) + {} -QScriptCompletionTask::~QScriptCompletionTask() -{ -} + void start() + { + QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); + frontend.scheduleGetCompletions(m_frameIndex, m_path); + } + void handleResponse(const QScriptDebuggerResponse &response, int /*commandId*/) + { + m_task->results = response.result().toStringList(); + m_task->emitFinished(); + finish(); + } + +private: + int m_frameIndex; + QStringList m_path; + QScriptCompletionTaskPrivate *m_task; +}; namespace { @@ -123,17 +129,49 @@ static bool isPrefixOf(const QString &prefix, const QString &what) } // namespace +class QScriptCompleteScriptsJob : public QScriptDebuggerCommandSchedulerJob +{ +public: + QScriptCompleteScriptsJob(const QString &prefix, QScriptCompletionTaskPrivate *task, + QScriptDebuggerCommandSchedulerInterface *scheduler) + : QScriptDebuggerCommandSchedulerJob(scheduler), + m_prefix(prefix), m_task(task) + {} + + void start() + { + QScriptDebuggerCommandSchedulerFrontend frontend(commandScheduler(), this); + frontend.scheduleGetScripts(); + } + void handleResponse(const QScriptDebuggerResponse &response, int /*commandId*/) + { + QScriptScriptMap scripts = response.resultAsScripts(); + QScriptScriptMap::const_iterator it; + for (it = scripts.constBegin(); it != scripts.constEnd(); ++it) { + QString fileName = it.value().fileName(); + if (isPrefixOf(m_prefix, fileName)) + m_task->results.append(fileName); + } + m_task->emitFinished(); + finish(); + } +private: + QString m_prefix; + QScriptCompletionTaskPrivate *m_task; +}; + void QScriptCompletionTaskPrivate::completeScriptExpression() { int pos = cursorPosition; if ((pos > 0) && contents.at(pos-1).isNumber()) { // completion of numbers is pointless + emitFinished(); return; } while ((pos > 0) && isIdentChar(contents.at(pos-1))) --pos; - int pos2 = cursorPosition; + int pos2 = cursorPosition - 1; while ((pos2 < contents.size()-1) && isIdentChar(contents.at(pos2+1))) ++pos2; QString ident = contents.mid(pos, pos2 - pos + 1); @@ -149,65 +187,41 @@ void QScriptCompletionTaskPrivate::completeScriptExpression() path.prepend(contents.mid(pos, pos2 - pos)); } - // ### super-cheating for now; have to use the async API - QScriptEngineDebuggerFrontend *edf = static_cast<QScriptEngineDebuggerFrontend*>(frontend); - QScriptDebuggerBackend *backend = edf->backend(); - QScriptContext *ctx = backend->context(frameIndex); - QScriptValueList objects; - QString prefix = path.last(); - QSet<QString> matches; - if (path.size() > 1) { - const QString &topLevelIdent = path.at(0); - QScriptValue obj; - if (topLevelIdent == QString::fromLatin1("this")) { - obj = ctx->thisObject(); - } else { - QScriptValueList scopeChain; - scopeChain = ctx->scopeChain(); - for (int i = 0; i < scopeChain.size(); ++i) { - QScriptValue oo = scopeChain.at(i).property(topLevelIdent); - if (oo.isObject()) { - obj = oo; - break; - } - } - } - for (int i = 1; obj.isObject() && (i < path.size()-1); ++i) - obj = obj.property(path.at(i)); - if (obj.isValid()) - objects.append(obj); - } else { - objects << ctx->scopeChain(); - QStringList keywords; - keywords.append(QString::fromLatin1("this")); - keywords.append(QString::fromLatin1("true")); - keywords.append(QString::fromLatin1("false")); - keywords.append(QString::fromLatin1("null")); - for (int i = 0; i < keywords.size(); ++i) { - const QString &kwd = keywords.at(i); - if (isPrefixOf(prefix, kwd)) - matches.insert(kwd); - } - } + length = path.last().length(); + type = QScriptCompletionTask::ScriptIdentifierCompletion; - for (int i = 0; i < objects.size(); ++i) { - QScriptValue obj = objects.at(i); - while (obj.isObject()) { - QScriptValueIterator it(obj); - while (it.hasNext()) { - it.next(); - QString propertyName = it.name(); - if (isPrefixOf(prefix, propertyName)) - matches.insert(propertyName); - } - obj = obj.prototype(); - } - } - results = matches.toList(); - qStableSort(results); + QScriptDebuggerJob *job = new QScriptCompleteExpressionJob(frameIndex, path, this, commandScheduler); + jobScheduler->scheduleJob(job); +} - length = prefix.length(); - type = QScriptCompletionTask::ScriptIdentifierCompletion; +void QScriptCompletionTaskPrivate::emitFinished() +{ + emit q_func()->finished(); +} + +QScriptCompletionTask::QScriptCompletionTask( + const QString &contents, int cursorPosition, int frameIndex, + QScriptDebuggerCommandSchedulerInterface *commandScheduler, + QScriptDebuggerJobSchedulerInterface *jobScheduler, + QScriptDebuggerConsole *console, + QObject *parent) + : QScriptCompletionTaskInterface( + *new QScriptCompletionTaskPrivate, parent) +{ + Q_D(QScriptCompletionTask); + d->contents = contents; + d->cursorPosition = cursorPosition; + if ((frameIndex == -1) && console) + d->frameIndex = console->currentFrameIndex(); + else + d->frameIndex = frameIndex; + d->commandScheduler = commandScheduler; + d->jobScheduler = jobScheduler; + d->console = console; +} + +QScriptCompletionTask::~QScriptCompletionTask() +{ } void QScriptCompletionTask::start() @@ -224,7 +238,6 @@ void QScriptCompletionTask::start() if ((d->cursorPosition >= cmdIndex) && (d->cursorPosition <= (cmdIndex+len))) { // editing command --> get command completions d->results = d->console->commandManager()->completions(prefix); - qStableSort(d->results); d->position = cmdRx.pos(1); d->length = prefix.length(); d->type = CommandNameCompletion; @@ -257,41 +270,37 @@ void QScriptCompletionTask::start() } QString argType = cmd->argumentTypes().value(argNum); if (!argType.isEmpty()) { - if (argType == QString::fromLatin1("command-or-group-name")) { + if (argType == QLatin1String("command-or-group-name")) { d->results = d->console->commandManager()->completions(arg); - } else if (argType == QString::fromLatin1("script-filename")) { - // ### super-cheating for now; have to use the async API - QScriptEngineDebuggerFrontend *edf = static_cast<QScriptEngineDebuggerFrontend*>(d->frontend); - QScriptDebuggerBackend *backend = edf->backend(); - QScriptScriptMap scripts = backend->scripts(); - QScriptScriptMap::const_iterator it; - for (it = scripts.constBegin(); it != scripts.constEnd(); ++it) { - QString fileName = it.value().fileName(); - if (isPrefixOf(arg, fileName)) - d->results.append(fileName); - } - } else if (argType == QString::fromLatin1("subcommand-name")) { + } else if (argType == QLatin1String("script-filename")) { + d->position = pos; + d->length = arg.length(); + d->type = CommandArgumentCompletion; + QScriptDebuggerJob *job = new QScriptCompleteScriptsJob(arg, d, d->commandScheduler); + d->jobScheduler->scheduleJob(job); + } else if (argType == QLatin1String("subcommand-name")) { for (int i = 0; i < cmd->subCommands().size(); ++i) { QString name = cmd->subCommands().at(i); if (isPrefixOf(arg, name)) d->results.append(name); } - } else if (argType == QString::fromLatin1("script")) { + qStableSort(d->results); + } else if (argType == QLatin1String("script")) { d->completeScriptExpression(); + } else { + emit finished(); } if ((d->type == NoCompletion) && !d->results.isEmpty()) { - qStableSort(d->results); d->position = pos; d->length = arg.length(); d->type = CommandArgumentCompletion; + emit finished(); } } - emit finished(); } } else { // assume it's an eval expression d->completeScriptExpression(); - emit finished(); } } diff --git a/src/scripttools/debugging/qscriptcompletiontask_p.h b/src/scripttools/debugging/qscriptcompletiontask_p.h index 890c219..24328d0 100644 --- a/src/scripttools/debugging/qscriptcompletiontask_p.h +++ b/src/scripttools/debugging/qscriptcompletiontask_p.h @@ -60,7 +60,8 @@ QT_BEGIN_NAMESPACE -class QScriptDebuggerFrontend; +class QScriptDebuggerCommandSchedulerInterface; +class QScriptDebuggerJobSchedulerInterface; class QScriptDebuggerConsole; class QScriptCompletionTaskPrivate; @@ -70,9 +71,9 @@ class Q_AUTOTEST_EXPORT QScriptCompletionTask Q_OBJECT public: QScriptCompletionTask( - const QString &contents, int cursorPosition, - int frameIndex, - QScriptDebuggerFrontend *frontend, + const QString &contents, int cursorPosition, int frameIndex, + QScriptDebuggerCommandSchedulerInterface *commandScheduler, + QScriptDebuggerJobSchedulerInterface *jobScheduler, QScriptDebuggerConsole *console, QObject *parent = 0); ~QScriptCompletionTask(); diff --git a/src/scripttools/debugging/qscriptdebugger.cpp b/src/scripttools/debugging/qscriptdebugger.cpp index fe7e7ca..9a5eb91 100644 --- a/src/scripttools/debugging/qscriptdebugger.cpp +++ b/src/scripttools/debugging/qscriptdebugger.cpp @@ -75,10 +75,6 @@ #include "qscriptdebuggerjob_p_p.h" #include "qscriptxmlparser_p.h" -#include "qscriptenginedebuggerfrontend_p.h" -#include "qscriptdebuggerbackend_p.h" -#include <QtScript/qscriptengine.h> - #include "private/qobject_p.h" #include <QtScript/qscriptcontext.h> @@ -94,6 +90,9 @@ #include <QtGui/qevent.h> #include <QtGui/qicon.h> #include <QtGui/qinputdialog.h> +#include <QtGui/qmenu.h> +#include <QtGui/qtoolbar.h> +#include <QtGui/qtooltip.h> QT_BEGIN_NAMESPACE typedef QPair<QList<qint64>, QList<qint64> > QScriptScriptsDelta; @@ -137,8 +136,8 @@ static bool scriptDebuggerEventCallback(void **data) \brief The QScriptDebugger class provides a Qt Script debugger. - \ingroup scripttools - \mainclass + \ingroup script + */ class QScriptDebuggerPrivate @@ -171,8 +170,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 +632,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 +682,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); } /*! @@ -688,7 +693,7 @@ QScriptCompletionTaskInterface *QScriptDebuggerPrivate::createCompletionTask( const QString &contents, int cursorPosition, int frameIndex, int options) { return new QScriptCompletionTask( - contents, cursorPosition, frameIndex, frontend, + contents, cursorPosition, frameIndex, this, this, (options & QScriptCompletionProviderInterface::ConsoleCommandCompletion) ? console : 0); } @@ -988,7 +993,8 @@ public: m_debugger->scriptsModel->addScript(scriptId, data); // ### could be slow, might want to do this in a separate thread - QString xml = qt_scriptToXml(data.contents(), data.baseLineNumber()); +// Q_ASSERT_X(false, Q_FUNC_INFO, "implement me"); + QString xml; // = qt_scriptToXml(data.contents(), data.baseLineNumber()); QScriptXmlParser::Result extraInfo = QScriptXmlParser::parse(xml); m_debugger->scriptsModel->addExtraScriptInfo( scriptId, extraInfo.functionsInfo, extraInfo.executableLineNumbers); @@ -1072,7 +1078,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 +1110,6 @@ public: private: QScriptDebuggerPrivate *m_debugger; int m_frameIndex; - int m_state; }; class EmitStoppedSignalJob : public QScriptDebuggerJob @@ -1331,6 +1336,122 @@ void QScriptDebugger::setFrontend(QScriptDebuggerFrontend *frontend) } } +QAction *QScriptDebugger::action(DebuggerAction action, QObject *parent) +{ + switch (action) { + case InterruptAction: + return interruptAction(parent); + case ContinueAction: + return continueAction(parent); + case StepIntoAction: + return stepIntoAction(parent); + case StepOverAction: + return stepOverAction(parent); + case StepOutAction: + return stepOutAction(parent); + case RunToCursorAction: + return runToCursorAction(parent); + case RunToNewScriptAction: + return runToNewScriptAction(parent); + case ToggleBreakpointAction: + return toggleBreakpointAction(parent); + case ClearDebugOutputAction: + return clearDebugOutputAction(parent); + case ClearErrorLogAction: + return clearErrorLogAction(parent); + case ClearConsoleAction: + return clearConsoleAction(parent); + case FindInScriptAction: + return findInScriptAction(parent); + case FindNextInScriptAction: + return findNextInScriptAction(parent); + case FindPreviousInScriptAction: + return findPreviousInScriptAction(parent); + case GoToLineAction: + return goToLineAction(parent); + } + return 0; +} + +QWidget *QScriptDebugger::widget(DebuggerWidget widget) +{ + switch (widget) { + case ConsoleWidget: { + QScriptDebuggerConsoleWidgetInterface *w = consoleWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createConsoleWidget(); + setConsoleWidget(w); + } + return w; + } + case StackWidget: { + QScriptDebuggerStackWidgetInterface *w = stackWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createStackWidget(); + setStackWidget(w); + } + return w; + } + case ScriptsWidget: { + QScriptDebuggerScriptsWidgetInterface *w = scriptsWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createScriptsWidget(); + setScriptsWidget(w); + } + return w; + } + case LocalsWidget: { + QScriptDebuggerLocalsWidgetInterface *w = localsWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createLocalsWidget(); + setLocalsWidget(w); + } + return w; + } + case CodeWidget: { + QScriptDebuggerCodeWidgetInterface *w = codeWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createCodeWidget(); + setCodeWidget(w); + } + return w; + } + case CodeFinderWidget: { + QScriptDebuggerCodeFinderWidgetInterface *w = codeFinderWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createCodeFinderWidget(); + setCodeFinderWidget(w); + } + return w; + } + case BreakpointsWidget: { + QScriptBreakpointsWidgetInterface *w = breakpointsWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createBreakpointsWidget(); + setBreakpointsWidget(w); + } + return w; + } + case DebugOutputWidget: { + QScriptDebugOutputWidgetInterface *w = debugOutputWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createDebugOutputWidget(); + setDebugOutputWidget(w); + } + return w; + } + case ErrorLogWidget: { + QScriptErrorLogWidgetInterface *w = errorLogWidget(); + if (!w && widgetFactory()) { + w = widgetFactory()->createErrorLogWidget(); + setErrorLogWidget(w); + } + return w; + } + } + return 0; +} + QScriptDebuggerConsoleWidgetInterface *QScriptDebugger::consoleWidget() const { Q_D(const QScriptDebugger); @@ -1783,6 +1904,51 @@ QAction *QScriptDebugger::goToLineAction(QObject *parent) const return d->goToLineAction; } +QMenu *QScriptDebugger::createStandardMenu(QWidget *widgetParent, QObject *actionParent) +{ + QMenu *menu = new QMenu(widgetParent); + menu->setTitle(QObject::tr("Debug")); + menu->addAction(action(ContinueAction, actionParent)); + menu->addAction(action(InterruptAction, actionParent)); + menu->addAction(action(StepIntoAction, actionParent)); + menu->addAction(action(StepOverAction, actionParent)); + menu->addAction(action(StepOutAction, actionParent)); + menu->addAction(action(RunToCursorAction, actionParent)); + menu->addAction(action(RunToNewScriptAction, actionParent)); + + menu->addSeparator(); + menu->addAction(action(ToggleBreakpointAction, actionParent)); + + menu->addSeparator(); + menu->addAction(action(ClearDebugOutputAction, actionParent)); + menu->addAction(action(ClearErrorLogAction, actionParent)); + menu->addAction(action(ClearConsoleAction, actionParent)); + + return menu; +} + +QToolBar *QScriptDebugger::createStandardToolBar(QWidget *widgetParent, QObject *actionParent) +{ + QToolBar *tb = new QToolBar(widgetParent); + tb->setObjectName(QLatin1String("qtscriptdebugger_standardToolBar")); + tb->addAction(action(ContinueAction, actionParent)); + tb->addAction(action(InterruptAction, actionParent)); + tb->addAction(action(StepIntoAction, actionParent)); + tb->addAction(action(StepOverAction, actionParent)); + tb->addAction(action(StepOutAction, actionParent)); + tb->addAction(action(RunToCursorAction, actionParent)); + tb->addAction(action(RunToNewScriptAction, actionParent)); + tb->addSeparator(); + tb->addAction(action(FindInScriptAction, actionParent)); + return tb; +} + +bool QScriptDebugger::isInteractive() const +{ + Q_D(const QScriptDebugger); + return d->interactive; +} + /*! \reimp */ diff --git a/src/scripttools/debugging/qscriptdebugger_p.h b/src/scripttools/debugging/qscriptdebugger_p.h index d38ec2b..687b92c 100644 --- a/src/scripttools/debugging/qscriptdebugger_p.h +++ b/src/scripttools/debugging/qscriptdebugger_p.h @@ -70,18 +70,54 @@ class QScriptErrorLogWidgetInterface; class QScriptDebuggerWidgetFactoryInterface; class QAction; class QEvent; +class QMenu; +class QToolBar; class QScriptDebuggerPrivate; class Q_AUTOTEST_EXPORT QScriptDebugger : public QObject { Q_OBJECT public: + // mirrors QScriptEngineDebugger::DebuggerWidget + enum DebuggerWidget { + ConsoleWidget, + StackWidget, + ScriptsWidget, + LocalsWidget, + CodeWidget, + CodeFinderWidget, + BreakpointsWidget, + DebugOutputWidget, + ErrorLogWidget + }; + // mirrors QScriptEngineDebugger::DebuggerAction + enum DebuggerAction { + InterruptAction, + ContinueAction, + StepIntoAction, + StepOverAction, + StepOutAction, + RunToCursorAction, + RunToNewScriptAction, + ToggleBreakpointAction, + ClearDebugOutputAction, + ClearErrorLogAction, + ClearConsoleAction, + FindInScriptAction, + FindNextInScriptAction, + FindPreviousInScriptAction, + GoToLineAction + }; + QScriptDebugger(QObject *parent = 0); ~QScriptDebugger(); QScriptDebuggerFrontend *frontend() const; void setFrontend(QScriptDebuggerFrontend *frontend); + QWidget *widget(DebuggerWidget widget); + QAction *action(DebuggerAction action, QObject *parent); + QScriptDebuggerConsoleWidgetInterface *consoleWidget() const; void setConsoleWidget(QScriptDebuggerConsoleWidgetInterface *consoleWidget); @@ -131,8 +167,13 @@ public: QAction *clearConsoleAction(QObject *parent) const; QAction *clearErrorLogAction(QObject *parent) const; + QMenu *createStandardMenu(QWidget *widgetParent, QObject *actionParent); + QToolBar *createStandardToolBar(QWidget *widgetParent, QObject *actionParent); + bool eventFilter(QObject *, QEvent *e); + bool isInteractive() const; + Q_SIGNALS: void stopped() const; void started() const; diff --git a/src/scripttools/debugging/qscriptdebuggeragent.cpp b/src/scripttools/debugging/qscriptdebuggeragent.cpp index b7ee8e5..2db48d3 100644 --- a/src/scripttools/debugging/qscriptdebuggeragent.cpp +++ b/src/scripttools/debugging/qscriptdebuggeragent.cpp @@ -88,7 +88,7 @@ QScriptDebuggerAgentPrivate *QScriptDebuggerAgentPrivate::get( */ QScriptDebuggerAgent::QScriptDebuggerAgent( QScriptDebuggerBackendPrivate *backend, QScriptEngine *engine) - : QScriptEngineAgent(*new QScriptDebuggerAgentPrivate, engine) + : QScriptEngineAgent(engine), d_ptr(new QScriptDebuggerAgentPrivate()) { Q_D(QScriptDebuggerAgent); d->backend = backend; @@ -110,6 +110,7 @@ QScriptDebuggerAgent::~QScriptDebuggerAgent() Q_D(QScriptDebuggerAgent); if (d->backend) d->backend->agentDestroyed(this); + delete d; } /*! diff --git a/src/scripttools/debugging/qscriptdebuggeragent_p.h b/src/scripttools/debugging/qscriptdebuggeragent_p.h index 74a8ac0..0849d95 100644 --- a/src/scripttools/debugging/qscriptdebuggeragent_p.h +++ b/src/scripttools/debugging/qscriptdebuggeragent_p.h @@ -125,6 +125,7 @@ public: const QVariant &argument = QVariant()); private: + QScriptDebuggerAgentPrivate *d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerAgent) Q_DISABLE_COPY(QScriptDebuggerAgent) }; diff --git a/src/scripttools/debugging/qscriptdebuggeragent_p_p.h b/src/scripttools/debugging/qscriptdebuggeragent_p_p.h index d01d915..55bcbd7 100644 --- a/src/scripttools/debugging/qscriptdebuggeragent_p_p.h +++ b/src/scripttools/debugging/qscriptdebuggeragent_p_p.h @@ -53,8 +53,6 @@ // We mean it. // -#include <private/qscriptengineagent_p.h> - #include <QtScript/qscriptvalue.h> #include <QtCore/qdatetime.h> #include <QtCore/qhash.h> @@ -68,9 +66,7 @@ QT_BEGIN_NAMESPACE class QScriptDebuggerAgent; class QScriptDebuggerAgentPrivate - : public QScriptEngineAgentPrivate { - Q_DECLARE_PUBLIC(QScriptDebuggerAgent) public: enum State { NoState, diff --git a/src/scripttools/debugging/qscriptdebuggerbackend.cpp b/src/scripttools/debugging/qscriptdebuggerbackend.cpp index 2ef5785..2efff04 100644 --- a/src/scripttools/debugging/qscriptdebuggerbackend.cpp +++ b/src/scripttools/debugging/qscriptdebuggerbackend.cpp @@ -291,7 +291,7 @@ QScriptValue QScriptDebuggerBackendPrivate::trace(QScriptContext *context, QString str; for (int i = 0; i < context->argumentCount(); ++i) { if (i > 0) - str.append(QLatin1String(" ")); + str.append(QLatin1Char(' ')); str.append(context->argument(i).toString()); } QScriptDebuggerEvent e(QScriptDebuggerEvent::Trace); @@ -384,7 +384,6 @@ QScriptDebuggerBackend::QScriptDebuggerBackend() QScriptDebuggerBackend::~QScriptDebuggerBackend() { detach(); - delete d_ptr; } /*! @@ -411,14 +410,15 @@ void QScriptDebuggerBackend::attachTo(QScriptEngine *engine) detach(); d->agent = new QScriptDebuggerAgent(d, engine); QScriptValue global = engine->globalObject(); + d->origTraceFunction = global.property(QString::fromLatin1("print")); global.setProperty(QString::fromLatin1("print"), traceFunction()); // global.setProperty(QString::fromLatin1("qAssert"), assertFunction()); + d->origFileNameFunction = global.property(QString::fromLatin1("__FILE__")); global.setProperty(QString::fromLatin1("__FILE__"), fileNameFunction(), - QScriptValue::PropertyGetter | QScriptValue::PropertySetter - | QScriptValue::ReadOnly); + QScriptValue::PropertyGetter | QScriptValue::ReadOnly); + d->origLineNumberFunction = global.property(QString::fromLatin1("__LINE__")); global.setProperty(QString::fromLatin1("__LINE__"), lineNumberFunction(), - QScriptValue::PropertyGetter | QScriptValue::PropertySetter - | QScriptValue::ReadOnly); + QScriptValue::PropertyGetter | QScriptValue::ReadOnly); engine->setAgent(d->agent); } @@ -432,21 +432,25 @@ void QScriptDebuggerBackend::attachTo(QScriptEngine *engine) void QScriptDebuggerBackend::detach() { Q_D(QScriptDebuggerBackend); - if (!d->agent) - return; - QScriptEngine *eng = d->agent->engine(); - if (eng && eng->agent() == d->agent) { - eng->setAgent(0); - QScriptValue global = eng->globalObject(); - if (global.property(QString::fromLatin1("print")).strictlyEquals(traceFunction())) - global.setProperty(QString::fromLatin1("print"), QScriptValue()); -// global.setProperty(QString::fromLatin1("qAssert"), QScriptValue()); - if (global.property(QString::fromLatin1("__FILE__")).strictlyEquals(fileNameFunction())) - global.setProperty(QString::fromLatin1("__FILE__"), QScriptValue()); - if (global.property(QString::fromLatin1("__LINE__")).strictlyEquals(lineNumberFunction())) - global.setProperty(QString::fromLatin1("__LINE__"), QScriptValue()); - d->agent->nullifyBackendPointer(); - d->agent = 0; // agent is owned by engine + if (d->agent) { + QScriptEngine *eng = d->agent->engine(); + if (eng && eng->agent() == d->agent) { + eng->setAgent(0); + QScriptValue global = eng->globalObject(); + global.setProperty(QString::fromLatin1("print"), d->origTraceFunction); + d->origTraceFunction = QScriptValue(); +// global.setProperty(QString::fromLatin1("qAssert"), QScriptValue()); + global.setProperty(QString::fromLatin1("__FILE__"), QScriptValue(), + QScriptValue::PropertyGetter); + global.setProperty(QString::fromLatin1("__FILE__"), d->origFileNameFunction); + d->origFileNameFunction = QScriptValue(); + global.setProperty(QString::fromLatin1("__LINE__"), QScriptValue(), + QScriptValue::PropertyGetter); + global.setProperty(QString::fromLatin1("__LINE__"), d->origLineNumberFunction); + d->origLineNumberFunction = QScriptValue(); + d->agent->nullifyBackendPointer(); + d->agent = 0; // agent is owned by engine + } } d->pendingEvaluateLineNumber = -1; diff --git a/src/scripttools/debugging/qscriptdebuggerbackend_p.h b/src/scripttools/debugging/qscriptdebuggerbackend_p.h index a372b0b..ad3d883 100644 --- a/src/scripttools/debugging/qscriptdebuggerbackend_p.h +++ b/src/scripttools/debugging/qscriptdebuggerbackend_p.h @@ -144,7 +144,7 @@ protected: protected: QScriptDebuggerBackend(QScriptDebuggerBackendPrivate &dd); - QScriptDebuggerBackendPrivate *d_ptr; + QScopedPointer<QScriptDebuggerBackendPrivate> d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerBackend) diff --git a/src/scripttools/debugging/qscriptdebuggerbackend_p_p.h b/src/scripttools/debugging/qscriptdebuggerbackend_p_p.h index 14175a2..a5d55ee 100644 --- a/src/scripttools/debugging/qscriptdebuggerbackend_p_p.h +++ b/src/scripttools/debugging/qscriptdebuggerbackend_p_p.h @@ -57,6 +57,7 @@ #include <QtCore/qhash.h> #include <QtCore/qlist.h> +#include <QtScript/qscriptvalue.h> #include "qscriptdebuggerbackend_p.h" @@ -66,7 +67,6 @@ class QEvent; class QString; class QScriptContext; class QScriptEngine; -class QScriptValue; class QScriptValueIterator; class QScriptObjectSnapshot; class QScriptDebuggerAgent; @@ -126,6 +126,10 @@ public: QObject *eventReceiver; QScriptDebuggerBackend *q_ptr; + + QScriptValue origTraceFunction; + QScriptValue origFileNameFunction; + QScriptValue origLineNumberFunction; }; QT_END_NAMESPACE diff --git a/src/scripttools/debugging/qscriptdebuggercodeview.cpp b/src/scripttools/debugging/qscriptdebuggercodeview.cpp index 2eccb43..ff377eb 100644 --- a/src/scripttools/debugging/qscriptdebuggercodeview.cpp +++ b/src/scripttools/debugging/qscriptdebuggercodeview.cpp @@ -214,7 +214,6 @@ bool QScriptDebuggerCodeView::event(QEvent *e) if (contents.isEmpty()) return false; int linePosition = cursor.position() - block.position(); - linePosition -= 3; if (linePosition < 0) linePosition = 0; @@ -233,7 +232,7 @@ bool QScriptDebuggerCodeView::event(QEvent *e) // ignore string literals return false; } - int pos2 = linePosition; + int pos2 = linePosition - 1; while ((pos2 < contents.size()-1) && isIdentChar(contents.at(pos2+1))) ++pos2; QString ident = contents.mid(pos, pos2 - pos + 1); diff --git a/src/scripttools/debugging/qscriptdebuggercodewidget.cpp b/src/scripttools/debugging/qscriptdebuggercodewidget.cpp index f56d4a2..b19e2f1 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 23c10c1..5554cda 100644 --- a/src/scripttools/debugging/qscriptdebuggercommand.cpp +++ b/src/scripttools/debugging/qscriptdebuggercommand.cpp @@ -45,6 +45,7 @@ #include <QtCore/qhash.h> #include <QtCore/qdatastream.h> +#include <QtCore/qstringlist.h> Q_DECLARE_METATYPE(QScriptBreakpointData) Q_DECLARE_METATYPE(QScriptDebuggerValue) @@ -118,7 +119,6 @@ QScriptDebuggerCommand::QScriptDebuggerCommand(const QScriptDebuggerCommand &oth */ QScriptDebuggerCommand::~QScriptDebuggerCommand() { - delete d_ptr; } /*! @@ -558,6 +558,25 @@ 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::getCompletions( + int contextIndex, const QStringList &path) +{ + QScriptDebuggerCommand cmd(GetCompletions); + cmd.setContextIndex(contextIndex); + cmd.setAttribute(UserAttribute, path); + return cmd; +} + QScriptDebuggerCommand QScriptDebuggerCommand::newScriptObjectSnapshotCommand() { QScriptDebuggerCommand cmd(NewScriptObjectSnapshot); @@ -646,7 +665,7 @@ QScriptDebuggerCommand QScriptDebuggerCommand::clearExceptionsCommand() */ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerCommand &command) { - const QScriptDebuggerCommandPrivate *d = command.d_ptr; + const QScriptDebuggerCommandPrivate *d = command.d_ptr.data(); out << (quint32)d->type; out << (qint32)d->attributes.size(); QHash<QScriptDebuggerCommand::Attribute, QVariant>::const_iterator it; @@ -666,7 +685,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerCommand &command) */ QDataStream &operator>>(QDataStream &in, QScriptDebuggerCommand &command) { - QScriptDebuggerCommandPrivate *d = command.d_ptr; + QScriptDebuggerCommandPrivate *d = command.d_ptr.data(); quint32 type; in >> type; diff --git a/src/scripttools/debugging/qscriptdebuggercommand_p.h b/src/scripttools/debugging/qscriptdebuggercommand_p.h index 78e042f..47bb4cf 100644 --- a/src/scripttools/debugging/qscriptdebuggercommand_p.h +++ b/src/scripttools/debugging/qscriptdebuggercommand_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qhash.h> #include <QtCore/qvariant.h> @@ -106,6 +106,8 @@ public: GetActivationObject, GetScopeChain, ContextsCheckpoint, + GetPropertyExpressionValue, + GetCompletions, NewScriptObjectSnapshot, ScriptObjectSnapshotCapture, @@ -229,6 +231,9 @@ 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 getCompletions(int contextIndex, const QStringList &path); static QScriptDebuggerCommand newScriptObjectSnapshotCommand(); static QScriptDebuggerCommand scriptObjectSnapshotCaptureCommand(int id, const QScriptDebuggerValue &object); @@ -250,7 +255,7 @@ public: static QScriptDebuggerCommand clearExceptionsCommand(); private: - QScriptDebuggerCommandPrivate *d_ptr; + QScopedPointer<QScriptDebuggerCommandPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerCommand) }; diff --git a/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp b/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp index 3dc4c05..b135efd 100644 --- a/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp +++ b/src/scripttools/debugging/qscriptdebuggercommandexecutor.cpp @@ -98,15 +98,20 @@ QScriptDebuggerCommandExecutor::QScriptDebuggerCommandExecutor() QScriptDebuggerCommandExecutor::~QScriptDebuggerCommandExecutor() { - delete d_ptr; +} + +static bool isPrefixOf(const QString &prefix, const QString &what) +{ + return ((what.length() > prefix.length()) + && what.startsWith(prefix)); } /*! 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 +305,104 @@ 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::GetCompletions: { + QScriptContext *ctx = backend->context(command.contextIndex()); + QVariant attr = command.attribute(QScriptDebuggerCommand::UserAttribute); + QStringList path = attr.toStringList(); + if (!ctx || path.isEmpty()) + break; + QScriptValueList objects; + QString prefix = path.last(); + QSet<QString> matches; + if (path.size() > 1) { + const QString &topLevelIdent = path.at(0); + QScriptValue obj; + if (topLevelIdent == QLatin1String("this")) { + obj = ctx->thisObject(); + } else { + QScriptValueList scopeChain; + scopeChain = ctx->scopeChain(); + for (int i = 0; i < scopeChain.size(); ++i) { + QScriptValue oo = scopeChain.at(i).property(topLevelIdent); + if (oo.isObject()) { + obj = oo; + break; + } + } + } + for (int i = 1; obj.isObject() && (i < path.size()-1); ++i) + obj = obj.property(path.at(i)); + if (obj.isValid()) + objects.append(obj); + } else { + objects << ctx->scopeChain(); + QStringList keywords; + keywords.append(QString::fromLatin1("this")); + keywords.append(QString::fromLatin1("true")); + keywords.append(QString::fromLatin1("false")); + keywords.append(QString::fromLatin1("null")); + for (int i = 0; i < keywords.size(); ++i) { + const QString &kwd = keywords.at(i); + if (isPrefixOf(prefix, kwd)) + matches.insert(kwd); + } + } + + for (int i = 0; i < objects.size(); ++i) { + QScriptValue obj = objects.at(i); + while (obj.isObject()) { + QScriptValueIterator it(obj); + while (it.hasNext()) { + it.next(); + QString propertyName = it.name(); + if (isPrefixOf(prefix, propertyName)) + matches.insert(propertyName); + } + obj = obj.prototype(); + } + } + QStringList matchesList = matches.toList(); + qStableSort(matchesList); + response.setResult(matchesList); + } break; + case QScriptDebuggerCommand::NewScriptObjectSnapshot: { int id = backend->newScriptObjectSnapshot(); response.setResult(id); diff --git a/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h b/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h index 0e7ae0f..1412d61 100644 --- a/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h +++ b/src/scripttools/debugging/qscriptdebuggercommandexecutor_p.h @@ -54,6 +54,7 @@ // #include <QtCore/qobjectdefs.h> +#include <QtCore/qscopedpointer.h> QT_BEGIN_NAMESPACE @@ -74,7 +75,7 @@ public: protected: QScriptDebuggerCommandExecutor(QScriptDebuggerCommandExecutorPrivate &dd); - QScriptDebuggerCommandExecutorPrivate *d_ptr; + QScopedPointer<QScriptDebuggerCommandExecutorPrivate> d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerCommandExecutor) diff --git a/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp b/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp index 96f5f78..8f4e856 100644 --- a/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp +++ b/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend.cpp @@ -251,6 +251,17 @@ 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::scheduleGetCompletions(int contextIndex, const QStringList &path) +{ + return scheduleCommand(QScriptDebuggerCommand::getCompletions(contextIndex, 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 af4201b..1426dc5 100644 --- a/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend_p.h +++ b/src/scripttools/debugging/qscriptdebuggercommandschedulerfrontend_p.h @@ -109,6 +109,9 @@ public: int scheduleGetActivationObject(int contextIndex); int scheduleGetScopeChain(int contextIndex); int scheduleContextsCheckpoint(); + int scheduleGetPropertyExpressionValue(int contextIndex, int lineNumber, + const QStringList &path); + int scheduleGetCompletions(int contextIndex, const QStringList &path); // iteration int scheduleNewScriptValueIterator(const QScriptDebuggerValue &object); diff --git a/src/scripttools/debugging/qscriptdebuggerconsole.cpp b/src/scripttools/debugging/qscriptdebuggerconsole.cpp index 75221fd..29b4575 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsole.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsole.cpp @@ -163,10 +163,10 @@ QScriptDebuggerConsoleCommandJob *QScriptDebuggerConsolePrivate::createJob( .arg(name)); for (int j = 0; j < completions.size(); ++j) { if (j > 0) - msg.append(QString::fromLatin1(", ")); + msg.append(QLatin1String(", ")); msg.append(completions.at(j)); } - msg.append(QString::fromLatin1(".")); + msg.append(QLatin1Char('.')); messageHandler->message(QtWarningMsg, msg); return 0; } @@ -199,7 +199,6 @@ QScriptDebuggerConsole::QScriptDebuggerConsole() QScriptDebuggerConsole::~QScriptDebuggerConsole() { - delete d_ptr; } void QScriptDebuggerConsole::loadScriptedCommands(const QString &scriptsPath, diff --git a/src/scripttools/debugging/qscriptdebuggerconsole_p.h b/src/scripttools/debugging/qscriptdebuggerconsole_p.h index 3a8cd2b..6815955 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsole_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsole_p.h @@ -54,6 +54,7 @@ // #include <QtCore/qobjectdefs.h> +#include <QtCore/qscopedpointer.h> #include "qscriptdebuggerconsolehistorianinterface_p.h" @@ -109,7 +110,7 @@ public: void bumpSessionId(); private: - QScriptDebuggerConsolePrivate *d_ptr; + QScopedPointer<QScriptDebuggerConsolePrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerConsole) Q_DISABLE_COPY(QScriptDebuggerConsole) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp b/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp index e5b7252..ab0df3d 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommand.cpp @@ -72,7 +72,6 @@ QScriptDebuggerConsoleCommand::QScriptDebuggerConsoleCommand() QScriptDebuggerConsoleCommand::~QScriptDebuggerConsoleCommand() { - delete d_ptr; } QScriptDebuggerConsoleCommand::QScriptDebuggerConsoleCommand(QScriptDebuggerConsoleCommandPrivate &dd) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h b/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h index 3fd9629..943fd9c 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommand_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qlist.h> QT_BEGIN_NAMESPACE @@ -91,7 +91,7 @@ public: protected: QScriptDebuggerConsoleCommand(QScriptDebuggerConsoleCommandPrivate &dd); - QScriptDebuggerConsoleCommandPrivate *d_ptr; + QScopedPointer<QScriptDebuggerConsoleCommandPrivate> d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerConsoleCommand) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp index 75820cf..0c0d5e9 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata.cpp @@ -90,7 +90,7 @@ QScriptDebuggerConsoleCommandGroupData::QScriptDebuggerConsoleCommandGroupData( QScriptDebuggerConsoleCommandGroupData::QScriptDebuggerConsoleCommandGroupData( const QScriptDebuggerConsoleCommandGroupData &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -98,22 +98,12 @@ QScriptDebuggerConsoleCommandGroupData::QScriptDebuggerConsoleCommandGroupData( QScriptDebuggerConsoleCommandGroupData::~QScriptDebuggerConsoleCommandGroupData() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } QScriptDebuggerConsoleCommandGroupData &QScriptDebuggerConsoleCommandGroupData::operator=( const QScriptDebuggerConsoleCommandGroupData &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h index 4f48f09..2f901f2 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qmap.h> QT_BEGIN_NAMESPACE @@ -82,7 +82,7 @@ public: const QScriptDebuggerConsoleCommandGroupData &other); private: - QScriptDebuggerConsoleCommandGroupDataPrivate *d_ptr; + QScopedSharedPointer<QScriptDebuggerConsoleCommandGroupDataPrivate> d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerConsoleCommandGroupData) diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp index 8651b24..56b60ce 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager.cpp @@ -105,7 +105,6 @@ QScriptDebuggerConsoleCommandManager::QScriptDebuggerConsoleCommandManager() QScriptDebuggerConsoleCommandManager::~QScriptDebuggerConsoleCommandManager() { - delete d_ptr; } /*! diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h index b41a117..4397558 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandmanager_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qmap.h> #include <QtCore/qlist.h> @@ -86,7 +86,7 @@ public: QStringList completions(const QString &prefix) const; private: - QScriptDebuggerConsoleCommandManagerPrivate *d_ptr; + QScopedPointer<QScriptDebuggerConsoleCommandManagerPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerConsoleCommandManager) }; diff --git a/src/scripttools/debugging/qscriptdebuggerconsoleglobalobject.cpp b/src/scripttools/debugging/qscriptdebuggerconsoleglobalobject.cpp index 39edc64..8ff90da 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsoleglobalobject.cpp +++ b/src/scripttools/debugging/qscriptdebuggerconsoleglobalobject.cpp @@ -361,6 +361,7 @@ void QScriptDebuggerConsoleGlobalObject::warning(const QString &text, int lineNumber, int columnNumber) { Q_D(QScriptDebuggerConsoleGlobalObject); + Q_ASSERT(d->messageHandler != 0); d->messageHandler->message(QtWarningMsg, text, fileName, lineNumber, columnNumber); } @@ -369,6 +370,7 @@ void QScriptDebuggerConsoleGlobalObject::message(const QString &text, int lineNumber, int columnNumber) { Q_D(QScriptDebuggerConsoleGlobalObject); + Q_ASSERT(d->messageHandler != 0); d->messageHandler->message(QtDebugMsg, text, fileName, lineNumber, columnNumber); } @@ -377,6 +379,7 @@ void QScriptDebuggerConsoleGlobalObject::error(const QString &text, int lineNumber, int columnNumber) { Q_D(QScriptDebuggerConsoleGlobalObject); + Q_ASSERT(d->messageHandler != 0); d->messageHandler->message(QtCriticalMsg, text, fileName, lineNumber, columnNumber); } diff --git a/src/scripttools/debugging/qscriptdebuggerevent.cpp b/src/scripttools/debugging/qscriptdebuggerevent.cpp index 6302901..08104c1 100644 --- a/src/scripttools/debugging/qscriptdebuggerevent.cpp +++ b/src/scripttools/debugging/qscriptdebuggerevent.cpp @@ -98,7 +98,6 @@ QScriptDebuggerEvent::QScriptDebuggerEvent(const QScriptDebuggerEvent &other) QScriptDebuggerEvent::~QScriptDebuggerEvent() { - delete d_ptr; } QScriptDebuggerEvent &QScriptDebuggerEvent::operator=(const QScriptDebuggerEvent &other) @@ -277,7 +276,7 @@ bool QScriptDebuggerEvent::operator!=(const QScriptDebuggerEvent &other) const */ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerEvent &event) { - const QScriptDebuggerEventPrivate *d = event.d_ptr; + const QScriptDebuggerEventPrivate *d = event.d_ptr.data(); out << (quint32)d->type; out << (qint32)d->attributes.size(); QHash<QScriptDebuggerEvent::Attribute, QVariant>::const_iterator it; @@ -297,7 +296,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerEvent &event) */ QDataStream &operator>>(QDataStream &in, QScriptDebuggerEvent &event) { - QScriptDebuggerEventPrivate *d = event.d_ptr; + QScriptDebuggerEventPrivate *d = event.d_ptr.data(); quint32 type; in >> type; diff --git a/src/scripttools/debugging/qscriptdebuggerevent_p.h b/src/scripttools/debugging/qscriptdebuggerevent_p.h index 5d894ea..2ac58a7 100644 --- a/src/scripttools/debugging/qscriptdebuggerevent_p.h +++ b/src/scripttools/debugging/qscriptdebuggerevent_p.h @@ -57,6 +57,7 @@ #include <QtCore/qcoreevent.h> #include <QtCore/qhash.h> #include <QtCore/qvariant.h> +#include <QtCore/qscopedpointer.h> QT_BEGIN_NAMESPACE @@ -137,7 +138,7 @@ public: bool operator!=(const QScriptDebuggerEvent &other) const; private: - QScriptDebuggerEventPrivate *d_ptr; + QScopedPointer<QScriptDebuggerEventPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerEvent) }; diff --git a/src/scripttools/debugging/qscriptdebuggerfrontend.cpp b/src/scripttools/debugging/qscriptdebuggerfrontend.cpp index 1ae1093..8fcc946 100644 --- a/src/scripttools/debugging/qscriptdebuggerfrontend.cpp +++ b/src/scripttools/debugging/qscriptdebuggerfrontend.cpp @@ -143,7 +143,6 @@ QScriptDebuggerFrontend::QScriptDebuggerFrontend() QScriptDebuggerFrontend::~QScriptDebuggerFrontend() { - delete d_ptr; } QScriptDebuggerFrontend::QScriptDebuggerFrontend(QScriptDebuggerFrontendPrivate &dd) diff --git a/src/scripttools/debugging/qscriptdebuggerfrontend_p.h b/src/scripttools/debugging/qscriptdebuggerfrontend_p.h index c12e02a..fe8464a 100644 --- a/src/scripttools/debugging/qscriptdebuggerfrontend_p.h +++ b/src/scripttools/debugging/qscriptdebuggerfrontend_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qstring.h> #include "qscriptdebuggercommandschedulerinterface_p.h" @@ -90,7 +90,7 @@ protected: protected: QScriptDebuggerFrontend(QScriptDebuggerFrontendPrivate &dd); - QScriptDebuggerFrontendPrivate *d_ptr; + QScopedPointer<QScriptDebuggerFrontendPrivate> d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerFrontend) diff --git a/src/scripttools/debugging/qscriptdebuggerjob.cpp b/src/scripttools/debugging/qscriptdebuggerjob.cpp index 42a735a..4630e6c 100644 --- a/src/scripttools/debugging/qscriptdebuggerjob.cpp +++ b/src/scripttools/debugging/qscriptdebuggerjob.cpp @@ -85,7 +85,6 @@ QScriptDebuggerJob::QScriptDebuggerJob(QScriptDebuggerJobPrivate &dd) QScriptDebuggerJob::~QScriptDebuggerJob() { - delete d_ptr; } void QScriptDebuggerJob::finish() diff --git a/src/scripttools/debugging/qscriptdebuggerjob_p.h b/src/scripttools/debugging/qscriptdebuggerjob_p.h index 0d3c35c..0a7bc62 100644 --- a/src/scripttools/debugging/qscriptdebuggerjob_p.h +++ b/src/scripttools/debugging/qscriptdebuggerjob_p.h @@ -54,6 +54,7 @@ // #include <QtCore/qobjectdefs.h> +#include <QtCore/qscopedpointer.h> QT_BEGIN_NAMESPACE @@ -76,7 +77,7 @@ public: protected: QScriptDebuggerJob(QScriptDebuggerJobPrivate &dd); - QScriptDebuggerJobPrivate *d_ptr; + QScopedPointer<QScriptDebuggerJobPrivate> d_ptr; private: Q_DECLARE_PRIVATE(QScriptDebuggerJob) diff --git a/src/scripttools/debugging/qscriptdebuggerlocalsmodel.cpp b/src/scripttools/debugging/qscriptdebuggerlocalsmodel.cpp index 369f568..ca458cf 100644 --- a/src/scripttools/debugging/qscriptdebuggerlocalsmodel.cpp +++ b/src/scripttools/debugging/qscriptdebuggerlocalsmodel.cpp @@ -136,6 +136,7 @@ public: const QScriptDebuggerValuePropertyList &props); void deleteObjectSnapshots(const QList<qint64> &snapshotIds); + void deleteAllObjectSnapshots(); QScriptDebuggerJobSchedulerInterface *jobScheduler; QScriptDebuggerCommandSchedulerInterface *commandScheduler; @@ -240,6 +241,14 @@ void QScriptDebuggerLocalsModelPrivate::deleteObjectSnapshots(const QList<qint64 frontend.scheduleDeleteScriptObjectSnapshot(snapshotIds.at(i)); } +void QScriptDebuggerLocalsModelPrivate::deleteAllObjectSnapshots() +{ + QList<qint64> snapshotIds; + for (int i = 0; i < invisibleRootNode->children.count(); ++i) + snapshotIds += findSnapshotIdsRecursively(invisibleRootNode->children.at(i)); + deleteObjectSnapshots(snapshotIds); +} + QScriptDebuggerLocalsModelPrivate *QScriptDebuggerLocalsModelPrivate::get(QScriptDebuggerLocalsModel *q) { return q->d_func(); @@ -442,13 +451,6 @@ QScriptDebuggerLocalsModel::QScriptDebuggerLocalsModel( QScriptDebuggerLocalsModel::~QScriptDebuggerLocalsModel() { - Q_D(QScriptDebuggerLocalsModel); - QList<qint64> snapshotIds; - for (int i = 0; i < d->invisibleRootNode->children.count(); ++i) - snapshotIds += findSnapshotIdsRecursively(d->invisibleRootNode->children.at(i)); - QScriptDebuggerCommandSchedulerFrontend frontend(d->commandScheduler, 0); - for (int j = 0; j < snapshotIds.size(); ++j) - frontend.scheduleDeleteScriptObjectSnapshot(snapshotIds.at(j)); } QModelIndex QScriptDebuggerLocalsModelPrivate::addTopLevelObject(const QString &name, const QScriptDebuggerValue &object) @@ -807,7 +809,7 @@ QVariant QScriptDebuggerLocalsModel::data(const QModelIndex &index, int role) co QString str = node->property.valueAsString(); if (node->property.value().type() == QScriptDebuggerValue::StringValue) { // escape - str.replace(QLatin1String("\""), QLatin1String("\\\"")); + str.replace(QLatin1Char('\"'), QLatin1String("\\\"")); str.prepend(QLatin1Char('\"')); str.append(QLatin1Char('\"')); } diff --git a/src/scripttools/debugging/qscriptdebuggerobjectsnapshotdelta_p.h b/src/scripttools/debugging/qscriptdebuggerobjectsnapshotdelta_p.h index 379947f..bd349e7 100644 --- a/src/scripttools/debugging/qscriptdebuggerobjectsnapshotdelta_p.h +++ b/src/scripttools/debugging/qscriptdebuggerobjectsnapshotdelta_p.h @@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE +class QDataStream; + class Q_AUTOTEST_EXPORT QScriptDebuggerObjectSnapshotDelta { public: @@ -68,6 +70,9 @@ public: QScriptDebuggerValuePropertyList addedProperties; }; +Q_AUTOTEST_EXPORT QDataStream &operator<<(QDataStream &, const QScriptDebuggerObjectSnapshotDelta &); +Q_AUTOTEST_EXPORT QDataStream &operator>>(QDataStream &, QScriptDebuggerObjectSnapshotDelta &); + QT_END_NAMESPACE #endif diff --git a/src/scripttools/debugging/qscriptdebuggerresponse.cpp b/src/scripttools/debugging/qscriptdebuggerresponse.cpp index a9b25b7..8f04951 100644 --- a/src/scripttools/debugging/qscriptdebuggerresponse.cpp +++ b/src/scripttools/debugging/qscriptdebuggerresponse.cpp @@ -101,7 +101,6 @@ QScriptDebuggerResponse::QScriptDebuggerResponse(const QScriptDebuggerResponse & QScriptDebuggerResponse::~QScriptDebuggerResponse() { - delete d_ptr; } QScriptDebuggerResponse &QScriptDebuggerResponse::operator=(const QScriptDebuggerResponse &other) @@ -320,7 +319,7 @@ bool QScriptDebuggerResponse::operator!=(const QScriptDebuggerResponse &other) c */ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerResponse &response) { - const QScriptDebuggerResponsePrivate *d = response.d_ptr; + const QScriptDebuggerResponsePrivate *d = response.d_ptr.data(); out << (quint32)d->error; out << d->result; out << d->async; @@ -336,7 +335,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptDebuggerResponse &respons */ QDataStream &operator>>(QDataStream &in, QScriptDebuggerResponse &response) { - QScriptDebuggerResponsePrivate *d = response.d_ptr; + QScriptDebuggerResponsePrivate *d = response.d_ptr.data(); quint32 error; in >> error; diff --git a/src/scripttools/debugging/qscriptdebuggerresponse_p.h b/src/scripttools/debugging/qscriptdebuggerresponse_p.h index 6288cd7..ef2e973 100644 --- a/src/scripttools/debugging/qscriptdebuggerresponse_p.h +++ b/src/scripttools/debugging/qscriptdebuggerresponse_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qmap.h> #include <QtCore/qvariant.h> @@ -127,7 +127,7 @@ public: bool operator!=(const QScriptDebuggerResponse &other) const; private: - QScriptDebuggerResponsePrivate *d_ptr; + QScopedPointer<QScriptDebuggerResponsePrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerResponse) }; diff --git a/src/scripttools/debugging/qscriptdebuggerscriptedconsolecommand.cpp b/src/scripttools/debugging/qscriptdebuggerscriptedconsolecommand.cpp index 24fc415..aa39a8e 100644 --- a/src/scripttools/debugging/qscriptdebuggerscriptedconsolecommand.cpp +++ b/src/scripttools/debugging/qscriptdebuggerscriptedconsolecommand.cpp @@ -460,7 +460,7 @@ void QScriptDebuggerScriptedConsoleCommandJob::handleResponse( } /*! - \reimp + \internal */ QString QScriptDebuggerScriptedConsoleCommand::name() const { @@ -469,7 +469,7 @@ QString QScriptDebuggerScriptedConsoleCommand::name() const } /*! - \reimp + \internal */ QString QScriptDebuggerScriptedConsoleCommand::group() const { @@ -478,7 +478,7 @@ QString QScriptDebuggerScriptedConsoleCommand::group() const } /*! - \reimp + \internal */ QString QScriptDebuggerScriptedConsoleCommand::shortDescription() const { @@ -487,7 +487,7 @@ QString QScriptDebuggerScriptedConsoleCommand::shortDescription() const } /*! - \reimp + \internal */ QString QScriptDebuggerScriptedConsoleCommand::longDescription() const { @@ -496,7 +496,7 @@ QString QScriptDebuggerScriptedConsoleCommand::longDescription() const } /*! - \reimp + \internal */ QStringList QScriptDebuggerScriptedConsoleCommand::aliases() const { @@ -505,7 +505,7 @@ QStringList QScriptDebuggerScriptedConsoleCommand::aliases() const } /*! - \reimp + \internal */ QStringList QScriptDebuggerScriptedConsoleCommand::seeAlso() const { @@ -514,7 +514,7 @@ QStringList QScriptDebuggerScriptedConsoleCommand::seeAlso() const } /*! - \reimp + \internal */ QStringList QScriptDebuggerScriptedConsoleCommand::argumentTypes() const { @@ -523,7 +523,7 @@ QStringList QScriptDebuggerScriptedConsoleCommand::argumentTypes() const } /*! - \reimp + \internal */ QStringList QScriptDebuggerScriptedConsoleCommand::subCommands() const { @@ -532,7 +532,7 @@ QStringList QScriptDebuggerScriptedConsoleCommand::subCommands() const } /*! - \reimp + \internal */ QScriptDebuggerConsoleCommandJob *QScriptDebuggerScriptedConsoleCommand::createJob( const QStringList &arguments, diff --git a/src/scripttools/debugging/qscriptdebuggerstackmodel.cpp b/src/scripttools/debugging/qscriptdebuggerstackmodel.cpp index bc4ff5d..4f49ee1 100644 --- a/src/scripttools/debugging/qscriptdebuggerstackmodel.cpp +++ b/src/scripttools/debugging/qscriptdebuggerstackmodel.cpp @@ -131,11 +131,14 @@ QVariant QScriptDebuggerStackModel::data(const QModelIndex &index, int role) con name = QString::fromLatin1("<anonymous>"); return name; } else if (index.column() == 2) { - if (info.lineNumber() == -1) - return QString::fromLatin1("<native>"); QString fn = QFileInfo(info.fileName()).fileName(); - if (fn.isEmpty()) - fn = QString::fromLatin1("<anonymous script, id=%0>").arg(info.scriptId()); + if (fn.isEmpty()) { + if (info.functionType() == QScriptContextInfo::ScriptFunction) + fn = QString::fromLatin1("<anonymous script, id=%0>").arg(info.scriptId()); + else + fn = QString::fromLatin1("<native>"); + + } return QString::fromLatin1("%0:%1").arg(fn).arg(info.lineNumber()); } } else if (role == Qt::ToolTipRole) { diff --git a/src/scripttools/debugging/qscriptdebuggerstandardwidgetfactory.cpp b/src/scripttools/debugging/qscriptdebuggerstandardwidgetfactory.cpp new file mode 100644 index 0000000..d4fba2a --- /dev/null +++ b/src/scripttools/debugging/qscriptdebuggerstandardwidgetfactory.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSCriptTools module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qscriptdebuggerstandardwidgetfactory_p.h" +#include "qscriptdebuggerconsolewidget_p.h" +#include "qscriptdebuggerstackwidget_p.h" +#include "qscriptdebuggerscriptswidget_p.h" +#include "qscriptdebuggerlocalswidget_p.h" +#include "qscriptdebuggercodewidget_p.h" +#include "qscriptdebuggercodefinderwidget_p.h" +#include "qscriptbreakpointswidget_p.h" +#include "qscriptdebugoutputwidget_p.h" +#include "qscripterrorlogwidget_p.h" + +QT_BEGIN_NAMESPACE + +QScriptDebuggerStandardWidgetFactory::QScriptDebuggerStandardWidgetFactory(QObject *parent) + : QObject(parent) +{ +} + +QScriptDebuggerStandardWidgetFactory::~QScriptDebuggerStandardWidgetFactory() +{ +} + +QScriptDebugOutputWidgetInterface *QScriptDebuggerStandardWidgetFactory::createDebugOutputWidget() +{ + return new QScriptDebugOutputWidget(); +} + +QScriptDebuggerConsoleWidgetInterface *QScriptDebuggerStandardWidgetFactory::createConsoleWidget() +{ + return new QScriptDebuggerConsoleWidget(); +} + +QScriptErrorLogWidgetInterface *QScriptDebuggerStandardWidgetFactory::createErrorLogWidget() +{ + return new QScriptErrorLogWidget(); +} + +QScriptDebuggerCodeFinderWidgetInterface *QScriptDebuggerStandardWidgetFactory::createCodeFinderWidget() +{ + return new QScriptDebuggerCodeFinderWidget(); +} + +QScriptDebuggerStackWidgetInterface *QScriptDebuggerStandardWidgetFactory::createStackWidget() +{ + return new QScriptDebuggerStackWidget(); +} + +QScriptDebuggerScriptsWidgetInterface *QScriptDebuggerStandardWidgetFactory::createScriptsWidget() +{ + return new QScriptDebuggerScriptsWidget(); +} + +QScriptDebuggerLocalsWidgetInterface *QScriptDebuggerStandardWidgetFactory::createLocalsWidget() +{ + return new QScriptDebuggerLocalsWidget(); +} + +QScriptDebuggerCodeWidgetInterface *QScriptDebuggerStandardWidgetFactory::createCodeWidget() +{ + return new QScriptDebuggerCodeWidget(); +} + +QScriptBreakpointsWidgetInterface *QScriptDebuggerStandardWidgetFactory::createBreakpointsWidget() +{ + return new QScriptBreakpointsWidget(); +} + +QT_END_NAMESPACE diff --git a/src/scripttools/debugging/qscriptdebuggerstandardwidgetfactory_p.h b/src/scripttools/debugging/qscriptdebuggerstandardwidgetfactory_p.h new file mode 100644 index 0000000..77fca53 --- /dev/null +++ b/src/scripttools/debugging/qscriptdebuggerstandardwidgetfactory_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSCriptTools module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTDEBUGGERSTANDARDWIDGETFACTORY_P_H +#define QSCRIPTDEBUGGERSTANDARDWIDGETFACTORY_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qobject.h> + +#include "qscriptdebuggerwidgetfactoryinterface_p.h" + +QT_BEGIN_NAMESPACE + +class Q_AUTOTEST_EXPORT QScriptDebuggerStandardWidgetFactory + : public QObject, public QScriptDebuggerWidgetFactoryInterface +{ +public: + QScriptDebuggerStandardWidgetFactory(QObject *parent = 0); + virtual ~QScriptDebuggerStandardWidgetFactory(); + + QScriptDebugOutputWidgetInterface *createDebugOutputWidget(); + QScriptDebuggerConsoleWidgetInterface *createConsoleWidget(); + QScriptErrorLogWidgetInterface *createErrorLogWidget(); + QScriptDebuggerCodeFinderWidgetInterface *createCodeFinderWidget(); + QScriptDebuggerStackWidgetInterface *createStackWidget(); + QScriptDebuggerScriptsWidgetInterface *createScriptsWidget(); + QScriptDebuggerLocalsWidgetInterface *createLocalsWidget(); + QScriptDebuggerCodeWidgetInterface *createCodeWidget(); + QScriptBreakpointsWidgetInterface *createBreakpointsWidget(); + +private: + Q_DISABLE_COPY(QScriptDebuggerStandardWidgetFactory) +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/scripttools/debugging/qscriptdebuggervalue.cpp b/src/scripttools/debugging/qscriptdebuggervalue.cpp index 68f4fcd..201bbb0 100644 --- a/src/scripttools/debugging/qscriptdebuggervalue.cpp +++ b/src/scripttools/debugging/qscriptdebuggervalue.cpp @@ -94,7 +94,7 @@ QScriptDebuggerValue::QScriptDebuggerValue(const QScriptValue &value) : d_ptr(0) { if (value.isValid()) { - d_ptr = new QScriptDebuggerValuePrivate; + d_ptr.reset(new QScriptDebuggerValuePrivate); if (value.isUndefined()) d_ptr->type = UndefinedValue; else if (value.isNull()) @@ -157,7 +157,7 @@ QScriptDebuggerValue::QScriptDebuggerValue(ValueType type) } QScriptDebuggerValue::QScriptDebuggerValue(const QScriptDebuggerValue &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -165,21 +165,11 @@ QScriptDebuggerValue::QScriptDebuggerValue(const QScriptDebuggerValue &other) QScriptDebuggerValue::~QScriptDebuggerValue() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } QScriptDebuggerValue &QScriptDebuggerValue::operator=(const QScriptDebuggerValue &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/scripttools/debugging/qscriptdebuggervalue_p.h b/src/scripttools/debugging/qscriptdebuggervalue_p.h index c508cca..63cdce0 100644 --- a/src/scripttools/debugging/qscriptdebuggervalue_p.h +++ b/src/scripttools/debugging/qscriptdebuggervalue_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qlist.h> QT_BEGIN_NAMESPACE @@ -103,7 +103,7 @@ public: bool operator!=(const QScriptDebuggerValue &other) const; private: - QScriptDebuggerValuePrivate *d_ptr; + QScopedSharedPointer<QScriptDebuggerValuePrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerValue) }; diff --git a/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp b/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp index d15f512..f7cc899 100644 --- a/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp +++ b/src/scripttools/debugging/qscriptdebuggervalueproperty.cpp @@ -41,6 +41,7 @@ #include "qscriptdebuggervalueproperty_p.h" #include "qscriptdebuggervalue_p.h" +#include "qscriptdebuggerobjectsnapshotdelta_p.h" #include <QtCore/qatomic.h> #include <QtCore/qdatastream.h> @@ -105,7 +106,7 @@ QScriptDebuggerValueProperty::QScriptDebuggerValueProperty(const QString &name, Constructs a QScriptDebuggerValueProperty that is a copy of the \a other property. */ QScriptDebuggerValueProperty::QScriptDebuggerValueProperty(const QScriptDebuggerValueProperty &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -116,10 +117,6 @@ QScriptDebuggerValueProperty::QScriptDebuggerValueProperty(const QScriptDebugger */ QScriptDebuggerValueProperty::~QScriptDebuggerValueProperty() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } /*! @@ -127,13 +124,7 @@ QScriptDebuggerValueProperty::~QScriptDebuggerValueProperty() */ QScriptDebuggerValueProperty &QScriptDebuggerValueProperty::operator=(const QScriptDebuggerValueProperty &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } @@ -225,4 +216,20 @@ QDataStream &operator>>(QDataStream &in, QScriptDebuggerValueProperty &property) return in; } +QDataStream &operator<<(QDataStream &out, const QScriptDebuggerObjectSnapshotDelta &delta) +{ + out << delta.removedProperties; + out << delta.changedProperties; + out << delta.addedProperties; + return out; +} + +QDataStream &operator>>(QDataStream &in, QScriptDebuggerObjectSnapshotDelta &delta) +{ + in >> delta.removedProperties; + in >> delta.changedProperties; + in >> delta.addedProperties; + return in; +} + QT_END_NAMESPACE diff --git a/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h b/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h index 0e12740..8464c63 100644 --- a/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h +++ b/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h @@ -55,6 +55,7 @@ #include <QtCore/qobjectdefs.h> #include <QtCore/qlist.h> +#include <QtCore/qscopedpointer.h> #include <QtScript/qscriptvalue.h> QT_BEGIN_NAMESPACE @@ -85,7 +86,7 @@ public: bool isValid() const; private: - QScriptDebuggerValuePropertyPrivate *d_ptr; + QScopedSharedPointer<QScriptDebuggerValuePropertyPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptDebuggerValueProperty) }; diff --git a/src/scripttools/debugging/qscriptdebuggerwidgetfactoryinterface_p.h b/src/scripttools/debugging/qscriptdebuggerwidgetfactoryinterface_p.h index e30103f..d7ba522 100644 --- a/src/scripttools/debugging/qscriptdebuggerwidgetfactoryinterface_p.h +++ b/src/scripttools/debugging/qscriptdebuggerwidgetfactoryinterface_p.h @@ -61,6 +61,11 @@ class QScriptDebugOutputWidgetInterface; class QScriptDebuggerConsoleWidgetInterface; class QScriptErrorLogWidgetInterface; class QScriptDebuggerCodeFinderWidgetInterface; +class QScriptDebuggerStackWidgetInterface; +class QScriptDebuggerScriptsWidgetInterface; +class QScriptDebuggerLocalsWidgetInterface; +class QScriptDebuggerCodeWidgetInterface; +class QScriptBreakpointsWidgetInterface; class Q_AUTOTEST_EXPORT QScriptDebuggerWidgetFactoryInterface { @@ -71,6 +76,11 @@ public: virtual QScriptDebuggerConsoleWidgetInterface *createConsoleWidget() = 0; virtual QScriptErrorLogWidgetInterface *createErrorLogWidget() = 0; virtual QScriptDebuggerCodeFinderWidgetInterface *createCodeFinderWidget() = 0; + virtual QScriptDebuggerStackWidgetInterface *createStackWidget() = 0; + virtual QScriptDebuggerScriptsWidgetInterface *createScriptsWidget() = 0; + virtual QScriptDebuggerLocalsWidgetInterface *createLocalsWidget() = 0; + virtual QScriptDebuggerCodeWidgetInterface *createCodeWidget() = 0; + virtual QScriptBreakpointsWidgetInterface *createBreakpointsWidget() = 0; }; QT_END_NAMESPACE diff --git a/src/scripttools/debugging/qscriptedit.cpp b/src/scripttools/debugging/qscriptedit.cpp index 8623300..c32567e 100644 --- a/src/scripttools/debugging/qscriptedit.cpp +++ b/src/scripttools/debugging/qscriptedit.cpp @@ -156,6 +156,16 @@ void QScriptEdit::setExecutableLineNumbers(const QSet<int> &lineNumbers) m_executableLineNumbers = lineNumbers; } +bool QScriptEdit::isExecutableLine(int lineNumber) const +{ +#if 0 // ### enable me once we have information about the script again + return m_executableLineNumbers.contains(lineNumber); +#else + Q_UNUSED(lineNumber); + return true; +#endif +} + int QScriptEdit::currentLineNumber() const { return textCursor().blockNumber() + m_baseLineNumber; @@ -342,7 +352,7 @@ void QScriptEdit::extraAreaPaintEvent(QPaintEvent *e) icon.paint(&painter, r, Qt::AlignCenter); } - if (!m_executableLineNumbers.contains(lineNumber)) + if (!isExecutableLine(lineNumber)) painter.setPen(pal.color(QPalette::Mid)); else painter.setPen(QColor(Qt::darkCyan)); @@ -369,7 +379,7 @@ void QScriptEdit::extraAreaMouseEvent(QMouseEvent *e) if (e->type() == QEvent::MouseMove && e->buttons() == 0) { // mouse tracking bool hand = (e->pos().x() <= markWidth); int lineNumber = cursor.blockNumber() + m_baseLineNumber; - hand = hand && m_executableLineNumbers.contains(lineNumber); + hand = hand && isExecutableLine(lineNumber); #ifndef QT_NO_CURSOR if (hand != (m_extraArea->cursor().shape() == Qt::PointingHandCursor)) m_extraArea->setCursor(hand ? Qt::PointingHandCursor : Qt::ArrowCursor); @@ -379,7 +389,7 @@ void QScriptEdit::extraAreaMouseEvent(QMouseEvent *e) if (e->type() == QEvent::MouseButtonPress) { if (e->button() == Qt::LeftButton) { int lineNumber = cursor.blockNumber() + m_baseLineNumber; - bool executable = m_executableLineNumbers.contains(lineNumber); + bool executable = isExecutableLine(lineNumber); if ((e->pos().x() <= markWidth) && executable) m_extraAreaToggleBlockNumber = cursor.blockNumber(); else @@ -394,7 +404,7 @@ void QScriptEdit::extraAreaMouseEvent(QMouseEvent *e) } } else if (e->button() == Qt::RightButton) { int lineNumber = cursor.blockNumber() + m_baseLineNumber; - if (!m_executableLineNumbers.contains(lineNumber)) + if (!isExecutableLine(lineNumber)) return; bool has = m_breakpoints.contains(lineNumber); QMenu *popup = new QMenu(); diff --git a/src/scripttools/debugging/qscriptedit_p.h b/src/scripttools/debugging/qscriptedit_p.h index 8ca378a..1ce61e4 100644 --- a/src/scripttools/debugging/qscriptedit_p.h +++ b/src/scripttools/debugging/qscriptedit_p.h @@ -75,6 +75,7 @@ public: int executionLineNumber() const; void setExecutionLineNumber(int lineNumber, bool error); void setExecutableLineNumbers(const QSet<int> &lineNumbers); + bool isExecutableLine(int lineNumber) const; int currentLineNumber() const; void gotoLine(int lineNumber); diff --git a/src/scripttools/debugging/qscriptenginedebugger.cpp b/src/scripttools/debugging/qscriptenginedebugger.cpp index 8e7bd71..21a0781 100644 --- a/src/scripttools/debugging/qscriptenginedebugger.cpp +++ b/src/scripttools/debugging/qscriptenginedebugger.cpp @@ -42,25 +42,14 @@ #include "qscriptenginedebugger.h" #include "qscriptdebugger_p.h" #include "qscriptenginedebuggerfrontend_p.h" -#include "qscriptdebuggerconsolewidget_p.h" -#include "qscriptdebuggerstackwidget_p.h" -#include "qscriptdebuggerscriptswidget_p.h" -#include "qscriptdebuggerlocalswidget_p.h" -#include "qscriptdebuggercodewidget_p.h" -#include "qscriptdebuggercodefinderwidget_p.h" -#include "qscriptbreakpointswidget_p.h" -#include "qscriptdebugoutputwidget_p.h" -#include "qscripterrorlogwidget_p.h" -#include "qscriptdebuggerwidgetfactoryinterface_p.h" +#include "qscriptdebuggerstandardwidgetfactory_p.h" #include <private/qobject_p.h> #include <QtCore/qsettings.h> #include <QtGui/qapplication.h> #include <QtGui/qdockwidget.h> #include <QtGui/qmainwindow.h> -#include <QtGui/qmenu.h> #include <QtGui/qmenubar.h> -#include <QtGui/qtoolbar.h> #include <QtGui/qboxlayout.h> // this has to be outside the namespace @@ -86,8 +75,8 @@ public: \brief The QScriptEngineDebugger class provides a QScriptEngine debugger. - \ingroup scripttools - \mainclass + \ingroup script + The QScriptEngineDebugger class provides a debugger that can be embedded into Qt applications that use Qt Script. The debugger @@ -137,7 +126,7 @@ public: mode in which it accepts input from the user. The evaluationResumed() signal is emitted when script evaluation is resumed, i.e, when execution control is given back to the script - engine. + engine. The state() function returns the debugger's current state. When calling QScriptEngine::evaluate() it is useful to pass a descriptive script name (file name) as second argument, as this is @@ -237,20 +226,24 @@ public: \value GoToLineAction Shows the "Go to Line" dialog. */ +/*! + \enum QScriptEngineDebugger::DebuggerState + \since 4.6 + + This enum specifies the current state of the debugger. + + \value RunningState The debugger is running. (Script evaluation is allowed.) + \value SuspendedState The debugger has suspended script evaluation. +*/ + class QScriptEngineDebuggerPrivate - : public QObjectPrivate, - public QScriptDebuggerWidgetFactoryInterface + : public QObjectPrivate { Q_DECLARE_PUBLIC(QScriptEngineDebugger) public: QScriptEngineDebuggerPrivate(); ~QScriptEngineDebuggerPrivate(); - QScriptDebugOutputWidgetInterface *createDebugOutputWidget(); - QScriptDebuggerConsoleWidgetInterface *createConsoleWidget(); - QScriptErrorLogWidgetInterface *createErrorLogWidget(); - QScriptDebuggerCodeFinderWidgetInterface *createCodeFinderWidget(); - // private slots void _q_showStandardWindow(); @@ -320,26 +313,6 @@ QScriptEngineDebuggerPrivate::~QScriptEngineDebuggerPrivate() } } -QScriptDebugOutputWidgetInterface *QScriptEngineDebuggerPrivate::createDebugOutputWidget() -{ - return new QScriptDebugOutputWidget(); -} - -QScriptDebuggerConsoleWidgetInterface *QScriptEngineDebuggerPrivate::createConsoleWidget() -{ - return new QScriptDebuggerConsoleWidget(); -} - -QScriptErrorLogWidgetInterface *QScriptEngineDebuggerPrivate::createErrorLogWidget() -{ - return new QScriptErrorLogWidget(); -} - -QScriptDebuggerCodeFinderWidgetInterface *QScriptEngineDebuggerPrivate::createCodeFinderWidget() -{ - return new QScriptDebuggerCodeFinderWidget(); -} - void QScriptEngineDebuggerPrivate::_q_showStandardWindow() { Q_Q(QScriptEngineDebugger); @@ -352,7 +325,7 @@ void QScriptEngineDebuggerPrivate::createDebugger() Q_Q(QScriptEngineDebugger); if (!debugger) { debugger = new QScriptDebugger(); - debugger->setWidgetFactory(this); + debugger->setWidgetFactory(new QScriptDebuggerStandardWidgetFactory(q)); QObject::connect(debugger, SIGNAL(started()), q, SIGNAL(evaluationResumed())); QObject::connect(debugger, SIGNAL(stopped()), @@ -424,6 +397,20 @@ void QScriptEngineDebugger::detach() } /*! + \since 4.6 + + Returns the current state of the debugger. + + \sa evaluationResumed() + \sa evaluationSuspended() +*/ +QScriptEngineDebugger::DebuggerState QScriptEngineDebugger::state() const +{ + Q_D(const QScriptEngineDebugger); + return !d->debugger || !d->debugger->isInteractive() ? SuspendedState : RunningState; +} + +/*! Returns a pointer to the instance of the specified standard \a widget. The widgets available are defined by the DebuggerWidget @@ -447,81 +434,7 @@ QWidget *QScriptEngineDebugger::widget(DebuggerWidget widget) const { Q_D(const QScriptEngineDebugger); const_cast<QScriptEngineDebuggerPrivate*>(d)->createDebugger(); - switch (widget) { - case ConsoleWidget: { - QScriptDebuggerConsoleWidgetInterface *w = d->debugger->consoleWidget(); - if (!w) { - w = new QScriptDebuggerConsoleWidget(); - d->debugger->setConsoleWidget(w); - } - return w; - } - case StackWidget: { - QScriptDebuggerStackWidgetInterface *w = d->debugger->stackWidget(); - if (!w) { - w = new QScriptDebuggerStackWidget(); - d->debugger->setStackWidget(w); - } - return w; - } - case ScriptsWidget: { - QScriptDebuggerScriptsWidgetInterface *w = d->debugger->scriptsWidget(); - if (!w) { - w = new QScriptDebuggerScriptsWidget(); - d->debugger->setScriptsWidget(w); - } - return w; - } - case LocalsWidget: { - QScriptDebuggerLocalsWidgetInterface *w = d->debugger->localsWidget(); - if (!w) { - w = new QScriptDebuggerLocalsWidget(); - d->debugger->setLocalsWidget(w); - } - return w; - } - case CodeWidget: { - QScriptDebuggerCodeWidgetInterface *w = d->debugger->codeWidget(); - if (!w) { - w = new QScriptDebuggerCodeWidget(); - d->debugger->setCodeWidget(w); - } - return w; - } - case CodeFinderWidget: { - QScriptDebuggerCodeFinderWidgetInterface *w = d->debugger->codeFinderWidget(); - if (!w) { - w = new QScriptDebuggerCodeFinderWidget(); - d->debugger->setCodeFinderWidget(w); - } - return w; - } - case BreakpointsWidget: { - QScriptBreakpointsWidgetInterface *w = d->debugger->breakpointsWidget(); - if (!w) { - w = new QScriptBreakpointsWidget(); - d->debugger->setBreakpointsWidget(w); - } - return w; - } - case DebugOutputWidget: { - QScriptDebugOutputWidgetInterface *w = d->debugger->debugOutputWidget(); - if (!w) { - w = new QScriptDebugOutputWidget(); - d->debugger->setDebugOutputWidget(w); - } - return w; - } - case ErrorLogWidget: { - QScriptErrorLogWidgetInterface *w = d->debugger->errorLogWidget(); - if (!w) { - w = new QScriptErrorLogWidget(); - d->debugger->setErrorLogWidget(w); - } - return w; - } - } - return 0; + return d->debugger->widget(static_cast<QScriptDebugger::DebuggerWidget>(static_cast<int>(widget))); } /*! @@ -545,39 +458,7 @@ QAction *QScriptEngineDebugger::action(DebuggerAction action) const Q_D(const QScriptEngineDebugger); QScriptEngineDebugger *that = const_cast<QScriptEngineDebugger*>(this); that->d_func()->createDebugger(); - switch (action) { - case InterruptAction: - return d->debugger->interruptAction(that); - case ContinueAction: - return d->debugger->continueAction(that); - case StepIntoAction: - return d->debugger->stepIntoAction(that); - case StepOverAction: - return d->debugger->stepOverAction(that); - case StepOutAction: - return d->debugger->stepOutAction(that); - case RunToCursorAction: - return d->debugger->runToCursorAction(that); - case RunToNewScriptAction: - return d->debugger->runToNewScriptAction(that); - case ToggleBreakpointAction: - return d->debugger->toggleBreakpointAction(that); - case ClearDebugOutputAction: - return d->debugger->clearDebugOutputAction(that); - case ClearErrorLogAction: - return d->debugger->clearErrorLogAction(that); - case ClearConsoleAction: - return d->debugger->clearConsoleAction(that); - case FindInScriptAction: - return d->debugger->findInScriptAction(that); - case FindNextInScriptAction: - return d->debugger->findNextInScriptAction(that); - case FindPreviousInScriptAction: - return d->debugger->findPreviousInScriptAction(that); - case GoToLineAction: - return d->debugger->goToLineAction(that); - } - return 0; + return d->debugger->action(static_cast<QScriptDebugger::DebuggerAction>(static_cast<int>(action)), that); } /*! @@ -730,25 +611,9 @@ QMainWindow *QScriptEngineDebugger::standardWindow() const */ QMenu *QScriptEngineDebugger::createStandardMenu(QWidget *parent) { - QMenu *menu = new QMenu(parent); - menu->setTitle(QObject::tr("Debug")); - menu->addAction(action(ContinueAction)); - menu->addAction(action(InterruptAction)); - menu->addAction(action(StepIntoAction)); - menu->addAction(action(StepOverAction)); - menu->addAction(action(StepOutAction)); - menu->addAction(action(RunToCursorAction)); - menu->addAction(action(RunToNewScriptAction)); - - menu->addSeparator(); - menu->addAction(action(ToggleBreakpointAction)); - - menu->addSeparator(); - menu->addAction(action(ClearDebugOutputAction)); - menu->addAction(action(ClearErrorLogAction)); - menu->addAction(action(ClearConsoleAction)); - - return menu; + Q_D(QScriptEngineDebugger); + d->createDebugger(); + return d->debugger->createStandardMenu(parent, this); } /*! @@ -759,18 +624,9 @@ QMenu *QScriptEngineDebugger::createStandardMenu(QWidget *parent) */ QToolBar *QScriptEngineDebugger::createStandardToolBar(QWidget *parent) { - QToolBar *tb = new QToolBar(parent); - tb->setObjectName(QLatin1String("qtscriptdebugger_standardToolBar")); - tb->addAction(action(ContinueAction)); - tb->addAction(action(InterruptAction)); - tb->addAction(action(StepIntoAction)); - tb->addAction(action(StepOverAction)); - tb->addAction(action(StepOutAction)); - tb->addAction(action(RunToCursorAction)); - tb->addAction(action(RunToNewScriptAction)); - tb->addSeparator(); - tb->addAction(action(FindInScriptAction)); - return tb; + Q_D(QScriptEngineDebugger); + d->createDebugger(); + return d->debugger->createStandardToolBar(parent, this); } /*! diff --git a/src/scripttools/debugging/qscriptenginedebugger.h b/src/scripttools/debugging/qscriptenginedebugger.h index c9fd2fd..fc2832f 100644 --- a/src/scripttools/debugging/qscriptenginedebugger.h +++ b/src/scripttools/debugging/qscriptenginedebugger.h @@ -92,6 +92,11 @@ public: GoToLineAction }; + enum DebuggerState { + RunningState, + SuspendedState + }; + QScriptEngineDebugger(QObject *parent = 0); ~QScriptEngineDebugger(); @@ -108,6 +113,8 @@ public: QWidget *widget(DebuggerWidget widget) const; QAction *action(DebuggerAction action) const; + DebuggerState state() const; + Q_SIGNALS: void evaluationSuspended(); void evaluationResumed(); diff --git a/src/scripttools/debugging/qscriptenginedebuggerfrontend.cpp b/src/scripttools/debugging/qscriptenginedebuggerfrontend.cpp index 219d70b..f710d25 100644 --- a/src/scripttools/debugging/qscriptenginedebuggerfrontend.cpp +++ b/src/scripttools/debugging/qscriptenginedebuggerfrontend.cpp @@ -323,7 +323,7 @@ QScriptDebuggerBackend *QScriptEngineDebuggerFrontend::backend() const } /*! - \reimp + \internal */ void QScriptEngineDebuggerFrontend::processCommand(int id, const QScriptDebuggerCommand &command) { diff --git a/src/scripttools/debugging/qscriptscriptdata.cpp b/src/scripttools/debugging/qscriptscriptdata.cpp index 553f8cd..dfddef3 100644 --- a/src/scripttools/debugging/qscriptscriptdata.cpp +++ b/src/scripttools/debugging/qscriptscriptdata.cpp @@ -98,7 +98,7 @@ QScriptScriptData::QScriptScriptData(const QString &contents, const QString &fil } QScriptScriptData::QScriptScriptData(const QScriptScriptData &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -106,21 +106,11 @@ QScriptScriptData::QScriptScriptData(const QScriptScriptData &other) QScriptScriptData::~QScriptScriptData() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } QScriptScriptData &QScriptScriptData::operator=(const QScriptScriptData &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } @@ -191,7 +181,7 @@ bool QScriptScriptData::operator!=(const QScriptScriptData &other) const QDataStream &operator<<(QDataStream &out, const QScriptScriptData &data) { - const QScriptScriptDataPrivate *d = data.d_ptr; + const QScriptScriptDataPrivate *d = data.d_ptr.data(); if (d) { out << d->contents; out << d->fileName; @@ -207,10 +197,10 @@ QDataStream &operator<<(QDataStream &out, const QScriptScriptData &data) QDataStream &operator>>(QDataStream &in, QScriptScriptData &data) { if (!data.d_ptr) { - data.d_ptr = new QScriptScriptDataPrivate(); + data.d_ptr.reset(new QScriptScriptDataPrivate()); data.d_ptr->ref.ref(); } - QScriptScriptDataPrivate *d = data.d_ptr; + QScriptScriptDataPrivate *d = data.d_ptr.data(); in >> d->contents; in >> d->fileName; qint32 ln; diff --git a/src/scripttools/debugging/qscriptscriptdata_p.h b/src/scripttools/debugging/qscriptscriptdata_p.h index 1792493..8ed61ad 100644 --- a/src/scripttools/debugging/qscriptscriptdata_p.h +++ b/src/scripttools/debugging/qscriptscriptdata_p.h @@ -54,7 +54,7 @@ // #include <QtCore/qobjectdefs.h> - +#include <QtCore/qscopedpointer.h> #include <QtCore/qdatetime.h> #include <QtCore/qmap.h> @@ -91,7 +91,7 @@ public: bool operator!=(const QScriptScriptData &other) const; private: - QScriptScriptDataPrivate *d_ptr; + QScopedSharedPointer<QScriptScriptDataPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptScriptData) }; diff --git a/src/scripttools/debugging/qscriptstdmessagehandler.cpp b/src/scripttools/debugging/qscriptstdmessagehandler.cpp index 1f43689..6fc6df0 100644 --- a/src/scripttools/debugging/qscriptstdmessagehandler.cpp +++ b/src/scripttools/debugging/qscriptstdmessagehandler.cpp @@ -66,7 +66,6 @@ QScriptStdMessageHandler::QScriptStdMessageHandler() QScriptStdMessageHandler::~QScriptStdMessageHandler() { - delete d_ptr; } void QScriptStdMessageHandler::message(QtMsgType type, const QString &text, @@ -92,18 +91,7 @@ void QScriptStdMessageHandler::message(QtMsgType type, const QString &text, } msg.append(text); - FILE *fp = 0; - switch (type) { - case QtDebugMsg: - fp = stdout; - break; - case QtWarningMsg: - case QtCriticalMsg: - case QtFatalMsg: - fp = stderr; - break; - } - + FILE *fp = (type == QtDebugMsg) ? stdout : stderr; fprintf(fp, "%s\n", msg.toLatin1().constData()); fflush(fp); } diff --git a/src/scripttools/debugging/qscriptstdmessagehandler_p.h b/src/scripttools/debugging/qscriptstdmessagehandler_p.h index 7321687..9f1364c 100644 --- a/src/scripttools/debugging/qscriptstdmessagehandler_p.h +++ b/src/scripttools/debugging/qscriptstdmessagehandler_p.h @@ -53,6 +53,8 @@ // We mean it. // +#include <QtCore/qscopedpointer.h> + #include "qscriptmessagehandlerinterface_p.h" QT_BEGIN_NAMESPACE @@ -71,7 +73,7 @@ public: const QVariant &data = QVariant()); private: - QScriptStdMessageHandlerPrivate *d_ptr; + QScopedPointer<QScriptStdMessageHandlerPrivate> d_ptr; private: Q_DECLARE_PRIVATE(QScriptStdMessageHandler) diff --git a/src/scripttools/debugging/qscripttooltipproviderinterface_p.h b/src/scripttools/debugging/qscripttooltipproviderinterface_p.h index 4b17d31..9909068 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 diff --git a/src/scripttools/debugging/qscriptvalueproperty.cpp b/src/scripttools/debugging/qscriptvalueproperty.cpp index b1db6d2..643b4a9 100644 --- a/src/scripttools/debugging/qscriptvalueproperty.cpp +++ b/src/scripttools/debugging/qscriptvalueproperty.cpp @@ -95,7 +95,7 @@ QScriptValueProperty::QScriptValueProperty(const QString &name, Constructs a QScriptValueProperty that is a copy of the \a other property. */ QScriptValueProperty::QScriptValueProperty(const QScriptValueProperty &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { if (d_ptr) d_ptr->ref.ref(); @@ -106,10 +106,6 @@ QScriptValueProperty::QScriptValueProperty(const QScriptValueProperty &other) */ QScriptValueProperty::~QScriptValueProperty() { - if (d_ptr && !d_ptr->ref.deref()) { - delete d_ptr; - d_ptr = 0; - } } /*! @@ -117,13 +113,7 @@ QScriptValueProperty::~QScriptValueProperty() */ QScriptValueProperty &QScriptValueProperty::operator=(const QScriptValueProperty &other) { - if (d_ptr == other.d_ptr) - return *this; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = other.d_ptr; - if (d_ptr) - d_ptr->ref.ref(); + d_ptr.assign(other.d_ptr.data()); return *this; } diff --git a/src/scripttools/debugging/qscriptvalueproperty_p.h b/src/scripttools/debugging/qscriptvalueproperty_p.h index 3eb0d7a..b40e065 100644 --- a/src/scripttools/debugging/qscriptvalueproperty_p.h +++ b/src/scripttools/debugging/qscriptvalueproperty_p.h @@ -55,6 +55,7 @@ #include <QtCore/qobjectdefs.h> #include <QtCore/qlist.h> +#include <QtCore/qscopedpointer.h> #include <QtScript/qscriptvalue.h> QT_BEGIN_NAMESPACE @@ -81,7 +82,7 @@ public: bool isValid() const; private: - QScriptValuePropertyPrivate *d_ptr; + QScopedSharedPointer<QScriptValuePropertyPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptValueProperty) }; diff --git a/src/scripttools/scripttools.pro b/src/scripttools/scripttools.pro index faf0936a..b1df7aa 100644 --- a/src/scripttools/scripttools.pro +++ b/src/scripttools/scripttools.pro @@ -9,4 +9,7 @@ unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtScript include(../qbase.pri) + include(debugging/debugging.pri) + +symbian:TARGET.UID3=0x2001E625 |