1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickdesignersupportstates_p.h"
5
6#include <private/qquickstategroup_p.h>
7#include <private/qquickpropertychanges_p.h>
8
9QT_BEGIN_NAMESPACE
10
11bool QQuickDesignerSupportStates::isStateActive(QObject *object, QQmlContext *context)
12{
13 QQuickState *stateObject = qobject_cast<QQuickState*>(object);
14
15 if (!stateObject)
16 return false;
17
18 QQuickStateGroup *stateGroup = stateObject->stateGroup();
19
20 QQmlProperty property(object, QLatin1String("name"), context);
21
22 return stateObject && stateGroup && stateGroup->state() == property.read();
23}
24
25void QQuickDesignerSupportStates::activateState(QObject *object, QQmlContext *context)
26{
27 QQuickState *stateObject = qobject_cast<QQuickState*>(object);
28
29 if (!stateObject)
30 return;
31
32 QQuickStateGroup *stateGroup = stateObject->stateGroup();
33
34 QQmlProperty property(object, QLatin1String("name"), context);
35
36 stateGroup->setState(property.read().toString());
37}
38
39void QQuickDesignerSupportStates::deactivateState(QObject *object)
40{
41 QQuickState *stateObject = qobject_cast<QQuickState*>(object);
42
43 if (!stateObject)
44 return;
45
46 QQuickStateGroup *stateGroup = stateObject->stateGroup();
47
48 if (stateGroup)
49 stateGroup->setState(QString());
50}
51
52bool QQuickDesignerSupportStates::changeValueInRevertList(QObject *state, QObject *target,
53 const QQuickDesignerSupport::PropertyName &propertyName,
54 const QVariant &value)
55{
56 QQuickState *stateObject = qobject_cast<QQuickState*>(object: state);
57
58 if (!stateObject)
59 return false;
60
61 return stateObject->changeValueInRevertList(target, name: QString::fromUtf8(ba: propertyName), revertValue: value);
62}
63
64bool QQuickDesignerSupportStates::updateStateBinding(QObject *state, QObject *target,
65 const QQuickDesignerSupport::PropertyName &propertyName,
66 const QString &expression)
67{
68 QQuickState *stateObject = qobject_cast<QQuickState*>(object: state);
69
70 if (!stateObject)
71 return false;
72
73 return stateObject->changeValueInRevertList(target, name: QString::fromUtf8(ba: propertyName), revertValue: expression);
74}
75
76bool QQuickDesignerSupportStates::resetStateProperty(QObject *state, QObject *target,
77 const QQuickDesignerSupport::PropertyName &propertyName,
78 const QVariant & /* resetValue */)
79{
80 QQuickState *stateObject = qobject_cast<QQuickState*>(object: state);
81
82 if (!stateObject)
83 return false;
84
85 return stateObject->removeEntryFromRevertList(target, name: QString::fromUtf8(ba: propertyName));
86}
87
88QT_END_NAMESPACE
89
90

source code of qtdeclarative/src/quick/designer/qquickdesignersupportstates.cpp