diff options
author | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2015-05-20 18:29:07 +0200 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2015-05-21 07:39:35 +0000 |
commit | 4763acbd954ee1d1f846651d348b9a048b7cad89 (patch) | |
tree | 566755f13cb862e73c2de7654845d17786847b51 /share | |
parent | c919795a083ed659936a15657f45c540c3f0a602 (diff) | |
download | qt-creator-4763acbd954ee1d1f846651d348b9a048b7cad89.tar.gz |
QmlPuppet: Clean up private API usage in QmlStateNodeInstance
Change-Id: If1c8cee81cbdd6f90808a824c2b4d023dd8a3e12
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
Diffstat (limited to 'share')
5 files changed, 103 insertions, 54 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.h index 5ef9514910..58ab771858 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlpropertychangesnodeinstance.h @@ -37,10 +37,6 @@ #include <QPair> #include <QWeakPointer> -QT_BEGIN_NAMESPACE -class QQuickProperty; -QT_END_NAMESPACE - namespace QmlDesigner { namespace Internal { diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.cpp index 5544b369aa..74c546d632 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.cpp @@ -30,10 +30,9 @@ #include "qmlstatenodeinstance.h" -#include <private/qquickstategroup_p.h> +#include <qmlprivategate.h> #include "qmlpropertychangesnodeinstance.h" -#include <private/qquickstateoperations_p.h> namespace QmlDesigner { namespace Internal { @@ -44,7 +43,7 @@ namespace Internal { QmlStateNodeInstance manages a QQuickState object. */ -QmlStateNodeInstance::QmlStateNodeInstance(QQuickState *object) : +QmlStateNodeInstance::QmlStateNodeInstance(QObject *object) : ObjectNodeInstance(object) { } @@ -52,11 +51,7 @@ QmlStateNodeInstance::QmlStateNodeInstance(QQuickState *object) : QmlStateNodeInstance::Pointer QmlStateNodeInstance::create(QObject *object) { - QQuickState *stateObject = qobject_cast<QQuickState*>(object); - - Q_ASSERT(stateObject); - - Pointer instance(new QmlStateNodeInstance(stateObject)); + Pointer instance(new QmlStateNodeInstance(object)); instance->populateResetHashes(); @@ -65,42 +60,21 @@ QmlStateNodeInstance::Pointer void QmlStateNodeInstance::activateState() { - if (stateGroup() - && !isStateActive() + if (!QmlPrivateGate::States::isStateActive(object(), context()) && nodeInstanceServer()->hasInstanceForObject(object())) { nodeInstanceServer()->setStateInstance(nodeInstanceServer()->instanceForObject(object())); - stateGroup()->setState(property("name").toString()); + QmlPrivateGate::States::activateState(object(), context()); } - } void QmlStateNodeInstance::deactivateState() { - if (stateGroup()) { - if (isStateActive()) { - nodeInstanceServer()->clearStateInstance(); - stateGroup()->setState(QString()); - } + if (QmlPrivateGate::States::isStateActive(object(), context())) { + nodeInstanceServer()->clearStateInstance(); + QmlPrivateGate::States::deactivateState(object()); } } -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 PropertyName &name, const QVariant &value) { bool hasParent = parent(); @@ -123,17 +97,17 @@ void QmlStateNodeInstance::setPropertyBinding(const PropertyName &name, const QS bool QmlStateNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &target, const PropertyName &propertyName, const QVariant &value) { - return stateObject()->changeValueInRevertList(target->object(), QString::fromUtf8(propertyName), value); + return QmlPrivateGate::States::changeValueInRevertList(object(), target->object(), propertyName, value); } bool QmlStateNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &target, const PropertyName &propertyName, const QString &expression) { - return stateObject()->changeValueInRevertList(target->object(), QString::fromUtf8(propertyName), expression); + return QmlPrivateGate::States::updateStateBinding(object(), target->object(), propertyName, expression); } -bool QmlStateNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &target, const PropertyName &propertyName, const QVariant & /* resetValue */) +bool QmlStateNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &target, const PropertyName &propertyName, const QVariant & resetValue) { - return stateObject()->removeEntryFromRevertList(target->object(), QString::fromUtf8(propertyName)); + return QmlPrivateGate::States::resetStateProperty(object(), target->object(), propertyName, resetValue); } } // namespace Internal diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.h index c7526c8f81..80a6864134 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qmlstatenodeinstance.h @@ -32,11 +32,6 @@ #include "objectnodeinstance.h" -QT_BEGIN_NAMESPACE -class QQuickState; -class QQuickStateGroup; -QT_END_NAMESPACE - namespace QmlDesigner { namespace Internal { @@ -61,13 +56,7 @@ public: protected: - - QmlStateNodeInstance(QQuickState *object); - - bool isStateActive() const; - - QQuickState *stateObject() const; - QQuickStateGroup *stateGroup() const; + QmlStateNodeInstance(QObject *object); }; } // namespace Internal diff --git a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp index 9eb7432b8d..7461585455 100644 --- a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp +++ b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp @@ -47,10 +47,15 @@ #include <private/qquicktextinput_p.h> #include <private/qquicktextedit_p.h> #include <private/qquicktransition_p.h> + #include <private/qquickanimation_p.h> #include <private/qqmlmetatype_p.h> #include <private/qqmltimer_p.h> +#include <private/qquickstategroup_p.h> +#include <private/qquickstateoperations_p.h> + + #include <designersupport.h> namespace QmlDesigner { @@ -580,6 +585,81 @@ QObject *readQObjectProperty(const QMetaProperty &metaProperty, QObject *object) return QQmlMetaType::toQObject(metaProperty.read(object)); } +namespace States { + +bool isStateActive(QObject *object, QQmlContext *context) +{ + QQuickState *stateObject = qobject_cast<QQuickState*>(object); + + if (!stateObject) + return false; + + QQuickStateGroup *stateGroup = stateObject->stateGroup(); + + QQmlProperty property(object, "name", context); + + return stateObject && stateGroup && stateGroup->state() == property.read(); +} + +void activateState(QObject *object, QQmlContext *context) +{ + QQuickState *stateObject = qobject_cast<QQuickState*>(object); + + if (!stateObject) + return; + + QQuickStateGroup *stateGroup = stateObject->stateGroup(); + + QQmlProperty property(object, "name", context); + + stateGroup->setState(property.read().toString()); +} + +void deactivateState(QObject *object) +{ + QQuickState *stateObject = qobject_cast<QQuickState*>(object); + + if (!stateObject) + return; + + QQuickStateGroup *stateGroup = stateObject->stateGroup(); + + if (stateGroup) + stateGroup->setState(QString()); +} + +bool changeValueInRevertList(QObject *state, QObject *target, const PropertyName &propertyName, const QVariant &value) +{ + QQuickState *stateObject = qobject_cast<QQuickState*>(state); + + if (!stateObject) + return false; + + return stateObject->changeValueInRevertList(target, QString::fromUtf8(propertyName), value); +} + +bool updateStateBinding(QObject *state, QObject *target, const PropertyName &propertyName, const QString &expression) +{ + QQuickState *stateObject = qobject_cast<QQuickState*>(state); + + if (!stateObject) + return false; + + return stateObject->changeValueInRevertList(target, QString::fromUtf8(propertyName), expression); +} + +bool resetStateProperty(QObject *state, QObject *target, const PropertyName &propertyName, const QVariant & /* resetValue */) +{ + QQuickState *stateObject = qobject_cast<QQuickState*>(state); + + if (!stateObject) + return false; + + return stateObject->removeEntryFromRevertList(target, QString::fromUtf8(propertyName)); +} + +} //namespace States + ComponentCompleteDisabler::ComponentCompleteDisabler() { DesignerSupport::disableComponentComplete(); diff --git a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h index 23b98b5e02..c3731c66a9 100644 --- a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h +++ b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h @@ -102,6 +102,16 @@ public: bool isPropertyQObject(const QMetaProperty &metaProperty); QObject *readQObjectProperty(const QMetaProperty &metaProperty, QObject *object); + namespace States { + + bool isStateActive(QObject *object, QQmlContext *context); + void activateState(QObject *object, QQmlContext *context); + void deactivateState(QObject *object); + bool changeValueInRevertList(QObject *state, QObject *target, const PropertyName &propertyName, const QVariant &value); + bool updateStateBinding(QObject *state, QObject *target, const PropertyName &propertyName, const QString &expression); + bool resetStateProperty(QObject *state, QObject *target, const PropertyName &propertyName, const QVariant &); + + } //namespace States } // namespace QmlPrivateGate } // namespace Internal |