From 3e6dbc962111228d9ff7a7afe11d69dabf97fff8 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 6 May 2009 23:06:01 +1000 Subject: Shift QmlBindableValue data into d-ptr --- src/declarative/qml/qml.pri | 1 + src/declarative/qml/qmlbindablevalue.cpp | 61 ++++++++++++++++++++----------- src/declarative/qml/qmlbindablevalue.h | 6 +-- src/declarative/qml/qmlbindablevalue_p.h | 63 ++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 src/declarative/qml/qmlbindablevalue_p.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 5198264..99e30e4 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -29,6 +29,7 @@ HEADERS += qml/qmlparser_p.h \ qml/qmlvmemetaobject_p.h \ qml/qml.h \ qml/qmlbindablevalue.h \ + qml/qmlbindablevalue_p.h \ qml/qmlmetaproperty.h \ qml/qmlcomponent.h \ qml/qmlcomponent_p.h \ diff --git a/src/declarative/qml/qmlbindablevalue.cpp b/src/declarative/qml/qmlbindablevalue.cpp index b312b40..3950f82 100644 --- a/src/declarative/qml/qmlbindablevalue.cpp +++ b/src/declarative/qml/qmlbindablevalue.cpp @@ -41,6 +41,7 @@ #include #include "qmlbindablevalue.h" +#include "qmlbindablevalue_p.h" #include #include #include @@ -50,20 +51,25 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(scriptWarnings, QML_SCRIPT_WARNINGS); +QmlBindableValuePrivate::QmlBindableValuePrivate() +: inited(false) +{ +} + QML_DEFINE_NOCREATE_TYPE(QmlBindableValue); QmlBindableValue::QmlBindableValue(QObject *parent) -: QmlPropertyValueSource(parent), _inited(false) +: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent) { qFatal("QmlBindableValue: Default constructor not supported"); } QmlBindableValue::QmlBindableValue(void *data, QmlRefCount *rc, QObject *obj, QObject *parent) -: QmlPropertyValueSource(parent), QmlExpression(QmlContext::activeContext(), data, rc, obj), _inited(false) +: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(QmlContext::activeContext(), data, rc, obj) { } QmlBindableValue::QmlBindableValue(const QString &str, QObject *obj, bool sse, QObject *parent) -: QmlPropertyValueSource(parent), QmlExpression(QmlContext::activeContext(), str, obj, sse), _inited(false) +: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(QmlContext::activeContext(), str, obj, sse) { } @@ -73,16 +79,25 @@ QmlBindableValue::~QmlBindableValue() void QmlBindableValue::setTarget(const QmlMetaProperty &prop) { - _property = prop; + Q_D(QmlBindableValue); + d->property = prop; update(); } +QmlMetaProperty QmlBindableValue::property() const +{ + Q_D(const QmlBindableValue); + return d->property; +} + void QmlBindableValue::init() { - if (_inited) + Q_D(QmlBindableValue); + + if (d->inited) return; - _inited = true; + d->inited = true; update(); } @@ -95,20 +110,22 @@ void QmlBindableValue::setExpression(const QString &expr) Q_DECLARE_METATYPE(QList); void QmlBindableValue::update() { + Q_D(QmlBindableValue); + #ifdef Q_ENABLE_PERFORMANCE_LOG QFxPerfTimer bu; #endif - if (!_inited) + if (!d->inited) return; - if (_property.propertyCategory() == QmlMetaProperty::List) { + if (d->property.propertyCategory() == QmlMetaProperty::List) { QVariant value = this->value(); - int listType = QmlMetaType::listType(_property.propertyType()); + int listType = QmlMetaType::listType(d->property.propertyType()); if (value.userType() == qMetaTypeId >()) { const QList &list = qvariant_cast >(value); - QVariant listVar = _property.read(); + QVariant listVar = d->property.read(); QmlMetaType::clear(listVar); for (int ii = 0; ii < list.count(); ++ii) { QVariant v = QmlMetaType::fromObject(list.at(ii), listType); @@ -117,14 +134,14 @@ void QmlBindableValue::update() } else if (value.type() == uint(listType) || value.userType() == listType) { - QVariant listVar = _property.read(); + QVariant listVar = d->property.read(); QmlMetaType::clear(listVar); QmlMetaType::append(listVar, value); } - } else if (_property.propertyCategory() == QmlMetaProperty::QmlList) { + } else if (d->property.propertyCategory() == QmlMetaProperty::QmlList) { // XXX - optimize! QVariant value = this->value(); - QVariant list = _property.read(); + QVariant list = d->property.read(); QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)list.constData(); @@ -153,20 +170,20 @@ void QmlBindableValue::update() void *d = (void *)&obj; li->append(d); } - } else if (_property.propertyCategory() == QmlMetaProperty::Bindable) { + } else if (d->property.propertyCategory() == QmlMetaProperty::Bindable) { // NOTE: We assume that only core properties can have // propertyType == Bindable - int idx = _property.coreIndex(); + int idx = d->property.coreIndex(); Q_ASSERT(idx != -1); void *a[1]; QmlBindableValue *t = this; a[0] = (void *)&t; - _property.object()->qt_metacall(QMetaObject::WriteProperty, - idx, a); + d->property.object()->qt_metacall(QMetaObject::WriteProperty, + idx, a); - } else if (_property.propertyCategory() == QmlMetaProperty::Object) { + } else if (d->property.propertyCategory() == QmlMetaProperty::Object) { QVariant value = this->value(); if ((int)value.type() != qMetaTypeId()) { @@ -186,17 +203,17 @@ void QmlBindableValue::update() // NOTE: We assume that only core properties can have // propertyType == Object - int idx = _property.coreIndex(); + int idx = d->property.coreIndex(); Q_ASSERT(idx != -1); void *a[1]; a[0] = (void *)&obj; - _property.object()->qt_metacall(QMetaObject::WriteProperty, + d->property.object()->qt_metacall(QMetaObject::WriteProperty, idx, a); - } else if (_property.propertyCategory() == QmlMetaProperty::Normal) { + } else if (d->property.propertyCategory() == QmlMetaProperty::Normal) { QVariant value = this->value(); - _property.write(value); + d->property.write(value); } } diff --git a/src/declarative/qml/qmlbindablevalue.h b/src/declarative/qml/qmlbindablevalue.h index 578fc12..c4ef64a 100644 --- a/src/declarative/qml/qmlbindablevalue.h +++ b/src/declarative/qml/qmlbindablevalue.h @@ -56,6 +56,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlExpression; class QmlContext; +class QmlBindableValuePrivate; class Q_DECLARATIVE_EXPORT QmlBindableValue : public QmlPropertyValueSource, public QmlExpression { @@ -67,7 +68,7 @@ public: ~QmlBindableValue(); virtual void setTarget(const QmlMetaProperty &); - QmlMetaProperty property() const { return _property; } + QmlMetaProperty property() const; Q_CLASSINFO("DefaultProperty", "expression"); Q_PROPERTY(QString expression READ expression WRITE setExpression); @@ -82,8 +83,7 @@ protected: virtual void valueChanged(); private: - bool _inited; - QmlMetaProperty _property; + Q_DECLARE_PRIVATE(QmlBindableValue) }; QML_DECLARE_TYPE(QmlBindableValue); diff --git a/src/declarative/qml/qmlbindablevalue_p.h b/src/declarative/qml/qmlbindablevalue_p.h new file mode 100644 index 0000000..b6de5b7 --- /dev/null +++ b/src/declarative/qml/qmlbindablevalue_p.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLBINDABLEVALUE_P_H +#define QMLBINDABLEVALUE_P_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlBindableValuePrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlBindableValue); +public: + QmlBindableValuePrivate(); + + bool inited; + QmlMetaProperty property; +}; + +QT_END_NAMESPACE + +#endif // QMLBINDABLEVALUE_P_H -- cgit v0.12