summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAurindam Jana <aurindam.jana@nokia.com>2011-12-20 16:12:38 +0100
committerAurindam Jana <aurindam.jana@nokia.com>2012-01-11 16:02:07 +0100
commit8bab001016a59b0b7ca97cf9a464882c4964a324 (patch)
tree19fe59e90ad2de41da3d21800fab8bc5150fcd93 /src
parent6a17d889d4190723bdb3add8143c534fe6f924c3 (diff)
downloadqt-creator-8bab001016a59b0b7ca97cf9a464882c4964a324.tar.gz
QmlJSDebug: Add a Debug Message Client
QDebugMessageClient uses the QDebugMessageService to retrieve and emit the debug output. Change-Id: Id02d148954dfa613d3fd317b4a533cfed34e345b Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/libs/qmljsdebugclient/qdebugmessageclient.cpp69
-rw-r--r--src/libs/qmljsdebugclient/qdebugmessageclient.h65
-rw-r--r--src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri6
-rw-r--r--src/plugins/debugger/qml/qmladapter.cpp28
-rw-r--r--src/plugins/debugger/qml/qmladapter.h4
-rw-r--r--src/plugins/debugger/qml/qmljsscriptconsole.cpp47
-rw-r--r--src/plugins/debugger/qml/qmljsscriptconsole.h1
7 files changed, 213 insertions, 7 deletions
diff --git a/src/libs/qmljsdebugclient/qdebugmessageclient.cpp b/src/libs/qmljsdebugclient/qdebugmessageclient.cpp
new file mode 100644
index 0000000000..bc1a11f665
--- /dev/null
+++ b/src/libs/qmljsdebugclient/qdebugmessageclient.cpp
@@ -0,0 +1,69 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**************************************************************************/
+
+#include "qdebugmessageclient.h"
+
+namespace QmlJsDebugClient {
+
+QDebugMessageClient::QDebugMessageClient(QDeclarativeDebugConnection *client)
+ : QDeclarativeDebugClient(QLatin1String("DebugMessages"), client)
+{
+}
+
+QDebugMessageClient::~QDebugMessageClient()
+{
+}
+
+void QDebugMessageClient::statusChanged(Status status)
+{
+ emit newStatus(status);
+}
+
+void QDebugMessageClient::messageReceived(const QByteArray &data)
+{
+ QDataStream ds(data);
+ QByteArray command;
+ ds >> command;
+
+ if (command == "MESSAGE") {
+ QByteArray messagePacket;
+ ds >> messagePacket;
+
+ QByteArray debugMessage;
+ int type;
+ QDataStream ms(messagePacket);
+ ms >> type >> debugMessage;
+ emit message(QtMsgType(type), QString::fromUtf8(debugMessage.data()));
+ }
+}
+
+} // namespace QmlJsDebugClient
diff --git a/src/libs/qmljsdebugclient/qdebugmessageclient.h b/src/libs/qmljsdebugclient/qdebugmessageclient.h
new file mode 100644
index 0000000000..59635cdf8b
--- /dev/null
+++ b/src/libs/qmljsdebugclient/qdebugmessageclient.h
@@ -0,0 +1,65 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**************************************************************************/
+
+#ifndef QDEBUGMESSAGECLIENT_H
+#define QDEBUGMESSAGECLIENT_H
+
+#include "qdeclarativedebugclient.h"
+#include "qmljsdebugclient_global.h"
+
+namespace QmlJsDebugClient {
+
+class QDebugMessageClientPrivate;
+class QMLJSDEBUGCLIENT_EXPORT QDebugMessageClient : public QDeclarativeDebugClient
+{
+ Q_OBJECT
+
+public:
+ explicit QDebugMessageClient(QDeclarativeDebugConnection *client);
+ ~QDebugMessageClient();
+
+protected:
+ virtual void statusChanged(Status status);
+ virtual void messageReceived(const QByteArray &);
+
+signals:
+ void newStatus(QDeclarativeDebugClient::Status);
+ void message(QtMsgType, const QString &);
+
+private:
+ class QDebugMessageClientPrivate *d;
+ Q_DISABLE_COPY(QDebugMessageClient)
+};
+
+} // namespace QmlJsDebugClient
+
+#endif // QDEBUGMESSAGECLIENT_H
diff --git a/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri b/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri
index 6b9fc03fb7..f15d920bf9 100644
--- a/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri
+++ b/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri
@@ -16,7 +16,8 @@ HEADERS += \
$$PWD/qmlprofilertraceclient.h \
$$PWD/qpacketprotocol.h \
$$PWD/qv8profilerclient.h \
- $$PWD/qmljsdebugclientconstants.h
+ $$PWD/qmljsdebugclientconstants.h \
+ $$PWD/qdebugmessageclient.h
SOURCES += \
$$PWD/qdeclarativedebugclient.cpp \
@@ -25,7 +26,8 @@ SOURCES += \
$$PWD/qmlprofilereventlist.cpp \
$$PWD/qmlprofilertraceclient.cpp \
$$PWD/qpacketprotocol.cpp \
- $$PWD/qv8profilerclient.cpp
+ $$PWD/qv8profilerclient.cpp \
+ $$PWD/qdebugmessageclient.cpp
OTHER_FILES += \
$$PWD/qmljsdebugclient.pri \
diff --git a/src/plugins/debugger/qml/qmladapter.cpp b/src/plugins/debugger/qml/qmladapter.cpp
index 9997f55581..dfdcde3cf2 100644
--- a/src/plugins/debugger/qml/qmladapter.cpp
+++ b/src/plugins/debugger/qml/qmladapter.cpp
@@ -42,6 +42,8 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
+#include <qmljsdebugclient/qdebugmessageclient.h>
+
#include <QtCore/QTimer>
#include <QtCore/QDebug>
@@ -57,6 +59,7 @@ public:
, m_engineDebugClient(0)
, m_conn(0)
, m_currentSelectedDebugId(-1)
+ , m_msgClient(0)
{
m_connectionTimer.setInterval(4000);
m_connectionTimer.setSingleShot(true);
@@ -70,6 +73,7 @@ public:
QHash<QString, QmlDebuggerClient*> debugClients;
int m_currentSelectedDebugId;
QString m_currentSelectedDebugName;
+ QmlJsDebugClient::QDebugMessageClient *m_msgClient;
};
} // namespace Internal
@@ -89,6 +93,9 @@ QmlAdapter::QmlAdapter(DebuggerEngine *engine, QObject *parent)
pluginManager->addObject(this);
createDebuggerClients();
+ d->m_msgClient = new QmlJsDebugClient::QDebugMessageClient(d->m_conn);
+ connect(d->m_msgClient, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
+ this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
}
QmlAdapter::~QmlAdapter()
@@ -155,11 +162,15 @@ void QmlAdapter::clientStatusChanged(QDeclarativeDebugClient::Status status)
serviceName = client->name();
logServiceStatusChange(serviceName, status);
+}
- if (status == QDeclarativeDebugClient::Enabled) {
- d->m_qmlClient = d->debugClients.value(serviceName);
- d->m_qmlClient->startSession();
- }
+void QmlAdapter::debugClientStatusChanged(QDeclarativeDebugClient::Status /*status*/)
+{
+ QDeclarativeDebugClient *client = qobject_cast<QDeclarativeDebugClient*>(sender());
+ QTC_ASSERT(client, return);
+
+ d->m_qmlClient = qobject_cast<Internal::QmlDebuggerClient *>(client);
+ d->m_qmlClient->startSession();
}
void QmlAdapter::connectionStateChanged()
@@ -211,10 +222,14 @@ void QmlAdapter::createDebuggerClients()
Internal::QScriptDebuggerClient *client1 = new Internal::QScriptDebuggerClient(d->m_conn);
connect(client1, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
+ connect(client1, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
+ this, SLOT(debugClientStatusChanged(QDeclarativeDebugClient::Status)));
Internal::QmlV8DebuggerClient *client2 = new Internal::QmlV8DebuggerClient(d->m_conn);
connect(client2, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
+ connect(client2, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
+ this, SLOT(debugClientStatusChanged(QDeclarativeDebugClient::Status)));
d->debugClients.insert(client1->name(),client1);
d->debugClients.insert(client2->name(),client2);
@@ -292,6 +307,11 @@ void QmlAdapter::setEngineDebugClient(QmlJsDebugClient::QDeclarativeEngineDebug
d->m_engineDebugClient = client;
}
+QmlJsDebugClient::QDebugMessageClient *QmlAdapter::messageClient() const
+{
+ return d->m_msgClient;
+}
+
int QmlAdapter::currentSelectedDebugId() const
{
return d->m_currentSelectedDebugId;
diff --git a/src/plugins/debugger/qml/qmladapter.h b/src/plugins/debugger/qml/qmladapter.h
index 2618529a5b..b0283dd633 100644
--- a/src/plugins/debugger/qml/qmladapter.h
+++ b/src/plugins/debugger/qml/qmladapter.h
@@ -42,6 +42,7 @@
namespace QmlJsDebugClient {
class QDeclarativeEngineDebug;
class QDeclarativeDebugConnection;
+class QDebugMessageClient;
}
namespace Debugger {
@@ -77,6 +78,8 @@ public:
QmlJsDebugClient::QDeclarativeEngineDebug *engineDebugClient() const;
void setEngineDebugClient(QmlJsDebugClient::QDeclarativeEngineDebug *client);
+ QDebugMessageClient *messageClient() const;
+
int currentSelectedDebugId() const;
QString currentSelectedDisplayName() const;
void setCurrentSelectedDebugInfo(int debugId, const QString &displayName = QString());
@@ -96,6 +99,7 @@ signals:
private slots:
void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
void clientStatusChanged(QDeclarativeDebugClient::Status status);
+ void debugClientStatusChanged(QDeclarativeDebugClient::Status status);
void connectionStateChanged();
void checkConnectionState();
diff --git a/src/plugins/debugger/qml/qmljsscriptconsole.cpp b/src/plugins/debugger/qml/qmljsscriptconsole.cpp
index 1626f33619..041b78bc72 100644
--- a/src/plugins/debugger/qml/qmljsscriptconsole.cpp
+++ b/src/plugins/debugger/qml/qmljsscriptconsole.cpp
@@ -42,6 +42,8 @@
#include <coreplugin/coreconstants.h>
#include <utils/statuslabel.h>
+#include <qmljsdebugclient/qdebugmessageclient.h>
+
#include <QtGui/QMenu>
#include <QtGui/QTextBlock>
#include <QtGui/QHBoxLayout>
@@ -209,8 +211,11 @@ void QmlJSScriptConsole::setInferiorStopped(bool inferiorStopped)
void QmlJSScriptConsole::setQmlAdapter(QmlAdapter *adapter)
{
d->adapter = adapter;
- if (adapter)
+ if (adapter) {
connect(adapter, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ connect(adapter->messageClient(), SIGNAL(message(QtMsgType,QString)),
+ this, SLOT(insertDebugOutput(QtMsgType,QString)));
+ }
clear();
}
@@ -278,6 +283,46 @@ void QmlJSScriptConsole::onSelectionChanged()
}
}
+void QmlJSScriptConsole::insertDebugOutput(QtMsgType type, const QString &debugMsg)
+{
+ QString msg(debugMsg);
+ msg.append(_("\n"));
+
+ QTextCursor cursor = textCursor();
+
+ cursor.setPosition(d->startOfEditableArea - d->prompt.length());
+ cursor.insertText(msg);
+
+ QTextEdit::ExtraSelection sel;
+
+ QTextCharFormat resultFormat;
+ switch (type) {
+ case QtDebugMsg:
+ resultFormat.setForeground(QColor(Qt::darkBlue));
+ break;
+ case QtWarningMsg:
+ resultFormat.setForeground(QColor(Qt::darkYellow));
+ break;
+ case QtCriticalMsg:
+ resultFormat.setForeground(QColor(Qt::darkRed));
+ break;
+ default:
+ resultFormat.setForeground(QColor(Qt::black));
+ }
+
+ cursor.movePosition(QTextCursor::PreviousBlock);
+ cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
+
+ sel.format = resultFormat;
+ sel.cursor = cursor;
+
+ d->selections.append(sel);
+
+ setExtraSelections(d->selections);
+
+ d->startOfEditableArea += msg.length();
+}
+
void QmlJSScriptConsole::keyPressEvent(QKeyEvent *e)
{
bool keyConsumed = false;
diff --git a/src/plugins/debugger/qml/qmljsscriptconsole.h b/src/plugins/debugger/qml/qmljsscriptconsole.h
index 7ddc842b56..2bfcc86d51 100644
--- a/src/plugins/debugger/qml/qmljsscriptconsole.h
+++ b/src/plugins/debugger/qml/qmljsscriptconsole.h
@@ -97,6 +97,7 @@ public slots:
void clear();
void onStateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State);
void onSelectionChanged();
+ void insertDebugOutput(QtMsgType type, const QString &debugMsg);
protected:
void keyPressEvent(QKeyEvent *e);