Commit de151fc1 authored by Aurindam Jana's avatar Aurindam Jana

ScriptConsole: Refactor

Clean up QmlEngine specific code from debbuger plugin.
The logic to check if the current debug engine is qmlengine
is done by scriptconsole. It also listens to debug engine
state transitions to enable/disable itself accordingly.

Change-Id: If21b1167e870e87166b2f7fd6f3283063e47ded0
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 63187490
......@@ -62,8 +62,6 @@
#include "watchwindow.h"
#include "watchutils.h"
#include "debuggertooltipmanager.h"
#include "qml/qmlengine.h"
#include "qml/qmlcppengine.h"
#include "snapshothandler.h"
#include "threadshandler.h"
......@@ -2097,14 +2095,7 @@ void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine)
//m_threadBox->setModelColumn(ThreadData::ComboNameColumn);
m_watchersWindow->setModel(engine->watchersModel());
//Initialize QmlJSConsole
QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(engine);
QmlCppEngine *qmlCppEngine = qobject_cast<QmlCppEngine *>(engine);
if (qmlCppEngine)
qmlEngine = qobject_cast<QmlEngine *>(qmlCppEngine->qmlEngine());
if (qmlEngine) {
m_scriptConsoleWindow->setQmlAdapter(qmlEngine->adapter());
}
m_scriptConsoleWindow->setEngine(engine);
engine->watchHandler()->rebuildModel();
......@@ -2376,19 +2367,6 @@ void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
|| state == InferiorUnrunnable;
setBusyCursor(!notbusy);
//Console should be enabled only for QML
QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(engine);
QmlCppEngine *qmlCppEngine = qobject_cast<QmlCppEngine *>(engine);
if (qmlCppEngine)
qmlEngine = qobject_cast<QmlEngine *>(qmlCppEngine->qmlEngine());
if (qmlEngine && (state == InferiorRunOk || state == InferiorStopOk)) {
m_scriptConsoleWindow->setEnabled(true);
m_scriptConsoleWindow->setInferiorStopped(state == InferiorStopOk);
} else {
m_scriptConsoleWindow->setEnabled(false);
}
}
void DebuggerPluginPrivate::updateDebugActions()
......
......@@ -47,6 +47,8 @@
#include <utils/qtcassert.h>
#include <qmljsdebugclient/qdebugmessageclient.h>
#include <debugger/qml/qmlcppengine.h>
#include <debugger/qml/qmlengine.h>
#include <QtGui/QMenu>
#include <QtGui/QTextBlock>
......@@ -67,7 +69,8 @@ class QmlJSScriptConsolePrivate
{
public:
QmlJSScriptConsolePrivate()
: prompt(_("> ")),
: adapter(0),
prompt(_("> ")),
startOfEditableArea(-1),
lastKnownPosition(0),
inferiorStopped(false)
......@@ -79,7 +82,7 @@ public:
void appendToHistory(const QString &script);
bool canEvaluateScript(const QString &script);
QWeakPointer<QmlAdapter> adapter;
QmlAdapter *adapter;
QString prompt;
int startOfEditableArea;
......@@ -193,14 +196,27 @@ QmlJSScriptConsoleWidget::~QmlJSScriptConsoleWidget()
settings->setValue(_(SHOW_ERROR), QVariant(m_showError->isChecked()));
settings->endGroup();
}
void QmlJSScriptConsoleWidget::setQmlAdapter(QmlAdapter *adapter)
{
m_console->setQmlAdapter(adapter);
}
void QmlJSScriptConsoleWidget::setInferiorStopped(bool inferiorStopped)
void QmlJSScriptConsoleWidget::setEngine(DebuggerEngine *engine)
{
m_console->setInferiorStopped(inferiorStopped);
if (m_console->engine())
disconnect(m_console->engine(), SIGNAL(stateChanged(Debugger::DebuggerState)),
this, SLOT(engineStateChanged(Debugger::DebuggerState)));
QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(engine);
QmlCppEngine *qmlCppEngine = qobject_cast<QmlCppEngine *>(engine);
if (qmlCppEngine)
qmlEngine = qobject_cast<QmlEngine *>(qmlCppEngine->qmlEngine());
//Supports only QML Engine
if (qmlEngine) {
connect(qmlEngine, SIGNAL(stateChanged(Debugger::DebuggerState)),
this, SLOT(engineStateChanged(Debugger::DebuggerState)));
engineStateChanged(qmlEngine->state());
}
m_console->setEngine(qmlEngine);
}
void QmlJSScriptConsoleWidget::appendResult(const QString &result)
......@@ -224,6 +240,16 @@ void QmlJSScriptConsoleWidget::setDebugLevel()
m_console->setDebugLevel(level);
}
void QmlJSScriptConsoleWidget::engineStateChanged(Debugger::DebuggerState state)
{
if (state == InferiorRunOk || state == InferiorStopOk) {
setEnabled(true);
m_console->setInferiorStopped(state == InferiorStopOk);
} else {
setEnabled(false);
}
}
///////////////////////////////////////////////////////////////////////
//
// QmlJSScriptConsole
......@@ -266,17 +292,33 @@ void QmlJSScriptConsole::setInferiorStopped(bool inferiorStopped)
onSelectionChanged();
}
void QmlJSScriptConsole::setQmlAdapter(QmlAdapter *adapter)
void QmlJSScriptConsole::setEngine(QmlEngine *engine)
{
d->adapter = adapter;
if (adapter) {
connect(adapter, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
connect(adapter->messageClient(), SIGNAL(message(QtMsgType,QString)),
if (d->adapter) {
disconnect(d->adapter, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
disconnect(d->adapter->messageClient(), SIGNAL(message(QtMsgType,QString)),
this, SLOT(insertDebugOutput(QtMsgType,QString)));
d->adapter = 0;
}
if (engine) {
d->adapter = engine->adapter();
connect(d->adapter, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
connect(d->adapter->messageClient(), SIGNAL(message(QtMsgType,QString)),
this, SLOT(insertDebugOutput(QtMsgType,QString)));
}
clear();
}
DebuggerEngine * QmlJSScriptConsole::engine()
{
if (d->adapter) {
return d->adapter->debuggerEngine();
}
return 0;
}
void QmlJSScriptConsole::appendResult(const QString &result)
{
QString currentScript = getCurrentScript();
......@@ -336,11 +378,11 @@ void QmlJSScriptConsole::onStateChanged(QmlJsDebugClient::QDeclarativeDebugQuery
void QmlJSScriptConsole::onSelectionChanged()
{
if (!d->adapter.isNull()) {
if (d->adapter) {
QString status;
if (!d->inferiorStopped) {
status.append(tr("Current Selected Object: "));
status.append(d->adapter.data()->currentSelectedDisplayName());
status.append(d->adapter->currentSelectedDisplayName());
}
emit updateStatusMessage(status, 0);
}
......@@ -571,9 +613,9 @@ void QmlJSScriptConsole::handleReturnKey()
//Select the engine for evaluation based on
//inferior state
if (!d->inferiorStopped) {
if (!d->adapter.isNull()) {
QDeclarativeEngineDebug *engineDebug = d->adapter.data()->engineDebugClient();
int id = d->adapter.data()->currentSelectedDebugId();
if (d->adapter) {
QDeclarativeEngineDebug *engineDebug = d->adapter->engineDebugClient();
int id = d->adapter->currentSelectedDebugId();
if (engineDebug && id != -1) {
QDeclarativeDebugExpressionQuery *query =
engineDebug->queryExpressionResult(id, currentScript, this);
......
......@@ -34,6 +34,7 @@
#define QMLJSSCRIPTCONSOLE_H
#include <qmljsdebugclient/qdeclarativeenginedebug.h>
#include <debugger/debuggerconstants.h>
#include <QtGui/QPlainTextEdit>
QT_BEGIN_NAMESPACE
......@@ -46,12 +47,13 @@ class StatusLabel;
namespace Debugger {
class QmlAdapter;
class DebuggerEngine;
namespace Internal {
class QmlJSScriptConsolePrivate;
class QmlJSScriptConsole;
class QmlEngine;
class QmlJSScriptConsoleWidget : public QWidget
{
......@@ -60,16 +62,18 @@ public:
QmlJSScriptConsoleWidget(QWidget *parent = 0);
~QmlJSScriptConsoleWidget();
void setQmlAdapter(QmlAdapter *adapter);
void setInferiorStopped(bool inferiorStopped);
void setEngine(DebuggerEngine *engine);
public slots:
void appendResult(const QString &result);
void setDebugLevel();
signals:
void evaluateExpression(const QString &expr);
private slots:
void setDebugLevel();
void engineStateChanged(Debugger::DebuggerState state);
private:
QmlJSScriptConsole *m_console;
Utils::StatusLabel *m_statusLabel;
......@@ -105,7 +109,8 @@ public:
void setInferiorStopped(bool inferiorStopped);
void setQmlAdapter(QmlAdapter *adapter);
void setEngine(QmlEngine *engine);
DebuggerEngine *engine();
void appendResult(const QString &result);
......@@ -114,7 +119,6 @@ public:
public slots:
void clear();
void onStateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State);
void onSelectionChanged();
void insertDebugOutput(QtMsgType type, const QString &debugMsg);
protected:
......@@ -127,6 +131,7 @@ signals:
void updateStatusMessage(const QString &message, int timeoutMS);
private slots:
void onSelectionChanged();
void onCursorPositionChanged();
private:
......@@ -141,6 +146,7 @@ private:
private:
QmlJSScriptConsolePrivate *d;
friend class QmlJSScriptConsolePrivate;
};
} //Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment