From 4763acbd954ee1d1f846651d348b9a048b7cad89 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 20 May 2015 18:29:07 +0200 Subject: QmlPuppet: Clean up private API usage in QmlStateNodeInstance Change-Id: If1c8cee81cbdd6f90808a824c2b4d023dd8a3e12 Reviewed-by: Tim Jenssen --- .../instances/qmlpropertychangesnodeinstance.h | 4 -- .../qml2puppet/instances/qmlstatenodeinstance.cpp | 50 ++++---------- .../qml2puppet/instances/qmlstatenodeinstance.h | 13 +--- .../qmlpuppet/qmlprivategate/qmlprivategate.cpp | 80 ++++++++++++++++++++++ .../qml/qmlpuppet/qmlprivategate/qmlprivategate.h | 10 +++ 5 files changed, 103 insertions(+), 54 deletions(-) (limited to 'share') 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 #include -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 +#include #include "qmlpropertychangesnodeinstance.h" -#include 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(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(object())); - return static_cast(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 #include #include + #include #include #include +#include +#include + + #include 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(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(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(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(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(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(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 -- cgit v1.2.1