From 857f7d6505a570d5cbb307763e17784a1cc730ec Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 30 Aug 2011 17:34:39 +0200 Subject: Add an abstraction layer for the qml designer The Qml Designer for Qt4 is using private headers but this broke very often because nobody outside of the designer team was aware of it. This is an attempt to define a clear interface which the designer is using. Change-Id: I9ad2db234043da8e787024d3c2d346356bbbef47 Reviewed-on: http://codereview.qt.nokia.com/3608 Reviewed-by: Qt Sanity Bot Reviewed-by: Aaron Kennedy --- src/declarative/declarative.pro | 1 + src/declarative/designer/designer.pri | 2 + src/declarative/designer/designersupport.cpp | 406 +++++++++++++++++++++++++++ src/declarative/designer/designersupport.h | 149 ++++++++++ 4 files changed, 558 insertions(+) create mode 100644 src/declarative/designer/designer.pri create mode 100644 src/declarative/designer/designersupport.cpp create mode 100644 src/declarative/designer/designersupport.h (limited to 'src') diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 5e50fa57f5..4d550e481a 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -32,6 +32,7 @@ include(debugger/debugger.pri) include(scenegraph/scenegraph.pri) include(items/items.pri) include(particles/particles.pri) +include(designer/designer.pri) symbian: { TARGET.UID3=0x2001E623 diff --git a/src/declarative/designer/designer.pri b/src/declarative/designer/designer.pri new file mode 100644 index 0000000000..c523525977 --- /dev/null +++ b/src/declarative/designer/designer.pri @@ -0,0 +1,2 @@ +HEADERS += designer/designersupport.h +SOURCES += designer/designersupport.cpp diff --git a/src/declarative/designer/designersupport.cpp b/src/declarative/designer/designersupport.cpp new file mode 100644 index 0000000000..824642a989 --- /dev/null +++ b/src/declarative/designer/designersupport.cpp @@ -0,0 +1,406 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 "designersupport.h" +#include "qsgitem_p.h" + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +DesignerSupport::DesignerSupport() +{ +} + +DesignerSupport::~DesignerSupport() +{ + QHash::iterator iterator; + + for (iterator = m_itemTextureHash.begin(); iterator != m_itemTextureHash.end(); ++iterator) { + QSGShaderEffectTexture *texture = iterator.value(); + QSGItem *item = iterator.key(); + QSGItemPrivate::get(item)->derefFromEffectItem(true); + delete texture; + } +} + +void DesignerSupport::refFromEffectItem(QSGItem *referencedItem, bool hide) +{ + if (referencedItem == 0) + return; + + QSGItemPrivate::get(referencedItem)->refFromEffectItem(hide); + QSGCanvasPrivate::get(referencedItem->canvas())->updateDirtyNode(referencedItem); + + Q_ASSERT(QSGItemPrivate::get(referencedItem)->rootNode); + + if (!m_itemTextureHash.contains(referencedItem)) { + QSGShaderEffectTexture *texture = new QSGShaderEffectTexture(referencedItem); + + texture->setLive(true); + texture->setItem(QSGItemPrivate::get(referencedItem)->rootNode); + texture->setRect(referencedItem->boundingRect()); + texture->setSize(referencedItem->boundingRect().size().toSize()); + texture->setRecursive(true); + texture->setFormat(GL_RGBA8); + texture->setHasMipmaps(false); + + m_itemTextureHash.insert(referencedItem, texture); + } +} + +void DesignerSupport::derefFromEffectItem(QSGItem *referencedItem, bool unhide) +{ + if (referencedItem == 0) + return; + + delete m_itemTextureHash.take(referencedItem); + QSGItemPrivate::get(referencedItem)->derefFromEffectItem(unhide); +} + +QImage DesignerSupport::renderImageForItem(QSGItem *referencedItem) +{ + if (referencedItem == 0 || referencedItem->parentItem() == 0) { + qDebug() << __FILE__ << __LINE__ << "Warning: Item can be rendered."; + return QImage(); + } + + QSGShaderEffectTexture *renderTexture = m_itemTextureHash.value(referencedItem); + + Q_ASSERT(renderTexture); + if (renderTexture == 0) + return QImage(); + renderTexture->setRect(referencedItem->boundingRect()); + renderTexture->setSize(referencedItem->boundingRect().size().toSize()); + renderTexture->updateTexture(); + + QImage renderImage = renderTexture->toImage(); + renderImage = renderImage.mirrored(false, true); + + if (renderImage.size().isEmpty()) + qDebug() << __FILE__ << __LINE__ << "Warning: Image is empty."; + + qDebug() << __FUNCTION__ << renderImage.size(); + + return renderImage; +} + +bool DesignerSupport::isDirty(QSGItem *referencedItem, DirtyType dirtyType) +{ + if (referencedItem == 0) + return false; + + return QSGItemPrivate::get(referencedItem)->dirtyAttributes & dirtyType; +} + +void DesignerSupport::resetDirty(QSGItem *referencedItem) +{ + if (referencedItem == 0) + return; + + QSGItemPrivate::get(referencedItem)->dirtyAttributes = 0x0; + QSGItemPrivate::get(referencedItem)->removeFromDirtyList(); +} + +QTransform DesignerSupport::canvasTransform(QSGItem *referencedItem) +{ + if (referencedItem == 0) + return QTransform(); + + return QSGItemPrivate::get(referencedItem)->itemToCanvasTransform(); +} + +QTransform DesignerSupport::parentTransform(QSGItem *referencedItem) +{ + if (referencedItem == 0) + return QTransform(); + + QTransform parentTransform; + + QSGItemPrivate::get(referencedItem)->itemToParentTransform(parentTransform); + + return parentTransform; +} + +QString propertyNameForAnchorLine(const QSGAnchorLine::AnchorLine &anchorLine) +{ + switch (anchorLine) { + case QSGAnchorLine::Left: return QLatin1String("left"); + case QSGAnchorLine::Right: return QLatin1String("right"); + case QSGAnchorLine::Top: return QLatin1String("top"); + case QSGAnchorLine::Bottom: return QLatin1String("bottom"); + case QSGAnchorLine::HCenter: return QLatin1String("horizontalCenter"); + case QSGAnchorLine::VCenter: return QLatin1String("verticalCenter"); + case QSGAnchorLine::Baseline: return QLatin1String("baseline"); + case QSGAnchorLine::Invalid: + default: return QString(); + } +} + +bool isValidAnchorName(const QString &name) +{ + static QStringList anchorNameList(QStringList() << QLatin1String("anchors.top") + << QLatin1String("anchors.left") + << QLatin1String("anchors.right") + << QLatin1String("anchors.bottom") + << QLatin1String("anchors.verticalCenter") + << QLatin1String("anchors.horizontalCenter") + << QLatin1String("anchors.fill") + << QLatin1String("anchors.centerIn") + << QLatin1String("anchors.baseline")); + + return anchorNameList.contains(name); +} + +bool DesignerSupport::isAnchoredTo(QSGItem *fromItem, QSGItem *toItem) +{ + Q_ASSERT(dynamic_cast(QSGItemPrivate::get(fromItem))); + QSGItemPrivate *fromItemPrivate = static_cast(QSGItemPrivate::get(fromItem)); + QSGAnchors *anchors = fromItemPrivate->anchors(); + return anchors->fill() == toItem + || anchors->centerIn() == toItem + || anchors->bottom().item == toItem + || anchors->top().item == toItem + || anchors->left().item == toItem + || anchors->right().item == toItem + || anchors->verticalCenter().item == toItem + || anchors->horizontalCenter().item == toItem + || anchors->baseline().item == toItem; +} + +bool DesignerSupport::areChildrenAnchoredTo(QSGItem *fromItem, QSGItem *toItem) +{ + foreach (QSGItem *childItem, fromItem->childItems()) { + if (childItem) { + if (isAnchoredTo(childItem, toItem)) + return true; + + if (areChildrenAnchoredTo(childItem, toItem)) + return true; + } + } + + return false; +} + +QSGAnchors *anchors(QSGItem *item) +{ + QSGItemPrivate *itemPrivate = static_cast(QSGItemPrivate::get(item)); + return itemPrivate->anchors(); +} + +QSGAnchors::Anchor anchorLineFlagForName(const QString &name) +{ + if (name == QLatin1String("anchors.top")) + return QSGAnchors::TopAnchor; + + if (name == QLatin1String("anchors.left")) + return QSGAnchors::LeftAnchor; + + if (name == QLatin1String("anchors.bottom")) + return QSGAnchors::BottomAnchor; + + if (name == QLatin1String("anchors.right")) + return QSGAnchors::RightAnchor; + + if (name == QLatin1String("anchors.horizontalCenter")) + return QSGAnchors::HCenterAnchor; + + if (name == QLatin1String("anchors.verticalCenter")) + return QSGAnchors::VCenterAnchor; + + if (name == QLatin1String("anchors.baseline")) + return QSGAnchors::BaselineAnchor; + + + Q_ASSERT_X(false, Q_FUNC_INFO, "wrong anchor name - this should never happen"); + return QSGAnchors::LeftAnchor; +} + +bool DesignerSupport::hasAnchor(QSGItem *item, const QString &name) +{ + if (!isValidAnchorName(name)) + return false; + + if (name == QLatin1String("anchors.fill")) + return anchors(item)->fill() != 0; + + if (name == QLatin1String("anchors.centerIn")) + return anchors(item)->centerIn() != 0; + + if (name == QLatin1String("anchors.right")) + return anchors(item)->right().item != 0; + + if (name == QLatin1String("anchors.top")) + return anchors(item)->top().item != 0; + + if (name == QLatin1String("anchors.left")) + return anchors(item)->left().item != 0; + + if (name == QLatin1String("anchors.bottom")) + return anchors(item)->bottom().item != 0; + + if (name == QLatin1String("anchors.horizontalCenter")) + return anchors(item)->horizontalCenter().item != 0; + + if (name == QLatin1String("anchors.verticalCenter")) + return anchors(item)->verticalCenter().item != 0; + + if (name == QLatin1String("anchors.baseline")) + return anchors(item)->baseline().item != 0; + + return anchors(item)->usedAnchors().testFlag(anchorLineFlagForName(name)); +} + +QSGItem *DesignerSupport::anchorFillTargetItem(QSGItem *item) +{ + return anchors(item)->fill(); +} + +QSGItem *DesignerSupport::anchorCenterInTargetItem(QSGItem *item) +{ + return anchors(item)->centerIn(); +} + + + +QPair DesignerSupport::anchorLineTarget(QSGItem *item, const QString &name, QDeclarativeContext *context) +{ + QObject *targetObject = 0; + QString targetName; + + if (name == QLatin1String("anchors.fill")) { + targetObject = anchors(item)->fill(); + } else if (name == QLatin1String("anchors.centerIn")) { + targetObject = anchors(item)->centerIn(); + } else { + QDeclarativeProperty metaProperty(item, name, context); + if (!metaProperty.isValid()) + return QPair(); + + QSGAnchorLine anchorLine = metaProperty.read().value(); + if (anchorLine.anchorLine != QSGAnchorLine::Invalid) { + targetObject = anchorLine.item; + targetName = propertyNameForAnchorLine(anchorLine.anchorLine); + } + + } + + return QPair(targetName, targetObject); +} + +void DesignerSupport::resetAnchor(QSGItem *item, const QString &name) +{ + if (name == QLatin1String("anchors.fill")) { + anchors(item)->resetFill(); + } else if (name == QLatin1String("anchors.centerIn")) { + anchors(item)->resetCenterIn(); + } else if (name == QLatin1String("anchors.top")) { + anchors(item)->resetTop(); + } else if (name == QLatin1String("anchors.left")) { + anchors(item)->resetLeft(); + } else if (name == QLatin1String("anchors.right")) { + anchors(item)->resetRight(); + } else if (name == QLatin1String("anchors.bottom")) { + anchors(item)->resetBottom(); + } else if (name == QLatin1String("anchors.horizontalCenter")) { + anchors(item)->resetHorizontalCenter(); + } else if (name == QLatin1String("anchors.verticalCenter")) { + anchors(item)->resetVerticalCenter(); + } else if (name == QLatin1String("anchors.baseline")) { + anchors(item)->resetBaseline(); + } +} + +QList DesignerSupport::statesForItem(QSGItem *item) +{ + QList objectList; + QList stateList = QSGItemPrivate::get(item)->_states()->states(); + qCopy(stateList.begin(), stateList.end(), objectList.begin()); + + return objectList; +} + +bool DesignerSupport::isComponentComplete(QSGItem *item) +{ + return static_cast(QSGItemPrivate::get(item))->componentComplete; +} + +int DesignerSupport::borderWidth(QSGItem *item) +{ + QSGRectangle *rectangle = qobject_cast(item); + if (rectangle) + return rectangle->border()->width(); + + return 0; +} + +void DesignerSupport::refreshExpressions(QDeclarativeContext *context) +{ + QDeclarativeContextPrivate::get(context)->data->refreshExpressions(); +} + +void DesignerSupport::setRootItem(QSGView *view, QSGItem *item) +{ + QSGViewPrivate::get(view)->setRootObject(item); +} + +bool DesignerSupport::isValidWidth(QSGItem *item) +{ + return QSGItemPrivate::get(item)->heightValid; +} + +bool DesignerSupport::isValidHeight(QSGItem *item) +{ + return QSGItemPrivate::get(item)->widthValid; +} + +void DesignerSupport::updateDirtyNode(QSGItem *item) +{ + QSGCanvasPrivate::get(item->canvas())->updateDirtyNode(item); +} + +QT_END_NAMESPACE diff --git a/src/declarative/designer/designersupport.h b/src/declarative/designer/designersupport.h new file mode 100644 index 0000000000..0165769506 --- /dev/null +++ b/src/declarative/designer/designersupport.h @@ -0,0 +1,149 @@ +// Commit: +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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$ +** +****************************************************************************/ + +#ifndef DESIGNERSUPPORT_H +#define DESIGNERSUPPORT_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 +#include + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QSGItem; +class QSGShaderEffectTexture; +class QImage; +class QTransform; +class QDeclarativeContext; +class QSGView; + + +class Q_DECLARATIVE_EXPORT DesignerSupport +{ +public: + enum DirtyType { + TransformOrigin = 0x00000001, + Transform = 0x00000002, + BasicTransform = 0x00000004, + Position = 0x00000008, + Size = 0x00000010, + + ZValue = 0x00000020, + Content = 0x00000040, + Smooth = 0x00000080, + OpacityValue = 0x00000100, + ChildrenChanged = 0x00000200, + ChildrenStackingChanged = 0x00000400, + ParentChanged = 0x00000800, + + Clip = 0x00001000, + Canvas = 0x00002000, + + EffectReference = 0x00008000, + Visible = 0x00010000, + HideReference = 0x00020000, + + TransformUpdateMask = TransformOrigin | Transform | BasicTransform | Position | Size | Canvas, + ComplexTransformUpdateMask = Transform | Canvas, + ContentUpdateMask = Size | Content | Smooth | Canvas, + ChildrenUpdateMask = ChildrenChanged | ChildrenStackingChanged | EffectReference | Canvas + }; + + + DesignerSupport(); + ~DesignerSupport(); + + void refFromEffectItem(QSGItem *referencedItem, bool hide = true); + void derefFromEffectItem(QSGItem *referencedItem, bool unhide = true); + + QImage renderImageForItem(QSGItem *referencedItem); + + static bool isDirty(QSGItem *referencedItem, DirtyType dirtyType); + static void resetDirty(QSGItem *referencedItem); + + static QTransform canvasTransform(QSGItem *referencedItem); + static QTransform parentTransform(QSGItem *referencedItem); + + static bool isAnchoredTo(QSGItem *fromItem, QSGItem *toItem); + static bool areChildrenAnchoredTo(QSGItem *fromItem, QSGItem *toItem); + static bool hasAnchor(QSGItem *item, const QString &name); + static QSGItem *anchorFillTargetItem(QSGItem *item); + static QSGItem *anchorCenterInTargetItem(QSGItem *item); + static QPair anchorLineTarget(QSGItem *item, const QString &name, QDeclarativeContext *context); + static void resetAnchor(QSGItem *item, const QString &name); + + + static QList statesForItem(QSGItem *item); + + static bool isComponentComplete(QSGItem *item); + + static int borderWidth(QSGItem *item); + + static void refreshExpressions(QDeclarativeContext *context); + + static void setRootItem(QSGView *view, QSGItem *item); + + static bool isValidWidth(QSGItem *item); + static bool isValidHeight(QSGItem *item); + + static void updateDirtyNode(QSGItem *item); + +private: + QHash m_itemTextureHash; +}; + +QT_END_NAMESPACE + +#endif // DESIGNERSUPPORT_H -- cgit v1.2.3 From 0f56ed1162ac8d5256692766edb47c49ea283e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 31 Aug 2011 13:50:21 +0200 Subject: Fix build with Clang We have to qualify calls to baseclass functions in templates. See: http://clang.llvm.org/compatibility.html#dep_lookup_bases Change-Id: If779f1789d269f20a0255d63b1a7d6b9fef0118e Reviewed-on: http://codereview.qt.nokia.com/3961 Reviewed-by: Kent Hansen Reviewed-by: Qt Sanity Bot --- src/declarative/qml/qdeclarativevme.cpp | 2 +- src/declarative/qml/v8/qscripttools_p.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index bf290869b4..0e04f2b43a 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -1128,7 +1128,7 @@ void QDeclarativeVMEStack::push(const T &o) { Q_ASSERT(_index <= VLA::size()); if (_index == VLA::size()) - append(o); + this->append(o); else VLA::data()[_index] = o; } diff --git a/src/declarative/qml/v8/qscripttools_p.h b/src/declarative/qml/v8/qscripttools_p.h index c8dace0b9f..a718691556 100644 --- a/src/declarative/qml/v8/qscripttools_p.h +++ b/src/declarative/qml/v8/qscripttools_p.h @@ -51,7 +51,7 @@ public: template void QScriptIntrusiveList::insert(N *n) { - Q_ASSERT_X(!contains(n), Q_FUNC_INFO, "Can't insert a value which is in the list already"); + Q_ASSERT_X(!this->contains(n), Q_FUNC_INFO, "Can't insert a value which is in the list already"); Q_ASSERT_X(!(n->*member).isInList(), Q_FUNC_INFO, "Can't insert a value which is in another list"); QIntrusiveList::insert(n); } @@ -59,7 +59,7 @@ void QScriptIntrusiveList::insert(N *n) template void QScriptIntrusiveList::remove(N *n) { - Q_ASSERT_X(contains(n), Q_FUNC_INFO, "Can't remove a value which is not in the list"); + Q_ASSERT_X(this->contains(n), Q_FUNC_INFO, "Can't remove a value which is not in the list"); QIntrusiveList::remove(n); } -- cgit v1.2.3 From 8804ec49bda8672c5700ab843f2958c3d2bd8e41 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 30 Aug 2011 17:21:30 +0200 Subject: Rename QDeclarativeEngineDebugServer to ~Service And fix the file names/location, too Change-Id: If2d5ec0896332896ad11af748ec8f75c39e1555c Reviewed-on: http://codereview.qt.nokia.com/3890 Reviewed-by: Qt Sanity Bot Reviewed-by: Kai Koehne --- src/declarative/debugger/debugger.pri | 6 +- src/declarative/debugger/qdeclarativedebug.cpp | 16 +- .../debugger/qdeclarativeenginedebugservice.cpp | 747 +++++++++++++++++++++ .../debugger/qdeclarativeenginedebugservice_p.h | 134 ++++ src/declarative/qml/qdeclarativecomponent.cpp | 4 +- src/declarative/qml/qdeclarativeengine.cpp | 8 +- src/declarative/qml/qdeclarativeenginedebug.cpp | 747 --------------------- src/declarative/qml/qdeclarativeenginedebug_p.h | 134 ---- src/declarative/qml/qml.pri | 2 - 9 files changed, 899 insertions(+), 899 deletions(-) create mode 100644 src/declarative/debugger/qdeclarativeenginedebugservice.cpp create mode 100644 src/declarative/debugger/qdeclarativeenginedebugservice_p.h delete mode 100644 src/declarative/qml/qdeclarativeenginedebug.cpp delete mode 100644 src/declarative/qml/qdeclarativeenginedebug_p.h (limited to 'src') diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index e7462d4e78..8124774761 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -10,7 +10,8 @@ SOURCES += \ $$PWD/qdeclarativedebughelper.cpp \ $$PWD/qdeclarativedebugserver.cpp \ $$PWD/qdeclarativeinspectorservice.cpp \ - $$PWD/qv8debugservice.cpp + $$PWD/qv8debugservice.cpp \ + $$PWD/qdeclarativeenginedebugservice.cpp HEADERS += \ $$PWD/qdeclarativedebuggerstatus_p.h \ @@ -25,4 +26,5 @@ HEADERS += \ $$PWD/qdeclarativedebugserverconnection_p.h \ $$PWD/qdeclarativeinspectorservice_p.h \ $$PWD/qdeclarativeinspectorinterface_p.h \ - $$PWD/qv8debugservice_p.h + $$PWD/qv8debugservice_p.h \ + $$PWD/qdeclarativeenginedebugservice_p.h diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp index 620ee1d66a..17bd5534ab 100644 --- a/src/declarative/debugger/qdeclarativedebug.cpp +++ b/src/declarative/debugger/qdeclarativedebug.cpp @@ -43,7 +43,7 @@ #include "private/qdeclarativedebugclient_p.h" -#include +#include #include @@ -207,7 +207,7 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclara void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o, bool simple) { - QDeclarativeEngineDebugServer::QDeclarativeObjectData data; + QDeclarativeEngineDebugService::QDeclarativeObjectData data; ds >> data; o.m_debugId = data.objectId; o.m_class = data.objectType; @@ -234,7 +234,7 @@ void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugOb ds >> propCount; for (int ii = 0; ii < propCount; ++ii) { - QDeclarativeEngineDebugServer::QDeclarativeObjectProperty data; + QDeclarativeEngineDebugService::QDeclarativeObjectProperty data; ds >> data; QDeclarativeDebugPropertyReference prop; prop.m_objectDebugId = o.m_debugId; @@ -243,21 +243,21 @@ void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugOb prop.m_hasNotifySignal = data.hasNotifySignal; prop.m_valueTypeName = data.valueTypeName; switch (data.type) { - case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::Basic: - case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::List: - case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::SignalProperty: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Basic: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::List: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::SignalProperty: { prop.m_value = data.value; break; } - case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::Object: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Object: { QDeclarativeDebugObjectReference obj; obj.m_debugId = prop.m_value.toInt(); prop.m_value = QVariant::fromValue(obj); break; } - case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::Unknown: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Unknown: break; } o.m_properties << prop; diff --git a/src/declarative/debugger/qdeclarativeenginedebugservice.cpp b/src/declarative/debugger/qdeclarativeenginedebugservice.cpp new file mode 100644 index 0000000000..2e5683c753 --- /dev/null +++ b/src/declarative/debugger/qdeclarativeenginedebugservice.cpp @@ -0,0 +1,747 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** 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. +** +** 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. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qdeclarativeenginedebugservice_p.h" + +#include "private/qdeclarativeboundsignal_p.h" +#include "qdeclarativeengine.h" +#include "private/qdeclarativemetatype_p.h" +#include "qdeclarativeproperty.h" +#include "private/qdeclarativeproperty_p.h" +#include "private/qdeclarativebinding_p.h" +#include "private/qdeclarativecontext_p.h" +#include "private/qdeclarativewatcher_p.h" +#include "private/qdeclarativevaluetype_p.h" +#include "private/qdeclarativevmemetaobject_p.h" +#include "private/qdeclarativeexpression_p.h" +#include "private/qdeclarativepropertychanges_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QDeclarativeEngineDebugService, qmlEngineDebugService); + +QDeclarativeEngineDebugService *QDeclarativeEngineDebugService::instance() +{ + return qmlEngineDebugService(); +} + +QDeclarativeEngineDebugService::QDeclarativeEngineDebugService(QObject *parent) +: QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), + m_watch(new QDeclarativeWatcher(this)) +{ + QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)), + this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant))); +} + +QDataStream &operator<<(QDataStream &ds, + const QDeclarativeEngineDebugService::QDeclarativeObjectData &data) +{ + ds << data.url << data.lineNumber << data.columnNumber << data.idString + << data.objectName << data.objectType << data.objectId << data.contextId; + return ds; +} + +QDataStream &operator>>(QDataStream &ds, + QDeclarativeEngineDebugService::QDeclarativeObjectData &data) +{ + ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString + >> data.objectName >> data.objectType >> data.objectId >> data.contextId; + return ds; +} + +QDataStream &operator<<(QDataStream &ds, + const QDeclarativeEngineDebugService::QDeclarativeObjectProperty &data) +{ + ds << (int)data.type << data.name << data.value << data.valueTypeName + << data.binding << data.hasNotifySignal; + return ds; +} + +QDataStream &operator>>(QDataStream &ds, + QDeclarativeEngineDebugService::QDeclarativeObjectProperty &data) +{ + int type; + ds >> type >> data.name >> data.value >> data.valueTypeName + >> data.binding >> data.hasNotifySignal; + data.type = (QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Type)type; + return ds; +} + +static inline bool isSignalPropertyName(const QString &signalName) +{ + // see QmlCompiler::isSignalPropertyName + return signalName.length() >= 3 && signalName.startsWith(QLatin1String("on")) && + signalName.at(2).isLetter() && signalName.at(2).isUpper(); +} + +static bool hasValidSignal(QObject *object, const QString &propertyName) +{ + if (!isSignalPropertyName(propertyName)) + return false; + + QString signalName = propertyName.mid(2); + signalName[0] = signalName.at(0).toLower(); + + int sigIdx = QDeclarativePropertyPrivate::findSignalByName(object->metaObject(), signalName.toLatin1()).methodIndex(); + + if (sigIdx == -1) + return false; + + return true; +} + +QDeclarativeEngineDebugService::QDeclarativeObjectProperty +QDeclarativeEngineDebugService::propertyData(QObject *obj, int propIdx) +{ + QDeclarativeObjectProperty rv; + + QMetaProperty prop = obj->metaObject()->property(propIdx); + + rv.type = QDeclarativeObjectProperty::Unknown; + rv.valueTypeName = QString::fromUtf8(prop.typeName()); + rv.name = QString::fromUtf8(prop.name()); + rv.hasNotifySignal = prop.hasNotifySignal(); + QDeclarativeAbstractBinding *binding = + QDeclarativePropertyPrivate::binding(QDeclarativeProperty(obj, rv.name)); + if (binding) + rv.binding = binding->expression(); + + if (QDeclarativeValueTypeFactory::isValueType(prop.userType())) { + rv.type = QDeclarativeObjectProperty::Basic; + } else if (QDeclarativeMetaType::isQObject(prop.userType())) { + rv.type = QDeclarativeObjectProperty::Object; + } else if (QDeclarativeMetaType::isList(prop.userType())) { + rv.type = QDeclarativeObjectProperty::List; + } + + QVariant value; + if (rv.type != QDeclarativeObjectProperty::Unknown && prop.userType() != 0) { + value = prop.read(obj); + } + rv.value = valueContents(value); + + return rv; +} + +QVariant QDeclarativeEngineDebugService::valueContents(const QVariant &value) const +{ + int userType = value.userType(); + + if (value.type() == QVariant::List) { + QVariantList contents; + QVariantList list = value.toList(); + int count = list.size(); + for (int i = 0; i < count; i++) + contents << valueContents(list.at(i)); + return contents; + } + + if (QDeclarativeValueTypeFactory::isValueType(userType)) + return value; + + if (QDeclarativeMetaType::isQObject(userType)) { + QObject *o = QDeclarativeMetaType::toQObject(value); + if (o) { + QString name = o->objectName(); + if (name.isEmpty()) + name = QLatin1String(""); + return name; + } + } + + return QLatin1String(""); +} + +void QDeclarativeEngineDebugService::buildObjectDump(QDataStream &message, + QObject *object, bool recur, bool dumpProperties) +{ + message << objectData(object); + + QObjectList children = object->children(); + + int childrenCount = children.count(); + for (int ii = 0; ii < children.count(); ++ii) { + if (qobject_cast(children[ii]) || QDeclarativeBoundSignal::cast(children[ii])) + --childrenCount; + } + + message << childrenCount << recur; + + QList fakeProperties; + + for (int ii = 0; ii < children.count(); ++ii) { + QObject *child = children.at(ii); + if (qobject_cast(child)) + continue; + QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); + if (signal) { + if (!dumpProperties) + continue; + QDeclarativeObjectProperty prop; + prop.type = QDeclarativeObjectProperty::SignalProperty; + prop.hasNotifySignal = false; + QDeclarativeExpression *expr = signal->expression(); + if (expr) { + prop.value = expr->expression(); + QObject *scope = expr->scopeObject(); + if (scope) { + QString sig = QLatin1String(scope->metaObject()->method(signal->index()).signature()); + int lparen = sig.indexOf(QLatin1Char('(')); + if (lparen >= 0) { + QString methodName = sig.mid(0, lparen); + prop.name = QLatin1String("on") + methodName[0].toUpper() + + methodName.mid(1); + } + } + } + fakeProperties << prop; + } else { + if (recur) + buildObjectDump(message, child, recur, dumpProperties); + else + message << objectData(child); + } + } + + if (!dumpProperties) { + message << 0; + return; + } + + QList propertyIndexes; + for (int ii = 0; ii < object->metaObject()->propertyCount(); ++ii) { + if (object->metaObject()->property(ii).isScriptable()) + propertyIndexes << ii; + } + + message << propertyIndexes.size() + fakeProperties.count(); + + for (int ii = 0; ii < propertyIndexes.size(); ++ii) + message << propertyData(object, propertyIndexes.at(ii)); + + for (int ii = 0; ii < fakeProperties.count(); ++ii) + message << fakeProperties[ii]; +} + +void QDeclarativeEngineDebugService::prepareDeferredObjects(QObject *obj) +{ + qmlExecuteDeferred(obj); + + QObjectList children = obj->children(); + for (int ii = 0; ii < children.count(); ++ii) { + QObject *child = children.at(ii); + prepareDeferredObjects(child); + } + +} + +void QDeclarativeEngineDebugService::buildObjectList(QDataStream &message, QDeclarativeContext *ctxt) +{ + QDeclarativeContextData *p = QDeclarativeContextData::get(ctxt); + + QString ctxtName = ctxt->objectName(); + int ctxtId = QDeclarativeDebugService::idForObject(ctxt); + + message << ctxtName << ctxtId; + + int count = 0; + + QDeclarativeContextData *child = p->childContexts; + while (child) { + ++count; + child = child->nextChild; + } + + message << count; + + child = p->childContexts; + while (child) { + buildObjectList(message, child->asQDeclarativeContext()); + child = child->nextChild; + } + + // Clean deleted objects + QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(ctxt); + for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) { + if (!ctxtPriv->instances.at(ii)) { + ctxtPriv->instances.removeAt(ii); + --ii; + } + } + + message << ctxtPriv->instances.count(); + for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) { + message << objectData(ctxtPriv->instances.at(ii)); + } +} + +void QDeclarativeEngineDebugService::buildStatesList(QDeclarativeContext *ctxt, bool cleanList=false) +{ + if (cleanList) + m_allStates.clear(); + + QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(ctxt); + for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) { + buildStatesList(ctxtPriv->instances.at(ii)); + } + + QDeclarativeContextData *child = QDeclarativeContextData::get(ctxt)->childContexts; + while (child) { + buildStatesList(child->asQDeclarativeContext()); + child = child->nextChild; + } +} + +void QDeclarativeEngineDebugService::buildStatesList(QObject *obj) +{ + if (QDeclarativeState *state = qobject_cast(obj)) { + m_allStates.append(state); + } + + QObjectList children = obj->children(); + for (int ii = 0; ii < children.count(); ++ii) { + buildStatesList(children.at(ii)); + } +} + +QDeclarativeEngineDebugService::QDeclarativeObjectData +QDeclarativeEngineDebugService::objectData(QObject *object) +{ + QDeclarativeData *ddata = QDeclarativeData::get(object); + QDeclarativeObjectData rv; + if (ddata && ddata->outerContext) { + rv.url = ddata->outerContext->url; + rv.lineNumber = ddata->lineNumber; + rv.columnNumber = ddata->columnNumber; + } else { + rv.lineNumber = -1; + rv.columnNumber = -1; + } + + QDeclarativeContext *context = qmlContext(object); + if (context) { + QDeclarativeContextData *cdata = QDeclarativeContextData::get(context); + if (cdata) + rv.idString = cdata->findObjectId(object); + } + + rv.objectName = object->objectName(); + rv.objectId = QDeclarativeDebugService::idForObject(object); + rv.contextId = QDeclarativeDebugService::idForObject(qmlContext(object)); + + QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject()); + if (type) { + QString typeName = QLatin1String(type->qmlTypeName()); + int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); + rv.objectType = lastSlash < 0 ? typeName : typeName.mid(lastSlash+1); + } else { + rv.objectType = QString::fromUtf8(object->metaObject()->className()); + int marker = rv.objectType.indexOf(QLatin1String("_QMLTYPE_")); + if (marker != -1) + rv.objectType = rv.objectType.left(marker); + } + + return rv; +} + +void QDeclarativeEngineDebugService::messageReceived(const QByteArray &message) +{ + QDataStream ds(message); + + QByteArray type; + ds >> type; + + if (type == "LIST_ENGINES") { + int queryId; + ds >> queryId; + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("LIST_ENGINES_R"); + rs << queryId << m_engines.count(); + + for (int ii = 0; ii < m_engines.count(); ++ii) { + QDeclarativeEngine *engine = m_engines.at(ii); + + QString engineName = engine->objectName(); + int engineId = QDeclarativeDebugService::idForObject(engine); + + rs << engineName << engineId; + } + + sendMessage(reply); + } else if (type == "LIST_OBJECTS") { + int queryId; + int engineId = -1; + ds >> queryId >> engineId; + + QDeclarativeEngine *engine = + qobject_cast(QDeclarativeDebugService::objectForId(engineId)); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("LIST_OBJECTS_R") << queryId; + + if (engine) { + buildObjectList(rs, engine->rootContext()); + buildStatesList(engine->rootContext(), true); + } + + sendMessage(reply); + } else if (type == "FETCH_OBJECT") { + int queryId; + int objectId; + bool recurse; + bool dumpProperties = true; + + ds >> queryId >> objectId >> recurse >> dumpProperties; + + QObject *object = QDeclarativeDebugService::objectForId(objectId); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("FETCH_OBJECT_R") << queryId; + + if (object) { + if (recurse) + prepareDeferredObjects(object); + buildObjectDump(rs, object, recurse, dumpProperties); + } + + sendMessage(reply); + } else if (type == "WATCH_OBJECT") { + int queryId; + int objectId; + + ds >> queryId >> objectId; + bool ok = m_watch->addWatch(queryId, objectId); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("WATCH_OBJECT_R") << queryId << ok; + + sendMessage(reply); + } else if (type == "WATCH_PROPERTY") { + int queryId; + int objectId; + QByteArray property; + + ds >> queryId >> objectId >> property; + bool ok = m_watch->addWatch(queryId, objectId, property); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("WATCH_PROPERTY_R") << queryId << ok; + + sendMessage(reply); + } else if (type == "WATCH_EXPR_OBJECT") { + int queryId; + int debugId; + QString expr; + + ds >> queryId >> debugId >> expr; + bool ok = m_watch->addWatch(queryId, debugId, expr); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("WATCH_EXPR_OBJECT_R") << queryId << ok; + sendMessage(reply); + } else if (type == "NO_WATCH") { + int queryId; + + ds >> queryId; + m_watch->removeWatch(queryId); + } else if (type == "EVAL_EXPRESSION") { + int queryId; + int objectId; + QString expr; + + ds >> queryId >> objectId >> expr; + + QObject *object = QDeclarativeDebugService::objectForId(objectId); + QDeclarativeContext *context = qmlContext(object); + QVariant result; + if (object && context) { + QDeclarativeExpression exprObj(context, object, expr); + bool undefined = false; + QVariant value = exprObj.evaluate(&undefined); + if (undefined) + result = QLatin1String(""); + else + result = valueContents(value); + } else { + result = QLatin1String(""); + } + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("EVAL_EXPRESSION_R") << queryId << result; + + sendMessage(reply); + } else if (type == "SET_BINDING") { + int objectId; + QString propertyName; + QVariant expr; + bool isLiteralValue; + QString filename; + int line; + ds >> objectId >> propertyName >> expr >> isLiteralValue; + if (!ds.atEnd()) { // backward compatibility from 2.1, 2.2 + ds >> filename >> line; + } + setBinding(objectId, propertyName, expr, isLiteralValue, filename, line); + } else if (type == "RESET_BINDING") { + int objectId; + QString propertyName; + ds >> objectId >> propertyName; + resetBinding(objectId, propertyName); + } else if (type == "SET_METHOD_BODY") { + int objectId; + QString methodName; + QString methodBody; + ds >> objectId >> methodName >> methodBody; + setMethodBody(objectId, methodName, methodBody); + } +} + +void QDeclarativeEngineDebugService::setBinding(int objectId, + const QString &propertyName, + const QVariant &expression, + bool isLiteralValue, + QString filename, + int line) +{ + QObject *object = objectForId(objectId); + QDeclarativeContext *context = qmlContext(object); + + if (object && context) { + QDeclarativeProperty property(object, propertyName, context); + if (property.isValid()) { + + bool inBaseState = true; + + foreach(QWeakPointer statePointer, m_allStates) { + if (QDeclarativeState *state = statePointer.data()) { + // here we assume that the revert list on itself defines the base state + if (state->isStateActive() && state->containsPropertyInRevertList(object, propertyName)) { + inBaseState = false; + + QDeclarativeBinding *newBinding = 0; + if (!isLiteralValue) { + newBinding = new QDeclarativeBinding(expression.toString(), object, context); + newBinding->setTarget(property); + newBinding->setNotifyOnValueChanged(true); + newBinding->setSourceLocation(filename, line); + } + + state->changeBindingInRevertList(object, propertyName, newBinding); + + if (isLiteralValue) + state->changeValueInRevertList(object, propertyName, expression); + } + } + } + + if (inBaseState) { + if (isLiteralValue) { + property.write(expression); + } else if (hasValidSignal(object, propertyName)) { + QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); + QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); + declarativeExpression->setSourceLocation(filename, line); + } else if (property.isProperty()) { + QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); + binding->setTarget(property); + binding->setSourceLocation(filename, line); + binding->setNotifyOnValueChanged(true); + QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); + if (oldBinding) + oldBinding->destroy(); + binding->update(); + } else { + qWarning() << "QDeclarativeEngineDebugService::setBinding: unable to set property" << propertyName << "on object" << object; + } + } + + } else { + // not a valid property + if (QDeclarativePropertyChanges *propertyChanges = qobject_cast(object)) { + if (isLiteralValue) { + propertyChanges->changeValue(propertyName, expression); + } else { + propertyChanges->changeExpression(propertyName, expression.toString()); + } + } else { + qWarning() << "QDeclarativeEngineDebugService::setBinding: unable to set property" << propertyName << "on object" << object; + } + } + } +} + +void QDeclarativeEngineDebugService::resetBinding(int objectId, const QString &propertyName) +{ + QObject *object = objectForId(objectId); + QDeclarativeContext *context = qmlContext(object); + + if (object && context) { + if (object->property(propertyName.toLatin1()).isValid()) { + QDeclarativeProperty property(object, propertyName); + QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::binding(property); + if (oldBinding) { + QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, 0); + if (oldBinding) + oldBinding->destroy(); + } + if (property.isResettable()) { + // Note: this will reset the property in any case, without regard to states + // Right now almost no QDeclarativeItem has reset methods for its properties (with the + // notable exception of QDeclarativeAnchors), so this is not a big issue + // later on, setBinding does take states into account + property.reset(); + } else { + // overwrite with default value + if (QDeclarativeType *objType = QDeclarativeMetaType::qmlType(object->metaObject())) { + if (QObject *emptyObject = objType->create()) { + if (emptyObject->property(propertyName.toLatin1()).isValid()) { + QVariant defaultValue = QDeclarativeProperty(emptyObject, propertyName).read(); + if (defaultValue.isValid()) { + setBinding(objectId, propertyName, defaultValue, true); + } + } + delete emptyObject; + } + } + } + } else if (hasValidSignal(object, propertyName)) { + QDeclarativeProperty property(object, propertyName, context); + QDeclarativePropertyPrivate::setSignalExpression(property, 0); + } else { + if (QDeclarativePropertyChanges *propertyChanges = qobject_cast(object)) { + propertyChanges->removeProperty(propertyName); + } + } + } +} + +void QDeclarativeEngineDebugService::setMethodBody(int objectId, const QString &method, const QString &body) +{ + QObject *object = objectForId(objectId); + QDeclarativeContext *context = qmlContext(object); + if (!object || !context || !context->engine()) + return; + QDeclarativeContextData *contextData = QDeclarativeContextData::get(context); + if (!contextData) + return; + + QDeclarativePropertyCache::Data dummy; + QDeclarativePropertyCache::Data *prop = + QDeclarativePropertyCache::property(context->engine(), object, method, dummy); + + if (!prop || !prop->isVMEFunction()) + return; + + QMetaMethod metaMethod = object->metaObject()->method(prop->coreIndex); + QList paramNames = metaMethod.parameterNames(); + + QString paramStr; + for (int ii = 0; ii < paramNames.count(); ++ii) { + if (ii != 0) paramStr.append(QLatin1String(",")); + paramStr.append(QString::fromUtf8(paramNames.at(ii))); + } + + QString jsfunction = QLatin1String("(function ") + method + QLatin1String("(") + paramStr + + QLatin1String(") {"); + jsfunction += body; + jsfunction += QLatin1String("\n})"); + + QDeclarativeVMEMetaObject *vmeMetaObject = + static_cast(QObjectPrivate::get(object)->metaObject); + Q_ASSERT(vmeMetaObject); // the fact we found the property above should guarentee this + + int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex); + vmeMetaObject->setVmeMethod(prop->coreIndex, QDeclarativeExpressionPrivate::evalFunction(contextData, object, jsfunction, contextData->url.toString(), lineNumber)); +} + +void QDeclarativeEngineDebugService::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value) +{ + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + + rs << QByteArray("UPDATE_WATCH") << id << objectId << QByteArray(property.name()) << valueContents(value); + + sendMessage(reply); +} + +void QDeclarativeEngineDebugService::addEngine(QDeclarativeEngine *engine) +{ + Q_ASSERT(engine); + Q_ASSERT(!m_engines.contains(engine)); + + m_engines.append(engine); +} + +void QDeclarativeEngineDebugService::remEngine(QDeclarativeEngine *engine) +{ + Q_ASSERT(engine); + Q_ASSERT(m_engines.contains(engine)); + + m_engines.removeAll(engine); +} + +void QDeclarativeEngineDebugService::objectCreated(QDeclarativeEngine *engine, QObject *object) +{ + Q_ASSERT(engine); + Q_ASSERT(m_engines.contains(engine)); + + int engineId = QDeclarativeDebugService::idForObject(engine); + int objectId = QDeclarativeDebugService::idForObject(object); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + + rs << QByteArray("OBJECT_CREATED") << engineId << objectId; + sendMessage(reply); +} + +QT_END_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativeenginedebugservice_p.h b/src/declarative/debugger/qdeclarativeenginedebugservice_p.h new file mode 100644 index 0000000000..3674b83fe7 --- /dev/null +++ b/src/declarative/debugger/qdeclarativeenginedebugservice_p.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** 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. +** +** 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. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEENGINEDEBUGSERVICE_P_H +#define QDECLARATIVEENGINEDEBUGSERVICE_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 + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QDeclarativeEngine; +class QDeclarativeContext; +class QDeclarativeWatcher; +class QDataStream; +class QDeclarativeState; + +class QDeclarativeEngineDebugService : public QDeclarativeDebugService +{ + Q_OBJECT +public: + QDeclarativeEngineDebugService(QObject * = 0); + + struct QDeclarativeObjectData { + QUrl url; + int lineNumber; + int columnNumber; + QString idString; + QString objectName; + QString objectType; + int objectId; + int contextId; + }; + + struct QDeclarativeObjectProperty { + enum Type { Unknown, Basic, Object, List, SignalProperty }; + Type type; + QString name; + QVariant value; + QString valueTypeName; + QString binding; + bool hasNotifySignal; + }; + + void addEngine(QDeclarativeEngine *); + void remEngine(QDeclarativeEngine *); + void objectCreated(QDeclarativeEngine *, QObject *); + + static QDeclarativeEngineDebugService *instance(); + +protected: + virtual void messageReceived(const QByteArray &); + +private Q_SLOTS: + void propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value); + +private: + void prepareDeferredObjects(QObject *); + void buildObjectList(QDataStream &, QDeclarativeContext *); + void buildObjectDump(QDataStream &, QObject *, bool, bool); + void buildStatesList(QDeclarativeContext *, bool); + void buildStatesList(QObject *obj); + QDeclarativeObjectData objectData(QObject *); + QDeclarativeObjectProperty propertyData(QObject *, int); + QVariant valueContents(const QVariant &defaultValue) const; + void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue, QString filename = QString(), int line = -1); + void resetBinding(int objectId, const QString &propertyName); + void setMethodBody(int objectId, const QString &method, const QString &body); + + QList m_engines; + QDeclarativeWatcher *m_watch; + QList > m_allStates; +}; +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugService::QDeclarativeObjectData &); +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugService::QDeclarativeObjectData &); +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugService::QDeclarativeObjectProperty &); +Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugService::QDeclarativeObjectProperty &); + +QT_END_NAMESPACE + +#endif // QDECLARATIVEENGINEDEBUGSERVICE_P_H + diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 49aa6d99b6..c7bc2cdd91 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -53,7 +53,7 @@ #include "private/qdeclarativeglobal_p.h" #include "private/qdeclarativescript_p.h" #include "private/qdeclarativedebugtrace_p.h" -#include "private/qdeclarativeenginedebug_p.h" +#include "private/qdeclarativeenginedebugservice_p.h" #include "private/qv8engine_p.h" #include "private/qv8include_p.h" @@ -952,7 +952,7 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *parentCon if (enginePriv->isDebugging && rv) { if (!parentContext->isInternal) parentContext->asQDeclarativeContextPrivate()->instances.append(rv); - QDeclarativeEngineDebugServer::instance()->objectCreated(parentContext->engine, rv); + QDeclarativeEngineDebugService::instance()->objectCreated(parentContext->engine, rv); if (isRoot) { QDeclarativeDebugTrace::rangeData(QDeclarativeDebugTrace::Creating, buildTypeNameForDebug(rv->metaObject())); QDeclarativeData *data = QDeclarativeData::get(rv); diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 7e8f93e202..fa7854b456 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -50,7 +50,7 @@ #include "qdeclarativecomponent.h" #include "private/qdeclarativebinding_p_p.h" #include "private/qdeclarativevme_p.h" -#include "private/qdeclarativeenginedebug_p.h" +#include "private/qdeclarativeenginedebugservice_p.h" #include "private/qdeclarativestringconverters_p.h" #include "private/qdeclarativexmlhttprequest_p.h" #include "private/qdeclarativesqldatabase_p.h" @@ -448,9 +448,9 @@ void QDeclarativeEnginePrivate::init() rootContext = new QDeclarativeContext(q,true); if (QCoreApplication::instance()->thread() == q->thread() && - QDeclarativeEngineDebugServer::isDebuggingEnabled()) { + QDeclarativeEngineDebugService::isDebuggingEnabled()) { isDebugging = true; - QDeclarativeEngineDebugServer::instance()->addEngine(q); + QDeclarativeEngineDebugService::instance()->addEngine(q); QV8DebugService::instance()->addEngine(q); } } @@ -515,7 +515,7 @@ QDeclarativeEngine::~QDeclarativeEngine() { Q_D(QDeclarativeEngine); if (d->isDebugging) - QDeclarativeEngineDebugServer::instance()->remEngine(this); + QDeclarativeEngineDebugService::instance()->remEngine(this); // if we are the parent of any of the qobject module api instances, // we need to remove them from our internal list, in order to prevent diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp deleted file mode 100644 index 6c605cbc2b..0000000000 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ /dev/null @@ -1,747 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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. -** -** 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. -** -** 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. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "private/qdeclarativeenginedebug_p.h" - -#include "private/qdeclarativeboundsignal_p.h" -#include "qdeclarativeengine.h" -#include "private/qdeclarativemetatype_p.h" -#include "qdeclarativeproperty.h" -#include "private/qdeclarativeproperty_p.h" -#include "private/qdeclarativebinding_p.h" -#include "private/qdeclarativecontext_p.h" -#include "private/qdeclarativewatcher_p.h" -#include "private/qdeclarativevaluetype_p.h" -#include "private/qdeclarativevmemetaobject_p.h" -#include "private/qdeclarativeexpression_p.h" -#include "private/qdeclarativepropertychanges_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer); - -QDeclarativeEngineDebugServer *QDeclarativeEngineDebugServer::instance() -{ - return qmlEngineDebugServer(); -} - -QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent) -: QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), - m_watch(new QDeclarativeWatcher(this)) -{ - QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)), - this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant))); -} - -QDataStream &operator<<(QDataStream &ds, - const QDeclarativeEngineDebugServer::QDeclarativeObjectData &data) -{ - ds << data.url << data.lineNumber << data.columnNumber << data.idString - << data.objectName << data.objectType << data.objectId << data.contextId; - return ds; -} - -QDataStream &operator>>(QDataStream &ds, - QDeclarativeEngineDebugServer::QDeclarativeObjectData &data) -{ - ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString - >> data.objectName >> data.objectType >> data.objectId >> data.contextId; - return ds; -} - -QDataStream &operator<<(QDataStream &ds, - const QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &data) -{ - ds << (int)data.type << data.name << data.value << data.valueTypeName - << data.binding << data.hasNotifySignal; - return ds; -} - -QDataStream &operator>>(QDataStream &ds, - QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &data) -{ - int type; - ds >> type >> data.name >> data.value >> data.valueTypeName - >> data.binding >> data.hasNotifySignal; - data.type = (QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::Type)type; - return ds; -} - -static inline bool isSignalPropertyName(const QString &signalName) -{ - // see QmlCompiler::isSignalPropertyName - return signalName.length() >= 3 && signalName.startsWith(QLatin1String("on")) && - signalName.at(2).isLetter() && signalName.at(2).isUpper(); -} - -static bool hasValidSignal(QObject *object, const QString &propertyName) -{ - if (!isSignalPropertyName(propertyName)) - return false; - - QString signalName = propertyName.mid(2); - signalName[0] = signalName.at(0).toLower(); - - int sigIdx = QDeclarativePropertyPrivate::findSignalByName(object->metaObject(), signalName.toLatin1()).methodIndex(); - - if (sigIdx == -1) - return false; - - return true; -} - -QDeclarativeEngineDebugServer::QDeclarativeObjectProperty -QDeclarativeEngineDebugServer::propertyData(QObject *obj, int propIdx) -{ - QDeclarativeObjectProperty rv; - - QMetaProperty prop = obj->metaObject()->property(propIdx); - - rv.type = QDeclarativeObjectProperty::Unknown; - rv.valueTypeName = QString::fromUtf8(prop.typeName()); - rv.name = QString::fromUtf8(prop.name()); - rv.hasNotifySignal = prop.hasNotifySignal(); - QDeclarativeAbstractBinding *binding = - QDeclarativePropertyPrivate::binding(QDeclarativeProperty(obj, rv.name)); - if (binding) - rv.binding = binding->expression(); - - if (QDeclarativeValueTypeFactory::isValueType(prop.userType())) { - rv.type = QDeclarativeObjectProperty::Basic; - } else if (QDeclarativeMetaType::isQObject(prop.userType())) { - rv.type = QDeclarativeObjectProperty::Object; - } else if (QDeclarativeMetaType::isList(prop.userType())) { - rv.type = QDeclarativeObjectProperty::List; - } - - QVariant value; - if (rv.type != QDeclarativeObjectProperty::Unknown && prop.userType() != 0) { - value = prop.read(obj); - } - rv.value = valueContents(value); - - return rv; -} - -QVariant QDeclarativeEngineDebugServer::valueContents(const QVariant &value) const -{ - int userType = value.userType(); - - if (value.type() == QVariant::List) { - QVariantList contents; - QVariantList list = value.toList(); - int count = list.size(); - for (int i = 0; i < count; i++) - contents << valueContents(list.at(i)); - return contents; - } - - if (QDeclarativeValueTypeFactory::isValueType(userType)) - return value; - - if (QDeclarativeMetaType::isQObject(userType)) { - QObject *o = QDeclarativeMetaType::toQObject(value); - if (o) { - QString name = o->objectName(); - if (name.isEmpty()) - name = QLatin1String(""); - return name; - } - } - - return QLatin1String(""); -} - -void QDeclarativeEngineDebugServer::buildObjectDump(QDataStream &message, - QObject *object, bool recur, bool dumpProperties) -{ - message << objectData(object); - - QObjectList children = object->children(); - - int childrenCount = children.count(); - for (int ii = 0; ii < children.count(); ++ii) { - if (qobject_cast(children[ii]) || QDeclarativeBoundSignal::cast(children[ii])) - --childrenCount; - } - - message << childrenCount << recur; - - QList fakeProperties; - - for (int ii = 0; ii < children.count(); ++ii) { - QObject *child = children.at(ii); - if (qobject_cast(child)) - continue; - QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); - if (signal) { - if (!dumpProperties) - continue; - QDeclarativeObjectProperty prop; - prop.type = QDeclarativeObjectProperty::SignalProperty; - prop.hasNotifySignal = false; - QDeclarativeExpression *expr = signal->expression(); - if (expr) { - prop.value = expr->expression(); - QObject *scope = expr->scopeObject(); - if (scope) { - QString sig = QLatin1String(scope->metaObject()->method(signal->index()).signature()); - int lparen = sig.indexOf(QLatin1Char('(')); - if (lparen >= 0) { - QString methodName = sig.mid(0, lparen); - prop.name = QLatin1String("on") + methodName[0].toUpper() - + methodName.mid(1); - } - } - } - fakeProperties << prop; - } else { - if (recur) - buildObjectDump(message, child, recur, dumpProperties); - else - message << objectData(child); - } - } - - if (!dumpProperties) { - message << 0; - return; - } - - QList propertyIndexes; - for (int ii = 0; ii < object->metaObject()->propertyCount(); ++ii) { - if (object->metaObject()->property(ii).isScriptable()) - propertyIndexes << ii; - } - - message << propertyIndexes.size() + fakeProperties.count(); - - for (int ii = 0; ii < propertyIndexes.size(); ++ii) - message << propertyData(object, propertyIndexes.at(ii)); - - for (int ii = 0; ii < fakeProperties.count(); ++ii) - message << fakeProperties[ii]; -} - -void QDeclarativeEngineDebugServer::prepareDeferredObjects(QObject *obj) -{ - qmlExecuteDeferred(obj); - - QObjectList children = obj->children(); - for (int ii = 0; ii < children.count(); ++ii) { - QObject *child = children.at(ii); - prepareDeferredObjects(child); - } - -} - -void QDeclarativeEngineDebugServer::buildObjectList(QDataStream &message, QDeclarativeContext *ctxt) -{ - QDeclarativeContextData *p = QDeclarativeContextData::get(ctxt); - - QString ctxtName = ctxt->objectName(); - int ctxtId = QDeclarativeDebugService::idForObject(ctxt); - - message << ctxtName << ctxtId; - - int count = 0; - - QDeclarativeContextData *child = p->childContexts; - while (child) { - ++count; - child = child->nextChild; - } - - message << count; - - child = p->childContexts; - while (child) { - buildObjectList(message, child->asQDeclarativeContext()); - child = child->nextChild; - } - - // Clean deleted objects - QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(ctxt); - for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) { - if (!ctxtPriv->instances.at(ii)) { - ctxtPriv->instances.removeAt(ii); - --ii; - } - } - - message << ctxtPriv->instances.count(); - for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) { - message << objectData(ctxtPriv->instances.at(ii)); - } -} - -void QDeclarativeEngineDebugServer::buildStatesList(QDeclarativeContext *ctxt, bool cleanList=false) -{ - if (cleanList) - m_allStates.clear(); - - QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(ctxt); - for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) { - buildStatesList(ctxtPriv->instances.at(ii)); - } - - QDeclarativeContextData *child = QDeclarativeContextData::get(ctxt)->childContexts; - while (child) { - buildStatesList(child->asQDeclarativeContext()); - child = child->nextChild; - } -} - -void QDeclarativeEngineDebugServer::buildStatesList(QObject *obj) -{ - if (QDeclarativeState *state = qobject_cast(obj)) { - m_allStates.append(state); - } - - QObjectList children = obj->children(); - for (int ii = 0; ii < children.count(); ++ii) { - buildStatesList(children.at(ii)); - } -} - -QDeclarativeEngineDebugServer::QDeclarativeObjectData -QDeclarativeEngineDebugServer::objectData(QObject *object) -{ - QDeclarativeData *ddata = QDeclarativeData::get(object); - QDeclarativeObjectData rv; - if (ddata && ddata->outerContext) { - rv.url = ddata->outerContext->url; - rv.lineNumber = ddata->lineNumber; - rv.columnNumber = ddata->columnNumber; - } else { - rv.lineNumber = -1; - rv.columnNumber = -1; - } - - QDeclarativeContext *context = qmlContext(object); - if (context) { - QDeclarativeContextData *cdata = QDeclarativeContextData::get(context); - if (cdata) - rv.idString = cdata->findObjectId(object); - } - - rv.objectName = object->objectName(); - rv.objectId = QDeclarativeDebugService::idForObject(object); - rv.contextId = QDeclarativeDebugService::idForObject(qmlContext(object)); - - QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject()); - if (type) { - QString typeName = QLatin1String(type->qmlTypeName()); - int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); - rv.objectType = lastSlash < 0 ? typeName : typeName.mid(lastSlash+1); - } else { - rv.objectType = QString::fromUtf8(object->metaObject()->className()); - int marker = rv.objectType.indexOf(QLatin1String("_QMLTYPE_")); - if (marker != -1) - rv.objectType = rv.objectType.left(marker); - } - - return rv; -} - -void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) -{ - QDataStream ds(message); - - QByteArray type; - ds >> type; - - if (type == "LIST_ENGINES") { - int queryId; - ds >> queryId; - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("LIST_ENGINES_R"); - rs << queryId << m_engines.count(); - - for (int ii = 0; ii < m_engines.count(); ++ii) { - QDeclarativeEngine *engine = m_engines.at(ii); - - QString engineName = engine->objectName(); - int engineId = QDeclarativeDebugService::idForObject(engine); - - rs << engineName << engineId; - } - - sendMessage(reply); - } else if (type == "LIST_OBJECTS") { - int queryId; - int engineId = -1; - ds >> queryId >> engineId; - - QDeclarativeEngine *engine = - qobject_cast(QDeclarativeDebugService::objectForId(engineId)); - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("LIST_OBJECTS_R") << queryId; - - if (engine) { - buildObjectList(rs, engine->rootContext()); - buildStatesList(engine->rootContext(), true); - } - - sendMessage(reply); - } else if (type == "FETCH_OBJECT") { - int queryId; - int objectId; - bool recurse; - bool dumpProperties = true; - - ds >> queryId >> objectId >> recurse >> dumpProperties; - - QObject *object = QDeclarativeDebugService::objectForId(objectId); - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("FETCH_OBJECT_R") << queryId; - - if (object) { - if (recurse) - prepareDeferredObjects(object); - buildObjectDump(rs, object, recurse, dumpProperties); - } - - sendMessage(reply); - } else if (type == "WATCH_OBJECT") { - int queryId; - int objectId; - - ds >> queryId >> objectId; - bool ok = m_watch->addWatch(queryId, objectId); - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("WATCH_OBJECT_R") << queryId << ok; - - sendMessage(reply); - } else if (type == "WATCH_PROPERTY") { - int queryId; - int objectId; - QByteArray property; - - ds >> queryId >> objectId >> property; - bool ok = m_watch->addWatch(queryId, objectId, property); - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("WATCH_PROPERTY_R") << queryId << ok; - - sendMessage(reply); - } else if (type == "WATCH_EXPR_OBJECT") { - int queryId; - int debugId; - QString expr; - - ds >> queryId >> debugId >> expr; - bool ok = m_watch->addWatch(queryId, debugId, expr); - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("WATCH_EXPR_OBJECT_R") << queryId << ok; - sendMessage(reply); - } else if (type == "NO_WATCH") { - int queryId; - - ds >> queryId; - m_watch->removeWatch(queryId); - } else if (type == "EVAL_EXPRESSION") { - int queryId; - int objectId; - QString expr; - - ds >> queryId >> objectId >> expr; - - QObject *object = QDeclarativeDebugService::objectForId(objectId); - QDeclarativeContext *context = qmlContext(object); - QVariant result; - if (object && context) { - QDeclarativeExpression exprObj(context, object, expr); - bool undefined = false; - QVariant value = exprObj.evaluate(&undefined); - if (undefined) - result = QLatin1String(""); - else - result = valueContents(value); - } else { - result = QLatin1String(""); - } - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("EVAL_EXPRESSION_R") << queryId << result; - - sendMessage(reply); - } else if (type == "SET_BINDING") { - int objectId; - QString propertyName; - QVariant expr; - bool isLiteralValue; - QString filename; - int line; - ds >> objectId >> propertyName >> expr >> isLiteralValue; - if (!ds.atEnd()) { // backward compatibility from 2.1, 2.2 - ds >> filename >> line; - } - setBinding(objectId, propertyName, expr, isLiteralValue, filename, line); - } else if (type == "RESET_BINDING") { - int objectId; - QString propertyName; - ds >> objectId >> propertyName; - resetBinding(objectId, propertyName); - } else if (type == "SET_METHOD_BODY") { - int objectId; - QString methodName; - QString methodBody; - ds >> objectId >> methodName >> methodBody; - setMethodBody(objectId, methodName, methodBody); - } -} - -void QDeclarativeEngineDebugServer::setBinding(int objectId, - const QString &propertyName, - const QVariant &expression, - bool isLiteralValue, - QString filename, - int line) -{ - QObject *object = objectForId(objectId); - QDeclarativeContext *context = qmlContext(object); - - if (object && context) { - QDeclarativeProperty property(object, propertyName, context); - if (property.isValid()) { - - bool inBaseState = true; - - foreach(QWeakPointer statePointer, m_allStates) { - if (QDeclarativeState *state = statePointer.data()) { - // here we assume that the revert list on itself defines the base state - if (state->isStateActive() && state->containsPropertyInRevertList(object, propertyName)) { - inBaseState = false; - - QDeclarativeBinding *newBinding = 0; - if (!isLiteralValue) { - newBinding = new QDeclarativeBinding(expression.toString(), object, context); - newBinding->setTarget(property); - newBinding->setNotifyOnValueChanged(true); - newBinding->setSourceLocation(filename, line); - } - - state->changeBindingInRevertList(object, propertyName, newBinding); - - if (isLiteralValue) - state->changeValueInRevertList(object, propertyName, expression); - } - } - } - - if (inBaseState) { - if (isLiteralValue) { - property.write(expression); - } else if (hasValidSignal(object, propertyName)) { - QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); - QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); - declarativeExpression->setSourceLocation(filename, line); - } else if (property.isProperty()) { - QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); - binding->setTarget(property); - binding->setSourceLocation(filename, line); - binding->setNotifyOnValueChanged(true); - QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); - if (oldBinding) - oldBinding->destroy(); - binding->update(); - } else { - qWarning() << "QDeclarativeEngineDebugServer::setBinding: unable to set property" << propertyName << "on object" << object; - } - } - - } else { - // not a valid property - if (QDeclarativePropertyChanges *propertyChanges = qobject_cast(object)) { - if (isLiteralValue) { - propertyChanges->changeValue(propertyName, expression); - } else { - propertyChanges->changeExpression(propertyName, expression.toString()); - } - } else { - qWarning() << "QDeclarativeEngineDebugServer::setBinding: unable to set property" << propertyName << "on object" << object; - } - } - } -} - -void QDeclarativeEngineDebugServer::resetBinding(int objectId, const QString &propertyName) -{ - QObject *object = objectForId(objectId); - QDeclarativeContext *context = qmlContext(object); - - if (object && context) { - if (object->property(propertyName.toLatin1()).isValid()) { - QDeclarativeProperty property(object, propertyName); - QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::binding(property); - if (oldBinding) { - QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, 0); - if (oldBinding) - oldBinding->destroy(); - } - if (property.isResettable()) { - // Note: this will reset the property in any case, without regard to states - // Right now almost no QDeclarativeItem has reset methods for its properties (with the - // notable exception of QDeclarativeAnchors), so this is not a big issue - // later on, setBinding does take states into account - property.reset(); - } else { - // overwrite with default value - if (QDeclarativeType *objType = QDeclarativeMetaType::qmlType(object->metaObject())) { - if (QObject *emptyObject = objType->create()) { - if (emptyObject->property(propertyName.toLatin1()).isValid()) { - QVariant defaultValue = QDeclarativeProperty(emptyObject, propertyName).read(); - if (defaultValue.isValid()) { - setBinding(objectId, propertyName, defaultValue, true); - } - } - delete emptyObject; - } - } - } - } else if (hasValidSignal(object, propertyName)) { - QDeclarativeProperty property(object, propertyName, context); - QDeclarativePropertyPrivate::setSignalExpression(property, 0); - } else { - if (QDeclarativePropertyChanges *propertyChanges = qobject_cast(object)) { - propertyChanges->removeProperty(propertyName); - } - } - } -} - -void QDeclarativeEngineDebugServer::setMethodBody(int objectId, const QString &method, const QString &body) -{ - QObject *object = objectForId(objectId); - QDeclarativeContext *context = qmlContext(object); - if (!object || !context || !context->engine()) - return; - QDeclarativeContextData *contextData = QDeclarativeContextData::get(context); - if (!contextData) - return; - - QDeclarativePropertyCache::Data dummy; - QDeclarativePropertyCache::Data *prop = - QDeclarativePropertyCache::property(context->engine(), object, method, dummy); - - if (!prop || !prop->isVMEFunction()) - return; - - QMetaMethod metaMethod = object->metaObject()->method(prop->coreIndex); - QList paramNames = metaMethod.parameterNames(); - - QString paramStr; - for (int ii = 0; ii < paramNames.count(); ++ii) { - if (ii != 0) paramStr.append(QLatin1String(",")); - paramStr.append(QString::fromUtf8(paramNames.at(ii))); - } - - QString jsfunction = QLatin1String("(function ") + method + QLatin1String("(") + paramStr + - QLatin1String(") {"); - jsfunction += body; - jsfunction += QLatin1String("\n})"); - - QDeclarativeVMEMetaObject *vmeMetaObject = - static_cast(QObjectPrivate::get(object)->metaObject); - Q_ASSERT(vmeMetaObject); // the fact we found the property above should guarentee this - - int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex); - vmeMetaObject->setVmeMethod(prop->coreIndex, QDeclarativeExpressionPrivate::evalFunction(contextData, object, jsfunction, contextData->url.toString(), lineNumber)); -} - -void QDeclarativeEngineDebugServer::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value) -{ - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - - rs << QByteArray("UPDATE_WATCH") << id << objectId << QByteArray(property.name()) << valueContents(value); - - sendMessage(reply); -} - -void QDeclarativeEngineDebugServer::addEngine(QDeclarativeEngine *engine) -{ - Q_ASSERT(engine); - Q_ASSERT(!m_engines.contains(engine)); - - m_engines.append(engine); -} - -void QDeclarativeEngineDebugServer::remEngine(QDeclarativeEngine *engine) -{ - Q_ASSERT(engine); - Q_ASSERT(m_engines.contains(engine)); - - m_engines.removeAll(engine); -} - -void QDeclarativeEngineDebugServer::objectCreated(QDeclarativeEngine *engine, QObject *object) -{ - Q_ASSERT(engine); - Q_ASSERT(m_engines.contains(engine)); - - int engineId = QDeclarativeDebugService::idForObject(engine); - int objectId = QDeclarativeDebugService::idForObject(object); - - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - - rs << QByteArray("OBJECT_CREATED") << engineId << objectId; - sendMessage(reply); -} - -QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h deleted file mode 100644 index 804a043635..0000000000 --- a/src/declarative/qml/qdeclarativeenginedebug_p.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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. -** -** 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. -** -** 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. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEENGINEDEBUG_P_H -#define QDECLARATIVEENGINEDEBUG_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 - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeEngine; -class QDeclarativeContext; -class QDeclarativeWatcher; -class QDataStream; -class QDeclarativeState; - -class QDeclarativeEngineDebugServer : public QDeclarativeDebugService -{ - Q_OBJECT -public: - QDeclarativeEngineDebugServer(QObject * = 0); - - struct QDeclarativeObjectData { - QUrl url; - int lineNumber; - int columnNumber; - QString idString; - QString objectName; - QString objectType; - int objectId; - int contextId; - }; - - struct QDeclarativeObjectProperty { - enum Type { Unknown, Basic, Object, List, SignalProperty }; - Type type; - QString name; - QVariant value; - QString valueTypeName; - QString binding; - bool hasNotifySignal; - }; - - void addEngine(QDeclarativeEngine *); - void remEngine(QDeclarativeEngine *); - void objectCreated(QDeclarativeEngine *, QObject *); - - static QDeclarativeEngineDebugServer *instance(); - -protected: - virtual void messageReceived(const QByteArray &); - -private Q_SLOTS: - void propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value); - -private: - void prepareDeferredObjects(QObject *); - void buildObjectList(QDataStream &, QDeclarativeContext *); - void buildObjectDump(QDataStream &, QObject *, bool, bool); - void buildStatesList(QDeclarativeContext *, bool); - void buildStatesList(QObject *obj); - QDeclarativeObjectData objectData(QObject *); - QDeclarativeObjectProperty propertyData(QObject *, int); - QVariant valueContents(const QVariant &defaultValue) const; - void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue, QString filename = QString(), int line = -1); - void resetBinding(int objectId, const QString &propertyName); - void setMethodBody(int objectId, const QString &method, const QString &body); - - QList m_engines; - QDeclarativeWatcher *m_watch; - QList > m_allStates; -}; -Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectData &); -Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugServer::QDeclarativeObjectData &); -Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &); -Q_DECLARATIVE_PRIVATE_EXPORT QDataStream &operator>>(QDataStream &, QDeclarativeEngineDebugServer::QDeclarativeObjectProperty &); - -QT_END_NAMESPACE - -#endif // QDECLARATIVEENGINEDEBUG_P_H - diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 7ef28c0231..61e3aa3ab9 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -23,7 +23,6 @@ SOURCES += \ $$PWD/qdeclarativeinfo.cpp \ $$PWD/qdeclarativeerror.cpp \ $$PWD/qdeclarativescript.cpp \ - $$PWD/qdeclarativeenginedebug.cpp \ $$PWD/qdeclarativerewrite.cpp \ $$PWD/qdeclarativevaluetype.cpp \ $$PWD/qdeclarativefastproperties.cpp \ @@ -81,7 +80,6 @@ HEADERS += \ $$PWD/qdeclarativedata_p.h \ $$PWD/qdeclarativeerror.h \ $$PWD/qdeclarativescript_p.h \ - $$PWD/qdeclarativeenginedebug_p.h \ $$PWD/qdeclarativerewrite_p.h \ $$PWD/qdeclarativevaluetype_p.h \ $$PWD/qdeclarativefastproperties_p.h \ -- cgit v1.2.3 From a07f68eff5ac4696a551f083d186a685f7ef043d Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 31 Aug 2011 09:12:39 +0200 Subject: Debugger: Rename qdeclarativedebug* to qdeclarativeenginedebug* Change-Id: I0c289bdf555aa317dc12c5dbcff0168ebcc7bd50 Reviewed-on: http://codereview.qt.nokia.com/3935 Reviewed-by: Qt Sanity Bot Reviewed-by: Aurindam Jana --- src/declarative/debugger/debugger.pri | 4 +- src/declarative/debugger/qdeclarativedebug.cpp | 1068 -------------------- src/declarative/debugger/qdeclarativedebug_p.h | 387 ------- .../debugger/qdeclarativeenginedebug.cpp | 1068 ++++++++++++++++++++ .../debugger/qdeclarativeenginedebug_p.h | 387 +++++++ 5 files changed, 1457 insertions(+), 1457 deletions(-) delete mode 100644 src/declarative/debugger/qdeclarativedebug.cpp delete mode 100644 src/declarative/debugger/qdeclarativedebug_p.h create mode 100644 src/declarative/debugger/qdeclarativeenginedebug.cpp create mode 100644 src/declarative/debugger/qdeclarativeenginedebug_p.h (limited to 'src') diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 8124774761..f2790c4ecd 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -5,7 +5,7 @@ SOURCES += \ $$PWD/qpacketprotocol.cpp \ $$PWD/qdeclarativedebugservice.cpp \ $$PWD/qdeclarativedebugclient.cpp \ - $$PWD/qdeclarativedebug.cpp \ + $$PWD/qdeclarativeenginedebug.cpp \ $$PWD/qdeclarativedebugtrace.cpp \ $$PWD/qdeclarativedebughelper.cpp \ $$PWD/qdeclarativedebugserver.cpp \ @@ -19,7 +19,7 @@ HEADERS += \ $$PWD/qdeclarativedebugservice_p.h \ $$PWD/qdeclarativedebugservice_p_p.h \ $$PWD/qdeclarativedebugclient_p.h \ - $$PWD/qdeclarativedebug_p.h \ + $$PWD/qdeclarativeenginedebug_p.h \ $$PWD/qdeclarativedebugtrace_p.h \ $$PWD/qdeclarativedebughelper_p.h \ $$PWD/qdeclarativedebugserver_p.h \ diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp deleted file mode 100644 index 17bd5534ab..0000000000 --- a/src/declarative/debugger/qdeclarativedebug.cpp +++ /dev/null @@ -1,1068 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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. -** -** 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. -** -** 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. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "private/qdeclarativedebug_p.h" - -#include "private/qdeclarativedebugclient_p.h" - -#include - -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeEngineDebugClient : public QDeclarativeDebugClient -{ -public: - QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p); - -protected: - virtual void statusChanged(Status status); - virtual void messageReceived(const QByteArray &); - -private: - QDeclarativeEngineDebugPrivate *priv; - friend class QDeclarativeEngineDebugPrivate; -}; - -class QDeclarativeEngineDebugPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeEngineDebug) -public: - QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *); - ~QDeclarativeEngineDebugPrivate(); - - void statusChanged(QDeclarativeEngineDebug::Status status); - void message(const QByteArray &); - - QDeclarativeEngineDebugClient *client; - int nextId; - int getId(); - - void decode(QDataStream &, QDeclarativeDebugContextReference &); - void decode(QDataStream &, QDeclarativeDebugObjectReference &, bool simple); - - static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugEnginesQuery *); - static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugRootContextQuery *); - static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugObjectQuery *); - static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugExpressionQuery *); - static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugWatch *); - - QHash enginesQuery; - QHash rootContextQuery; - QHash objectQuery; - QHash expressionQuery; - - QHash watched; -}; - -QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, - QDeclarativeEngineDebugPrivate *p) -: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p) -{ -} - -void QDeclarativeEngineDebugClient::statusChanged(Status status) -{ - if (priv) - priv->statusChanged(static_cast(status)); -} - -void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data) -{ - if (priv) - priv->message(data); -} - -QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c) -: client(new QDeclarativeEngineDebugClient(c, this)), nextId(0) -{ -} - -QDeclarativeEngineDebugPrivate::~QDeclarativeEngineDebugPrivate() -{ - if (client) - client->priv = 0; - delete client; - - QHash::iterator enginesIter = enginesQuery.begin(); - for (; enginesIter != enginesQuery.end(); ++enginesIter) { - enginesIter.value()->m_client = 0; - if (enginesIter.value()->state() == QDeclarativeDebugQuery::Waiting) - enginesIter.value()->setState(QDeclarativeDebugQuery::Error); - } - - QHash::iterator rootContextIter = rootContextQuery.begin(); - for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) { - rootContextIter.value()->m_client = 0; - if (rootContextIter.value()->state() == QDeclarativeDebugQuery::Waiting) - rootContextIter.value()->setState(QDeclarativeDebugQuery::Error); - } - - QHash::iterator objectIter = objectQuery.begin(); - for (; objectIter != objectQuery.end(); ++objectIter) { - objectIter.value()->m_client = 0; - if (objectIter.value()->state() == QDeclarativeDebugQuery::Waiting) - objectIter.value()->setState(QDeclarativeDebugQuery::Error); - } - - QHash::iterator exprIter = expressionQuery.begin(); - for (; exprIter != expressionQuery.end(); ++exprIter) { - exprIter.value()->m_client = 0; - if (exprIter.value()->state() == QDeclarativeDebugQuery::Waiting) - exprIter.value()->setState(QDeclarativeDebugQuery::Error); - } - - QHash::iterator watchIter = watched.begin(); - for (; watchIter != watched.end(); ++watchIter) { - watchIter.value()->m_client = 0; - watchIter.value()->setState(QDeclarativeDebugWatch::Dead); - } -} - -int QDeclarativeEngineDebugPrivate::getId() -{ - return nextId++; -} - -void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugEnginesQuery *q) -{ - if (c && q) { - QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); - p->enginesQuery.remove(q->m_queryId); - } -} - -void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, - QDeclarativeDebugRootContextQuery *q) -{ - if (c && q) { - QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); - p->rootContextQuery.remove(q->m_queryId); - } -} - -void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q) -{ - if (c && q) { - QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); - p->objectQuery.remove(q->m_queryId); - } -} - -void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugExpressionQuery *q) -{ - if (c && q) { - QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); - p->expressionQuery.remove(q->m_queryId); - } -} - -void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugWatch *w) -{ - if (c && w) { - QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); - p->watched.remove(w->m_queryId); - } -} - -void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o, - bool simple) -{ - QDeclarativeEngineDebugService::QDeclarativeObjectData data; - ds >> data; - o.m_debugId = data.objectId; - o.m_class = data.objectType; - o.m_idString = data.idString; - o.m_name = data.objectName; - o.m_source.m_url = data.url; - o.m_source.m_lineNumber = data.lineNumber; - o.m_source.m_columnNumber = data.columnNumber; - o.m_contextDebugId = data.contextId; - - if (simple) - return; - - int childCount; - bool recur; - ds >> childCount >> recur; - - for (int ii = 0; ii < childCount; ++ii) { - o.m_children.append(QDeclarativeDebugObjectReference()); - decode(ds, o.m_children.last(), !recur); - } - - int propCount; - ds >> propCount; - - for (int ii = 0; ii < propCount; ++ii) { - QDeclarativeEngineDebugService::QDeclarativeObjectProperty data; - ds >> data; - QDeclarativeDebugPropertyReference prop; - prop.m_objectDebugId = o.m_debugId; - prop.m_name = data.name; - prop.m_binding = data.binding; - prop.m_hasNotifySignal = data.hasNotifySignal; - prop.m_valueTypeName = data.valueTypeName; - switch (data.type) { - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Basic: - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::List: - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::SignalProperty: - { - prop.m_value = data.value; - break; - } - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Object: - { - QDeclarativeDebugObjectReference obj; - obj.m_debugId = prop.m_value.toInt(); - prop.m_value = QVariant::fromValue(obj); - break; - } - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Unknown: - break; - } - o.m_properties << prop; - } -} - -void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugContextReference &c) -{ - ds >> c.m_name >> c.m_debugId; - - int contextCount; - ds >> contextCount; - - for (int ii = 0; ii < contextCount; ++ii) { - c.m_contexts.append(QDeclarativeDebugContextReference()); - decode(ds, c.m_contexts.last()); - } - - int objectCount; - ds >> objectCount; - - for (int ii = 0; ii < objectCount; ++ii) { - QDeclarativeDebugObjectReference obj; - decode(ds, obj, true); - - obj.m_contextDebugId = c.m_debugId; - c.m_objects << obj; - } -} - -void QDeclarativeEngineDebugPrivate::statusChanged(QDeclarativeEngineDebug::Status status) -{ - emit q_func()->statusChanged(status); -} - -void QDeclarativeEngineDebugPrivate::message(const QByteArray &data) -{ - QDataStream ds(data); - - QByteArray type; - ds >> type; - - //qDebug() << "QDeclarativeEngineDebugPrivate::message()" << type; - - if (type == "LIST_ENGINES_R") { - int queryId; - ds >> queryId; - - QDeclarativeDebugEnginesQuery *query = enginesQuery.value(queryId); - if (!query) - return; - enginesQuery.remove(queryId); - - int count; - ds >> count; - - for (int ii = 0; ii < count; ++ii) { - QDeclarativeDebugEngineReference ref; - ds >> ref.m_name; - ds >> ref.m_debugId; - query->m_engines << ref; - } - - query->m_client = 0; - query->setState(QDeclarativeDebugQuery::Completed); - } else if (type == "LIST_OBJECTS_R") { - int queryId; - ds >> queryId; - - QDeclarativeDebugRootContextQuery *query = rootContextQuery.value(queryId); - if (!query) - return; - rootContextQuery.remove(queryId); - - if (!ds.atEnd()) - decode(ds, query->m_context); - - query->m_client = 0; - query->setState(QDeclarativeDebugQuery::Completed); - } else if (type == "FETCH_OBJECT_R") { - int queryId; - ds >> queryId; - - QDeclarativeDebugObjectQuery *query = objectQuery.value(queryId); - if (!query) - return; - objectQuery.remove(queryId); - - if (!ds.atEnd()) - decode(ds, query->m_object, false); - - query->m_client = 0; - query->setState(QDeclarativeDebugQuery::Completed); - } else if (type == "EVAL_EXPRESSION_R") { - int queryId; - QVariant result; - ds >> queryId >> result; - - QDeclarativeDebugExpressionQuery *query = expressionQuery.value(queryId); - if (!query) - return; - expressionQuery.remove(queryId); - - query->m_result = result; - query->m_client = 0; - query->setState(QDeclarativeDebugQuery::Completed); - } else if (type == "WATCH_PROPERTY_R") { - int queryId; - bool ok; - ds >> queryId >> ok; - - QDeclarativeDebugWatch *watch = watched.value(queryId); - if (!watch) - return; - - watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive); - } else if (type == "WATCH_OBJECT_R") { - int queryId; - bool ok; - ds >> queryId >> ok; - - QDeclarativeDebugWatch *watch = watched.value(queryId); - if (!watch) - return; - - watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive); - } else if (type == "WATCH_EXPR_OBJECT_R") { - int queryId; - bool ok; - ds >> queryId >> ok; - - QDeclarativeDebugWatch *watch = watched.value(queryId); - if (!watch) - return; - - watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive); - } else if (type == "UPDATE_WATCH") { - int queryId; - int debugId; - QByteArray name; - QVariant value; - ds >> queryId >> debugId >> name >> value; - - QDeclarativeDebugWatch *watch = watched.value(queryId, 0); - if (!watch) - return; - emit watch->valueChanged(name, value); - } else if (type == "OBJECT_CREATED") { - emit q_func()->newObjects(); - } -} - -QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent) -: QObject(*(new QDeclarativeEngineDebugPrivate(client)), parent) -{ -} - -QDeclarativeEngineDebug::Status QDeclarativeEngineDebug::status() const -{ - Q_D(const QDeclarativeEngineDebug); - - return static_cast(d->client->status()); -} - -QDeclarativeDebugPropertyWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - - QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled) { - int queryId = d->getId(); - watch->m_queryId = queryId; - watch->m_client = this; - watch->m_objectDebugId = property.objectDebugId(); - watch->m_name = property.name(); - d->watched.insert(queryId, watch); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8(); - d->client->sendMessage(message); - } else { - watch->m_state = QDeclarativeDebugWatch::Dead; - } - - return watch; -} - -QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugContextReference &, const QString &, QObject *) -{ - qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented"); - return 0; -} - -QDeclarativeDebugObjectExpressionWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, const QString &expr, QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled) { - int queryId = d->getId(); - watch->m_queryId = queryId; - watch->m_client = this; - watch->m_objectDebugId = object.debugId(); - watch->m_expr = expr; - d->watched.insert(queryId, watch); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr; - d->client->sendMessage(message); - } else { - watch->m_state = QDeclarativeDebugWatch::Dead; - } - return watch; -} - -QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - - QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled) { - int queryId = d->getId(); - watch->m_queryId = queryId; - watch->m_client = this; - watch->m_objectDebugId = object.debugId(); - d->watched.insert(queryId, watch); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId(); - d->client->sendMessage(message); - } else { - watch->m_state = QDeclarativeDebugWatch::Dead; - } - - return watch; -} - -QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugFileReference &, QObject *) -{ - qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented"); - return 0; -} - -void QDeclarativeEngineDebug::removeWatch(QDeclarativeDebugWatch *watch) -{ - Q_D(QDeclarativeEngineDebug); - - if (!watch || !watch->m_client) - return; - - watch->m_client = 0; - watch->setState(QDeclarativeDebugWatch::Inactive); - - d->watched.remove(watch->queryId()); - - if (d->client && d->client->status() == QDeclarativeDebugClient::Enabled) { - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("NO_WATCH") << watch->queryId(); - d->client->sendMessage(message); - } -} - -QDeclarativeDebugEnginesQuery *QDeclarativeEngineDebug::queryAvailableEngines(QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - - QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->enginesQuery.insert(queryId, query); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("LIST_ENGINES") << queryId; - d->client->sendMessage(message); - } else { - query->m_state = QDeclarativeDebugQuery::Error; - } - - return query; -} - -QDeclarativeDebugRootContextQuery *QDeclarativeEngineDebug::queryRootContexts(const QDeclarativeDebugEngineReference &engine, QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - - QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled && engine.debugId() != -1) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->rootContextQuery.insert(queryId, query); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("LIST_OBJECTS") << queryId << engine.debugId(); - d->client->sendMessage(message); - } else { - query->m_state = QDeclarativeDebugQuery::Error; - } - - return query; -} - -QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclarativeDebugObjectReference &object, QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - - QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->objectQuery.insert(queryId, query); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() - << false << true; - d->client->sendMessage(message); - } else { - query->m_state = QDeclarativeDebugQuery::Error; - } - - return query; -} - -QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(const QDeclarativeDebugObjectReference &object, QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - - QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->objectQuery.insert(queryId, query); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() - << true << true; - d->client->sendMessage(message); - } else { - query->m_state = QDeclarativeDebugQuery::Error; - } - - return query; -} - -QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent) -{ - Q_D(QDeclarativeEngineDebug); - - QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent); - if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { - query->m_client = this; - query->m_expr = expr; - int queryId = d->getId(); - query->m_queryId = queryId; - d->expressionQuery.insert(queryId, query); - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("EVAL_EXPRESSION") << queryId << objectDebugId << expr; - d->client->sendMessage(message); - } else { - query->m_state = QDeclarativeDebugQuery::Error; - } - - return query; -} - -bool QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, const QString &propertyName, - const QVariant &bindingExpression, - bool isLiteralValue, - QString source, int line) -{ - Q_D(QDeclarativeEngineDebug); - - if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue << source << line; - d->client->sendMessage(message); - return true; - } else { - return false; - } -} - -bool QDeclarativeEngineDebug::resetBindingForObject(int objectDebugId, const QString &propertyName) -{ - Q_D(QDeclarativeEngineDebug); - - if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName; - d->client->sendMessage(message); - return true; - } else { - return false; - } -} - -bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &methodName, - const QString &methodBody) -{ - Q_D(QDeclarativeEngineDebug); - - if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody; - d->client->sendMessage(message); - return true; - } else { - return false; - } -} - -QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent) -: QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1) -{ -} - -QDeclarativeDebugWatch::~QDeclarativeDebugWatch() -{ - if (m_client && m_queryId != -1) - QDeclarativeEngineDebugPrivate::remove(m_client, this); -} - -int QDeclarativeDebugWatch::queryId() const -{ - return m_queryId; -} - -int QDeclarativeDebugWatch::objectDebugId() const -{ - return m_objectDebugId; -} - -QDeclarativeDebugWatch::State QDeclarativeDebugWatch::state() const -{ - return m_state; -} - -void QDeclarativeDebugWatch::setState(State s) -{ - if (m_state == s) - return; - m_state = s; - emit stateChanged(m_state); -} - -QDeclarativeDebugPropertyWatch::QDeclarativeDebugPropertyWatch(QObject *parent) - : QDeclarativeDebugWatch(parent) -{ -} - -QString QDeclarativeDebugPropertyWatch::name() const -{ - return m_name; -} - - -QDeclarativeDebugObjectExpressionWatch::QDeclarativeDebugObjectExpressionWatch(QObject *parent) - : QDeclarativeDebugWatch(parent) -{ -} - -QString QDeclarativeDebugObjectExpressionWatch::expression() const -{ - return m_expr; -} - - -QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent) -: QObject(parent), m_state(Waiting) -{ -} - -QDeclarativeDebugQuery::State QDeclarativeDebugQuery::state() const -{ - return m_state; -} - -bool QDeclarativeDebugQuery::isWaiting() const -{ - return m_state == Waiting; -} - -void QDeclarativeDebugQuery::setState(State s) -{ - if (m_state == s) - return; - m_state = s; - emit stateChanged(m_state); -} - -QDeclarativeDebugEnginesQuery::QDeclarativeDebugEnginesQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QDeclarativeDebugEnginesQuery::~QDeclarativeDebugEnginesQuery() -{ - if (m_client && m_queryId != -1) - QDeclarativeEngineDebugPrivate::remove(m_client, this); -} - -QList QDeclarativeDebugEnginesQuery::engines() const -{ - return m_engines; -} - -QDeclarativeDebugRootContextQuery::QDeclarativeDebugRootContextQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QDeclarativeDebugRootContextQuery::~QDeclarativeDebugRootContextQuery() -{ - if (m_client && m_queryId != -1) - QDeclarativeEngineDebugPrivate::remove(m_client, this); -} - -QDeclarativeDebugContextReference QDeclarativeDebugRootContextQuery::rootContext() const -{ - return m_context; -} - -QDeclarativeDebugObjectQuery::QDeclarativeDebugObjectQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QDeclarativeDebugObjectQuery::~QDeclarativeDebugObjectQuery() -{ - if (m_client && m_queryId != -1) - QDeclarativeEngineDebugPrivate::remove(m_client, this); -} - -QDeclarativeDebugObjectReference QDeclarativeDebugObjectQuery::object() const -{ - return m_object; -} - -QDeclarativeDebugExpressionQuery::QDeclarativeDebugExpressionQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QDeclarativeDebugExpressionQuery::~QDeclarativeDebugExpressionQuery() -{ - if (m_client && m_queryId != -1) - QDeclarativeEngineDebugPrivate::remove(m_client, this); -} - -QVariant QDeclarativeDebugExpressionQuery::expression() const -{ - return m_expr; -} - -QVariant QDeclarativeDebugExpressionQuery::result() const -{ - return m_result; -} - -QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference() -: m_debugId(-1) -{ -} - -QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(int debugId) -: m_debugId(debugId) -{ -} - -QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &o) -: m_debugId(o.m_debugId), m_name(o.m_name) -{ -} - -QDeclarativeDebugEngineReference & -QDeclarativeDebugEngineReference::operator=(const QDeclarativeDebugEngineReference &o) -{ - m_debugId = o.m_debugId; m_name = o.m_name; - return *this; -} - -int QDeclarativeDebugEngineReference::debugId() const -{ - return m_debugId; -} - -QString QDeclarativeDebugEngineReference::name() const -{ - return m_name; -} - -QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference() -: m_debugId(-1), m_contextDebugId(-1) -{ -} - -QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(int debugId) -: m_debugId(debugId), m_contextDebugId(-1) -{ -} - -QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &o) -: m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString), - m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId), - m_properties(o.m_properties), m_children(o.m_children) -{ -} - -QDeclarativeDebugObjectReference & -QDeclarativeDebugObjectReference::operator=(const QDeclarativeDebugObjectReference &o) -{ - m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString; - m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId; - m_properties = o.m_properties; m_children = o.m_children; - return *this; -} - -int QDeclarativeDebugObjectReference::debugId() const -{ - return m_debugId; -} - -QString QDeclarativeDebugObjectReference::className() const -{ - return m_class; -} - -QString QDeclarativeDebugObjectReference::idString() const -{ - return m_idString; -} - -QString QDeclarativeDebugObjectReference::name() const -{ - return m_name; -} - -QDeclarativeDebugFileReference QDeclarativeDebugObjectReference::source() const -{ - return m_source; -} - -int QDeclarativeDebugObjectReference::contextDebugId() const -{ - return m_contextDebugId; -} - -QList QDeclarativeDebugObjectReference::properties() const -{ - return m_properties; -} - -QList QDeclarativeDebugObjectReference::children() const -{ - return m_children; -} - -QDeclarativeDebugContextReference::QDeclarativeDebugContextReference() -: m_debugId(-1) -{ -} - -QDeclarativeDebugContextReference::QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &o) -: m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts) -{ -} - -QDeclarativeDebugContextReference &QDeclarativeDebugContextReference::operator=(const QDeclarativeDebugContextReference &o) -{ - m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects; - m_contexts = o.m_contexts; - return *this; -} - -int QDeclarativeDebugContextReference::debugId() const -{ - return m_debugId; -} - -QString QDeclarativeDebugContextReference::name() const -{ - return m_name; -} - -QList QDeclarativeDebugContextReference::objects() const -{ - return m_objects; -} - -QList QDeclarativeDebugContextReference::contexts() const -{ - return m_contexts; -} - -QDeclarativeDebugFileReference::QDeclarativeDebugFileReference() -: m_lineNumber(-1), m_columnNumber(-1) -{ -} - -QDeclarativeDebugFileReference::QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &o) -: m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber) -{ -} - -QDeclarativeDebugFileReference &QDeclarativeDebugFileReference::operator=(const QDeclarativeDebugFileReference &o) -{ - m_url = o.m_url; m_lineNumber = o.m_lineNumber; m_columnNumber = o.m_columnNumber; - return *this; -} - -QUrl QDeclarativeDebugFileReference::url() const -{ - return m_url; -} - -void QDeclarativeDebugFileReference::setUrl(const QUrl &u) -{ - m_url = u; -} - -int QDeclarativeDebugFileReference::lineNumber() const -{ - return m_lineNumber; -} - -void QDeclarativeDebugFileReference::setLineNumber(int l) -{ - m_lineNumber = l; -} - -int QDeclarativeDebugFileReference::columnNumber() const -{ - return m_columnNumber; -} - -void QDeclarativeDebugFileReference::setColumnNumber(int c) -{ - m_columnNumber = c; -} - -QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference() -: m_objectDebugId(-1), m_hasNotifySignal(false) -{ -} - -QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &o) -: m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value), - m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding), - m_hasNotifySignal(o.m_hasNotifySignal) -{ -} - -QDeclarativeDebugPropertyReference &QDeclarativeDebugPropertyReference::operator=(const QDeclarativeDebugPropertyReference &o) -{ - m_objectDebugId = o.m_objectDebugId; m_name = o.m_name; m_value = o.m_value; - m_valueTypeName = o.m_valueTypeName; m_binding = o.m_binding; - m_hasNotifySignal = o.m_hasNotifySignal; - return *this; -} - -int QDeclarativeDebugPropertyReference::objectDebugId() const -{ - return m_objectDebugId; -} - -QString QDeclarativeDebugPropertyReference::name() const -{ - return m_name; -} - -QString QDeclarativeDebugPropertyReference::valueTypeName() const -{ - return m_valueTypeName; -} - -QVariant QDeclarativeDebugPropertyReference::value() const -{ - return m_value; -} - -QString QDeclarativeDebugPropertyReference::binding() const -{ - return m_binding; -} - -bool QDeclarativeDebugPropertyReference::hasNotifySignal() const -{ - return m_hasNotifySignal; -} - -QT_END_NAMESPACE - diff --git a/src/declarative/debugger/qdeclarativedebug_p.h b/src/declarative/debugger/qdeclarativedebug_p.h deleted file mode 100644 index f822637eb4..0000000000 --- a/src/declarative/debugger/qdeclarativedebug_p.h +++ /dev/null @@ -1,387 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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. -** -** 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. -** -** 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. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QDECLARATIVEDEBUG_H -#define QDECLARATIVEDEBUG_H - -#include -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeDebugConnection; -class QDeclarativeDebugWatch; -class QDeclarativeDebugPropertyWatch; -class QDeclarativeDebugObjectExpressionWatch; -class QDeclarativeDebugEnginesQuery; -class QDeclarativeDebugRootContextQuery; -class QDeclarativeDebugObjectQuery; -class QDeclarativeDebugExpressionQuery; -class QDeclarativeDebugPropertyReference; -class QDeclarativeDebugContextReference; -class QDeclarativeDebugObjectReference; -class QDeclarativeDebugFileReference; -class QDeclarativeDebugEngineReference; -class QDeclarativeEngineDebugPrivate; -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeEngineDebug : public QObject -{ -Q_OBJECT -public: - enum Status { NotConnected, Unavailable, Enabled }; - - explicit QDeclarativeEngineDebug(QDeclarativeDebugConnection *, QObject * = 0); - - Status status() const; - - QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &, - QObject *parent = 0); - QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &, - QObject *parent = 0); - QDeclarativeDebugObjectExpressionWatch *addWatch(const QDeclarativeDebugObjectReference &, const QString &, - QObject *parent = 0); - QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugObjectReference &, - QObject *parent = 0); - QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugFileReference &, - QObject *parent = 0); - - void removeWatch(QDeclarativeDebugWatch *watch); - - QDeclarativeDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0); - QDeclarativeDebugRootContextQuery *queryRootContexts(const QDeclarativeDebugEngineReference &, - QObject *parent = 0); - QDeclarativeDebugObjectQuery *queryObject(const QDeclarativeDebugObjectReference &, - QObject *parent = 0); - QDeclarativeDebugObjectQuery *queryObjectRecursive(const QDeclarativeDebugObjectReference &, - QObject *parent = 0); - QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, - const QString &expr, - QObject *parent = 0); - bool setBindingForObject(int objectDebugId, const QString &propertyName, - const QVariant &bindingExpression, bool isLiteralValue, - QString source = QString(), int line = -1); - bool resetBindingForObject(int objectDebugId, const QString &propertyName); - bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody); - -Q_SIGNALS: - void newObjects(); - void statusChanged(Status status); - -private: - Q_DECLARE_PRIVATE(QDeclarativeEngineDebug) -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugWatch : public QObject -{ -Q_OBJECT -public: - enum State { Waiting, Active, Inactive, Dead }; - - QDeclarativeDebugWatch(QObject *); - ~QDeclarativeDebugWatch(); - - int queryId() const; - int objectDebugId() const; - State state() const; - -Q_SIGNALS: - void stateChanged(QDeclarativeDebugWatch::State); - //void objectChanged(int, const QDeclarativeDebugObjectReference &); - //void valueChanged(int, const QVariant &); - - // Server sends value as string if it is a user-type variant - void valueChanged(const QByteArray &name, const QVariant &value); - -private: - friend class QDeclarativeEngineDebug; - friend class QDeclarativeEngineDebugPrivate; - void setState(State); - State m_state; - int m_queryId; - QDeclarativeEngineDebug *m_client; - int m_objectDebugId; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugPropertyWatch : public QDeclarativeDebugWatch -{ - Q_OBJECT -public: - QDeclarativeDebugPropertyWatch(QObject *parent); - - QString name() const; - -private: - friend class QDeclarativeEngineDebug; - QString m_name; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectExpressionWatch : public QDeclarativeDebugWatch -{ - Q_OBJECT -public: - QDeclarativeDebugObjectExpressionWatch(QObject *parent); - - QString expression() const; - -private: - friend class QDeclarativeEngineDebug; - QString m_expr; - int m_debugId; -}; - - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugQuery : public QObject -{ -Q_OBJECT -public: - enum State { Waiting, Error, Completed }; - - State state() const; - bool isWaiting() const; - -// bool waitUntilCompleted(); - -Q_SIGNALS: - void stateChanged(QDeclarativeDebugQuery::State); - -protected: - QDeclarativeDebugQuery(QObject *); - -private: - friend class QDeclarativeEngineDebug; - friend class QDeclarativeEngineDebugPrivate; - void setState(State); - State m_state; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugFileReference -{ -public: - QDeclarativeDebugFileReference(); - QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &); - QDeclarativeDebugFileReference &operator=(const QDeclarativeDebugFileReference &); - - QUrl url() const; - void setUrl(const QUrl &); - int lineNumber() const; - void setLineNumber(int); - int columnNumber() const; - void setColumnNumber(int); - -private: - friend class QDeclarativeEngineDebugPrivate; - QUrl m_url; - int m_lineNumber; - int m_columnNumber; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugEngineReference -{ -public: - QDeclarativeDebugEngineReference(); - QDeclarativeDebugEngineReference(int); - QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &); - QDeclarativeDebugEngineReference &operator=(const QDeclarativeDebugEngineReference &); - - int debugId() const; - QString name() const; - -private: - friend class QDeclarativeEngineDebugPrivate; - int m_debugId; - QString m_name; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectReference -{ -public: - QDeclarativeDebugObjectReference(); - QDeclarativeDebugObjectReference(int); - QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &); - QDeclarativeDebugObjectReference &operator=(const QDeclarativeDebugObjectReference &); - - int debugId() const; - QString className() const; - QString idString() const; - QString name() const; - - QDeclarativeDebugFileReference source() const; - int contextDebugId() const; - - QList properties() const; - QList children() const; - -private: - friend class QDeclarativeEngineDebugPrivate; - int m_debugId; - QString m_class; - QString m_idString; - QString m_name; - QDeclarativeDebugFileReference m_source; - int m_contextDebugId; - QList m_properties; - QList m_children; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugContextReference -{ -public: - QDeclarativeDebugContextReference(); - QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &); - QDeclarativeDebugContextReference &operator=(const QDeclarativeDebugContextReference &); - - int debugId() const; - QString name() const; - - QList objects() const; - QList contexts() const; - -private: - friend class QDeclarativeEngineDebugPrivate; - int m_debugId; - QString m_name; - QList m_objects; - QList m_contexts; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugPropertyReference -{ -public: - QDeclarativeDebugPropertyReference(); - QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &); - QDeclarativeDebugPropertyReference &operator=(const QDeclarativeDebugPropertyReference &); - - int objectDebugId() const; - QString name() const; - QVariant value() const; - QString valueTypeName() const; - QString binding() const; - bool hasNotifySignal() const; - -private: - friend class QDeclarativeEngineDebugPrivate; - int m_objectDebugId; - QString m_name; - QVariant m_value; - QString m_valueTypeName; - QString m_binding; - bool m_hasNotifySignal; -}; - - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugEnginesQuery : public QDeclarativeDebugQuery -{ -Q_OBJECT -public: - virtual ~QDeclarativeDebugEnginesQuery(); - QList engines() const; -private: - friend class QDeclarativeEngineDebug; - friend class QDeclarativeEngineDebugPrivate; - QDeclarativeDebugEnginesQuery(QObject *); - QDeclarativeEngineDebug *m_client; - int m_queryId; - QList m_engines; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugRootContextQuery : public QDeclarativeDebugQuery -{ -Q_OBJECT -public: - virtual ~QDeclarativeDebugRootContextQuery(); - QDeclarativeDebugContextReference rootContext() const; -private: - friend class QDeclarativeEngineDebug; - friend class QDeclarativeEngineDebugPrivate; - QDeclarativeDebugRootContextQuery(QObject *); - QDeclarativeEngineDebug *m_client; - int m_queryId; - QDeclarativeDebugContextReference m_context; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectQuery : public QDeclarativeDebugQuery -{ -Q_OBJECT -public: - virtual ~QDeclarativeDebugObjectQuery(); - QDeclarativeDebugObjectReference object() const; -private: - friend class QDeclarativeEngineDebug; - friend class QDeclarativeEngineDebugPrivate; - QDeclarativeDebugObjectQuery(QObject *); - QDeclarativeEngineDebug *m_client; - int m_queryId; - QDeclarativeDebugObjectReference m_object; - -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugExpressionQuery : public QDeclarativeDebugQuery -{ -Q_OBJECT -public: - virtual ~QDeclarativeDebugExpressionQuery(); - QVariant expression() const; - QVariant result() const; -private: - friend class QDeclarativeEngineDebug; - friend class QDeclarativeEngineDebugPrivate; - QDeclarativeDebugExpressionQuery(QObject *); - QDeclarativeEngineDebug *m_client; - int m_queryId; - QVariant m_expr; - QVariant m_result; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QDeclarativeDebugEngineReference) -Q_DECLARE_METATYPE(QDeclarativeDebugObjectReference) -Q_DECLARE_METATYPE(QDeclarativeDebugContextReference) -Q_DECLARE_METATYPE(QDeclarativeDebugPropertyReference) - -QT_END_HEADER - -#endif // QDECLARATIVEDEBUG_H diff --git a/src/declarative/debugger/qdeclarativeenginedebug.cpp b/src/declarative/debugger/qdeclarativeenginedebug.cpp new file mode 100644 index 0000000000..85ce7108dd --- /dev/null +++ b/src/declarative/debugger/qdeclarativeenginedebug.cpp @@ -0,0 +1,1068 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** 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. +** +** 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. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qdeclarativeenginedebug_p.h" + +#include "private/qdeclarativedebugclient_p.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QDeclarativeEngineDebugClient : public QDeclarativeDebugClient +{ +public: + QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p); + +protected: + virtual void statusChanged(Status status); + virtual void messageReceived(const QByteArray &); + +private: + QDeclarativeEngineDebugPrivate *priv; + friend class QDeclarativeEngineDebugPrivate; +}; + +class QDeclarativeEngineDebugPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QDeclarativeEngineDebug) +public: + QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *); + ~QDeclarativeEngineDebugPrivate(); + + void statusChanged(QDeclarativeEngineDebug::Status status); + void message(const QByteArray &); + + QDeclarativeEngineDebugClient *client; + int nextId; + int getId(); + + void decode(QDataStream &, QDeclarativeDebugContextReference &); + void decode(QDataStream &, QDeclarativeDebugObjectReference &, bool simple); + + static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugEnginesQuery *); + static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugRootContextQuery *); + static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugObjectQuery *); + static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugExpressionQuery *); + static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugWatch *); + + QHash enginesQuery; + QHash rootContextQuery; + QHash objectQuery; + QHash expressionQuery; + + QHash watched; +}; + +QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, + QDeclarativeEngineDebugPrivate *p) +: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p) +{ +} + +void QDeclarativeEngineDebugClient::statusChanged(Status status) +{ + if (priv) + priv->statusChanged(static_cast(status)); +} + +void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data) +{ + if (priv) + priv->message(data); +} + +QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c) +: client(new QDeclarativeEngineDebugClient(c, this)), nextId(0) +{ +} + +QDeclarativeEngineDebugPrivate::~QDeclarativeEngineDebugPrivate() +{ + if (client) + client->priv = 0; + delete client; + + QHash::iterator enginesIter = enginesQuery.begin(); + for (; enginesIter != enginesQuery.end(); ++enginesIter) { + enginesIter.value()->m_client = 0; + if (enginesIter.value()->state() == QDeclarativeDebugQuery::Waiting) + enginesIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator rootContextIter = rootContextQuery.begin(); + for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) { + rootContextIter.value()->m_client = 0; + if (rootContextIter.value()->state() == QDeclarativeDebugQuery::Waiting) + rootContextIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator objectIter = objectQuery.begin(); + for (; objectIter != objectQuery.end(); ++objectIter) { + objectIter.value()->m_client = 0; + if (objectIter.value()->state() == QDeclarativeDebugQuery::Waiting) + objectIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator exprIter = expressionQuery.begin(); + for (; exprIter != expressionQuery.end(); ++exprIter) { + exprIter.value()->m_client = 0; + if (exprIter.value()->state() == QDeclarativeDebugQuery::Waiting) + exprIter.value()->setState(QDeclarativeDebugQuery::Error); + } + + QHash::iterator watchIter = watched.begin(); + for (; watchIter != watched.end(); ++watchIter) { + watchIter.value()->m_client = 0; + watchIter.value()->setState(QDeclarativeDebugWatch::Dead); + } +} + +int QDeclarativeEngineDebugPrivate::getId() +{ + return nextId++; +} + +void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugEnginesQuery *q) +{ + if (c && q) { + QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); + p->enginesQuery.remove(q->m_queryId); + } +} + +void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, + QDeclarativeDebugRootContextQuery *q) +{ + if (c && q) { + QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); + p->rootContextQuery.remove(q->m_queryId); + } +} + +void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q) +{ + if (c && q) { + QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); + p->objectQuery.remove(q->m_queryId); + } +} + +void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugExpressionQuery *q) +{ + if (c && q) { + QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); + p->expressionQuery.remove(q->m_queryId); + } +} + +void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugWatch *w) +{ + if (c && w) { + QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); + p->watched.remove(w->m_queryId); + } +} + +void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o, + bool simple) +{ + QDeclarativeEngineDebugService::QDeclarativeObjectData data; + ds >> data; + o.m_debugId = data.objectId; + o.m_class = data.objectType; + o.m_idString = data.idString; + o.m_name = data.objectName; + o.m_source.m_url = data.url; + o.m_source.m_lineNumber = data.lineNumber; + o.m_source.m_columnNumber = data.columnNumber; + o.m_contextDebugId = data.contextId; + + if (simple) + return; + + int childCount; + bool recur; + ds >> childCount >> recur; + + for (int ii = 0; ii < childCount; ++ii) { + o.m_children.append(QDeclarativeDebugObjectReference()); + decode(ds, o.m_children.last(), !recur); + } + + int propCount; + ds >> propCount; + + for (int ii = 0; ii < propCount; ++ii) { + QDeclarativeEngineDebugService::QDeclarativeObjectProperty data; + ds >> data; + QDeclarativeDebugPropertyReference prop; + prop.m_objectDebugId = o.m_debugId; + prop.m_name = data.name; + prop.m_binding = data.binding; + prop.m_hasNotifySignal = data.hasNotifySignal; + prop.m_valueTypeName = data.valueTypeName; + switch (data.type) { + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Basic: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::List: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::SignalProperty: + { + prop.m_value = data.value; + break; + } + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Object: + { + QDeclarativeDebugObjectReference obj; + obj.m_debugId = prop.m_value.toInt(); + prop.m_value = QVariant::fromValue(obj); + break; + } + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Unknown: + break; + } + o.m_properties << prop; + } +} + +void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugContextReference &c) +{ + ds >> c.m_name >> c.m_debugId; + + int contextCount; + ds >> contextCount; + + for (int ii = 0; ii < contextCount; ++ii) { + c.m_contexts.append(QDeclarativeDebugContextReference()); + decode(ds, c.m_contexts.last()); + } + + int objectCount; + ds >> objectCount; + + for (int ii = 0; ii < objectCount; ++ii) { + QDeclarativeDebugObjectReference obj; + decode(ds, obj, true); + + obj.m_contextDebugId = c.m_debugId; + c.m_objects << obj; + } +} + +void QDeclarativeEngineDebugPrivate::statusChanged(QDeclarativeEngineDebug::Status status) +{ + emit q_func()->statusChanged(status); +} + +void QDeclarativeEngineDebugPrivate::message(const QByteArray &data) +{ + QDataStream ds(data); + + QByteArray type; + ds >> type; + + //qDebug() << "QDeclarativeEngineDebugPrivate::message()" << type; + + if (type == "LIST_ENGINES_R") { + int queryId; + ds >> queryId; + + QDeclarativeDebugEnginesQuery *query = enginesQuery.value(queryId); + if (!query) + return; + enginesQuery.remove(queryId); + + int count; + ds >> count; + + for (int ii = 0; ii < count; ++ii) { + QDeclarativeDebugEngineReference ref; + ds >> ref.m_name; + ds >> ref.m_debugId; + query->m_engines << ref; + } + + query->m_client = 0; + query->setState(QDeclarativeDebugQuery::Completed); + } else if (type == "LIST_OBJECTS_R") { + int queryId; + ds >> queryId; + + QDeclarativeDebugRootContextQuery *query = rootContextQuery.value(queryId); + if (!query) + return; + rootContextQuery.remove(queryId); + + if (!ds.atEnd()) + decode(ds, query->m_context); + + query->m_client = 0; + query->setState(QDeclarativeDebugQuery::Completed); + } else if (type == "FETCH_OBJECT_R") { + int queryId; + ds >> queryId; + + QDeclarativeDebugObjectQuery *query = objectQuery.value(queryId); + if (!query) + return; + objectQuery.remove(queryId); + + if (!ds.atEnd()) + decode(ds, query->m_object, false); + + query->m_client = 0; + query->setState(QDeclarativeDebugQuery::Completed); + } else if (type == "EVAL_EXPRESSION_R") { + int queryId; + QVariant result; + ds >> queryId >> result; + + QDeclarativeDebugExpressionQuery *query = expressionQuery.value(queryId); + if (!query) + return; + expressionQuery.remove(queryId); + + query->m_result = result; + query->m_client = 0; + query->setState(QDeclarativeDebugQuery::Completed); + } else if (type == "WATCH_PROPERTY_R") { + int queryId; + bool ok; + ds >> queryId >> ok; + + QDeclarativeDebugWatch *watch = watched.value(queryId); + if (!watch) + return; + + watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive); + } else if (type == "WATCH_OBJECT_R") { + int queryId; + bool ok; + ds >> queryId >> ok; + + QDeclarativeDebugWatch *watch = watched.value(queryId); + if (!watch) + return; + + watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive); + } else if (type == "WATCH_EXPR_OBJECT_R") { + int queryId; + bool ok; + ds >> queryId >> ok; + + QDeclarativeDebugWatch *watch = watched.value(queryId); + if (!watch) + return; + + watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive); + } else if (type == "UPDATE_WATCH") { + int queryId; + int debugId; + QByteArray name; + QVariant value; + ds >> queryId >> debugId >> name >> value; + + QDeclarativeDebugWatch *watch = watched.value(queryId, 0); + if (!watch) + return; + emit watch->valueChanged(name, value); + } else if (type == "OBJECT_CREATED") { + emit q_func()->newObjects(); + } +} + +QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent) +: QObject(*(new QDeclarativeEngineDebugPrivate(client)), parent) +{ +} + +QDeclarativeEngineDebug::Status QDeclarativeEngineDebug::status() const +{ + Q_D(const QDeclarativeEngineDebug); + + return static_cast(d->client->status()); +} + +QDeclarativeDebugPropertyWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled) { + int queryId = d->getId(); + watch->m_queryId = queryId; + watch->m_client = this; + watch->m_objectDebugId = property.objectDebugId(); + watch->m_name = property.name(); + d->watched.insert(queryId, watch); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8(); + d->client->sendMessage(message); + } else { + watch->m_state = QDeclarativeDebugWatch::Dead; + } + + return watch; +} + +QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugContextReference &, const QString &, QObject *) +{ + qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented"); + return 0; +} + +QDeclarativeDebugObjectExpressionWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, const QString &expr, QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled) { + int queryId = d->getId(); + watch->m_queryId = queryId; + watch->m_client = this; + watch->m_objectDebugId = object.debugId(); + watch->m_expr = expr; + d->watched.insert(queryId, watch); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr; + d->client->sendMessage(message); + } else { + watch->m_state = QDeclarativeDebugWatch::Dead; + } + return watch; +} + +QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled) { + int queryId = d->getId(); + watch->m_queryId = queryId; + watch->m_client = this; + watch->m_objectDebugId = object.debugId(); + d->watched.insert(queryId, watch); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId(); + d->client->sendMessage(message); + } else { + watch->m_state = QDeclarativeDebugWatch::Dead; + } + + return watch; +} + +QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugFileReference &, QObject *) +{ + qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented"); + return 0; +} + +void QDeclarativeEngineDebug::removeWatch(QDeclarativeDebugWatch *watch) +{ + Q_D(QDeclarativeEngineDebug); + + if (!watch || !watch->m_client) + return; + + watch->m_client = 0; + watch->setState(QDeclarativeDebugWatch::Inactive); + + d->watched.remove(watch->queryId()); + + if (d->client && d->client->status() == QDeclarativeDebugClient::Enabled) { + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("NO_WATCH") << watch->queryId(); + d->client->sendMessage(message); + } +} + +QDeclarativeDebugEnginesQuery *QDeclarativeEngineDebug::queryAvailableEngines(QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled) { + query->m_client = this; + int queryId = d->getId(); + query->m_queryId = queryId; + d->enginesQuery.insert(queryId, query); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("LIST_ENGINES") << queryId; + d->client->sendMessage(message); + } else { + query->m_state = QDeclarativeDebugQuery::Error; + } + + return query; +} + +QDeclarativeDebugRootContextQuery *QDeclarativeEngineDebug::queryRootContexts(const QDeclarativeDebugEngineReference &engine, QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled && engine.debugId() != -1) { + query->m_client = this; + int queryId = d->getId(); + query->m_queryId = queryId; + d->rootContextQuery.insert(queryId, query); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("LIST_OBJECTS") << queryId << engine.debugId(); + d->client->sendMessage(message); + } else { + query->m_state = QDeclarativeDebugQuery::Error; + } + + return query; +} + +QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclarativeDebugObjectReference &object, QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) { + query->m_client = this; + int queryId = d->getId(); + query->m_queryId = queryId; + d->objectQuery.insert(queryId, query); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() + << false << true; + d->client->sendMessage(message); + } else { + query->m_state = QDeclarativeDebugQuery::Error; + } + + return query; +} + +QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(const QDeclarativeDebugObjectReference &object, QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) { + query->m_client = this; + int queryId = d->getId(); + query->m_queryId = queryId; + d->objectQuery.insert(queryId, query); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() + << true << true; + d->client->sendMessage(message); + } else { + query->m_state = QDeclarativeDebugQuery::Error; + } + + return query; +} + +QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent); + if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { + query->m_client = this; + query->m_expr = expr; + int queryId = d->getId(); + query->m_queryId = queryId; + d->expressionQuery.insert(queryId, query); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("EVAL_EXPRESSION") << queryId << objectDebugId << expr; + d->client->sendMessage(message); + } else { + query->m_state = QDeclarativeDebugQuery::Error; + } + + return query; +} + +bool QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue, + QString source, int line) +{ + Q_D(QDeclarativeEngineDebug); + + if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue << source << line; + d->client->sendMessage(message); + return true; + } else { + return false; + } +} + +bool QDeclarativeEngineDebug::resetBindingForObject(int objectDebugId, const QString &propertyName) +{ + Q_D(QDeclarativeEngineDebug); + + if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName; + d->client->sendMessage(message); + return true; + } else { + return false; + } +} + +bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &methodName, + const QString &methodBody) +{ + Q_D(QDeclarativeEngineDebug); + + if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) { + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody; + d->client->sendMessage(message); + return true; + } else { + return false; + } +} + +QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent) +: QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1) +{ +} + +QDeclarativeDebugWatch::~QDeclarativeDebugWatch() +{ + if (m_client && m_queryId != -1) + QDeclarativeEngineDebugPrivate::remove(m_client, this); +} + +int QDeclarativeDebugWatch::queryId() const +{ + return m_queryId; +} + +int QDeclarativeDebugWatch::objectDebugId() const +{ + return m_objectDebugId; +} + +QDeclarativeDebugWatch::State QDeclarativeDebugWatch::state() const +{ + return m_state; +} + +void QDeclarativeDebugWatch::setState(State s) +{ + if (m_state == s) + return; + m_state = s; + emit stateChanged(m_state); +} + +QDeclarativeDebugPropertyWatch::QDeclarativeDebugPropertyWatch(QObject *parent) + : QDeclarativeDebugWatch(parent) +{ +} + +QString QDeclarativeDebugPropertyWatch::name() const +{ + return m_name; +} + + +QDeclarativeDebugObjectExpressionWatch::QDeclarativeDebugObjectExpressionWatch(QObject *parent) + : QDeclarativeDebugWatch(parent) +{ +} + +QString QDeclarativeDebugObjectExpressionWatch::expression() const +{ + return m_expr; +} + + +QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent) +: QObject(parent), m_state(Waiting) +{ +} + +QDeclarativeDebugQuery::State QDeclarativeDebugQuery::state() const +{ + return m_state; +} + +bool QDeclarativeDebugQuery::isWaiting() const +{ + return m_state == Waiting; +} + +void QDeclarativeDebugQuery::setState(State s) +{ + if (m_state == s) + return; + m_state = s; + emit stateChanged(m_state); +} + +QDeclarativeDebugEnginesQuery::QDeclarativeDebugEnginesQuery(QObject *parent) +: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) +{ +} + +QDeclarativeDebugEnginesQuery::~QDeclarativeDebugEnginesQuery() +{ + if (m_client && m_queryId != -1) + QDeclarativeEngineDebugPrivate::remove(m_client, this); +} + +QList QDeclarativeDebugEnginesQuery::engines() const +{ + return m_engines; +} + +QDeclarativeDebugRootContextQuery::QDeclarativeDebugRootContextQuery(QObject *parent) +: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) +{ +} + +QDeclarativeDebugRootContextQuery::~QDeclarativeDebugRootContextQuery() +{ + if (m_client && m_queryId != -1) + QDeclarativeEngineDebugPrivate::remove(m_client, this); +} + +QDeclarativeDebugContextReference QDeclarativeDebugRootContextQuery::rootContext() const +{ + return m_context; +} + +QDeclarativeDebugObjectQuery::QDeclarativeDebugObjectQuery(QObject *parent) +: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) +{ +} + +QDeclarativeDebugObjectQuery::~QDeclarativeDebugObjectQuery() +{ + if (m_client && m_queryId != -1) + QDeclarativeEngineDebugPrivate::remove(m_client, this); +} + +QDeclarativeDebugObjectReference QDeclarativeDebugObjectQuery::object() const +{ + return m_object; +} + +QDeclarativeDebugExpressionQuery::QDeclarativeDebugExpressionQuery(QObject *parent) +: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) +{ +} + +QDeclarativeDebugExpressionQuery::~QDeclarativeDebugExpressionQuery() +{ + if (m_client && m_queryId != -1) + QDeclarativeEngineDebugPrivate::remove(m_client, this); +} + +QVariant QDeclarativeDebugExpressionQuery::expression() const +{ + return m_expr; +} + +QVariant QDeclarativeDebugExpressionQuery::result() const +{ + return m_result; +} + +QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference() +: m_debugId(-1) +{ +} + +QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(int debugId) +: m_debugId(debugId) +{ +} + +QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &o) +: m_debugId(o.m_debugId), m_name(o.m_name) +{ +} + +QDeclarativeDebugEngineReference & +QDeclarativeDebugEngineReference::operator=(const QDeclarativeDebugEngineReference &o) +{ + m_debugId = o.m_debugId; m_name = o.m_name; + return *this; +} + +int QDeclarativeDebugEngineReference::debugId() const +{ + return m_debugId; +} + +QString QDeclarativeDebugEngineReference::name() const +{ + return m_name; +} + +QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference() +: m_debugId(-1), m_contextDebugId(-1) +{ +} + +QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(int debugId) +: m_debugId(debugId), m_contextDebugId(-1) +{ +} + +QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &o) +: m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString), + m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId), + m_properties(o.m_properties), m_children(o.m_children) +{ +} + +QDeclarativeDebugObjectReference & +QDeclarativeDebugObjectReference::operator=(const QDeclarativeDebugObjectReference &o) +{ + m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString; + m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId; + m_properties = o.m_properties; m_children = o.m_children; + return *this; +} + +int QDeclarativeDebugObjectReference::debugId() const +{ + return m_debugId; +} + +QString QDeclarativeDebugObjectReference::className() const +{ + return m_class; +} + +QString QDeclarativeDebugObjectReference::idString() const +{ + return m_idString; +} + +QString QDeclarativeDebugObjectReference::name() const +{ + return m_name; +} + +QDeclarativeDebugFileReference QDeclarativeDebugObjectReference::source() const +{ + return m_source; +} + +int QDeclarativeDebugObjectReference::contextDebugId() const +{ + return m_contextDebugId; +} + +QList QDeclarativeDebugObjectReference::properties() const +{ + return m_properties; +} + +QList QDeclarativeDebugObjectReference::children() const +{ + return m_children; +} + +QDeclarativeDebugContextReference::QDeclarativeDebugContextReference() +: m_debugId(-1) +{ +} + +QDeclarativeDebugContextReference::QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &o) +: m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts) +{ +} + +QDeclarativeDebugContextReference &QDeclarativeDebugContextReference::operator=(const QDeclarativeDebugContextReference &o) +{ + m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects; + m_contexts = o.m_contexts; + return *this; +} + +int QDeclarativeDebugContextReference::debugId() const +{ + return m_debugId; +} + +QString QDeclarativeDebugContextReference::name() const +{ + return m_name; +} + +QList QDeclarativeDebugContextReference::objects() const +{ + return m_objects; +} + +QList QDeclarativeDebugContextReference::contexts() const +{ + return m_contexts; +} + +QDeclarativeDebugFileReference::QDeclarativeDebugFileReference() +: m_lineNumber(-1), m_columnNumber(-1) +{ +} + +QDeclarativeDebugFileReference::QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &o) +: m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber) +{ +} + +QDeclarativeDebugFileReference &QDeclarativeDebugFileReference::operator=(const QDeclarativeDebugFileReference &o) +{ + m_url = o.m_url; m_lineNumber = o.m_lineNumber; m_columnNumber = o.m_columnNumber; + return *this; +} + +QUrl QDeclarativeDebugFileReference::url() const +{ + return m_url; +} + +void QDeclarativeDebugFileReference::setUrl(const QUrl &u) +{ + m_url = u; +} + +int QDeclarativeDebugFileReference::lineNumber() const +{ + return m_lineNumber; +} + +void QDeclarativeDebugFileReference::setLineNumber(int l) +{ + m_lineNumber = l; +} + +int QDeclarativeDebugFileReference::columnNumber() const +{ + return m_columnNumber; +} + +void QDeclarativeDebugFileReference::setColumnNumber(int c) +{ + m_columnNumber = c; +} + +QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference() +: m_objectDebugId(-1), m_hasNotifySignal(false) +{ +} + +QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &o) +: m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value), + m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding), + m_hasNotifySignal(o.m_hasNotifySignal) +{ +} + +QDeclarativeDebugPropertyReference &QDeclarativeDebugPropertyReference::operator=(const QDeclarativeDebugPropertyReference &o) +{ + m_objectDebugId = o.m_objectDebugId; m_name = o.m_name; m_value = o.m_value; + m_valueTypeName = o.m_valueTypeName; m_binding = o.m_binding; + m_hasNotifySignal = o.m_hasNotifySignal; + return *this; +} + +int QDeclarativeDebugPropertyReference::objectDebugId() const +{ + return m_objectDebugId; +} + +QString QDeclarativeDebugPropertyReference::name() const +{ + return m_name; +} + +QString QDeclarativeDebugPropertyReference::valueTypeName() const +{ + return m_valueTypeName; +} + +QVariant QDeclarativeDebugPropertyReference::value() const +{ + return m_value; +} + +QString QDeclarativeDebugPropertyReference::binding() const +{ + return m_binding; +} + +bool QDeclarativeDebugPropertyReference::hasNotifySignal() const +{ + return m_hasNotifySignal; +} + +QT_END_NAMESPACE + diff --git a/src/declarative/debugger/qdeclarativeenginedebug_p.h b/src/declarative/debugger/qdeclarativeenginedebug_p.h new file mode 100644 index 0000000000..9b70e1c6bc --- /dev/null +++ b/src/declarative/debugger/qdeclarativeenginedebug_p.h @@ -0,0 +1,387 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** 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. +** +** 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. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QDECLARATIVEENGINEDEBUG_H +#define QDECLARATIVEENGINEDEBUG_H + +#include +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeDebugConnection; +class QDeclarativeDebugWatch; +class QDeclarativeDebugPropertyWatch; +class QDeclarativeDebugObjectExpressionWatch; +class QDeclarativeDebugEnginesQuery; +class QDeclarativeDebugRootContextQuery; +class QDeclarativeDebugObjectQuery; +class QDeclarativeDebugExpressionQuery; +class QDeclarativeDebugPropertyReference; +class QDeclarativeDebugContextReference; +class QDeclarativeDebugObjectReference; +class QDeclarativeDebugFileReference; +class QDeclarativeDebugEngineReference; +class QDeclarativeEngineDebugPrivate; +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeEngineDebug : public QObject +{ +Q_OBJECT +public: + enum Status { NotConnected, Unavailable, Enabled }; + + explicit QDeclarativeEngineDebug(QDeclarativeDebugConnection *, QObject * = 0); + + Status status() const; + + QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &, + QObject *parent = 0); + QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &, + QObject *parent = 0); + QDeclarativeDebugObjectExpressionWatch *addWatch(const QDeclarativeDebugObjectReference &, const QString &, + QObject *parent = 0); + QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugObjectReference &, + QObject *parent = 0); + QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugFileReference &, + QObject *parent = 0); + + void removeWatch(QDeclarativeDebugWatch *watch); + + QDeclarativeDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0); + QDeclarativeDebugRootContextQuery *queryRootContexts(const QDeclarativeDebugEngineReference &, + QObject *parent = 0); + QDeclarativeDebugObjectQuery *queryObject(const QDeclarativeDebugObjectReference &, + QObject *parent = 0); + QDeclarativeDebugObjectQuery *queryObjectRecursive(const QDeclarativeDebugObjectReference &, + QObject *parent = 0); + QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, + const QString &expr, + QObject *parent = 0); + bool setBindingForObject(int objectDebugId, const QString &propertyName, + const QVariant &bindingExpression, bool isLiteralValue, + QString source = QString(), int line = -1); + bool resetBindingForObject(int objectDebugId, const QString &propertyName); + bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody); + +Q_SIGNALS: + void newObjects(); + void statusChanged(Status status); + +private: + Q_DECLARE_PRIVATE(QDeclarativeEngineDebug) +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugWatch : public QObject +{ +Q_OBJECT +public: + enum State { Waiting, Active, Inactive, Dead }; + + QDeclarativeDebugWatch(QObject *); + ~QDeclarativeDebugWatch(); + + int queryId() const; + int objectDebugId() const; + State state() const; + +Q_SIGNALS: + void stateChanged(QDeclarativeDebugWatch::State); + //void objectChanged(int, const QDeclarativeDebugObjectReference &); + //void valueChanged(int, const QVariant &); + + // Server sends value as string if it is a user-type variant + void valueChanged(const QByteArray &name, const QVariant &value); + +private: + friend class QDeclarativeEngineDebug; + friend class QDeclarativeEngineDebugPrivate; + void setState(State); + State m_state; + int m_queryId; + QDeclarativeEngineDebug *m_client; + int m_objectDebugId; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugPropertyWatch : public QDeclarativeDebugWatch +{ + Q_OBJECT +public: + QDeclarativeDebugPropertyWatch(QObject *parent); + + QString name() const; + +private: + friend class QDeclarativeEngineDebug; + QString m_name; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectExpressionWatch : public QDeclarativeDebugWatch +{ + Q_OBJECT +public: + QDeclarativeDebugObjectExpressionWatch(QObject *parent); + + QString expression() const; + +private: + friend class QDeclarativeEngineDebug; + QString m_expr; + int m_debugId; +}; + + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugQuery : public QObject +{ +Q_OBJECT +public: + enum State { Waiting, Error, Completed }; + + State state() const; + bool isWaiting() const; + +// bool waitUntilCompleted(); + +Q_SIGNALS: + void stateChanged(QDeclarativeDebugQuery::State); + +protected: + QDeclarativeDebugQuery(QObject *); + +private: + friend class QDeclarativeEngineDebug; + friend class QDeclarativeEngineDebugPrivate; + void setState(State); + State m_state; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugFileReference +{ +public: + QDeclarativeDebugFileReference(); + QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &); + QDeclarativeDebugFileReference &operator=(const QDeclarativeDebugFileReference &); + + QUrl url() const; + void setUrl(const QUrl &); + int lineNumber() const; + void setLineNumber(int); + int columnNumber() const; + void setColumnNumber(int); + +private: + friend class QDeclarativeEngineDebugPrivate; + QUrl m_url; + int m_lineNumber; + int m_columnNumber; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugEngineReference +{ +public: + QDeclarativeDebugEngineReference(); + QDeclarativeDebugEngineReference(int); + QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &); + QDeclarativeDebugEngineReference &operator=(const QDeclarativeDebugEngineReference &); + + int debugId() const; + QString name() const; + +private: + friend class QDeclarativeEngineDebugPrivate; + int m_debugId; + QString m_name; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectReference +{ +public: + QDeclarativeDebugObjectReference(); + QDeclarativeDebugObjectReference(int); + QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &); + QDeclarativeDebugObjectReference &operator=(const QDeclarativeDebugObjectReference &); + + int debugId() const; + QString className() const; + QString idString() const; + QString name() const; + + QDeclarativeDebugFileReference source() const; + int contextDebugId() const; + + QList properties() const; + QList children() const; + +private: + friend class QDeclarativeEngineDebugPrivate; + int m_debugId; + QString m_class; + QString m_idString; + QString m_name; + QDeclarativeDebugFileReference m_source; + int m_contextDebugId; + QList m_properties; + QList m_children; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugContextReference +{ +public: + QDeclarativeDebugContextReference(); + QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &); + QDeclarativeDebugContextReference &operator=(const QDeclarativeDebugContextReference &); + + int debugId() const; + QString name() const; + + QList objects() const; + QList contexts() const; + +private: + friend class QDeclarativeEngineDebugPrivate; + int m_debugId; + QString m_name; + QList m_objects; + QList m_contexts; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugPropertyReference +{ +public: + QDeclarativeDebugPropertyReference(); + QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &); + QDeclarativeDebugPropertyReference &operator=(const QDeclarativeDebugPropertyReference &); + + int objectDebugId() const; + QString name() const; + QVariant value() const; + QString valueTypeName() const; + QString binding() const; + bool hasNotifySignal() const; + +private: + friend class QDeclarativeEngineDebugPrivate; + int m_objectDebugId; + QString m_name; + QVariant m_value; + QString m_valueTypeName; + QString m_binding; + bool m_hasNotifySignal; +}; + + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugEnginesQuery : public QDeclarativeDebugQuery +{ +Q_OBJECT +public: + virtual ~QDeclarativeDebugEnginesQuery(); + QList engines() const; +private: + friend class QDeclarativeEngineDebug; + friend class QDeclarativeEngineDebugPrivate; + QDeclarativeDebugEnginesQuery(QObject *); + QDeclarativeEngineDebug *m_client; + int m_queryId; + QList m_engines; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugRootContextQuery : public QDeclarativeDebugQuery +{ +Q_OBJECT +public: + virtual ~QDeclarativeDebugRootContextQuery(); + QDeclarativeDebugContextReference rootContext() const; +private: + friend class QDeclarativeEngineDebug; + friend class QDeclarativeEngineDebugPrivate; + QDeclarativeDebugRootContextQuery(QObject *); + QDeclarativeEngineDebug *m_client; + int m_queryId; + QDeclarativeDebugContextReference m_context; +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectQuery : public QDeclarativeDebugQuery +{ +Q_OBJECT +public: + virtual ~QDeclarativeDebugObjectQuery(); + QDeclarativeDebugObjectReference object() const; +private: + friend class QDeclarativeEngineDebug; + friend class QDeclarativeEngineDebugPrivate; + QDeclarativeDebugObjectQuery(QObject *); + QDeclarativeEngineDebug *m_client; + int m_queryId; + QDeclarativeDebugObjectReference m_object; + +}; + +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugExpressionQuery : public QDeclarativeDebugQuery +{ +Q_OBJECT +public: + virtual ~QDeclarativeDebugExpressionQuery(); + QVariant expression() const; + QVariant result() const; +private: + friend class QDeclarativeEngineDebug; + friend class QDeclarativeEngineDebugPrivate; + QDeclarativeDebugExpressionQuery(QObject *); + QDeclarativeEngineDebug *m_client; + int m_queryId; + QVariant m_expr; + QVariant m_result; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QDeclarativeDebugEngineReference) +Q_DECLARE_METATYPE(QDeclarativeDebugObjectReference) +Q_DECLARE_METATYPE(QDeclarativeDebugContextReference) +Q_DECLARE_METATYPE(QDeclarativeDebugPropertyReference) + +QT_END_HEADER + +#endif // QDECLARATIVEENGINEDEBUG_H -- cgit v1.2.3 From 8801dd4f173a4e7676400dd18d76d89dfe3b3791 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 31 Aug 2011 18:29:13 +0200 Subject: Add bounding rectangle for rendering images in designer support Elements can be outside the root items bounding rectange. So we compute the bounding rectangle of an item and its children on the designer side. We exclude all children which are the designer created. Change-Id: I3c4f9ca5291c8f65e3670be1fd0900edf449b46f Reviewed-on: http://codereview.qt.nokia.com/3963 Reviewed-by: Thomas Hartmann --- src/declarative/designer/designersupport.cpp | 8 +++----- src/declarative/designer/designersupport.h | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/declarative/designer/designersupport.cpp b/src/declarative/designer/designersupport.cpp index 824642a989..91186a4a2e 100644 --- a/src/declarative/designer/designersupport.cpp +++ b/src/declarative/designer/designersupport.cpp @@ -101,7 +101,7 @@ void DesignerSupport::derefFromEffectItem(QSGItem *referencedItem, bool unhide) QSGItemPrivate::get(referencedItem)->derefFromEffectItem(unhide); } -QImage DesignerSupport::renderImageForItem(QSGItem *referencedItem) +QImage DesignerSupport::renderImageForItem(QSGItem *referencedItem, const QRectF &boundingRect, const QSize &imageSize) { if (referencedItem == 0 || referencedItem->parentItem() == 0) { qDebug() << __FILE__ << __LINE__ << "Warning: Item can be rendered."; @@ -113,8 +113,8 @@ QImage DesignerSupport::renderImageForItem(QSGItem *referencedItem) Q_ASSERT(renderTexture); if (renderTexture == 0) return QImage(); - renderTexture->setRect(referencedItem->boundingRect()); - renderTexture->setSize(referencedItem->boundingRect().size().toSize()); + renderTexture->setRect(boundingRect); + renderTexture->setSize(imageSize); renderTexture->updateTexture(); QImage renderImage = renderTexture->toImage(); @@ -123,8 +123,6 @@ QImage DesignerSupport::renderImageForItem(QSGItem *referencedItem) if (renderImage.size().isEmpty()) qDebug() << __FILE__ << __LINE__ << "Warning: Image is empty."; - qDebug() << __FUNCTION__ << renderImage.size(); - return renderImage; } diff --git a/src/declarative/designer/designersupport.h b/src/declarative/designer/designersupport.h index 0165769506..5e5b38b46c 100644 --- a/src/declarative/designer/designersupport.h +++ b/src/declarative/designer/designersupport.h @@ -57,6 +57,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -108,7 +109,7 @@ public: void refFromEffectItem(QSGItem *referencedItem, bool hide = true); void derefFromEffectItem(QSGItem *referencedItem, bool unhide = true); - QImage renderImageForItem(QSGItem *referencedItem); + QImage renderImageForItem(QSGItem *referencedItem, const QRectF &boundingRect, const QSize &imageSize); static bool isDirty(QSGItem *referencedItem, DirtyType dirtyType); static void resetDirty(QSGItem *referencedItem); -- cgit v1.2.3 From 6fbc4b7e7e5aed8739ca1143e0fc1e38b8c8e17a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 29 Aug 2011 15:33:36 +1000 Subject: Batch view changes instead of applying them immediately If there are multiple changes to be applied to a view before the next repaint, collate them using QDeclarativeChangeSet and apply the changes as a group on the next layout(). (Note that changes to the current index are applied in sequence as changes are received, since changing it out of order produces different results.) Previously, any itemsInserted(), itemsRemoved() and itemsMoved() changes were immediately applied and items were repositioned immediately. In this situation if the same indexes changed multiple times between repaints, this could lead to redundant changes and bugs arising from multiple changes to the same items. Functions that will execute differently depending on whether pending view changes have been applied (e.g. count(), currentIndex(), highlight()) now call applyPendingChanges() before proceeding to ensure they are executed on a view that is up to date. Also, itemsMoved() operations that moved item/s backwards will now properly move backwards instead of being adjusted to a forward movement (which was implemented recently with e2b5681b1adab83555c7307b05f508d796a1152b) since backwards movements can be implemented more easily with the batched changes which translates moves into insert/remove actions. Change-Id: If9b39755898e8d2ed7e4bc61288206d5f1d653fd Reviewed-on: http://codereview.qt.nokia.com/3697 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- src/declarative/items/qsggridview.cpp | 375 ++++++----------------------- src/declarative/items/qsggridview_p.h | 5 - src/declarative/items/qsgitemview.cpp | 344 +++++++++++++++++++++++--- src/declarative/items/qsgitemview_p.h | 6 +- src/declarative/items/qsgitemview_p_p.h | 36 ++- src/declarative/items/qsglistview.cpp | 411 +++++++------------------------- src/declarative/items/qsglistview_p.h | 5 - 7 files changed, 517 insertions(+), 665 deletions(-) (limited to 'src') diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp index bc4954a168..f0956367c5 100644 --- a/src/declarative/items/qsggridview.cpp +++ b/src/declarative/items/qsggridview.cpp @@ -166,6 +166,9 @@ public: virtual FxViewItem *newViewItem(int index, QSGItem *item); virtual void repositionPackageItemAt(QSGItem *item, int index); + virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem); + virtual void resetFirstItemPosition(); + virtual void moveItemBy(FxViewItem *item, const QList &items, const QList &movedBackwards); virtual void createHighlight(); virtual void updateHighlight(); @@ -173,6 +176,7 @@ public: virtual void setPosition(qreal pos); virtual void layoutVisibleItems(); + bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, QList *, QList*, FxViewItem *); virtual qreal headerSize() const; virtual qreal footerSize() const; @@ -560,6 +564,24 @@ void QSGGridViewPrivate::repositionPackageItemAt(QSGItem *item, int index) } } +void QSGGridViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem) +{ + FxGridItemSG *toGridItem = static_cast(toItem); + static_cast(item)->setPosition(toGridItem->colPos(), toGridItem->rowPos()); +} + +void QSGGridViewPrivate::resetFirstItemPosition() +{ + FxGridItemSG *item = static_cast(visibleItems.first()); + item->setPosition(0, 0); +} + +void QSGGridViewPrivate::moveItemBy(FxViewItem *item, const QList &forwards, const QList &backwards) +{ + int moveCount = forwards.count() - backwards.count(); + FxGridItemSG *gridItem = static_cast(item); + gridItem->setPosition(gridItem->colPos(), gridItem->rowPos() + ((moveCount / columns) * rowSize())); +} void QSGGridViewPrivate::createHighlight() { @@ -602,6 +624,8 @@ void QSGGridViewPrivate::createHighlight() void QSGGridViewPrivate::updateHighlight() { + applyPendingChanges(); + if ((!currentItem && highlight) || (currentItem && !highlight)) createHighlight(); bool strictHighlight = haveHighlightRange && highlightRange == QSGGridView::StrictlyEnforceRange; @@ -1370,6 +1394,7 @@ void QSGGridView::setCellWidth(int cellWidth) d->cellWidth = qMax(1, cellWidth); d->updateViewport(); emit cellWidthChanged(); + d->forceLayout = true; d->layout(); } } @@ -1387,6 +1412,7 @@ void QSGGridView::setCellHeight(int cellHeight) d->cellHeight = qMax(1, cellHeight); d->updateViewport(); emit cellHeightChanged(); + d->forceLayout = true; d->layout(); } } @@ -1688,349 +1714,95 @@ void QSGGridView::moveCurrentIndexRight() } } - -void QSGGridView::itemsInserted(int modelIndex, int count) +bool QSGGridViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::Insert &change, QList *movedBackwards, QList *addedItems, FxViewItem *firstVisible) { - Q_D(QSGGridView); - if (!isComponentComplete() || !d->model || !d->model->isValid()) - return; + Q_Q(QSGGridView); + + int modelIndex = change.index; + int count = change.count; + + int index = visibleItems.count() ? mapFromModel(modelIndex) : 0; - int index = d->visibleItems.count() ? d->mapFromModel(modelIndex) : 0; if (index < 0) { - int i = d->visibleItems.count() - 1; - while (i > 0 && d->visibleItems.at(i)->index == -1) + int i = visibleItems.count() - 1; + while (i > 0 && visibleItems.at(i)->index == -1) --i; - if (d->visibleItems.at(i)->index + 1 == modelIndex) { + if (visibleItems.at(i)->index + 1 == modelIndex) { // Special case of appending an item to the model. - index = d->visibleIndex + d->visibleItems.count(); + index = visibleIndex + visibleItems.count(); } else { - if (modelIndex <= d->visibleIndex) { + if (modelIndex <= visibleIndex) { // Insert before visible items - d->visibleIndex += count; - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxViewItem *item = d->visibleItems.at(i); + visibleIndex += count; + for (int i = 0; i < visibleItems.count(); ++i) { + FxViewItem *item = visibleItems.at(i); if (item->index != -1 && item->index >= modelIndex) item->index += count; } } - if (d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) - d->currentItem->index = d->currentIndex; - emit currentIndexChanged(); - } - d->scheduleLayout(); - d->itemCount += count; - emit countChanged(); - return; + return true; } } int insertCount = count; - if (index < d->visibleIndex && d->visibleItems.count()) { - insertCount -= d->visibleIndex - index; - index = d->visibleIndex; - modelIndex = d->visibleIndex; + if (index < visibleIndex && visibleItems.count()) { + insertCount -= visibleIndex - index; + index = visibleIndex; + modelIndex = visibleIndex; } - qreal tempPos = d->isRightToLeftTopToBottom() ? -d->position()-d->size()+width()+1 : d->position(); - int to = d->buffer+tempPos+d->size()-1; + qreal tempPos = isRightToLeftTopToBottom() ? -position()-size()+q->width()+1 : position(); + int to = buffer+tempPos+size()-1; int colPos = 0; int rowPos = 0; - if (d->visibleItems.count()) { - index -= d->visibleIndex; - if (index < d->visibleItems.count()) { - FxGridItemSG *gridItem = static_cast(d->visibleItems.at(index)); + if (visibleItems.count()) { + index -= visibleIndex; + if (index < visibleItems.count()) { + FxGridItemSG *gridItem = static_cast(visibleItems.at(index)); colPos = gridItem->colPos(); rowPos = gridItem->rowPos(); } else { // appending items to visible list - FxGridItemSG *gridItem = static_cast(d->visibleItems.at(index-1)); - colPos = gridItem->colPos() + d->colSize(); + FxGridItemSG *gridItem = static_cast(visibleItems.at(index-1)); + colPos = gridItem->colPos() + colSize(); rowPos = gridItem->rowPos(); - if (colPos > d->colSize() * (d->columns-1)) { + if (colPos > colSize() * (columns-1)) { colPos = 0; - rowPos += d->rowSize(); + rowPos += rowSize(); } } } // Update the indexes of the following visible items. - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxViewItem *item = d->visibleItems.at(i); + for (int i = 0; i < visibleItems.count(); ++i) { + FxViewItem *item = visibleItems.at(i); if (item->index != -1 && item->index >= modelIndex) item->index += count; } - bool addedVisible = false; - QList added; int i = 0; - while (i < insertCount && rowPos <= to + d->rowSize()*(d->columns - (colPos/d->colSize()))/qreal(d->columns)) { - if (!addedVisible) { - d->scheduleLayout(); - addedVisible = true; + bool prevAddedCount = addedItems->count(); + while (i < insertCount && rowPos <= to + rowSize()*(columns - (colPos/colSize()))/qreal(columns)) { + FxViewItem *item = 0; + if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) { + if (item->index > modelIndex + i) + movedBackwards->append(item); + item->index = modelIndex + i; } - FxGridItemSG *item = static_cast(d->createItem(modelIndex + i)); - d->visibleItems.insert(index, item); - item->setPosition(colPos, rowPos); - added.append(item); - colPos += d->colSize(); - if (colPos > d->colSize() * (d->columns-1)) { + if (!item) + item = createItem(modelIndex + i); + visibleItems.insert(index, item); + addedItems->append(item); + colPos += colSize(); + if (colPos > colSize() * (columns-1)) { colPos = 0; - rowPos += d->rowSize(); + rowPos += rowSize(); } ++index; ++i; } - if (i < insertCount) { - // We didn't insert all our new items, which means anything - // beyond the current index is not visible - remove it. - while (d->visibleItems.count() > index) { - d->releaseItem(d->visibleItems.takeLast()); - } - } - - // update visibleIndex - d->visibleIndex = 0; - for (QList::Iterator it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index != -1) { - d->visibleIndex = (*it)->index; - break; - } - } - - if (d->itemCount && d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) { - d->currentItem->index = d->currentIndex; - static_cast(d->currentItem)->setPosition(d->colPosAt(d->currentIndex), d->rowPosAt(d->currentIndex)); - } - emit currentIndexChanged(); - } else if (d->itemCount == 0 && (!d->currentIndex || (d->currentIndex < 0 && !d->currentIndexCleared))) { - setCurrentIndex(0); - } - - // everything is in order now - emit add() signal - for (int j = 0; j < added.count(); ++j) - added.at(j)->attached->emitAdd(); - - d->itemCount += count; - emit countChanged(); -} - -void QSGGridView::itemsRemoved(int modelIndex, int count) -{ - Q_D(QSGGridView); - if (!isComponentComplete() || !d->model || !d->model->isValid()) - return; - - d->itemCount -= count; - bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; - bool removedVisible = false; - - // Remove the items from the visible list, skipping anything already marked for removal - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxViewItem *item = *it; - if (item->index == -1 || item->index < modelIndex) { - // already removed, or before removed items - if (item->index < modelIndex && !removedVisible) { - d->scheduleLayout(); - removedVisible = true; - } - ++it; - } else if (item->index >= modelIndex + count) { - // after removed items - item->index -= count; - ++it; - } else { - // removed item - if (!removedVisible) { - d->scheduleLayout(); - removedVisible = true; - } - item->attached->emitRemove(); - if (item->attached->delayRemove()) { - item->index = -1; - connect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved()), Qt::QueuedConnection); - ++it; - } else { - it = d->visibleItems.erase(it); - d->releaseItem(item); - } - } - } - - // update visibleIndex - d->visibleIndex = 0; - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index != -1) { - d->visibleIndex = (*it)->index; - break; - } - } - - // fix current - if (d->currentIndex >= modelIndex + count) { - d->currentIndex -= count; - if (d->currentItem) - d->currentItem->index -= count; - emit currentIndexChanged(); - } else if (currentRemoved) { - // current item has been removed. - d->releaseItem(d->currentItem); - d->currentItem = 0; - d->currentIndex = -1; - if (d->itemCount) - d->updateCurrent(qMin(modelIndex, d->itemCount-1)); - else - emit currentIndexChanged(); - } - - if (removedVisible && d->visibleItems.isEmpty()) { - d->timeline.clear(); - if (d->itemCount == 0) { - d->setPosition(d->contentStartPosition()); - d->updateHeader(); - d->updateFooter(); - } - } - - emit countChanged(); -} - - -void QSGGridView::itemsMoved(int from, int to, int count) -{ - Q_D(QSGGridView); - if (!isComponentComplete() || !d->isValid()) - return; - d->updateUnrequestedIndexes(); - - if (d->visibleItems.isEmpty()) { - d->refill(); - return; - } - - d->moveReason = QSGGridViewPrivate::Other; - - bool movingBackwards = from > to; - d->adjustMoveParameters(&from, &to, &count); - - QHash moved; - int moveByCount = 0; - FxGridItemSG *firstVisible = static_cast(d->firstVisibleItem()); - int firstItemIndex = firstVisible ? firstVisible->index : -1; - - // if visibleItems.first() is above the content start pos, and the items - // beneath it are moved, ensure this first item is later repositioned correctly - // (to above the next visible item) so that subsequent layout() is correct - bool repositionFirstItem = firstVisible - && d->visibleItems.first()->position() < firstVisible->position() - && from > d->visibleItems.first()->index; - - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxViewItem *item = *it; - if (item->index >= from && item->index < from + count) { - // take the items that are moving - item->index += (to-from); - moved.insert(item->index, static_cast(item)); - if (repositionFirstItem) - moveByCount++; - it = d->visibleItems.erase(it); - } else { - if (item->index > from && item->index != -1) { - // move everything after the moved items. - item->index -= count; - if (item->index < d->visibleIndex) - d->visibleIndex = item->index; - } - ++it; - } - } - - int movedCount = 0; - int endIndex = d->visibleIndex; - it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxViewItem *item = *it; - if (movedCount < count && item->index >= to && item->index < to + count) { - // place items in the target position, reusing any existing items - int targetIndex = item->index + movedCount; - FxGridItemSG *movedItem = moved.take(targetIndex); - if (!movedItem) - movedItem = static_cast(d->createItem(targetIndex)); - it = d->visibleItems.insert(it, movedItem); - ++it; - ++movedCount; - } else { - if (item->index != -1) { - if (item->index >= to) { - // update everything after the moved items. - item->index += count; - } - endIndex = item->index; - } - ++it; - } - } - - // If we have moved items to the end of the visible items - // then add any existing moved items that we have - while (FxGridItemSG *item = moved.take(endIndex+1)) { - d->visibleItems.append(item); - ++endIndex; - } - - // update visibleIndex - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index != -1) { - d->visibleIndex = (*it)->index; - break; - } - } - // if first visible item is moving but another item is moving up to replace it, - // do this positioning now to avoid shifting all content forwards - if (movingBackwards && firstItemIndex >= 0) { - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index == firstItemIndex) { - static_cast(*it)->setPosition(firstVisible->colPos(), - firstVisible->rowPos()); - break; - } - } - } - - // Fix current index - if (d->currentIndex >= 0 && d->currentItem) { - int oldCurrent = d->currentIndex; - d->currentIndex = d->model->indexOf(d->currentItem->item, this); - if (oldCurrent != d->currentIndex) { - d->currentItem->index = d->currentIndex; - emit currentIndexChanged(); - } - } - - // Whatever moved items remain are no longer visible items. - while (moved.count()) { - int idx = moved.begin().key(); - FxGridItemSG *item = moved.take(idx); - if (d->currentItem && item->item == d->currentItem->item) - item->setPosition(d->colPosAt(idx), d->rowPosAt(idx)); - d->releaseItem(item); - } - - // Ensure we don't cause an ugly list scroll. - if (d->visibleItems.count() && moveByCount > 0) { - FxGridItemSG *first = static_cast(d->visibleItems.first()); - first->setPosition(first->colPos(), first->rowPos() + ((moveByCount / d->columns) * d->rowSize())); - } - - d->layout(); + return addedItems->count() > prevAddedCount; } /*! @@ -2098,6 +1870,7 @@ void QSGGridView::itemsMoved(int from, int to, int count) \bold Note: methods should only be called after the Component has completed. */ + QSGGridViewAttached *QSGGridView::qmlAttachedProperties(QObject *obj) { return new QSGGridViewAttached(obj); diff --git a/src/declarative/items/qsggridview_p.h b/src/declarative/items/qsggridview_p.h index ae4ce346db..1cdf81d213 100644 --- a/src/declarative/items/qsggridview_p.h +++ b/src/declarative/items/qsggridview_p.h @@ -109,11 +109,6 @@ Q_SIGNALS: protected: virtual void viewportMoved(); virtual void keyPressEvent(QKeyEvent *); - -private Q_SLOTS: - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); }; class QSGGridViewAttached : public QSGItemViewAttached diff --git a/src/declarative/items/qsgitemview.cpp b/src/declarative/items/qsgitemview.cpp index 5543f12f6d..c28fbb1532 100644 --- a/src/declarative/items/qsgitemview.cpp +++ b/src/declarative/items/qsgitemview.cpp @@ -58,6 +58,102 @@ FxViewItem::~FxViewItem() } } + +QSGItemViewChangeSet::QSGItemViewChangeSet() + : active(false) +{ + reset(); +} + +bool QSGItemViewChangeSet::hasPendingChanges() const +{ + return !pendingChanges.isEmpty(); +} + +void QSGItemViewChangeSet::doInsert(int index, int count) +{ + pendingChanges.insert(index, count); + + if (newCurrentIndex >= index) { + // adjust current item index + newCurrentIndex += count; + currentChanged = true; + } else if (newCurrentIndex < 0) { + newCurrentIndex = 0; + currentChanged = true; + } + + itemCount += count; +} + +void QSGItemViewChangeSet::doRemove(int index, int count) +{ + itemCount -= count; + pendingChanges.remove(index, count); + + if (newCurrentIndex >= index + count) { + newCurrentIndex -= count; + currentChanged = true; + } else if (newCurrentIndex >= index && newCurrentIndex < index + count) { + // current item has been removed. + currentRemoved = true; + newCurrentIndex = -1; + if (itemCount) + newCurrentIndex = qMin(index, itemCount-1); + currentChanged = true; + } +} + +void QSGItemViewChangeSet::doMove(int from, int to, int count) +{ + pendingChanges.move(from, to, count); + + if (to > from) { + if (newCurrentIndex >= from) { + if (newCurrentIndex < from + count) + newCurrentIndex += (to-from); + else if (newCurrentIndex < to + count) + newCurrentIndex -= count; + } + currentChanged = true; + } else if (to < from) { + if (newCurrentIndex >= to) { + if (newCurrentIndex >= from && newCurrentIndex < from + count) + newCurrentIndex -= (from-to); + else if (newCurrentIndex < from) + newCurrentIndex += count; + } + currentChanged = true; + } +} + +void QSGItemViewChangeSet::QSGItemViewChangeSet::doChange(int index, int count) +{ + pendingChanges.change(index, count); +} + +void QSGItemViewChangeSet::prepare(int currentIndex, int count) +{ + if (active) + return; + reset(); + active = true; + itemCount = count; + newCurrentIndex = currentIndex; +} + +void QSGItemViewChangeSet::reset() +{ + itemCount = 0; + newCurrentIndex = -1; + pendingChanges.clear(); + removedItems.clear(); + active = false; + currentChanged = false; + currentRemoved = false; +} + + QSGItemView::QSGItemView(QSGFlickablePrivate &dd, QSGItem *parent) : QSGFlickable(dd, parent) { @@ -81,6 +177,7 @@ QSGItem *QSGItemView::currentItem() const Q_D(const QSGItemView); if (!d->currentItem) return 0; + const_cast(d)->applyPendingChanges(); return d->currentItem->item; } @@ -213,14 +310,16 @@ void QSGItemView::setDelegate(QDeclarativeComponent *delegate) int QSGItemView::count() const { Q_D(const QSGItemView); - if (d->model) - return d->model->count(); - return 0; + if (!d->model) + return 0; + const_cast(d)->applyPendingChanges(); + return d->model->count(); } int QSGItemView::currentIndex() const { Q_D(const QSGItemView); + const_cast(d)->applyPendingChanges(); return d->currentIndex; } @@ -230,6 +329,8 @@ void QSGItemView::setCurrentIndex(int index) if (d->requestedIndex >= 0) // currently creating item return; d->currentIndexCleared = (index == -1); + + d->applyPendingChanges(); if (index == d->currentIndex) return; if (isComponentComplete() && d->isValid()) { @@ -313,6 +414,7 @@ QDeclarativeComponent *QSGItemView::header() const QSGItem *QSGItemView::headerItem() const { Q_D(const QSGItemView); + const_cast(d)->applyPendingChanges(); return d->header ? d->header->item : 0; } @@ -320,6 +422,7 @@ void QSGItemView::setHeader(QDeclarativeComponent *headerComponent) { Q_D(QSGItemView); if (d->headerComponent != headerComponent) { + d->applyPendingChanges(); delete d->header; d->header = 0; d->headerComponent = headerComponent; @@ -348,6 +451,7 @@ QDeclarativeComponent *QSGItemView::footer() const QSGItem *QSGItemView::footerItem() const { Q_D(const QSGItemView); + const_cast(d)->applyPendingChanges(); return d->footer ? d->footer->item : 0; } @@ -355,6 +459,7 @@ void QSGItemView::setFooter(QDeclarativeComponent *footerComponent) { Q_D(QSGItemView); if (d->footerComponent != footerComponent) { + d->applyPendingChanges(); delete d->footer; d->footer = 0; d->footerComponent = footerComponent; @@ -373,6 +478,7 @@ void QSGItemView::setFooter(QDeclarativeComponent *footerComponent) QDeclarativeComponent *QSGItemView::highlight() const { Q_D(const QSGItemView); + const_cast(d)->applyPendingChanges(); return d->highlightComponent; } @@ -380,6 +486,7 @@ void QSGItemView::setHighlight(QDeclarativeComponent *highlightComponent) { Q_D(QSGItemView); if (highlightComponent != d->highlightComponent) { + d->applyPendingChanges(); d->highlightComponent = highlightComponent; d->createHighlight(); if (d->currentItem) @@ -391,9 +498,8 @@ void QSGItemView::setHighlight(QDeclarativeComponent *highlightComponent) QSGItem *QSGItemView::highlightItem() const { Q_D(const QSGItemView); - if (!d->highlight) - return 0; - return d->highlight->item; + const_cast(d)->applyPendingChanges(); + return d->highlight ? d->highlight->item : 0; } bool QSGItemView::highlightFollowsCurrentItem() const @@ -506,10 +612,10 @@ void QSGItemViewPrivate::positionViewAtIndex(int index, int mode) return; if (mode < QSGItemView::Beginning || mode > QSGItemView::Contain) return; + + applyPendingChanges(); int idx = qMax(qMin(index, model->count()-1), 0); - if (layoutScheduled) - layout(); qreal pos = isContentFlowReversed() ? -position() - size() : position(); FxViewItem *item = visibleItem(idx); qreal maxExtent; @@ -614,6 +720,12 @@ int QSGItemView::indexAt(qreal x, qreal y) const return -1; } +void QSGItemViewPrivate::applyPendingChanges() +{ + Q_Q(QSGItemView); + if (q->isComponentComplete() && currentChanges.hasPendingChanges()) + layout(); +} // for debugging only void QSGItemViewPrivate::checkVisible() const @@ -629,8 +741,6 @@ void QSGItemViewPrivate::checkVisible() const } } - - void QSGItemViewPrivate::itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { Q_Q(QSGItemView); @@ -668,11 +778,51 @@ void QSGItemView::destroyRemoved() d->layout(); } -void QSGItemView::itemsChanged(int, int) +void QSGItemView::itemsInserted(int index, int count) { Q_D(QSGItemView); - d->updateSections(); - d->layout(); + if (!isComponentComplete() || !d->model || !d->model->isValid()) + return; + + d->currentChanges.prepare(d->currentIndex, d->itemCount); + d->currentChanges.doInsert(index, count); + d->scheduleLayout(); +} + +void QSGItemView::itemsRemoved(int index, int count) +{ + Q_D(QSGItemView); + if (!isComponentComplete() || !d->model || !d->model->isValid()) + return; + + d->currentChanges.prepare(d->currentIndex, d->itemCount); + d->currentChanges.doRemove(index, count); + d->scheduleLayout(); +} + +void QSGItemView::itemsMoved(int from, int to, int count) +{ + Q_D(QSGItemView); + if (!isComponentComplete() || !d->model || !d->model->isValid()) + return; + + if (from == to || count <= 0 || from < 0 || to < 0) + return; + + d->currentChanges.prepare(d->currentIndex, d->itemCount); + d->currentChanges.doMove(from, to, count); + d->scheduleLayout(); +} + +void QSGItemView::itemsChanged(int index, int count) +{ + Q_D(QSGItemView); + if (!isComponentComplete() || !d->model || !d->model->isValid()) + return; + + d->currentChanges.prepare(d->currentIndex, d->itemCount); + d->currentChanges.doChange(index, count); + d->scheduleLayout(); } void QSGItemView::modelReset() @@ -796,7 +946,6 @@ void QSGItemView::trackedPositionChanged() } } - void QSGItemView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QSGItemView); @@ -1017,7 +1166,7 @@ QSGItemViewPrivate::QSGItemViewPrivate() , headerComponent(0), header(0), footerComponent(0), footer(0) , minExtent(0), maxExtent(0) , ownModel(false), wrap(false), lazyRelease(false), deferredRelease(false) - , layoutScheduled(false), inViewportMoved(false), currentIndexCleared(false) + , layoutScheduled(false), inApplyModelChanges(false), inViewportMoved(false), forceLayout(false), currentIndexCleared(false) , haveHighlightRange(false), autoHighlight(true), highlightRangeStartValid(false), highlightRangeEndValid(false) , minExtentDirty(true), maxExtentDirty(true) { @@ -1082,7 +1231,7 @@ FxViewItem *QSGItemViewPrivate::firstVisibleItem() const { const qreal pos = isContentFlowReversed() ? -position()-size() : position(); for (int i = 0; i < visibleItems.count(); ++i) { FxViewItem *item = visibleItems.at(i); - if (item->index != -1 && item->endPosition() >= pos) + if (item->index != -1 && item->endPosition() > pos) return item; } return visibleItems.count() ? visibleItems.first() : 0; @@ -1105,18 +1254,6 @@ int QSGItemViewPrivate::mapFromModel(int modelIndex) const return -1; // Not in visibleList } -void QSGItemViewPrivate::adjustMoveParameters(int *from, int *to, int *count) const -{ - if (*from > *to) { - // Only move forwards - flip if backwards moving - int tfrom = *from; - int tto = *to; - *from = tto; - *to = tto + *count; - *count = tfrom - tto; - } -} - void QSGItemViewPrivate::init() { Q_Q(QSGItemView); @@ -1130,6 +1267,8 @@ void QSGItemViewPrivate::init() void QSGItemViewPrivate::updateCurrent(int modelIndex) { Q_Q(QSGItemView); + applyPendingChanges(); + if (!q->isComponentComplete() || !isValid() || modelIndex < 0 || modelIndex >= model->count()) { if (currentItem) { currentItem->attached->setIsCurrentItem(false); @@ -1168,6 +1307,7 @@ void QSGItemViewPrivate::updateCurrent(int modelIndex) void QSGItemViewPrivate::clear() { + currentChanges.reset(); timeline.clear(); for (int i = 0; i < visibleItems.count(); ++i) @@ -1207,6 +1347,9 @@ void QSGItemViewPrivate::refill(qreal from, qreal to, bool doBuffer) if (!isValid() || !q->isComponentComplete()) return; + currentChanges.reset(); + + int prevCount = itemCount; itemCount = model->count(); qreal bufferFrom = from - buffer; qreal bufferTo = to + buffer; @@ -1240,12 +1383,15 @@ void QSGItemViewPrivate::refill(qreal from, qreal to, bool doBuffer) } lazyRelease = false; + if (prevCount != itemCount) + emit q->countChanged(); } void QSGItemViewPrivate::regenerate() { Q_Q(QSGItemView); if (q->isComponentComplete()) { + currentChanges.reset(); delete header; header = 0; delete footer; @@ -1290,6 +1436,10 @@ void QSGItemViewPrivate::layout() return; } + if (!applyModelChanges() && !forceLayout) + return; + forceLayout = false; + layoutVisibleItems(); refill(); @@ -1297,6 +1447,7 @@ void QSGItemViewPrivate::layout() maxExtentDirty = true; updateHighlight(); + if (!q->isMoving() && !q->isFlicking()) { fixupPosition(); refill(); @@ -1308,6 +1459,132 @@ void QSGItemViewPrivate::layout() updateUnrequestedPositions(); } +bool QSGItemViewPrivate::applyModelChanges() +{ + Q_Q(QSGItemView); + if (!q->isComponentComplete() || !currentChanges.hasPendingChanges() || inApplyModelChanges) + return false; + inApplyModelChanges = true; + + updateUnrequestedIndexes(); + moveReason = QSGItemViewPrivate::Other; + + int prevCount = itemCount; + bool removedVisible = false; + + FxViewItem *firstVisible = firstVisibleItem(); + FxViewItem *origVisibleItemsFirst = visibleItems.count() ? visibleItems.first() : 0; + int firstItemIndex = firstVisible ? firstVisible->index : -1; + QList removedBeforeFirstVisible; + + const QVector &removals = currentChanges.pendingChanges.removes(); + for (int i=0; i::Iterator it = visibleItems.begin(); + while (it != visibleItems.end()) { + FxViewItem *item = *it; + if (item->index == -1 || item->index < removals[i].index) { + // already removed, or before removed items + if (item->index < removals[i].index && !removedVisible) + removedVisible = true; + ++it; + } else if (item->index >= removals[i].index + removals[i].count) { + // after removed items + item->index -= removals[i].count; + ++it; + } else { + // removed item + removedVisible = true; + item->attached->emitRemove(); + if (item->attached->delayRemove()) { + item->index = -1; + QObject::connect(item->attached, SIGNAL(delayRemoveChanged()), q, SLOT(destroyRemoved()), Qt::QueuedConnection); + ++it; + } else { + if (firstVisible && item->position() < firstVisible->position() && item != visibleItems.first()) + removedBeforeFirstVisible.append(item); + if (removals[i].isMove()) { + currentChanges.removedItems.insert(removals[i].moveKey(item->index), item); + } else { + if (item == firstVisible) + firstVisible = 0; + currentChanges.removedItems.insertMulti(QDeclarativeChangeSet::MoveKey(), item); + } + it = visibleItems.erase(it); + } + } + } + + } + if (!removals.isEmpty()) + updateVisibleIndex(); + + const QVector &insertions = currentChanges.pendingChanges.inserts(); + bool addedVisible = false; + QList addedItems; + QList movedBackwards; + + for (int i=0; iattached->emitAdd(); + + // if first visible item is moving but another item is moving up to replace it, + // do this positioning now to avoid shifting all content forwards + if (firstVisible && firstItemIndex >= 0) { + for (int i=0; iindex == firstItemIndex) { + resetItemPosition(movedBackwards[i], firstVisible); + movedBackwards.removeAt(i); + break; + } + } + } + + // Ensure we don't cause an ugly list scroll + if (firstVisible && visibleItems.count() && visibleItems.first() != firstVisible) { + // ensure first item is placed at correct postion if moving backward + // since it will be used to position all subsequent items + if (movedBackwards.count() && origVisibleItemsFirst) + resetItemPosition(visibleItems.first(), origVisibleItemsFirst); + moveItemBy(visibleItems.first(), removedBeforeFirstVisible, movedBackwards); + } + + // Whatever removed/moved items remain are no longer visible items. + for (QHash::Iterator it = currentChanges.removedItems.begin(); + it != currentChanges.removedItems.end(); ++it) { + releaseItem(it.value()); + } + currentChanges.removedItems.clear(); + + if (currentChanges.currentChanged) { + if (currentChanges.currentRemoved && currentItem) { + currentItem->attached->setIsCurrentItem(false); + releaseItem(currentItem); + currentItem = 0; + } + if (!currentIndexCleared) + updateCurrent(currentChanges.newCurrentIndex); + } + currentChanges.reset(); + + updateSections(); + if (prevCount != itemCount) + emit q->countChanged(); + + inApplyModelChanges = false; + return removedVisible || addedVisible || !currentChanges.pendingChanges.changes().isEmpty(); +} + FxViewItem *QSGItemViewPrivate::createItem(int modelIndex) { Q_Q(QSGItemView); @@ -1415,4 +1692,15 @@ void QSGItemViewPrivate::updateUnrequestedPositions() repositionPackageItemAt(it.key(), it.value()); } +void QSGItemViewPrivate::updateVisibleIndex() +{ + visibleIndex = 0; + for (QList::Iterator it = visibleItems.begin(); it != visibleItems.end(); ++it) { + if ((*it)->index != -1) { + visibleIndex = (*it)->index; + break; + } + } +} + QT_END_NAMESPACE diff --git a/src/declarative/items/qsgitemview_p.h b/src/declarative/items/qsgitemview_p.h index b784015f66..b1093ffdbe 100644 --- a/src/declarative/items/qsgitemview_p.h +++ b/src/declarative/items/qsgitemview_p.h @@ -191,13 +191,17 @@ protected: protected slots: virtual void updateSections() {} void destroyRemoved(); - void itemsChanged(int index, int count); void createdItem(int index, QSGItem *item); void modelReset(); void destroyingItem(QSGItem *item); void animStopped(); void trackedPositionChanged(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void itemsChanged(int index, int count); + private: Q_DECLARE_PRIVATE(QSGItemView) }; diff --git a/src/declarative/items/qsgitemview_p_p.h b/src/declarative/items/qsgitemview_p_p.h index f20f4cca3e..e2e222ba36 100644 --- a/src/declarative/items/qsgitemview_p_p.h +++ b/src/declarative/items/qsgitemview_p_p.h @@ -45,6 +45,7 @@ #include "qsgitemview_p.h" #include "qsgflickable_p_p.h" #include "qsgvisualitemmodel_p.h" +#include QT_BEGIN_HEADER @@ -73,6 +74,30 @@ public: QSGItemViewAttached *attached; }; +class QSGItemViewChangeSet +{ +public: + QSGItemViewChangeSet(); + + bool hasPendingChanges() const; + void prepare(int currentIndex, int count); + void reset(); + + void doInsert(int index, int count); + void doRemove(int index, int count); + void doMove(int from, int to, int count); + void doChange(int index, int count); + + int itemCount; + int newCurrentIndex; + QDeclarativeChangeSet pendingChanges; + QHash removedItems; + + bool active : 1; + bool currentChanged : 1; + bool currentRemoved : 1; +}; + class QSGItemViewPrivate : public QSGFlickablePrivate { Q_DECLARE_PUBLIC(QSGItemView) @@ -92,7 +117,6 @@ public: FxViewItem *visibleItem(int modelIndex) const; FxViewItem *firstVisibleItem() const; int mapFromModel(int modelIndex) const; - void adjustMoveParameters(int *from, int *to, int *count) const; virtual void init(); virtual void clear(); @@ -115,7 +139,10 @@ public: void updateTrackedItem(); void updateUnrequestedIndexes(); void updateUnrequestedPositions(); + void updateVisibleIndex(); void positionViewAtIndex(int index, int mode); + void applyPendingChanges(); + bool applyModelChanges(); void checkVisible() const; @@ -135,6 +162,7 @@ public: FxViewItem *trackedItem; QHash unrequestedItems; int requestedIndex; + QSGItemViewChangeSet currentChanges; // XXX split into struct QDeclarativeComponent *highlightComponent; @@ -157,7 +185,9 @@ public: bool lazyRelease : 1; bool deferredRelease : 1; bool layoutScheduled : 1; + bool inApplyModelChanges : 1; bool inViewportMoved : 1; + bool forceLayout : 1; bool currentIndexCleared : 1; bool haveHighlightRange : 1; bool autoHighlight : 1; @@ -195,9 +225,13 @@ protected: virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0; virtual void repositionPackageItemAt(QSGItem *item, int index) = 0; + virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem) = 0; + virtual void resetFirstItemPosition() = 0; + virtual void moveItemBy(FxViewItem *item, const QList &, const QList &) = 0; virtual void layoutVisibleItems() = 0; virtual void changedVisibleIndex(int newIndex) = 0; + virtual bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, QList *, QList *, FxViewItem *) = 0; virtual void initializeViewItem(FxViewItem *) {} virtual void initializeCurrentItem() {} diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp index 3be4a4bd58..82a2dd7774 100644 --- a/src/declarative/items/qsglistview.cpp +++ b/src/declarative/items/qsglistview.cpp @@ -209,6 +209,9 @@ public: virtual void initializeViewItem(FxViewItem *item); virtual void releaseItem(FxViewItem *item); virtual void repositionPackageItemAt(QSGItem *item, int index); + virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem); + virtual void resetFirstItemPosition(); + virtual void moveItemBy(FxViewItem *item, const QList &items, const QList &movedBackwards); virtual void createHighlight(); virtual void updateHighlight(); @@ -216,6 +219,7 @@ public: virtual void setPosition(qreal pos); virtual void layoutVisibleItems(); + bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, QList *, QList *, FxViewItem *firstVisible); virtual void updateSections(); void createSection(FxListItemSG *); @@ -684,6 +688,27 @@ void QSGListViewPrivate::repositionPackageItemAt(QSGItem *item, int index) } } +void QSGListViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem) +{ + static_cast(item)->setPosition(toItem->position()); +} + +void QSGListViewPrivate::resetFirstItemPosition() +{ + FxListItemSG *item = static_cast(visibleItems.first()); + item->setPosition(0); +} + +void QSGListViewPrivate::moveItemBy(FxViewItem *item, const QList &forwards, const QList &backwards) +{ + qreal pos = 0; + for (int i=0; isize(); + for (int i=0; isize(); + static_cast(item)->setPosition(item->position() + pos); +} + void QSGListViewPrivate::createHighlight() { Q_Q(QSGListView); @@ -733,6 +758,8 @@ void QSGListViewPrivate::createHighlight() void QSGListViewPrivate::updateHighlight() { + applyPendingChanges(); + if ((!currentItem && highlight) || (currentItem && !highlight)) createHighlight(); bool strictHighlight = haveHighlightRange && highlightRange == QSGListView::StrictlyEnforceRange; @@ -1009,6 +1036,7 @@ void QSGListViewPrivate::itemGeometryChanged(QSGItem *item, const QRectF &newGeo if (item != contentItem && (!highlight || item != highlight->item)) { if ((orient == QSGListView::Vertical && newGeometry.height() != oldGeometry.height()) || (orient == QSGListView::Horizontal && newGeometry.width() != oldGeometry.width())) { + forceLayout = true; scheduleLayout(); } } @@ -1565,6 +1593,7 @@ void QSGListView::setSpacing(qreal spacing) Q_D(QSGListView); if (spacing != d->spacing) { d->spacing = spacing; + d->forceLayout = true; d->layout(); emit spacingChanged(); } @@ -2067,373 +2096,107 @@ void QSGListView::updateSections() roles << d->sectionCriteria->property().toUtf8(); d->model->setWatchedRoles(roles); d->updateSections(); - if (d->itemCount) + if (d->itemCount) { + d->forceLayout = true; d->layout(); + } } } -void QSGListView::itemsInserted(int modelIndex, int count) +bool QSGListViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::Insert &change, QList *movedBackwards, QList *addedItems, FxViewItem *firstVisible) { - Q_D(QSGListView); - if (!isComponentComplete() || !d->model || !d->model->isValid()) - return; - d->updateUnrequestedIndexes(); - d->moveReason = QSGListViewPrivate::Other; + Q_Q(QSGListView); + + int modelIndex = change.index; + int count = change.count; + + + qreal tempPos = isRightToLeft() ? -position()-size() : position(); + int index = visibleItems.count() ? mapFromModel(modelIndex) : 0; - qreal tempPos = d->isRightToLeft() ? -d->position()-d->size() : d->position(); - int index = d->visibleItems.count() ? d->mapFromModel(modelIndex) : 0; if (index < 0) { - int i = d->visibleItems.count() - 1; - while (i > 0 && d->visibleItems.at(i)->index == -1) + int i = visibleItems.count() - 1; + while (i > 0 && visibleItems.at(i)->index == -1) --i; - if (i == 0 && d->visibleItems.first()->index == -1) { + if (i == 0 && visibleItems.first()->index == -1) { // there are no visible items except items marked for removal - index = d->visibleItems.count(); - } else if (d->visibleItems.at(i)->index + 1 == modelIndex - && d->visibleItems.at(i)->endPosition() <= d->buffer+tempPos+d->size()) { + index = visibleItems.count(); + } else if (visibleItems.at(i)->index + 1 == modelIndex + && visibleItems.at(i)->endPosition() <= buffer+tempPos+size()) { // Special case of appending an item to the model. - index = d->visibleItems.count(); + index = visibleItems.count(); } else { - if (modelIndex < d->visibleIndex) { + if (modelIndex < visibleIndex) { // Insert before visible items - d->visibleIndex += count; - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxViewItem *item = d->visibleItems.at(i); + visibleIndex += count; + for (int i = 0; i < visibleItems.count(); ++i) { + FxViewItem *item = visibleItems.at(i); if (item->index != -1 && item->index >= modelIndex) item->index += count; } } - if (d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) - d->currentItem->index = d->currentIndex; - emit currentIndexChanged(); - } - d->scheduleLayout(); - d->itemCount += count; - emit countChanged(); - return; + return true; } } // index can be the next item past the end of the visible items list (i.e. appended) int pos = 0; - if (d->visibleItems.count()) { - pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position() - : d->visibleItems.last()->endPosition()+d->spacing; + if (visibleItems.count()) { + pos = index < visibleItems.count() ? visibleItems.at(index)->position() + : visibleItems.last()->endPosition()+spacing; } - int initialPos = pos; - int diff = 0; - QList added; - bool addedVisible = false; - FxViewItem *firstVisible = d->firstVisibleItem(); + int prevAddedCount = addedItems->count(); if (firstVisible && pos < firstVisible->position()) { // Insert items before the visible item. int insertionIdx = index; int i = 0; - int from = tempPos - d->buffer; + int from = tempPos - buffer; + for (i = count-1; i >= 0 && pos > from; --i) { - if (!addedVisible) { - d->scheduleLayout(); - addedVisible = true; + FxViewItem *item = 0; + if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) { + if (item->index > modelIndex + i) + movedBackwards->append(item); + item->index = modelIndex + i; } - FxListItemSG *item = static_cast(d->createItem(modelIndex + i)); - d->visibleItems.insert(insertionIdx, item); - pos -= item->size() + d->spacing; - item->setPosition(pos); + if (!item) + item = createItem(modelIndex + i); + + visibleItems.insert(insertionIdx, item); + addedItems->append(item); + pos -= item->size() + spacing; index++; } - if (i >= 0) { - // If we didn't insert all our new items - anything - // before the current index is not visible - remove it. - while (insertionIdx--) { - FxListItemSG *item = static_cast(d->visibleItems.takeFirst()); - if (item->index != -1) - d->visibleIndex++; - d->releaseItem(item); - } - } else { - // adjust pos of items before inserted items. - for (int i = insertionIdx-1; i >= 0; i--) { - FxListItemSG *listItem = static_cast(d->visibleItems.at(i)); - listItem->setPosition(listItem->position() - (initialPos - pos)); - } - } } else { int i = 0; - int to = d->buffer+tempPos+d->size(); + int to = buffer+tempPos+size(); for (i = 0; i < count && pos <= to; ++i) { - if (!addedVisible) { - d->scheduleLayout(); - addedVisible = true; - } - FxListItemSG *item = static_cast(d->createItem(modelIndex + i)); - d->visibleItems.insert(index, item); - item->setPosition(pos); - added.append(item); - pos += item->size() + d->spacing; - ++index; - } - if (i != count) { - // We didn't insert all our new items, which means anything - // beyond the current index is not visible - remove it. - while (d->visibleItems.count() > index) - d->releaseItem(d->visibleItems.takeLast()); - } - diff = pos - initialPos; - } - if (d->itemCount && d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) { - d->currentItem->index = d->currentIndex; - static_cast(d->currentItem)->setPosition(static_cast(d->currentItem)->position() + diff); - } - emit currentIndexChanged(); - } else if (!d->itemCount && (!d->currentIndex || (d->currentIndex < 0 && !d->currentIndexCleared))) { - d->updateCurrent(0); - } - // Update the indexes of the following visible items. - for (; index < d->visibleItems.count(); ++index) { - FxViewItem *item = d->visibleItems.at(index); - if (d->currentItem && item->item != d->currentItem->item) - static_cast(item)->setPosition(item->position() + diff); - if (item->index != -1) - item->index += count; - } - // everything is in order now - emit add() signal - for (int j = 0; j < added.count(); ++j) - added.at(j)->attached->emitAdd(); - - d->updateSections(); - d->itemCount += count; - emit countChanged(); -} - -void QSGListView::itemsRemoved(int modelIndex, int count) -{ - Q_D(QSGListView); - if (!isComponentComplete() || !d->model || !d->model->isValid()) - return; - d->moveReason = QSGListViewPrivate::Other; - d->updateUnrequestedIndexes(); - d->itemCount -= count; - - FxViewItem *firstVisible = d->firstVisibleItem(); - int preRemovedSize = 0; - bool removedVisible = false; - // Remove the items from the visible list, skipping anything already marked for removal - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxViewItem *item = *it; - if (item->index == -1 || item->index < modelIndex) { - // already removed, or before removed items - ++it; - } else if (item->index >= modelIndex + count) { - // after removed items - item->index -= count; - ++it; - } else { - // removed item - if (!removedVisible) { - d->scheduleLayout(); - removedVisible = true; - } - item->attached->emitRemove(); - if (item->attached->delayRemove()) { - item->index = -1; - connect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved()), Qt::QueuedConnection); - ++it; - } else { - if (item == firstVisible) - firstVisible = 0; - if (firstVisible && item->position() < firstVisible->position()) - preRemovedSize += item->size(); - it = d->visibleItems.erase(it); - d->releaseItem(item); + FxViewItem *item = 0; + if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) { + if (item->index > modelIndex + i) + movedBackwards->append(item); + item->index = modelIndex + i; } - } - } + if (!item) + item = createItem(modelIndex + i); - if (firstVisible && d->visibleItems.first() != firstVisible) - static_cast(d->visibleItems.first())->setPosition(d->visibleItems.first()->position() + preRemovedSize); - - // update visibleIndex - bool haveVisibleIndex = false; - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index != -1) { - d->visibleIndex = (*it)->index; - haveVisibleIndex = true; - break; - } - } - - // fix current - if (d->currentIndex >= modelIndex + count) { - d->currentIndex -= count; - if (d->currentItem) - d->currentItem->index -= count; - emit currentIndexChanged(); - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { - // current item has been removed. - if (d->currentItem) { - d->currentItem->attached->setIsCurrentItem(false); - d->releaseItem(d->currentItem); - d->currentItem = 0; + visibleItems.insert(index, item); + addedItems->append(item); + pos += item->size() + spacing; + ++index; } - d->currentIndex = -1; - if (d->itemCount) - d->updateCurrent(qMin(modelIndex, d->itemCount-1)); - else - emit currentIndexChanged(); } - if (!haveVisibleIndex) { - d->timeline.clear(); - if (removedVisible && d->itemCount == 0) { - d->visibleIndex = 0; - d->visiblePos = 0; - d->setPosition(d->contentStartPosition()); - d->updateHeader(); - d->updateFooter(); - } else { - if (modelIndex < d->visibleIndex) - d->visibleIndex = modelIndex+1; - d->visibleIndex = qMax(qMin(d->visibleIndex, d->itemCount-1), 0); - } + for (; index < visibleItems.count(); ++index) { + FxViewItem *item = visibleItems.at(index); + if (item->index != -1) + item->index += count; } - d->updateSections(); - emit countChanged(); + return addedItems->count() > prevAddedCount; } -void QSGListView::itemsMoved(int from, int to, int count) -{ - Q_D(QSGListView); - if (!isComponentComplete() || !d->isValid()) - return; - d->updateUnrequestedIndexes(); - - if (d->visibleItems.isEmpty()) { - d->refill(); - return; - } - - d->moveReason = QSGListViewPrivate::Other; - - bool movingBackwards = from > to; - d->adjustMoveParameters(&from, &to, &count); - - QHash moved; - int moveBy = 0; - FxViewItem *firstVisible = d->firstVisibleItem(); - int firstItemIndex = firstVisible ? firstVisible->index : -1; - - // if visibleItems.first() is above the content start pos, and the items - // beneath it are moved, ensure this first item is later repositioned correctly - // (to above the next visible item) so that subsequent layout() is correct - bool repositionFirstItem = firstVisible - && d->visibleItems.first()->position() < firstVisible->position() - && from > d->visibleItems.first()->index; - - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxViewItem *item = *it; - if (item->index >= from && item->index < from + count) { - // take the items that are moving - item->index += (to-from); - moved.insert(item->index, item); - if (repositionFirstItem) - moveBy += item->size(); - it = d->visibleItems.erase(it); - } else { - // move everything after the moved items. - if (item->index > from && item->index != -1) - item->index -= count; - ++it; - } - } - - int movedCount = 0; - int endIndex = d->visibleIndex; - it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxViewItem *item = *it; - if (movedCount < count && item->index >= to && item->index < to + count) { - // place items in the target position, reusing any existing items - int targetIndex = item->index + movedCount; - FxViewItem *movedItem = moved.take(targetIndex); - if (!movedItem) - movedItem = d->createItem(targetIndex); - it = d->visibleItems.insert(it, movedItem); - ++it; - ++movedCount; - } else { - if (item->index != -1) { - if (item->index >= to) { - // update everything after the moved items. - item->index += count; - } - endIndex = item->index; - } - ++it; - } - } - - // If we have moved items to the end of the visible items - // then add any existing moved items that we have - while (FxViewItem *item = moved.take(endIndex+1)) { - d->visibleItems.append(item); - ++endIndex; - } - - // update visibleIndex - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index != -1) { - d->visibleIndex = (*it)->index; - break; - } - } - - // if first visible item is moving but another item is moving up to replace it, - // do this positioning now to avoid shifting all content forwards - if (movingBackwards && firstItemIndex >= 0) { - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index == firstItemIndex) { - static_cast(*it)->setPosition(firstVisible->position()); - break; - } - } - } - - // Fix current index - if (d->currentIndex >= 0 && d->currentItem) { - int oldCurrent = d->currentIndex; - d->currentIndex = d->model->indexOf(d->currentItem->item, this); - if (oldCurrent != d->currentIndex) { - d->currentItem->index = d->currentIndex; - emit currentIndexChanged(); - } - } - - // Whatever moved items remain are no longer visible items. - while (moved.count()) { - int idx = moved.begin().key(); - FxViewItem *item = moved.take(idx); - if (d->currentItem && item->item == d->currentItem->item) - static_cast(item)->setPosition(d->positionAt(idx)); - d->releaseItem(item); - } - - // Ensure we don't cause an ugly list scroll. - if (d->visibleItems.count()) - static_cast(d->visibleItems.first())->setPosition(d->visibleItems.first()->position() + moveBy); - - d->updateSections(); - d->layout(); -} /*! \qmlmethod QtQuick2::ListView::positionViewAtIndex(int index, PositionMode mode) diff --git a/src/declarative/items/qsglistview_p.h b/src/declarative/items/qsglistview_p.h index e45e16b85d..8ff4b05346 100644 --- a/src/declarative/items/qsglistview_p.h +++ b/src/declarative/items/qsglistview_p.h @@ -166,11 +166,6 @@ protected: protected Q_SLOTS: void updateSections(); - -private Q_SLOTS: - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); }; class QSGListViewAttached : public QSGItemViewAttached -- cgit v1.2.3 From 1dd8b509074ba60da671f7671f8cf09c3fc001ae Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 30 Aug 2011 16:02:41 +1000 Subject: Remove scheduleLayout() and layoutScheduled No longer necessary since views now call QSGItem::polish() which does its own layout scheduling and only does layouts when necessary Change-Id: I7d265fcf4177344c4ba10600b551a5545284316f Reviewed-on: http://codereview.qt.nokia.com/3843 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- src/declarative/items/qsggridview.cpp | 2 +- src/declarative/items/qsgitemview.cpp | 20 +++++--------------- src/declarative/items/qsgitemview_p_p.h | 2 -- src/declarative/items/qsglistview.cpp | 2 +- 4 files changed, 7 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp index f0956367c5..50ea86ab04 100644 --- a/src/declarative/items/qsggridview.cpp +++ b/src/declarative/items/qsggridview.cpp @@ -774,7 +774,7 @@ void QSGGridViewPrivate::itemGeometryChanged(QSGItem *item, const QRectF &newGeo if (item == q) { if (newGeometry.height() != oldGeometry.height() || newGeometry.width() != oldGeometry.width()) { updateViewport(); - scheduleLayout(); + q->polish(); } } } diff --git a/src/declarative/items/qsgitemview.cpp b/src/declarative/items/qsgitemview.cpp index c28fbb1532..cd598e9a28 100644 --- a/src/declarative/items/qsgitemview.cpp +++ b/src/declarative/items/qsgitemview.cpp @@ -786,7 +786,7 @@ void QSGItemView::itemsInserted(int index, int count) d->currentChanges.prepare(d->currentIndex, d->itemCount); d->currentChanges.doInsert(index, count); - d->scheduleLayout(); + polish(); } void QSGItemView::itemsRemoved(int index, int count) @@ -797,7 +797,7 @@ void QSGItemView::itemsRemoved(int index, int count) d->currentChanges.prepare(d->currentIndex, d->itemCount); d->currentChanges.doRemove(index, count); - d->scheduleLayout(); + polish(); } void QSGItemView::itemsMoved(int from, int to, int count) @@ -811,7 +811,7 @@ void QSGItemView::itemsMoved(int from, int to, int count) d->currentChanges.prepare(d->currentIndex, d->itemCount); d->currentChanges.doMove(from, to, count); - d->scheduleLayout(); + polish(); } void QSGItemView::itemsChanged(int index, int count) @@ -822,7 +822,7 @@ void QSGItemView::itemsChanged(int index, int count) d->currentChanges.prepare(d->currentIndex, d->itemCount); d->currentChanges.doChange(index, count); - d->scheduleLayout(); + polish(); } void QSGItemView::modelReset() @@ -1166,7 +1166,7 @@ QSGItemViewPrivate::QSGItemViewPrivate() , headerComponent(0), header(0), footerComponent(0), footer(0) , minExtent(0), maxExtent(0) , ownModel(false), wrap(false), lazyRelease(false), deferredRelease(false) - , layoutScheduled(false), inApplyModelChanges(false), inViewportMoved(false), forceLayout(false), currentIndexCleared(false) + , inApplyModelChanges(false), inViewportMoved(false), forceLayout(false), currentIndexCleared(false) , haveHighlightRange(false), autoHighlight(true), highlightRangeStartValid(false), highlightRangeEndValid(false) , minExtentDirty(true), maxExtentDirty(true) { @@ -1406,15 +1406,6 @@ void QSGItemViewPrivate::regenerate() } } -void QSGItemViewPrivate::scheduleLayout() -{ - Q_Q(QSGItemView); - if (!layoutScheduled) { - layoutScheduled = true; - q->polish(); - } -} - void QSGItemViewPrivate::updateViewport() { Q_Q(QSGItemView); @@ -1429,7 +1420,6 @@ void QSGItemViewPrivate::updateViewport() void QSGItemViewPrivate::layout() { Q_Q(QSGItemView); - layoutScheduled = false; if (!isValid() && !visibleItems.count()) { clear(); setPosition(contentStartPosition()); diff --git a/src/declarative/items/qsgitemview_p_p.h b/src/declarative/items/qsgitemview_p_p.h index e2e222ba36..243045526a 100644 --- a/src/declarative/items/qsgitemview_p_p.h +++ b/src/declarative/items/qsgitemview_p_p.h @@ -126,7 +126,6 @@ public: void layout(); void refill(); void refill(qreal from, qreal to, bool doBuffer = false); - void scheduleLayout(); void mirrorChange(); FxViewItem *createItem(int modelIndex); @@ -184,7 +183,6 @@ public: bool wrap : 1; bool lazyRelease : 1; bool deferredRelease : 1; - bool layoutScheduled : 1; bool inApplyModelChanges : 1; bool inViewportMoved : 1; bool forceLayout : 1; diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp index 82a2dd7774..73bbd87e2a 100644 --- a/src/declarative/items/qsglistview.cpp +++ b/src/declarative/items/qsglistview.cpp @@ -1037,7 +1037,7 @@ void QSGListViewPrivate::itemGeometryChanged(QSGItem *item, const QRectF &newGeo if ((orient == QSGListView::Vertical && newGeometry.height() != oldGeometry.height()) || (orient == QSGListView::Horizontal && newGeometry.width() != oldGeometry.width())) { forceLayout = true; - scheduleLayout(); + q->polish(); } } } -- cgit v1.2.3 From d481f2ff518df1e44103d1850e7d52bd69260c34 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 31 Aug 2011 12:36:32 +1000 Subject: Allow reference to signals using 'on' handler syntax. This will allow APIs like the following: trigger: mouseArea.onClicked However, signal handlers will not be callable from QML: mouseArea.onClicked() //throws exception Change-Id: I2ef5cb4e1f3ed4814ef590962391e1b14e3f0c43 Reviewed-on: http://codereview.qt.nokia.com/3683 Reviewed-by: Qt Sanity Bot Reviewed-by: Aaron Kennedy --- src/declarative/qml/ftw/qmetaobjectbuilder.cpp | 10 ++-- src/declarative/qml/qdeclarativepropertycache.cpp | 33 +++++++++++++ src/declarative/qml/qdeclarativepropertycache_p.h | 5 +- src/declarative/qml/v8/qv8engine_p.h | 2 +- src/declarative/qml/v8/qv8qobjectwrapper.cpp | 57 +++++++++++++++++++---- src/declarative/qml/v8/qv8qobjectwrapper_p.h | 2 + 6 files changed, 94 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/declarative/qml/ftw/qmetaobjectbuilder.cpp b/src/declarative/qml/ftw/qmetaobjectbuilder.cpp index f5e8369ebc..e52b9e1172 100644 --- a/src/declarative/qml/ftw/qmetaobjectbuilder.cpp +++ b/src/declarative/qml/ftw/qmetaobjectbuilder.cpp @@ -155,6 +155,7 @@ struct QMetaObjectPrivate int enumeratorCount, enumeratorData; int constructorCount, constructorData; int flags; + int signalCount; }; static inline const QMetaObjectPrivate *priv(const uint* data) @@ -1206,7 +1207,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, QMetaObjectPrivate *pmeta = reinterpret_cast(buf + size); int pmetaSize = size; - dataIndex = 13; // Number of fields in the QMetaObjectPrivate. + dataIndex = 14; // Number of fields in the QMetaObjectPrivate. for (index = 0; index < d->properties.size(); ++index) { if (d->properties[index].notifySignal != -1) { hasNotifySignals = true; @@ -1214,9 +1215,10 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, } } if (buf) { - pmeta->revision = 3; + pmeta->revision = 4; pmeta->flags = d->flags; pmeta->className = 0; // Class name is always the first string. + //pmeta->signalCount is handled in the "output method loop" as an optimization. pmeta->classInfoCount = d->classInfoNames.size(); pmeta->classInfoData = dataIndex; @@ -1274,7 +1276,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, } // Reset the current data position to just past the QMetaObjectPrivate. - dataIndex = 13; + dataIndex = 14; // Add the class name to the string table. int offset = 0; @@ -1312,6 +1314,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, data[dataIndex + 2] = ret; data[dataIndex + 3] = tag; data[dataIndex + 4] = attrs; + if (method->methodType() == QMetaMethod::Signal) + pmeta->signalCount++; } dataIndex += 5; } diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 406e43fc21..05232d981a 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -313,10 +313,14 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb allowedRevisionCache.append(0); int methodCount = metaObject->methodCount(); + Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4); + int signalCount = QMetaObjectPrivate::get(metaObject)->signalCount; // 3 to block the destroyed signal and the deleteLater() slot int methodOffset = qMax(3, metaObject->methodOffset()); methodIndexCache.resize(methodCount - methodIndexCacheStart); + signalHandlerIndexCache.resize(signalCount); + int signalHandlerIndex = 0; for (int ii = methodOffset; ii < methodCount; ++ii) { QMetaMethod m = metaObject->method(ii); if (m.access() == QMetaMethod::Private) @@ -329,6 +333,7 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb while (*cptr != '(') { Q_ASSERT(*cptr != 0); utf8 |= *cptr & 0x80; ++cptr; } Data *data = &methodIndexCache[ii - methodIndexCacheStart]; + Data *sigdata = 0; data->lazyLoad(m); @@ -342,6 +347,12 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb data->metaObjectOffset = allowedRevisionCache.count() - 1; + if (data->isSignal()) { + sigdata = &signalHandlerIndexCache[signalHandlerIndex]; + *sigdata = *data; + sigdata->flags |= Data::IsSignalHandler; + } + Data *old = 0; if (utf8) { @@ -349,11 +360,33 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb if (Data **it = stringCache.value(methodName)) old = *it; stringCache.insert(methodName, data); + + if (data->isSignal()) { + QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1)); + stringCache.insert(on, sigdata); + ++signalHandlerIndex; + } } else { QHashedCStringRef methodName(signature, cptr - signature); if (Data **it = stringCache.value(methodName)) old = *it; stringCache.insert(methodName, data); + + if (data->isSignal()) { + int length = methodName.length(); + + char str[length + 3]; + str[0] = 'o'; + str[1] = 'n'; + str[2] = toupper(signature[0]); + if (length > 1) + memcpy(&str[3], &signature[1], length - 1); + str[length + 2] = '\0'; + + QHashedString on(QString::fromLatin1(str)); + stringCache.insert(on, sigdata); + ++signalHandlerIndex; + } } if (old) { diff --git a/src/declarative/qml/qdeclarativepropertycache_p.h b/src/declarative/qml/qdeclarativepropertycache_p.h index 8a1da1929c..33565c4d45 100644 --- a/src/declarative/qml/qdeclarativepropertycache_p.h +++ b/src/declarative/qml/qdeclarativepropertycache_p.h @@ -104,9 +104,10 @@ public: IsSignal = 0x00008000, // Function is a signal IsVMESignal = 0x00010000, // Signal was added by QML IsV8Function = 0x00020000, // Function takes QDeclarativeV8Function* args + IsSignalHandler = 0x00040000, // Function is a signal handler // Internal QDeclarativePropertyCache flags - NotFullyResolved = 0x00040000 // True if the type data is to be lazily resolved + NotFullyResolved = 0x00080000 // True if the type data is to be lazily resolved }; Q_DECLARE_FLAGS(Flags, Flag) @@ -133,6 +134,7 @@ public: bool isSignal() const { return flags & IsSignal; } bool isVMESignal() const { return flags & IsVMESignal; } bool isV8Function() const { return flags & IsV8Function; } + bool isSignalHandler() const { return flags & IsSignalHandler; } union { int propType; // When !NotFullyResolved @@ -221,6 +223,7 @@ private: IndexCache propertyIndexCache; IndexCache methodIndexCache; + IndexCache signalHandlerIndexCache; StringCache stringCache; AllowedRevisionCache allowedRevisionCache; v8::Persistent constructor; diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h index bd5f360748..ab4da423ee 100644 --- a/src/declarative/qml/v8/qv8engine_p.h +++ b/src/declarative/qml/v8/qv8engine_p.h @@ -135,7 +135,7 @@ public: QV8ObjectResource(QV8Engine *engine) : engine(engine) { Q_ASSERT(engine); } enum ResourceType { ContextType, QObjectType, TypeType, ListType, VariantType, ValueTypeType, XMLHttpRequestType, DOMNodeType, SQLDatabaseType, - ListModelType, Context2DType, ParticleDataType }; + ListModelType, Context2DType, ParticleDataType, SignalHandlerType }; virtual ResourceType resourceType() const = 0; QV8Engine *engine; diff --git a/src/declarative/qml/v8/qv8qobjectwrapper.cpp b/src/declarative/qml/v8/qv8qobjectwrapper.cpp index 52e106494c..bf8dcea51b 100644 --- a/src/declarative/qml/v8/qv8qobjectwrapper.cpp +++ b/src/declarative/qml/v8/qv8qobjectwrapper.cpp @@ -109,6 +109,16 @@ public: QV8QObjectWrapper *wrapper; }; +class QV8SignalHandlerResource : public QV8ObjectResource +{ + V8_RESOURCE_TYPE(SignalHandlerType) +public: + QV8SignalHandlerResource(QV8Engine *engine, QObject *object, int index); + + QDeclarativeGuard object; + int index; +}; + namespace { struct MetaCallArgument { inline MetaCallArgument(); @@ -152,6 +162,11 @@ QV8QObjectResource::QV8QObjectResource(QV8Engine *engine, QObject *object) { } +QV8SignalHandlerResource::QV8SignalHandlerResource(QV8Engine *engine, QObject *object, int index) +: QV8ObjectResource(engine), object(object), index(index) +{ +} + static QAtomicInt objectIdCounter(1); QV8QObjectWrapper::QV8QObjectWrapper() @@ -177,6 +192,7 @@ void QV8QObjectWrapper::destroy() qPersistentDispose(m_hiddenObject); qPersistentDispose(m_destroySymbol); qPersistentDispose(m_toStringSymbol); + qPersistentDispose(m_signalHandlerConstructor); qPersistentDispose(m_methodConstructor); qPersistentDispose(m_constructor); } @@ -278,10 +294,21 @@ void QV8QObjectWrapper::init(QV8Engine *engine) m_methodConstructor = qPersistentNew(createFn); } + v8::Local connect = V8FUNCTION(Connect, engine); + v8::Local disconnect = V8FUNCTION(Disconnect, engine); + + { + v8::Local ft = v8::FunctionTemplate::New(); + ft->InstanceTemplate()->SetHasExternalResource(true); + ft->PrototypeTemplate()->Set(v8::String::New("connect"), connect, v8::DontEnum); + ft->PrototypeTemplate()->Set(v8::String::New("disconnect"), disconnect, v8::DontEnum); + m_signalHandlerConstructor = qPersistentNew(ft->GetFunction()); + } + { v8::Local prototype = engine->global()->Get(v8::String::New("Function"))->ToObject()->Get(v8::String::New("prototype"))->ToObject(); - prototype->Set(v8::String::New("connect"), V8FUNCTION(Connect, engine), v8::DontEnum); - prototype->Set(v8::String::New("disconnect"), V8FUNCTION(Disconnect, engine), v8::DontEnum); + prototype->Set(v8::String::New("connect"), connect, v8::DontEnum); + prototype->Set(v8::String::New("disconnect"), disconnect, v8::DontEnum); } } @@ -461,6 +488,11 @@ v8::Handle QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject return ((QDeclarativeVMEMetaObject *)(object->metaObject()))->vmeMethod(result->coreIndex); } else if (result->isV8Function()) { return MethodClosure::createWithGlobal(engine, object, objectHandle, result->coreIndex); + } else if (result->isSignalHandler()) { + v8::Local handler = engine->qobjectWrapper()->m_signalHandlerConstructor->NewInstance(); + QV8SignalHandlerResource *r = new QV8SignalHandlerResource(engine, object, result->coreIndex); + handler->SetExternalResource(r); + return handler; } else { return MethodClosure::create(engine, object, objectHandle, result->coreIndex); } @@ -998,6 +1030,17 @@ v8::Handle QV8QObjectWrapper::newQObject(QObject *object) } } +QPair QV8QObjectWrapper::ExtractQtSignal(QV8Engine *engine, v8::Handle object) +{ + if (object->IsFunction()) + return ExtractQtMethod(engine, v8::Handle::Cast(object)); + + if (QV8SignalHandlerResource *resource = v8_resource_cast(object)) + return qMakePair(resource->object.data(), resource->index); + + return qMakePair((QObject *)0, -1); +} + QPair QV8QObjectWrapper::ExtractQtMethod(QV8Engine *engine, v8::Handle function) { v8::ScriptOrigin origin = function->GetScriptOrigin(); @@ -1166,10 +1209,7 @@ v8::Handle QV8QObjectWrapper::Connect(const v8::Arguments &args) QV8Engine *engine = V8ENGINE(); - if (!args.This()->IsFunction()) - V8THROW_ERROR("Function.prototype.connect: this object is not a signal"); - - QPair signalInfo = ExtractQtMethod(engine, v8::Handle::Cast(args.This())); + QPair signalInfo = ExtractQtSignal(engine, args.This()); QObject *signalObject = signalInfo.first; int signalIndex = signalInfo.second; @@ -1228,10 +1268,7 @@ v8::Handle QV8QObjectWrapper::Disconnect(const v8::Arguments &args) QV8Engine *engine = V8ENGINE(); - if (!args.This()->IsFunction()) - V8THROW_ERROR("Function.prototype.disconnect: this object is not a signal"); - - QPair signalInfo = ExtractQtMethod(engine, v8::Handle::Cast(args.This())); + QPair signalInfo = ExtractQtSignal(engine, args.This()); QObject *signalObject = signalInfo.first; int signalIndex = signalInfo.second; diff --git a/src/declarative/qml/v8/qv8qobjectwrapper_p.h b/src/declarative/qml/v8/qv8qobjectwrapper_p.h index d0a489bed8..be118a9c34 100644 --- a/src/declarative/qml/v8/qv8qobjectwrapper_p.h +++ b/src/declarative/qml/v8/qv8qobjectwrapper_p.h @@ -111,11 +111,13 @@ private: static v8::Handle Disconnect(const v8::Arguments &args); static v8::Handle Invoke(const v8::Arguments &args); static QPair ExtractQtMethod(QV8Engine *, v8::Handle); + static QPair ExtractQtSignal(QV8Engine *, v8::Handle); QV8Engine *m_engine; quint32 m_id; v8::Persistent m_constructor; v8::Persistent m_methodConstructor; + v8::Persistent m_signalHandlerConstructor; v8::Persistent m_toStringSymbol; v8::Persistent m_destroySymbol; QHashedV8String m_toStringString; -- cgit v1.2.3 From 6080375fed90c09bfabb96a0319817f14f693b05 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Mon, 22 Aug 2011 15:51:28 +1000 Subject: Allow conversion of QObject Module API to QVariant This commit adds a conversion codepath for QV8TypeResource to QVariant where the resource contains a QObject module API. This allows such a module API to be used as the "target" in a Connections element. Task-number: QTBUG-20937 Change-Id: I9214b531968f2e6981a86e643859a97297c6a02a Reviewed-on: http://codereview.qt.nokia.com/3286 Reviewed-by: Chris Adams Reviewed-by: Qt Sanity Bot --- src/declarative/qml/v8/qv8engine.cpp | 3 ++- src/declarative/qml/v8/qv8typewrapper.cpp | 28 ++++++++++++++++++++++++++++ src/declarative/qml/v8/qv8typewrapper_p.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp index 8eaf9024ea..5b74f48170 100644 --- a/src/declarative/qml/v8/qv8engine.cpp +++ b/src/declarative/qml/v8/qv8engine.cpp @@ -208,7 +208,6 @@ QVariant QV8Engine::toVariant(v8::Handle value, int typeHint) if (r) { switch (r->resourceType()) { case QV8ObjectResource::ContextType: - case QV8ObjectResource::TypeType: case QV8ObjectResource::XMLHttpRequestType: case QV8ObjectResource::DOMNodeType: case QV8ObjectResource::SQLDatabaseType: @@ -216,6 +215,8 @@ QVariant QV8Engine::toVariant(v8::Handle value, int typeHint) case QV8ObjectResource::Context2DType: case QV8ObjectResource::ParticleDataType: return QVariant(); + case QV8ObjectResource::TypeType: + return m_typeWrapper.toVariant(r); case QV8ObjectResource::QObjectType: return qVariantFromValue(m_qobjectWrapper.toQObject(r)); case QV8ObjectResource::ListType: diff --git a/src/declarative/qml/v8/qv8typewrapper.cpp b/src/declarative/qml/v8/qv8typewrapper.cpp index f46aaab320..c89d5ab8ae 100644 --- a/src/declarative/qml/v8/qv8typewrapper.cpp +++ b/src/declarative/qml/v8/qv8typewrapper.cpp @@ -128,6 +128,34 @@ v8::Local QV8TypeWrapper::newObject(QObject *o, QDeclarativeTypeName return rv; } +QVariant QV8TypeWrapper::toVariant(QV8ObjectResource *r) +{ + Q_ASSERT(r->resourceType() == QV8ObjectResource::TypeType); + QV8TypeResource *resource = static_cast(r); + QV8Engine *v8engine = resource->engine; + + if (resource->typeNamespace) { + if (QDeclarativeMetaType::ModuleApiInstance *moduleApi = resource->typeNamespace->moduleApi(resource->importNamespace)) { + if (moduleApi->scriptCallback) { + moduleApi->scriptApi = moduleApi->scriptCallback(v8engine->engine(), v8engine->engine()); + moduleApi->scriptCallback = 0; + moduleApi->qobjectCallback = 0; + } else if (moduleApi->qobjectCallback) { + moduleApi->qobjectApi = moduleApi->qobjectCallback(v8engine->engine(), v8engine->engine()); + moduleApi->scriptCallback = 0; + moduleApi->qobjectCallback = 0; + } + + if (moduleApi->qobjectApi) { + return QVariant::fromValue(moduleApi->qobjectApi); + } + } + } + + // only QObject Module API can be converted to a variant. + return QVariant(); +} + v8::Handle QV8TypeWrapper::Getter(v8::Local property, const v8::AccessorInfo &info) { diff --git a/src/declarative/qml/v8/qv8typewrapper_p.h b/src/declarative/qml/v8/qv8typewrapper_p.h index 2e79946a6e..f9309f8e28 100644 --- a/src/declarative/qml/v8/qv8typewrapper_p.h +++ b/src/declarative/qml/v8/qv8typewrapper_p.h @@ -75,6 +75,7 @@ public: v8::Local newObject(QObject *, QDeclarativeType *, TypeNameMode = IncludeEnums); v8::Local newObject(QObject *, QDeclarativeTypeNameCache *, const void *, TypeNameMode = IncludeEnums); + QVariant toVariant(QV8ObjectResource *); private: static v8::Handle Getter(v8::Local property, -- cgit v1.2.3 From 23c826303436f438aaac6f3edc87e1d5b22ee549 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 1 Sep 2011 13:52:23 +1000 Subject: Don't emit attached add() and remove() for moved items Regression from 6fbc4b7e7e5aed8739ca1143e0fc1e38b8c8e17a Change-Id: I0bcd55548dca1559deea0d66112e7cdeb3da4ed9 Reviewed-on: http://codereview.qt.nokia.com/4023 Reviewed-by: Bea Lam Reviewed-by: Qt Sanity Bot --- src/declarative/items/qsggridview.cpp | 3 ++- src/declarative/items/qsgitemview.cpp | 6 ++++-- src/declarative/items/qsglistview.cpp | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp index 50ea86ab04..1d4e8313b4 100644 --- a/src/declarative/items/qsggridview.cpp +++ b/src/declarative/items/qsggridview.cpp @@ -1792,7 +1792,8 @@ bool QSGGridViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::Inser if (!item) item = createItem(modelIndex + i); visibleItems.insert(index, item); - addedItems->append(item); + if (!change.isMove()) + addedItems->append(item); colPos += colSize(); if (colPos > colSize() * (columns-1)) { colPos = 0; diff --git a/src/declarative/items/qsgitemview.cpp b/src/declarative/items/qsgitemview.cpp index cd598e9a28..401a17e2b7 100644 --- a/src/declarative/items/qsgitemview.cpp +++ b/src/declarative/items/qsgitemview.cpp @@ -1487,8 +1487,10 @@ bool QSGItemViewPrivate::applyModelChanges() } else { // removed item removedVisible = true; - item->attached->emitRemove(); - if (item->attached->delayRemove()) { + if (!removals[i].isMove()) + item->attached->emitRemove(); + + if (item->attached->delayRemove() && !removals[i].isMove()) { item->index = -1; QObject::connect(item->attached, SIGNAL(delayRemoveChanged()), q, SLOT(destroyRemoved()), Qt::QueuedConnection); ++it; diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp index 73bbd87e2a..321c66c41a 100644 --- a/src/declarative/items/qsglistview.cpp +++ b/src/declarative/items/qsglistview.cpp @@ -2164,7 +2164,8 @@ bool QSGListViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::Inser item = createItem(modelIndex + i); visibleItems.insert(insertionIdx, item); - addedItems->append(item); + if (!change.isMove()) + addedItems->append(item); pos -= item->size() + spacing; index++; } @@ -2182,7 +2183,8 @@ bool QSGListViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::Inser item = createItem(modelIndex + i); visibleItems.insert(index, item); - addedItems->append(item); + if (!change.isMove()) + addedItems->append(item); pos += item->size() + spacing; ++index; } -- cgit v1.2.3 From e824620e9306d665b81cb12e167f50fb1090fddc Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 2 Sep 2011 18:04:00 +1000 Subject: Ensure layout is done after delayed deletion of items Regression from 1dd8b509074ba60da671f7671f8cf09c3fc001ae Change-Id: I5957444e2f1493aa8fbf3b532fd1ef704deec50c Reviewed-on: http://codereview.qt.nokia.com/4118 Reviewed-by: Bea Lam --- src/declarative/items/qsgitemview.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/declarative/items/qsgitemview.cpp b/src/declarative/items/qsgitemview.cpp index 401a17e2b7..141be4f0dd 100644 --- a/src/declarative/items/qsgitemview.cpp +++ b/src/declarative/items/qsgitemview.cpp @@ -775,6 +775,7 @@ void QSGItemView::destroyRemoved() // Correct the positioning of the items d->updateSections(); + d->forceLayout = true; d->layout(); } -- cgit v1.2.3 From 3e18093886c567d0e83bac87185590bbc5eb9246 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Wed, 31 Aug 2011 17:40:42 +0200 Subject: Exported QSGShaderEffectMesh. Reintroduced the possibility to set the ShaderEffect::mesh property to any object deriving from QSGShaderEffectMesh. Change-Id: Idf91b2289d4e7b8fd12993a4a2bc1647dfba0ae0 Reviewed-on: http://codereview.qt.nokia.com/4003 Reviewed-by: Qt Sanity Bot Reviewed-by: Gunnar Sletta --- src/declarative/items/qsgitemsmodule.cpp | 4 +- src/declarative/items/qsgshadereffect.cpp | 72 ++++++++------------------- src/declarative/items/qsgshadereffect_p.h | 2 +- src/declarative/items/qsgshadereffectmesh.cpp | 42 ++++++++++++++-- src/declarative/items/qsgshadereffectmesh_p.h | 2 +- 5 files changed, 64 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/declarative/items/qsgitemsmodule.cpp b/src/declarative/items/qsgitemsmodule.cpp index 9359906f25..bca0437eb5 100644 --- a/src/declarative/items/qsgitemsmodule.cpp +++ b/src/declarative/items/qsgitemsmodule.cpp @@ -174,8 +174,8 @@ static void qt_sgitems_defineModule(const char *uri, int major, int minor) qmlRegisterType("QtQuick", 2, 0, "ShaderEffectItem"); // TODO: Remove after grace period. qmlRegisterType("QtQuick", 2, 0, "ShaderEffect"); qmlRegisterType("QtQuick", 2, 0, "ShaderEffectSource"); - qmlRegisterUncreatableType("QtQuick", 2, 0, "ShaderEffectMesh", QSGShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh.")); // TODO: Remove after grace period. - qmlRegisterType("QtQuick", 2, 0, "GridMesh"); // TODO: Remove after grace period. + qmlRegisterUncreatableType("QtQuick", 2, 0, "ShaderEffectMesh", QSGShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh.")); + qmlRegisterType("QtQuick", 2, 0, "GridMesh"); qmlRegisterUncreatableType("QtQuick", 2, 0, "PaintedItem", QSGPaintedItem::tr("Cannot create instance of abstract class PaintedItem")); diff --git a/src/declarative/items/qsgshadereffect.cpp b/src/declarative/items/qsgshadereffect.cpp index c5ea64dcd2..015d724c1e 100644 --- a/src/declarative/items/qsgshadereffect.cpp +++ b/src/declarative/items/qsgshadereffect.cpp @@ -188,7 +188,7 @@ QSGShaderEffectItem::QSGShaderEffectItem(QSGItem *parent) QSGShaderEffect::QSGShaderEffect(QSGItem *parent) : QSGItem(parent) , m_meshResolution(1, 1) - , m_deprecatedMesh(0) + , m_mesh(0) , m_cullMode(NoCulling) , m_blending(true) , m_dirtyData(true) @@ -272,63 +272,34 @@ void QSGShaderEffect::setBlending(bool enable) } /*! - \qmlproperty size QtQuick2::ShaderEffect::mesh + \qmlproperty variant QtQuick2::ShaderEffect::mesh - This property holds the mesh resolution. The default resolution is 1x1 - which is the minimum and corresponds to a mesh with four vertices. - For non-linear vertex transformations, you probably want to set the - resolution higher. + This property defines the mesh used to draw the ShaderEffect. It can hold + any mesh object deriving from \l QSGShaderEffectMesh, such as \l GridMesh. + If a size value is assigned to this property, the ShaderEffect implicitly + uses a \l GridMesh with the value as + \l{GridMesh::resolution}{mesh resolution}. By default, this property is + the size 1x1. - \row - \o \image declarative-gridmesh.png - \o \qml - import QtQuick 2.0 - - ShaderEffect { - width: 200 - height: 200 - mesh: Qt.size(20, 20) - property variant source: Image { - source: "qt-logo.png" - sourceSize { width: 200; height: 200 } - smooth: true - } - vertexShader: " - uniform highp mat4 qt_Matrix; - attribute highp vec4 qt_Vertex; - attribute highp vec2 qt_MultiTexCoord0; - varying highp vec2 qt_TexCoord0; - uniform highp float width; - void main() { - highp vec4 pos = qt_Vertex; - highp float d = .5 * smoothstep(0., 1., qt_MultiTexCoord0.y); - pos.x = width * mix(d, 1.0 - d, qt_MultiTexCoord0.x); - gl_Position = qt_Matrix * pos; - qt_TexCoord0 = qt_MultiTexCoord0; - }" - } - \endqml - \endrow + \sa GridMesh */ QVariant QSGShaderEffect::mesh() const { - return m_deprecatedMesh ? qVariantFromValue(static_cast(m_deprecatedMesh)) - : qVariantFromValue(m_meshResolution); + return m_mesh ? qVariantFromValue(static_cast(m_mesh)) + : qVariantFromValue(m_meshResolution); } void QSGShaderEffect::setMesh(const QVariant &mesh) { - // TODO: Replace QVariant with QSize after grace period. QSGShaderEffectMesh *newMesh = qobject_cast(qVariantValue(mesh)); - if (newMesh && newMesh == m_deprecatedMesh) + if (newMesh && newMesh == m_mesh) return; - if (m_deprecatedMesh) - disconnect(m_deprecatedMesh, SIGNAL(geometryChanged()), this, 0); - m_deprecatedMesh = newMesh; - if (m_deprecatedMesh) { - qWarning("ShaderEffect: Setting the mesh to something other than a size is deprecated."); - connect(m_deprecatedMesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry())); + if (m_mesh) + disconnect(m_mesh, SIGNAL(geometryChanged()), this, 0); + m_mesh = newMesh; + if (m_mesh) { + connect(m_mesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry())); } else { if (qVariantCanConvert(mesh)) { m_meshResolution = mesh.toSize(); @@ -344,7 +315,7 @@ void QSGShaderEffect::setMesh(const QVariant &mesh) } } if (!ok) - qWarning("ShaderEffect: mesh resolution must be a size."); + qWarning("ShaderEffect: mesh property must be size or object deriving from QSGShaderEffectMesh."); } m_defaultMesh.setResolution(m_meshResolution); } @@ -505,10 +476,9 @@ void QSGShaderEffect::updateProperties() lookThroughShaderCode(vertexCode); lookThroughShaderCode(fragmentCode); - // TODO: Remove !m_deprecatedMesh check after grace period. - if (!m_deprecatedMesh && !m_source.attributeNames.contains(qt_position_attribute_name)) + if (!m_mesh && !m_source.attributeNames.contains(qt_position_attribute_name)) qWarning("QSGShaderEffect: Missing reference to \'%s\'.", qt_position_attribute_name); - if (!m_deprecatedMesh && !m_source.attributeNames.contains(qt_texcoord_attribute_name)) + if (!m_mesh && !m_source.attributeNames.contains(qt_texcoord_attribute_name)) qWarning("QSGShaderEffect: Missing reference to \'%s\'.", qt_texcoord_attribute_name); if (!m_source.respectsMatrix) qWarning("QSGShaderEffect: Missing reference to \'qt_Matrix\'."); @@ -594,7 +564,7 @@ QSGNode *QSGShaderEffect::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData node->setFlag(QSGNode::OwnsGeometry, false); QSGGeometry *geometry = node->geometry(); QRectF rect(0, 0, width(), height()); - QSGShaderEffectMesh *mesh = m_deprecatedMesh ? m_deprecatedMesh : &m_defaultMesh; + QSGShaderEffectMesh *mesh = m_mesh ? m_mesh : &m_defaultMesh; geometry = mesh->updateGeometry(geometry, m_source.attributeNames, rect); if (!geometry) { diff --git a/src/declarative/items/qsgshadereffect_p.h b/src/declarative/items/qsgshadereffect_p.h index 0cced9a229..9fe9f13251 100644 --- a/src/declarative/items/qsgshadereffect_p.h +++ b/src/declarative/items/qsgshadereffect_p.h @@ -131,7 +131,7 @@ private: QSGShaderEffectProgram m_source; QSize m_meshResolution; - QSGShaderEffectMesh *m_deprecatedMesh; // TODO: Remove after grace period. + QSGShaderEffectMesh *m_mesh; QSGGridMesh m_defaultMesh; CullMode m_cullMode; diff --git a/src/declarative/items/qsgshadereffectmesh.cpp b/src/declarative/items/qsgshadereffectmesh.cpp index 6d3d17e4ff..53fd917e06 100644 --- a/src/declarative/items/qsgshadereffectmesh.cpp +++ b/src/declarative/items/qsgshadereffectmesh.cpp @@ -51,8 +51,9 @@ QSGShaderEffectMesh::QSGShaderEffectMesh(QObject *parent) } /*! - \class QSGGridMesh - \since 5.0 + \qmlclass GridMesh QSGGridMesh + \inqmlmodule QtQuick 2 + \ingroup qml-utility-elements \brief GridMesh defines a mesh with vertices arranged in a grid. GridMesh defines a rectangular mesh consisting of vertices arranged in an @@ -152,12 +153,47 @@ QSGGeometry *QSGGridMesh::updateGeometry(QSGGeometry *geometry, const QVector Date: Wed, 31 Aug 2011 09:15:05 +0200 Subject: Debugger: Fix indentation & trailing whitespace Change-Id: I4b85b205a359e4c3adc1fcb6682945724a0910c5 Reviewed-by: Aurindam Jana Reviewed-on: http://codereview.qt.nokia.com/3937 Reviewed-by: Kai Koehne --- .../debugger/qdeclarativedebugclient.cpp | 16 ++-- .../debugger/qdeclarativedebugserver.cpp | 10 +- .../debugger/qdeclarativedebugservice.cpp | 42 ++++----- .../debugger/qdeclarativedebugtrace.cpp | 12 +-- .../debugger/qdeclarativeenginedebug.cpp | 104 ++++++++++----------- .../debugger/qdeclarativeenginedebug_p.h | 41 ++++---- .../debugger/qdeclarativeenginedebugservice.cpp | 46 ++++----- src/declarative/debugger/qpacketprotocol.cpp | 26 +++--- src/declarative/debugger/qpacketprotocol_p.h | 2 +- 9 files changed, 150 insertions(+), 149 deletions(-) (limited to 'src') diff --git a/src/declarative/debugger/qdeclarativedebugclient.cpp b/src/declarative/debugger/qdeclarativedebugclient.cpp index d3617b19b5..9853a9ff60 100644 --- a/src/declarative/debugger/qdeclarativedebugclient.cpp +++ b/src/declarative/debugger/qdeclarativedebugclient.cpp @@ -84,7 +84,7 @@ public Q_SLOTS: }; QDeclarativeDebugConnectionPrivate::QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c) -: QObject(c), q(c), protocol(0), gotHello(false) + : QObject(c), q(c), protocol(0), gotHello(false) { protocol = new QPacketProtocol(q, this); QObject::connect(c, SIGNAL(connected()), this, SLOT(connected())); @@ -183,7 +183,7 @@ void QDeclarativeDebugConnectionPrivate::readyRead() pack >> message; QHash::Iterator iter = - plugins.find(name); + plugins.find(name); if (iter == plugins.end()) { qWarning() << "QDeclarativeDebugConnection: Message received for missing plugin" << name; } else { @@ -194,7 +194,7 @@ void QDeclarativeDebugConnectionPrivate::readyRead() } QDeclarativeDebugConnection::QDeclarativeDebugConnection(QObject *parent) -: QTcpSocket(parent), d(new QDeclarativeDebugConnectionPrivate(this)) + : QTcpSocket(parent), d(new QDeclarativeDebugConnectionPrivate(this)) { } @@ -202,8 +202,8 @@ QDeclarativeDebugConnection::~QDeclarativeDebugConnection() { QHash::iterator iter = d->plugins.begin(); for (; iter != d->plugins.end(); ++iter) { - iter.value()->d_func()->connection = 0; - iter.value()->statusChanged(QDeclarativeDebugClient::NotConnected); + iter.value()->d_func()->connection = 0; + iter.value()->statusChanged(QDeclarativeDebugClient::NotConnected); } } @@ -213,13 +213,13 @@ bool QDeclarativeDebugConnection::isConnected() const } QDeclarativeDebugClientPrivate::QDeclarativeDebugClientPrivate() -: connection(0) + : connection(0) { } QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name, - QDeclarativeDebugConnection *parent) -: QObject(*(new QDeclarativeDebugClientPrivate), parent) + QDeclarativeDebugConnection *parent) + : QObject(*(new QDeclarativeDebugClientPrivate), parent) { Q_D(QDeclarativeDebugClient); d->name = name; diff --git a/src/declarative/debugger/qdeclarativedebugserver.cpp b/src/declarative/debugger/qdeclarativedebugserver.cpp index e7785d0f90..1963dcecfd 100644 --- a/src/declarative/debugger/qdeclarativedebugserver.cpp +++ b/src/declarative/debugger/qdeclarativedebugserver.cpp @@ -120,7 +120,7 @@ void QDeclarativeDebugServerPrivate::advertisePlugins() } QDeclarativeDebugServerConnection *QDeclarativeDebugServerPrivate::loadConnectionPlugin( - const QString &pluginName) + const QString &pluginName) { QStringList pluginCandidates; const QStringList paths = QCoreApplication::libraryPaths(); @@ -178,9 +178,9 @@ QDeclarativeDebugServer *QDeclarativeDebugServer::instance() if (!appD->qmljsDebugArgumentsString().isEmpty()) { if (!QDeclarativeEnginePrivate::qml_debugging_enabled) { const QString message = - QString::fromAscii("QDeclarativeDebugServer: Ignoring \"-qmljsdebugger=%1\". " - "Debugging has not been enabled.").arg( - appD->qmljsDebugArgumentsString()); + QString::fromAscii("QDeclarativeDebugServer: Ignoring \"-qmljsdebugger=%1\". " + "Debugging has not been enabled.").arg( + appD->qmljsDebugArgumentsString()); qWarning("%s", qPrintable(message)); return 0; } @@ -231,7 +231,7 @@ QDeclarativeDebugServer *QDeclarativeDebugServer::instance() } QDeclarativeDebugServer::QDeclarativeDebugServer() -: QObject(*(new QDeclarativeDebugServerPrivate)) + : QObject(*(new QDeclarativeDebugServerPrivate)) { } diff --git a/src/declarative/debugger/qdeclarativedebugservice.cpp b/src/declarative/debugger/qdeclarativedebugservice.cpp index 7274211bf2..ecd9e0fb85 100644 --- a/src/declarative/debugger/qdeclarativedebugservice.cpp +++ b/src/declarative/debugger/qdeclarativedebugservice.cpp @@ -49,12 +49,12 @@ QT_BEGIN_NAMESPACE QDeclarativeDebugServicePrivate::QDeclarativeDebugServicePrivate() -: server(0) + : server(0) { } QDeclarativeDebugService::QDeclarativeDebugService(const QString &name, QObject *parent) -: QObject(*(new QDeclarativeDebugServicePrivate), parent) + : QObject(*(new QDeclarativeDebugServicePrivate), parent) { Q_D(QDeclarativeDebugService); d->name = name; @@ -114,21 +114,21 @@ QDeclarativeDebugService::Status QDeclarativeDebugService::status() const namespace { - struct ObjectReference - { - QPointer object; - int id; - }; +struct ObjectReference +{ + QPointer object; + int id; +}; - struct ObjectReferenceHash - { - ObjectReferenceHash() : nextId(0) {} +struct ObjectReferenceHash +{ + ObjectReferenceHash() : nextId(0) {} - QHash objects; - QHash ids; + QHash objects; + QHash ids; - int nextId; - }; + int nextId; +}; } Q_GLOBAL_STATIC(ObjectReferenceHash, objectReferenceHash); @@ -144,8 +144,8 @@ int QDeclarativeDebugService::idForObject(QObject *object) return -1; ObjectReferenceHash *hash = objectReferenceHash(); - QHash::Iterator iter = - hash->objects.find(object); + QHash::Iterator iter = + hash->objects.find(object); if (iter == hash->objects.end()) { int id = hash->nextId++; @@ -162,7 +162,7 @@ int QDeclarativeDebugService::idForObject(QObject *object) hash->ids.insert(id, object); iter->object = object; iter->id = id; - } + } return iter->id; } @@ -180,8 +180,8 @@ QObject *QDeclarativeDebugService::objectForId(int id) return 0; - QHash::Iterator objIter = - hash->objects.find(*iter); + QHash::Iterator objIter = + hash->objects.find(*iter); Q_ASSERT(objIter != hash->objects.end()); if (objIter->object == 0) { @@ -213,8 +213,8 @@ QString QDeclarativeDebugService::objectToString(QObject *obj) if(objectName.isEmpty()) objectName = QLatin1String(""); - QString rv = QString::fromUtf8(obj->metaObject()->className()) + - QLatin1String(": ") + objectName; + QString rv = QString::fromUtf8(obj->metaObject()->className()) + + QLatin1String(": ") + objectName; return rv; } diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp index 0a46d68aa7..dc1a34d733 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace.cpp +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -64,8 +64,8 @@ QByteArray QDeclarativeDebugData::toByteArray() const } QDeclarativeDebugTrace::QDeclarativeDebugTrace() -: QDeclarativeDebugService(QLatin1String("CanvasFrameRate")), - m_enabled(false), m_deferredSend(true), m_messageReceived(false) + : QDeclarativeDebugService(QLatin1String("CanvasFrameRate")), + m_enabled(false), m_deferredSend(true), m_messageReceived(false) { m_timer.start(); if (status() == Enabled) { @@ -77,19 +77,19 @@ QDeclarativeDebugTrace::QDeclarativeDebugTrace() void QDeclarativeDebugTrace::addEvent(EventType t) { - if (QDeclarativeDebugService::isDebuggingEnabled()) + if (QDeclarativeDebugService::isDebuggingEnabled()) traceInstance()->addEventImpl(t); } void QDeclarativeDebugTrace::startRange(RangeType t) { - if (QDeclarativeDebugService::isDebuggingEnabled()) + if (QDeclarativeDebugService::isDebuggingEnabled()) traceInstance()->startRangeImpl(t); } void QDeclarativeDebugTrace::rangeData(RangeType t, const QString &data) { - if (QDeclarativeDebugService::isDebuggingEnabled()) + if (QDeclarativeDebugService::isDebuggingEnabled()) traceInstance()->rangeDataImpl(t, data); } @@ -113,7 +113,7 @@ void QDeclarativeDebugTrace::rangeLocation(RangeType t, const QUrl &fileName, in void QDeclarativeDebugTrace::endRange(RangeType t) { - if (QDeclarativeDebugService::isDebuggingEnabled()) + if (QDeclarativeDebugService::isDebuggingEnabled()) traceInstance()->endRangeImpl(t); } diff --git a/src/declarative/debugger/qdeclarativeenginedebug.cpp b/src/declarative/debugger/qdeclarativeenginedebug.cpp index 85ce7108dd..836885db2a 100644 --- a/src/declarative/debugger/qdeclarativeenginedebug.cpp +++ b/src/declarative/debugger/qdeclarativeenginedebug.cpp @@ -95,8 +95,8 @@ public: }; QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, - QDeclarativeEngineDebugPrivate *p) -: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p) + QDeclarativeEngineDebugPrivate *p) + : QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p) { } @@ -113,7 +113,7 @@ void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data) } QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c) -: client(new QDeclarativeEngineDebugClient(c, this)), nextId(0) + : client(new QDeclarativeEngineDebugClient(c, this)), nextId(0) { } @@ -172,7 +172,7 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclara } void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, - QDeclarativeDebugRootContextQuery *q) + QDeclarativeDebugRootContextQuery *q) { if (c && q) { QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c); @@ -205,7 +205,7 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclara } void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o, - bool simple) + bool simple) { QDeclarativeEngineDebugService::QDeclarativeObjectData data; ds >> data; @@ -243,22 +243,22 @@ void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugOb prop.m_hasNotifySignal = data.hasNotifySignal; prop.m_valueTypeName = data.valueTypeName; switch (data.type) { - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Basic: - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::List: - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::SignalProperty: - { - prop.m_value = data.value; - break; - } - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Object: - { - QDeclarativeDebugObjectReference obj; - obj.m_debugId = prop.m_value.toInt(); - prop.m_value = QVariant::fromValue(obj); - break; - } - case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Unknown: - break; + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Basic: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::List: + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::SignalProperty: + { + prop.m_value = data.value; + break; + } + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Object: + { + QDeclarativeDebugObjectReference obj; + obj.m_debugId = prop.m_value.toInt(); + prop.m_value = QVariant::fromValue(obj); + break; + } + case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Unknown: + break; } o.m_properties << prop; } @@ -332,7 +332,7 @@ void QDeclarativeEngineDebugPrivate::message(const QByteArray &data) return; rootContextQuery.remove(queryId); - if (!ds.atEnd()) + if (!ds.atEnd()) decode(ds, query->m_context); query->m_client = 0; @@ -411,7 +411,7 @@ void QDeclarativeEngineDebugPrivate::message(const QByteArray &data) } QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent) -: QObject(*(new QDeclarativeEngineDebugPrivate(client)), parent) + : QObject(*(new QDeclarativeEngineDebugPrivate(client)), parent) { } @@ -580,7 +580,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclar QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() + ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() << false << true; d->client->sendMessage(message); } else { @@ -603,7 +603,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(cons QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() + ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() << true << true; d->client->sendMessage(message); } else { @@ -686,7 +686,7 @@ bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &me } QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent) -: QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1) + : QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1) { } @@ -742,7 +742,7 @@ QString QDeclarativeDebugObjectExpressionWatch::expression() const QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent) -: QObject(parent), m_state(Waiting) + : QObject(parent), m_state(Waiting) { } @@ -765,13 +765,13 @@ void QDeclarativeDebugQuery::setState(State s) } QDeclarativeDebugEnginesQuery::QDeclarativeDebugEnginesQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) + : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) { } QDeclarativeDebugEnginesQuery::~QDeclarativeDebugEnginesQuery() { - if (m_client && m_queryId != -1) + if (m_client && m_queryId != -1) QDeclarativeEngineDebugPrivate::remove(m_client, this); } @@ -781,13 +781,13 @@ QList QDeclarativeDebugEnginesQuery::engines() } QDeclarativeDebugRootContextQuery::QDeclarativeDebugRootContextQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) + : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) { } QDeclarativeDebugRootContextQuery::~QDeclarativeDebugRootContextQuery() { - if (m_client && m_queryId != -1) + if (m_client && m_queryId != -1) QDeclarativeEngineDebugPrivate::remove(m_client, this); } @@ -797,13 +797,13 @@ QDeclarativeDebugContextReference QDeclarativeDebugRootContextQuery::rootContext } QDeclarativeDebugObjectQuery::QDeclarativeDebugObjectQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) + : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) { } QDeclarativeDebugObjectQuery::~QDeclarativeDebugObjectQuery() { - if (m_client && m_queryId != -1) + if (m_client && m_queryId != -1) QDeclarativeEngineDebugPrivate::remove(m_client, this); } @@ -813,13 +813,13 @@ QDeclarativeDebugObjectReference QDeclarativeDebugObjectQuery::object() const } QDeclarativeDebugExpressionQuery::QDeclarativeDebugExpressionQuery(QObject *parent) -: QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) + : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1) { } QDeclarativeDebugExpressionQuery::~QDeclarativeDebugExpressionQuery() { - if (m_client && m_queryId != -1) + if (m_client && m_queryId != -1) QDeclarativeEngineDebugPrivate::remove(m_client, this); } @@ -834,17 +834,17 @@ QVariant QDeclarativeDebugExpressionQuery::result() const } QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference() -: m_debugId(-1) + : m_debugId(-1) { } QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(int debugId) -: m_debugId(debugId) + : m_debugId(debugId) { } QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &o) -: m_debugId(o.m_debugId), m_name(o.m_name) + : m_debugId(o.m_debugId), m_name(o.m_name) { } @@ -866,19 +866,19 @@ QString QDeclarativeDebugEngineReference::name() const } QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference() -: m_debugId(-1), m_contextDebugId(-1) + : m_debugId(-1), m_contextDebugId(-1) { } QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(int debugId) -: m_debugId(debugId), m_contextDebugId(-1) + : m_debugId(debugId), m_contextDebugId(-1) { } QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &o) -: m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString), - m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId), - m_properties(o.m_properties), m_children(o.m_children) + : m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString), + m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId), + m_properties(o.m_properties), m_children(o.m_children) { } @@ -932,18 +932,18 @@ QList QDeclarativeDebugObjectReference::childr } QDeclarativeDebugContextReference::QDeclarativeDebugContextReference() -: m_debugId(-1) + : m_debugId(-1) { } QDeclarativeDebugContextReference::QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &o) -: m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts) + : m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts) { } QDeclarativeDebugContextReference &QDeclarativeDebugContextReference::operator=(const QDeclarativeDebugContextReference &o) { - m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects; + m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects; m_contexts = o.m_contexts; return *this; } @@ -969,12 +969,12 @@ QList QDeclarativeDebugContextReference::cont } QDeclarativeDebugFileReference::QDeclarativeDebugFileReference() -: m_lineNumber(-1), m_columnNumber(-1) + : m_lineNumber(-1), m_columnNumber(-1) { } QDeclarativeDebugFileReference::QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &o) -: m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber) + : m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber) { } @@ -1015,14 +1015,14 @@ void QDeclarativeDebugFileReference::setColumnNumber(int c) } QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference() -: m_objectDebugId(-1), m_hasNotifySignal(false) + : m_objectDebugId(-1), m_hasNotifySignal(false) { } QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &o) -: m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value), - m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding), - m_hasNotifySignal(o.m_hasNotifySignal) + : m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value), + m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding), + m_hasNotifySignal(o.m_hasNotifySignal) { } diff --git a/src/declarative/debugger/qdeclarativeenginedebug_p.h b/src/declarative/debugger/qdeclarativeenginedebug_p.h index 9b70e1c6bc..24d0d85794 100644 --- a/src/declarative/debugger/qdeclarativeenginedebug_p.h +++ b/src/declarative/debugger/qdeclarativeenginedebug_p.h @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef QDECLARATIVEENGINEDEBUG_H #define QDECLARATIVEENGINEDEBUG_H @@ -69,7 +70,7 @@ class QDeclarativeDebugEngineReference; class QDeclarativeEngineDebugPrivate; class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeEngineDebug : public QObject { -Q_OBJECT + Q_OBJECT public: enum Status { NotConnected, Unavailable, Enabled }; @@ -78,28 +79,28 @@ public: Status status() const; QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &, - QObject *parent = 0); + QObject *parent = 0); QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &, - QObject *parent = 0); + QObject *parent = 0); QDeclarativeDebugObjectExpressionWatch *addWatch(const QDeclarativeDebugObjectReference &, const QString &, - QObject *parent = 0); + QObject *parent = 0); QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugObjectReference &, - QObject *parent = 0); + QObject *parent = 0); QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugFileReference &, - QObject *parent = 0); + QObject *parent = 0); void removeWatch(QDeclarativeDebugWatch *watch); QDeclarativeDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0); QDeclarativeDebugRootContextQuery *queryRootContexts(const QDeclarativeDebugEngineReference &, - QObject *parent = 0); - QDeclarativeDebugObjectQuery *queryObject(const QDeclarativeDebugObjectReference &, - QObject *parent = 0); - QDeclarativeDebugObjectQuery *queryObjectRecursive(const QDeclarativeDebugObjectReference &, + QObject *parent = 0); + QDeclarativeDebugObjectQuery *queryObject(const QDeclarativeDebugObjectReference &, QObject *parent = 0); - QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, - const QString &expr, - QObject *parent = 0); + QDeclarativeDebugObjectQuery *queryObjectRecursive(const QDeclarativeDebugObjectReference &, + QObject *parent = 0); + QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, + const QString &expr, + QObject *parent = 0); bool setBindingForObject(int objectDebugId, const QString &propertyName, const QVariant &bindingExpression, bool isLiteralValue, QString source = QString(), int line = -1); @@ -116,7 +117,7 @@ private: class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugWatch : public QObject { -Q_OBJECT + Q_OBJECT public: enum State { Waiting, Active, Inactive, Dead }; @@ -175,14 +176,14 @@ private: class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugQuery : public QObject { -Q_OBJECT + Q_OBJECT public: enum State { Waiting, Error, Completed }; State state() const; bool isWaiting() const; -// bool waitUntilCompleted(); + // bool waitUntilCompleted(); Q_SIGNALS: void stateChanged(QDeclarativeDebugQuery::State); @@ -314,7 +315,7 @@ private: class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugEnginesQuery : public QDeclarativeDebugQuery { -Q_OBJECT + Q_OBJECT public: virtual ~QDeclarativeDebugEnginesQuery(); QList engines() const; @@ -329,7 +330,7 @@ private: class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugRootContextQuery : public QDeclarativeDebugQuery { -Q_OBJECT + Q_OBJECT public: virtual ~QDeclarativeDebugRootContextQuery(); QDeclarativeDebugContextReference rootContext() const; @@ -344,7 +345,7 @@ private: class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectQuery : public QDeclarativeDebugQuery { -Q_OBJECT + Q_OBJECT public: virtual ~QDeclarativeDebugObjectQuery(); QDeclarativeDebugObjectReference object() const; @@ -360,7 +361,7 @@ private: class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugExpressionQuery : public QDeclarativeDebugQuery { -Q_OBJECT + Q_OBJECT public: virtual ~QDeclarativeDebugExpressionQuery(); QVariant expression() const; diff --git a/src/declarative/debugger/qdeclarativeenginedebugservice.cpp b/src/declarative/debugger/qdeclarativeenginedebugservice.cpp index 2e5683c753..9841f8778e 100644 --- a/src/declarative/debugger/qdeclarativeenginedebugservice.cpp +++ b/src/declarative/debugger/qdeclarativeenginedebugservice.cpp @@ -67,8 +67,8 @@ QDeclarativeEngineDebugService *QDeclarativeEngineDebugService::instance() } QDeclarativeEngineDebugService::QDeclarativeEngineDebugService(QObject *parent) -: QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), - m_watch(new QDeclarativeWatcher(this)) + : QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), + m_watch(new QDeclarativeWatcher(this)) { QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)), this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant))); @@ -112,7 +112,7 @@ static inline bool isSignalPropertyName(const QString &signalName) { // see QmlCompiler::isSignalPropertyName return signalName.length() >= 3 && signalName.startsWith(QLatin1String("on")) && - signalName.at(2).isLetter() && signalName.at(2).isUpper(); + signalName.at(2).isLetter() && signalName.at(2).isUpper(); } static bool hasValidSignal(QObject *object, const QString &propertyName) @@ -142,8 +142,8 @@ QDeclarativeEngineDebugService::propertyData(QObject *obj, int propIdx) rv.valueTypeName = QString::fromUtf8(prop.typeName()); rv.name = QString::fromUtf8(prop.name()); rv.hasNotifySignal = prop.hasNotifySignal(); - QDeclarativeAbstractBinding *binding = - QDeclarativePropertyPrivate::binding(QDeclarativeProperty(obj, rv.name)); + QDeclarativeAbstractBinding *binding = + QDeclarativePropertyPrivate::binding(QDeclarativeProperty(obj, rv.name)); if (binding) rv.binding = binding->expression(); @@ -193,8 +193,8 @@ QVariant QDeclarativeEngineDebugService::valueContents(const QVariant &value) co return QLatin1String(""); } -void QDeclarativeEngineDebugService::buildObjectDump(QDataStream &message, - QObject *object, bool recur, bool dumpProperties) +void QDeclarativeEngineDebugService::buildObjectDump(QDataStream &message, + QObject *object, bool recur, bool dumpProperties) { message << objectData(object); @@ -283,7 +283,7 @@ void QDeclarativeEngineDebugService::buildObjectList(QDataStream &message, QDecl QString ctxtName = ctxt->objectName(); int ctxtId = QDeclarativeDebugService::idForObject(ctxt); - message << ctxtName << ctxtId; + message << ctxtName << ctxtId; int count = 0; @@ -336,7 +336,7 @@ void QDeclarativeEngineDebugService::buildStatesList(QDeclarativeContext *ctxt, void QDeclarativeEngineDebugService::buildStatesList(QObject *obj) { if (QDeclarativeState *state = qobject_cast(obj)) { - m_allStates.append(state); + m_allStates.append(state); } QObjectList children = obj->children(); @@ -416,8 +416,8 @@ void QDeclarativeEngineDebugService::messageReceived(const QByteArray &message) int engineId = -1; ds >> queryId >> engineId; - QDeclarativeEngine *engine = - qobject_cast(QDeclarativeDebugService::objectForId(engineId)); + QDeclarativeEngine *engine = + qobject_cast(QDeclarativeDebugService::objectForId(engineId)); QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); @@ -546,11 +546,11 @@ void QDeclarativeEngineDebugService::messageReceived(const QByteArray &message) } void QDeclarativeEngineDebugService::setBinding(int objectId, - const QString &propertyName, - const QVariant &expression, - bool isLiteralValue, - QString filename, - int line) + const QString &propertyName, + const QVariant &expression, + bool isLiteralValue, + QString filename, + int line) { QObject *object = objectForId(objectId); QDeclarativeContext *context = qmlContext(object); @@ -656,7 +656,7 @@ void QDeclarativeEngineDebugService::resetBinding(int objectId, const QString &p } else if (hasValidSignal(object, propertyName)) { QDeclarativeProperty property(object, propertyName, context); QDeclarativePropertyPrivate::setSignalExpression(property, 0); - } else { + } else { if (QDeclarativePropertyChanges *propertyChanges = qobject_cast(object)) { propertyChanges->removeProperty(propertyName); } @@ -675,8 +675,8 @@ void QDeclarativeEngineDebugService::setMethodBody(int objectId, const QString & return; QDeclarativePropertyCache::Data dummy; - QDeclarativePropertyCache::Data *prop = - QDeclarativePropertyCache::property(context->engine(), object, method, dummy); + QDeclarativePropertyCache::Data *prop = + QDeclarativePropertyCache::property(context->engine(), object, method, dummy); if (!prop || !prop->isVMEFunction()) return; @@ -690,13 +690,13 @@ void QDeclarativeEngineDebugService::setMethodBody(int objectId, const QString & paramStr.append(QString::fromUtf8(paramNames.at(ii))); } - QString jsfunction = QLatin1String("(function ") + method + QLatin1String("(") + paramStr + - QLatin1String(") {"); + QString jsfunction = QLatin1String("(function ") + method + QLatin1String("(") + paramStr + + QLatin1String(") {"); jsfunction += body; jsfunction += QLatin1String("\n})"); - QDeclarativeVMEMetaObject *vmeMetaObject = - static_cast(QObjectPrivate::get(object)->metaObject); + QDeclarativeVMEMetaObject *vmeMetaObject = + static_cast(QObjectPrivate::get(object)->metaObject); Q_ASSERT(vmeMetaObject); // the fact we found the property above should guarentee this int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex); diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp index 9caaa79011..0f1c15e3b8 100644 --- a/src/declarative/debugger/qpacketprotocol.cpp +++ b/src/declarative/debugger/qpacketprotocol.cpp @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE \brief The QPacketProtocol class encapsulates communicating discrete packets across fragmented IO channels, such as TCP sockets. - QPacketProtocol makes it simple to send arbitrary sized data "packets" across + QPacketProtocol makes it simple to send arbitrary sized data "packets" across fragmented transports such as TCP and UDP. As transmission boundaries are not respected, sending packets over protocols @@ -111,11 +111,11 @@ QT_BEGIN_NAMESPACE class QPacketProtocolPrivate : public QObject { -Q_OBJECT + Q_OBJECT public: QPacketProtocolPrivate(QPacketProtocol * parent, QIODevice * _dev) - : QObject(parent), inProgressSize(-1), maxPacketSize(MAX_PACKET_SIZE), - waitingForPacket(false), dev(_dev) + : QObject(parent), inProgressSize(-1), maxPacketSize(MAX_PACKET_SIZE), + waitingForPacket(false), dev(_dev) { Q_ASSERT(4 == sizeof(qint32)); @@ -222,7 +222,7 @@ public: specified \a parent. */ QPacketProtocol::QPacketProtocol(QIODevice * dev, QObject * parent) -: QObject(parent), d(new QPacketProtocolPrivate(this, dev)) + : QObject(parent), d(new QPacketProtocolPrivate(this, dev)) { Q_ASSERT(dev); } @@ -236,7 +236,7 @@ QPacketProtocol::~QPacketProtocol() /*! Returns the maximum packet size allowed. By default this is - 2,147,483,647 bytes. + 2,147,483,647 bytes. If a packet claiming to be larger than the maximum packet size is received, the QPacketProtocol::invalidPacket() signal is emitted. @@ -267,7 +267,7 @@ qint32 QPacketProtocol::setMaximumPacketSize(qint32 max) protocol.send() << "Hello world" << 123; \endcode - will send a packet containing "Hello world" and 123. To construct more + will send a packet containing "Hello world" and 123. To construct more complex packets, explicitly construct a QPacket instance. */ QPacketAutoSend QPacketProtocol::send() @@ -433,8 +433,8 @@ QIODevice * QPacketProtocol::device() \endcode Only packets returned from QPacketProtocol::read() may be read from. QPacket - instances constructed by directly by applications are for transmission only - and are considered "write only". Attempting to read data from them will + instances constructed by directly by applications are for transmission only + and are considered "write only". Attempting to read data from them will result in undefined behavior. \ingroup io @@ -445,7 +445,7 @@ QIODevice * QPacketProtocol::device() Constructs an empty write-only packet. */ QPacket::QPacket() -: QDataStream(), buf(0) + : QDataStream(), buf(0) { buf = new QBuffer(&b); buf->open(QIODevice::WriteOnly); @@ -469,7 +469,7 @@ QPacket::~QPacket() two packets are otherwise independent. */ QPacket::QPacket(const QPacket & other) -: QDataStream(), b(other.b), buf(0) + : QDataStream(), b(other.b), buf(0) { buf = new QBuffer(&b); buf->open(other.buf->openMode()); @@ -480,7 +480,7 @@ QPacket::QPacket(const QPacket & other) \internal */ QPacket::QPacket(const QByteArray & ba) -: QDataStream(), b(ba), buf(0) + : QDataStream(), b(ba), buf(0) { buf = new QBuffer(&b); buf->open(QIODevice::ReadOnly); @@ -535,7 +535,7 @@ void QPacket::clear() \internal */ QPacketAutoSend::QPacketAutoSend(QPacketProtocol * _p) -: QPacket(), p(_p) + : QPacket(), p(_p) { } diff --git a/src/declarative/debugger/qpacketprotocol_p.h b/src/declarative/debugger/qpacketprotocol_p.h index df3b170d17..9035d12947 100644 --- a/src/declarative/debugger/qpacketprotocol_p.h +++ b/src/declarative/debugger/qpacketprotocol_p.h @@ -61,7 +61,7 @@ class QPacketProtocolPrivate; class Q_DECLARATIVE_PRIVATE_EXPORT QPacketProtocol : public QObject { -Q_OBJECT + Q_OBJECT public: explicit QPacketProtocol(QIODevice * dev, QObject * parent = 0); virtual ~QPacketProtocol(); -- cgit v1.2.3 From b44395a4cbaa197b43c47fa92f9ca78696dc0d30 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 31 Aug 2011 09:17:57 +0200 Subject: Debugger: Add missing QT_BEGIN_NAMESPACE, QT_END_NAMESPACE Change-Id: I7cb404eac7a3f469fc6b1d40398ab0c40787cc8d Reviewed-on: http://codereview.qt.nokia.com/3938 Reviewed-by: Qt Sanity Bot Reviewed-by: Aurindam Jana --- src/declarative/debugger/qdeclarativedebugtrace.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp index dc1a34d733..befc3ea374 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace.cpp +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -45,6 +45,8 @@ #include #include +QT_BEGIN_NAMESPACE + Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance); // convert to a QByteArray that can be sent to the debug client @@ -223,3 +225,5 @@ void QDeclarativeDebugTrace::messageReceived(const QByteArray &message) if (!m_enabled) sendMessages(); } + +QT_END_NAMESPACE -- cgit v1.2.3 From b66a981bf10fccabc14f97bb0cb5ee2f973e15a8 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 31 Aug 2011 09:19:57 +0200 Subject: Debugger: Canonalize header defines Change-Id: I2cbe704326e993c47dd78182683787394f598ae4 Reviewed-on: http://codereview.qt.nokia.com/3939 Reviewed-by: Qt Sanity Bot Reviewed-by: Aurindam Jana --- src/declarative/debugger/qdeclarativeinspectorinterface_p.h | 6 +++--- src/declarative/debugger/qdeclarativeinspectorservice_p.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/declarative/debugger/qdeclarativeinspectorinterface_p.h b/src/declarative/debugger/qdeclarativeinspectorinterface_p.h index aa29d6807e..cb2b60407d 100644 --- a/src/declarative/debugger/qdeclarativeinspectorinterface_p.h +++ b/src/declarative/debugger/qdeclarativeinspectorinterface_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QDECLARATIVEOBSERVERINTERFACE_H -#define QDECLARATIVEOBSERVERINTERFACE_H +#ifndef QDECLARATIVEINSPECTORINTERFACE_H +#define QDECLARATIVEINSPECTORINTERFACE_H #include @@ -66,4 +66,4 @@ QT_END_NAMESPACE QT_END_HEADER -#endif // QDECLARATIVEOBSERVERINTERFACE_H +#endif // QDECLARATIVEINSPECTORINTERFACE_H diff --git a/src/declarative/debugger/qdeclarativeinspectorservice_p.h b/src/declarative/debugger/qdeclarativeinspectorservice_p.h index db94103210..229a974684 100644 --- a/src/declarative/debugger/qdeclarativeinspectorservice_p.h +++ b/src/declarative/debugger/qdeclarativeinspectorservice_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QDECLARATIVEOBSERVERSERVICE_H -#define QDECLARATIVEOBSERVERSERVICE_H +#ifndef QDECLARATIVEINSPECTORSERVICE_H +#define QDECLARATIVEINSPECTORSERVICE_H #include "private/qdeclarativedebugservice_p.h" #include @@ -87,4 +87,4 @@ QT_END_NAMESPACE QT_END_HEADER -#endif // QDECLARATIVEOBSERVERSERVICE_H +#endif // QDECLARATIVEINSPECTORSERVICE_H -- cgit v1.2.3 From a439673745ea1c92fe236c3928c34fa3f0637eec Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 31 Aug 2011 09:23:45 +0200 Subject: Debugger: Add private header warning to all _p.h files Change-Id: Ib5cccd8a2f252a2e67c8e0fdf979c3e8114ff131 Reviewed-on: http://codereview.qt.nokia.com/3940 Reviewed-by: Aurindam Jana Reviewed-by: Qt Sanity Bot --- src/declarative/debugger/qdeclarativedebugclient_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativedebuggerstatus_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativedebughelper_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativedebugserver_p.h | 11 +++++++++++ .../debugger/qdeclarativedebugserverconnection_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativedebugservice_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativedebugservice_p_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativedebugtrace_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativeenginedebug_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativeinspectorinterface_p.h | 11 +++++++++++ src/declarative/debugger/qdeclarativeinspectorservice_p.h | 11 +++++++++++ src/declarative/debugger/qpacketprotocol_p.h | 11 +++++++++++ 12 files changed, 132 insertions(+) (limited to 'src') diff --git a/src/declarative/debugger/qdeclarativedebugclient_p.h b/src/declarative/debugger/qdeclarativedebugclient_p.h index a2648d61c2..5b5d6705f9 100644 --- a/src/declarative/debugger/qdeclarativedebugclient_p.h +++ b/src/declarative/debugger/qdeclarativedebugclient_p.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEDEBUGCLIENT_H #define QDECLARATIVEDEBUGCLIENT_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 #include diff --git a/src/declarative/debugger/qdeclarativedebuggerstatus_p.h b/src/declarative/debugger/qdeclarativedebuggerstatus_p.h index 7904a06af6..385301e62d 100644 --- a/src/declarative/debugger/qdeclarativedebuggerstatus_p.h +++ b/src/declarative/debugger/qdeclarativedebuggerstatus_p.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEDEBUGGERSTATUS_P_H #define QDECLARATIVEDEBUGGERSTATUS_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 #include diff --git a/src/declarative/debugger/qdeclarativedebughelper_p.h b/src/declarative/debugger/qdeclarativedebughelper_p.h index d9ed5796ee..b92f3ba975 100644 --- a/src/declarative/debugger/qdeclarativedebughelper_p.h +++ b/src/declarative/debugger/qdeclarativedebughelper_p.h @@ -46,6 +46,17 @@ #include +// +// 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. +// + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativedebugserver_p.h b/src/declarative/debugger/qdeclarativedebugserver_p.h index 53c1077c7b..d80633cd7d 100644 --- a/src/declarative/debugger/qdeclarativedebugserver_p.h +++ b/src/declarative/debugger/qdeclarativedebugserver_p.h @@ -45,6 +45,17 @@ #include #include +// +// 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. +// + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativedebugserverconnection_p.h b/src/declarative/debugger/qdeclarativedebugserverconnection_p.h index d7f0de62fa..832224ea33 100644 --- a/src/declarative/debugger/qdeclarativedebugserverconnection_p.h +++ b/src/declarative/debugger/qdeclarativedebugserverconnection_p.h @@ -44,6 +44,17 @@ #include +// +// 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. +// + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativedebugservice_p.h b/src/declarative/debugger/qdeclarativedebugservice_p.h index 84e63c0ddc..05580ee5c2 100644 --- a/src/declarative/debugger/qdeclarativedebugservice_p.h +++ b/src/declarative/debugger/qdeclarativedebugservice_p.h @@ -46,6 +46,17 @@ #include +// +// 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. +// + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativedebugservice_p_p.h b/src/declarative/debugger/qdeclarativedebugservice_p_p.h index 78076892cb..12233ed739 100644 --- a/src/declarative/debugger/qdeclarativedebugservice_p_p.h +++ b/src/declarative/debugger/qdeclarativedebugservice_p_p.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEDEBUGSERVICE_P_H #define QDECLARATIVEDEBUGSERVICE_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 #include diff --git a/src/declarative/debugger/qdeclarativedebugtrace_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h index f2710cde93..fb2ef53a4a 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace_p.h +++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEDEBUGTRACE_P_H #define QDECLARATIVEDEBUGTRACE_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 #include diff --git a/src/declarative/debugger/qdeclarativeenginedebug_p.h b/src/declarative/debugger/qdeclarativeenginedebug_p.h index 24d0d85794..2cc6bfb9e9 100644 --- a/src/declarative/debugger/qdeclarativeenginedebug_p.h +++ b/src/declarative/debugger/qdeclarativeenginedebug_p.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEENGINEDEBUG_H #define QDECLARATIVEENGINEDEBUG_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 #include #include diff --git a/src/declarative/debugger/qdeclarativeinspectorinterface_p.h b/src/declarative/debugger/qdeclarativeinspectorinterface_p.h index cb2b60407d..d0d9f44d7b 100644 --- a/src/declarative/debugger/qdeclarativeinspectorinterface_p.h +++ b/src/declarative/debugger/qdeclarativeinspectorinterface_p.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEINSPECTORINTERFACE_H #define QDECLARATIVEINSPECTORINTERFACE_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 QT_BEGIN_HEADER diff --git a/src/declarative/debugger/qdeclarativeinspectorservice_p.h b/src/declarative/debugger/qdeclarativeinspectorservice_p.h index 229a974684..98b2e9deeb 100644 --- a/src/declarative/debugger/qdeclarativeinspectorservice_p.h +++ b/src/declarative/debugger/qdeclarativeinspectorservice_p.h @@ -42,6 +42,17 @@ #ifndef QDECLARATIVEINSPECTORSERVICE_H #define QDECLARATIVEINSPECTORSERVICE_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 "private/qdeclarativedebugservice_p.h" #include diff --git a/src/declarative/debugger/qpacketprotocol_p.h b/src/declarative/debugger/qpacketprotocol_p.h index 9035d12947..f7f3060c4b 100644 --- a/src/declarative/debugger/qpacketprotocol_p.h +++ b/src/declarative/debugger/qpacketprotocol_p.h @@ -42,6 +42,17 @@ #ifndef QPACKETPROTOCOL_H #define QPACKETPROTOCOL_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 #include -- cgit v1.2.3 From 6cb39fb829b78b5f6e9751283c7cd50400821e2a Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 31 Aug 2011 10:01:19 +0200 Subject: Debugger: Move QT_DECLARATIVE_DEBUG handling out of qdeclarative.h Apps don't have to (directly or indirectly) include qdeclarative.h. Instead, move the static instance to qdeclarativeengine.h, and qdeclarativeview.h, qsgview.h (which instantiate their own engine). Change-Id: I8b3e63ad4f134969734a2cc712395145d90e0dfa Reviewed-on: http://codereview.qt.nokia.com/3941 Reviewed-by: Qt Sanity Bot Reviewed-by: Aurindam Jana Reviewed-by: Martin Jones --- src/declarative/debugger/debugger.pri | 3 +- src/declarative/debugger/qdeclarativedebug.h | 67 ++++++++++++++++++++++++++++ src/declarative/items/qsgview.h | 3 +- src/declarative/qml/qdeclarative.h | 11 ----- src/declarative/qml/qdeclarativeengine.h | 1 + src/qtquick1/util/qdeclarativeview.h | 1 + 6 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 src/declarative/debugger/qdeclarativedebug.h (limited to 'src') diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index f2790c4ecd..a257da216f 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -27,4 +27,5 @@ HEADERS += \ $$PWD/qdeclarativeinspectorservice_p.h \ $$PWD/qdeclarativeinspectorinterface_p.h \ $$PWD/qv8debugservice_p.h \ - $$PWD/qdeclarativeenginedebugservice_p.h + $$PWD/qdeclarativeenginedebugservice_p.h \ + $$PWD/qdeclarativedebug.h diff --git a/src/declarative/debugger/qdeclarativedebug.h b/src/declarative/debugger/qdeclarativedebug.h new file mode 100644 index 0000000000..b7930b21f0 --- /dev/null +++ b/src/declarative/debugger/qdeclarativedebug.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** 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. +** +** 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. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEDEBUG_H +#define QDECLARATIVEDEBUG_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +struct Q_DECLARATIVE_EXPORT QDeclarativeDebuggingEnabler +{ + QDeclarativeDebuggingEnabler(); +}; + +// Execute code in constructor before first QDeclarativeEngine is instantiated +#if defined(QT_DECLARATIVE_DEBUG) +static QDeclarativeDebuggingEnabler qmlEnableDebuggingHelper; +#endif + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEDEBUG_H diff --git a/src/declarative/items/qsgview.h b/src/declarative/items/qsgview.h index 9b5ace13f3..ede488b2ce 100644 --- a/src/declarative/items/qsgview.h +++ b/src/declarative/items/qsgview.h @@ -43,8 +43,9 @@ #ifndef QSGVIEW_H #define QSGVIEW_H -#include #include +#include +#include QT_BEGIN_HEADER diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h index a0eb98d366..312aecbf76 100644 --- a/src/declarative/qml/qdeclarative.h +++ b/src/declarative/qml/qdeclarative.h @@ -552,17 +552,6 @@ inline int qmlRegisterModuleApi(const char *uri, int versionMajor, int versionMi return QDeclarativePrivate::qmlregister(QDeclarativePrivate::ModuleApiRegistration, &api); } -// Enable debugging before any QDeclarativeEngine is created -struct Q_DECLARATIVE_EXPORT QDeclarativeDebuggingEnabler -{ - QDeclarativeDebuggingEnabler(); -}; - -// Execute code in constructor before first QDeclarativeEngine is instantiated -#if defined(QT_DECLARATIVE_DEBUG) -static QDeclarativeDebuggingEnabler qmlEnableDebuggingHelper; -#endif - QT_END_NAMESPACE QML_DECLARE_TYPE(QObject) diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h index 3f90296681..74c3c6cb83 100644 --- a/src/declarative/qml/qdeclarativeengine.h +++ b/src/declarative/qml/qdeclarativeengine.h @@ -48,6 +48,7 @@ #include #include #include +#include QT_BEGIN_HEADER diff --git a/src/qtquick1/util/qdeclarativeview.h b/src/qtquick1/util/qdeclarativeview.h index 39a2322f99..aafb464b17 100644 --- a/src/qtquick1/util/qdeclarativeview.h +++ b/src/qtquick1/util/qdeclarativeview.h @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_HEADER -- cgit v1.2.3 From 08e187b1d48aeb3f824aa5240e55def428dcad45 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 31 Aug 2011 12:38:54 +0200 Subject: Debugger: Fixing coding style issues Applying changes done in the Qt Creator copies. Change-Id: I11e0547ddedd2e1f0b99d0ea586a1b209fa8d912 Reviewed-on: http://codereview.qt.nokia.com/3942 Reviewed-by: Aurindam Jana --- .../debugger/qdeclarativeenginedebug.cpp | 4 +++ .../debugger/qdeclarativeenginedebug_p.h | 3 +-- src/declarative/debugger/qpacketprotocol.cpp | 30 +++++++++++----------- src/declarative/debugger/qpacketprotocol_p.h | 12 ++++----- 4 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/declarative/debugger/qdeclarativeenginedebug.cpp b/src/declarative/debugger/qdeclarativeenginedebug.cpp index 836885db2a..237e2d6376 100644 --- a/src/declarative/debugger/qdeclarativeenginedebug.cpp +++ b/src/declarative/debugger/qdeclarativeenginedebug.cpp @@ -415,6 +415,10 @@ QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *cl { } +QDeclarativeEngineDebug::~QDeclarativeEngineDebug() +{ +} + QDeclarativeEngineDebug::Status QDeclarativeEngineDebug::status() const { Q_D(const QDeclarativeEngineDebug); diff --git a/src/declarative/debugger/qdeclarativeenginedebug_p.h b/src/declarative/debugger/qdeclarativeenginedebug_p.h index 2cc6bfb9e9..d98e4e875e 100644 --- a/src/declarative/debugger/qdeclarativeenginedebug_p.h +++ b/src/declarative/debugger/qdeclarativeenginedebug_p.h @@ -86,6 +86,7 @@ public: enum Status { NotConnected, Unavailable, Enabled }; explicit QDeclarativeEngineDebug(QDeclarativeDebugConnection *, QObject * = 0); + ~QDeclarativeEngineDebug(); Status status() const; @@ -194,8 +195,6 @@ public: State state() const; bool isWaiting() const; - // bool waitUntilCompleted(); - Q_SIGNALS: void stateChanged(QDeclarativeDebugQuery::State); diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp index 0f1c15e3b8..9b95d06e1e 100644 --- a/src/declarative/debugger/qpacketprotocol.cpp +++ b/src/declarative/debugger/qpacketprotocol.cpp @@ -41,12 +41,12 @@ #include "private/qpacketprotocol_p.h" -#include -#include +#include +#include QT_BEGIN_NAMESPACE -#define MAX_PACKET_SIZE 0x7FFFFFFF +static const unsigned int MAX_PACKET_SIZE = 0x7FFFFFFF; /*! \class QPacketProtocol @@ -113,7 +113,7 @@ class QPacketProtocolPrivate : public QObject { Q_OBJECT public: - QPacketProtocolPrivate(QPacketProtocol * parent, QIODevice * _dev) + QPacketProtocolPrivate(QPacketProtocol *parent, QIODevice *_dev) : QObject(parent), inProgressSize(-1), maxPacketSize(MAX_PACKET_SIZE), waitingForPacket(false), dev(_dev) { @@ -150,8 +150,8 @@ public Q_SLOTS: { Q_ASSERT(!sendingPackets.isEmpty()); - while(bytes) { - if(sendingPackets.at(0) > bytes) { + while (bytes) { + if (sendingPackets.at(0) > bytes) { sendingPackets[0] -= bytes; bytes = 0; } else { @@ -214,14 +214,14 @@ public: qint32 inProgressSize; qint32 maxPacketSize; bool waitingForPacket; - QIODevice * dev; + QIODevice *dev; }; /*! Construct a QPacketProtocol instance that works on \a dev with the specified \a parent. */ -QPacketProtocol::QPacketProtocol(QIODevice * dev, QObject * parent) +QPacketProtocol::QPacketProtocol(QIODevice *dev, QObject *parent) : QObject(parent), d(new QPacketProtocolPrivate(this, dev)) { Q_ASSERT(dev); @@ -255,7 +255,7 @@ qint32 QPacketProtocol::maximumPacketSize() const */ qint32 QPacketProtocol::setMaximumPacketSize(qint32 max) { - if(max > (signed)sizeof(qint32)) + if (max > (signed)sizeof(qint32)) d->maxPacketSize = max; return d->maxPacketSize; } @@ -282,7 +282,7 @@ QPacketAutoSend QPacketProtocol::send() */ void QPacketProtocol::send(const QPacket & p) { - if(p.b.isEmpty()) + if (p.b.isEmpty()) return; // We don't send empty packets qint64 sendSize = p.b.size() + sizeof(qint32); @@ -317,7 +317,7 @@ void QPacketProtocol::clear() */ QPacket QPacketProtocol::read() { - if(0 == d->packets.count()) + if (0 == d->packets.count()) return QPacket(); QPacket rv(d->packets.at(0)); @@ -370,7 +370,7 @@ bool QPacketProtocol::waitForReadyRead(int msecs) /*! Return the QIODevice passed to the QPacketProtocol constructor. */ -QIODevice * QPacketProtocol::device() +QIODevice *QPacketProtocol::device() { return d->dev; } @@ -458,7 +458,7 @@ QPacket::QPacket() */ QPacket::~QPacket() { - if(buf) { + if (buf) { delete buf; buf = 0; } @@ -534,14 +534,14 @@ void QPacket::clear() \internal */ -QPacketAutoSend::QPacketAutoSend(QPacketProtocol * _p) +QPacketAutoSend::QPacketAutoSend(QPacketProtocol *_p) : QPacket(), p(_p) { } QPacketAutoSend::~QPacketAutoSend() { - if(!b.isEmpty()) + if (!b.isEmpty()) p->send(*this); } diff --git a/src/declarative/debugger/qpacketprotocol_p.h b/src/declarative/debugger/qpacketprotocol_p.h index f7f3060c4b..5d9d820317 100644 --- a/src/declarative/debugger/qpacketprotocol_p.h +++ b/src/declarative/debugger/qpacketprotocol_p.h @@ -74,7 +74,7 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QPacketProtocol : public QObject { Q_OBJECT public: - explicit QPacketProtocol(QIODevice * dev, QObject * parent = 0); + explicit QPacketProtocol(QIODevice *dev, QObject *parent = 0); virtual ~QPacketProtocol(); qint32 maximumPacketSize() const; @@ -90,7 +90,7 @@ public: void clear(); - QIODevice * device(); + QIODevice *device(); Q_SIGNALS: void readyRead(); @@ -98,7 +98,7 @@ Q_SIGNALS: void packetWritten(); private: - QPacketProtocolPrivate * d; + QPacketProtocolPrivate *d; }; @@ -115,9 +115,9 @@ public: protected: friend class QPacketProtocol; - QPacket(const QByteArray & ba); + QPacket(const QByteArray &ba); QByteArray b; - QBuffer * buf; + QBuffer *buf; }; class Q_DECLARATIVE_PRIVATE_EXPORT QPacketAutoSend : public QPacket @@ -128,7 +128,7 @@ public: private: friend class QPacketProtocol; QPacketAutoSend(QPacketProtocol *); - QPacketProtocol * p; + QPacketProtocol *p; }; QT_END_NAMESPACE -- cgit v1.2.3 From d3c58815a37a311c1bd743a102368e03fd07fee1 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 31 Aug 2011 12:41:04 +0200 Subject: Debugger: Merge back changes from Qt Creator copy Apply changes done to the Qt Creator copy. In Qt Creator we also support connecting via OST, which we don't do inside QtDeclarative because it would pull in dependencies. Anyhow, make the code align nevertheless. Change-Id: I98f0be5ed3e136374e163cf1400df100128497ee Reviewed-on: http://codereview.qt.nokia.com/3943 Reviewed-by: Qt Sanity Bot Reviewed-by: Aurindam Jana --- .../debugger/qdeclarativedebugclient.cpp | 106 +++++++++++++++++++-- .../debugger/qdeclarativedebugclient_p.h | 22 ++++- 2 files changed, 119 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/declarative/debugger/qdeclarativedebugclient.cpp b/src/declarative/debugger/qdeclarativedebugclient.cpp index 9853a9ff60..606ad2deae 100644 --- a/src/declarative/debugger/qdeclarativedebugclient.cpp +++ b/src/declarative/debugger/qdeclarativedebugclient.cpp @@ -45,6 +45,7 @@ #include #include +#include #include @@ -71,20 +72,23 @@ public: QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c); QDeclarativeDebugConnection *q; QPacketProtocol *protocol; + QIODevice *device; bool gotHello; QStringList serverPlugins; QHash plugins; void advertisePlugins(); + void connectDeviceSignals(); public Q_SLOTS: void connected(); void readyRead(); + void deviceAboutToClose(); }; QDeclarativeDebugConnectionPrivate::QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c) - : QObject(c), q(c), protocol(0), gotHello(false) + : QObject(c), q(c), protocol(0), device(0), gotHello(false) { protocol = new QPacketProtocol(q, this); QObject::connect(c, SIGNAL(connected()), this, SLOT(connected())); @@ -137,7 +141,6 @@ void QDeclarativeDebugConnectionPrivate::readyRead() QObject::disconnect(protocol, SIGNAL(readyRead()), this, SLOT(readyRead())); return; } - gotHello = true; QHash::Iterator iter = plugins.begin(); @@ -193,8 +196,15 @@ void QDeclarativeDebugConnectionPrivate::readyRead() } } +void QDeclarativeDebugConnectionPrivate::deviceAboutToClose() +{ + // This is nasty syntax but we want to emit our own aboutToClose signal (by calling QIODevice::close()) + // without calling the underlying device close fn as that would cause an infinite loop + q->QIODevice::close(); +} + QDeclarativeDebugConnection::QDeclarativeDebugConnection(QObject *parent) - : QTcpSocket(parent), d(new QDeclarativeDebugConnectionPrivate(this)) + : QIODevice(parent), d(new QDeclarativeDebugConnectionPrivate(this)) { } @@ -209,9 +219,92 @@ QDeclarativeDebugConnection::~QDeclarativeDebugConnection() bool QDeclarativeDebugConnection::isConnected() const { - return state() == ConnectedState; + return state() == QAbstractSocket::ConnectedState; +} + +qint64 QDeclarativeDebugConnection::readData(char *data, qint64 maxSize) +{ + return d->device->read(data, maxSize); +} + +qint64 QDeclarativeDebugConnection::writeData(const char *data, qint64 maxSize) +{ + return d->device->write(data, maxSize); +} + +qint64 QDeclarativeDebugConnection::bytesAvailable() const +{ + return d->device->bytesAvailable(); +} + +bool QDeclarativeDebugConnection::isSequential() const +{ + return true; } +void QDeclarativeDebugConnection::close() +{ + if (isOpen()) { + QIODevice::close(); + d->device->close(); + emit stateChanged(QAbstractSocket::UnconnectedState); + + QHash::iterator iter = d->plugins.begin(); + for (; iter != d->plugins.end(); ++iter) { + iter.value()->statusChanged(QDeclarativeDebugClient::NotConnected); + } + } +} + +bool QDeclarativeDebugConnection::waitForConnected(int msecs) +{ + QAbstractSocket *socket = qobject_cast(d->device); + if (socket) + return socket->waitForConnected(msecs); + return false; +} + +QAbstractSocket::SocketState QDeclarativeDebugConnection::state() const +{ + QAbstractSocket *socket = qobject_cast(d->device); + if (socket) + return socket->state(); + + return QAbstractSocket::UnconnectedState; +} + +void QDeclarativeDebugConnection::flush() +{ + QAbstractSocket *socket = qobject_cast(d->device); + if (socket) { + socket->flush(); + return; + } +} + +void QDeclarativeDebugConnection::connectToHost(const QString &hostName, quint16 port) +{ + QTcpSocket *socket = new QTcpSocket(d); + socket->setProxy(QNetworkProxy::NoProxy); + d->device = socket; + d->connectDeviceSignals(); + d->gotHello = false; + connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SIGNAL(stateChanged(QAbstractSocket::SocketState))); + connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError))); + connect(socket, SIGNAL(connected()), this, SIGNAL(connected())); + socket->connectToHost(hostName, port); + QIODevice::open(ReadWrite | Unbuffered); +} + +void QDeclarativeDebugConnectionPrivate::connectDeviceSignals() +{ + connect(device, SIGNAL(bytesWritten(qint64)), q, SIGNAL(bytesWritten(qint64))); + connect(device, SIGNAL(readyRead()), q, SIGNAL(readyRead())); + connect(device, SIGNAL(aboutToClose()), this, SLOT(deviceAboutToClose())); +} + +// + QDeclarativeDebugClientPrivate::QDeclarativeDebugClientPrivate() : connection(0) { @@ -239,7 +332,7 @@ QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name, QDeclarativeDebugClient::~QDeclarativeDebugClient() { - Q_D(const QDeclarativeDebugClient); + Q_D(QDeclarativeDebugClient); if (d->connection && d->connection->d) { d->connection->d->plugins.remove(d->name); d->connection->d->advertisePlugins(); @@ -269,14 +362,13 @@ QDeclarativeDebugClient::Status QDeclarativeDebugClient::status() const void QDeclarativeDebugClient::sendMessage(const QByteArray &message) { Q_D(QDeclarativeDebugClient); - if (status() != Enabled) return; QPacket pack; pack << d->name << message; d->connection->d->protocol->send(pack); - d->connection->d->q->flush(); + d->connection->flush(); } void QDeclarativeDebugClient::statusChanged(Status) diff --git a/src/declarative/debugger/qdeclarativedebugclient_p.h b/src/declarative/debugger/qdeclarativedebugclient_p.h index 5b5d6705f9..5b219358ff 100644 --- a/src/declarative/debugger/qdeclarativedebugclient_p.h +++ b/src/declarative/debugger/qdeclarativedebugclient_p.h @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QDeclarativeDebugConnectionPrivate; -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugConnection : public QTcpSocket +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugConnection : public QIODevice { Q_OBJECT Q_DISABLE_COPY(QDeclarativeDebugConnection) @@ -72,7 +72,25 @@ public: QDeclarativeDebugConnection(QObject * = 0); ~QDeclarativeDebugConnection(); + void connectToHost(const QString &hostName, quint16 port); + + qint64 bytesAvailable() const; bool isConnected() const; + QAbstractSocket::SocketState state() const; + void flush(); + bool isSequential() const; + void close(); + bool waitForConnected(int msecs = 30000); + +signals: + void connected(); + void stateChanged(QAbstractSocket::SocketState socketState); + void error(QAbstractSocket::SocketError socketError); + +protected: + qint64 readData(char *data, qint64 maxSize); + qint64 writeData(const char *data, qint64 maxSize); + private: QDeclarativeDebugConnectionPrivate *d; friend class QDeclarativeDebugClient; @@ -96,7 +114,7 @@ public: Status status() const; - void sendMessage(const QByteArray &); + virtual void sendMessage(const QByteArray &); protected: virtual void statusChanged(Status); -- cgit v1.2.3 From ae064a9dc862b5912bde030394c426d166194898 Mon Sep 17 00:00:00 2001 From: Jonni Rainisto Date: Fri, 2 Sep 2011 11:35:11 +0300 Subject: Fix build break for QT_OPENGL_ES builds. Change-Id: I1e277e79bd9b3f38e3540495e8006f1c41cfecc8 Reviewed-on: http://codereview.qt.nokia.com/4122 Reviewed-by: Qt Sanity Bot Reviewed-by: Wolf-Michael Bolle Reviewed-by: Jonni Rainisto Reviewed-by: Rohan McGovern --- src/declarative/designer/designersupport.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/declarative/designer/designersupport.cpp b/src/declarative/designer/designersupport.cpp index 91186a4a2e..da02721789 100644 --- a/src/declarative/designer/designersupport.cpp +++ b/src/declarative/designer/designersupport.cpp @@ -85,7 +85,11 @@ void DesignerSupport::refFromEffectItem(QSGItem *referencedItem, bool hide) texture->setRect(referencedItem->boundingRect()); texture->setSize(referencedItem->boundingRect().size().toSize()); texture->setRecursive(true); +#ifndef QT_OPENGL_ES texture->setFormat(GL_RGBA8); +#else + texture->setFormat(GL_RGBA); +#endif texture->setHasMipmaps(false); m_itemTextureHash.insert(referencedItem, texture); -- cgit v1.2.3 From f22ae0f5f18a354bf3addd8023ad8b8810e42bac Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 2 Aug 2011 15:41:22 +1000 Subject: Fix some memory leaks in the compiler Task-number: QTBUG-17770 Change-Id: I6d9d357bf529a9a3f414182fb6a818ddedda8e18 Reviewed-on: http://codereview.qt.nokia.com/2487 Reviewed-by: Qt Sanity Bot Reviewed-by: Michael Brasser --- src/declarative/qml/qdeclarativebinding.cpp | 2 ++ src/declarative/qml/qdeclarativeexpression.cpp | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index d817990d7b..9a69a6bfd0 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -243,6 +243,8 @@ QDeclarativeBinding::createBinding(Identifier id, QObject *obj, QDeclarativeCont cdata = typeData->compiledData(); } QDeclarativeBinding *rv = cdata ? new QDeclarativeBinding(cdata->primitives.at(id), true, obj, ctxtdata, url, lineNumber, parent) : 0; + if (cdata) + cdata->release(); if (typeData) typeData->release(); return rv; diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index a24d46914c..4f6a71911f 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -256,6 +256,8 @@ QDeclarativeExpression::QDeclarativeExpression(const QDeclarativeScriptString &s else defaultConstruction = true; + if (cdata) + cdata->release(); if (typeData) typeData->release(); } -- cgit v1.2.3 From dd3983655c40a6c8879b8980d41a0cd2b7612da9 Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Fri, 2 Sep 2011 18:05:29 +0200 Subject: Remove friend class QV8DebugService from QV8Engine. The friend class is now redundant since QVDebugService now uses only public methods of QV8Engine. Change-Id: I492555d75bcbe08f921c5f2c3d634c691ed1223c Reviewed-on: http://codereview.qt.nokia.com/4151 Reviewed-by: Qt Sanity Bot Reviewed-by: Kai Koehne --- src/declarative/qml/v8/qv8engine_p.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h index ab4da423ee..6f09e977d5 100644 --- a/src/declarative/qml/v8/qv8engine_p.h +++ b/src/declarative/qml/v8/qv8engine_p.h @@ -470,7 +470,6 @@ private: ValueIteratorList m_valueIterators; Q_DISABLE_COPY(QV8Engine) - friend class QV8DebugService; }; // Allocate a new Persistent handle. *ALL* persistent handles in QML must be allocated -- cgit v1.2.3 From c0fe60cad2c48f18e618c3ca4589abe73752389e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 5 Sep 2011 11:40:10 +1000 Subject: View refill operations should take qreal, not int Regression from initial creation of QSGItemView. Task-number: QTBUG-21281 Change-Id: I810a0b56ba4bacda49ac62b6e4c11cf9c1825c10 Reviewed-on: http://codereview.qt.nokia.com/4160 Reviewed-by: Bea Lam Reviewed-by: Qt Sanity Bot --- src/declarative/items/qsggridview.cpp | 8 ++++---- src/declarative/items/qsgitemview_p_p.h | 4 ++-- src/declarative/items/qsglistview.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp index 1d4e8313b4..e2fe5cd9c8 100644 --- a/src/declarative/items/qsggridview.cpp +++ b/src/declarative/items/qsggridview.cpp @@ -160,8 +160,8 @@ public: FxViewItem *snapItemAt(qreal pos) const; int snapIndex() const; - virtual bool addVisibleItems(int fillFrom, int fillTo, bool doBuffer); - virtual bool removeNonVisibleItems(int bufferFrom, int bufferTo); + virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer); + virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo); virtual void visibleItemsChanged(); virtual FxViewItem *newViewItem(int index, QSGItem *item); @@ -387,7 +387,7 @@ FxViewItem *QSGGridViewPrivate::newViewItem(int modelIndex, QSGItem *item) return new FxGridItemSG(item, q, false); } -bool QSGGridViewPrivate::addVisibleItems(int fillFrom, int fillTo, bool doBuffer) +bool QSGGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) { int colPos = colPosAt(visibleIndex); int rowPos = rowPosAt(visibleIndex); @@ -479,7 +479,7 @@ bool QSGGridViewPrivate::addVisibleItems(int fillFrom, int fillTo, bool doBuffer return changed; } -bool QSGGridViewPrivate::removeNonVisibleItems(int bufferFrom, int bufferTo) +bool QSGGridViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) { FxGridItemSG *item = 0; bool changed = false; diff --git a/src/declarative/items/qsgitemview_p_p.h b/src/declarative/items/qsgitemview_p_p.h index 243045526a..2164dd60f4 100644 --- a/src/declarative/items/qsgitemview_p_p.h +++ b/src/declarative/items/qsgitemview_p_p.h @@ -217,8 +217,8 @@ protected: virtual void setPosition(qreal pos) = 0; virtual void fixupPosition() = 0; - virtual bool addVisibleItems(int fillFrom, int fillTo, bool doBuffer) = 0; - virtual bool removeNonVisibleItems(int bufferFrom, int bufferTo) = 0; + virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) = 0; + virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) = 0; virtual void visibleItemsChanged() = 0; virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0; diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp index 321c66c41a..e8a6bf2d50 100644 --- a/src/declarative/items/qsglistview.cpp +++ b/src/declarative/items/qsglistview.cpp @@ -201,8 +201,8 @@ public: virtual void init(); virtual void clear(); - virtual bool addVisibleItems(int fillFrom, int fillTo, bool doBuffer); - virtual bool removeNonVisibleItems(int bufferFrom, int bufferTo); + virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer); + virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo); virtual void visibleItemsChanged(); virtual FxViewItem *newViewItem(int index, QSGItem *item); @@ -539,7 +539,7 @@ void QSGListViewPrivate::releaseItem(FxViewItem *item) QSGItemViewPrivate::releaseItem(item); } -bool QSGListViewPrivate::addVisibleItems(int fillFrom, int fillTo, bool doBuffer) +bool QSGListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) { qreal itemEnd = visiblePos; if (visibleItems.count()) { @@ -603,7 +603,7 @@ bool QSGListViewPrivate::addVisibleItems(int fillFrom, int fillTo, bool doBuffer return changed; } -bool QSGListViewPrivate::removeNonVisibleItems(int bufferFrom, int bufferTo) +bool QSGListViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) { FxViewItem *item = 0; bool changed = false; -- cgit v1.2.3 From 249754bf7fe4a195c723eea73f2dd55a2bd905cb Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 19 Jul 2011 15:15:58 +1000 Subject: Delay masking the last character in Password echo mode. If QT_GUI_PASSWORD_ECHO_DELAY is defined in qplatformdefs.h with an integer value in milliseconds, QLineEdit and TextInput will display the last character entered unmasked for that delay period and then mask the character as normal. If QT_GUI_PASSWORD_ECHO_DELAY is not defined then the behaviour is unchanged. Task-number: QTBUG-17003 Reviewed-by: Martin Jones (cherry picked from commit f9e7aee2019d321edd655bfde7de43f20a106971) Change-Id: Iddfa0daa1b39f0589cab27e5003fdd86ad81ff89 Reviewed-on: http://codereview.qt.nokia.com/4170 Reviewed-by: Andrew den Exter --- src/declarative/items/qsgtextinput.cpp | 2 +- src/qtquick1/graphicsitems/qdeclarativetextinput.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/declarative/items/qsgtextinput.cpp b/src/declarative/items/qsgtextinput.cpp index 222a9002e7..01e517397c 100644 --- a/src/declarative/items/qsgtextinput.cpp +++ b/src/declarative/items/qsgtextinput.cpp @@ -1817,7 +1817,7 @@ void QSGTextInput::itemChange(ItemChange change, const ItemChangeData &value) bool hasFocus = value.boolValue; d->focused = hasFocus; setCursorVisible(hasFocus && d->canvas && d->canvas->hasFocus()); - if(echoMode() == QSGTextInput::PasswordEchoOnEdit && !hasFocus) + if(!hasFocus && d->control->passwordEchoEditing()) d->control->updatePasswordEchoEditing(false);//QLineControl sets it on key events, but doesn't deal with focus events if (!hasFocus) d->control->deselect(); diff --git a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp index a14d837be0..c61a3ff089 100644 --- a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp @@ -1058,7 +1058,7 @@ void QDeclarative1TextInputPrivate::focusChanged(bool hasFocus) Q_Q(QDeclarative1TextInput); focused = hasFocus; q->setCursorVisible(hasFocus && scene && scene->hasFocus()); - if(q->echoMode() == QDeclarative1TextInput::PasswordEchoOnEdit && !hasFocus) + if(!hasFocus && control->passwordEchoEditing()) control->updatePasswordEchoEditing(false);//QLineControl sets it on key events, but doesn't deal with focus events if (!hasFocus) control->deselect(); -- cgit v1.2.3 From 0c0f03e2b9756afb4e868a76734cc90102218f0a Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 30 Aug 2011 14:40:41 +1000 Subject: Improvements to textFormat: Text.StyledText Add support for: -

to

headers -

paragraph - underlined text - anchor -