Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickdesignersupportstates.cpp
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
6
7#include <private/qquickstategroup_p.h>
8#include <private/qquickpropertychanges_p.h>
9
11
12bool QQuickDesignerSupportStates::isStateActive(QObject *object, QQmlContext *context)
13{
14 QQuickState *stateObject = qobject_cast<QQuickState*>(object);
15
16 if (!stateObject)
17 return false;
18
19 QQuickStateGroup *stateGroup = stateObject->stateGroup();
20
21 QQmlProperty property(object, QLatin1String("name"), context);
22
23 return stateObject && stateGroup && stateGroup->state() == property.read();
24}
25
26void QQuickDesignerSupportStates::activateState(QObject *object, QQmlContext *context)
27{
28 QQuickState *stateObject = qobject_cast<QQuickState*>(object);
29
30 if (!stateObject)
31 return;
32
33 QQuickStateGroup *stateGroup = stateObject->stateGroup();
34
35 QQmlProperty property(object, QLatin1String("name"), context);
36
37 stateGroup->setState(property.read().toString());
38}
39
40void QQuickDesignerSupportStates::deactivateState(QObject *object)
41{
42 QQuickState *stateObject = qobject_cast<QQuickState*>(object);
43
44 if (!stateObject)
45 return;
46
47 QQuickStateGroup *stateGroup = stateObject->stateGroup();
48
49 if (stateGroup)
50 stateGroup->setState(QString());
51}
52
53bool QQuickDesignerSupportStates::changeValueInRevertList(QObject *state, QObject *target,
54 const QQuickDesignerSupport::PropertyName &propertyName,
55 const QVariant &value)
56{
57 QQuickState *stateObject = qobject_cast<QQuickState*>(state);
58
59 if (!stateObject)
60 return false;
61
62 return stateObject->changeValueInRevertList(target, QString::fromUtf8(propertyName), value);
63}
64
65bool QQuickDesignerSupportStates::updateStateBinding(QObject *state, QObject *target,
66 const QQuickDesignerSupport::PropertyName &propertyName,
67 const QString &expression)
68{
69 QQuickState *stateObject = qobject_cast<QQuickState*>(state);
70
71 if (!stateObject)
72 return false;
73
74 return stateObject->changeValueInRevertList(target, QString::fromUtf8(propertyName), expression);
75}
76
77bool QQuickDesignerSupportStates::resetStateProperty(QObject *state, QObject *target,
78 const QQuickDesignerSupport::PropertyName &propertyName,
79 const QVariant & /* resetValue */)
80{
81 QQuickState *stateObject = qobject_cast<QQuickState*>(state);
82
83 if (!stateObject)
84 return false;
85
86 return stateObject->removeEntryFromRevertList(target, QString::fromUtf8(propertyName));
87}
88
89QT_END_NAMESPACE
Combined button and popup list for selecting options.