1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qtquick2_p.h"
43 #include <private/qqmlengine_p.h>
44 #include <private/qquickutilmodule_p.h>
45 #include <private/qqmlvaluetype_p.h>
46 #include <private/qquickitemsmodule_p.h>
47 #include <private/qquickparticlesmodule_p.h>
48 #include <private/qquickwindowmodule_p.h>
50 #include <private/qqmlenginedebugservice_p.h>
51 #include <private/qqmldebugstatesdelegate_p.h>
52 #include <private/qqmlbinding_p.h>
53 #include <private/qqmlcontext_p.h>
54 #include <QtQuick/private/qquickpropertychanges_p.h>
55 #include <QtQuick/private/qquickstate_p.h>
56 #include <qqmlproperty.h>
57 #include <QtCore/QWeakPointer>
61 class QQmlQtQuick2DebugStatesDelegate : public QQmlDebugStatesDelegate
64 QQmlQtQuick2DebugStatesDelegate();
65 virtual ~QQmlQtQuick2DebugStatesDelegate();
66 virtual void buildStatesList(QQmlContext *ctxt, bool cleanList);
67 virtual void updateBinding(QQmlContext *context,
68 const QQmlProperty &property,
69 const QVariant &expression, bool isLiteralValue,
70 const QString &fileName, int line, int column,
72 virtual bool setBindingForInvalidProperty(QObject *object,
73 const QString &propertyName,
74 const QVariant &expression,
76 virtual void resetBindingForInvalidProperty(QObject *object,
77 const QString &propertyName);
80 void buildStatesList(QObject *obj);
82 QList<QWeakPointer<QQuickState> > m_allStates;
85 QQmlQtQuick2DebugStatesDelegate::QQmlQtQuick2DebugStatesDelegate()
89 QQmlQtQuick2DebugStatesDelegate::~QQmlQtQuick2DebugStatesDelegate()
93 void QQmlQtQuick2DebugStatesDelegate::buildStatesList(QQmlContext *ctxt, bool cleanList)
98 QQmlContextPrivate *ctxtPriv = QQmlContextPrivate::get(ctxt);
99 for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) {
100 buildStatesList(ctxtPriv->instances.at(ii));
103 QQmlContextData *child = QQmlContextData::get(ctxt)->childContexts;
105 buildStatesList(child->asQQmlContext());
106 child = child->nextChild;
110 void QQmlQtQuick2DebugStatesDelegate::buildStatesList(QObject *obj)
112 if (QQuickState *state = qobject_cast<QQuickState *>(obj)) {
113 m_allStates.append(state);
116 QObjectList children = obj->children();
117 for (int ii = 0; ii < children.count(); ++ii) {
118 buildStatesList(children.at(ii));
122 void QQmlQtQuick2DebugStatesDelegate::updateBinding(QQmlContext *context,
123 const QQmlProperty &property,
124 const QVariant &expression, bool isLiteralValue,
125 const QString &fileName, int line, int column,
128 QObject *object = property.object();
129 QString propertyName = property.name();
130 foreach (QWeakPointer<QQuickState> statePointer, m_allStates) {
131 if (QQuickState *state = statePointer.data()) {
132 // here we assume that the revert list on itself defines the base state
133 if (state->isStateActive() && state->containsPropertyInRevertList(object, propertyName)) {
134 *inBaseState = false;
136 QQmlBinding *newBinding = 0;
137 if (!isLiteralValue) {
138 newBinding = new QQmlBinding(expression.toString(), object, context);
139 newBinding->setTarget(property);
140 newBinding->setNotifyOnValueChanged(true);
141 newBinding->setSourceLocation(fileName, line, column);
144 state->changeBindingInRevertList(object, propertyName, newBinding);
147 state->changeValueInRevertList(object, propertyName, expression);
153 bool QQmlQtQuick2DebugStatesDelegate::setBindingForInvalidProperty(QObject *object,
154 const QString &propertyName,
155 const QVariant &expression,
158 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
160 propertyChanges->changeValue(propertyName, expression);
162 propertyChanges->changeExpression(propertyName, expression.toString());
169 void QQmlQtQuick2DebugStatesDelegate::resetBindingForInvalidProperty(QObject *object, const QString &propertyName)
171 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
172 propertyChanges->removeProperty(propertyName);
177 void QQmlQtQuick2Module::defineModule()
179 QQuickUtilModule::defineModule();
180 QQmlEnginePrivate::defineModule();
181 QQuickItemsModule::defineModule();
182 QQuickParticlesModule::defineModule();
183 QQuickWindowModule::defineModule();
184 QQmlValueTypeFactory::registerValueTypes();
186 if (QQmlEngineDebugService::isDebuggingEnabled()) {
187 QQmlEngineDebugService::instance()->setStatesDelegate(
188 new QQmlQtQuick2DebugStatesDelegate);