diff options
author | Marco Bubke <marco.bubke@digia.com> | 2012-09-19 15:57:22 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@digia.com> | 2012-09-24 11:46:20 +0200 |
commit | 770ab68c45e4569a840fcb43a9d19976aae58da2 (patch) | |
tree | 905e77039505025462b619f4399438f84775f0e9 /share/qtcreator | |
parent | 51f847246e48f072df3b8252cea399a35d694123 (diff) |
QmlDesigner.Instances: Refactor the qml2 puppet
Change-Id: Iaa7a744ecf13e011addc573a381ea523d2d50a55
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Diffstat (limited to 'share/qtcreator')
51 files changed, 6200 insertions, 198 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.cpp index ff0e894ecb..e0cd5e3144 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.cpp @@ -30,6 +30,8 @@ #include "changenodesourcecommand.h" +#include <QDataStream> + namespace QmlDesigner { ChangeNodeSourceCommand::ChangeNodeSourceCommand() diff --git a/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.h b/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.h index 8741a82afe..b8e2533e87 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.h +++ b/share/qtcreator/qml/qmlpuppet/commands/changenodesourcecommand.h @@ -32,6 +32,7 @@ #define CHANGENODESOURCECOMMAND_H #include <QMetaType> +#include <QString> namespace QmlDesigner { diff --git a/share/qtcreator/qml/qmlpuppet/commands/completecomponentcommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/completecomponentcommand.cpp index 19528214d3..0982915ec7 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/completecomponentcommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/completecomponentcommand.cpp @@ -30,6 +30,8 @@ #include "completecomponentcommand.h" +#include <QDataStream> + namespace QmlDesigner { CompleteComponentCommand::CompleteComponentCommand() diff --git a/share/qtcreator/qml/qmlpuppet/commands/componentcompletedcommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/componentcompletedcommand.cpp index af9ae55491..dbd4514ac1 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/componentcompletedcommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/componentcompletedcommand.cpp @@ -30,6 +30,8 @@ #include "componentcompletedcommand.h" +#include <QDataStream> + namespace QmlDesigner { ComponentCompletedCommand::ComponentCompletedCommand() diff --git a/share/qtcreator/qml/qmlpuppet/commands/removeinstancescommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/removeinstancescommand.cpp index 9dc0ff51e2..b556394729 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/removeinstancescommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/removeinstancescommand.cpp @@ -30,6 +30,8 @@ #include "removeinstancescommand.h" +#include <QDataStream> + namespace QmlDesigner { RemoveInstancesCommand::RemoveInstancesCommand() diff --git a/share/qtcreator/qml/qmlpuppet/commands/removesharedmemorycommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/removesharedmemorycommand.cpp index ff4ad0b97b..63bb675f7b 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/removesharedmemorycommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/removesharedmemorycommand.cpp @@ -33,6 +33,8 @@ #include "removesharedmemorycommand.h" +#include <QDataStream> + namespace QmlDesigner { RemoveSharedMemoryCommand::RemoveSharedMemoryCommand() diff --git a/share/qtcreator/qml/qmlpuppet/commands/reparentinstancescommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/reparentinstancescommand.cpp index d4800e2a06..4194b427ee 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/reparentinstancescommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/reparentinstancescommand.cpp @@ -30,6 +30,8 @@ #include "reparentinstancescommand.h" +#include <QDataStream> + namespace QmlDesigner { ReparentInstancesCommand::ReparentInstancesCommand() diff --git a/share/qtcreator/qml/qmlpuppet/commands/tokencommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/tokencommand.cpp index 953b42a8f6..9c938ea81e 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/tokencommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/tokencommand.cpp @@ -30,6 +30,8 @@ #include "tokencommand.h" +#include <QDataStream> + namespace QmlDesigner { TokenCommand::TokenCommand() diff --git a/share/qtcreator/qml/qmlpuppet/commands/tokencommand.h b/share/qtcreator/qml/qmlpuppet/commands/tokencommand.h index e79c4d1366..063dde5bb6 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/tokencommand.h +++ b/share/qtcreator/qml/qmlpuppet/commands/tokencommand.h @@ -34,6 +34,7 @@ #include <QMetaType> #include <QVector> +#include <QString> namespace QmlDesigner { diff --git a/share/qtcreator/qml/qmlpuppet/container/instancecontainer.cpp b/share/qtcreator/qml/qmlpuppet/container/instancecontainer.cpp index 5b1a0b828a..9a60c19b36 100644 --- a/share/qtcreator/qml/qmlpuppet/container/instancecontainer.cpp +++ b/share/qtcreator/qml/qmlpuppet/container/instancecontainer.cpp @@ -30,6 +30,8 @@ #include "instancecontainer.h" +#include <QDataStream> + namespace QmlDesigner { InstanceContainer::InstanceContainer() diff --git a/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.cpp b/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.cpp index 3978ab2692..6bdc03eda4 100644 --- a/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.cpp +++ b/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.cpp @@ -30,6 +30,8 @@ #include "reparentcontainer.h" +#include <QDataStream> + namespace QmlDesigner { ReparentContainer::ReparentContainer() diff --git a/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.h b/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.h index cb68f99622..29bf24929a 100644 --- a/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.h +++ b/share/qtcreator/qml/qmlpuppet/container/reparentcontainer.h @@ -32,6 +32,7 @@ #define REPARENTCONTAINER_H #include <qmetatype.h> +#include <QString> namespace QmlDesigner { diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/anchorchangesnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/anchorchangesnodeinstance.cpp new file mode 100644 index 0000000000..1c84c3b6d7 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/anchorchangesnodeinstance.cpp @@ -0,0 +1,85 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + + + +#include "anchorchangesnodeinstance.h" + +namespace QmlDesigner { + +namespace Internal { + +AnchorChangesNodeInstance::AnchorChangesNodeInstance(QObject *object) : + ObjectNodeInstance(object) +{ +} + +AnchorChangesNodeInstance::Pointer AnchorChangesNodeInstance::create(QObject *object) +{ + Q_ASSERT(object); + + Pointer instance(new AnchorChangesNodeInstance(object)); + + return instance; +} + +void AnchorChangesNodeInstance::setPropertyVariant(const QString &/*name*/, const QVariant &/*value*/) +{ +} + +void AnchorChangesNodeInstance::setPropertyBinding(const QString &/*name*/, const QString &/*expression*/) +{ +} + +QVariant AnchorChangesNodeInstance::property(const QString &/*name*/) const +{ + return QVariant(); +} + +void AnchorChangesNodeInstance::resetProperty(const QString &/*name*/) +{ +} + + +void AnchorChangesNodeInstance::reparent(const ServerNodeInstance &/*oldParentInstance*/, + const QString &/*oldParentProperty*/, + const ServerNodeInstance &/*newParentInstance*/, + const QString &/*newParentProperty*/) +{ +} + +QObject *AnchorChangesNodeInstance::changesObject() const +{ + return object(); +} + +} // namespace Internal + +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/anchorchangesnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/anchorchangesnodeinstance.h new file mode 100644 index 0000000000..ed117a1f9f --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/anchorchangesnodeinstance.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + + + +#ifndef QMLDESIGNER_ANCHORCHANGESNODEINSTANCE_H +#define QMLDESIGNER_ANCHORCHANGESNODEINSTANCE_H + +#include "objectnodeinstance.h" + +#include <QPair> +#include <QWeakPointer> + +QT_BEGIN_NAMESPACE +class QQmlProperty; +QT_END_NAMESPACE + +namespace QmlDesigner { + +namespace Internal { + +class AnchorChangesNodeInstance : public ObjectNodeInstance +{ +public: + typedef QSharedPointer<AnchorChangesNodeInstance> Pointer; + typedef QWeakPointer<AnchorChangesNodeInstance> WeakPointer; + + static Pointer create(QObject *objectToBeWrapped); + + virtual void setPropertyVariant(const QString &name, const QVariant &value); + virtual void setPropertyBinding(const QString &name, const QString &expression); + virtual QVariant property(const QString &name) const; + virtual void resetProperty(const QString &name); + + using ObjectNodeInstance::reparent; // keep the virtual reparent(...) method around + void reparent(const ServerNodeInstance &oldParentInstance, + const QString &oldParentProperty, + const ServerNodeInstance &newParentInstance, + const QString &newParentProperty); + +protected: + AnchorChangesNodeInstance(QObject *object); + QObject *changesObject() const; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // QMLDESIGNER_ANCHORCHANGESNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/behaviornodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/behaviornodeinstance.cpp new file mode 100644 index 0000000000..fc8bf24ace --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/behaviornodeinstance.cpp @@ -0,0 +1,93 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "behaviornodeinstance.h" + +#include <private/qquickbehavior_p.h> + +namespace QmlDesigner { +namespace Internal { + +BehaviorNodeInstance::BehaviorNodeInstance(QObject *object) + : ObjectNodeInstance(object), + m_isEnabled(true) +{ +} + +BehaviorNodeInstance::Pointer BehaviorNodeInstance::create(QObject *object) +{ + QQuickBehavior* behavior = qobject_cast<QQuickBehavior*>(object); + + Q_ASSERT(behavior); + + Pointer instance(new BehaviorNodeInstance(behavior)); + + instance->populateResetHashes(); + + behavior->setEnabled(false); + + return instance; +} + +void BehaviorNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +{ + if (name == "enabled") + return; + + ObjectNodeInstance::setPropertyVariant(name, value); +} + +void BehaviorNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +{ + if (name == "enabled") + return; + + ObjectNodeInstance::setPropertyBinding(name, expression); +} + +QVariant BehaviorNodeInstance::property(const QString &name) const +{ + if (name == "enabled") + return QVariant::fromValue(m_isEnabled); + + return ObjectNodeInstance::property(name); +} + +void BehaviorNodeInstance::resetProperty(const QString &name) +{ + if (name == "enabled") + m_isEnabled = true; + + ObjectNodeInstance::resetProperty(name); +} + + +} // namespace Internal +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/behaviornodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/behaviornodeinstance.h new file mode 100644 index 0000000000..acd14a4aa1 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/behaviornodeinstance.h @@ -0,0 +1,63 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef BEHAVIORNODEINSTANCE_H +#define BEHAVIORNODEINSTANCE_H + +#include "objectnodeinstance.h" + +namespace QmlDesigner { +namespace Internal { + +class BehaviorNodeInstance : public ObjectNodeInstance +{ +public: + typedef QSharedPointer<BehaviorNodeInstance> Pointer; + typedef QWeakPointer<BehaviorNodeInstance> WeakPointer; + + BehaviorNodeInstance(QObject *object); + + static Pointer create(QObject *objectToBeWrapped); + + void setPropertyVariant(const QString &name, const QVariant &value); + void setPropertyBinding(const QString &name, const QString &expression); + + + QVariant property(const QString &name) const; + void resetProperty(const QString &name); + +private: + bool m_isEnabled; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // BEHAVIORNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/childrenchangeeventfilter.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/childrenchangeeventfilter.cpp new file mode 100644 index 0000000000..ee653f81e7 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/childrenchangeeventfilter.cpp @@ -0,0 +1,59 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "childrenchangeeventfilter.h" + +#include <QEvent> + +namespace QmlDesigner { +namespace Internal { + +ChildrenChangeEventFilter::ChildrenChangeEventFilter(QObject *parent) + : QObject(parent) +{ +} + + +bool ChildrenChangeEventFilter::eventFilter(QObject * /*object*/, QEvent *event) +{ + switch (event->type()) { + case QEvent::ChildAdded: + case QEvent::ChildRemoved: + { + QChildEvent *childEvent = static_cast<QChildEvent*>(event); + emit childrenChanged(childEvent->child()); break; + } + default: break; + } + + return false; +} +} // namespace Internal +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/childrenchangeeventfilter.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/childrenchangeeventfilter.h new file mode 100644 index 0000000000..35a4c55f77 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/childrenchangeeventfilter.h @@ -0,0 +1,57 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef CHILDRENCHANGEEVENTFILTER_H +#define CHILDRENCHANGEEVENTFILTER_H + +#include <QObject> + +namespace QmlDesigner { +namespace Internal { + +class ChildrenChangeEventFilter : public QObject +{ + Q_OBJECT +public: + ChildrenChangeEventFilter(QObject *parent); + + +signals: + void childrenChanged(QObject *object); + +protected: + bool eventFilter(QObject *object, QEvent *event); + +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // CHILDRENCHANGEEVENTFILTER_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/componentnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/componentnodeinstance.cpp new file mode 100644 index 0000000000..b7a8054b70 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/componentnodeinstance.cpp @@ -0,0 +1,95 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "componentnodeinstance.h" + +#include <QQmlComponent> +#include <QQmlContext> + +#include <QDebug> + +namespace QmlDesigner { +namespace Internal { + + +ComponentNodeInstance::ComponentNodeInstance(QQmlComponent *component) + : ObjectNodeInstance(component) +{ +} + +QQmlComponent *ComponentNodeInstance::component() const +{ + Q_ASSERT(qobject_cast<QQmlComponent*>(object())); + return static_cast<QQmlComponent*>(object()); +} + +ComponentNodeInstance::Pointer ComponentNodeInstance::create(QObject *object) +{ + QQmlComponent *component = qobject_cast<QQmlComponent *>(object); + + Q_ASSERT(component); + + Pointer instance(new ComponentNodeInstance(component)); + + instance->populateResetHashes(); + + return instance; +} + +bool ComponentNodeInstance::hasContent() const +{ + return true; +} + +void ComponentNodeInstance::setNodeSource(const QString &source) +{ + QByteArray importArray; + foreach (const QString &import, nodeInstanceServer()->imports()) { + importArray.append(import.toUtf8()); + } + + QByteArray data(source.toUtf8()); + + data.prepend(importArray); + data.append("\n"); + + component()->setData(data, QUrl(nodeInstanceServer()->fileUrl().toString() + + QLatin1Char('_')+ id())); + setId(id()); + + if (component()->isError()) { + foreach (const QQmlError &error, component()->errors()) + qDebug() << error; + } + +} + +} // Internal +} // QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/componentnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/componentnodeinstance.h new file mode 100644 index 0000000000..a8b73ba792 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/componentnodeinstance.h @@ -0,0 +1,63 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef COMPONENTNODEINSTANCE_H +#define COMPONENTNODEINSTANCE_H + +#include "objectnodeinstance.h" + +QT_BEGIN_NAMESPACE +class QQmlComponent; +QT_END_NAMESPACE + +namespace QmlDesigner { +namespace Internal { + +class ComponentNodeInstance : public ObjectNodeInstance +{ +public: + typedef QSharedPointer<ComponentNodeInstance> Pointer; + typedef QWeakPointer<ComponentNodeInstance> WeakPointer; + ComponentNodeInstance(QQmlComponent *component); + static Pointer create(QObject *objectToBeWrapped); + + bool hasContent() const; + + void setNodeSource(const QString &source); + +private: //function + QQmlComponent *component() const; + +}; + +} // Internal +} // QmlDesigner + +#endif // COMPONENTNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummycontextobject.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummycontextobject.cpp new file mode 100644 index 0000000000..ae78d1e2d1 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummycontextobject.cpp @@ -0,0 +1,53 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "dummycontextobject.h" + +namespace QmlDesigner { + +DummyContextObject::DummyContextObject(QObject *parent) : + QObject(parent) +{ +} + +QObject *DummyContextObject::parentDummy() const +{ + return m_dummyParent.data(); +} + +void DummyContextObject::setParentDummy(QObject *parentDummy) +{ + if (m_dummyParent.data() != parentDummy) { + m_dummyParent = parentDummy; + emit parentDummyChanged(); + } +} + +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummycontextobject.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummycontextobject.h new file mode 100644 index 0000000000..18d1afc147 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummycontextobject.h @@ -0,0 +1,61 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef DUMMYCONTEXTOBJECT_H +#define DUMMYCONTEXTOBJECT_H + +#include <QObject> +#include <QWeakPointer> +#include <qqml.h> + +namespace QmlDesigner { + +class DummyContextObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject * parent READ parentDummy WRITE setParentDummy NOTIFY parentDummyChanged DESIGNABLE false FINAL) + +public: + explicit DummyContextObject(QObject *parent = 0); + + QObject *parentDummy() const; + void setParentDummy(QObject *parentDummy); + +signals: + void parentDummyChanged(); + +private: + QWeakPointer<QObject> m_dummyParent; +}; + +} // namespace QmlDesigner + +QML_DECLARE_TYPE(QmlDesigner::DummyContextObject) +#endif // DUMMYCONTEXTOBJECT_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummynodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummynodeinstance.cpp new file mode 100644 index 0000000000..9b2a8f1945 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummynodeinstance.cpp @@ -0,0 +1,110 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "dummynodeinstance.h" + +namespace QmlDesigner { +namespace Internal { + +DummyNodeInstance::DummyNodeInstance() + : ObjectNodeInstance(new QObject) +{ +} + +DummyNodeInstance::Pointer DummyNodeInstance::create() +{ + return Pointer(new DummyNodeInstance); +} + +void DummyNodeInstance::paint(QPainter * /*painter*/) +{ +} + +QRectF DummyNodeInstance::boundingRect() const +{ + return QRectF(); +} + +QPointF DummyNodeInstance::position() const +{ + return QPointF(); +} + +QSizeF DummyNodeInstance::size() const +{ + return QSizeF(); +} + +QTransform DummyNodeInstance::transform() const +{ + return QTransform(); +} + +double DummyNodeInstance::opacity() const +{ + return 0.0; +} + +void DummyNodeInstance::setPropertyVariant(const QString &/*name*/, const QVariant &/*value*/) +{ +} + +void DummyNodeInstance::setPropertyBinding(const QString &/*name*/, const QString &/*expression*/) +{ + +} + +void DummyNodeInstance::setId(const QString &/*id*/) +{ + +} + +QVariant DummyNodeInstance::property(const QString &/*name*/) const +{ + return QVariant(); +} + +QStringList DummyNodeInstance::properties() +{ + return QStringList(); +} + +QStringList DummyNodeInstance::localProperties() +{ + return QStringList(); +} + +void DummyNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &/*objectNodeInstance*/) +{ + +} + +} // namespace Internal +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummynodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummynodeinstance.h new file mode 100644 index 0000000000..9724b5dd41 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/dummynodeinstance.h @@ -0,0 +1,73 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef DUMMYNODEINSTANCE_H +#define DUMMYNODEINSTANCE_H + +#include <QWeakPointer> + +#include "objectnodeinstance.h" + +namespace QmlDesigner { +namespace Internal { + +class DummyNodeInstance : public ObjectNodeInstance +{ +public: + typedef QSharedPointer<DummyNodeInstance> Pointer; + typedef QWeakPointer<DummyNodeInstance> WeakPointer; + + static Pointer create(); + + void paint(QPainter *painter); + + QRectF boundingRect() const; + QPointF position() const; + QSizeF size() const; + QTransform transform() const; + double opacity() const; + + void setPropertyVariant(const QString &name, const QVariant &value); + void setPropertyBinding(const QString &name, const QString &expression); + void setId(const QString &id); + QVariant property(const QString &name) const; + QStringList properties(); + QStringList localProperties(); + + void initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance); + +protected: + DummyNodeInstance(); + +}; + +} +} +#endif // DUMMYNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri index 1eeb3d40b5..8407e0da16 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri @@ -1,15 +1,45 @@ INCLUDEPATH += $$PWD/ -HEADERS += $$PWD/qt5nodeinstanceserver.h \ - instances/qt5informationnodeinstanceserver.h \ - instances/qt5rendernodeinstanceserver.h \ - instances/qt5previewnodeinstanceserver.h +HEADERS += $$PWD/qt5nodeinstanceserver.h +HEADERS += $$PWD/qt5informationnodeinstanceserver.h +HEADERS += $$PWD/qt5rendernodeinstanceserver.h +HEADERS += $$PWD/qt5previewnodeinstanceserver.h HEADERS += $$PWD/qt5nodeinstanceclientproxy.h HEADERS += $$PWD/sgitemnodeinstance.h +HEADERS += $$PWD/behaviornodeinstance.h +HEADERS += $$PWD/dummycontextobject.h +HEADERS += $$PWD/childrenchangeeventfilter.h +HEADERS += $$PWD/componentnodeinstance.h +HEADERS += $$PWD/dummynodeinstance.h +HEADERS += $$PWD/nodeinstanceclientproxy.h +HEADERS += $$PWD/nodeinstancemetaobject.h +HEADERS += $$PWD/nodeinstanceserver.h +HEADERS += $$PWD/nodeinstancesignalspy.h +HEADERS += $$PWD/objectnodeinstance.h +HEADERS += $$PWD/qmlpropertychangesnodeinstance.h +HEADERS += $$PWD/qmlstatenodeinstance.h +HEADERS += $$PWD/qmltransitionnodeinstance.h +HEADERS += $$PWD/servernodeinstance.h +HEADERS += $$PWD/anchorchangesnodeinstance.h -SOURCES += $$PWD/qt5nodeinstanceserver.cpp \ - instances/qt5informationnodeinstanceserver.cpp \ - instances/qt5rendernodeinstanceserver.cpp \ - instances/qt5previewnodeinstanceserver.cpp +SOURCES += $$PWD/qt5nodeinstanceserver.cpp +SOURCES += $$PWD/qt5informationnodeinstanceserver.cpp +SOURCES += $$PWD/qt5rendernodeinstanceserver.cpp +SOURCES += $$PWD/qt5previewnodeinstanceserver.cpp SOURCES += $$PWD/qt5nodeinstanceclientproxy.cpp SOURCES += $$PWD/sgitemnodeinstance.cpp +SOURCES += $$PWD/behaviornodeinstance.cpp +SOURCES += $$PWD/dummycontextobject.cpp +SOURCES += $$PWD/childrenchangeeventfilter.cpp +SOURCES += $$PWD/componentnodeinstance.cpp +SOURCES += $$PWD/dummynodeinstance.cpp +SOURCES += $$PWD/nodeinstanceclientproxy.cpp +SOURCES += $$PWD/nodeinstancemetaobject.cpp +SOURCES += $$PWD/nodeinstanceserver.cpp +SOURCES += $$PWD/nodeinstancesignalspy.cpp +SOURCES += $$PWD/objectnodeinstance.cpp +SOURCES += $$PWD/qmlpropertychangesnodeinstance.cpp +SOURCES += $$PWD/qmlstatenodeinstance.cpp +SOURCES += $$PWD/qmltransitionnodeinstance.cpp +SOURCES += $$PWD/servernodeinstance.cpp +SOURCES += $$PWD/anchorchangesnodeinstance.cpp diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceclientproxy.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceclientproxy.cpp new file mode 100644 index 0000000000..6faaa870a6 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceclientproxy.cpp @@ -0,0 +1,346 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "nodeinstanceclientproxy.h" + +#include <QLocalSocket> +#include <QVariant> +#include <QCoreApplication> +#include <QStringList> + +#include "nodeinstanceserverinterface.h" + +#include "propertyabstractcontainer.h" +#include "propertyvaluecontainer.h" +#include "propertybindingcontainer.h" +#include "instancecontainer.h" +#include "createinstancescommand.h" +#include "createscenecommand.h" +#include "changevaluescommand.h" +#include "changebindingscommand.h" +#include "changeauxiliarycommand.h" +#include "changefileurlcommand.h" +#include "removeinstancescommand.h" +#include "clearscenecommand.h" +#include "removepropertiescommand.h" +#include "reparentinstancescommand.h" +#include "changeidscommand.h" +#include "changestatecommand.h" +#include "completecomponentcommand.h" +#include "synchronizecommand.h" +#include "removesharedmemorycommand.h" +#include "tokencommand.h" + +#include "informationchangedcommand.h" +#include "pixmapchangedcommand.h" +#include "valueschangedcommand.h" +#include "childrenchangedcommand.h" +#include "imagecontainer.h" +#include "statepreviewimagechangedcommand.h" +#include "componentcompletedcommand.h" +#include "changenodesourcecommand.h" + +namespace QmlDesigner { + +NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent) + : QObject(parent), + m_nodeInstanceServer(0), + m_blockSize(0), + m_writeCommandCounter(0), + m_lastReadCommandCounter(0), + m_synchronizeId(-1) +{ +} + +void NodeInstanceClientProxy::initializeSocket() +{ + m_socket = new QLocalSocket(this); + connect(m_socket, SIGNAL(readyRead()), this, SLOT(readDataStream())); + connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit())); + connect(m_socket, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit())); + m_socket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered); + m_socket->waitForConnected(-1); +} + +void NodeInstanceClientProxy::writeCommand(const QVariant &command) +{ + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out << quint32(0); + out << quint32(m_writeCommandCounter); + m_writeCommandCounter++; + out << command; + out.device()->seek(0); + out << quint32(block.size() - sizeof(quint32)); + + m_socket->write(block); +} + +void NodeInstanceClientProxy::informationChanged(const InformationChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::childrenChanged(const ChildrenChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::token(const TokenCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::flush() +{ +} + +void NodeInstanceClientProxy::synchronizeWithClientProcess() +{ + if (m_synchronizeId >= 0) { + SynchronizeCommand synchronizeCommand(m_synchronizeId); + writeCommand(QVariant::fromValue(synchronizeCommand)); + } +} + +qint64 NodeInstanceClientProxy::bytesToWrite() const +{ + return m_socket->bytesToWrite(); +} + +void NodeInstanceClientProxy::readDataStream() +{ + QList<QVariant> commandList; + + while (!m_socket->atEnd()) { + if (m_socket->bytesAvailable() < int(sizeof(quint32))) + break; + + QDataStream in(m_socket); + + if (m_blockSize == 0) { + in >> m_blockSize; + } + + if (m_socket->bytesAvailable() < m_blockSize) + break; + + quint32 commandCounter; + in >> commandCounter; + bool commandLost = !((m_lastReadCommandCounter == 0 && commandCounter == 0) || (m_lastReadCommandCounter + 1 == commandCounter)); + if (commandLost) + qDebug() << "client command lost: " << m_lastReadCommandCounter << commandCounter; + m_lastReadCommandCounter = commandCounter; + + QVariant command; + in >> command; + m_blockSize = 0; + + if (in.status() != QDataStream::Ok) { + qWarning() << "Stream is no ok!!!"; + exit(1); + } + + commandList.append(command); + } + + foreach (const QVariant &command, commandList) { + dispatchCommand(command); + } +} + +NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const +{ + return m_nodeInstanceServer; +} + +void NodeInstanceClientProxy::setNodeInstanceServer(NodeInstanceServerInterface *nodeInstanceServer) +{ + m_nodeInstanceServer = nodeInstanceServer; +} + +void NodeInstanceClientProxy::createInstances(const CreateInstancesCommand &command) +{ + nodeInstanceServer()->createInstances(command); +} + +void NodeInstanceClientProxy::changeFileUrl(const ChangeFileUrlCommand &command) +{ + nodeInstanceServer()->changeFileUrl(command); +} + +void NodeInstanceClientProxy::createScene(const CreateSceneCommand &command) +{ + nodeInstanceServer()->createScene(command); +} + +void NodeInstanceClientProxy::clearScene(const ClearSceneCommand &command) +{ + nodeInstanceServer()->clearScene(command); +} + +void NodeInstanceClientProxy::removeInstances(const RemoveInstancesCommand &command) +{ + nodeInstanceServer()->removeInstances(command); +} + +void NodeInstanceClientProxy::removeProperties(const RemovePropertiesCommand &command) +{ + nodeInstanceServer()->removeProperties(command); +} + +void NodeInstanceClientProxy::changePropertyBindings(const ChangeBindingsCommand &command) +{ + nodeInstanceServer()->changePropertyBindings(command); +} + +void NodeInstanceClientProxy::changePropertyValues(const ChangeValuesCommand &command) +{ + nodeInstanceServer()->changePropertyValues(command); +} + +void NodeInstanceClientProxy::changeAuxiliaryValues(const ChangeAuxiliaryCommand &command) +{ + nodeInstanceServer()->changeAuxiliaryValues(command); +} + +void NodeInstanceClientProxy::reparentInstances(const ReparentInstancesCommand &command) +{ + nodeInstanceServer()->reparentInstances(command); +} + +void NodeInstanceClientProxy::changeIds(const ChangeIdsCommand &command) +{ + nodeInstanceServer()->changeIds(command); +} + +void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command) +{ + nodeInstanceServer()->changeState(command); +} + +void NodeInstanceClientProxy::completeComponent(const CompleteComponentCommand &command) +{ + nodeInstanceServer()->completeComponent(command); +} + +void NodeInstanceClientProxy::changeNodeSource(const ChangeNodeSourceCommand &command) +{ + nodeInstanceServer()->changeNodeSource(command); +} + +void NodeInstanceClientProxy::removeSharedMemory(const RemoveSharedMemoryCommand &command) +{ + nodeInstanceServer()->removeSharedMemory(command); +} +void NodeInstanceClientProxy::redirectToken(const TokenCommand &command) +{ + nodeInstanceServer()->token(command); +} + +void NodeInstanceClientProxy::dispatchCommand(const QVariant &command) +{ + static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand"); + static const int changeFileUrlCommandType = QMetaType::type("ChangeFileUrlCommand"); + static const int createSceneCommandType = QMetaType::type("CreateSceneCommand"); + static const int clearSceneCommandType = QMetaType::type("ClearSceneCommand"); + static const int removeInstancesCommandType = QMetaType::type("RemoveInstancesCommand"); + static const int removePropertiesCommandType = QMetaType::type("RemovePropertiesCommand"); + static const int changeBindingsCommandType = QMetaType::type("ChangeBindingsCommand"); + static const int changeValuesCommandType = QMetaType::type("ChangeValuesCommand"); + static const int changeAuxiliaryCommandType = QMetaType::type("ChangeAuxiliaryCommand"); + static const int reparentInstancesCommandType = QMetaType::type("ReparentInstancesCommand"); + static const int changeIdsCommandType = QMetaType::type("ChangeIdsCommand"); + static const int changeStateCommandType = QMetaType::type("ChangeStateCommand"); + static const int completeComponentCommandType = QMetaType::type("CompleteComponentCommand"); + static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand"); + static const int changeNodeSourceCommandType = QMetaType::type("ChangeNodeSourceCommand"); + static const int removeSharedMemoryCommandType = QMetaType::type("RemoveSharedMemoryCommand"); + static const int tokenCommandType = QMetaType::type("TokenCommand"); + + if (command.userType() == createInstancesCommandType) { + createInstances(command.value<CreateInstancesCommand>()); + } else if (command.userType() == changeFileUrlCommandType) + changeFileUrl(command.value<ChangeFileUrlCommand>()); + else if (command.userType() == createSceneCommandType) + createScene(command.value<CreateSceneCommand>()); + else if (command.userType() == clearSceneCommandType) + clearScene(command.value<ClearSceneCommand>()); + else if (command.userType() == removeInstancesCommandType) + removeInstances(command.value<RemoveInstancesCommand>()); + else if (command.userType() == removePropertiesCommandType) + removeProperties(command.value<RemovePropertiesCommand>()); + else if (command.userType() == changeBindingsCommandType) + changePropertyBindings(command.value<ChangeBindingsCommand>()); + else if (command.userType() == changeValuesCommandType) + changePropertyValues(command.value<ChangeValuesCommand>()); + else if (command.userType() == changeAuxiliaryCommandType) + changeAuxiliaryValues(command.value<ChangeAuxiliaryCommand>()); + else if (command.userType() == reparentInstancesCommandType) + reparentInstances(command.value<ReparentInstancesCommand>()); + else if (command.userType() == changeIdsCommandType) + changeIds(command.value<ChangeIdsCommand>()); + else if (command.userType() == changeStateCommandType) + changeState(command.value<ChangeStateCommand>()); + else if (command.userType() == completeComponentCommandType) + completeComponent(command.value<CompleteComponentCommand>()); + else if (command.userType() == changeNodeSourceCommandType) + changeNodeSource(command.value<ChangeNodeSourceCommand>()); + else if (command.userType() == removeSharedMemoryCommandType) + removeSharedMemory(command.value<RemoveSharedMemoryCommand>()); + else if (command.userType() == tokenCommandType) + redirectToken(command.value<TokenCommand>()); + else if (command.userType() == synchronizeCommandType) { + SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>(); + m_synchronizeId = synchronizeCommand.synchronizeId(); + } else + Q_ASSERT(false); +} +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceclientproxy.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceclientproxy.h new file mode 100644 index 0000000000..7c503ddcc1 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceclientproxy.h @@ -0,0 +1,120 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef NODEINSTANCECLIENTPROXY_H +#define NODEINSTANCECLIENTPROXY_H + +#include "nodeinstanceclientinterface.h" + +#include <QObject> +#include <QHash> +#include <QWeakPointer> + +QT_BEGIN_NAMESPACE +class QLocalSocket; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceServerInterface; +class CreateSceneCommand; +class CreateInstancesCommand; +class ClearSceneCommand; +class ReparentInstancesCommand; +class ChangeFileUrlCommand; +class ChangeValuesCommand; +class ChangeAuxiliaryCommand; +class ChangeBindingsCommand; +class ChangeIdsCommand; +class RemoveInstancesCommand; +class RemovePropertiesCommand; +class CompleteComponentCommand; +class ChangeStateCommand; +class ChangeNodeSourceCommand; + + +class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface +{ + Q_OBJECT + +public: + NodeInstanceClientProxy(QObject *parent = 0); + + void informationChanged(const InformationChangedCommand &command); + void valuesChanged(const ValuesChangedCommand &command); + void pixmapChanged(const PixmapChangedCommand &command); + void childrenChanged(const ChildrenChangedCommand &command); + void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command); + void componentCompleted(const ComponentCompletedCommand &command); + void token(const TokenCommand &command); + + void flush(); + void synchronizeWithClientProcess(); + qint64 bytesToWrite() const; + +protected: + void initializeSocket(); + void writeCommand(const QVariant &command); + void dispatchCommand(const QVariant &command); + NodeInstanceServerInterface *nodeInstanceServer() const; + void setNodeInstanceServer(NodeInstanceServerInterface *nodeInstanceServer); + + void createInstances(const CreateInstancesCommand &command); + void changeFileUrl(const ChangeFileUrlCommand &command); + void createScene(const CreateSceneCommand &command); + void clearScene(const ClearSceneCommand &command); + void removeInstances(const RemoveInstancesCommand &command); + void removeProperties(const RemovePropertiesCommand &command); + void changePropertyBindings(const ChangeBindingsCommand &command); + void changePropertyValues(const ChangeValuesCommand &command); + void changeAuxiliaryValues(const ChangeAuxiliaryCommand &command); + void reparentInstances(const ReparentInstancesCommand &command); + void changeIds(const ChangeIdsCommand &command); + void changeState(const ChangeStateCommand &command); + void completeComponent(const CompleteComponentCommand &command); + void changeNodeSource(const ChangeNodeSourceCommand &command); + void removeSharedMemory(const RemoveSharedMemoryCommand &command); + void redirectToken(const TokenCommand &command); + +private slots: + void readDataStream(); + +private: + QLocalSocket *m_socket; + NodeInstanceServerInterface *m_nodeInstanceServer; + quint32 m_blockSize; + quint32 m_writeCommandCounter; + quint32 m_lastReadCommandCounter; + int m_synchronizeId; +}; + +} // namespace QmlDesigner + +#endif // NODEINSTANCECLIENTPROXY_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancemetaobject.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancemetaobject.cpp new file mode 100644 index 0000000000..2697682bd2 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancemetaobject.cpp @@ -0,0 +1,140 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "nodeinstancemetaobject.h" + +#include "objectnodeinstance.h" +#include <QSharedPointer> +#include <QMetaProperty> +#include <qnumeric.h> +#include <QDebug> + +namespace QmlDesigner { +namespace Internal { + +NodeInstanceMetaObject::NodeInstanceMetaObject(const ObjectNodeInstance::Pointer &nodeInstance, QQmlEngine *engine) + : QQmlOpenMetaObject(nodeInstance->object(), new QQmlOpenMetaObjectType(nodeInstance->object()->metaObject(), engine), true), + m_nodeInstance(nodeInstance), + m_context(nodeInstance->isRootNodeInstance() ? nodeInstance->context() : 0) +{ + setCached(true); +} + +NodeInstanceMetaObject::NodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance, QObject *object, const QString &prefix, QQmlEngine *engine) + : QQmlOpenMetaObject(object, new QQmlOpenMetaObjectType(object->metaObject(), engine), true), + m_nodeInstance(nodeInstance), + m_prefix(prefix) +{ + setCached(true); +} + +void NodeInstanceMetaObject::createNewProperty(const QString &name) +{ + int id = createProperty(name.toLatin1(), 0); + setValue(id, QVariant()); + Q_ASSERT(id >= 0); + Q_UNUSED(id) +} + +int NodeInstanceMetaObject::metaCall(QMetaObject::Call call, int id, void **a) +{ + int metaCallReturnValue = -1; + + if (call == QMetaObject::WriteProperty + && property(id).userType() == QMetaType::QVariant + && reinterpret_cast<QVariant *>(a[0])->type() == QVariant::Double + && qIsNaN(reinterpret_cast<QVariant *>(a[0])->toDouble())) { + return -1; + } + + if (call == QMetaObject::WriteProperty + && property(id).userType() == QMetaType::Double + && qIsNaN(*reinterpret_cast<double*>(a[0]))) { + return -1; + } + + if (call == QMetaObject::WriteProperty + && property(id).userType() == QMetaType::Float + && qIsNaN(*reinterpret_cast<float*>(a[0]))) { + return -1; + } + + QVariant oldValue; + + if (call == QMetaObject::WriteProperty && !property(id).hasNotifySignal()) + { + oldValue = property(id).read(object()); + } + + ObjectNodeInstance::Pointer objectNodeInstance = m_nodeInstance.toStrongRef(); + + if (parent() && id < parent()->propertyOffset()) { + metaCallReturnValue = parent()->metaCall(call, id, a); + } else { + metaCallReturnValue = QQmlOpenMetaObject::metaCall(call, id, a); + } + + if ((call == QMetaObject::WriteProperty || call == QMetaObject::ReadProperty) && metaCallReturnValue < 0) { + if (objectNodeInstance + && objectNodeInstance->nodeInstanceServer() + && objectNodeInstance->nodeInstanceServer()->dummyContextObject() + && !(objectNodeInstance && !objectNodeInstance->isRootNodeInstance() && property(id).name() == QLatin1String("parent"))) { + + QObject *contextDummyObject = objectNodeInstance->nodeInstanceServer()->dummyContextObject(); + int properyIndex = contextDummyObject->metaObject()->indexOfProperty(property(id).name()); + if (properyIndex >= 0) + metaCallReturnValue = contextDummyObject->qt_metacall(call, properyIndex, a); + } + } + + if (metaCallReturnValue >= 0 + && call == QMetaObject::WriteProperty + && !property(id).hasNotifySignal() + && oldValue != property(id).read(object())) + notifyPropertyChange(id); + + return metaCallReturnValue; +} + +void NodeInstanceMetaObject::notifyPropertyChange(int id) +{ + ObjectNodeInstance::Pointer objectNodeInstance = m_nodeInstance.toStrongRef(); + + if (objectNodeInstance && objectNodeInstance->nodeInstanceServer()) { + if (id < type()->propertyOffset()) { + objectNodeInstance->nodeInstanceServer()->notifyPropertyChange(objectNodeInstance->instanceId(), m_prefix + property(id).name()); + } else { + objectNodeInstance->nodeInstanceServer()->notifyPropertyChange(objectNodeInstance->instanceId(), m_prefix + name(id - type()->propertyOffset())); + } + } +} + +} // namespace Internal +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancemetaobject.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancemetaobject.h new file mode 100644 index 0000000000..201c734f38 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancemetaobject.h @@ -0,0 +1,64 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef NODEINSTANCEMETAOBJECT_H +#define NODEINSTANCEMETAOBJECT_H + +#include <QQmlContext> +#include <private/qqmlopenmetaobject_p.h> + +namespace QmlDesigner { +namespace Internal { + +class ObjectNodeInstance; +typedef QSharedPointer<ObjectNodeInstance> ObjectNodeInstancePointer; +typedef QWeakPointer<ObjectNodeInstance> ObjectNodeInstanceWeakPointer; + +class NodeInstanceMetaObject : public QQmlOpenMetaObject +{ +public: + NodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance, QQmlEngine *engine); + NodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance, QObject *object, const QString &prefix, QQmlEngine *engine); + void createNewProperty(const QString &name); + +protected: + int metaCall(QMetaObject::Call _c, int _id, void **_a); + void notifyPropertyChange(int id); + +private: + ObjectNodeInstanceWeakPointer m_nodeInstance; + QString m_prefix; + QWeakPointer<QQmlContext> m_context; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // NODEINSTANCEMETAOBJECT_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp new file mode 100644 index 0000000000..b986eef73b --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp @@ -0,0 +1,1165 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "nodeinstanceserver.h" + +#include <QQmlEngine> +#include <QFileSystemWatcher> +#include <QUrl> +#include <QSet> +#include <QDir> +#include <QVariant> +#include <QMetaType> +#include <QQmlComponent> +#include <QQmlContext> +#include <qqmllist.h> +#include <QAbstractAnimation> +#include <private/qabstractanimation_p.h> +#include <QMutableVectorIterator> + +#include "servernodeinstance.h" +#include "objectnodeinstance.h" +#include "childrenchangeeventfilter.h" +#include "propertyabstractcontainer.h" +#include "propertybindingcontainer.h" +#include "propertyvaluecontainer.h" +#include "instancecontainer.h" +#include "createinstancescommand.h" +#include "changefileurlcommand.h" +#include "clearscenecommand.h" +#include "reparentinstancescommand.h" +#include "changevaluescommand.h" +#include "changeauxiliarycommand.h" +#include "changebindingscommand.h" +#include "changeidscommand.h" +#include "removeinstancescommand.h" +#include "nodeinstanceclientinterface.h" +#include "removepropertiescommand.h" +#include "valueschangedcommand.h" +#include "informationchangedcommand.h" +#include "pixmapchangedcommand.h" +#include "commondefines.h" +#include "childrenchangeeventfilter.h" +#include "changestatecommand.h" +#include "childrenchangedcommand.h" +#include "completecomponentcommand.h" +#include "componentcompletedcommand.h" +#include "createscenecommand.h" +#include "changenodesourcecommand.h" +#include "tokencommand.h" +#include "removesharedmemorycommand.h" + +#include "dummycontextobject.h" + + +namespace QmlDesigner { + +NodeInstanceServer::NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) : + NodeInstanceServerInterface(), + m_childrenChangeEventFilter(new Internal::ChildrenChangeEventFilter(this)), + m_nodeInstanceClient(nodeInstanceClient), + m_timer(0), + m_renderTimerInterval(16), + m_slowRenderTimer(false), + m_slowRenderTimerInterval(200) +{ + qmlRegisterType<DummyContextObject>("QmlDesigner", 1, 0, "DummyContextObject"); + + connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*))); +} + +NodeInstanceServer::~NodeInstanceServer() +{ +} + +QList<ServerNodeInstance> NodeInstanceServer::createInstances(const QVector<InstanceContainer> &containerVector) +{ + Q_ASSERT(declarativeView() || quickView()); + QList<ServerNodeInstance> instanceList; + foreach (const InstanceContainer &instanceContainer, containerVector) { + ServerNodeInstance instance; + if (instanceContainer.nodeSourceType() == InstanceContainer::ComponentSource) { + instance = ServerNodeInstance::create(this, instanceContainer, ServerNodeInstance::WrapAsComponent); + } else { + instance = ServerNodeInstance::create(this, instanceContainer, ServerNodeInstance::DoNotWrapAsComponent); + } + insertInstanceRelationship(instance); + instanceList.append(instance); + instance.internalObject()->installEventFilter(childrenChangeEventFilter()); + if (instanceContainer.instanceId() == 0) { + m_rootNodeInstance = instance; + resizeCanvasSizeToRootItemSize(); + } + + foreach (QQmlContext* context, allSubContextsForObject(instance.internalObject())) + setupDummysForContext(context); + } + + return instanceList; +} + +void NodeInstanceServer::createInstances(const CreateInstancesCommand &command) +{ + createInstances(command.instances()); + refreshBindings(); + startRenderTimer(); +} + +ServerNodeInstance NodeInstanceServer::instanceForId(qint32 id) const +{ + if (id < 0) + return ServerNodeInstance(); + + Q_ASSERT(m_idInstanceHash.contains(id)); + return m_idInstanceHash.value(id); +} + +bool NodeInstanceServer::hasInstanceForId(qint32 id) const +{ + if (id < 0) + return false; + + return m_idInstanceHash.contains(id); +} + +ServerNodeInstance NodeInstanceServer::instanceForObject(QObject *object) const +{ + Q_ASSERT(m_objectInstanceHash.contains(object)); + return m_objectInstanceHash.value(object); +} + +bool NodeInstanceServer::hasInstanceForObject(QObject *object) const +{ + if (object == 0) + return false; + + return m_objectInstanceHash.contains(object); +} + +void NodeInstanceServer::setRenderTimerInterval(int timerInterval) +{ + m_renderTimerInterval = timerInterval; +} + +void NodeInstanceServer::setSlowRenderTimerInterval(int timerInterval) +{ + m_slowRenderTimerInterval = timerInterval; +} + +void NodeInstanceServer::setTimerId(int timerId) +{ + m_timer = timerId; +} + +int NodeInstanceServer::timerId() const +{ + return m_timer; +} + +int NodeInstanceServer::renderTimerInterval() const +{ + return m_renderTimerInterval; +} + +void NodeInstanceServer::startRenderTimer() +{ + if (m_slowRenderTimer) + stopRenderTimer(); + + if (m_timer == 0) + m_timer = startTimer(m_renderTimerInterval); + + m_slowRenderTimer = false; +} + +void NodeInstanceServer::slowDownRenderTimer() +{ + if (!m_slowRenderTimer) + stopRenderTimer(); + + if (m_timer != 0) { + killTimer(m_timer); + m_timer = 0; + } + + if (m_timer == 0) + m_timer = startTimer(m_slowRenderTimerInterval); + + m_slowRenderTimer = true; +} + +void NodeInstanceServer::stopRenderTimer() +{ + if (m_timer) { + killTimer(m_timer); + m_timer = 0; + } +} + +void NodeInstanceServer::createScene(const CreateSceneCommand &command) +{ + initializeView(command.imports()); + QUnifiedTimer::instance()->setSlowdownFactor(0.00001); + QUnifiedTimer::instance()->setSlowModeEnabled(true); + + QList<ServerNodeInstance> instanceList = setupScene(command); + + refreshBindings(); + + startRenderTimer(); +} + +void NodeInstanceServer::clearScene(const ClearSceneCommand &/*command*/) +{ + stopRenderTimer(); + + removeAllInstanceRelationships(); + m_fileSystemWatcherHash.clear(); + m_rootNodeInstance.makeInvalid(); + m_changedPropertyList.clear(); + m_fileUrl.clear(); +} + +void NodeInstanceServer::removeInstances(const RemoveInstancesCommand &command) +{ + ServerNodeInstance oldState = activeStateInstance(); + if (activeStateInstance().isValid()) + activeStateInstance().deactivateState(); + + foreach (qint32 instanceId, command.instanceIds()) { + removeInstanceRelationsip(instanceId); + } + + if (oldState.isValid()) + oldState.activateState(); + + refreshBindings(); + startRenderTimer(); +} + +void NodeInstanceServer::removeProperties(const RemovePropertiesCommand &command) +{ + bool hasDynamicProperties = false; + foreach (const PropertyAbstractContainer &container, command.properties()) { + hasDynamicProperties |= container.isDynamic(); + resetInstanceProperty(container); + } + + if (hasDynamicProperties) + refreshBindings(); + + startRenderTimer(); +} + +void NodeInstanceServer::reparentInstances(const QVector<ReparentContainer> &containerVector) +{ + foreach (const ReparentContainer &container, containerVector) { + ServerNodeInstance instance = instanceForId(container.instanceId()); + if (instance.isValid()) { + instance.reparent(instanceForId(container.oldParentInstanceId()), container.oldParentProperty(), instanceForId(container.newParentInstanceId()), container.newParentProperty()); + } + } + +} + +void NodeInstanceServer::reparentInstances(const ReparentInstancesCommand &command) +{ + reparentInstances(command.reparentInstances()); + refreshBindings(); + startRenderTimer(); +} + +void NodeInstanceServer::changeState(const ChangeStateCommand &command) +{ + if (hasInstanceForId(command.stateInstanceId())) { + if (activeStateInstance().isValid()) + activeStateInstance().deactivateState(); + ServerNodeInstance instance = instanceForId(command.stateInstanceId()); + instance.activateState(); + } else { + if (activeStateInstance().isValid()) + activeStateInstance().deactivateState(); + } + + startRenderTimer(); +} + +void NodeInstanceServer::completeComponent(const CompleteComponentCommand &command) +{ + QList<ServerNodeInstance> instanceList; + + foreach (qint32 instanceId, command.instances()) { + if (hasInstanceForId(instanceId)) { + ServerNodeInstance instance = instanceForId(instanceId); + instance.doComponentComplete(); + instanceList.append(instance); + } + } + + refreshBindings(); + + startRenderTimer(); +} + +void NodeInstanceServer::changeNodeSource(const ChangeNodeSourceCommand &command) +{ + if (hasInstanceForId(command.instanceId())) { + ServerNodeInstance instance = instanceForId(command.instanceId()); + if (instance.isValid()) + instance.setNodeSource(command.nodeSource()); + } + + startRenderTimer(); +} + +void NodeInstanceServer::token(const TokenCommand &/*command*/) +{ + +} + +void NodeInstanceServer::removeSharedMemory(const RemoveSharedMemoryCommand &/*command*/) +{ +} + +void NodeInstanceServer::setupImports(const QVector<AddImportContainer> &containerVector) +{ + foreach (const AddImportContainer &container, containerVector) { + QString importStatement = QString("import "); + + if (!container.fileName().isEmpty()) + importStatement += '"' + container.fileName() + '"'; + else if (!container.url().isEmpty()) + importStatement += container.url().toString(); + + if (!container.version().isEmpty()) + importStatement += ' ' + container.version(); + + if (!container.alias().isEmpty()) + importStatement += " as " + container.alias(); + + importStatement.append('\n'); + + if (!m_importList.contains(importStatement)) + m_importList.append(importStatement); + } + + delete m_importComponent.data(); + delete m_importComponentObject.data(); + + m_importComponent = new QQmlComponent(engine(), 0); + QString componentString; + foreach (const QString &importStatement, m_importList) + componentString += QString("%1").arg(importStatement); + + componentString += QString("Item {}\n"); + + m_importComponent->setData(componentString.toUtf8(), fileUrl()); + m_importComponentObject = m_importComponent->create(); + + if (!m_importComponent->errorString().isEmpty()) + qDebug() << "QmlDesigner.NodeInstances: import wrong: " << m_importComponent->errorString(); +} + +void NodeInstanceServer::setupFileUrl(const QUrl &fileUrl) +{ + if (!fileUrl.isEmpty()) { + engine()->setBaseUrl(fileUrl); + m_fileUrl = fileUrl; + } +} + +void NodeInstanceServer::setupDummyData(const QUrl &fileUrl) +{ + if (!fileUrl.isEmpty()) { + QStringList dummyDataDirectoryList = dummyDataDirectories(QFileInfo(fileUrl.toLocalFile()).path()); + foreach (const QString &dummyDataDirectory, dummyDataDirectoryList) { + loadDummyDataFiles(dummyDataDirectory); + loadDummyDataContext(dummyDataDirectory); + } + } + + if (m_dummyContextObject.isNull()) + setupDefaultDummyData(); +} + +void NodeInstanceServer::setupDefaultDummyData() +{ + QQmlComponent component(engine()); + QByteArray defaultContextObjectArray("import QtQuick 1.0\n" + "import QmlDesigner 1.0\n" + "DummyContextObject {\n" + " parent: QtObject {\n" + " property real width: 360\n" + " property real height: 640\n" + " }\n" + "}\n"); + + component.setData(defaultContextObjectArray, fileUrl()); + m_dummyContextObject = component.create(); + + if (component.isError()) { + QList<QQmlError> errors = component.errors(); + foreach (const QQmlError &error, errors) { + qWarning() << error; + } + } + + if (m_dummyContextObject) { + qWarning() << "Loaded default dummy context object."; + m_dummyContextObject->setParent(this); + } + + refreshBindings(); +} + +QList<ServerNodeInstance> NodeInstanceServer::setupInstances(const CreateSceneCommand &command) +{ + QList<ServerNodeInstance> instanceList = createInstances(command.instances()); + + foreach (const IdContainer &container, command.ids()) { + if (hasInstanceForId(container.instanceId())) + instanceForId(container.instanceId()).setId(container.id()); + } + + foreach (const PropertyValueContainer &container, command.valueChanges()) { + if (container.isDynamic()) + setInstancePropertyVariant(container); + } + + foreach (const PropertyValueContainer &container, command.valueChanges()) { + if (!container.isDynamic()) + setInstancePropertyVariant(container); + } + + reparentInstances(command.reparentInstances()); + + foreach (const PropertyBindingContainer &container, command.bindingChanges()) { + if (container.isDynamic()) + setInstancePropertyBinding(container); + } + + foreach (const PropertyBindingContainer &container, command.bindingChanges()) { + if (!container.isDynamic()) + setInstancePropertyBinding(container); + } + + foreach (const PropertyValueContainer &container, command.auxiliaryChanges()) { + setInstanceAuxiliaryData(container); + } + + foreach (ServerNodeInstance instance, instanceList) + instance.doComponentComplete(); + + return instanceList; +} + +void NodeInstanceServer::changeFileUrl(const ChangeFileUrlCommand &command) +{ + m_fileUrl = command.fileUrl(); + + if (engine()) + engine()->setBaseUrl(m_fileUrl); + + refreshBindings(); + startRenderTimer(); +} + +void NodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) +{ + bool hasDynamicProperties = false; + foreach (const PropertyValueContainer &container, command.valueChanges()) { + hasDynamicProperties |= container.isDynamic(); + setInstancePropertyVariant(container); + } + + if (hasDynamicProperties) + refreshBindings(); + + startRenderTimer(); +} + +void NodeInstanceServer::changeAuxiliaryValues(const ChangeAuxiliaryCommand &command) +{ + foreach (const PropertyValueContainer &container, command.auxiliaryChanges()) { + setInstanceAuxiliaryData(container); + } + + startRenderTimer(); +} + +void NodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command) +{ + bool hasDynamicProperties = false; + foreach (const PropertyBindingContainer &container, command.bindingChanges()) { + hasDynamicProperties |= container.isDynamic(); + setInstancePropertyBinding(container); + } + + if (hasDynamicProperties) + refreshBindings(); + + startRenderTimer(); +} + +void NodeInstanceServer::changeIds(const ChangeIdsCommand &command) +{ + foreach (const IdContainer &container, command.ids()) { + if (hasInstanceForId(container.instanceId())) + instanceForId(container.instanceId()).setId(container.id()); + } + + refreshBindings(); + startRenderTimer(); +} + +QQmlContext *NodeInstanceServer::context() const +{ + if (m_importComponentObject) { + QQmlContext *importComponentContext = QQmlEngine::contextForObject(m_importComponentObject.data()); + if (importComponentContext) // this should be the default + return importComponentContext; + } + + if (engine()) + return rootContext(); + + return 0; +} + +QQmlContext *NodeInstanceServer::rootContext() const +{ + return engine()->rootContext(); +} + +const QVector<NodeInstanceServer::InstancePropertyPair> NodeInstanceServer::changedPropertyList() const +{ + return m_changedPropertyList; +} + +void NodeInstanceServer::clearChangedPropertyList() +{ + m_changedPropertyList.clear(); +} + +void NodeInstanceServer::setupDummysForContext(QQmlContext *context) +{ + foreach (const DummyPair& dummyPair, m_dummyObjectList) { + if (dummyPair.second) { + context->setContextProperty(dummyPair.first, dummyPair.second.data()); + } + } +} + + +QList<QQmlContext*> NodeInstanceServer::allSubContextsForObject(QObject *object) +{ + QList<QQmlContext*> contextList; + + if (object) { + foreach (QObject *subObject, allSubObjectsForObject(object)) { + QQmlContext *contextOfObject = QQmlEngine::contextForObject(subObject); + if (contextOfObject) { + if (contextOfObject != context() && !contextList.contains(contextOfObject)) + contextList.append(contextOfObject); + } + } + } + + return contextList; +} + +QList<QObject*> NodeInstanceServer::allSubObjectsForObject(QObject *object) +{ + QList<QObject*> subChildren; + if (object) { + subChildren = object->findChildren<QObject*>(); + } + + return subChildren; +} + +void NodeInstanceServer::removeAllInstanceRelationships() +{ + // prevent destroyed() signals calling back + + foreach (ServerNodeInstance instance, m_objectInstanceHash) { + if (instance.isValid()) + instance.setId(QString()); + } + + //first the root object + if (rootNodeInstance().internalObject()) + rootNodeInstance().internalObject()->disconnect(); + + rootNodeInstance().makeInvalid(); + + + foreach (ServerNodeInstance instance, m_objectInstanceHash) { + if (instance.internalObject()) + instance.internalObject()->disconnect(); + instance.makeInvalid(); + } + + m_idInstanceHash.clear(); + m_objectInstanceHash.clear(); +} + +QFileSystemWatcher *NodeInstanceServer::dummydataFileSystemWatcher() +{ + if (m_dummdataFileSystemWatcher.isNull()) { + m_dummdataFileSystemWatcher = new QFileSystemWatcher(this); + connect(m_dummdataFileSystemWatcher.data(), SIGNAL(fileChanged(QString)), this, SLOT(refreshDummyData(QString))); + } + + return m_dummdataFileSystemWatcher.data(); +} + +QFileSystemWatcher *NodeInstanceServer::fileSystemWatcher() +{ + if (m_fileSystemWatcher.isNull()) { + m_fileSystemWatcher = new QFileSystemWatcher(this); + connect(m_fileSystemWatcher.data(), SIGNAL(fileChanged(QString)), this, SLOT(refreshLocalFileProperty(QString))); + } + + return m_fileSystemWatcher.data(); +} + +Internal::ChildrenChangeEventFilter *NodeInstanceServer::childrenChangeEventFilter() const +{ + return m_childrenChangeEventFilter.data(); +} + +void NodeInstanceServer::addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path) +{ + if (!m_fileSystemWatcherHash.contains(path)) { + m_fileSystemWatcherHash.insert(path, ObjectPropertyPair(object, propertyName)); + fileSystemWatcher()->addPath(path); + } +} + +void NodeInstanceServer::removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path) +{ + if (m_fileSystemWatcherHash.contains(path)) { + fileSystemWatcher()->removePath(path); + m_fileSystemWatcherHash.remove(path, ObjectPropertyPair(object, propertyName)); + } +} + +void NodeInstanceServer::refreshLocalFileProperty(const QString &path) +{ + if (m_fileSystemWatcherHash.contains(path)) { + foreach (const ObjectPropertyPair &objectPropertyPair, m_fileSystemWatcherHash) { + QObject *object = objectPropertyPair.first.data(); + QString propertyName = objectPropertyPair.second; + + if (hasInstanceForObject(object)) { + instanceForObject(object).refreshProperty(propertyName); + } + } + } +} + +void NodeInstanceServer::refreshDummyData(const QString &path) +{ + engine()->clearComponentCache(); + QFileInfo filePath(path); + if (filePath.completeBaseName().contains("_dummycontext")) { + loadDummyContextObjectFile(filePath); + } else { + loadDummyDataFile(filePath); + } + + refreshBindings(); + startRenderTimer(); +} + +void NodeInstanceServer::addChangedProperty(const InstancePropertyPair &property) +{ + if (!m_changedPropertyList.contains(property)) + m_changedPropertyList.append(property); +} + +void NodeInstanceServer::emitParentChanged(QObject *child) +{ + if (hasInstanceForObject(child)) { + addChangedProperty(InstancePropertyPair(instanceForObject(child), "parent")); + } +} + +Internal::ChildrenChangeEventFilter *NodeInstanceServer::childrenChangeEventFilter() +{ + if (m_childrenChangeEventFilter.isNull()) { + m_childrenChangeEventFilter = new Internal::ChildrenChangeEventFilter(this); + connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*))); + } + + return m_childrenChangeEventFilter.data(); +} + +void NodeInstanceServer::resetInstanceProperty(const PropertyAbstractContainer &propertyContainer) +{ + if (hasInstanceForId(propertyContainer.instanceId())) { // TODO ugly workaround + ServerNodeInstance instance = instanceForId(propertyContainer.instanceId()); + Q_ASSERT(instance.isValid()); + + const QString name = propertyContainer.name(); + + if (activeStateInstance().isValid() && !instance.isSubclassOf("QtQuick/PropertyChanges")) { + bool statePropertyWasReseted = activeStateInstance().resetStateProperty(instance, name, instance.resetVariant(name)); + if (!statePropertyWasReseted) + instance.resetProperty(name); + } else { + instance.resetProperty(name); + } + + if (propertyContainer.isDynamic() && propertyContainer.instanceId() == 0 && engine()) + rootContext()->setContextProperty(name, QVariant()); + } +} + + +void NodeInstanceServer::setInstancePropertyBinding(const PropertyBindingContainer &bindingContainer) +{ + if (hasInstanceForId(bindingContainer.instanceId())) { + ServerNodeInstance instance = instanceForId(bindingContainer.instanceId()); + + const QString name = bindingContainer.name(); + const QString expression = bindingContainer.expression(); + + + if (activeStateInstance().isValid() && !instance.isSubclassOf("QtQuick/PropertyChanges")) { + bool stateBindingWasUpdated = activeStateInstance().updateStateBinding(instance, name, expression); + if (!stateBindingWasUpdated) { + if (bindingContainer.isDynamic()) + instance.setPropertyDynamicBinding(name, bindingContainer.dynamicTypeName(), expression); + else + instance.setPropertyBinding(name, expression); + } + } else { + if (bindingContainer.isDynamic()) + instance.setPropertyDynamicBinding(name, bindingContainer.dynamicTypeName(), expression); + else + instance.setPropertyBinding(name, expression); + } + } +} + + +void NodeInstanceServer::removeProperties(const QList<PropertyAbstractContainer> &propertyList) +{ + foreach (const PropertyAbstractContainer &property, propertyList) + resetInstanceProperty(property); +} + +void NodeInstanceServer::setInstancePropertyVariant(const PropertyValueContainer &valueContainer) +{ + if (hasInstanceForId(valueContainer.instanceId())) { + ServerNodeInstance instance = instanceForId(valueContainer.instanceId()); + + + const QString name = valueContainer.name(); + const QVariant value = valueContainer.value(); + + + if (activeStateInstance().isValid() && !instance.isSubclassOf("QtQuick/PropertyChanges")) { + bool stateValueWasUpdated = activeStateInstance().updateStateVariant(instance, name, value); + if (!stateValueWasUpdated) { + if (valueContainer.isDynamic()) + instance.setPropertyDynamicVariant(name, valueContainer.dynamicTypeName(), value); + else + instance.setPropertyVariant(name, value); + } + } else { //base state + if (valueContainer.isDynamic()) + instance.setPropertyDynamicVariant(name, valueContainer.dynamicTypeName(), value); + else + instance.setPropertyVariant(name, value); + } + + if (valueContainer.isDynamic() && valueContainer.instanceId() == 0 && engine()) + rootContext()->setContextProperty(name, Internal::ObjectNodeInstance::fixResourcePaths(value)); + } +} + +void NodeInstanceServer::setInstanceAuxiliaryData(const PropertyValueContainer &auxiliaryContainer) +{ + //instanceId() == 0: the item is root + if (auxiliaryContainer.instanceId() == 0 && (auxiliaryContainer.name() == QLatin1String("width") || + auxiliaryContainer.name() == QLatin1String("height"))) { + + if (!auxiliaryContainer.value().isNull()) { + setInstancePropertyVariant(auxiliaryContainer); + } else { + rootNodeInstance().resetProperty(auxiliaryContainer.name()); + } + } + if (auxiliaryContainer.name().endsWith(QLatin1String("@NodeInstance"))) { + QString propertyName = auxiliaryContainer.name().leftRef(auxiliaryContainer.name().count() - 12).toString(); + if (!auxiliaryContainer.value().isNull()) { + setInstancePropertyVariant(PropertyValueContainer(auxiliaryContainer.instanceId(), + propertyName, + auxiliaryContainer.value(), + auxiliaryContainer.dynamicTypeName())); + } else { + rootNodeInstance().resetProperty(propertyName); + } + } +} + + +QUrl NodeInstanceServer::fileUrl() const +{ + return m_fileUrl; +} + +ServerNodeInstance NodeInstanceServer::activeStateInstance() const +{ + return m_activeStateInstance; +} + +ServerNodeInstance NodeInstanceServer::rootNodeInstance() const +{ + return m_rootNodeInstance; +} + +void NodeInstanceServer::setStateInstance(const ServerNodeInstance &stateInstance) +{ + m_activeStateInstance = stateInstance; +} + +void NodeInstanceServer::clearStateInstance() +{ + m_activeStateInstance = ServerNodeInstance(); +} + +void NodeInstanceServer::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == m_timer) { + collectItemChangesAndSendChangeCommands(); + } + + NodeInstanceServerInterface::timerEvent(event); +} + +NodeInstanceClientInterface *NodeInstanceServer::nodeInstanceClient() const +{ + return m_nodeInstanceClient; +} + +static QVector<InformationContainer> createInformationVector(const QList<ServerNodeInstance> &instanceList, bool initial) +{ + QVector<InformationContainer> informationVector; + + foreach (const ServerNodeInstance &instance, instanceList) { + informationVector.append(InformationContainer(instance.instanceId(), Position, instance.position())); + informationVector.append(InformationContainer(instance.instanceId(), Transform, instance.transform())); + informationVector.append(InformationContainer(instance.instanceId(), SceneTransform, instance.sceneTransform())); + informationVector.append(InformationContainer(instance.instanceId(), Size, instance.size())); + informationVector.append(InformationContainer(instance.instanceId(), BoundingRect, instance.boundingRect())); + informationVector.append(InformationContainer(instance.instanceId(), Transform, instance.transform())); + informationVector.append(InformationContainer(instance.instanceId(), HasContent, instance.hasContent())); + informationVector.append(InformationContainer(instance.instanceId(), IsMovable, instance.isMovable())); + informationVector.append(InformationContainer(instance.instanceId(), IsResizable, instance.isResizable())); + informationVector.append(InformationContainer(instance.instanceId(), IsInPositioner, instance.isInPositioner())); + informationVector.append(InformationContainer(instance.instanceId(), PenWidth, instance.penWidth())); + informationVector.append(InformationContainer(instance.instanceId(), IsAnchoredByChildren, instance.isAnchoredByChildren())); + informationVector.append(InformationContainer(instance.instanceId(), IsAnchoredBySibling, instance.isAnchoredBySibling())); + + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.fill"), instance.hasAnchor("anchors.fill"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.centerIn"), instance.hasAnchor("anchors.centerIn"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.right"), instance.hasAnchor("anchors.right"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.top"), instance.hasAnchor("anchors.top"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.left"), instance.hasAnchor("anchors.left"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.bottom"), instance.hasAnchor("anchors.bottom"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.horizontalCenter"), instance.hasAnchor("anchors.horizontalCenter"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.verticalCenter"), instance.hasAnchor("anchors.verticalCenter"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.baseline"), instance.hasAnchor("anchors.baseline"))); + + QPair<QString, ServerNodeInstance> anchorPair = instance.anchor("anchors.fill"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.fill"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.centerIn"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.centerIn"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.right"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.right"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.top"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.top"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.left"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.left"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.bottom"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.bottom"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.horizontalCenter"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.horizontalCenter"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.verticalCenter"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.verticalCenter"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.baseline"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.baseline"), anchorPair.first, anchorPair.second.instanceId())); + + QStringList propertyNames = instance.propertyNames(); + + if (initial) { + foreach (const QString &propertyName,propertyNames) + informationVector.append(InformationContainer(instance.instanceId(), InstanceTypeForProperty, propertyName, instance.instanceType(propertyName))); + } + + foreach (const QString &propertyName,instance.propertyNames()) { + bool hasChanged = false; + bool hasBinding = instance.hasBindingForProperty(propertyName, &hasChanged); + if (hasChanged) + informationVector.append(InformationContainer(instance.instanceId(), HasBindingForProperty, propertyName, hasBinding)); + } + + } + + return informationVector; +} + + +ChildrenChangedCommand NodeInstanceServer::createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const +{ + QVector<qint32> instanceVector; + + foreach (const ServerNodeInstance &instance, instanceList) + instanceVector.append(instance.instanceId()); + + return ChildrenChangedCommand(parentInstance.instanceId(), instanceVector, createInformationVector(instanceList, false)); +} + +InformationChangedCommand NodeInstanceServer::createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial) const +{ + return InformationChangedCommand(createInformationVector(instanceList, initial)); +} + +static bool supportedVariantType(QVariant::Type type) +{ + return type < QVariant::UserType && type != QVariant::Icon; +} + +ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const +{ + QVector<PropertyValueContainer> valueVector; + + foreach (const ServerNodeInstance &instance, instanceList) { + foreach (const QString &propertyName, instance.propertyNames()) { + QVariant propertyValue = instance.property(propertyName); + if (supportedVariantType(propertyValue.type())) + valueVector.append(PropertyValueContainer(instance.instanceId(), propertyName, propertyValue, QString())); + } + } + + return ValuesChangedCommand(valueVector); +} + +ComponentCompletedCommand NodeInstanceServer::createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList) +{ + QVector<qint32> idVector; + foreach (const ServerNodeInstance &instance, instanceList) { + if (instance.instanceId() >= 0) + idVector.append(instance.instanceId()); + } + + return ComponentCompletedCommand(idVector); +} + +ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const +{ + QVector<PropertyValueContainer> valueVector; + + foreach (const InstancePropertyPair &property, propertyList) { + const QString propertyName = property.second; + const ServerNodeInstance instance = property.first; + + if ( instance.isValid()) { + QVariant propertyValue = instance.property(propertyName); + if (supportedVariantType(propertyValue.type())) + valueVector.append(PropertyValueContainer(instance.instanceId(), propertyName, propertyValue, QString())); + } + } + + return ValuesChangedCommand(valueVector); +} + +QStringList NodeInstanceServer::imports() const +{ + return m_importList; +} + +void NodeInstanceServer::addImportString(const QString &import) +{ + m_importList.append(import); +} + +QObject *NodeInstanceServer::dummyContextObject() const +{ + return m_dummyContextObject.data(); +} + +void NodeInstanceServer::notifyPropertyChange(qint32 instanceid, const QString &propertyName) +{ + if (hasInstanceForId(instanceid)) + addChangedProperty(InstancePropertyPair(instanceForId(instanceid), propertyName)); +} + +void NodeInstanceServer::insertInstanceRelationship(const ServerNodeInstance &instance) +{ + Q_ASSERT(instance.isValid()); + Q_ASSERT(!m_idInstanceHash.contains(instance.instanceId())); + Q_ASSERT(!m_objectInstanceHash.contains(instance.internalObject())); + m_objectInstanceHash.insert(instance.internalObject(), instance); + m_idInstanceHash.insert(instance.instanceId(), instance); +} + +void NodeInstanceServer::removeInstanceRelationsip(qint32 instanceId) +{ + if (hasInstanceForId(instanceId)) { + ServerNodeInstance instance = instanceForId(instanceId); + if (instance.isValid()) + instance.setId(QString()); + m_idInstanceHash.remove(instanceId); + m_objectInstanceHash.remove(instance.internalObject()); + instance.makeInvalid(); + } +} + +PixmapChangedCommand NodeInstanceServer::createPixmapChangedCommand(const QList<ServerNodeInstance> &instanceList) const +{ + QVector<ImageContainer> imageVector; + + foreach (const ServerNodeInstance &instance, instanceList) { + if (instance.isValid() && instance.hasContent()) + imageVector.append(ImageContainer(instance.instanceId(), instance.renderImage(), instance.instanceId())); + } + + return PixmapChangedCommand(imageVector); +} + +void NodeInstanceServer::loadDummyDataFile(const QFileInfo& qmlFileInfo) +{ + QQmlComponent component(engine(), qmlFileInfo.filePath()); + QObject *dummyData = component.create(); + if (component.isError()) { + QList<QQmlError> errors = component.errors(); + foreach (const QQmlError &error, errors) { + qWarning() << error; + } + } + + QVariant oldDummyDataObject = rootContext()->contextProperty(qmlFileInfo.completeBaseName()); + + if (dummyData) { + qWarning() << "Loaded dummy data:" << qmlFileInfo.filePath(); + rootContext()->setContextProperty(qmlFileInfo.completeBaseName(), dummyData); + dummyData->setParent(this); + m_dummyObjectList.append(DummyPair(qmlFileInfo.completeBaseName(), dummyData)); + } + + if (!oldDummyDataObject.isNull()) + delete oldDummyDataObject.value<QObject*>(); + + if (!dummydataFileSystemWatcher()->files().contains(qmlFileInfo.filePath())) + dummydataFileSystemWatcher()->addPath(qmlFileInfo.filePath()); + + if (rootNodeInstance().isValid() && rootNodeInstance().internalObject()) { + foreach (QQmlContext *context, allSubContextsForObject(rootNodeInstance().internalObject())) + setupDummysForContext(context); + } +} + +void NodeInstanceServer::loadDummyContextObjectFile(const QFileInfo& qmlFileInfo) +{ + delete m_dummyContextObject.data(); + + QQmlComponent component(engine(), qmlFileInfo.filePath()); + m_dummyContextObject = component.create(); + + if (component.isError()) { + QList<QQmlError> errors = component.errors(); + foreach (const QQmlError &error, errors) { + qWarning() << error; + } + } + + if (m_dummyContextObject) { + qWarning() << "Loaded dummy context object:" << qmlFileInfo.filePath(); + m_dummyContextObject->setParent(this); + } + + if (!dummydataFileSystemWatcher()->files().contains(qmlFileInfo.filePath())) + dummydataFileSystemWatcher()->addPath(qmlFileInfo.filePath()); + + refreshBindings(); +} + +void NodeInstanceServer::loadDummyDataFiles(const QString& directory) +{ + QDir dir(directory, "*.qml"); + QList<QFileInfo> filePathList = dir.entryInfoList(); + foreach (const QFileInfo &qmlFileInfo, filePathList) { + loadDummyDataFile(qmlFileInfo); + } +} + +void NodeInstanceServer::loadDummyDataContext(const QString& directory) +{ + QDir dir(directory+"/context", "*.qml"); + QList<QFileInfo> filePathList = dir.entryInfoList(); + QString baseName = QFileInfo(fileUrl().toLocalFile()).completeBaseName(); + foreach (const QFileInfo &qmlFileInfo, filePathList) { + if (qmlFileInfo.completeBaseName() == baseName) + loadDummyContextObjectFile(qmlFileInfo); + } +} + +QStringList NodeInstanceServer::dummyDataDirectories(const QString& directoryPath) +{ + QStringList dummyDataDirectoryList; + QDir directory(directoryPath); + while (true) { + if (directory.isRoot() || !directory.exists()) + return dummyDataDirectoryList; + + if (directory.exists("dummydata")) + dummyDataDirectoryList.prepend(directory.absoluteFilePath("dummydata")); + + directory.cdUp(); + } +} + +} + + + diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h new file mode 100644 index 0000000000..cacdc26640 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h @@ -0,0 +1,228 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef NODEINSTANCESERVER_H +#define NODEINSTANCESERVER_H + +#include <QUrl> +#include <QVector> +#include <QSet> +#include <QStringList> + +#include <nodeinstanceserverinterface.h> +#include "servernodeinstance.h" + +QT_BEGIN_NAMESPACE +class QFileSystemWatcher; +class QQmlView; +class QQuickView; +class QQmlEngine; +class QGraphicsObject; +class QFileInfo; +class QQmlComponent; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceClientInterface; +class ValuesChangedCommand; +class PixmapChangedCommand; +class InformationChangedCommand; +class ChildrenChangedCommand; +class ReparentContainer; +class ComponentCompletedCommand; +class AddImportContainer; + +namespace Internal { + class ChildrenChangeEventFilter; +} + +class NodeInstanceServer : public NodeInstanceServerInterface +{ + Q_OBJECT +public: + typedef QPair<QWeakPointer<QObject>, QString> ObjectPropertyPair; + typedef QPair<qint32, QString> IdPropertyPair; + typedef QPair<ServerNodeInstance, QString> InstancePropertyPair; + typedef QPair<QString, QWeakPointer<QObject> > DummyPair; + + explicit NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient); + ~NodeInstanceServer(); + + void createInstances(const CreateInstancesCommand &command); + void changeFileUrl(const ChangeFileUrlCommand &command); + void changePropertyValues(const ChangeValuesCommand &command); + void changePropertyBindings(const ChangeBindingsCommand &command); + void changeAuxiliaryValues(const ChangeAuxiliaryCommand &command); + void changeIds(const ChangeIdsCommand &command); + void createScene(const CreateSceneCommand &command); + void clearScene(const ClearSceneCommand &command); + void removeInstances(const RemoveInstancesCommand &command); + void removeProperties(const RemovePropertiesCommand &command); + void reparentInstances(const ReparentInstancesCommand &command); + void changeState(const ChangeStateCommand &command); + void completeComponent(const CompleteComponentCommand &command); + void changeNodeSource(const ChangeNodeSourceCommand &command); + void token(const TokenCommand &command); + void removeSharedMemory(const RemoveSharedMemoryCommand &command); + + ServerNodeInstance instanceForId(qint32 id) const; + bool hasInstanceForId(qint32 id) const; + + ServerNodeInstance instanceForObject(QObject *object) const; + bool hasInstanceForObject(QObject *object) const; + + virtual QQmlEngine *engine() const = 0; + QQmlContext *context() const; + + void removeAllInstanceRelationships(); + + QFileSystemWatcher *fileSystemWatcher(); + QFileSystemWatcher *dummydataFileSystemWatcher(); + Internal::ChildrenChangeEventFilter *childrenChangeEventFilter() const; + void addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path); + void removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path); + + QUrl fileUrl() const; + + ServerNodeInstance activeStateInstance() const; + void setStateInstance(const ServerNodeInstance &stateInstance); + void clearStateInstance(); + + ServerNodeInstance rootNodeInstance() const; + + void notifyPropertyChange(qint32 instanceid, const QString &propertyName); + + QStringList imports() const; + QObject *dummyContextObject() const; + + virtual QQmlView *declarativeView() const = 0; + virtual QQuickView *quickView() const = 0; + +public slots: + void refreshLocalFileProperty(const QString &path); + void refreshDummyData(const QString &path); + void emitParentChanged(QObject *child); + +protected: + QList<ServerNodeInstance> createInstances(const QVector<InstanceContainer> &container); + void reparentInstances(const QVector<ReparentContainer> &containerVector); + void addImportString(const QString &import); + + Internal::ChildrenChangeEventFilter *childrenChangeEventFilter(); + void resetInstanceProperty(const PropertyAbstractContainer &propertyContainer); + void setInstancePropertyBinding(const PropertyBindingContainer &bindingContainer); + void setInstancePropertyVariant(const PropertyValueContainer &valueContainer); + void setInstanceAuxiliaryData(const PropertyValueContainer &auxiliaryContainer); + void removeProperties(const QList<PropertyAbstractContainer> &propertyList); + + void insertInstanceRelationship(const ServerNodeInstance &instance); + void removeInstanceRelationsip(qint32 instanceId); + + NodeInstanceClientInterface *nodeInstanceClient() const; + + void timerEvent(QTimerEvent *); + + virtual void collectItemChangesAndSendChangeCommands() = 0; + + ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const; + ValuesChangedCommand createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const; + PixmapChangedCommand createPixmapChangedCommand(const QList<ServerNodeInstance> &instanceList) const; + InformationChangedCommand createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial = false) const; + ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const; + ComponentCompletedCommand createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList); + + void addChangedProperty(const InstancePropertyPair &property); + + virtual void startRenderTimer(); + void slowDownRenderTimer(); + void stopRenderTimer(); + void setRenderTimerInterval(int timerInterval); + int renderTimerInterval() const; + void setSlowRenderTimerInterval(int timerInterval); + + virtual void initializeView(const QVector<AddImportContainer> &importVector) = 0; + virtual QList<ServerNodeInstance> setupScene(const CreateSceneCommand &command) = 0; + void loadDummyDataFiles(const QString& directory); + void loadDummyDataContext(const QString& directory); + void loadDummyDataFile(const QFileInfo& fileInfo); + void loadDummyContextObjectFile(const QFileInfo& fileInfo); + static QStringList dummyDataDirectories(const QString& directoryPath); + + void setTimerId(int timerId); + int timerId() const; + + QQmlContext *rootContext() const; + + + const QVector<InstancePropertyPair> changedPropertyList() const; + void clearChangedPropertyList(); + + virtual void refreshBindings() = 0; + + void setupDummysForContext(QQmlContext *context); + + void setupFileUrl(const QUrl &fileUrl); + void setupImports(const QVector<AddImportContainer> &container); + void setupDummyData(const QUrl &fileUrl); + void setupDefaultDummyData(); + QList<ServerNodeInstance> setupInstances(const CreateSceneCommand &command); + + QList<QQmlContext*> allSubContextsForObject(QObject *object); + static QList<QObject*> allSubObjectsForObject(QObject *object); + + virtual void resizeCanvasSizeToRootItemSize() = 0; + +private: + ServerNodeInstance m_rootNodeInstance; + ServerNodeInstance m_activeStateInstance; + QHash<qint32, ServerNodeInstance> m_idInstanceHash; + QHash<QObject*, ServerNodeInstance> m_objectInstanceHash; + QMultiHash<QString, ObjectPropertyPair> m_fileSystemWatcherHash; + QList<QPair<QString, QWeakPointer<QObject> > > m_dummyObjectList; + QWeakPointer<QFileSystemWatcher> m_fileSystemWatcher; + QWeakPointer<QFileSystemWatcher> m_dummdataFileSystemWatcher; + QWeakPointer<Internal::ChildrenChangeEventFilter> m_childrenChangeEventFilter; + QUrl m_fileUrl; + NodeInstanceClientInterface *m_nodeInstanceClient; + int m_timer; + int m_renderTimerInterval; + bool m_slowRenderTimer; + int m_slowRenderTimerInterval; + QVector<InstancePropertyPair> m_changedPropertyList; + QStringList m_importList; + QWeakPointer<QObject> m_dummyContextObject; + QWeakPointer<QQmlComponent> m_importComponent; + QWeakPointer<QObject> m_importComponentObject; +}; + +} + +#endif // NODEINSTANCESERVER_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancesignalspy.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancesignalspy.cpp new file mode 100644 index 0000000000..0e52f897ab --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancesignalspy.cpp @@ -0,0 +1,125 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "nodeinstancesignalspy.h" +#include "objectnodeinstance.h" + +#include <QMetaProperty> +#include <QMetaObject> +#include <QDebug> +#include <QSharedPointer> +#include <private/qqmlmetatype_p.h> + +namespace QmlDesigner { +namespace Internal { + +NodeInstanceSignalSpy::NodeInstanceSignalSpy() : + QObject() +{ + blockSignals(true); +} + +void NodeInstanceSignalSpy::setObjectNodeInstance(const ObjectNodeInstance::Pointer &nodeInstance) +{ + methodeOffset = QObject::staticMetaObject.methodCount() + 1; + registerObject(nodeInstance->object()); + m_objectNodeInstance = nodeInstance; + +} + +void NodeInstanceSignalSpy::registerObject(QObject *spiedObject, const QString &prefix) +{ + if (m_registeredObjectList.contains(spiedObject)) // prevent cycles + return; + + m_registeredObjectList.append(spiedObject); + for (int index = QObject::staticMetaObject.propertyOffset(); + index < spiedObject->metaObject()->propertyCount(); + index++) { + QMetaProperty metaProperty = spiedObject->metaObject()->property(index); + + // handle dot properties and connect the signals to the object + if (metaProperty.isReadable() + && !metaProperty.isWritable() + && QQmlMetaType::isQObject(metaProperty.userType())) { + QObject *propertyObject = QQmlMetaType::toQObject(metaProperty.read(spiedObject)); + if (propertyObject) + registerObject(propertyObject, prefix + metaProperty.name() + QLatin1Char('.')); + } else if (metaProperty.hasNotifySignal()) { + QMetaMethod metaMethod = metaProperty.notifySignal(); + bool isConnecting = QMetaObject::connect(spiedObject, metaMethod.methodIndex(), this, methodeOffset, Qt::DirectConnection); + Q_ASSERT(isConnecting); + Q_UNUSED(isConnecting); + m_indexPropertyHash.insert(methodeOffset, prefix + metaProperty.name()); + methodeOffset++; + } + + // search recursive in objects + if (metaProperty.isReadable() + && metaProperty.isWritable() + && QQmlMetaType::isQObject(metaProperty.userType())) { + QObject *propertyObject = QQmlMetaType::toQObject(metaProperty.read(spiedObject)); + if (propertyObject) + registerObject(propertyObject, prefix + metaProperty.name() + QLatin1Char('/')); + } + + // search recursive in objects list + if (metaProperty.isReadable() + && QQmlMetaType::isList(metaProperty.userType())) { + QQmlListReference list(spiedObject, metaProperty.name()); + + if (list.canCount() && list.canAt()) { + + for (int i = 0; i < list.count(); i++) { + QObject *propertyObject = list.at(i); + if (propertyObject) + registerObject(propertyObject, prefix + metaProperty.name() + QLatin1Char('/')); + } + } + } + } +} + +int NodeInstanceSignalSpy::qt_metacall(QMetaObject::Call call, int methodId, void **a) +{ + if (call == QMetaObject::InvokeMetaMethod && methodId > QObject::staticMetaObject.methodCount()) { + ObjectNodeInstance::Pointer nodeInstance = m_objectNodeInstance.toStrongRef(); + + if (nodeInstance && nodeInstance->nodeInstanceServer() && nodeInstance->isValid()) { + nodeInstance->nodeInstanceServer()->notifyPropertyChange(nodeInstance->instanceId(), m_indexPropertyHash.value(methodId)); + } + + } + + return QObject::qt_metacall(call, methodId, a); +} + +} // namespace Internal +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancesignalspy.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancesignalspy.h new file mode 100644 index 0000000000..c222f37fa6 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstancesignalspy.h @@ -0,0 +1,67 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef NODEINSTANCESIGNALSPY_H +#define NODEINSTANCESIGNALSPY_H + +#include <QObject> +#include <QHash> +#include <QSharedPointer> + +namespace QmlDesigner { +namespace Internal { + +class ObjectNodeInstance; +typedef QSharedPointer<ObjectNodeInstance> ObjectNodeInstancePointer; +typedef QWeakPointer<ObjectNodeInstance> ObjectNodeInstanceWeakPointer; + +class NodeInstanceSignalSpy : public QObject +{ +public: + explicit NodeInstanceSignalSpy(); + + void setObjectNodeInstance(const ObjectNodeInstancePointer &nodeInstance); + + virtual int qt_metacall(QMetaObject::Call, int, void **); + +protected: + void registerObject(QObject *spiedObject, const QString &prefix = QString()); + +private: + int methodeOffset; + QHash<int, QString> m_indexPropertyHash; + QObjectList m_registeredObjectList; + ObjectNodeInstanceWeakPointer m_objectNodeInstance; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // NODEINSTANCESIGNALSPY_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp new file mode 100644 index 0000000000..d6905d0e83 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp @@ -0,0 +1,1197 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "objectnodeinstance.h" + + + +#include <QEvent> +#include <QGraphicsScene> +#include <QQmlContext> +#include <QQmlError> +#include <QQmlEngine> +#include <QQmlProperty> +#include <QQmlComponent> +#include <QSharedPointer> +#include <QFileInfo> +#include <QFileSystemWatcher> +#include <QPixmapCache> +#ifndef QT_NO_WEBKIT +#include <QGraphicsWebView> +#endif +#include <QGraphicsObject> + +#include <QTextDocument> +#include <QLibraryInfo> + +#include <private/qqmlbinding_p.h> +#include <private/qqmlmetatype_p.h> +#include <private/qqmlvaluetype_p.h> +#include <private/qquicktransition_p.h> +#include <private/qquickanimation_p.h> +#include <private/qquicktimer_p.h> + +namespace QmlDesigner { +namespace Internal { + +ObjectNodeInstance::ObjectNodeInstance(QObject *object) + : m_instanceId(-1), + m_deleteHeldInstance(true), + m_object(object), + m_metaObject(0), + m_isInPositioner(false) +{ + +} + +ObjectNodeInstance::~ObjectNodeInstance() +{ + destroy(); +} + +void ObjectNodeInstance::destroy() +{ + if (deleteHeldInstance()) { + // Remove from old property + if (object()) { + setId(QString()); + if (m_instanceId >= 0) { + reparent(parentInstance(), m_parentProperty, ObjectNodeInstance::Pointer(), QString()); + } + } + + if (object()) { + QObject *obj = object(); + m_object.clear(); + delete obj; + } + } + + m_metaObject = 0; + m_instanceId = -1; +} + +void ObjectNodeInstance::setInstanceId(qint32 id) +{ + m_instanceId = id; +} + +qint32 ObjectNodeInstance::instanceId() const +{ + return m_instanceId; +} + +NodeInstanceServer *ObjectNodeInstance::nodeInstanceServer() const +{ + return m_nodeInstanceServer.data(); +} + +void ObjectNodeInstance::setNodeInstanceServer(NodeInstanceServer *server) +{ + Q_ASSERT(!m_nodeInstanceServer.data()); + + m_nodeInstanceServer = server; +} + +static bool hasPropertiesWitoutNotifications(const QMetaObject *metaObject) +{ + for (int propertyIndex = QObject::staticMetaObject.propertyCount(); propertyIndex < metaObject->propertyCount(); propertyIndex++) { + if (!metaObject->property(propertyIndex).hasNotifySignal()) + return true; + } + + return false; +} + +void ObjectNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance) +{ + const QMetaObject *metaObject = objectNodeInstance->object()->metaObject(); + m_metaObject = new NodeInstanceMetaObject(objectNodeInstance, nodeInstanceServer()->engine()); + for (int propertyIndex = QObject::staticMetaObject.propertyCount(); propertyIndex < metaObject->propertyCount(); propertyIndex++) { + if (QQmlMetaType::isQObject(metaObject->property(propertyIndex).userType())) { + QObject *propertyObject = QQmlMetaType::toQObject(metaObject->property(propertyIndex).read(objectNodeInstance->object())); + if (propertyObject && hasPropertiesWitoutNotifications(propertyObject->metaObject())) { + new NodeInstanceMetaObject(objectNodeInstance, propertyObject, metaObject->property(propertyIndex).name(), nodeInstanceServer()->engine()); + } + } + } + + m_signalSpy.setObjectNodeInstance(objectNodeInstance); +} + +void ObjectNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance) +{ + initializePropertyWatcher(objectNodeInstance); +} + +void ObjectNodeInstance::setId(const QString &id) +{ + if (!m_id.isEmpty() && context()) { + context()->engine()->rootContext()->setContextProperty(m_id, 0); + } + + if (!id.isEmpty() && context()) { + context()->engine()->rootContext()->setContextProperty(id, object()); // will also force refresh of all bindings + } + + m_id = id; +} + +QString ObjectNodeInstance::id() const +{ + return m_id; +} + +bool ObjectNodeInstance::isQmlGraphicsItem() const +{ + return false; +} + + +bool ObjectNodeInstance::isGraphicsObject() const +{ + return false; +} + +bool ObjectNodeInstance::isTransition() const +{ + return false; +} + +bool ObjectNodeInstance::isPositioner() const +{ + return false; +} + +bool ObjectNodeInstance::isSGItem() const +{ + return false; +} + +bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const +{ + return false; +} + +QTransform ObjectNodeInstance::transform() const +{ + return QTransform(); +} + +QTransform ObjectNodeInstance::customTransform() const +{ + return QTransform(); +} + +QTransform ObjectNodeInstance::sceneTransform() const +{ + return QTransform(); +} + +double ObjectNodeInstance::rotation() const +{ + return 0.0; +} + +double ObjectNodeInstance::scale() const +{ + return 1.0; +} + +QList<QGraphicsTransform *> ObjectNodeInstance::transformations() const +{ + QList<QGraphicsTransform *> transformationsList; + + return transformationsList; +} + +QPointF ObjectNodeInstance::transformOriginPoint() const +{ + return QPoint(); +} + +double ObjectNodeInstance::zValue() const +{ + return 0.0; +} + +double ObjectNodeInstance::opacity() const +{ + return 1.0; +} + +bool ObjectNodeInstance::hasAnchor(const QString &/*name*/) const +{ + return false; +} + +bool ObjectNodeInstance::isAnchoredBySibling() const +{ + return false; +} + +bool ObjectNodeInstance::isAnchoredByChildren() const +{ + return false; +} + +QPair<QString, ServerNodeInstance> ObjectNodeInstance::anchor(const QString &/*name*/) const +{ + return qMakePair(QString(), ServerNodeInstance()); +} + + +static bool isList(const QQmlProperty &property) +{ + return property.propertyTypeCategory() == QQmlProperty::List; +} + +static bool isObject(const QQmlProperty &property) +{ + return (property.propertyTypeCategory() == QQmlProperty::Object) || + //QVariant can also store QObjects. Lets trust our model. + (QLatin1String(property.propertyTypeName()) == QLatin1String("QVariant")); +} + +static QVariant objectToVariant(QObject *object) +{ + return QVariant::fromValue(object); +} + +static bool hasFullImplementedListInterface(const QQmlListReference &list) +{ + return list.isValid() && list.canCount() && list.canAt() && list.canAppend() && list.canClear(); +} + +static void removeObjectFromList(const QQmlProperty &property, QObject *objectToBeRemoved, QQmlEngine * engine) +{ + QQmlListReference listReference(property.object(), property.name().toLatin1(), engine); + + if (!hasFullImplementedListInterface(listReference)) { + qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; + return; + } + + int count = listReference.count(); + + QObjectList objectList; + + for (int i = 0; i < count; i ++) { + QObject *listItem = listReference.at(i); + if (listItem && listItem != objectToBeRemoved) + objectList.append(listItem); + } + + listReference.clear(); + + foreach (QObject *object, objectList) + listReference.append(object); +} + +void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty) +{ + QQmlProperty property(oldParent, oldParentProperty, context()); + + if (!property.isValid()) + return; + + if (isList(property)) { + removeObjectFromList(property, object, nodeInstanceServer()->engine()); + } else if (isObject(property)) { + if (nodeInstanceServer()->hasInstanceForObject(oldParent)) { + nodeInstanceServer()->instanceForObject(oldParent).resetProperty(oldParentProperty); + } + } + + if (object && object->parent()) + object->setParent(0); +} + +void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, const QString &newParentProperty) +{ + QQmlProperty property(newParent, newParentProperty, context()); + + if (isList(property)) { + QQmlListReference list = qvariant_cast<QQmlListReference>(property.read()); + + if (!hasFullImplementedListInterface(list)) { + qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; + return; + } + + list.append(object); + } else if (isObject(property)) { + property.write(objectToVariant(object)); + } + + QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); + + if (object && !(graphicsObject && graphicsObject->parentItem())) + object->setParent(newParent); + + Q_ASSERT(objectToVariant(object).isValid()); +} + +void ObjectNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty) +{ + if (oldParentInstance) { + removeFromOldProperty(object(), oldParentInstance->object(), oldParentProperty); + m_parentProperty.clear(); + } + + if (newParentInstance) { + m_parentProperty = newParentProperty; + addToNewProperty(object(), newParentInstance->object(), newParentProperty); + } +} +QVariant ObjectNodeInstance::convertSpecialCharacter(const QVariant& value) const +{ + QVariant specialCharacterConvertedValue = value; + if (value.type() == QVariant::String) { + QString string = value.toString(); + string.replace(QLatin1String("\\n"), QLatin1String("\n")); + string.replace(QLatin1String("\\t"), QLatin1String("\t")); + specialCharacterConvertedValue = string; + } + + return specialCharacterConvertedValue; +} + + +QVariant ObjectNodeInstance::fixResourcePaths(const QVariant &value) +{ + if (value.type() == QVariant::Url) + { + const QUrl url = value.toUrl(); + if (url.scheme() == QLatin1String("qrc")) { + const QString path = QLatin1String("qrc:") + url.path(); + QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); + if (!qrcSearchPath.isEmpty()) { + const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); + foreach (const QString &qrcPath, searchPaths) { + const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); + if (qrcDefintion.count() == 2) { + QString fixedPath = path; + fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); + if (QFileInfo(fixedPath).exists()) { + fixedPath.replace(QLatin1String("//"), QLatin1String("/")); + fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); + return QUrl(fixedPath); + } + } + } + } + } + } + if (value.type() == QVariant::String) { + const QString str = value.toString(); + if (str.contains(QLatin1String("qrc:"))) { + QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); + if (!qrcSearchPath.isEmpty()) { + const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); + foreach (const QString &qrcPath, searchPaths) { + const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); + if (qrcDefintion.count() == 2) { + QString fixedPath = str; + fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); + if (QFileInfo(fixedPath).exists()) { + fixedPath.replace(QLatin1String("//"), QLatin1String("/")); + fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); + return fixedPath; + } + } + } + } + } + } + return value; +} + +void ObjectNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +{ + QQmlProperty property(object(), name, context()); + + if (!property.isValid()) + return; + + QVariant fixedValue = fixResourcePaths(value); + + QVariant oldValue = property.read(); + if (oldValue.type() == QVariant::Url) { + QUrl url = oldValue.toUrl(); + QString path = url.toLocalFile(); + if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) + nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path); + } + + if (hasValidResetBinding(name)) { + QQmlPropertyPrivate::setBinding(property, 0, QQmlPropertyPrivate::BypassInterceptor | QQmlPropertyPrivate::DontRemoveBinding); + } + + bool isWritten = property.write(convertSpecialCharacter(fixedValue)); + + if (!isWritten) + qDebug() << "ObjectNodeInstance.setPropertyVariant: Cannot be written: " << object() << name << fixedValue; + + QVariant newValue = property.read(); + if (newValue.type() == QVariant::Url) { + QUrl url = newValue.toUrl(); + QString path = url.toLocalFile(); + if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) + nodeInstanceServer()->addFilePropertyToFileSystemWatcher(object(), name, path); + } +} + +void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +{ + QQmlProperty property(object(), name, context()); + + if (!property.isValid()) + return; + + if (property.isProperty()) { + QQmlBinding *binding = new QQmlBinding(expression, object(), context()); + binding->setTarget(property); + binding->setNotifyOnValueChanged(true); + QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::setBinding(property, binding); + if (oldBinding && !hasValidResetBinding(name)) + oldBinding->destroy(); + binding->update(); + if (binding->hasError()) { + //qDebug() <<" ObjectNodeInstance.setPropertyBinding has Error: " << object() << name << expression << binding->error(engine()).toString(); + if (property.property().userType() == QVariant::String) + property.write(QVariant(QString("#%1#").arg(expression))); + } + + } else { + qWarning() << "ObjectNodeInstance.setPropertyBinding: Cannot set binding for property" << name << ": property is unknown for type"; + } +} + +void ObjectNodeInstance::deleteObjectsInList(const QQmlProperty &property) +{ + QObjectList objectList; + QQmlListReference list = qvariant_cast<QQmlListReference>(property.read()); + + if (!hasFullImplementedListInterface(list)) { + qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; + return; + } + + for (int i = 0; i < list.count(); i++) { + objectList += list.at(i); + } + + list.clear(); +} + +void ObjectNodeInstance::resetProperty(const QString &name) +{ + doResetProperty(name); + + if (name == "font.pixelSize") + doResetProperty("font.pointSize"); + + if (name == "font.pointSize") + doResetProperty("font.pixelSize"); +} + +void ObjectNodeInstance::refreshProperty(const QString &name) +{ + QQmlProperty property(object(), name, context()); + + if (!property.isValid()) + return; + + QVariant oldValue(property.read()); + + if (property.isResettable()) + property.reset(); + else + property.write(resetValue(name)); + + if (oldValue.type() == QVariant::Url) { + QByteArray key = oldValue.toUrl().toEncoded(QUrl::UrlFormattingOption(0x100)); + QString pixmapKey = QString::fromLatin1(key.constData(), key.count()); + QPixmapCache::remove(pixmapKey); + } + + property.write(oldValue); +} + +bool ObjectNodeInstance::hasBindingForProperty(const QString &name, bool *hasChanged) const +{ + QQmlProperty property(object(), name, context()); + + bool hasBinding = QQmlPropertyPrivate::binding(property); + + if (hasChanged) { + *hasChanged = hasBinding != m_hasBindingHash.value(name, false); + if (*hasChanged) + m_hasBindingHash.insert(name, hasBinding); + } + + return QQmlPropertyPrivate::binding(property); +} + +void ObjectNodeInstance::doResetProperty(const QString &propertyName) +{ + m_modelAbstractPropertyHash.remove(propertyName); + + QQmlProperty property(object(), propertyName, context()); + + if (!property.isValid()) + return; + + QVariant oldValue = property.read(); + if (oldValue.type() == QVariant::Url) { + QUrl url = oldValue.toUrl(); + QString path = url.toLocalFile(); + if (QFileInfo(path).exists() && nodeInstanceServer()) + nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), propertyName, path); + } + + + QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(property); + if (binding && !(hasValidResetBinding(propertyName) && resetBinding(propertyName) == binding)) { + binding->setEnabled(false, 0); + binding->destroy(); + } + + + if (hasValidResetBinding(propertyName)) { + QQmlAbstractBinding *binding = resetBinding(propertyName); + QQmlPropertyPrivate::setBinding(property, binding, QQmlPropertyPrivate::DontRemoveBinding); + binding->update(); + } else if (property.isResettable()) { + property.reset(); + } else if (property.propertyTypeCategory() == QQmlProperty::List) { + QQmlListReference list = qvariant_cast<QQmlListReference>(property.read()); + + if (!hasFullImplementedListInterface(list)) { + qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; + return; + } + + list.clear(); + } else if (property.isWritable()) { + if (property.read() == resetValue(propertyName)) + return; + + property.write(resetValue(propertyName)); + } +} + +QVariant ObjectNodeInstance::property(const QString &name) const +{ + if (m_modelAbstractPropertyHash.contains(name)) + return QVariant::fromValue(m_modelAbstractPropertyHash.value(name)); + + // TODO: handle model nodes + + QQmlProperty property(object(), name, context()); + if (property.property().isEnumType()) { + QVariant value = property.read(); + return property.property().enumerator().valueToKey(value.toInt()); + } + + if (property.propertyType() == QVariant::Url) { + QUrl url = property.read().toUrl(); + if (url.isEmpty()) + return QVariant(); + + if (url.scheme() == "file") { + int basePathLength = nodeInstanceServer()->fileUrl().toLocalFile().lastIndexOf('/'); + return QUrl(url.toLocalFile().mid(basePathLength + 1)); + } + } + + return property.read(); +} + +QStringList allPropertyNames(QObject *object, const QString &baseName = QString(), QObjectList *inspectedObjects = new QObjectList) +{ + QStringList propertyNameList; + + + if (inspectedObjects== 0 || inspectedObjects->contains(object)) + return propertyNameList; + + inspectedObjects->append(object); + + + const QMetaObject *metaObject = object->metaObject(); + for (int index = 0; index < metaObject->propertyCount(); ++index) { + QMetaProperty metaProperty = metaObject->property(index); + QQmlProperty declarativeProperty(object, QLatin1String(metaProperty.name())); + if (declarativeProperty.isValid() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) { + if (declarativeProperty.name() != "parent") { + QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read()); + if (childObject) + propertyNameList.append(allPropertyNames(childObject, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); + } + } else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) { + QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType()); + valueType->setValue(metaProperty.read(object)); + propertyNameList.append(allPropertyNames(valueType, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); + } else { + propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name())); + } + } + + return propertyNameList; +} + +QStringList ObjectNodeInstance::propertyNames() const +{ + if (isValid()) + return allPropertyNames(object()); + return QStringList(); +} + +QString ObjectNodeInstance::instanceType(const QString &name) const +{ + QQmlProperty property(object(), name, context()); + if (!property.isValid()) + return QLatin1String("undefined"); + return property.propertyTypeName(); +} + +QList<ServerNodeInstance> ObjectNodeInstance::childItems() const +{ + return QList<ServerNodeInstance>(); +} + +QList<ServerNodeInstance> ObjectNodeInstance::stateInstances() const +{ + return QList<ServerNodeInstance>(); +} + +void ObjectNodeInstance::setNodeSource(const QString & /*source*/) +{ +} + +void ObjectNodeInstance::setDeleteHeldInstance(bool deleteInstance) +{ + m_deleteHeldInstance = deleteInstance; +} + +bool ObjectNodeInstance::deleteHeldInstance() const +{ + return m_deleteHeldInstance; +} + +ObjectNodeInstance::Pointer ObjectNodeInstance::create(QObject *object) +{ + Pointer instance(new ObjectNodeInstance(object)); + + instance->populateResetHashes(); + + return instance; +} + +static void stopAnimation(QObject *object) +{ + if (object == 0) + return; + + QQuickTransition *transition = qobject_cast<QQuickTransition*>(object); + QQuickAbstractAnimation *animation = qobject_cast<QQuickAbstractAnimation*>(object); + QQuickTimer *timer = qobject_cast<QQuickTimer*>(object); + if (transition) { + transition->setFromState(""); + transition->setToState(""); + } else if (animation) { +// QQuickScriptAction *scriptAimation = qobject_cast<QQuickScriptAction*>(animation); +// if (scriptAimation) FIXME +// scriptAimation->setScript(QQmlScriptString()); + animation->setLoops(1); + animation->complete(); + animation->setDisableUserControl(); + } else if (timer) { + timer->blockSignals(true); + } +} + +void allSubObject(QObject *object, QObjectList &objectList) +{ + // don't add null pointer and stop if the object is already in the list + if (!object || objectList.contains(object)) + return; + + objectList.append(object); + + for (int index = QObject::staticMetaObject.propertyOffset(); + index < object->metaObject()->propertyCount(); + index++) { + QMetaProperty metaProperty = object->metaObject()->property(index); + + // search recursive in property objects + if (metaProperty.isReadable() + && metaProperty.isWritable() + && QQmlMetaType::isQObject(metaProperty.userType())) { + if (metaProperty.name() != QLatin1String("parent")) { + QObject *propertyObject = QQmlMetaType::toQObject(metaProperty.read(object)); + allSubObject(propertyObject, objectList); + } + + } + + // search recursive in property object lists + if (metaProperty.isReadable() + && QQmlMetaType::isList(metaProperty.userType())) { + QQmlListReference list(object, metaProperty.name()); + if (list.canCount() && list.canAt()) { + for (int i = 0; i < list.count(); i++) { + QObject *propertyObject = list.at(i); + allSubObject(propertyObject, objectList); + + } + } + } + } + + // search recursive in object children list + foreach (QObject *childObject, object->children()) { + allSubObject(childObject, objectList); + } + + // search recursive in graphics item childItems list + QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); + if (graphicsObject) { + foreach (QGraphicsItem *item, graphicsObject->childItems()) { + QGraphicsObject *childObject = item->toGraphicsObject(); + allSubObject(childObject, objectList); + } + } +} + +static void disableTiledBackingStore(QObject *object) +{ +#ifndef QT_NO_WEBKIT + QGraphicsWebView *webView = qobject_cast<QGraphicsWebView*>(object); + if (webView) + webView->settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, false); +#else + Q_UNUSED(object); +#endif +} + +QStringList propertyNameForWritableProperties(QObject *object, const QString &baseName = QString(), QObjectList *inspectedObjects = new QObjectList()) +{ + QStringList propertyNameList; + + if (inspectedObjects == 0 || inspectedObjects->contains(object)) + return propertyNameList; + + inspectedObjects->append(object); + + const QMetaObject *metaObject = object->metaObject(); + for (int index = 0; index < metaObject->propertyCount(); ++index) { + QMetaProperty metaProperty = metaObject->property(index); + QQmlProperty declarativeProperty(object, QLatin1String(metaProperty.name())); + if (declarativeProperty.isValid() && !declarativeProperty.isWritable() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) { + if (declarativeProperty.name() != "parent") { + QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read()); + if (childObject) + propertyNameList.append(propertyNameForWritableProperties(childObject, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); + } + } else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) { + QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType()); + valueType->setValue(metaProperty.read(object)); + propertyNameList.append(propertyNameForWritableProperties(valueType, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); + } else if (metaProperty.isReadable() && metaProperty.isWritable()) { + propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name())); + } + } + + return propertyNameList; +} + +static void fixResourcePathsForObject(QObject *object) +{ + if (qgetenv("QMLDESIGNER_RC_PATHS").isEmpty()) + return; + + QStringList propertyNameList = propertyNameForWritableProperties(object); + + foreach (const QString &propertyName, propertyNameList) { + QQmlProperty property(object, propertyName, QQmlEngine::contextForObject(object)); + + const QVariant value = property.read(); + const QVariant fixedValue = ObjectNodeInstance::fixResourcePaths(value); + if (value != fixedValue) { + property.write(fixedValue); + } + } +} + +void tweakObjects(QObject *object) +{ + QObjectList objectList; + allSubObject(object, objectList); + foreach (QObject* childObject, objectList) { + disableTiledBackingStore(childObject); + stopAnimation(childObject); + fixResourcePathsForObject(childObject); + } +} + +QObject *ObjectNodeInstance::createComponentWrap(const QString &nodeSource, const QStringList &imports, QQmlContext *context) +{ + QQmlComponent *component = new QQmlComponent(context->engine()); + + QByteArray importArray; + + foreach (const QString &import, imports) { + importArray.append(import.toUtf8()); + } + + QByteArray data(nodeSource.toUtf8()); + + data.prepend(importArray); + + component->setData(data, context->baseUrl().resolved(QUrl("createComponent.qml"))); + + QObject *object = component; + tweakObjects(object); + + if (object && context) + QQmlEngine::setContextForObject(object, context); + + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); + + return object; +} + + +//The component might also be shipped with Creator. +//To avoid trouble with import "." we use the component shipped with Creator. +static inline QString fixComponentPathForIncompatibleQt(const QString &componentPath) +{ + QString result = componentPath; + const QLatin1String importString("/imports/"); + + if (componentPath.contains(importString)) { + int index = componentPath.indexOf(importString) + 8; + const QString relativeImportPath = componentPath.right(componentPath.length() - index); + QString fixedComponentPath = QLibraryInfo::location(QLibraryInfo::ImportsPath) + relativeImportPath; + fixedComponentPath.replace(QLatin1Char('\\'), QLatin1Char('/')); + if (QFileInfo(fixedComponentPath).exists()) + return fixedComponentPath; + QString fixedPath = QFileInfo(fixedComponentPath).path(); + if (fixedPath.endsWith(QLatin1String(".1.0"))) { + //plugin directories might contain the version number + fixedPath.chop(4); + fixedPath += QLatin1Char('/') + QFileInfo(componentPath).fileName(); + if (QFileInfo(fixedPath).exists()) + return fixedPath; + } + } + + return result; +} + +QObject *ObjectNodeInstance::createComponent(const QString &componentPath, QQmlContext *context) +{ + QQmlComponent component(context->engine(), QUrl::fromLocalFile(fixComponentPathForIncompatibleQt(componentPath))); + QObject *object = component.beginCreate(context); + + tweakObjects(object); + component.completeCreate(); + + if (component.isError()) { + qDebug() << componentPath; + foreach (const QQmlError &error, component.errors()) + qDebug() << error; + } + + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); + + return object; +} + +QObject *ObjectNodeInstance::createCustomParserObject(const QString &nodeSource, const QStringList &imports, QQmlContext *context) +{ + QQmlComponent component(context->engine()); + + QByteArray importArray; + foreach (const QString &import, imports) { + importArray.append(import.toUtf8()); + } + + QByteArray data(nodeSource.toUtf8()); + + data.prepend(importArray); + + component.setData(data, context->baseUrl().resolved(QUrl("createCustomParserObject.qml"))); + + QObject *object = component.beginCreate(context); + tweakObjects(object); + component.completeCreate(); + + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); + + return object; +} + +QObject *ObjectNodeInstance::createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context) +{ + QObject *object = 0; + QQmlType *type = QQmlMetaType::qmlType(typeName.toUtf8(), majorNumber, minorNumber); + if (type) { + if (type->typeName() == "QQmlComponent") { + object = new QQmlComponent(context->engine(), 0); + } else { + object = type->create(); + } + } else { + qWarning() << "QuickDesigner: Cannot create an object of type" + << QString("%1 %2,%3").arg(typeName).arg(majorNumber).arg(minorNumber) + << "- type isn't known to declarative meta type system"; + } + + tweakObjects(object); + + if (object && context) + QQmlEngine::setContextForObject(object, context); + + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); + + return object; +} + +QObject *ObjectNodeInstance::object() const +{ + if (!m_object.isNull() && !QObjectPrivate::get(m_object.data())->wasDeleted) + return m_object.data(); + return 0; +} + +bool ObjectNodeInstance::hasContent() const +{ + return false; +} + +bool ObjectNodeInstance::isResizable() const +{ + return false; +} + +bool ObjectNodeInstance::isMovable() const +{ + return false; +} + +bool ObjectNodeInstance::isInPositioner() const +{ + return m_isInPositioner; +} + +void ObjectNodeInstance::setInPositioner(bool isInPositioner) +{ + m_isInPositioner = isInPositioner; +} + +void ObjectNodeInstance::refreshPositioner() +{ +} + +void ObjectNodeInstance::updateAnchors() +{ +} + +QQmlContext *ObjectNodeInstance::context() const +{ + if (nodeInstanceServer()) + return nodeInstanceServer()->context(); + + qWarning() << "Error: No NodeInstanceServer"; + return 0; +} + +QQmlEngine *ObjectNodeInstance::engine() const +{ + return nodeInstanceServer()->engine(); +} + +void ObjectNodeInstance::paintUpdate() +{ +} + +void ObjectNodeInstance::activateState() +{ +} + +void ObjectNodeInstance::deactivateState() +{ +} + +void ObjectNodeInstance::populateResetHashes() +{ + QStringList propertyNameList = propertyNameForWritableProperties(object()); + + foreach (const QString &propertyName, propertyNameList) { + QQmlProperty property(object(), propertyName, QQmlEngine::contextForObject(object())); + + QQmlAbstractBinding::Pointer binding = QQmlAbstractBinding::getPointer(QQmlPropertyPrivate::binding(property)); + if (binding) { + m_resetBindingHash.insert(propertyName, binding); + } else if (property.isWritable()) { + m_resetValueHash.insert(propertyName, property.read()); + } + } +} + +QQmlAbstractBinding *ObjectNodeInstance::resetBinding(const QString &propertyName) const +{ + return m_resetBindingHash.value(propertyName).data(); +} + +bool ObjectNodeInstance::hasValidResetBinding(const QString &propertyName) const +{ + return m_resetBindingHash.contains(propertyName) && m_resetBindingHash.value(propertyName).data(); +} + +QVariant ObjectNodeInstance::resetValue(const QString &propertyName) const +{ + return m_resetValueHash.value(propertyName); +} + +void ObjectNodeInstance::setResetValue(const QString &propertyName, const QVariant &value) +{ + m_resetValueHash.insert(propertyName, value); +} + +void ObjectNodeInstance::paint(QPainter * /*painter*/) +{ +} + +QImage ObjectNodeInstance::renderImage() const +{ + return QImage(); +} + +QObject *ObjectNodeInstance::parent() const +{ + if (!object()) + return 0; + + return object()->parent(); +} + +QObject *parentObject(QObject *object) +{ + QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); + if (graphicsObject) + return graphicsObject->parentObject(); + + return object->parent(); +} + +ObjectNodeInstance::Pointer ObjectNodeInstance::parentInstance() const +{ + QObject *parentHolder = parent(); + if (!nodeInstanceServer()) + return Pointer(); + + while (parentHolder) { + if (nodeInstanceServer()->hasInstanceForObject(parentHolder)) + return nodeInstanceServer()->instanceForObject(parentHolder).internalInstance(); + + parentHolder = parentObject(parentHolder); + } + + return Pointer(); +} + +QRectF ObjectNodeInstance::boundingRect() const +{ + return QRect(); +} + +QPointF ObjectNodeInstance::position() const +{ + return QPointF(); +} + +QSizeF ObjectNodeInstance::size() const +{ + return QSizeF(); +} + +int ObjectNodeInstance::penWidth() const +{ + return 0; +} + +void ObjectNodeInstance::createDynamicProperty(const QString &name, const QString &/*typeName*/) +{ + if (m_metaObject == 0) { + qWarning() << "ObjectNodeInstance.createDynamicProperty: No Metaobject."; + return; + } + + m_metaObject->createNewProperty(name); +} + +bool ObjectNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QVariant &/*value*/) +{ + return false; +} + +bool ObjectNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QString &/*expression*/) +{ + return false; +} + +bool ObjectNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QVariant &/*resetValue*/) +{ + return false; +} + +void ObjectNodeInstance::doComponentComplete() +{ + +} + +bool ObjectNodeInstance::isRootNodeInstance() const +{ + return nodeInstanceServer()->rootNodeInstance().isWrappingThisObject(object()); +} + +bool ObjectNodeInstance::isValid() const +{ + return instanceId() >= 0 && object(); +} + +} +} + diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.h new file mode 100644 index 0000000000..157cf82b6b --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.h @@ -0,0 +1,212 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef ABSTRACTNODEINSTANCE_H +#define ABSTRACTNODEINSTANCE_H + +#include "nodeinstanceserver.h" +#include "nodeinstancemetaobject.h" +#include "nodeinstancesignalspy.h" + +#include <QPainter> +#include <QSharedPointer> +#include <QWeakPointer> + +QT_BEGIN_NAMESPACE +class QGraphicsItem; +class QQmlContext; +class QQmlEngine; +class QQmlProperty; +class QQmlAbstractBinding; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceServer; + +namespace Internal { + +class QmlGraphicsItemNodeInstance; +class GraphicsWidgetNodeInstance; +class GraphicsViewNodeInstance; +class GraphicsSceneNodeInstance; +class ProxyWidgetNodeInstance; +class WidgetNodeInstance; + +class ObjectNodeInstance +{ +public: + typedef QSharedPointer<ObjectNodeInstance> Pointer; + typedef QWeakPointer<ObjectNodeInstance> WeakPointer; + explicit ObjectNodeInstance(QObject *object); + + virtual ~ObjectNodeInstance(); + void destroy(); + //void setModelNode(const ModelNode &node); + + static Pointer create(QObject *objectToBeWrapped); + static QObject *createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context); + static QObject *createCustomParserObject(const QString &nodeSource, const QStringList &imports, QQmlContext *context); + static QObject *createComponent(const QString &componentPath, QQmlContext *context); + static QObject *createComponentWrap(const QString &nodeSource, const QStringList &imports, QQmlContext *context); + + void setInstanceId(qint32 id); + qint32 instanceId() const; + + NodeInstanceServer *nodeInstanceServer() const; + void setNodeInstanceServer(NodeInstanceServer *server); + virtual void initializePropertyWatcher(const Pointer &objectNodeInstance); + virtual void initialize(const Pointer &objectNodeInstance); + virtual void paint(QPainter *painter); + virtual QImage renderImage() const; + + virtual QObject *parent() const; + + Pointer parentInstance() const; + + virtual void reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty); + + virtual void setId(const QString &id); + virtual QString id() const; + + virtual bool isQmlGraphicsItem() const; + virtual bool isGraphicsObject() const; + virtual bool isTransition() const; + virtual bool isPositioner() const; + virtual bool isSGItem() const; + + virtual bool equalGraphicsItem(QGraphicsItem *item) const; + + virtual QRectF boundingRect() const; + + virtual QPointF position() const; + virtual QSizeF size() const; + virtual QTransform transform() const; + virtual QTransform customTransform() const; + virtual QTransform sceneTransform() const; + virtual double opacity() const; + + virtual int penWidth() const; + + virtual bool hasAnchor(const QString &name) const; + virtual QPair<QString, ServerNodeInstance> anchor(const QString &name) const; + virtual bool isAnchoredBySibling() const; + virtual bool isAnchoredByChildren() const; + + virtual double rotation() const; + virtual double scale() const; + virtual QList<QGraphicsTransform *> transformations() const; + virtual QPointF transformOriginPoint() const; + virtual double zValue() const; + + virtual void setPropertyVariant(const QString &name, const QVariant &value); + virtual void setPropertyBinding(const QString &name, const QString &expression); + virtual QVariant property(const QString &name) const; + virtual void resetProperty(const QString &name); + virtual void refreshProperty(const QString &name); + virtual QString instanceType(const QString &name) const; + QStringList propertyNames() const; + + virtual QList<ServerNodeInstance> childItems() const; + + void createDynamicProperty(const QString &name, const QString &typeName); + void setDeleteHeldInstance(bool deleteInstance); + bool deleteHeldInstance() const; + + virtual void updateAnchors(); + virtual void paintUpdate(); + + virtual void activateState(); + virtual void deactivateState(); + + void populateResetHashes(); + bool hasValidResetBinding(const QString &propertyName) const; + QQmlAbstractBinding *resetBinding(const QString &propertyName) const; + QVariant resetValue(const QString &propertyName) const; + void setResetValue(const QString &propertyName, const QVariant &value); + + QObject *object() const; + + virtual bool hasContent() const; + virtual bool isResizable() const; + virtual bool isMovable() const; + bool isInPositioner() const; + void setInPositioner(bool isInPositioner); + virtual void refreshPositioner(); + + bool hasBindingForProperty(const QString &name, bool *hasChanged = 0) const; + + QQmlContext *context() const; + QQmlEngine *engine() const; + + virtual bool updateStateVariant(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &value); + virtual bool updateStateBinding(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QString &expression); + virtual bool resetStateProperty(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &resetValue); + + + bool isValid() const; + bool isRootNodeInstance() const; + + virtual void doComponentComplete(); + + virtual QList<ServerNodeInstance> stateInstances() const; + + virtual void setNodeSource(const QString &source); + + static QVariant fixResourcePaths(const QVariant &value); + +protected: + void doResetProperty(const QString &propertyName); + void removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty); + void addToNewProperty(QObject *object, QObject *newParent, const QString &newParentProperty); + void deleteObjectsInList(const QQmlProperty &metaProperty); + QVariant convertSpecialCharacter(const QVariant& value) const; + +private: + QHash<QString, QVariant> m_resetValueHash; + QHash<QString, QWeakPointer<QQmlAbstractBinding> > m_resetBindingHash; + QHash<QString, ServerNodeInstance> m_modelAbstractPropertyHash; + mutable QHash<QString, bool> m_hasBindingHash; + qint32 m_instanceId; + QString m_id; + + QWeakPointer<NodeInstanceServer> m_nodeInstanceServer; + QString m_parentProperty; + bool m_deleteHeldInstance; + QWeakPointer<QObject> m_object; + NodeInstanceMetaObject *m_metaObject; + NodeInstanceSignalSpy m_signalSpy; + bool m_isInPositioner; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // ABSTRACTNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.cpp new file mode 100644 index 0000000000..32741c045e --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.cpp @@ -0,0 +1,119 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "qmlpropertychangesnodeinstance.h" +#include "qmlstatenodeinstance.h" +#include <QQmlEngine> +#include <QQmlContext> +#include <QQmlExpression> +#include <private/qqmlbinding_p.h> +#include <QMutableListIterator> + + +#include <private/qquickstate_p_p.h> +#include <private/qquickpropertychanges_p.h> +#include <private/qqmlproperty_p.h> + +namespace QmlDesigner { +namespace Internal { + +QmlPropertyChangesNodeInstance::QmlPropertyChangesNodeInstance(QQuickPropertyChanges *propertyChangesObject) : + ObjectNodeInstance(propertyChangesObject) +{ +} + +QmlPropertyChangesNodeInstance::Pointer QmlPropertyChangesNodeInstance::create(QObject *object) +{ + QQuickPropertyChanges *propertyChange = qobject_cast<QQuickPropertyChanges*>(object); + + Q_ASSERT(propertyChange); + + Pointer instance(new QmlPropertyChangesNodeInstance(propertyChange)); + + instance->populateResetHashes(); + + return instance; +} + +void QmlPropertyChangesNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +{ + QMetaObject metaObject = QQuickPropertyChanges::staticMetaObject; + + if (metaObject.indexOfProperty(name.toLatin1()) > 0) { // 'restoreEntryValues', 'explicit' + ObjectNodeInstance::setPropertyVariant(name, value); + } else { + changesObject()->changeValue(name.toLatin1(), value); + QObject *targetObject = changesObject()->object(); + if (targetObject && nodeInstanceServer()->activeStateInstance().isWrappingThisObject(changesObject()->state())) { + ServerNodeInstance targetInstance = nodeInstanceServer()->instanceForObject(targetObject); + targetInstance.setPropertyVariant(name, value); + } + } +} + +void QmlPropertyChangesNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +{ + QMetaObject metaObject = QQuickPropertyChanges::staticMetaObject; + + if (metaObject.indexOfProperty(name.toLatin1()) > 0) { // 'restoreEntryValues', 'explicit' + ObjectNodeInstance::setPropertyBinding(name, expression); + } else { + changesObject()->changeExpression(name.toLatin1(), expression); + } +} + +QVariant QmlPropertyChangesNodeInstance::property(const QString &name) const +{ + return changesObject()->property(name.toLatin1()); +} + +void QmlPropertyChangesNodeInstance::resetProperty(const QString &name) +{ + changesObject()->removeProperty(name.toLatin1()); +} + + +void QmlPropertyChangesNodeInstance::reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty) +{ + changesObject()->detachFromState(); + + ObjectNodeInstance::reparent(oldParentInstance.internalInstance(), oldParentProperty, newParentInstance.internalInstance(), newParentProperty); + + changesObject()->attachToState(); +} + +QQuickPropertyChanges *QmlPropertyChangesNodeInstance::changesObject() const +{ + Q_ASSERT(qobject_cast<QQuickPropertyChanges*>(object())); + return static_cast<QQuickPropertyChanges*>(object()); +} + +} // namespace Internal +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.h new file mode 100644 index 0000000000..829692c671 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.h @@ -0,0 +1,77 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef QMLPROPERTYCHANGESNODEINSTANCE_H +#define QMLPROPERTYCHANGESNODEINSTANCE_H + +#include "objectnodeinstance.h" +#include <private/qquickstateoperations_p.h> +#include <private/qquickpropertychanges_p.h> + +#include <QPair> +#include <QWeakPointer> + +QT_BEGIN_NAMESPACE +class QQuickProperty; +QT_END_NAMESPACE + +namespace QmlDesigner { + +namespace Internal { + +class QmlPropertyChangesNodeInstance; + +class QmlPropertyChangesNodeInstance : public ObjectNodeInstance +{ +public: + typedef QSharedPointer<QmlPropertyChangesNodeInstance> Pointer; + typedef QWeakPointer<QmlPropertyChangesNodeInstance> WeakPointer; + + static Pointer create(QObject *objectToBeWrapped); + + virtual void setPropertyVariant(const QString &name, const QVariant &value); + virtual void setPropertyBinding(const QString &name, const QString &expression); + virtual QVariant property(const QString &name) const; + virtual void resetProperty(const QString &name); + + using ObjectNodeInstance::reparent; // keep the virtual reparent(...) method around + void reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty); + +protected: + QmlPropertyChangesNodeInstance(QQuickPropertyChanges *object); + QQuickPropertyChanges *changesObject() const; +}; + +} // namespace Internal +} // namespace QmlDesigner + +//QML_DECLARE_TYPE(QmlDesigner::Internal::QmlPropertyChangesObject) + +#endif // QMLPROPERTYCHANGESNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.cpp new file mode 100644 index 0000000000..18f0cfe165 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.cpp @@ -0,0 +1,139 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "qmlstatenodeinstance.h" + +#include <private/qquickstategroup_p.h> + +#include "qmlpropertychangesnodeinstance.h" +#include <private/qquickstateoperations_p.h> + +namespace QmlDesigner { +namespace Internal { + +/** + \class QmlStateNodeInstance + + QmlStateNodeInstance manages a QQuickState object. + */ + +QmlStateNodeInstance::QmlStateNodeInstance(QQuickState *object) : + ObjectNodeInstance(object) +{ +} + +QmlStateNodeInstance::Pointer + QmlStateNodeInstance::create(QObject *object) +{ + QQuickState *stateObject = qobject_cast<QQuickState*>(object); + + Q_ASSERT(stateObject); + + Pointer instance(new QmlStateNodeInstance(stateObject)); + + instance->populateResetHashes(); + + return instance; +} + +void QmlStateNodeInstance::activateState() +{ + if (stateGroup()) { + if (!isStateActive()) { + nodeInstanceServer()->setStateInstance(nodeInstanceServer()->instanceForObject(object())); + stateGroup()->setState(property("name").toString()); + } + } +} + +void QmlStateNodeInstance::deactivateState() +{ + if (stateGroup()) { + if (isStateActive()) { + nodeInstanceServer()->clearStateInstance(); + stateGroup()->setState(QString()); + } + } +} + +QQuickState *QmlStateNodeInstance::stateObject() const +{ + Q_ASSERT(object()); + Q_ASSERT(qobject_cast<QQuickState*>(object())); + return static_cast<QQuickState*>(object()); +} + +QQuickStateGroup *QmlStateNodeInstance::stateGroup() const +{ + return stateObject()->stateGroup(); +} + +bool QmlStateNodeInstance::isStateActive() const +{ + return stateObject() && stateGroup() && stateGroup()->state() == property("name"); +} + +void QmlStateNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +{ + bool hasParent = parent(); + bool isStateOfTheRootModelNode = parentInstance() && parentInstance()->isRootNodeInstance(); + if (name == "when" && (!hasParent || isStateOfTheRootModelNode)) + return; + + ObjectNodeInstance::setPropertyVariant(name, value); +} + +void QmlStateNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +{ + bool hasParent = parent(); + bool isStateOfTheRootModelNode = parentInstance() && parentInstance()->isRootNodeInstance(); + if (name == "when" && (!hasParent || isStateOfTheRootModelNode)) + return; + + ObjectNodeInstance::setPropertyBinding(name, expression); +} + +bool QmlStateNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &value) +{ + return stateObject()->changeValueInRevertList(target->object(), propertyName.toLatin1(), value); +} + +bool QmlStateNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QString &expression) +{ + return stateObject()->changeValueInRevertList(target->object(), propertyName.toLatin1(), expression); +} + +bool QmlStateNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant & /* resetValue */) +{ + return stateObject()->removeEntryFromRevertList(target->object(), propertyName.toLatin1()); +} + +} // namespace Internal +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.h new file mode 100644 index 0000000000..999cc84000 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.h @@ -0,0 +1,77 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef QMLSTATENODEINSTANCE_H +#define QMLSTATENODEINSTANCE_H + +#include "objectnodeinstance.h" + +QT_BEGIN_NAMESPACE +class QQuickState; +class QQuickStateGroup; +QT_END_NAMESPACE + +namespace QmlDesigner { + +namespace Internal { + +class QmlStateNodeInstance : public ObjectNodeInstance +{ +public: + typedef QSharedPointer<QmlStateNodeInstance> Pointer; + typedef QWeakPointer<QmlStateNodeInstance> WeakPointer; + + static Pointer create(QObject *objectToBeWrapped); + + void setPropertyVariant(const QString &name, const QVariant &value); + void setPropertyBinding(const QString &name, const QString &expression); + + void activateState(); + void deactivateState(); + + bool updateStateVariant(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &value); + bool updateStateBinding(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QString &expression); + bool resetStateProperty(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &resetValue); + + +protected: + + QmlStateNodeInstance(QQuickState *object); + + bool isStateActive() const; + + QQuickState *stateObject() const; + QQuickStateGroup *stateGroup() const; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // QMLSTATENODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmltransitionnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmltransitionnodeinstance.cpp new file mode 100644 index 0000000000..3d0c6b40d9 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmltransitionnodeinstance.cpp @@ -0,0 +1,77 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#include "qmltransitionnodeinstance.h" +#include <private/qquicktransition_p.h> + +namespace QmlDesigner { +namespace Internal { + +QmlTransitionNodeInstance::QmlTransitionNodeInstance(QQuickTransition *transition) + : ObjectNodeInstance(transition) +{ +} + +QmlTransitionNodeInstance::Pointer QmlTransitionNodeInstance::create(QObject *object) +{ + QQuickTransition *transition = qobject_cast<QQuickTransition*>(object); + + Q_ASSERT(transition); + + Pointer instance(new QmlTransitionNodeInstance(transition)); + + instance->populateResetHashes(); + + transition->setToState("invalidState"); + transition->setFromState("invalidState"); + + return instance; +} + +bool QmlTransitionNodeInstance::isTransition() const +{ + return true; +} + +void QmlTransitionNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +{ + if (name == "from" || name == "to") + return; + + ObjectNodeInstance::setPropertyVariant(name, value); +} + +QQuickTransition *QmlTransitionNodeInstance::qmlTransition() const +{ + Q_ASSERT(qobject_cast<QQuickTransition*>(object())); + return static_cast<QQuickTransition*>(object()); +} +} +} diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmltransitionnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmltransitionnodeinstance.h new file mode 100644 index 0000000000..b7818effa2 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmltransitionnodeinstance.h @@ -0,0 +1,63 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef QMLTRANSITIONNODEINSTANCE_H +#define QMLTRANSITIONNODEINSTANCE_H + +#include "objectnodeinstance.h" + +QT_BEGIN_NAMESPACE +class QQuickTransition; +QT_END_NAMESPACE + +namespace QmlDesigner { +namespace Internal { + +class QmlTransitionNodeInstance : public ObjectNodeInstance +{ +public: + typedef QSharedPointer<QmlTransitionNodeInstance> Pointer; + typedef QWeakPointer<QmlTransitionNodeInstance> WeakPointer; + + static Pointer create(QObject *objectToBeWrapped); + + void setPropertyVariant(const QString &name, const QVariant &value); + + bool isTransition() const; + +protected: + QQuickTransition *qmlTransition() const; + +private: + QmlTransitionNodeInstance(QQuickTransition *transition); +}; +} +} +#endif // QMLTRANSITIONNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index d19dbe1e24..edbace9bda 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -30,7 +30,7 @@ #include "qt5informationnodeinstanceserver.h" -#include <QSGItem> +#include <QQuickItem> #include "servernodeinstance.h" #include "childrenchangeeventfilter.h" @@ -59,6 +59,7 @@ #include "componentcompletedcommand.h" #include "createscenecommand.h" #include "tokencommand.h" +#include "removesharedmemorycommand.h" #include "dummycontextobject.h" @@ -95,8 +96,8 @@ void Qt5InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands() QVector<InstancePropertyPair> propertyChangedList; bool adjustSceneRect = false; - if (sgView()) { - foreach (QSGItem *item, allItems()) { + if (quickView()) { + foreach (QQuickItem *item, allItems()) { if (item && hasInstanceForObject(item)) { ServerNodeInstance instance = instanceForObject(item); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.cpp index df8f48e9f0..96db7f5b57 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.cpp @@ -31,8 +31,8 @@ #include "qt5nodeinstanceserver.h" -#include <QSGItem> -#include <QSGView> +#include <QQuickItem> +#include <QQuickView> #include <designersupport.h> #include <addimportcontainer.h> @@ -49,40 +49,32 @@ Qt5NodeInstanceServer::Qt5NodeInstanceServer(NodeInstanceClientInterface *nodeIn Qt5NodeInstanceServer::~Qt5NodeInstanceServer() { - delete sgView(); + delete quickView(); delete m_designerSupport; m_designerSupport = 0; } -QSGView *Qt5NodeInstanceServer::sgView() const +QQuickView *Qt5NodeInstanceServer::quickView() const { - return m_sgView.data(); + return m_quickView.data(); } void Qt5NodeInstanceServer::initializeView(const QVector<AddImportContainer> &/*importVector*/) { - Q_ASSERT(!sgView()); - - m_sgView = new QSGView; -#ifndef Q_OS_MAC - sgView()->setAttribute(Qt::WA_DontShowOnScreen, true); -#endif - sgView()->show(); -#ifdef Q_OS_MAC - sgView()->setAttribute(Qt::WA_DontShowOnScreen, true); -#endif - sgView()->setUpdatesEnabled(false); + Q_ASSERT(!quickView()); + + m_quickView = new QQuickView; } -QDeclarativeView *Qt5NodeInstanceServer::declarativeView() const +QQmlView *Qt5NodeInstanceServer::declarativeView() const { return 0; } -QDeclarativeEngine *Qt5NodeInstanceServer::engine() const +QQmlEngine *Qt5NodeInstanceServer::engine() const { - if (sgView()) - return sgView()->engine(); + if (quickView()) + return quickView()->engine(); return 0; } @@ -93,7 +85,7 @@ void Qt5NodeInstanceServer::resizeCanvasSizeToRootItemSize() void Qt5NodeInstanceServer::resetAllItems() { - foreach (QSGItem *item, allItems()) + foreach (QQuickItem *item, allItems()) DesignerSupport::resetDirty(item); } @@ -105,29 +97,29 @@ QList<ServerNodeInstance> Qt5NodeInstanceServer::setupScene(const CreateSceneCom QList<ServerNodeInstance> instanceList = setupInstances(command); - sgView()->resize(rootNodeInstance().boundingRect().size().toSize()); + quickView()->resize(rootNodeInstance().boundingRect().size().toSize()); return instanceList; } -QList<QSGItem*> subItems(QSGItem *parentItem) +QList<QQuickItem*> subItems(QQuickItem *parentItem) { - QList<QSGItem*> itemList; + QList<QQuickItem*> itemList; itemList.append(parentItem->childItems()); - foreach (QSGItem *childItem, parentItem->childItems()) + foreach (QQuickItem *childItem, parentItem->childItems()) itemList.append(subItems(childItem)); return itemList; } -QList<QSGItem*> Qt5NodeInstanceServer::allItems() const +QList<QQuickItem*> Qt5NodeInstanceServer::allItems() const { - QList<QSGItem*> itemList; + QList<QQuickItem*> itemList; - if (sgView()) { - itemList.append(sgView()->rootItem()); - itemList.append(subItems(sgView()->rootItem())); + if (quickView()) { + itemList.append(quickView()->rootItem()); + itemList.append(subItems(quickView()->rootItem())); } return itemList; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.h index 3f011c74b4..ef70824226 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceserver.h @@ -36,7 +36,7 @@ #include "nodeinstanceserver.h" QT_BEGIN_NAMESPACE -class QSGItem; +class QQuickItem; class DesignerSupport; QT_END_NAMESPACE @@ -49,9 +49,9 @@ public: Qt5NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient); ~Qt5NodeInstanceServer(); - QSGView *sgView() const; - QDeclarativeView *declarativeView() const; - QDeclarativeEngine *engine() const; + QQuickView *quickView() const; + QQmlView *declarativeView() const; + QQmlEngine *engine() const; void refreshBindings(); DesignerSupport *designerSupport() const; @@ -64,10 +64,10 @@ protected: void resizeCanvasSizeToRootItemSize(); void resetAllItems(); QList<ServerNodeInstance> setupScene(const CreateSceneCommand &command); - QList<QSGItem*> allItems() const; + QList<QQuickItem*> allItems() const; private: - QWeakPointer<QSGView> m_sgView; + QWeakPointer<QQuickView> m_quickView; DesignerSupport *m_designerSupport; }; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp index 5209505a93..fe4d95a1b2 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp @@ -33,8 +33,9 @@ #include "nodeinstanceclientinterface.h" #include "statepreviewimagechangedcommand.h" #include "createscenecommand.h" +#include "removesharedmemorycommand.h" -#include <QSGItem> +#include <QQuickItem> #include <designersupport.h> namespace QmlDesigner { @@ -68,11 +69,11 @@ void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands() if (!inFunction && nodeInstanceClient()->bytesToWrite() < 10000) { inFunction = true; QVector<ImageContainer> imageContainerVector; - imageContainerVector.append(ImageContainer(0, renderPreviewImage())); + imageContainerVector.append(ImageContainer(0, renderPreviewImage(), -1)); foreach (ServerNodeInstance instance, rootNodeInstance().stateInstances()) { instance.activateState(); - imageContainerVector.append(ImageContainer(instance.instanceId(), renderPreviewImage())); + imageContainerVector.append(ImageContainer(instance.instanceId(), renderPreviewImage(), instance.instanceId())); instance.deactivateState(); } @@ -88,9 +89,9 @@ void Qt5PreviewNodeInstanceServer::changeState(const ChangeStateCommand &/*comma } -static void updateDirtyNodeRecursive(QSGItem *parentItem) +static void updateDirtyNodeRecursive(QQuickItem *parentItem) { - foreach (QSGItem *childItem, parentItem->childItems()) + foreach (QQuickItem *childItem, parentItem->childItems()) updateDirtyNodeRecursive(childItem); DesignerSupport::updateDirtyNode(parentItem); @@ -118,7 +119,7 @@ QImage Qt5PreviewNodeInstanceServer::renderPreviewImage() void QmlDesigner::Qt5PreviewNodeInstanceServer::removeSharedMemory(const QmlDesigner::RemoveSharedMemoryCommand &command) { if (command.typeName() == "Image") - ImageContainer::removeSharedMemory(command.keyNumber()); + ImageContainer::removeSharedMemorys(command.keyNumbers()); } } // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp index 027c4e3718..88c31b9bfd 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5rendernodeinstanceserver.cpp @@ -30,7 +30,7 @@ #include "qt5rendernodeinstanceserver.h" -#include <QSGItem> +#include <QQuickItem> #include "servernodeinstance.h" #include "childrenchangeeventfilter.h" @@ -59,7 +59,7 @@ #include "componentcompletedcommand.h" #include "createscenecommand.h" #include "sgitemnodeinstance.h" - +#include "removesharedmemorycommand.h" #include "dummycontextobject.h" @@ -70,7 +70,7 @@ namespace QmlDesigner { Qt5RenderNodeInstanceServer::Qt5RenderNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) : Qt5NodeInstanceServer(nodeInstanceClient) { - Internal::SGItemNodeInstance::createEffectItem(true); + Internal::QuickItemNodeInstance::createEffectItem(true); } void Qt5RenderNodeInstanceServer::collectItemChangesAndSendChangeCommands() @@ -79,8 +79,8 @@ void Qt5RenderNodeInstanceServer::collectItemChangesAndSendChangeCommands() if (!inFunction) { inFunction = true; - if (sgView() && nodeInstanceClient()->bytesToWrite() < 10000) { - foreach (QSGItem *item, allItems()) { + if (quickView() && nodeInstanceClient()->bytesToWrite() < 10000) { + foreach (QQuickItem *item, allItems()) { if (item && hasInstanceForObject(item)) { ServerNodeInstance instance = instanceForObject(item); if (DesignerSupport::isDirty(item, DesignerSupport::ContentUpdateMask)) @@ -148,7 +148,7 @@ void Qt5RenderNodeInstanceServer::completeComponent(const CompleteComponentComma void QmlDesigner::Qt5RenderNodeInstanceServer::removeSharedMemory(const QmlDesigner::RemoveSharedMemoryCommand &command) { if (command.typeName() == "Image") - ImageContainer::removeSharedMemory(command.keyNumber()); + ImageContainer::removeSharedMemorys(command.keyNumbers()); } } // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/servernodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/servernodeinstance.cpp new file mode 100644 index 0000000000..68abd113b6 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/servernodeinstance.cpp @@ -0,0 +1,637 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ +#include "servernodeinstance.h" + +#include "objectnodeinstance.h" +#include "dummynodeinstance.h" +#include "componentnodeinstance.h" +#include "qmltransitionnodeinstance.h" +#include "qmlpropertychangesnodeinstance.h" +#include "behaviornodeinstance.h" +#include "qmlstatenodeinstance.h" +#include "anchorchangesnodeinstance.h" + +#if QT_VERSION >= 0x050000 +#include "sgitemnodeinstance.h" +#else +#include "qmlgraphicsitemnodeinstance.h" +#include "positionernodeinstance.h" +#endif + +#include "nodeinstanceserver.h" +#include "instancecontainer.h" + +#include <QHash> +#include <QSet> +#include <QDebug> + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) +#include <QQuickItem> +#endif + +#include <QQmlEngine> + +/*! + \class QmlDesigner::NodeInstance + \ingroup CoreInstance + \brief NodeInstance is a common handle for the actual object representation of a ModelNode. + + NodeInstance abstracts away the differences e.g. in terms of position and size + for QWidget, QGraphicsView, QLayout etc objects. Multiple NodeInstance objects can share + the pointer to the same instance object. The actual instance will be deleted when + the last NodeInstance object referencing to it is deleted. This can be disabled by + setDeleteHeldInstance(). + + \see QmlDesigner::NodeInstanceView +*/ + +namespace QmlDesigner { + +/*! +\brief Constructor - creates a invalid NodeInstance + + +\see NodeInstanceView +*/ +ServerNodeInstance::ServerNodeInstance() +{ +} + +/*! +\brief Destructor + +*/ +ServerNodeInstance::~ServerNodeInstance() +{ +} + +/*! +\brief Constructor - creates a valid NodeInstance + +*/ +ServerNodeInstance::ServerNodeInstance(const Internal::ObjectNodeInstance::Pointer &abstractInstance) + : m_nodeInstance(abstractInstance) +{ + +} + + +ServerNodeInstance::ServerNodeInstance(const ServerNodeInstance &other) + : m_nodeInstance(other.m_nodeInstance) +{ +} + +ServerNodeInstance &ServerNodeInstance::operator=(const ServerNodeInstance &other) +{ + m_nodeInstance = other.m_nodeInstance; + return *this; +} + +/*! +\brief Paints the NodeInstance with this painter. +\param painter used QPainter +*/ +void ServerNodeInstance::paint(QPainter *painter) +{ + m_nodeInstance->paint(painter); +} + +QImage ServerNodeInstance::renderImage() const +{ + return m_nodeInstance->renderImage(); +} + +bool ServerNodeInstance::isRootNodeInstance() const +{ + return isValid() && m_nodeInstance->isRootNodeInstance(); +} + +bool ServerNodeInstance::isSubclassOf(QObject *object, const QByteArray &superTypeName) +{ + if (object == 0) + return false; + + const QMetaObject *metaObject = object->metaObject(); + + while (metaObject) { + QQmlType *qmlType = QQmlMetaType::qmlType(metaObject); + if (qmlType && qmlType->qmlTypeName() == superTypeName) // ignore version numbers + return true; + + if (metaObject->className() == superTypeName) + return true; + + metaObject = metaObject->superClass(); + } + + return false; +} + +void ServerNodeInstance::setNodeSource(const QString &source) +{ + m_nodeInstance->setNodeSource(source); +} + +bool ServerNodeInstance::isSubclassOf(const QString &superTypeName) const +{ + return isSubclassOf(internalObject(), superTypeName.toUtf8()); +} + +/*! +\brief Creates a new NodeInstace for this NodeMetaInfo + +\param metaInfo MetaInfo for which a Instance should be created +\param context QQmlContext which should be used +\returns Internal Pointer of a NodeInstance +\see NodeMetaInfo +*/ +Internal::ObjectNodeInstance::Pointer ServerNodeInstance::createInstance(QObject *objectToBeWrapped) +{ + Internal::ObjectNodeInstance::Pointer instance; + + if (objectToBeWrapped == 0) + instance = Internal::DummyNodeInstance::create(); +#if QT_VERSION >= 0x050000 + else if (isSubclassOf(objectToBeWrapped, "QQuickItem")) + instance = Internal::QuickItemNodeInstance::create(objectToBeWrapped); +#else + else if (isSubclassOf(objectToBeWrapped, "QQmlBasePositioner")) + instance = Internal::PositionerNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "QQmlItem")) + instance = Internal::QmlGraphicsItemNodeInstance::create(objectToBeWrapped); +#endif + else if (isSubclassOf(objectToBeWrapped, "QQmlComponent")) + instance = Internal::ComponentNodeInstance::create(objectToBeWrapped); + else if (objectToBeWrapped->inherits("QQmlAnchorChanges")) + instance = Internal::AnchorChangesNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "QQuickPropertyChanges")) + instance = Internal::QmlPropertyChangesNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "QQuickState")) + instance = Internal::QmlStateNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "QQuickTransition")) + instance = Internal::QmlTransitionNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "QQuickBehavior")) + instance = Internal::BehaviorNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "QObject")) + instance = Internal::ObjectNodeInstance::create(objectToBeWrapped); + else + instance = Internal::DummyNodeInstance::create(); + + + return instance; +} + +ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceServer, const InstanceContainer &instanceContainer, ComponentWrap componentWrap) +{ + Q_ASSERT(instanceContainer.instanceId() != -1); + Q_ASSERT(nodeInstanceServer); + + QObject *object = 0; + if (componentWrap == WrapAsComponent) { + object = Internal::ObjectNodeInstance::createComponentWrap(instanceContainer.nodeSource(), nodeInstanceServer->imports(), nodeInstanceServer->context()); + } else if (!instanceContainer.nodeSource().isEmpty()) { + object = Internal::ObjectNodeInstance::createCustomParserObject(instanceContainer.nodeSource(), nodeInstanceServer->imports(), nodeInstanceServer->context()); + } else if (!instanceContainer.componentPath().isEmpty()) { + object = Internal::ObjectNodeInstance::createComponent(instanceContainer.componentPath(), nodeInstanceServer->context()); + } else { + object = Internal::ObjectNodeInstance::createPrimitive(instanceContainer.type(), instanceContainer.majorNumber(), instanceContainer.minorNumber(), nodeInstanceServer->context()); + } + + if ((object == 0) && (instanceContainer.metaType() == InstanceContainer::ItemMetaType)) //If we cannot instanciate the object but we know it has to be an Ttem, we create an Item instead. +#if QT_VERSION >= 0x050000 + object = Internal::ObjectNodeInstance::createPrimitive("QQuickItem", 2, 0, nodeInstanceServer->context()); +#else + object = Internal::ObjectNodeInstance::createPrimitive("QtQuick/Item", 1, 0, nodeInstanceServer->context()); +#endif + + ServerNodeInstance instance(createInstance(object)); + + instance.internalInstance()->setNodeInstanceServer(nodeInstanceServer); + + instance.internalInstance()->setInstanceId(instanceContainer.instanceId()); + + instance.internalInstance()->initialize(instance.m_nodeInstance); + + //QObject::connect(instance.internalObject(), SIGNAL(destroyed(QObject*)), nodeInstanceView, SLOT(removeIdFromContext(QObject*))); + + return instance; +} + +void ServerNodeInstance::reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty) +{ + m_nodeInstance->reparent(oldParentInstance.m_nodeInstance, oldParentProperty, newParentInstance.m_nodeInstance, newParentProperty); +} + +/*! +\brief Returns the parent NodeInstance of this NodeInstance. + + If there is not parent than the parent is invalid. + +\returns Parent NodeInstance. +*/ +ServerNodeInstance ServerNodeInstance::parent() const +{ + return m_nodeInstance->parentInstance(); +} + +bool ServerNodeInstance::hasParent() const +{ + return m_nodeInstance->parent(); +} + +bool ServerNodeInstance::isValid() const +{ + return m_nodeInstance && m_nodeInstance->isValid(); +} + + +/*! +\brief Returns if the NodeInstance is a QGraphicsItem. +\returns true if this NodeInstance is a QGraphicsItem +*/ +bool ServerNodeInstance::equalGraphicsItem(QGraphicsItem *item) const +{ + return m_nodeInstance->equalGraphicsItem(item); +} + +/*! +\brief Returns the bounding rect of the NodeInstance. +\returns QRectF of the NodeInstance +*/ +QRectF ServerNodeInstance::boundingRect() const +{ + QRectF boundingRect(m_nodeInstance->boundingRect()); + +// +// if (modelNode().isValid()) { // TODO implement recursiv stuff +// if (qFuzzyIsNull(boundingRect.width())) +// boundingRect.setWidth(nodeState().property("width").value().toDouble()); +// +// if (qFuzzyIsNull(boundingRect.height())) +// boundingRect.setHeight(nodeState().property("height").value().toDouble()); +// } + + return boundingRect; +} + +void ServerNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +{ + m_nodeInstance->setPropertyVariant(name, value); + +} + +void ServerNodeInstance::setPropertyDynamicVariant(const QString &name, const QString &typeName, const QVariant &value) +{ + m_nodeInstance->createDynamicProperty(name, typeName); + m_nodeInstance->setPropertyVariant(name, value); +} + +void ServerNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +{ + m_nodeInstance->setPropertyBinding(name, expression); +} + +void ServerNodeInstance::setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression) +{ + m_nodeInstance->createDynamicProperty(name, typeName); + m_nodeInstance->setPropertyBinding(name, expression); +} + +void ServerNodeInstance::resetProperty(const QString &name) +{ + m_nodeInstance->resetProperty(name); +} + +void ServerNodeInstance::refreshProperty(const QString &name) +{ + m_nodeInstance->refreshProperty(name); +} + +void ServerNodeInstance::setId(const QString &id) +{ + m_nodeInstance->setId(id); +} + +/*! +\brief Returns the property value of the property of this NodeInstance. +\returns QVariant value +*/ +QVariant ServerNodeInstance::property(const QString &name) const +{ + return m_nodeInstance->property(name); +} + +QStringList ServerNodeInstance::propertyNames() const +{ + return m_nodeInstance->propertyNames(); +} + +bool ServerNodeInstance::hasBindingForProperty(const QString &name, bool *hasChanged) const +{ + return m_nodeInstance->hasBindingForProperty(name, hasChanged); +} + +/*! +\brief Returns the property default value of the property of this NodeInstance. +\returns QVariant default value which is the reset value to +*/ +QVariant ServerNodeInstance::defaultValue(const QString &name) const +{ + return m_nodeInstance->resetValue(name); +} + +/*! +\brief Returns the type of the property of this NodeInstance. +*/ +QString ServerNodeInstance::instanceType(const QString &name) const +{ + return m_nodeInstance->instanceType(name); +} + +void ServerNodeInstance::makeInvalid() +{ + if (m_nodeInstance) + m_nodeInstance->destroy(); + m_nodeInstance.clear(); +} + +bool ServerNodeInstance::hasContent() const +{ + return m_nodeInstance->hasContent(); +} + +bool ServerNodeInstance::isResizable() const +{ + return m_nodeInstance->isResizable(); +} + +bool ServerNodeInstance::isMovable() const +{ + return m_nodeInstance->isMovable(); +} + +bool ServerNodeInstance::isInPositioner() const +{ + return m_nodeInstance->isInPositioner(); +} + +bool ServerNodeInstance::hasAnchor(const QString &name) const +{ + return m_nodeInstance->hasAnchor(name); +} + +int ServerNodeInstance::penWidth() const +{ + return m_nodeInstance->penWidth(); +} + +bool ServerNodeInstance::isAnchoredBySibling() const +{ + return m_nodeInstance->isAnchoredBySibling(); +} + +bool ServerNodeInstance::isAnchoredByChildren() const +{ + return m_nodeInstance->isAnchoredByChildren(); +} + +QPair<QString, ServerNodeInstance> ServerNodeInstance::anchor(const QString &name) const +{ + return m_nodeInstance->anchor(name); +} + +QDebug operator<<(QDebug debug, const ServerNodeInstance &instance) +{ + if (instance.isValid()) { + debug.nospace() << "ServerNodeInstance(" + << instance.instanceId() << ", " + << instance.internalObject() << ", " + << instance.id() << ", " + << instance.parent() << ')'; + } else { + debug.nospace() << "ServerNodeInstance(invalid)"; + } + + return debug.space(); +} + +uint qHash(const ServerNodeInstance &instance) +{ + return ::qHash(instance.instanceId()); +} + +bool operator==(const ServerNodeInstance &first, const ServerNodeInstance &second) +{ + return first.instanceId() == second.instanceId(); +} + +bool ServerNodeInstance::isWrappingThisObject(QObject *object) const +{ + return internalObject() && internalObject() == object; +} + +/*! +\brief Returns the position in parent coordiantes. +\returns QPointF of the position of the instance. +*/ +QPointF ServerNodeInstance::position() const +{ + return m_nodeInstance->position(); +} + +/*! +\brief Returns the size in local coordiantes. +\returns QSizeF of the size of the instance. +*/ +QSizeF ServerNodeInstance::size() const +{ + QSizeF instanceSize = m_nodeInstance->size(); + + return instanceSize; +} + +QTransform ServerNodeInstance::transform() const +{ + return m_nodeInstance->transform(); +} + +/*! +\brief Returns the transform matrix of the instance. +\returns QTransform of the instance. +*/ +QTransform ServerNodeInstance::customTransform() const +{ + return m_nodeInstance->customTransform(); +} + +QTransform ServerNodeInstance::sceneTransform() const +{ + return m_nodeInstance->sceneTransform(); +} + +double ServerNodeInstance::rotation() const +{ + return m_nodeInstance->rotation(); +} + +double ServerNodeInstance::scale() const +{ + return m_nodeInstance->scale(); +} + +QList<QGraphicsTransform *> ServerNodeInstance::transformations() const +{ + return m_nodeInstance->transformations(); +} + +QPointF ServerNodeInstance::transformOriginPoint() const +{ + return m_nodeInstance->transformOriginPoint(); +} + +double ServerNodeInstance::zValue() const +{ + return m_nodeInstance->zValue(); +} + +/*! +\brief Returns the opacity of the instance. +\returns 0.0 mean transparent and 1.0 opaque. +*/ +double ServerNodeInstance::opacity() const +{ + return m_nodeInstance->opacity(); +} + + +void ServerNodeInstance::setDeleteHeldInstance(bool deleteInstance) +{ + m_nodeInstance->setDeleteHeldInstance(deleteInstance); +} + + +void ServerNodeInstance::paintUpdate() +{ + m_nodeInstance->paintUpdate(); +} + +QObject *ServerNodeInstance::internalObject() const +{ + if (m_nodeInstance.isNull()) + return 0; + + return m_nodeInstance->object(); +} + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) +QQuickItem *ServerNodeInstance::internalSGItem() const +{ + return qobject_cast<QQuickItem*>(internalObject()); +} +#endif + +void ServerNodeInstance::activateState() +{ + m_nodeInstance->activateState(); +} + +void ServerNodeInstance::deactivateState() +{ + m_nodeInstance->deactivateState(); +} + +bool ServerNodeInstance::updateStateVariant(const ServerNodeInstance &target, const QString &propertyName, const QVariant &value) +{ + return m_nodeInstance->updateStateVariant(target.internalInstance(), propertyName, value); +} + +bool ServerNodeInstance::updateStateBinding(const ServerNodeInstance &target, const QString &propertyName, const QString &expression) +{ + return m_nodeInstance->updateStateBinding(target.internalInstance(), propertyName, expression); +} + +QVariant ServerNodeInstance::resetVariant(const QString &propertyName) const +{ + return m_nodeInstance->resetValue(propertyName); +} + +bool ServerNodeInstance::resetStateProperty(const ServerNodeInstance &target, const QString &propertyName, const QVariant &resetValue) +{ + return m_nodeInstance->resetStateProperty(target.internalInstance(), propertyName, resetValue); +} + +/*! + Makes types used in node instances known to the Qml engine. To be called once at initialization time. +*/ +void ServerNodeInstance::registerQmlTypes() +{ +// qmlRegisterType<QmlDesigner::Internal::QmlPropertyChangesObject>(); +} + +void ServerNodeInstance::doComponentComplete() +{ + m_nodeInstance->doComponentComplete(); +} + +QList<ServerNodeInstance> ServerNodeInstance::childItems() const +{ + return m_nodeInstance->childItems(); +} + +QString ServerNodeInstance::id() const +{ + return m_nodeInstance->id(); +} + +qint32 ServerNodeInstance::instanceId() const +{ + if (isValid()) { + return m_nodeInstance->instanceId(); + } else { + return -1; + } +} + +QObject* ServerNodeInstance::testHandle() const +{ + return internalObject(); +} + +QList<ServerNodeInstance> ServerNodeInstance::stateInstances() const +{ + return m_nodeInstance->stateInstances(); +} + +Internal::ObjectNodeInstance::Pointer ServerNodeInstance::internalInstance() const +{ + return m_nodeInstance; +} + +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/servernodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/servernodeinstance.h new file mode 100644 index 0000000000..9050aee8e8 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/servernodeinstance.h @@ -0,0 +1,217 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/ +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +**************************************************************************/ + +#ifndef SERVERNODEINSTANCE_H +#define SERVERNODEINSTANCE_H + +#include <QSharedPointer> +#include <QHash> +#include <QRectF> + +#include <nodeinstanceserverinterface.h> +#include <propertyvaluecontainer.h> + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +class QQmlContext; +class QGraphicsItem; +class QGraphicsTransform; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) +class QQuickItem; +#endif +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceServer; +class Qt4NodeInstanceServer; +class Qt4PreviewNodeInstanceServer; +class Qt5NodeInstanceServer; +class Qt5PreviewNodeInstanceServer; +class InstanceContainer; + +namespace Internal { + class ObjectNodeInstance; + class QmlGraphicsItemNodeInstance; + class QmlPropertyChangesNodeInstance; + class GraphicsObjectNodeInstance; + class QmlStateNodeInstance; + class QuickItemNodeInstance; +} + +class ServerNodeInstance +{ + friend class NodeInstanceServer; + friend class Qt4NodeInstanceServer; + friend class Qt4PreviewNodeInstanceServer; + friend class Qt5NodeInstanceServer; + friend class Qt5PreviewNodeInstanceServer; + friend class QHash<qint32, ServerNodeInstance>; + friend uint qHash(const ServerNodeInstance &instance); + friend bool operator==(const ServerNodeInstance &first, const ServerNodeInstance &second); + friend QDebug operator<<(QDebug debug, const ServerNodeInstance &instance); + friend class NodeMetaInfo; + friend class QmlDesigner::Internal::QmlGraphicsItemNodeInstance; + friend class QmlDesigner::Internal::QuickItemNodeInstance; + friend class QmlDesigner::Internal::GraphicsObjectNodeInstance; + friend class QmlDesigner::Internal::ObjectNodeInstance; + friend class QmlDesigner::Internal::QmlPropertyChangesNodeInstance; + friend class QmlDesigner::Internal::QmlStateNodeInstance; + +public: + enum ComponentWrap { + WrapAsComponent, + DoNotWrapAsComponent + }; + + ServerNodeInstance(); + ~ServerNodeInstance(); + ServerNodeInstance(const ServerNodeInstance &other); + ServerNodeInstance& operator=(const ServerNodeInstance &other); + + void paint(QPainter *painter); + QImage renderImage() const; + + ServerNodeInstance parent() const; + bool hasParent() const; + + bool equalGraphicsItem(QGraphicsItem *item) const; + + QRectF boundingRect() const; + QPointF position() const; + QSizeF size() const; + QTransform transform() const; + QTransform customTransform() const; + QTransform sceneTransform() const; + double rotation() const; + double scale() const; + QList<QGraphicsTransform *> transformations() const; + QPointF transformOriginPoint() const; + double zValue() const; + + double opacity() const; + QVariant property(const QString &name) const; + QVariant defaultValue(const QString &name) const; + QString instanceType(const QString &name) const; + QStringList propertyNames() const; + + + bool hasBindingForProperty(const QString &name, bool *hasChanged = 0) const; + + bool isValid() const; + void makeInvalid(); + bool hasContent() const; + bool isResizable() const; + bool isMovable() const; + bool isInPositioner() const; + + bool isSubclassOf(const QString &superTypeName) const; + bool isRootNodeInstance() const; + + bool isWrappingThisObject(QObject *object) const; + + QVariant resetVariant(const QString &name) const; + + bool hasAnchor(const QString &name) const; + bool isAnchoredBySibling() const; + bool isAnchoredByChildren() const; + QPair<QString, ServerNodeInstance> anchor(const QString &name) const; + + int penWidth() const; + + static void registerQmlTypes(); + + void doComponentComplete(); + + QList<ServerNodeInstance> childItems() const; + + QString id() const; + qint32 instanceId() const; + + QObject* testHandle() const; + QSharedPointer<Internal::ObjectNodeInstance> internalInstance() const; + + QList<ServerNodeInstance> stateInstances() const; + +private: // functions + ServerNodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance); + + void setPropertyVariant(const QString &name, const QVariant &value); + void setPropertyDynamicVariant(const QString &name, const QString &typeName, const QVariant &value); + + void setPropertyBinding(const QString &name, const QString &expression); + void setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression); + + void resetProperty(const QString &name); + void refreshProperty(const QString &name); + + void activateState(); + void deactivateState(); + void refreshState(); + + bool updateStateVariant(const ServerNodeInstance &target, const QString &propertyName, const QVariant &value); + bool updateStateBinding(const ServerNodeInstance &target, const QString &propertyName, const QString &expression); + bool resetStateProperty(const ServerNodeInstance &target, const QString &propertyName, const QVariant &resetValue); + + static ServerNodeInstance create(NodeInstanceServer *nodeInstanceServer, const InstanceContainer &instanceContainer, ComponentWrap componentWrap); + + void setDeleteHeldInstance(bool deleteInstance); + void reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty); + + + void setId(const QString &id); + + static QSharedPointer<Internal::ObjectNodeInstance> createInstance(QObject *objectToBeWrapped); + + void paintUpdate(); + + static bool isSubclassOf(QObject *object, const QByteArray &superTypeName); + + void setNodeSource(const QString &source); + + + QObject *internalObject() const; // should be not used outside of the nodeinstances!!!! +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) + QQuickItem *internalSGItem() const; +#endif + +private: // variables + QSharedPointer<Internal::ObjectNodeInstance> m_nodeInstance; +}; + +uint qHash(const ServerNodeInstance &instance); +bool operator==(const ServerNodeInstance &first, const ServerNodeInstance &second); +QDebug operator<<(QDebug debug, const ServerNodeInstance &instance); +} + +Q_DECLARE_METATYPE(QmlDesigner::ServerNodeInstance) + +#endif // SERVERNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.cpp index 05ab200234..7e788f7bfb 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.cpp @@ -32,8 +32,8 @@ #include "qt5nodeinstanceserver.h" -#include <QDeclarativeExpression> -#include <QSGView> +#include <QQmlExpression> +#include <QQuickView> #include <cmath> #include <QHash> @@ -43,9 +43,9 @@ namespace QmlDesigner { namespace Internal { -bool SGItemNodeInstance::s_createEffectItem = false; +bool QuickItemNodeInstance::s_createEffectItem = false; -SGItemNodeInstance::SGItemNodeInstance(QSGItem *item) +QuickItemNodeInstance::QuickItemNodeInstance(QQuickItem *item) : ObjectNodeInstance(item), m_hasHeight(false), m_hasWidth(false), @@ -59,22 +59,22 @@ SGItemNodeInstance::SGItemNodeInstance(QSGItem *item) { } -SGItemNodeInstance::~SGItemNodeInstance() +QuickItemNodeInstance::~QuickItemNodeInstance() { - if (sgItem()) - designerSupport()->derefFromEffectItem(sgItem()); + if (quickItem()) + designerSupport()->derefFromEffectItem(quickItem()); } -bool SGItemNodeInstance::hasContent() const +bool QuickItemNodeInstance::hasContent() const { return m_hasContent; } -QList<ServerNodeInstance> SGItemNodeInstance::childItems() const +QList<ServerNodeInstance> QuickItemNodeInstance::childItems() const { QList<ServerNodeInstance> instanceList; - foreach (QSGItem *childItem, sgItem()->childItems()) + foreach (QQuickItem *childItem, quickItem()->childItems()) { if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) { instanceList.append(nodeInstanceServer()->instanceForObject(childItem)); @@ -90,12 +90,12 @@ QList<ServerNodeInstance> SGItemNodeInstance::childItems() const return instanceList; } -QList<ServerNodeInstance> SGItemNodeInstance::childItemsForChild(QSGItem *childItem) const +QList<ServerNodeInstance> QuickItemNodeInstance::childItemsForChild(QQuickItem *childItem) const { QList<ServerNodeInstance> instanceList; if (childItem) { - foreach (QSGItem *childItem, childItem->childItems()) + foreach (QQuickItem *childItem, childItem->childItems()) { if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) { instanceList.append(nodeInstanceServer()->instanceForObject(childItem)); @@ -107,18 +107,18 @@ QList<ServerNodeInstance> SGItemNodeInstance::childItemsForChild(QSGItem *childI return instanceList; } -void SGItemNodeInstance::setHasContent(bool hasContent) +void QuickItemNodeInstance::setHasContent(bool hasContent) { m_hasContent = hasContent; } -bool anyItemHasContent(QSGItem *graphicsItem) +bool anyItemHasContent(QQuickItem *graphicsItem) { - if (graphicsItem->flags().testFlag(QSGItem::ItemHasContents)) + if (graphicsItem->flags().testFlag(QQuickItem::ItemHasContents)) return true; - foreach (QSGItem *childItem, graphicsItem->childItems()) { + foreach (QQuickItem *childItem, graphicsItem->childItems()) { if (anyItemHasContent(childItem)) return true; } @@ -126,67 +126,68 @@ bool anyItemHasContent(QSGItem *graphicsItem) return false; } -QPointF SGItemNodeInstance::position() const +QPointF QuickItemNodeInstance::position() const { - return sgItem()->pos(); + return quickItem()->pos(); } -QTransform SGItemNodeInstance::transform() const +QTransform QuickItemNodeInstance::transform() const { - return DesignerSupport::parentTransform(sgItem()); + return DesignerSupport::parentTransform(quickItem()); } -QTransform SGItemNodeInstance::customTransform() const +QTransform QuickItemNodeInstance::customTransform() const { return QTransform(); } -QTransform SGItemNodeInstance::sceneTransform() const +QTransform QuickItemNodeInstance::sceneTransform() const { - return DesignerSupport::canvasTransform(sgItem()); + return QTransform(); +// return DesignerSupport::canvasTransform(quickItem()); } -double SGItemNodeInstance::rotation() const +double QuickItemNodeInstance::rotation() const { - return sgItem()->rotation(); + return quickItem()->rotation(); } -double SGItemNodeInstance::scale() const +double QuickItemNodeInstance::scale() const { - return sgItem()->scale(); + return quickItem()->scale(); } -QPointF SGItemNodeInstance::transformOriginPoint() const +QPointF QuickItemNodeInstance::transformOriginPoint() const { - return sgItem()->transformOriginPoint(); + return quickItem()->transformOriginPoint(); } -double SGItemNodeInstance::zValue() const +double QuickItemNodeInstance::zValue() const { - return sgItem()->z(); + return quickItem()->z(); } -double SGItemNodeInstance::opacity() const +double QuickItemNodeInstance::opacity() const { - return sgItem()->opacity(); + return quickItem()->opacity(); } -QObject *SGItemNodeInstance::parent() const +QObject *QuickItemNodeInstance::parent() const { - if (!sgItem() || !sgItem()->parentItem()) + if (!quickItem() || !quickItem()->parentItem()) return 0; - return sgItem()->parentItem(); + return quickItem()->parentItem(); } -bool SGItemNodeInstance::equalSGItem(QSGItem *item) const +bool QuickItemNodeInstance::equalQuickItem(QQuickItem *item) const { - return item == sgItem(); + return item == quickItem(); } -void SGItemNodeInstance::updateDirtyNodeRecursive(QSGItem *parentItem) const +void QuickItemNodeInstance::updateDirtyNodeRecursive(QQuickItem *parentItem) const { - foreach (QSGItem *childItem, parentItem->childItems()) { + foreach (QQuickItem *childItem, parentItem->childItems()) { if (!nodeInstanceServer()->hasInstanceForObject(childItem)) updateDirtyNodeRecursive(childItem); } @@ -194,86 +195,86 @@ void SGItemNodeInstance::updateDirtyNodeRecursive(QSGItem *parentItem) const DesignerSupport::updateDirtyNode(parentItem); } -QImage SGItemNodeInstance::renderImage() const +QImage QuickItemNodeInstance::renderImage() const { - updateDirtyNodeRecursive(sgItem()); + updateDirtyNodeRecursive(quickItem()); - QRectF boundingRect = boundingRectWithStepChilds(sgItem()); + QRectF boundingRect = boundingRectWithStepChilds(quickItem()); - QImage renderImage = designerSupport()->renderImageForItem(sgItem(), boundingRect, boundingRect.size().toSize()); + QImage renderImage = designerSupport()->renderImageForItem(quickItem(), boundingRect, boundingRect.size().toSize()); renderImage = renderImage.convertToFormat(QImage::Format_ARGB32_Premultiplied); return renderImage; } -bool SGItemNodeInstance::isMovable() const +bool QuickItemNodeInstance::isMovable() const { if (isRootNodeInstance()) return false; - return m_isMovable && sgItem() && sgItem()->parentItem(); + return m_isMovable && quickItem() && quickItem()->parentItem(); } -void SGItemNodeInstance::setMovable(bool movable) +void QuickItemNodeInstance::setMovable(bool movable) { m_isMovable = movable; } -SGItemNodeInstance::Pointer SGItemNodeInstance::create(QObject *object) +QuickItemNodeInstance::Pointer QuickItemNodeInstance::create(QObject *object) { - QSGItem *sgItem = qobject_cast<QSGItem*>(object); + QQuickItem *quickItem = qobject_cast<QQuickItem*>(object); - Q_ASSERT(sgItem); + Q_ASSERT(quickItem); - Pointer instance(new SGItemNodeInstance(sgItem)); + Pointer instance(new QuickItemNodeInstance(quickItem)); - instance->setHasContent(anyItemHasContent(sgItem)); - sgItem->setFlag(QSGItem::ItemHasContents, true); + instance->setHasContent(anyItemHasContent(quickItem)); + quickItem->setFlag(QQuickItem::ItemHasContents, true); - static_cast<QDeclarativeParserStatus*>(sgItem)->classBegin(); + static_cast<QQmlParserStatus*>(quickItem)->classBegin(); instance->populateResetHashes(); return instance; } -void SGItemNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance) +void QuickItemNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance) { if (instanceId() == 0) { - DesignerSupport::setRootItem(nodeInstanceServer()->sgView(), sgItem()); + DesignerSupport::setRootItem(nodeInstanceServer()->quickView(), quickItem()); } else { - sgItem()->setParentItem(qobject_cast<QSGItem*>(nodeInstanceServer()->sgView()->rootObject())); + quickItem()->setParentItem(qobject_cast<QQuickItem*>(nodeInstanceServer()->quickView()->rootObject())); } if (s_createEffectItem || instanceId() == 0) - designerSupport()->refFromEffectItem(sgItem()); + designerSupport()->refFromEffectItem(quickItem()); ObjectNodeInstance::initialize(objectNodeInstance); - sgItem()->update(); + quickItem()->update(); } -bool SGItemNodeInstance::isSGItem() const +bool QuickItemNodeInstance::isQuickItem() const { return true; } -QSizeF SGItemNodeInstance::size() const +QSizeF QuickItemNodeInstance::size() const { double width; - if (DesignerSupport::isValidWidth(sgItem())) { - width = sgItem()->width(); + if (DesignerSupport::isValidWidth(quickItem())) { + width = quickItem()->width(); } else { - width = sgItem()->implicitWidth(); + width = quickItem()->implicitWidth(); } double height; - if (DesignerSupport::isValidHeight(sgItem())) { - height = sgItem()->height(); + if (DesignerSupport::isValidHeight(quickItem())) { + height = quickItem()->height(); } else { - height = sgItem()->implicitHeight(); + height = quickItem()->implicitHeight(); } @@ -285,11 +286,11 @@ static inline bool isRectangleSane(const QRectF &rect) return rect.isValid() && (rect.width() < 10000) && (rect.height() < 10000); } -QRectF SGItemNodeInstance::boundingRectWithStepChilds(QSGItem *parentItem) const +QRectF QuickItemNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) const { QRectF boundingRect = parentItem->boundingRect(); - foreach (QSGItem *childItem, parentItem->childItems()) { + foreach (QQuickItem *childItem, parentItem->childItems()) { if (!nodeInstanceServer()->hasInstanceForObject(childItem)) { QRectF transformedRect = childItem->mapRectToItem(parentItem, boundingRectWithStepChilds(childItem)); if (isRectangleSane(transformedRect)) @@ -300,20 +301,20 @@ QRectF SGItemNodeInstance::boundingRectWithStepChilds(QSGItem *parentItem) const return boundingRect; } -QRectF SGItemNodeInstance::boundingRect() const +QRectF QuickItemNodeInstance::boundingRect() const { - if (sgItem()) { - if (sgItem()->clip()) { - return sgItem()->boundingRect(); + if (quickItem()) { + if (quickItem()->clip()) { + return quickItem()->boundingRect(); } else { - return boundingRectWithStepChilds(sgItem()); + return boundingRectWithStepChilds(quickItem()); } } return QRectF(); } -void SGItemNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +void QuickItemNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) { if (name == "state") return; // states are only set by us @@ -345,7 +346,7 @@ void SGItemNodeInstance::setPropertyVariant(const QString &name, const QVariant refresh(); } -void SGItemNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +void QuickItemNodeInstance::setPropertyBinding(const QString &name, const QString &expression) { if (name == "state") return; // states are only set by us @@ -353,37 +354,37 @@ void SGItemNodeInstance::setPropertyBinding(const QString &name, const QString & ObjectNodeInstance::setPropertyBinding(name, expression); } -QVariant SGItemNodeInstance::property(const QString &name) const +QVariant QuickItemNodeInstance::property(const QString &name) const { return ObjectNodeInstance::property(name); } -void SGItemNodeInstance::resetHorizontal() +void QuickItemNodeInstance::resetHorizontal() { setPropertyVariant("x", m_x); if (m_width > 0.0) { setPropertyVariant("width", m_width); } else { - setPropertyVariant("width", sgItem()->implicitWidth()); + setPropertyVariant("width", quickItem()->implicitWidth()); } } -void SGItemNodeInstance::resetVertical() +void QuickItemNodeInstance::resetVertical() { setPropertyVariant("y", m_y); if (m_height > 0.0) { setPropertyVariant("height", m_height); } else { - setPropertyVariant("height", sgItem()->implicitWidth()); + setPropertyVariant("height", quickItem()->implicitWidth()); } } -static void repositioning(QSGItem *item) +static void repositioning(QQuickItem *item) { if (!item) return; -// QDeclarativeBasePositioner *positioner = qobject_cast<QDeclarativeBasePositioner*>(item); +// QQmlBasePositioner *positioner = qobject_cast<QQmlBasePositioner*>(item); // if (positioner) // positioner->rePositioning(); @@ -391,41 +392,41 @@ static void repositioning(QSGItem *item) repositioning(item->parentItem()); } -void SGItemNodeInstance::refresh() +void QuickItemNodeInstance::refresh() { - repositioning(sgItem()); + repositioning(quickItem()); } -void SGItemNodeInstance::doComponentComplete() +void QuickItemNodeInstance::doComponentComplete() { - if (sgItem()) { - if (DesignerSupport::isComponentComplete(sgItem())) + if (quickItem()) { + if (DesignerSupport::isComponentComplete(quickItem())) return; - static_cast<QDeclarativeParserStatus*>(sgItem())->componentComplete(); + static_cast<QQmlParserStatus*>(quickItem())->componentComplete(); } - sgItem()->update(); + quickItem()->update(); } -bool SGItemNodeInstance::isResizable() const +bool QuickItemNodeInstance::isResizable() const { if (isRootNodeInstance()) return false; - return m_isResizable && sgItem() && sgItem()->parentItem(); + return m_isResizable && quickItem() && quickItem()->parentItem(); } -void SGItemNodeInstance::setResizable(bool resizeable) +void QuickItemNodeInstance::setResizable(bool resizeable) { m_isResizable = resizeable; } -int SGItemNodeInstance::penWidth() const +int QuickItemNodeInstance::penWidth() const { - return DesignerSupport::borderWidth(sgItem()); + return DesignerSupport::borderWidth(quickItem()); } -void SGItemNodeInstance::resetProperty(const QString &name) +void QuickItemNodeInstance::resetProperty(const QString &name) { if (name == "height") { m_hasHeight = false; @@ -443,7 +444,7 @@ void SGItemNodeInstance::resetProperty(const QString &name) if (name == "y") m_y = 0.0; - DesignerSupport::resetAnchor(sgItem(), name); + DesignerSupport::resetAnchor(quickItem(), name); if (name == "anchors.fill") { resetHorizontal(); @@ -470,7 +471,7 @@ void SGItemNodeInstance::resetProperty(const QString &name) ObjectNodeInstance::resetProperty(name); } -void SGItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty) +void QuickItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty) { if (oldParentInstance && oldParentInstance->isPositioner()) { setInPositioner(false); @@ -493,7 +494,7 @@ void SGItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentIn } refresh(); - DesignerSupport::updateDirtyNode(sgItem()); + DesignerSupport::updateDirtyNode(quickItem()); } static bool isValidAnchorName(const QString &name) @@ -511,17 +512,17 @@ static bool isValidAnchorName(const QString &name) return anchorNameList.contains(name); } -bool SGItemNodeInstance::hasAnchor(const QString &name) const +bool QuickItemNodeInstance::hasAnchor(const QString &name) const { - return DesignerSupport::hasAnchor(sgItem(), name); + return DesignerSupport::hasAnchor(quickItem(), name); } -QPair<QString, ServerNodeInstance> SGItemNodeInstance::anchor(const QString &name) const +QPair<QString, ServerNodeInstance> QuickItemNodeInstance::anchor(const QString &name) const { - if (!isValidAnchorName(name) || !DesignerSupport::hasAnchor(sgItem(), name)) + if (!isValidAnchorName(name) || !DesignerSupport::hasAnchor(quickItem(), name)) return ObjectNodeInstance::anchor(name); - QPair<QString, QObject*> nameObjectPair = DesignerSupport::anchorLineTarget(sgItem(), name, context()); + QPair<QString, QObject*> nameObjectPair = DesignerSupport::anchorLineTarget(quickItem(), name, context()); QObject *targetObject = nameObjectPair.second; QString targetName = nameObjectPair.first; @@ -533,10 +534,10 @@ QPair<QString, ServerNodeInstance> SGItemNodeInstance::anchor(const QString &nam } } -QList<ServerNodeInstance> SGItemNodeInstance::stateInstances() const +QList<ServerNodeInstance> QuickItemNodeInstance::stateInstances() const { QList<ServerNodeInstance> instanceList; - QList<QObject*> stateList = DesignerSupport::statesForItem(sgItem()); + QList<QObject*> stateList = DesignerSupport::statesForItem(quickItem()); foreach (QObject *state, stateList) { if (state && nodeInstanceServer()->hasInstanceForObject(state)) @@ -546,12 +547,12 @@ QList<ServerNodeInstance> SGItemNodeInstance::stateInstances() const return instanceList; } -bool SGItemNodeInstance::isAnchoredBySibling() const +bool QuickItemNodeInstance::isAnchoredBySibling() const { - if (sgItem()->parentItem()) { - foreach (QSGItem *siblingItem, sgItem()->parentItem()->childItems()) { // search in siblings for a anchor to this item + if (quickItem()->parentItem()) { + foreach (QQuickItem *siblingItem, quickItem()->parentItem()->childItems()) { // search in siblings for a anchor to this item if (siblingItem) { - if (DesignerSupport::isAnchoredTo(siblingItem, sgItem())) + if (DesignerSupport::isAnchoredTo(siblingItem, quickItem())) return true; } } @@ -560,34 +561,34 @@ bool SGItemNodeInstance::isAnchoredBySibling() const return false; } -bool SGItemNodeInstance::isAnchoredByChildren() const +bool QuickItemNodeInstance::isAnchoredByChildren() const { - if (DesignerSupport::areChildrenAnchoredTo(sgItem(), sgItem())) // search in children for a anchor to this item + if (DesignerSupport::areChildrenAnchoredTo(quickItem(), quickItem())) // search in children for a anchor to this item return true; return false; } -QSGItem *SGItemNodeInstance::sgItem() const +QQuickItem *QuickItemNodeInstance::quickItem() const { if (object() == 0) return 0; - Q_ASSERT(qobject_cast<QSGItem*>(object())); - return static_cast<QSGItem*>(object()); + Q_ASSERT(qobject_cast<QQuickItem*>(object())); + return static_cast<QQuickItem*>(object()); } -DesignerSupport *SGItemNodeInstance::designerSupport() const +DesignerSupport *QuickItemNodeInstance::designerSupport() const { return qt5NodeInstanceServer()->designerSupport(); } -Qt5NodeInstanceServer *SGItemNodeInstance::qt5NodeInstanceServer() const +Qt5NodeInstanceServer *QuickItemNodeInstance::qt5NodeInstanceServer() const { return qobject_cast<Qt5NodeInstanceServer*>(nodeInstanceServer()); } -void SGItemNodeInstance::createEffectItem(bool createEffectItem) +void QuickItemNodeInstance::createEffectItem(bool createEffectItem) { s_createEffectItem = createEffectItem; } diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.h index 21d1b9492d..c14f85ea20 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/sgitemnodeinstance.h @@ -28,31 +28,31 @@ ** **************************************************************************/ -#ifndef SGITEMNODEINSTANCE_H -#define SGITEMNODEINSTANCE_H +#ifndef QuickITEMNODEINSTANCE_H +#define QuickITEMNODEINSTANCE_H #include <QtGlobal> #include "objectnodeinstance.h" -#include <QSGItem> +#include <QQuickItem> #include <designersupport.h> namespace QmlDesigner { namespace Internal { -class SGItemNodeInstance : public ObjectNodeInstance +class QuickItemNodeInstance : public ObjectNodeInstance { public: - typedef QSharedPointer<SGItemNodeInstance> Pointer; - typedef QWeakPointer<SGItemNodeInstance> WeakPointer; + typedef QSharedPointer<QuickItemNodeInstance> Pointer; + typedef QWeakPointer<QuickItemNodeInstance> WeakPointer; - ~SGItemNodeInstance(); + ~QuickItemNodeInstance(); static Pointer create(QObject *objectToBeWrapped); void initialize(const ObjectNodeInstance::Pointer &objectNodeInstance); - bool isSGItem() const; + bool isQuickItem() const; QRectF boundingRect() const; QPointF position() const; @@ -69,12 +69,12 @@ public: QPointF transformOriginPoint() const; double zValue() const; - bool equalSGItem(QSGItem *item) const; + bool equalQuickItem(QQuickItem *item) const; bool hasContent() const; QList<ServerNodeInstance> childItems() const; - QList<ServerNodeInstance> childItemsForChild(QSGItem *childItem) const; + QList<ServerNodeInstance> childItemsForChild(QQuickItem *childItem) const; bool isMovable() const; void setMovable(bool movable); @@ -110,13 +110,13 @@ public: static void createEffectItem(bool createEffectItem); protected: - SGItemNodeInstance(QSGItem*); - QSGItem *sgItem() const; + QuickItemNodeInstance(QQuickItem*); + QQuickItem *quickItem() const; void resetHorizontal(); void resetVertical(); void refresh(); - QRectF boundingRectWithStepChilds(QSGItem *parentItem) const; - void updateDirtyNodeRecursive(QSGItem *parentItem) const; + QRectF boundingRectWithStepChilds(QQuickItem *parentItem) const; + void updateDirtyNodeRecursive(QQuickItem *parentItem) const; private: //variables bool m_hasHeight; @@ -134,5 +134,5 @@ private: //variables } // namespace Internal } // namespace QmlDesigner -#endif // SGITEMNODEINSTANCE_H +#endif // QuickITEMNODEINSTANCE_H diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pro b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pro index 77351d8a9e..b92eb0acef 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pro +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pro @@ -2,22 +2,20 @@ TARGET = qml2puppet TEMPLATE = app -QT += core gui declarative network - +QT += core gui qml quick network v8 contains (QT_CONFIG, webkit) { QT += webkit } -QT += core-private declarative-private gui-private script-private v8-private +QT += core-private qml-private quick-private gui-private script-private v8-private DEFINES += QWEAKPOINTER_ENABLE_ARROW -include(../../../../qtcreator.pri) +include(../../../../../qtcreator.pri) DESTDIR = $$[QT_INSTALL_BINS] -include(../../../rpath.pri) +include(../../../../../src/rpath.pri) include (instances/instances.pri) -include (../instances/instances.pri) include (../commands/commands.pri) include (../container/container.pri) include (../interfaces/interfaces.pri) |