QmlPuppet: Clean up private API usage in QmlStateNodeInstance

Change-Id: If1c8cee81cbdd6f90808a824c2b4d023dd8a3e12
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Thomas Hartmann
2015-05-20 18:29:07 +02:00
parent c919795a08
commit 4763acbd95
5 changed files with 103 additions and 54 deletions
@@ -37,10 +37,6 @@
#include <QPair>
#include <QWeakPointer>
QT_BEGIN_NAMESPACE
class QQuickProperty;
QT_END_NAMESPACE
namespace QmlDesigner {
namespace Internal {
@@ -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
@@ -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
@@ -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();
@@ -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