1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qtquick2_p.h"
43 #include <private/qqmlengine_p.h>
44 #include <private/qquickutilmodule_p.h>
45 #include <private/qquickvaluetypes_p.h>
46 #include <private/qquickitemsmodule_p.h>
48 #include <private/qqmlenginedebugservice_p.h>
49 #include <private/qqmldebugstatesdelegate_p.h>
50 #include <private/qqmlbinding_p.h>
51 #include <private/qqmlcontext_p.h>
52 #include <private/qquickapplication_p.h>
53 #include <QtQuick/private/qquickpropertychanges_p.h>
54 #include <QtQuick/private/qquickstate_p.h>
55 #include <qqmlproperty.h>
56 #include <QtCore/QPointer>
60 class QQmlQtQuick2DebugStatesDelegate : public QQmlDebugStatesDelegate
63 QQmlQtQuick2DebugStatesDelegate();
64 virtual ~QQmlQtQuick2DebugStatesDelegate();
65 virtual void buildStatesList(bool cleanList, const QList<QPointer<QObject> > &instances);
66 virtual void updateBinding(QQmlContext *context,
67 const QQmlProperty &property,
68 const QVariant &expression, bool isLiteralValue,
69 const QString &fileName, int line, int column,
71 virtual bool setBindingForInvalidProperty(QObject *object,
72 const QString &propertyName,
73 const QVariant &expression,
75 virtual void resetBindingForInvalidProperty(QObject *object,
76 const QString &propertyName);
79 void buildStatesList(QObject *obj);
81 QList<QPointer<QQuickState> > m_allStates;
84 QQmlQtQuick2DebugStatesDelegate::QQmlQtQuick2DebugStatesDelegate()
88 QQmlQtQuick2DebugStatesDelegate::~QQmlQtQuick2DebugStatesDelegate()
92 void QQmlQtQuick2DebugStatesDelegate::buildStatesList(bool cleanList,
93 const QList<QPointer<QObject> > &instances)
98 //only root context has all instances
99 for (int ii = 0; ii < instances.count(); ++ii) {
100 buildStatesList(instances.at(ii));
104 void QQmlQtQuick2DebugStatesDelegate::buildStatesList(QObject *obj)
106 if (QQuickState *state = qobject_cast<QQuickState *>(obj)) {
107 m_allStates.append(state);
110 QObjectList children = obj->children();
111 for (int ii = 0; ii < children.count(); ++ii) {
112 buildStatesList(children.at(ii));
116 void QQmlQtQuick2DebugStatesDelegate::updateBinding(QQmlContext *context,
117 const QQmlProperty &property,
118 const QVariant &expression, bool isLiteralValue,
119 const QString &fileName, int line, int column,
122 typedef QPointer<QQuickState> QuickStatePointer;
123 QObject *object = property.object();
124 QString propertyName = property.name();
125 foreach (const QuickStatePointer& statePointer, m_allStates) {
126 if (QQuickState *state = statePointer.data()) {
127 // here we assume that the revert list on itself defines the base state
128 if (state->isStateActive() && state->containsPropertyInRevertList(object, propertyName)) {
129 *inBaseState = false;
131 QQmlBinding *newBinding = 0;
132 if (!isLiteralValue) {
133 newBinding = new QQmlBinding(expression.toString(), false, object,
134 QQmlContextData::get(context), fileName,
136 newBinding->setTarget(property);
137 newBinding->setNotifyOnValueChanged(true);
140 state->changeBindingInRevertList(object, propertyName, newBinding);
143 state->changeValueInRevertList(object, propertyName, expression);
149 bool QQmlQtQuick2DebugStatesDelegate::setBindingForInvalidProperty(QObject *object,
150 const QString &propertyName,
151 const QVariant &expression,
154 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
156 propertyChanges->changeValue(propertyName, expression);
158 propertyChanges->changeExpression(propertyName, expression.toString());
165 void QQmlQtQuick2DebugStatesDelegate::resetBindingForInvalidProperty(QObject *object, const QString &propertyName)
167 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
168 propertyChanges->removeProperty(propertyName);
173 void QQmlQtQuick2Module::defineModule()
175 QQuickUtilModule::defineModule();
176 QQmlEnginePrivate::defineQtQuick2Module();
177 QQuickItemsModule::defineModule();
179 qmlRegisterUncreatableType<QQuickApplication>("QtQuick",2,0,"Application", QQuickApplication::tr("Application is an abstract class"));
181 QQuickValueTypes::registerValueTypes();
183 if (QQmlEngineDebugService::isDebuggingEnabled()) {
184 QQmlEngineDebugService::instance()->setStatesDelegate(
185 new QQmlQtQuick2DebugStatesDelegate);