forked from qt-creator/qt-creator
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>
This commit is contained in:
69
src/libs/qmljsdebugclient/qdebugmessageclient.cpp
Normal file
69
src/libs/qmljsdebugclient/qdebugmessageclient.cpp
Normal file
@@ -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
|
||||
65
src/libs/qmljsdebugclient/qdebugmessageclient.h
Normal file
65
src/libs/qmljsdebugclient/qdebugmessageclient.h
Normal file
@@ -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
|
||||
@@ -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 \
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user