diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-07-15 17:00:22 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-08-04 13:35:00 +0000 |
commit | 158b4dccbe7b24168eed05d1eb31065e45168e0e (patch) | |
tree | 9cc47b8feaf36a76e7610d2b1c7b8b7a9a294300 /src/plugins/qmltooling/shared | |
parent | 183eae3cbcb3c5c99d97fdc38f9dba7ea87cf05f (diff) |
Move inspector service and QtQuick2 inspector into a common plugin
The inspector service doesn't do anything useful without the QtQuick2
plugin and vice versa. This way we can also use the
QQmlDebugPluginManager.
Change-Id: I78f154dcc9103ec9ec3d2eda216bfb293231583e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmltooling/shared')
-rw-r--r-- | src/plugins/qmltooling/shared/abstracttool.cpp | 50 | ||||
-rw-r--r-- | src/plugins/qmltooling/shared/abstracttool.h | 85 | ||||
-rw-r--r-- | src/plugins/qmltooling/shared/abstractviewinspector.cpp | 420 | ||||
-rw-r--r-- | src/plugins/qmltooling/shared/abstractviewinspector.h | 126 |
4 files changed, 0 insertions, 681 deletions
diff --git a/src/plugins/qmltooling/shared/abstracttool.cpp b/src/plugins/qmltooling/shared/abstracttool.cpp deleted file mode 100644 index 3e059bed13..0000000000 --- a/src/plugins/qmltooling/shared/abstracttool.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** 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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "abstracttool.h" - -#include "abstractviewinspector.h" - -QT_BEGIN_NAMESPACE - -namespace QmlJSDebugger { - -AbstractTool::AbstractTool(AbstractViewInspector *inspector) : - QObject(inspector), - m_inspector(inspector) -{ -} - -} // namespace QmlJSDebugger - -QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/shared/abstracttool.h b/src/plugins/qmltooling/shared/abstracttool.h deleted file mode 100644 index c796925866..0000000000 --- a/src/plugins/qmltooling/shared/abstracttool.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** 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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ABSTRACTTOOL_H -#define ABSTRACTTOOL_H - -#include <QtCore/QObject> - -QT_BEGIN_NAMESPACE -class QMouseEvent; -class QKeyEvent; -class QWheelEvent; -class QTouchEvent; - -namespace QmlJSDebugger { - -class AbstractViewInspector; - -class AbstractTool : public QObject -{ - Q_OBJECT - -public: - explicit AbstractTool(AbstractViewInspector *inspector); - - AbstractViewInspector *inspector() const { return m_inspector; } - - virtual void enable(bool enable) = 0; - - virtual void leaveEvent(QEvent *event) = 0; - - virtual void mousePressEvent(QMouseEvent *event) = 0; - virtual void mouseMoveEvent(QMouseEvent *event) = 0; - virtual void mouseReleaseEvent(QMouseEvent *event) = 0; - virtual void mouseDoubleClickEvent(QMouseEvent *event) = 0; - - virtual void hoverMoveEvent(QMouseEvent *event) = 0; -#ifndef QT_NO_WHEELEVENT - virtual void wheelEvent(QWheelEvent *event) = 0; -#endif - - virtual void keyPressEvent(QKeyEvent *event) = 0; - virtual void keyReleaseEvent(QKeyEvent *keyEvent) = 0; - - virtual void touchEvent(QTouchEvent *) {} - -private: - AbstractViewInspector *m_inspector; -}; - -} // namespace QmlJSDebugger - -QT_END_NAMESPACE - -#endif // ABSTRACTTOOL_H diff --git a/src/plugins/qmltooling/shared/abstractviewinspector.cpp b/src/plugins/qmltooling/shared/abstractviewinspector.cpp deleted file mode 100644 index e1b55c8449..0000000000 --- a/src/plugins/qmltooling/shared/abstractviewinspector.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** 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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "abstractviewinspector.h" -#include "abstracttool.h" - -#include <QtCore/QDebug> -#include <QtQml/QQmlEngine> -#include <QtQml/QQmlComponent> -#include <QtCore/private/qabstractanimation_p.h> -#include <QtQml/private/qqmlinspectorservice_p.h> -#include <QtQml/private/qqmldebugconnector_p.h> -#include <QtQml/private/qqmlcontext_p.h> - -#include <QtGui/QMouseEvent> -#include <QtGui/QTouchEvent> - -//INSPECTOR SERVICE PROTOCOL -// <HEADER><COMMAND><DATA> -// <HEADER> : <type{request, response, event}><requestId/eventId>[<response_success_bool>] -// <COMMAND> : {"enable", "disable", "select", "reload", "setAnimationSpeed", -// "showAppOnTop", "createObject", "destroyObject", "moveObject", -// "clearCache"} -// <DATA> : select: <debugIds_int_list> -// reload: <hash<changed_filename_string, filecontents_bytearray>> -// setAnimationSpeed: <speed_real> -// showAppOnTop: <set_bool> -// createObject: <qml_string><parentId_int><imports_string_list><filename_string> -// destroyObject: <debugId_int> -// moveObject: <debugId_int><newParentId_int> -// clearCache: void -// Response for "destroyObject" carries the <debugId_int> of the destroyed object. - -QT_BEGIN_NAMESPACE - -const char REQUEST[] = "request"; -const char RESPONSE[] = "response"; -const char EVENT[] = "event"; -const char ENABLE[] = "enable"; -const char DISABLE[] = "disable"; -const char SELECT[] = "select"; -const char RELOAD[] = "reload"; -const char SET_ANIMATION_SPEED[] = "setAnimationSpeed"; -const char SHOW_APP_ON_TOP[] = "showAppOnTop"; -const char CREATE_OBJECT[] = "createObject"; -const char DESTROY_OBJECT[] = "destroyObject"; -const char MOVE_OBJECT[] = "moveObject"; -const char CLEAR_CACHE[] = "clearCache"; - -namespace QmlJSDebugger { - - -AbstractViewInspector::AbstractViewInspector(QObject *parent) : - QObject(parent), - m_enabled(false), - m_debugService(QQmlDebugConnector::service<QQmlInspectorServiceImpl>()), - m_eventId(0), - m_reloadEventId(-1) -{ -} - -void AbstractViewInspector::createQmlObject(const QString &qml, QObject *parent, - const QStringList &importList, - const QString &filename) -{ - if (!parent) - return; - - QString imports; - foreach (const QString &s, importList) { - imports += s; - imports += QLatin1Char('\n'); - } - - QQmlContext *parentContext = declarativeEngine()->contextForObject(parent); - QQmlComponent component(declarativeEngine()); - QByteArray constructedQml = QString(imports + qml).toLatin1(); - - component.setData(constructedQml, QUrl::fromLocalFile(filename)); - QObject *newObject = component.create(parentContext); - if (newObject) - reparentQmlObject(newObject, parent); -} - -void AbstractViewInspector::clearComponentCache() -{ - declarativeEngine()->clearComponentCache(); -} - -void AbstractViewInspector::setEnabled(bool value) -{ - if (m_enabled == value) - return; - - m_enabled = value; - foreach (AbstractTool *tool, m_tools) - tool->enable(m_enabled); -} - -void AbstractViewInspector::setAnimationSpeed(qreal slowDownFactor) -{ - QUnifiedTimer::instance()->setSlowModeEnabled(slowDownFactor != 1.0); - QUnifiedTimer::instance()->setSlowdownFactor(slowDownFactor); -} - -bool AbstractViewInspector::eventFilter(QObject *obj, QEvent *event) -{ - if (!enabled()) - return QObject::eventFilter(obj, event); - - switch (event->type()) { - case QEvent::Leave: - if (leaveEvent(event)) - return true; - break; - case QEvent::MouseButtonPress: - if (mousePressEvent(static_cast<QMouseEvent*>(event))) - return true; - break; - case QEvent::MouseMove: - if (mouseMoveEvent(static_cast<QMouseEvent*>(event))) - return true; - break; - case QEvent::MouseButtonRelease: - if (mouseReleaseEvent(static_cast<QMouseEvent*>(event))) - return true; - break; - case QEvent::KeyPress: - if (keyPressEvent(static_cast<QKeyEvent*>(event))) - return true; - break; - case QEvent::KeyRelease: - if (keyReleaseEvent(static_cast<QKeyEvent*>(event))) - return true; - break; - case QEvent::MouseButtonDblClick: - if (mouseDoubleClickEvent(static_cast<QMouseEvent*>(event))) - return true; - break; -#ifndef QT_NO_WHEELEVENT - case QEvent::Wheel: - if (wheelEvent(static_cast<QWheelEvent*>(event))) - return true; - break; -#endif - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - if (touchEvent(static_cast<QTouchEvent*>(event))) - return true; - break; - default: - break; - } - - return QObject::eventFilter(obj, event); -} - -bool AbstractViewInspector::leaveEvent(QEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->leaveEvent(event); - return true; -} - -bool AbstractViewInspector::mousePressEvent(QMouseEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->mousePressEvent(event); - return true; -} - -bool AbstractViewInspector::mouseMoveEvent(QMouseEvent *event) -{ - if (event->buttons()) { - foreach (AbstractTool *tool, m_tools) - tool->mouseMoveEvent(event); - } else { - foreach (AbstractTool *tool, m_tools) - tool->hoverMoveEvent(event); - } - return true; -} - -bool AbstractViewInspector::mouseReleaseEvent(QMouseEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->mouseReleaseEvent(event); - return true; -} - -bool AbstractViewInspector::keyPressEvent(QKeyEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->keyPressEvent(event); - return true; -} - -bool AbstractViewInspector::keyReleaseEvent(QKeyEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->keyReleaseEvent(event); - return true; -} - -bool AbstractViewInspector::mouseDoubleClickEvent(QMouseEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->mouseDoubleClickEvent(event); - return true; -} - -#ifndef QT_NO_WHEELEVENT -bool AbstractViewInspector::wheelEvent(QWheelEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->wheelEvent(event); - return true; -} -#endif - -bool AbstractViewInspector::touchEvent(QTouchEvent *event) -{ - foreach (AbstractTool *tool, m_tools) - tool->touchEvent(event); - return true; -} - -void AbstractViewInspector::onQmlObjectDestroyed(QObject *object) -{ - if (!m_hashObjectsTobeDestroyed.contains(object)) - return; - - QPair<int, int> ids = m_hashObjectsTobeDestroyed.take(object); - - QByteArray response; - - QQmlDebugStream rs(&response, QIODevice::WriteOnly); - rs << QByteArray(RESPONSE) << ids.first << true << ids.second; - - emit m_debugService->messageToClient(m_debugService->name(), response); -} - -void AbstractViewInspector::handleMessage(const QByteArray &message) -{ - bool success = true; - QQmlDebugStream ds(message); - - QByteArray type; - ds >> type; - - int requestId = -1; - if (type == REQUEST) { - QByteArray command; - ds >> requestId >> command; - - if (command == ENABLE) { - setEnabled(true); - - } else if (command == DISABLE) { - setEnabled(false); - - } else if (command == SELECT) { - QList<int> debugIds; - ds >> debugIds; - - QList<QObject*> selectedObjects; - foreach (int debugId, debugIds) { - if (QObject *obj = QQmlDebugService::objectForId(debugId)) - selectedObjects << obj; - } - if (m_enabled) - changeCurrentObjects(selectedObjects); - - } else if (command == RELOAD) { - QHash<QString, QByteArray> changesHash; - ds >> changesHash; - m_reloadEventId = requestId; - reloadQmlFile(changesHash); - return; - - } else if (command == SET_ANIMATION_SPEED) { - qreal speed; - ds >> speed; - setAnimationSpeed(speed); - - } else if (command == SHOW_APP_ON_TOP) { - bool showOnTop; - ds >> showOnTop; - setShowAppOnTop(showOnTop); - - } else if (command == CREATE_OBJECT) { - QString qml; - int parentId; - QString filename; - QStringList imports; - ds >> qml >> parentId >> imports >> filename; - createQmlObject(qml, QQmlDebugService::objectForId(parentId), - imports, filename); - - } else if (command == DESTROY_OBJECT) { - int debugId; - ds >> debugId; - if (QObject *obj = QQmlDebugService::objectForId(debugId)) { - QPair<int, int> ids(requestId, debugId); - m_hashObjectsTobeDestroyed.insert(obj, ids); - connect(obj, SIGNAL(destroyed(QObject*)), SLOT(onQmlObjectDestroyed(QObject*))); - obj->deleteLater(); - } - return; - - } else if (command == MOVE_OBJECT) { - int debugId, newParent; - ds >> debugId >> newParent; - reparentQmlObject(QQmlDebugService::objectForId(debugId), - QQmlDebugService::objectForId(newParent)); - - } else if (command == CLEAR_CACHE) { - clearComponentCache(); - - } else { - qWarning() << "Warning: Not handling command:" << command; - success = false; - - } - } else { - qWarning() << "Warning: Not handling type:" << type << REQUEST; - success = false; - - } - - QByteArray response; - QQmlDebugStream rs(&response, QIODevice::WriteOnly); - rs << QByteArray(RESPONSE) << requestId << success; - emit m_debugService->messageToClient(m_debugService->name(), response); -} - -void AbstractViewInspector::sendCurrentObjects(const QList<QObject*> &objects) -{ - QByteArray message; - QQmlDebugStream ds(&message, QIODevice::WriteOnly); - - ds << QByteArray(EVENT) << m_eventId++ << QByteArray(SELECT); - - QList<int> debugIds; - debugIds.reserve(objects.count()); - foreach (QObject *object, objects) - debugIds << QQmlDebugService::idForObject(object); - ds << debugIds; - - emit m_debugService->messageToClient(m_debugService->name(), message); -} - -void AbstractViewInspector::sendQmlFileReloaded(bool success) -{ - if (m_reloadEventId == -1) - return; - - QByteArray response; - - QQmlDebugStream rs(&response, QIODevice::WriteOnly); - rs << QByteArray(RESPONSE) << m_reloadEventId << success; - - emit m_debugService->messageToClient(m_debugService->name(), response); -} - -QString AbstractViewInspector::idStringForObject(QObject *obj) const -{ - QQmlContext *context = qmlContext(obj); - if (context) { - QQmlContextData *cdata = QQmlContextData::get(context); - if (cdata) - return cdata->findObjectId(obj); - } - return QString(); -} - -void AbstractViewInspector::appendTool(AbstractTool *tool) -{ - m_tools.append(tool); -} - -void AbstractViewInspector::removeTool(AbstractTool *tool) -{ - m_tools.removeOne(tool); -} - -} // namespace QmlJSDebugger - -QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/shared/abstractviewinspector.h b/src/plugins/qmltooling/shared/abstractviewinspector.h deleted file mode 100644 index 342e6359d7..0000000000 --- a/src/plugins/qmltooling/shared/abstractviewinspector.h +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** 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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ABSTRACTVIEWINSPECTOR_H -#define ABSTRACTVIEWINSPECTOR_H - -#include <QtCore/QHash> -#include <QtCore/QObject> -#include <QtCore/QStringList> - -QT_BEGIN_NAMESPACE -class QQmlEngine; -class QQmlDebugService; -class QKeyEvent; -class QMouseEvent; -class QWheelEvent; -class QTouchEvent; - -namespace QmlJSDebugger { - -class AbstractTool; - -/* - * The common code between QQuickView and QQuickView inspectors lives here, - */ -class AbstractViewInspector : public QObject -{ - Q_OBJECT - -public: - explicit AbstractViewInspector(QObject *parent = 0); - - void handleMessage(const QByteArray &message); - - void createQmlObject(const QString &qml, QObject *parent, - const QStringList &importList, - const QString &filename = QString()); - void clearComponentCache(); - - bool enabled() const { return m_enabled; } - - void sendCurrentObjects(const QList<QObject*> &); - - void sendQmlFileReloaded(bool success); - - QString idStringForObject(QObject *obj) const; - - virtual void changeCurrentObjects(const QList<QObject*> &objects) = 0; - virtual void reparentQmlObject(QObject *object, QObject *newParent) = 0; - virtual Qt::WindowFlags windowFlags() const = 0; - virtual void setWindowFlags(Qt::WindowFlags flags) = 0; - virtual QQmlEngine *declarativeEngine() const = 0; - virtual void reloadQmlFile(const QHash<QString, QByteArray> &changesHash) = 0; - - void appendTool(AbstractTool *tool); - void removeTool(AbstractTool *tool); - -protected: - bool eventFilter(QObject *, QEvent *); - - virtual bool leaveEvent(QEvent *); - virtual bool mousePressEvent(QMouseEvent *event); - virtual bool mouseMoveEvent(QMouseEvent *event); - virtual bool mouseReleaseEvent(QMouseEvent *event); - virtual bool keyPressEvent(QKeyEvent *event); - virtual bool keyReleaseEvent(QKeyEvent *keyEvent); - virtual bool mouseDoubleClickEvent(QMouseEvent *event); -#ifndef QT_NO_WHEELEVENT - virtual bool wheelEvent(QWheelEvent *event); -#endif - virtual bool touchEvent(QTouchEvent *event); - virtual void setShowAppOnTop(bool) = 0; - -private slots: - void onQmlObjectDestroyed(QObject *object); - -private: - void setEnabled(bool value); - - void setAnimationSpeed(qreal factor); - - bool m_enabled; - - QQmlDebugService *m_debugService; - QList<AbstractTool *> m_tools; - int m_eventId; - int m_reloadEventId; - // Hash< object to be destroyed, QPair<destroy eventId, object debugId> > - QHash<QObject *, QPair<int, int> > m_hashObjectsTobeDestroyed; -}; - -} // namespace QmlJSDebugger - -QT_END_NAMESPACE - -#endif // ABSTRACTVIEWINSPECTOR_H |