From cd8d8d49f78c1cbb8ad3546e66a461b9e6e29ff5 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 14:24:20 +1000 Subject: Make QmlBinding (and friends) private QmlBinding exposes way too many implementation details to be confident about making it public right now. --- doc/src/declarative/extending.qdoc | 12 -- src/declarative/qml/qml.pri | 2 +- src/declarative/qml/qmlbinding.cpp | 2 +- src/declarative/qml/qmlbinding.h | 132 --------------------- src/declarative/qml/qmlbinding_p.h | 76 +++++++++--- src/declarative/qml/qmlbinding_p_p.h | 89 ++++++++++++++ src/declarative/qml/qmlcompiledbindings_p.h | 2 +- src/declarative/qml/qmlcompiler.cpp | 2 +- src/declarative/qml/qmlcomponent.cpp | 2 +- src/declarative/qml/qmlengine.cpp | 2 +- src/declarative/qml/qmlenginedebug.cpp | 2 +- src/declarative/qml/qmlmetaproperty.cpp | 2 +- src/declarative/qml/qmlobjectscriptclass.cpp | 2 +- src/declarative/qml/qmlpropertycache.cpp | 4 +- src/declarative/qml/qmlvme.cpp | 4 +- src/declarative/util/qmlpropertychanges.cpp | 2 +- src/declarative/util/qmlstate.cpp | 2 +- src/declarative/util/qmlstategroup.cpp | 2 +- src/declarative/util/qmltransitionmanager.cpp | 2 +- tests/auto/declarative/qmldebug/tst_qmldebug.cpp | 2 +- .../qmlmetaproperty/tst_qmlmetaproperty.cpp | 2 +- 21 files changed, 169 insertions(+), 178 deletions(-) delete mode 100644 src/declarative/qml/qmlbinding.h create mode 100644 src/declarative/qml/qmlbinding_p_p.h diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index d3e6c14..396ddab 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -557,18 +557,6 @@ to be used in bindings should have a NOTIFY signal instead. \l {Extending QML - Binding Example} shows the BirthdayParty example updated to include NOTIFY signals for use in binding. -\section1 Binding and Script Properties - -While generally no changes are needed to a C++ class to use property -binding, sometimes more advanced interaction between the binding engine and -an object is desirable. To facilitate this, there is a special exception -in the bind engine for allowing an object to access the binding directly. - -If a binding is assigned to a property with a type of QmlBinding -pointer (ie. \c {QmlBinding *}), each time the binding value changes, -a QmlBinding instance is assigned to that property. The QmlBinding instance -allows the object to read the binding and to evaluate the binding's current value. - \section1 Extension Objects \snippet examples/declarative/extending/extended/example.qml 0 diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 2313c37..f09a944 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -60,8 +60,8 @@ HEADERS += \ $$PWD/qmlinstruction_p.h \ $$PWD/qmlvmemetaobject_p.h \ $$PWD/qml.h \ - $$PWD/qmlbinding.h \ $$PWD/qmlbinding_p.h \ + $$PWD/qmlbinding_p_p.h \ $$PWD/qmlmetaproperty.h \ $$PWD/qmlmoduleplugin.h \ $$PWD/qmlcomponent.h \ diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index feadd0f..9f93fee 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlbinding.h" #include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qml.h" #include "qmlcontext.h" diff --git a/src/declarative/qml/qmlbinding.h b/src/declarative/qml/qmlbinding.h deleted file mode 100644 index 151b71c..0000000 --- a/src/declarative/qml/qmlbinding.h +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLBINDING_H -#define QMLBINDING_H - -#include "qml.h" -#include "qmlpropertyvaluesource.h" -#include "qmlexpression.h" - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlAbstractBinding -{ -public: - QmlAbstractBinding(); - virtual ~QmlAbstractBinding(); - - virtual void destroy(); - - virtual QString expression() const; - - void setEnabled(bool e) { setEnabled(e, QmlMetaProperty::DontRemoveBinding); } - virtual void setEnabled(bool, QmlMetaProperty::WriteFlags) = 0; - virtual int propertyIndex() = 0; - - void update() { update(QmlMetaProperty::DontRemoveBinding); } - virtual void update(QmlMetaProperty::WriteFlags) = 0; - - void addToObject(QObject *); - void removeFromObject(); - -protected: - void clear(); - -private: - friend class QmlDeclarativeData; - friend class QmlMetaProperty; - friend class QmlMetaPropertyPrivate; - friend class QmlVME; - - QObject *m_object; - QmlAbstractBinding **m_mePtr; - QmlAbstractBinding **m_prevBinding; - QmlAbstractBinding *m_nextBinding; -}; - -class QmlContext; -class QmlBindingPrivate; -class Q_DECLARATIVE_EXPORT QmlBinding : public QmlExpression, - public QmlAbstractBinding -{ -Q_OBJECT -public: - QmlBinding(const QString &, QObject *, QmlContext *, QObject *parent=0); - QmlBinding(void *, QmlRefCount *, QObject *, QmlContext *, const QString &, int, - QObject *parent); - ~QmlBinding(); - - void setTarget(const QmlMetaProperty &); - QmlMetaProperty property() const; - - bool enabled() const; - - // Inherited from QmlAbstractBinding - virtual void setEnabled(bool, QmlMetaProperty::WriteFlags flags); - virtual int propertyIndex(); - virtual void update(QmlMetaProperty::WriteFlags flags); - virtual QString expression() const; - -public Q_SLOTS: - void update() { update(QmlMetaProperty::DontRemoveBinding); } - -protected: - void emitValueChanged(); - -private: - Q_DECLARE_PRIVATE(QmlBinding) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlBinding); - -QT_END_HEADER - -#endif // QMLBINDING_H diff --git a/src/declarative/qml/qmlbinding_p.h b/src/declarative/qml/qmlbinding_p.h index b4f88b5..4594476 100644 --- a/src/declarative/qml/qmlbinding_p.h +++ b/src/declarative/qml/qmlbinding_p.h @@ -53,36 +53,82 @@ // We mean it. // -#include "qmlbinding.h" +#include "qml.h" +#include "qmlpropertyvaluesource.h" +#include "qmlexpression.h" -#include "qmlmetaproperty.h" -#include "qmlexpression_p.h" +#include +#include QT_BEGIN_NAMESPACE -class QmlBindingData : public QmlExpressionData +class Q_AUTOTEST_EXPORT QmlAbstractBinding { public: - QmlBindingData(); - virtual ~QmlBindingData(); + QmlAbstractBinding(); + virtual ~QmlAbstractBinding(); - bool updating:1; - bool enabled:1; + virtual void destroy(); - QmlMetaProperty property; + virtual QString expression() const; - virtual void refresh(); + void setEnabled(bool e) { setEnabled(e, QmlMetaProperty::DontRemoveBinding); } + virtual void setEnabled(bool, QmlMetaProperty::WriteFlags) = 0; + virtual int propertyIndex() = 0; + + void update() { update(QmlMetaProperty::DontRemoveBinding); } + virtual void update(QmlMetaProperty::WriteFlags) = 0; + + void addToObject(QObject *); + void removeFromObject(); + +protected: + void clear(); + +private: + friend class QmlDeclarativeData; + friend class QmlMetaProperty; + friend class QmlMetaPropertyPrivate; + friend class QmlVME; + + QObject *m_object; + QmlAbstractBinding **m_mePtr; + QmlAbstractBinding **m_prevBinding; + QmlAbstractBinding *m_nextBinding; }; -class QmlBindingPrivate : public QmlExpressionPrivate +class QmlContext; +class QmlBindingPrivate; +class Q_AUTOTEST_EXPORT QmlBinding : public QmlExpression, public QmlAbstractBinding { - Q_DECLARE_PUBLIC(QmlBinding) +Q_OBJECT public: - QmlBindingPrivate(); + QmlBinding(const QString &, QObject *, QmlContext *, QObject *parent=0); + QmlBinding(void *, QmlRefCount *, QObject *, QmlContext *, const QString &, int, + QObject *parent); + ~QmlBinding(); + + void setTarget(const QmlMetaProperty &); + QmlMetaProperty property() const; + + bool enabled() const; + + // Inherited from QmlAbstractBinding + virtual void setEnabled(bool, QmlMetaProperty::WriteFlags flags); + virtual int propertyIndex(); + virtual void update(QmlMetaProperty::WriteFlags flags); + virtual QString expression() const; + +public Q_SLOTS: + void update() { update(QmlMetaProperty::DontRemoveBinding); } + +protected: + void emitValueChanged(); - QmlBindingData *bindingData() { return static_cast(data); } - const QmlBindingData *bindingData() const { return static_cast(data); } +private: + Q_DECLARE_PRIVATE(QmlBinding) }; +Q_DECLARE_METATYPE(QmlBinding*); QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlbinding_p_p.h b/src/declarative/qml/qmlbinding_p_p.h new file mode 100644 index 0000000..e5a06fc --- /dev/null +++ b/src/declarative/qml/qmlbinding_p_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLBINDING_P_P_H +#define QMLBINDING_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlbinding_p.h" + +#include "qmlmetaproperty.h" +#include "qmlexpression_p.h" + +QT_BEGIN_NAMESPACE + +class QmlBindingData : public QmlExpressionData +{ +public: + QmlBindingData(); + virtual ~QmlBindingData(); + + bool updating:1; + bool enabled:1; + + QmlMetaProperty property; + + virtual void refresh(); +}; + +class QmlBindingPrivate : public QmlExpressionPrivate +{ + Q_DECLARE_PUBLIC(QmlBinding) +public: + QmlBindingPrivate(); + + QmlBindingData *bindingData() { return static_cast(data); } + const QmlBindingData *bindingData() const { return static_cast(data); } +}; + +QT_END_NAMESPACE + +#endif // QMLBINDING_P_P_H diff --git a/src/declarative/qml/qmlcompiledbindings_p.h b/src/declarative/qml/qmlcompiledbindings_p.h index 38fb2a3..056cc21 100644 --- a/src/declarative/qml/qmlcompiledbindings_p.h +++ b/src/declarative/qml/qmlcompiledbindings_p.h @@ -54,7 +54,7 @@ // #include "qmlexpression_p.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" QT_BEGIN_HEADER diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index bbae201..10b6e4f 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -63,7 +63,7 @@ #include "qmlscriptstring.h" #include "qmlglobal_p.h" #include "qmlscriptparser_p.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlcompiledbindings_p.h" #include diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 87ecb8a..4ab4f70 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -49,8 +49,8 @@ #include "qmlvme_p.h" #include "qml.h" #include "qmlengine.h" -#include "qmlbinding.h" #include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qmlglobal_p.h" #include "qmlscriptparser_p.h" diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 97d8250..2460f52 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -51,7 +51,7 @@ #include "qmlcomponent.h" #include "qmlmetaproperty_p.h" #include "qmlmoduleplugin.h" -#include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qmlvme_p.h" #include "qmlenginedebug_p.h" #include "qmlstringconverters_p.h" diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 654157c..2ab709a 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -45,7 +45,7 @@ #include "qmlengine.h" #include "qmlmetatype.h" #include "qmlmetaproperty.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlcontext_p.h" #include "qmlwatcher_p.h" diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 1742c43..ac619ec 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -44,7 +44,7 @@ #include "qmlcompositetypedata_p.h" #include "qml.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlcontext.h" #include "qmlcontext_p.h" #include "qmlboundsignal_p.h" diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index 15ece1d..155a7d6 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -46,7 +46,7 @@ #include "qmldeclarativedata_p.h" #include "qmltypenamescriptclass_p.h" #include "qmllistscriptclass_p.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlguard_p.h" #include "qmlvmemetaobject_p.h" diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index a3e655b..2d087b6 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -42,8 +42,8 @@ #include "qmlpropertycache_p.h" #include "qmlengine_p.h" -#include "qmlbinding.h" -#include "qdebug.h" +#include "qmlbinding_p.h" +#include Q_DECLARE_METATYPE(QScriptValue); diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 8655809..f8f1ff0 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -51,11 +51,11 @@ #include "qmlengine.h" #include "qmlcontext.h" #include "qmlcomponent.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlengine_p.h" #include "qmlcomponent_p.h" #include "qmlvmemetaobject_p.h" -#include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qmlcontext_p.h" #include "qmlcompiledbindings_p.h" #include "qmlglobal_p.h" diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index 068cb4d..0ce3604 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index 4462b1f..ea99bd5 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -48,7 +48,7 @@ #include "qmlanimation_p.h" #include "qmlanimation_p_p.h" -#include +#include #include #include diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index 4ad77c8..7a5db1b 100644 --- a/src/declarative/util/qmlstategroup.cpp +++ b/src/declarative/util/qmlstategroup.cpp @@ -44,7 +44,7 @@ #include "qmltransition_p.h" #include "qmlstate_p_p.h" -#include +#include #include #include diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp index f2a4d64..60d9a60 100644 --- a/src/declarative/util/qmltransitionmanager.cpp +++ b/src/declarative/util/qmltransitionmanager.cpp @@ -43,7 +43,7 @@ #include "qmlstate_p_p.h" -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp index ba07331..2f1a557 100644 --- a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp +++ b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp @@ -51,8 +51,8 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index c289641..540d658 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include class MyQmlObject : public QObject -- cgit v0.12