From f5bb807d6938fbd39ea1f99ed45c817d538e4287 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 25 Feb 2010 20:01:25 +1000 Subject: Rename QDeclarativeMetaProperty -> QDeclarativeProperty There's nothing meta about our properties. --- .../graphicsitems/qdeclarativegridview.cpp | 4 +- .../graphicsitems/qdeclarativelistview.cpp | 4 +- src/declarative/qml/qdeclarativebinding.cpp | 12 +- src/declarative/qml/qdeclarativebinding_p.h | 26 +- src/declarative/qml/qdeclarativebinding_p_p.h | 4 +- .../qml/qdeclarativecompiledbindings.cpp | 12 +- src/declarative/qml/qdeclarativecompiler.cpp | 12 +- src/declarative/qml/qdeclarativecomponent.cpp | 4 +- src/declarative/qml/qdeclarativeengine.cpp | 3 +- src/declarative/qml/qdeclarativeengine_p.h | 2 +- src/declarative/qml/qdeclarativeenginedebug.cpp | 6 +- src/declarative/qml/qdeclarativelist.cpp | 4 +- src/declarative/qml/qdeclarativemetaproperty.cpp | 1200 -------------------- src/declarative/qml/qdeclarativemetaproperty.h | 133 --- src/declarative/qml/qdeclarativemetaproperty_p.h | 140 --- src/declarative/qml/qdeclarativemetatype.cpp | 2 +- .../qml/qdeclarativeobjectscriptclass.cpp | 4 +- src/declarative/qml/qdeclarativeproperty.cpp | 1200 ++++++++++++++++++++ src/declarative/qml/qdeclarativeproperty.h | 133 +++ src/declarative/qml/qdeclarativeproperty_p.h | 140 +++ .../qml/qdeclarativepropertyvalueinterceptor.cpp | 2 +- .../qml/qdeclarativepropertyvalueinterceptor.h | 4 +- .../qml/qdeclarativepropertyvaluesource.cpp | 2 +- .../qml/qdeclarativepropertyvaluesource.h | 4 +- src/declarative/qml/qdeclarativevaluetype.cpp | 18 +- src/declarative/qml/qdeclarativevaluetype_p.h | 24 +- src/declarative/qml/qdeclarativevme.cpp | 22 +- src/declarative/qml/qdeclarativevmemetaobject.cpp | 2 +- src/declarative/qml/qml.pri | 6 +- src/declarative/util/qdeclarativeanimation.cpp | 36 +- src/declarative/util/qdeclarativeanimation_p.h | 18 +- src/declarative/util/qdeclarativeanimation_p_p.h | 4 +- src/declarative/util/qdeclarativebehavior.cpp | 12 +- src/declarative/util/qdeclarativebehavior_p.h | 2 +- src/declarative/util/qdeclarativebind.cpp | 4 +- src/declarative/util/qdeclarativeeasefollow.cpp | 6 +- src/declarative/util/qdeclarativeeasefollow_p.h | 4 +- .../util/qdeclarativepropertychanges.cpp | 30 +- src/declarative/util/qdeclarativespringfollow.cpp | 4 +- src/declarative/util/qdeclarativespringfollow_p.h | 2 +- src/declarative/util/qdeclarativestate.cpp | 6 +- src/declarative/util/qdeclarativestate_p.h | 4 +- src/declarative/util/qdeclarativestate_p_p.h | 8 +- .../util/qdeclarativestateoperations.cpp | 8 +- src/declarative/util/qdeclarativetransition.cpp | 2 +- src/declarative/util/qdeclarativetransition_p.h | 2 +- .../util/qdeclarativetransitionmanager.cpp | 22 +- tests/auto/declarative/declarative.pro | 2 +- .../qdeclarativedebug/tst_qdeclarativedebug.cpp | 6 +- .../declarative/qdeclarativelanguage/testtypes.h | 6 +- .../tst_qdeclarativelanguage.cpp | 10 +- .../tst_qdeclarativelistreference.cpp | 12 +- .../qdeclarativemetaproperty.pro | 5 - .../tst_qdeclarativemetaproperty.cpp | 1186 ------------------- .../tst_qdeclarativemetatype.cpp | 4 +- .../qdeclarativeproperty/qdeclarativeproperty.pro | 5 + .../tst_qdeclarativeproperty.cpp | 1186 +++++++++++++++++++ .../declarative/qdeclarativevaluetypes/testtypes.h | 12 +- 58 files changed, 2868 insertions(+), 2869 deletions(-) delete mode 100644 src/declarative/qml/qdeclarativemetaproperty.cpp delete mode 100644 src/declarative/qml/qdeclarativemetaproperty.h delete mode 100644 src/declarative/qml/qdeclarativemetaproperty_p.h create mode 100644 src/declarative/qml/qdeclarativeproperty.cpp create mode 100644 src/declarative/qml/qdeclarativeproperty.h create mode 100644 src/declarative/qml/qdeclarativeproperty_p.h delete mode 100644 tests/auto/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro delete mode 100644 tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp create mode 100644 tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro create mode 100644 tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index b378db2..ab5022b 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -607,11 +607,11 @@ void QDeclarativeGridViewPrivate::createHighlight() item->setParent(q->viewport()); highlight = new FxGridItem(item, q); highlightXAnimator = new QDeclarativeEaseFollow(q); - highlightXAnimator->setTarget(QDeclarativeMetaProperty(highlight->item, QLatin1String("x"))); + highlightXAnimator->setTarget(QDeclarativeProperty(highlight->item, QLatin1String("x"))); highlightXAnimator->setDuration(150); highlightXAnimator->setEnabled(autoHighlight); highlightYAnimator = new QDeclarativeEaseFollow(q); - highlightYAnimator->setTarget(QDeclarativeMetaProperty(highlight->item, QLatin1String("y"))); + highlightYAnimator->setTarget(QDeclarativeProperty(highlight->item, QLatin1String("y"))); highlightYAnimator->setDuration(150); highlightYAnimator->setEnabled(autoHighlight); changed = true; diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index bd2f4fc..e6b6f2a 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -804,13 +804,13 @@ void QDeclarativeListViewPrivate::createHighlight() highlight->item->setWidth(currentItem->item->width()); const QLatin1String posProp(orient == QDeclarativeListView::Vertical ? "y" : "x"); highlightPosAnimator = new QDeclarativeEaseFollow(q); - highlightPosAnimator->setTarget(QDeclarativeMetaProperty(highlight->item, posProp)); + highlightPosAnimator->setTarget(QDeclarativeProperty(highlight->item, posProp)); highlightPosAnimator->setVelocity(highlightMoveSpeed); highlightPosAnimator->setEnabled(autoHighlight); const QLatin1String sizeProp(orient == QDeclarativeListView::Vertical ? "height" : "width"); highlightSizeAnimator = new QDeclarativeEaseFollow(q); highlightSizeAnimator->setVelocity(highlightResizeSpeed); - highlightSizeAnimator->setTarget(QDeclarativeMetaProperty(highlight->item, sizeProp)); + highlightSizeAnimator->setTarget(QDeclarativeProperty(highlight->item, sizeProp)); highlightSizeAnimator->setEnabled(autoHighlight); changed = true; } diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 720c562..cecca65 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -97,7 +97,7 @@ QDeclarativeBinding::~QDeclarativeBinding() { } -void QDeclarativeBinding::setTarget(const QDeclarativeMetaProperty &prop) +void QDeclarativeBinding::setTarget(const QDeclarativeProperty &prop) { Q_D(QDeclarativeBinding); d->bindingData()->property = prop; @@ -105,13 +105,13 @@ void QDeclarativeBinding::setTarget(const QDeclarativeMetaProperty &prop) update(); } -QDeclarativeMetaProperty QDeclarativeBinding::property() const +QDeclarativeProperty QDeclarativeBinding::property() const { Q_D(const QDeclarativeBinding); return d->bindingData()->property; } -void QDeclarativeBinding::update(QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) { Q_D(QDeclarativeBinding); @@ -161,7 +161,7 @@ void QDeclarativeBinding::update(QDeclarativeMetaPropertyPrivate::WriteFlags fla data->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + QLatin1String(QMetaType::typeName(data->property.propertyType()))); } else if (!isUndefined && data->property.object() && - !QDeclarativeMetaPropertyPrivate::write(data->property, value, flags)) { + !QDeclarativePropertyPrivate::write(data->property, value, flags)) { QUrl url = QUrl(data->url); int line = data->line; @@ -204,7 +204,7 @@ void QDeclarativeBindingPrivate::emitValueChanged() q->update(); } -void QDeclarativeBinding::setEnabled(bool e, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteFlags flags) { Q_D(QDeclarativeBinding); d->bindingData()->enabled = e; @@ -300,7 +300,7 @@ QString QDeclarativeAbstractBinding::expression() const return QLatin1String(""); } -void QDeclarativeAbstractBinding::setEnabled(bool e, QDeclarativeMetaPropertyPrivate::WriteFlags) +void QDeclarativeAbstractBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteFlags) { if (e) m_mePtr = 0; } diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h index ac174fa..f66b9c7 100644 --- a/src/declarative/qml/qdeclarativebinding_p.h +++ b/src/declarative/qml/qdeclarativebinding_p.h @@ -56,8 +56,8 @@ #include "qdeclarative.h" #include "qdeclarativepropertyvaluesource.h" #include "qdeclarativeexpression.h" -#include "qdeclarativemetaproperty.h" -#include "qdeclarativemetaproperty_p.h" +#include "qdeclarativeproperty.h" +#include "qdeclarativeproperty_p.h" #include #include @@ -74,12 +74,12 @@ public: virtual QString expression() const; - void setEnabled(bool e) { setEnabled(e, QDeclarativeMetaPropertyPrivate::DontRemoveBinding); } - virtual void setEnabled(bool, QDeclarativeMetaPropertyPrivate::WriteFlags) = 0; + void setEnabled(bool e) { setEnabled(e, QDeclarativePropertyPrivate::DontRemoveBinding); } + virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags) = 0; virtual int propertyIndex() = 0; - void update() { update(QDeclarativeMetaPropertyPrivate::DontRemoveBinding); } - virtual void update(QDeclarativeMetaPropertyPrivate::WriteFlags) = 0; + void update() { update(QDeclarativePropertyPrivate::DontRemoveBinding); } + virtual void update(QDeclarativePropertyPrivate::WriteFlags) = 0; void addToObject(QObject *); void removeFromObject(); @@ -89,8 +89,8 @@ protected: private: friend class QDeclarativeDeclarativeData; - friend class QDeclarativeMetaProperty; - friend class QDeclarativeMetaPropertyPrivate; + friend class QDeclarativeProperty; + friend class QDeclarativePropertyPrivate; friend class QDeclarativeVME; QObject *m_object; @@ -110,19 +110,19 @@ public: QObject *parent); ~QDeclarativeBinding(); - void setTarget(const QDeclarativeMetaProperty &); - QDeclarativeMetaProperty property() const; + void setTarget(const QDeclarativeProperty &); + QDeclarativeProperty property() const; bool enabled() const; // Inherited from QDeclarativeAbstractBinding - virtual void setEnabled(bool, QDeclarativeMetaPropertyPrivate::WriteFlags flags); + virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags flags); virtual int propertyIndex(); - virtual void update(QDeclarativeMetaPropertyPrivate::WriteFlags flags); + virtual void update(QDeclarativePropertyPrivate::WriteFlags flags); virtual QString expression() const; public Q_SLOTS: - void update() { update(QDeclarativeMetaPropertyPrivate::DontRemoveBinding); } + void update() { update(QDeclarativePropertyPrivate::DontRemoveBinding); } protected: void emitValueChanged(); diff --git a/src/declarative/qml/qdeclarativebinding_p_p.h b/src/declarative/qml/qdeclarativebinding_p_p.h index ac88400..041103c 100644 --- a/src/declarative/qml/qdeclarativebinding_p_p.h +++ b/src/declarative/qml/qdeclarativebinding_p_p.h @@ -55,7 +55,7 @@ #include "qdeclarativebinding_p.h" -#include "qdeclarativemetaproperty.h" +#include "qdeclarativeproperty.h" #include "qdeclarativeexpression_p.h" QT_BEGIN_NAMESPACE @@ -69,7 +69,7 @@ public: bool updating:1; bool enabled:1; - QDeclarativeMetaProperty property; + QDeclarativeProperty property; virtual void refresh(); }; diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index a88f02e..17937fd 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -109,9 +109,9 @@ public: scope(0), target(0), parent(0) {} // Inherited from QDeclarativeAbstractBinding - virtual void setEnabled(bool, QDeclarativeMetaPropertyPrivate::WriteFlags flags); + virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags flags); virtual int propertyIndex(); - virtual void update(QDeclarativeMetaPropertyPrivate::WriteFlags flags); + virtual void update(QDeclarativePropertyPrivate::WriteFlags flags); virtual void destroy(); int index:30; @@ -244,7 +244,7 @@ QDeclarativeAbstractBinding *QDeclarativeCompiledBindings::configBinding(int ind return rv; } -void QDeclarativeCompiledBindingsPrivate::Binding::setEnabled(bool e, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeCompiledBindingsPrivate::Binding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteFlags flags) { if (e) { addToObject(target); @@ -267,7 +267,7 @@ int QDeclarativeCompiledBindingsPrivate::Binding::propertyIndex() return property & 0xFFFF; } -void QDeclarativeCompiledBindingsPrivate::Binding::update(QDeclarativeMetaPropertyPrivate::WriteFlags) +void QDeclarativeCompiledBindingsPrivate::Binding::update(QDeclarativePropertyPrivate::WriteFlags) { parent->run(this); } @@ -324,7 +324,7 @@ void QDeclarativeCompiledBindingsPrivate::run(Binding *binding) run(binding->index, cp, binding, binding->scope, target); vt->write(binding->target, binding->property & 0xFFFF, - QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::DontRemoveBinding); } else { run(binding->index, cp, binding, binding->scope, binding->target); } @@ -1701,7 +1701,7 @@ bool QDeclarativeBindingCompilerPrivate::compile(QDeclarativeJS::AST::Node *node const QMetaObject *from = type.metaObject; const QMetaObject *to = engine->rawMetaObjectForType(destination->type); - if (QDeclarativeMetaPropertyPrivate::canConvert(from, to)) + if (QDeclarativePropertyPrivate::canConvert(from, to)) type.type = destination->type; } diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 9ac65f9..9dc090b 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -58,7 +58,7 @@ #include "parser/qdeclarativejsast_p.h" #include "qdeclarativevmemetaobject_p.h" #include "qdeclarativeexpression_p.h" -#include "qdeclarativemetaproperty_p.h" +#include "qdeclarativeproperty_p.h" #include "qdeclarativerewrite_p.h" #include "qdeclarativescriptstring.h" #include "qdeclarativeglobal_p.h" @@ -2036,7 +2036,7 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro if (propertyMetaObject) { const QMetaObject *c = v->object->metatype; while(c) { - isAssignable |= (QDeclarativeMetaPropertyPrivate::equal(c, propertyMetaObject)); + isAssignable |= (QDeclarativePropertyPrivate::equal(c, propertyMetaObject)); c = c->superClass(); } } @@ -2619,7 +2619,7 @@ int QDeclarativeCompiler::genValueTypeData(QDeclarativeParser::Property *valueTy QDeclarativeParser::Property *prop) { QByteArray data = - QDeclarativeMetaPropertyPrivate::saveValueType(prop->parent->metaObject(), prop->index, + QDeclarativePropertyPrivate::saveValueType(prop->parent->metaObject(), prop->index, QDeclarativeEnginePrivate::get(engine)->valueTypes[prop->type]->metaObject(), valueTypeProp->index); // valueTypeProp->index, valueTypeProp->type); @@ -2629,7 +2629,7 @@ int QDeclarativeCompiler::genValueTypeData(QDeclarativeParser::Property *valueTy int QDeclarativeCompiler::genPropertyData(QDeclarativeParser::Property *prop) { - return output->indexForByteArray(QDeclarativeMetaPropertyPrivate::saveProperty(prop->parent->metaObject(), prop->index)); + return output->indexForByteArray(QDeclarativePropertyPrivate::saveProperty(prop->parent->metaObject(), prop->index)); } bool QDeclarativeCompiler::completeComponentBuild() @@ -2735,7 +2735,7 @@ bool QDeclarativeCompiler::canCoerce(int to, QDeclarativeParser::Object *from) const QMetaObject *fromMo = from->metaObject(); while (fromMo) { - if (QDeclarativeMetaPropertyPrivate::equal(fromMo, toMo)) + if (QDeclarativePropertyPrivate::equal(fromMo, toMo)) return true; fromMo = fromMo->superClass(); } @@ -2754,7 +2754,7 @@ bool QDeclarativeCompiler::canCoerce(int to, int from) QDeclarativeEnginePrivate::get(engine)->rawMetaObjectForType(from); while (fromMo) { - if (QDeclarativeMetaPropertyPrivate::equal(fromMo, toMo)) + if (QDeclarativePropertyPrivate::equal(fromMo, toMo)) return true; fromMo = fromMo->superClass(); } diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index aaf36e0..fe63ad2 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -698,8 +698,8 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri state->bindValues.at(ii); for (int jj = 0; jj < bv.count; ++jj) { if(bv.at(jj)) - bv.at(jj)->setEnabled(true, QDeclarativeMetaPropertyPrivate::BypassInterceptor | - QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + bv.at(jj)->setEnabled(true, QDeclarativePropertyPrivate::BypassInterceptor | + QDeclarativePropertyPrivate::DontRemoveBinding); } QDeclarativeEnginePrivate::clear(bv); } diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 4435a5b..8abea4e 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -49,7 +49,6 @@ #include "qdeclarativecontext.h" #include "qdeclarativeexpression.h" #include "qdeclarativecomponent.h" -#include "qdeclarativemetaproperty_p.h" #include "qdeclarativebinding_p_p.h" #include "qdeclarativevme_p.h" #include "qdeclarativeenginedebug_p.h" @@ -110,7 +109,7 @@ #define CSIDL_APPDATA 0x001a // \Application Data #endif -Q_DECLARE_METATYPE(QDeclarativeMetaProperty) +Q_DECLARE_METATYPE(QDeclarativeProperty) QT_BEGIN_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index c4a40c5..2364315 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -62,7 +62,7 @@ #include "qdeclarativevaluetype_p.h" #include "qdeclarativecontext.h" #include "qdeclarativeexpression.h" -#include "qdeclarativemetaproperty_p.h" +#include "qdeclarativeproperty_p.h" #include "qdeclarativepropertycache_p.h" #include "qdeclarativeobjectscriptclass_p.h" #include "qdeclarativecontextscriptclass_p.h" diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 2ae0b54..09882cb 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -44,8 +44,8 @@ #include "qdeclarativeboundsignal_p.h" #include "qdeclarativeengine.h" #include "qdeclarativemetatype_p.h" -#include "qdeclarativemetaproperty.h" -#include "qdeclarativemetaproperty_p.h" +#include "qdeclarativeproperty.h" +#include "qdeclarativeproperty_p.h" #include "qdeclarativebinding_p.h" #include "qdeclarativecontext_p.h" #include "qdeclarativewatcher_p.h" @@ -110,7 +110,7 @@ QDeclarativeEngineDebugServer::propertyData(QObject *obj, int propIdx) rv.name = QString::fromUtf8(prop.name()); rv.hasNotifySignal = prop.hasNotifySignal(); QDeclarativeAbstractBinding *binding = - QDeclarativeMetaPropertyPrivate::binding(QDeclarativeMetaProperty(obj, rv.name)); + QDeclarativePropertyPrivate::binding(QDeclarativeProperty(obj, rv.name)); if (binding) rv.binding = binding->expression(); diff --git a/src/declarative/qml/qdeclarativelist.cpp b/src/declarative/qml/qdeclarativelist.cpp index 4c9586c..af720d7 100644 --- a/src/declarative/qml/qdeclarativelist.cpp +++ b/src/declarative/qml/qdeclarativelist.cpp @@ -42,7 +42,7 @@ #include "qdeclarativelist.h" #include "qdeclarativelist_p.h" #include "qdeclarativeengine_p.h" -#include "qdeclarativemetaproperty_p.h" +#include "qdeclarativeproperty_p.h" QT_BEGIN_NAMESPACE @@ -174,7 +174,7 @@ bool QDeclarativeListReference::append(QObject *o) const { if (!canAppend()) return false; - if (o && !QDeclarativeMetaPropertyPrivate::canConvert(o->metaObject(), d->elementType)) + if (o && !QDeclarativePropertyPrivate::canConvert(o->metaObject(), d->elementType)) return false; d->property.append(&d->property, o); diff --git a/src/declarative/qml/qdeclarativemetaproperty.cpp b/src/declarative/qml/qdeclarativemetaproperty.cpp deleted file mode 100644 index a976140..0000000 --- a/src/declarative/qml/qdeclarativemetaproperty.cpp +++ /dev/null @@ -1,1200 +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$ -** -****************************************************************************/ - -#include "qdeclarativemetaproperty.h" -#include "qdeclarativemetaproperty_p.h" - -#include "qdeclarativecompositetypedata_p.h" -#include "qdeclarative.h" -#include "qdeclarativebinding_p.h" -#include "qdeclarativecontext.h" -#include "qdeclarativecontext_p.h" -#include "qdeclarativeboundsignal_p.h" -#include "qdeclarativeengine.h" -#include "qdeclarativeengine_p.h" -#include "qdeclarativedeclarativedata_p.h" -#include "qdeclarativestringconverters_p.h" -#include "qdeclarativelist_p.h" - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QDeclarativeMetaProperty - \brief The QDeclarativeMetaProperty class abstracts accessing QML properties. - \internal - */ - -/*! - Create an invalid QDeclarativeMetaProperty. -*/ -QDeclarativeMetaProperty::QDeclarativeMetaProperty() -: d(new QDeclarativeMetaPropertyPrivate) -{ - d->q = this; -} - -/*! \internal */ -QDeclarativeMetaProperty::~QDeclarativeMetaProperty() -{ - delete d; d = 0; -} - -/*! - Creates a QDeclarativeMetaProperty for the default property of \a obj. If there is no - default property, an invalid QDeclarativeMetaProperty will be created. - */ -QDeclarativeMetaProperty::QDeclarativeMetaProperty(QObject *obj) -: d(new QDeclarativeMetaPropertyPrivate) -{ - d->q = this; - d->initDefault(obj); -} - -/*! - \internal - Creates a QDeclarativeMetaProperty for the default property of \a obj. If there is no - default property, an invalid QDeclarativeMetaProperty will be created. - */ -QDeclarativeMetaProperty::QDeclarativeMetaProperty(QObject *obj, QDeclarativeContext *ctxt) -: d(new QDeclarativeMetaPropertyPrivate) -{ - d->q = this; - d->context = ctxt; - d->initDefault(obj); -} - -/*! - Initialize from the default property of \a obj -*/ -void QDeclarativeMetaPropertyPrivate::initDefault(QObject *obj) -{ - if (!obj) - return; - - QMetaProperty p = QDeclarativeMetaType::defaultProperty(obj); - core.load(p); - if (core.isValid()) { - isDefaultProperty = true; - object = obj; - } -} - -/*! - Creates a QDeclarativeMetaProperty for the property \a name of \a obj. - */ -QDeclarativeMetaProperty::QDeclarativeMetaProperty(QObject *obj, const QString &name) -: d(new QDeclarativeMetaPropertyPrivate) -{ - d->q = this; - d->initProperty(obj, name); - if (!isValid()) d->object = 0; -} - -/*! - \internal - Creates a QDeclarativeMetaProperty for the property \a name of \a obj. - */ -QDeclarativeMetaProperty::QDeclarativeMetaProperty(QObject *obj, const QString &name, QDeclarativeContext *ctxt) -: d(new QDeclarativeMetaPropertyPrivate) -{ - d->q = this; - d->context = ctxt; - d->initProperty(obj, name); - if (!isValid()) { d->object = 0; d->context = 0; } -} - -Q_GLOBAL_STATIC(QDeclarativeValueTypeFactory, qmlValueTypes); - -void QDeclarativeMetaPropertyPrivate::initProperty(QObject *obj, const QString &name) -{ - if (!obj) return; - - QDeclarativeEngine *engine = context?context->engine():0; - QDeclarativeTypeNameCache *typeNameCache = context?QDeclarativeContextPrivate::get(context)->imports:0; - - QStringList path = name.split(QLatin1Char('.')); - if (path.isEmpty()) return; - - QObject *currentObject = obj; - - // Everything up to the last property must be an "object type" property - for (int ii = 0; ii < path.count() - 1; ++ii) { - const QString &pathName = path.at(ii); - - if (QDeclarativeTypeNameCache::Data *data = typeNameCache?typeNameCache->data(pathName):0) { - if (data->type) { - QDeclarativeAttachedPropertiesFunc func = data->type->attachedPropertiesFunction(); - if (!func) return; // Not an attachable type - - currentObject = qmlAttachedPropertiesObjectById(data->type->index(), currentObject); - if (!currentObject) return; // Something is broken with the attachable type - } else { - Q_ASSERT(data->typeNamespace); - if ((ii + 1) == path.count()) return; // No type following the namespace - - ++ii; data = data->typeNamespace->data(path.at(ii)); - if (!data || !data->type) return; // Invalid type in namespace - - QDeclarativeAttachedPropertiesFunc func = data->type->attachedPropertiesFunction(); - if (!func) return; // Not an attachable type - - currentObject = qmlAttachedPropertiesObjectById(data->type->index(), currentObject); - if (!currentObject) return; // Something is broken with the attachable type - } - } else { - - QDeclarativePropertyCache::Data local; - QDeclarativePropertyCache::Data *property = - QDeclarativePropertyCache::property(engine, obj, pathName, local); - - if (!property) return; // Not a property - if (property->flags & QDeclarativePropertyCache::Data::IsFunction) - return; // Not an object property - - if (ii == (path.count() - 2) && property->propType < (int)QVariant::UserType) { - // We're now at a value type property. We can use a global valuetypes array as we - // never actually use the objects, just look up their properties. - QObject *typeObject = qmlValueTypes()->valueTypes[property->propType]; - if (!typeObject) return; // Not a value type - - int idx = typeObject->metaObject()->indexOfProperty(path.last().toUtf8().constData()); - if (idx == -1) return; // Value type property does not exist - - QMetaProperty vtProp = typeObject->metaObject()->property(idx); - - object = currentObject; - core = *property; - valueType.flags = QDeclarativePropertyCache::Data::flagsForProperty(vtProp); - valueType.valueTypeCoreIdx = idx; - valueType.valueTypePropType = vtProp.userType(); - - return; - } else { - if (!(property->flags & QDeclarativePropertyCache::Data::IsQObjectDerived)) - return; // Not an object property - - void *args[] = { ¤tObject, 0 }; - QMetaObject::metacall(currentObject, QMetaObject::ReadProperty, property->coreIndex, args); - if (!currentObject) return; // No value - - } - } - - } - - const QString &terminal = path.last(); - - if (terminal.count() >= 3 && - terminal.at(0) == QLatin1Char('o') && - terminal.at(1) == QLatin1Char('n') && - terminal.at(2).isUpper()) { - - QString signalName = terminal.mid(2); - signalName[0] = signalName.at(0).toLower(); - - QMetaMethod method = findSignal(currentObject, signalName); - if (method.signature()) { - object = currentObject; - core.load(method); - return; - } - } - - // Property - QDeclarativePropertyCache::Data local; - QDeclarativePropertyCache::Data *property = - QDeclarativePropertyCache::property(context?context->engine():0, currentObject, terminal, local); - if (property && !(property->flags & QDeclarativePropertyCache::Data::IsFunction)) { - object = currentObject; - core = *property; - } -} - -/*! - Create a copy of \a other. -*/ -QDeclarativeMetaProperty::QDeclarativeMetaProperty(const QDeclarativeMetaProperty &other) -: d(new QDeclarativeMetaPropertyPrivate(*other.d)) -{ - d->q = this; -} - -/*! - \enum QDeclarativeMetaProperty::PropertyTypeCategory - - This enum specifies a category of QML property. - - \value InvalidCategory The property is invalid. - \value List The property is a QList pointer - \value Object The property is a QObject derived type pointer - \value Normal The property is none of the above. - */ - -/*! - \enum QDeclarativeMetaProperty::Type - - This enum specifies a type of QML property. - - \value Invalid The property is invalid. - \value Property The property is a regular Qt property. - \value SignalProperty The property is a signal property. - \value Default The property is the default property. -*/ - -/*! - Returns the property category. -*/ -QDeclarativeMetaProperty::PropertyTypeCategory QDeclarativeMetaProperty::propertyTypeCategory() const -{ - return d->propertyTypeCategory(); -} - -QDeclarativeMetaProperty::PropertyTypeCategory -QDeclarativeMetaPropertyPrivate::propertyTypeCategory() const -{ - uint type = q->type(); - - if (type & QDeclarativeMetaProperty::ValueTypeProperty) { - return QDeclarativeMetaProperty::Normal; - } else if (type & QDeclarativeMetaProperty::Property) { - int type = propertyType(); - if (type == QVariant::Invalid) - return QDeclarativeMetaProperty::InvalidCategory; - else if ((uint)type < QVariant::UserType) - return QDeclarativeMetaProperty::Normal; - else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) - return QDeclarativeMetaProperty::Object; - else if (core.flags & QDeclarativePropertyCache::Data::IsQList) - return QDeclarativeMetaProperty::List; - else - return QDeclarativeMetaProperty::Normal; - } else { - return QDeclarativeMetaProperty::InvalidCategory; - } -} - -/*! - Returns the type name of the property, or 0 if the property has no type - name. -*/ -const char *QDeclarativeMetaProperty::propertyTypeName() const -{ - if (type() & ValueTypeProperty) { - - QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->context); - QDeclarativeValueType *valueType = 0; - if (ep) valueType = ep->valueTypes[d->core.propType]; - else valueType = QDeclarativeValueTypeFactory::valueType(d->core.propType); - Q_ASSERT(valueType); - - const char *rv = valueType->metaObject()->property(d->valueType.valueTypeCoreIdx).typeName(); - - if (!ep) delete valueType; - - return rv; - } else if (d->object && type() & Property && d->core.isValid()) { - return d->object->metaObject()->property(d->core.coreIndex).typeName(); - } else { - return 0; - } -} - -/*! - Returns true if \a other and this QDeclarativeMetaProperty represent the same - property. -*/ -bool QDeclarativeMetaProperty::operator==(const QDeclarativeMetaProperty &other) const -{ - // category is intentially omitted here as it is generated - // from the other members - return d->object == other.d->object && - d->core == other.d->core && - d->valueType == other.d->valueType; -} - -/*! - Returns the QVariant type of the property, or QVariant::Invalid if the - property has no QVariant type. -*/ -int QDeclarativeMetaProperty::propertyType() const -{ - return d->propertyType(); -} - -int QDeclarativeMetaPropertyPrivate::propertyType() const -{ - uint type = q->type(); - if (type & QDeclarativeMetaProperty::ValueTypeProperty) { - return valueType.valueTypePropType; - } else if (type & QDeclarativeMetaProperty::Property) { - if (core.propType == (int)QVariant::LastType) - return qMetaTypeId(); - else - return core.propType; - } else { - return QVariant::Invalid; - } -} - -/*! - Returns the type of the property. -*/ -QDeclarativeMetaProperty::Type QDeclarativeMetaProperty::type() const -{ - if (d->core.flags & QDeclarativePropertyCache::Data::IsFunction) - return SignalProperty; - else if (d->valueType.valueTypeCoreIdx != -1) - return (Type)(Property | ValueTypeProperty); - else if (d->core.isValid()) - return (Type)(Property | ((d->isDefaultProperty)?Default:0)); - else - return Invalid; -} - -/*! - Returns true if this QDeclarativeMetaProperty represents a regular Qt property. -*/ -bool QDeclarativeMetaProperty::isProperty() const -{ - return type() & Property; -} - -/*! - Returns true if this QDeclarativeMetaProperty represents a default property. -*/ -bool QDeclarativeMetaProperty::isDefault() const -{ - return type() & Default; -} - -/*! - Returns the QDeclarativeMetaProperty's QObject. -*/ -QObject *QDeclarativeMetaProperty::object() const -{ - return d->object; -} - -/*! - Assign \a other to this QDeclarativeMetaProperty. -*/ -QDeclarativeMetaProperty &QDeclarativeMetaProperty::operator=(const QDeclarativeMetaProperty &other) -{ - d->context = other.d->context; - d->object = other.d->object; - - d->isDefaultProperty = other.d->isDefaultProperty; - d->isNameCached = other.d->isNameCached; - d->core = other.d->core; - d->nameCache = other.d->nameCache; - - d->valueType = other.d->valueType; - - return *this; -} - -/*! - Returns true if the property is writable, otherwise false. -*/ -bool QDeclarativeMetaProperty::isWritable() const -{ - QDeclarativeMetaProperty::PropertyTypeCategory category = propertyTypeCategory(); - - if (!d->object) - return false; - if (category == List) - return true; - else if (type() & SignalProperty) - return false; - else if (d->core.isValid() && d->object) - return d->core.flags & QDeclarativePropertyCache::Data::IsWritable; - else - return false; -} - -/*! - Returns true if the property is designable, otherwise false. -*/ -bool QDeclarativeMetaProperty::isDesignable() const -{ - if (type() & Property && d->core.isValid() && d->object) - return d->object->metaObject()->property(d->core.coreIndex).isDesignable(); - else - return false; -} - -/*! - Returns true if the property is resettable, otherwise false. -*/ -bool QDeclarativeMetaProperty::isResettable() const -{ - if (type() & Property && d->core.isValid() && d->object) - return d->core.flags & QDeclarativePropertyCache::Data::IsResettable; - else - return false; -} - -/*! - Returns true if the QDeclarativeMetaProperty refers to a valid property, otherwise - false. -*/ -bool QDeclarativeMetaProperty::isValid() const -{ - return type() != Invalid; -} - -/*! - Return the name of this QML property. -*/ -QString QDeclarativeMetaProperty::name() const -{ - if (!d->isNameCached) { - // ### - if (!d->object) { - } else if (type() & ValueTypeProperty) { - QString rv = d->core.name(d->object) + QLatin1Char('.'); - - QDeclarativeEnginePrivate *ep = d->context?QDeclarativeEnginePrivate::get(d->context->engine()):0; - QDeclarativeValueType *valueType = 0; - if (ep) valueType = ep->valueTypes[d->core.propType]; - else valueType = QDeclarativeValueTypeFactory::valueType(d->core.propType); - Q_ASSERT(valueType); - - rv += QString::fromUtf8(valueType->metaObject()->property(d->valueType.valueTypeCoreIdx).name()); - - if (!ep) delete valueType; - - d->nameCache = rv; - } else if (type() & SignalProperty) { - QString name = QLatin1String("on") + d->core.name(d->object); - name[2] = name.at(2).toUpper(); - d->nameCache = name; - } else { - d->nameCache = d->core.name(d->object); - } - d->isNameCached = true; - } - - return d->nameCache; -} - -/*! - Returns the \l{QMetaProperty} {Qt property} associated with - this QML property. - */ -QMetaProperty QDeclarativeMetaProperty::property() const -{ - if (type() & Property && d->core.isValid() && d->object) - return d->object->metaObject()->property(d->core.coreIndex); - else - return QMetaProperty(); -} - -/*! - Return the QMetaMethod for this property if it is a SignalProperty, - otherwise returns an invalid QMetaMethod. -*/ -QMetaMethod QDeclarativeMetaProperty::method() const -{ - if (type() & SignalProperty && d->object) - return d->object->metaObject()->method(d->core.coreIndex); - else - return QMetaMethod(); -} - - -/*! - Returns the binding associated with this property, or 0 if no binding - exists. -*/ -QDeclarativeAbstractBinding * -QDeclarativeMetaPropertyPrivate::binding(const QDeclarativeMetaProperty &that) -{ - if (!that.isProperty() || !that.d->object) - return 0; - - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(that.d->object); - if (!data) - return 0; - - if (!data->hasBindingBit(that.d->core.coreIndex)) - return 0; - - QDeclarativeAbstractBinding *binding = data->bindings; - while (binding) { - // ### This wont work for value types - if (binding->propertyIndex() == that.d->core.coreIndex) - return binding; - binding = binding->m_nextBinding; - } - return 0; -} - -/*! - Set the binding associated with this property to \a newBinding. Returns - the existing binding (if any), otherwise 0. - - \a newBinding will be enabled, and the returned binding (if any) will be - disabled. - - Ownership of \a newBinding transfers to QML. Ownership of the return value - is assumed by the caller. - - \a flags is passed through to the binding and is used for the initial update (when - the binding sets the intial value, it will use these flags for the write). -*/ -QDeclarativeAbstractBinding * -QDeclarativeMetaPropertyPrivate::setBinding(const QDeclarativeMetaProperty &that, - QDeclarativeAbstractBinding *newBinding, - WriteFlags flags) -{ - if (!that.isProperty() || !that.d->object) { - if (newBinding) - newBinding->destroy(); - return 0; - } - - return that.d->setBinding(that.d->object, that.d->core, newBinding, flags); -} - -QDeclarativeAbstractBinding * -QDeclarativeMetaPropertyPrivate::setBinding(QObject *object, const QDeclarativePropertyCache::Data &core, - QDeclarativeAbstractBinding *newBinding, WriteFlags flags) -{ - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, 0 != newBinding); - - if (data && data->hasBindingBit(core.coreIndex)) { - QDeclarativeAbstractBinding *binding = data->bindings; - while (binding) { - // ### This wont work for value types - if (binding->propertyIndex() == core.coreIndex) { - binding->setEnabled(false); - - if (newBinding) - newBinding->setEnabled(true, flags); - - return binding; // ### QDeclarativeAbstractBinding; - } - - binding = binding->m_nextBinding; - } - } - - if (newBinding) - newBinding->setEnabled(true, flags); - - return 0; -} - -/*! - Returns the expression associated with this signal property, or 0 if no - signal expression exists. -*/ -QDeclarativeExpression * -QDeclarativeMetaPropertyPrivate::signalExpression(const QDeclarativeMetaProperty &that) -{ - if (!(that.type() & QDeclarativeMetaProperty::SignalProperty)) - return 0; - - const QObjectList &children = that.d->object->children(); - - for (int ii = 0; ii < children.count(); ++ii) { - QObject *child = children.at(ii); - - QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); - if (signal && signal->index() == that.coreIndex()) - return signal->expression(); - } - - return 0; -} - -/*! - Set the signal expression associated with this signal property to \a expr. - Returns the existing signal expression (if any), otherwise 0. - - Ownership of \a expr transfers to QML. Ownership of the return value is - assumed by the caller. -*/ -QDeclarativeExpression * -QDeclarativeMetaPropertyPrivate::setSignalExpression(const QDeclarativeMetaProperty &that, - QDeclarativeExpression *expr) -{ - if (!(that.type() & QDeclarativeMetaProperty::SignalProperty)) { - delete expr; - return 0; - } - - const QObjectList &children = that.d->object->children(); - - for (int ii = 0; ii < children.count(); ++ii) { - QObject *child = children.at(ii); - - QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); - if (signal && signal->index() == that.coreIndex()) - return signal->setExpression(expr); - } - - if (expr) { - QDeclarativeBoundSignal *signal = new QDeclarativeBoundSignal(that.d->object, that.method(), that.d->object); - return signal->setExpression(expr); - } else { - return 0; - } -} - -QMetaMethod QDeclarativeMetaPropertyPrivate::findSignal(QObject *obj, const QString &name) -{ - const QMetaObject *mo = obj->metaObject(); - - int methods = mo->methodCount(); - for (int ii = methods - 1; ii >= 0; --ii) { - QMetaMethod method = mo->method(ii); - QString methodName = QString::fromUtf8(method.signature()); - int idx = methodName.indexOf(QLatin1Char('(')); - methodName = methodName.left(idx); - - if (methodName == name) - return method; - } - return QMetaMethod(); -} - -/*! - Returns the property value. -*/ -QVariant QDeclarativeMetaProperty::read() const -{ - if (!d->object) - return QVariant(); - - if (type() & SignalProperty) { - - return QVariant(); - - } else if (type() & Property) { - - return d->readValueProperty(); - - } - return QVariant(); -} - -QVariant QDeclarativeMetaPropertyPrivate::readValueProperty() -{ - uint type = q->type(); - if(type & QDeclarativeMetaProperty::ValueTypeProperty) { - - QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); - QDeclarativeValueType *valueType = 0; - if (ep) valueType = ep->valueTypes[core.propType]; - else valueType = QDeclarativeValueTypeFactory::valueType(core.propType); - Q_ASSERT(valueType); - - valueType->read(object, core.coreIndex); - - QVariant rv = - valueType->metaObject()->property(this->valueType.valueTypeCoreIdx).read(valueType); - - if (!ep) delete valueType; - return rv; - - } else if(core.flags & QDeclarativePropertyCache::Data::IsQList) { - - QDeclarativeListProperty prop; - void *args[] = { &prop, 0 }; - QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args); - return QVariant::fromValue(QDeclarativeListReferencePrivate::init(prop, core.propType, context?context->engine():0)); - - } else { - - return object->metaObject()->property(core.coreIndex).read(object.data()); - - } -} - -//### -//writeEnumProperty MIRRORS the relelvant bit of QMetaProperty::write AND MUST BE KEPT IN SYNC! -//### -bool QDeclarativeMetaPropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, const QVariant &value, int flags) -{ - if (!object || !prop.isWritable()) - return false; - - QVariant v = value; - if (prop.isEnumType()) { - QMetaEnum menum = prop.enumerator(); - if (v.userType() == QVariant::String -#ifdef QT3_SUPPORT - || v.userType() == QVariant::CString -#endif - ) { - if (prop.isFlagType()) - v = QVariant(menum.keysToValue(value.toByteArray())); - else - v = QVariant(menum.keyToValue(value.toByteArray())); - } else if (v.userType() != QVariant::Int && v.userType() != QVariant::UInt) { - int enumMetaTypeId = QMetaType::type(QByteArray(menum.scope()) + "::" + menum.name()); - if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData()) - return false; - v = QVariant(*reinterpret_cast(v.constData())); - } - v.convert(QVariant::Int); - } - - // the status variable is changed by qt_metacall to indicate what it did - // this feature is currently only used by QtDBus and should not be depended - // upon. Don't change it without looking into QDBusAbstractInterface first - // -1 (unchanged): normal qt_metacall, result stored in argv[0] - // changed: result stored directly in value, return the value of status - int status = -1; - void *argv[] = { v.data(), &v, &status, &flags }; - QMetaObject::metacall(object, QMetaObject::WriteProperty, idx, argv); - return status; -} - -bool QDeclarativeMetaPropertyPrivate::writeValueProperty(const QVariant &value, WriteFlags flags) -{ - // Remove any existing bindings on this property - if (!(flags & DontRemoveBinding)) { - QDeclarativeAbstractBinding *binding = setBinding(*q, 0); - if (binding) binding->destroy(); - } - - bool rv = false; - uint type = q->type(); - if (type & QDeclarativeMetaProperty::ValueTypeProperty) { - QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); - - QDeclarativeValueType *writeBack = 0; - if (ep) { - writeBack = ep->valueTypes[core.propType]; - } else { - writeBack = QDeclarativeValueTypeFactory::valueType(core.propType); - } - - writeBack->read(object, core.coreIndex); - - QDeclarativePropertyCache::Data data = core; - data.flags = valueType.flags; - data.coreIndex = valueType.valueTypeCoreIdx; - data.propType = valueType.valueTypePropType; - rv = write(writeBack, data, value, context, flags); - - writeBack->write(object, core.coreIndex, flags); - if (!ep) delete writeBack; - - } else { - - rv = write(object, core, value, context, flags); - - } - - return rv; -} - -bool QDeclarativeMetaPropertyPrivate::write(QObject *object, const QDeclarativePropertyCache::Data &property, - const QVariant &value, QDeclarativeContext *context, - WriteFlags flags) -{ - int coreIdx = property.coreIndex; - int status = -1; //for dbus - - if (property.flags & QDeclarativePropertyCache::Data::IsEnumType) { - QMetaProperty prop = object->metaObject()->property(property.coreIndex); - QVariant v = value; - // Enum values come through the script engine as doubles - if (value.userType() == QVariant::Double) { - double integral; - double fractional = modf(value.toDouble(), &integral); - if (qFuzzyIsNull(fractional)) - v.convert(QVariant::Int); - } - return writeEnumProperty(prop, coreIdx, object, v, flags); - } - - int propertyType = property.propType; - int variantType = value.userType(); - - QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(context); - - if (propertyType == QVariant::Url) { - - QUrl u; - bool found = false; - if (variantType == QVariant::Url) { - u = value.toUrl(); - found = true; - } else if (variantType == QVariant::ByteArray) { - u = QUrl(QString::fromUtf8(value.toByteArray())); - found = true; - } else if (variantType == QVariant::String) { - u = QUrl(value.toString()); - found = true; - } - - if (!found) - return false; - - if (context && u.isRelative() && !u.isEmpty()) - u = context->resolvedUrl(u); - int status = -1; - void *argv[] = { &u, 0, &status, &flags }; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv); - - } else if (variantType == propertyType) { - - void *a[] = { (void *)value.constData(), 0, &status, &flags }; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - - } else if (qMetaTypeId() == propertyType) { - - void *a[] = { (void *)&value, 0, &status, &flags }; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - - } else if (property.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) { - - const QMetaObject *valMo = rawMetaObjectForType(enginePriv, value.userType()); - - if (!valMo) - return false; - - QObject *o = *(QObject **)value.constData(); - const QMetaObject *propMo = rawMetaObjectForType(enginePriv, propertyType); - - if (o) valMo = o->metaObject(); - - if (canConvert(valMo, propMo)) { - void *args[] = { &o, 0, &status, &flags }; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, - args); - } else if (!o && canConvert(propMo, valMo)) { - // In the case of a null QObject, we assign the null if there is - // any change that the null variant type could be up or down cast to - // the property type. - void *args[] = { &o, 0, &status, &flags }; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, - args); - } else { - return false; - } - - } else if (property.flags & QDeclarativePropertyCache::Data::IsQList) { - - const QMetaObject *listType = 0; - if (enginePriv) { - listType = enginePriv->rawMetaObjectForType(enginePriv->listType(property.propType)); - } else { - QDeclarativeType *type = QDeclarativeMetaType::qmlType(QDeclarativeMetaType::listType(property.propType)); - if (!type) return false; - listType = type->baseMetaObject(); - } - if (!listType) return false; - - QDeclarativeListProperty prop; - void *args[] = { &prop, 0 }; - QMetaObject::metacall(object, QMetaObject::ReadProperty, coreIdx, args); - - if (!prop.clear) return false; - - prop.clear(&prop); - - if (value.userType() == qMetaTypeId >()) { - const QList &list = qvariant_cast >(value); - - for (int ii = 0; ii < list.count(); ++ii) { - QObject *o = list.at(ii); - if (!canConvert(o->metaObject(), listType)) - o = 0; - prop.append(&prop, (void *)o); - } - } else { - QObject *o = enginePriv?enginePriv->toQObject(value):QDeclarativeMetaType::toQObject(value); - if (!canConvert(o->metaObject(), listType)) - o = 0; - prop.append(&prop, (void *)o); - } - - } else { - Q_ASSERT(variantType != propertyType); - - QVariant v = value; - if (v.convert((QVariant::Type)propertyType)) { - void *a[] = { (void *)v.constData(), 0, &status, &flags}; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - } else if ((uint)propertyType >= QVariant::UserType && variantType == QVariant::String) { - QDeclarativeMetaType::StringConverter con = QDeclarativeMetaType::customStringConverter(propertyType); - if (!con) - return false; - - QVariant v = con(value.toString()); - if (v.userType() == propertyType) { - void *a[] = { (void *)v.constData(), 0, &status, &flags}; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - } - } else if (variantType == QVariant::String) { - bool ok = false; - QVariant v = QDeclarativeStringConverters::variantFromString(value.toString(), propertyType, &ok); - if (!ok) - return false; - - void *a[] = { (void *)v.constData(), 0, &status, &flags}; - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - } else { - return false; - } - } - - return true; -} - -const QMetaObject *QDeclarativeMetaPropertyPrivate::rawMetaObjectForType(QDeclarativeEnginePrivate *engine, int userType) -{ - if (engine) { - return engine->rawMetaObjectForType(userType); - } else { - QDeclarativeType *type = QDeclarativeMetaType::qmlType(userType); - return type?type->baseMetaObject():0; - } -} - -/*! - Set the property value to \a value. -*/ -bool QDeclarativeMetaProperty::write(const QVariant &value) const -{ - return QDeclarativeMetaPropertyPrivate::write(*this, value, 0); -} - -/*! - Resets the property value. -*/ -bool QDeclarativeMetaProperty::reset() const -{ - if (isResettable()) { - void *args[] = { 0 }; - QMetaObject::metacall(d->object, QMetaObject::ResetProperty, d->core.coreIndex, args); - return true; - } else { - return false; - } -} - -bool QDeclarativeMetaPropertyPrivate::write(const QDeclarativeMetaProperty &that, - const QVariant &value, WriteFlags flags) -{ - if (that.d->object && that.type() & QDeclarativeMetaProperty::Property && - that.d->core.isValid() && that.isWritable()) - return that.d->writeValueProperty(value, flags); - else - return false; -} - -/*! - Returns true if the property has a change notifier signal, otherwise false. -*/ -bool QDeclarativeMetaProperty::hasChangedNotifier() const -{ - if (type() & Property && d->object) { - return d->object->metaObject()->property(d->core.coreIndex).hasNotifySignal(); - } - return false; -} - -/*! - Returns true if the property needs a change notifier signal for bindings - to remain upto date, false otherwise. - - Some properties, such as attached properties or those whose value never - changes, do not require a change notifier. -*/ -bool QDeclarativeMetaProperty::needsChangedNotifier() const -{ - return type() & Property && !property().isConstant(); -} - -/*! - Connects the property's change notifier signal to the - specified \a method of the \a dest object and returns - true. Returns false if this metaproperty does not - represent a regular Qt property or if it has no - change notifier signal, or if the \a dest object does - not have the specified \a method. -*/ -bool QDeclarativeMetaProperty::connectNotifier(QObject *dest, int method) const -{ - if (!(type() & Property) || !d->object) - return false; - - QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex); - if (prop.hasNotifySignal()) { - return QMetaObject::connect(d->object, prop.notifySignalIndex(), dest, method, Qt::DirectConnection); - } else { - return false; - } -} - -/*! - Connects the property's change notifier signal to the - specified \a slot of the \a dest object and returns - true. Returns false if this metaproperty does not - represent a regular Qt property or if it has no - change notifier signal, or if the \a dest object does - not have the specified \a slot. -*/ -bool QDeclarativeMetaProperty::connectNotifier(QObject *dest, const char *slot) const -{ - if (!(type() & Property) || !d->object) - return false; - - QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex); - if (prop.hasNotifySignal()) { - QByteArray signal(QByteArray("2") + prop.notifySignal().signature()); - return QObject::connect(d->object, signal.constData(), dest, slot); - } else { - return false; - } -} - -/*! - Return the Qt metaobject index of the property. -*/ -int QDeclarativeMetaProperty::coreIndex() const -{ - return d->core.coreIndex; -} - -int QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(const QDeclarativeMetaProperty &that) -{ - return that.d->valueType.valueTypeCoreIdx; -} - -struct SerializedData { - QDeclarativeMetaProperty::Type type; - QDeclarativePropertyCache::Data core; -}; - -struct ValueTypeSerializedData : public SerializedData { - QDeclarativePropertyCache::ValueTypeData valueType; -}; - -QByteArray QDeclarativeMetaPropertyPrivate::saveValueType(const QMetaObject *metaObject, int index, - const QMetaObject *subObject, int subIndex) -{ - QMetaProperty prop = metaObject->property(index); - QMetaProperty subProp = subObject->property(subIndex); - - ValueTypeSerializedData sd; - sd.type = QDeclarativeMetaProperty::ValueTypeProperty; - sd.core.load(metaObject->property(index)); - sd.valueType.flags = QDeclarativePropertyCache::Data::flagsForProperty(subProp); - sd.valueType.valueTypeCoreIdx = subIndex; - sd.valueType.valueTypePropType = subProp.userType(); - - QByteArray rv((const char *)&sd, sizeof(sd)); - - return rv; -} - -QByteArray QDeclarativeMetaPropertyPrivate::saveProperty(const QMetaObject *metaObject, int index) -{ - SerializedData sd; - sd.type = QDeclarativeMetaProperty::Property; - sd.core.load(metaObject->property(index)); - - QByteArray rv((const char *)&sd, sizeof(sd)); - return rv; -} - -QDeclarativeMetaProperty -QDeclarativeMetaPropertyPrivate::restore(const QByteArray &data, QObject *object, QDeclarativeContext *ctxt) -{ - QDeclarativeMetaProperty prop; - - if (data.isEmpty()) - return prop; - - prop.d->object = object; - prop.d->context = ctxt; - - const SerializedData *sd = (const SerializedData *)data.constData(); - if (sd->type == QDeclarativeMetaProperty::Property) { - prop.d->core = sd->core; - } else if(sd->type == QDeclarativeMetaProperty::ValueTypeProperty) { - const ValueTypeSerializedData *vt = (const ValueTypeSerializedData *)sd; - prop.d->core = vt->core; - prop.d->valueType = vt->valueType; - } - - return prop; -} - -/*! - Returns true if lhs and rhs refer to the same metaobject data -*/ -bool QDeclarativeMetaPropertyPrivate::equal(const QMetaObject *lhs, const QMetaObject *rhs) -{ - return lhs == rhs || (1 && lhs && rhs && lhs->d.stringdata == rhs->d.stringdata); -} - -/*! - Returns true if from inherits to. -*/ -bool QDeclarativeMetaPropertyPrivate::canConvert(const QMetaObject *from, const QMetaObject *to) -{ - if (from && to == &QObject::staticMetaObject) - return true; - - while (from) { - if (equal(from, to)) - return true; - from = from->superClass(); - } - - return false; -} - -QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativemetaproperty.h b/src/declarative/qml/qdeclarativemetaproperty.h deleted file mode 100644 index 828749f..0000000 --- a/src/declarative/qml/qdeclarativemetaproperty.h +++ /dev/null @@ -1,133 +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 QDECLARATIVEMETAPROPERTY_H -#define QDECLARATIVEMETAPROPERTY_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QObject; -class QDeclarativeAbstractBinding; -class QDeclarativeExpression; -class QStringList; -class QVariant; -struct QMetaObject; -class QDeclarativeContext; -class QDeclarativeEngine; - -class QDeclarativeMetaPropertyPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeMetaProperty -{ -public: - enum PropertyTypeCategory { - InvalidCategory, - List, - Object, - Normal - }; - - enum Type { Invalid = 0x00, - Property = 0x01, - SignalProperty = 0x02, - Default = 0x08, - ValueTypeProperty = 0x10 - }; - - QDeclarativeMetaProperty(); - ~QDeclarativeMetaProperty(); - - QDeclarativeMetaProperty(QObject *); - QDeclarativeMetaProperty(QObject *, QDeclarativeContext *); - - QDeclarativeMetaProperty(QObject *, const QString &); - QDeclarativeMetaProperty(QObject *, const QString &, QDeclarativeContext *); - - QDeclarativeMetaProperty(const QDeclarativeMetaProperty &); - QDeclarativeMetaProperty &operator=(const QDeclarativeMetaProperty &); - - QString name() const; - - QVariant read() const; - bool write(const QVariant &) const; - bool reset() const; - - bool hasChangedNotifier() const; - bool needsChangedNotifier() const; - bool connectNotifier(QObject *dest, const char *slot) const; - bool connectNotifier(QObject *dest, int method) const; - - Type type() const; - bool isProperty() const; - bool isDefault() const; - bool isWritable() const; - bool isDesignable() const; - bool isResettable() const; - bool isValid() const; - QObject *object() const; - - int propertyType() const; - PropertyTypeCategory propertyTypeCategory() const; - const char *propertyTypeName() const; - - bool operator==(const QDeclarativeMetaProperty &) const; - - int coreIndex() const; - QMetaProperty property() const; - QMetaMethod method() const; - -private: - friend class QDeclarativeEnginePrivate; - friend class QDeclarativeMetaPropertyPrivate; - QDeclarativeMetaPropertyPrivate *d; -}; -typedef QList QDeclarativeMetaProperties; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECLARATIVEMETAPROPERTY_H diff --git a/src/declarative/qml/qdeclarativemetaproperty_p.h b/src/declarative/qml/qdeclarativemetaproperty_p.h deleted file mode 100644 index a171545..0000000 --- a/src/declarative/qml/qdeclarativemetaproperty_p.h +++ /dev/null @@ -1,140 +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 QDECLARATIVEMETAPROPERTY_P_H -#define QDECLARATIVEMETAPROPERTY_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 "qdeclarativemetaproperty.h" - -#include "qdeclarativepropertycache_p.h" -#include "qdeclarativeguard_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeContext; -class QDeclarativeEnginePrivate; -class Q_AUTOTEST_EXPORT QDeclarativeMetaPropertyPrivate -{ -public: - enum WriteFlag { BypassInterceptor = 0x01, DontRemoveBinding = 0x02 }; - Q_DECLARE_FLAGS(WriteFlags, WriteFlag) - - QDeclarativeMetaPropertyPrivate() - : q(0), context(0), object(0), isDefaultProperty(false), isNameCached(false) {} - - - QDeclarativeMetaPropertyPrivate(const QDeclarativeMetaPropertyPrivate &other) - : q(0), context(other.context), object(other.object), - isDefaultProperty(other.isDefaultProperty), isNameCached(other.isNameCached), - core(other.core), nameCache(other.nameCache), - valueType(other.valueType) {} - - QDeclarativeMetaProperty *q; - QDeclarativeContext *context; - QDeclarativeGuard object; - - bool isDefaultProperty:1; - bool isNameCached:1; - QDeclarativePropertyCache::Data core; - QString nameCache; - - // Describes the "virtual" value-type sub-property. - QDeclarativePropertyCache::ValueTypeData valueType; - - void initProperty(QObject *obj, const QString &name); - void initDefault(QObject *obj); - - QMetaMethod findSignal(QObject *, const QString &); - - int propertyType() const; - QDeclarativeMetaProperty::PropertyTypeCategory propertyTypeCategory() const; - - QVariant readValueProperty(); - bool writeValueProperty(const QVariant &, WriteFlags); - - static const QMetaObject *rawMetaObjectForType(QDeclarativeEnginePrivate *, int); - static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, - const QVariant &value, int flags); - static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &, - QDeclarativeContext *, WriteFlags flags = 0); - static QDeclarativeAbstractBinding *setBinding(QObject *, const QDeclarativePropertyCache::Data &, - QDeclarativeAbstractBinding *, - WriteFlags flags = DontRemoveBinding); - - static QByteArray saveValueType(const QMetaObject *, int, - const QMetaObject *, int); - static QByteArray saveProperty(const QMetaObject *, int); - static QDeclarativeMetaProperty restore(const QByteArray &, QObject *, QDeclarativeContext *); - - static bool equal(const QMetaObject *, const QMetaObject *); - static bool canConvert(const QMetaObject *from, const QMetaObject *to); - - - // "Public" (to QML) methods - static QDeclarativeAbstractBinding *binding(const QDeclarativeMetaProperty &that); - static QDeclarativeAbstractBinding *setBinding(const QDeclarativeMetaProperty &that, - QDeclarativeAbstractBinding *, - WriteFlags flags = DontRemoveBinding); - static QDeclarativeExpression *signalExpression(const QDeclarativeMetaProperty &that); - static QDeclarativeExpression *setSignalExpression(const QDeclarativeMetaProperty &that, - QDeclarativeExpression *) ; - static bool write(const QDeclarativeMetaProperty &that, const QVariant &, WriteFlags); - static int valueTypeCoreIndex(const QDeclarativeMetaProperty &that); -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeMetaPropertyPrivate::WriteFlags) - -QT_END_NAMESPACE - -#endif // QDECLARATIVEMETAPROPERTY_P_H diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index e87f8ba..abbb9d6 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -619,7 +619,7 @@ QDeclarativeType *QDeclarativeMetaType::qmlType(const QByteArray &name, int vers QList types = data->nameToType.values(name); foreach (QDeclarativeType *t, types) { - // XXX version_major<0 just a kludge for QDeclarativeMetaPropertyPrivate::initProperty + // XXX version_major<0 just a kludge for QDeclarativePropertyPrivate::initProperty if (version_major<0 || t->availableInVersion(version_major,version_minor)) return t; } diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 50fe5c0..542f417 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -338,7 +338,7 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj, } } - QDeclarativeAbstractBinding *delBinding = QDeclarativeMetaPropertyPrivate::setBinding(obj, *lastData, 0); + QDeclarativeAbstractBinding *delBinding = QDeclarativePropertyPrivate::setBinding(obj, *lastData, 0); if (delBinding) delBinding->destroy(); @@ -348,7 +348,7 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj, } else { // ### Can well known types be optimized? QVariant v = QDeclarativeScriptClass::toVariant(engine, value); - QDeclarativeMetaPropertyPrivate::write(obj, *lastData, v, evalContext); + QDeclarativePropertyPrivate::write(obj, *lastData, v, evalContext); } } diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp new file mode 100644 index 0000000..88f356d --- /dev/null +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -0,0 +1,1200 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "qdeclarativeproperty.h" +#include "qdeclarativeproperty_p.h" + +#include "qdeclarativecompositetypedata_p.h" +#include "qdeclarative.h" +#include "qdeclarativebinding_p.h" +#include "qdeclarativecontext.h" +#include "qdeclarativecontext_p.h" +#include "qdeclarativeboundsignal_p.h" +#include "qdeclarativeengine.h" +#include "qdeclarativeengine_p.h" +#include "qdeclarativedeclarativedata_p.h" +#include "qdeclarativestringconverters_p.h" +#include "qdeclarativelist_p.h" + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QDeclarativeProperty + \brief The QDeclarativeProperty class abstracts accessing QML properties. + \internal + */ + +/*! + Create an invalid QDeclarativeProperty. +*/ +QDeclarativeProperty::QDeclarativeProperty() +: d(new QDeclarativePropertyPrivate) +{ + d->q = this; +} + +/*! \internal */ +QDeclarativeProperty::~QDeclarativeProperty() +{ + delete d; d = 0; +} + +/*! + Creates a QDeclarativeProperty for the default property of \a obj. If there is no + default property, an invalid QDeclarativeProperty will be created. + */ +QDeclarativeProperty::QDeclarativeProperty(QObject *obj) +: d(new QDeclarativePropertyPrivate) +{ + d->q = this; + d->initDefault(obj); +} + +/*! + \internal + Creates a QDeclarativeProperty for the default property of \a obj. If there is no + default property, an invalid QDeclarativeProperty will be created. + */ +QDeclarativeProperty::QDeclarativeProperty(QObject *obj, QDeclarativeContext *ctxt) +: d(new QDeclarativePropertyPrivate) +{ + d->q = this; + d->context = ctxt; + d->initDefault(obj); +} + +/*! + Initialize from the default property of \a obj +*/ +void QDeclarativePropertyPrivate::initDefault(QObject *obj) +{ + if (!obj) + return; + + QMetaProperty p = QDeclarativeMetaType::defaultProperty(obj); + core.load(p); + if (core.isValid()) { + isDefaultProperty = true; + object = obj; + } +} + +/*! + Creates a QDeclarativeProperty for the property \a name of \a obj. + */ +QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name) +: d(new QDeclarativePropertyPrivate) +{ + d->q = this; + d->initProperty(obj, name); + if (!isValid()) d->object = 0; +} + +/*! + \internal + Creates a QDeclarativeProperty for the property \a name of \a obj. + */ +QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name, QDeclarativeContext *ctxt) +: d(new QDeclarativePropertyPrivate) +{ + d->q = this; + d->context = ctxt; + d->initProperty(obj, name); + if (!isValid()) { d->object = 0; d->context = 0; } +} + +Q_GLOBAL_STATIC(QDeclarativeValueTypeFactory, qmlValueTypes); + +void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name) +{ + if (!obj) return; + + QDeclarativeEngine *engine = context?context->engine():0; + QDeclarativeTypeNameCache *typeNameCache = context?QDeclarativeContextPrivate::get(context)->imports:0; + + QStringList path = name.split(QLatin1Char('.')); + if (path.isEmpty()) return; + + QObject *currentObject = obj; + + // Everything up to the last property must be an "object type" property + for (int ii = 0; ii < path.count() - 1; ++ii) { + const QString &pathName = path.at(ii); + + if (QDeclarativeTypeNameCache::Data *data = typeNameCache?typeNameCache->data(pathName):0) { + if (data->type) { + QDeclarativeAttachedPropertiesFunc func = data->type->attachedPropertiesFunction(); + if (!func) return; // Not an attachable type + + currentObject = qmlAttachedPropertiesObjectById(data->type->index(), currentObject); + if (!currentObject) return; // Something is broken with the attachable type + } else { + Q_ASSERT(data->typeNamespace); + if ((ii + 1) == path.count()) return; // No type following the namespace + + ++ii; data = data->typeNamespace->data(path.at(ii)); + if (!data || !data->type) return; // Invalid type in namespace + + QDeclarativeAttachedPropertiesFunc func = data->type->attachedPropertiesFunction(); + if (!func) return; // Not an attachable type + + currentObject = qmlAttachedPropertiesObjectById(data->type->index(), currentObject); + if (!currentObject) return; // Something is broken with the attachable type + } + } else { + + QDeclarativePropertyCache::Data local; + QDeclarativePropertyCache::Data *property = + QDeclarativePropertyCache::property(engine, obj, pathName, local); + + if (!property) return; // Not a property + if (property->flags & QDeclarativePropertyCache::Data::IsFunction) + return; // Not an object property + + if (ii == (path.count() - 2) && property->propType < (int)QVariant::UserType) { + // We're now at a value type property. We can use a global valuetypes array as we + // never actually use the objects, just look up their properties. + QObject *typeObject = qmlValueTypes()->valueTypes[property->propType]; + if (!typeObject) return; // Not a value type + + int idx = typeObject->metaObject()->indexOfProperty(path.last().toUtf8().constData()); + if (idx == -1) return; // Value type property does not exist + + QMetaProperty vtProp = typeObject->metaObject()->property(idx); + + object = currentObject; + core = *property; + valueType.flags = QDeclarativePropertyCache::Data::flagsForProperty(vtProp); + valueType.valueTypeCoreIdx = idx; + valueType.valueTypePropType = vtProp.userType(); + + return; + } else { + if (!(property->flags & QDeclarativePropertyCache::Data::IsQObjectDerived)) + return; // Not an object property + + void *args[] = { ¤tObject, 0 }; + QMetaObject::metacall(currentObject, QMetaObject::ReadProperty, property->coreIndex, args); + if (!currentObject) return; // No value + + } + } + + } + + const QString &terminal = path.last(); + + if (terminal.count() >= 3 && + terminal.at(0) == QLatin1Char('o') && + terminal.at(1) == QLatin1Char('n') && + terminal.at(2).isUpper()) { + + QString signalName = terminal.mid(2); + signalName[0] = signalName.at(0).toLower(); + + QMetaMethod method = findSignal(currentObject, signalName); + if (method.signature()) { + object = currentObject; + core.load(method); + return; + } + } + + // Property + QDeclarativePropertyCache::Data local; + QDeclarativePropertyCache::Data *property = + QDeclarativePropertyCache::property(context?context->engine():0, currentObject, terminal, local); + if (property && !(property->flags & QDeclarativePropertyCache::Data::IsFunction)) { + object = currentObject; + core = *property; + } +} + +/*! + Create a copy of \a other. +*/ +QDeclarativeProperty::QDeclarativeProperty(const QDeclarativeProperty &other) +: d(new QDeclarativePropertyPrivate(*other.d)) +{ + d->q = this; +} + +/*! + \enum QDeclarativeProperty::PropertyTypeCategory + + This enum specifies a category of QML property. + + \value InvalidCategory The property is invalid. + \value List The property is a QList pointer + \value Object The property is a QObject derived type pointer + \value Normal The property is none of the above. + */ + +/*! + \enum QDeclarativeProperty::Type + + This enum specifies a type of QML property. + + \value Invalid The property is invalid. + \value Property The property is a regular Qt property. + \value SignalProperty The property is a signal property. + \value Default The property is the default property. +*/ + +/*! + Returns the property category. +*/ +QDeclarativeProperty::PropertyTypeCategory QDeclarativeProperty::propertyTypeCategory() const +{ + return d->propertyTypeCategory(); +} + +QDeclarativeProperty::PropertyTypeCategory +QDeclarativePropertyPrivate::propertyTypeCategory() const +{ + uint type = q->type(); + + if (type & QDeclarativeProperty::ValueTypeProperty) { + return QDeclarativeProperty::Normal; + } else if (type & QDeclarativeProperty::Property) { + int type = propertyType(); + if (type == QVariant::Invalid) + return QDeclarativeProperty::InvalidCategory; + else if ((uint)type < QVariant::UserType) + return QDeclarativeProperty::Normal; + else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) + return QDeclarativeProperty::Object; + else if (core.flags & QDeclarativePropertyCache::Data::IsQList) + return QDeclarativeProperty::List; + else + return QDeclarativeProperty::Normal; + } else { + return QDeclarativeProperty::InvalidCategory; + } +} + +/*! + Returns the type name of the property, or 0 if the property has no type + name. +*/ +const char *QDeclarativeProperty::propertyTypeName() const +{ + if (type() & ValueTypeProperty) { + + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->context); + QDeclarativeValueType *valueType = 0; + if (ep) valueType = ep->valueTypes[d->core.propType]; + else valueType = QDeclarativeValueTypeFactory::valueType(d->core.propType); + Q_ASSERT(valueType); + + const char *rv = valueType->metaObject()->property(d->valueType.valueTypeCoreIdx).typeName(); + + if (!ep) delete valueType; + + return rv; + } else if (d->object && type() & Property && d->core.isValid()) { + return d->object->metaObject()->property(d->core.coreIndex).typeName(); + } else { + return 0; + } +} + +/*! + Returns true if \a other and this QDeclarativeProperty represent the same + property. +*/ +bool QDeclarativeProperty::operator==(const QDeclarativeProperty &other) const +{ + // category is intentially omitted here as it is generated + // from the other members + return d->object == other.d->object && + d->core == other.d->core && + d->valueType == other.d->valueType; +} + +/*! + Returns the QVariant type of the property, or QVariant::Invalid if the + property has no QVariant type. +*/ +int QDeclarativeProperty::propertyType() const +{ + return d->propertyType(); +} + +int QDeclarativePropertyPrivate::propertyType() const +{ + uint type = q->type(); + if (type & QDeclarativeProperty::ValueTypeProperty) { + return valueType.valueTypePropType; + } else if (type & QDeclarativeProperty::Property) { + if (core.propType == (int)QVariant::LastType) + return qMetaTypeId(); + else + return core.propType; + } else { + return QVariant::Invalid; + } +} + +/*! + Returns the type of the property. +*/ +QDeclarativeProperty::Type QDeclarativeProperty::type() const +{ + if (d->core.flags & QDeclarativePropertyCache::Data::IsFunction) + return SignalProperty; + else if (d->valueType.valueTypeCoreIdx != -1) + return (Type)(Property | ValueTypeProperty); + else if (d->core.isValid()) + return (Type)(Property | ((d->isDefaultProperty)?Default:0)); + else + return Invalid; +} + +/*! + Returns true if this QDeclarativeProperty represents a regular Qt property. +*/ +bool QDeclarativeProperty::isProperty() const +{ + return type() & Property; +} + +/*! + Returns true if this QDeclarativeProperty represents a default property. +*/ +bool QDeclarativeProperty::isDefault() const +{ + return type() & Default; +} + +/*! + Returns the QDeclarativeProperty's QObject. +*/ +QObject *QDeclarativeProperty::object() const +{ + return d->object; +} + +/*! + Assign \a other to this QDeclarativeProperty. +*/ +QDeclarativeProperty &QDeclarativeProperty::operator=(const QDeclarativeProperty &other) +{ + d->context = other.d->context; + d->object = other.d->object; + + d->isDefaultProperty = other.d->isDefaultProperty; + d->isNameCached = other.d->isNameCached; + d->core = other.d->core; + d->nameCache = other.d->nameCache; + + d->valueType = other.d->valueType; + + return *this; +} + +/*! + Returns true if the property is writable, otherwise false. +*/ +bool QDeclarativeProperty::isWritable() const +{ + QDeclarativeProperty::PropertyTypeCategory category = propertyTypeCategory(); + + if (!d->object) + return false; + if (category == List) + return true; + else if (type() & SignalProperty) + return false; + else if (d->core.isValid() && d->object) + return d->core.flags & QDeclarativePropertyCache::Data::IsWritable; + else + return false; +} + +/*! + Returns true if the property is designable, otherwise false. +*/ +bool QDeclarativeProperty::isDesignable() const +{ + if (type() & Property && d->core.isValid() && d->object) + return d->object->metaObject()->property(d->core.coreIndex).isDesignable(); + else + return false; +} + +/*! + Returns true if the property is resettable, otherwise false. +*/ +bool QDeclarativeProperty::isResettable() const +{ + if (type() & Property && d->core.isValid() && d->object) + return d->core.flags & QDeclarativePropertyCache::Data::IsResettable; + else + return false; +} + +/*! + Returns true if the QDeclarativeProperty refers to a valid property, otherwise + false. +*/ +bool QDeclarativeProperty::isValid() const +{ + return type() != Invalid; +} + +/*! + Return the name of this QML property. +*/ +QString QDeclarativeProperty::name() const +{ + if (!d->isNameCached) { + // ### + if (!d->object) { + } else if (type() & ValueTypeProperty) { + QString rv = d->core.name(d->object) + QLatin1Char('.'); + + QDeclarativeEnginePrivate *ep = d->context?QDeclarativeEnginePrivate::get(d->context->engine()):0; + QDeclarativeValueType *valueType = 0; + if (ep) valueType = ep->valueTypes[d->core.propType]; + else valueType = QDeclarativeValueTypeFactory::valueType(d->core.propType); + Q_ASSERT(valueType); + + rv += QString::fromUtf8(valueType->metaObject()->property(d->valueType.valueTypeCoreIdx).name()); + + if (!ep) delete valueType; + + d->nameCache = rv; + } else if (type() & SignalProperty) { + QString name = QLatin1String("on") + d->core.name(d->object); + name[2] = name.at(2).toUpper(); + d->nameCache = name; + } else { + d->nameCache = d->core.name(d->object); + } + d->isNameCached = true; + } + + return d->nameCache; +} + +/*! + Returns the \l{QMetaProperty} {Qt property} associated with + this QML property. + */ +QMetaProperty QDeclarativeProperty::property() const +{ + if (type() & Property && d->core.isValid() && d->object) + return d->object->metaObject()->property(d->core.coreIndex); + else + return QMetaProperty(); +} + +/*! + Return the QMetaMethod for this property if it is a SignalProperty, + otherwise returns an invalid QMetaMethod. +*/ +QMetaMethod QDeclarativeProperty::method() const +{ + if (type() & SignalProperty && d->object) + return d->object->metaObject()->method(d->core.coreIndex); + else + return QMetaMethod(); +} + + +/*! + Returns the binding associated with this property, or 0 if no binding + exists. +*/ +QDeclarativeAbstractBinding * +QDeclarativePropertyPrivate::binding(const QDeclarativeProperty &that) +{ + if (!that.isProperty() || !that.d->object) + return 0; + + QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(that.d->object); + if (!data) + return 0; + + if (!data->hasBindingBit(that.d->core.coreIndex)) + return 0; + + QDeclarativeAbstractBinding *binding = data->bindings; + while (binding) { + // ### This wont work for value types + if (binding->propertyIndex() == that.d->core.coreIndex) + return binding; + binding = binding->m_nextBinding; + } + return 0; +} + +/*! + Set the binding associated with this property to \a newBinding. Returns + the existing binding (if any), otherwise 0. + + \a newBinding will be enabled, and the returned binding (if any) will be + disabled. + + Ownership of \a newBinding transfers to QML. Ownership of the return value + is assumed by the caller. + + \a flags is passed through to the binding and is used for the initial update (when + the binding sets the intial value, it will use these flags for the write). +*/ +QDeclarativeAbstractBinding * +QDeclarativePropertyPrivate::setBinding(const QDeclarativeProperty &that, + QDeclarativeAbstractBinding *newBinding, + WriteFlags flags) +{ + if (!that.isProperty() || !that.d->object) { + if (newBinding) + newBinding->destroy(); + return 0; + } + + return that.d->setBinding(that.d->object, that.d->core, newBinding, flags); +} + +QDeclarativeAbstractBinding * +QDeclarativePropertyPrivate::setBinding(QObject *object, const QDeclarativePropertyCache::Data &core, + QDeclarativeAbstractBinding *newBinding, WriteFlags flags) +{ + QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, 0 != newBinding); + + if (data && data->hasBindingBit(core.coreIndex)) { + QDeclarativeAbstractBinding *binding = data->bindings; + while (binding) { + // ### This wont work for value types + if (binding->propertyIndex() == core.coreIndex) { + binding->setEnabled(false); + + if (newBinding) + newBinding->setEnabled(true, flags); + + return binding; // ### QDeclarativeAbstractBinding; + } + + binding = binding->m_nextBinding; + } + } + + if (newBinding) + newBinding->setEnabled(true, flags); + + return 0; +} + +/*! + Returns the expression associated with this signal property, or 0 if no + signal expression exists. +*/ +QDeclarativeExpression * +QDeclarativePropertyPrivate::signalExpression(const QDeclarativeProperty &that) +{ + if (!(that.type() & QDeclarativeProperty::SignalProperty)) + return 0; + + const QObjectList &children = that.d->object->children(); + + for (int ii = 0; ii < children.count(); ++ii) { + QObject *child = children.at(ii); + + QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); + if (signal && signal->index() == that.coreIndex()) + return signal->expression(); + } + + return 0; +} + +/*! + Set the signal expression associated with this signal property to \a expr. + Returns the existing signal expression (if any), otherwise 0. + + Ownership of \a expr transfers to QML. Ownership of the return value is + assumed by the caller. +*/ +QDeclarativeExpression * +QDeclarativePropertyPrivate::setSignalExpression(const QDeclarativeProperty &that, + QDeclarativeExpression *expr) +{ + if (!(that.type() & QDeclarativeProperty::SignalProperty)) { + delete expr; + return 0; + } + + const QObjectList &children = that.d->object->children(); + + for (int ii = 0; ii < children.count(); ++ii) { + QObject *child = children.at(ii); + + QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child); + if (signal && signal->index() == that.coreIndex()) + return signal->setExpression(expr); + } + + if (expr) { + QDeclarativeBoundSignal *signal = new QDeclarativeBoundSignal(that.d->object, that.method(), that.d->object); + return signal->setExpression(expr); + } else { + return 0; + } +} + +QMetaMethod QDeclarativePropertyPrivate::findSignal(QObject *obj, const QString &name) +{ + const QMetaObject *mo = obj->metaObject(); + + int methods = mo->methodCount(); + for (int ii = methods - 1; ii >= 0; --ii) { + QMetaMethod method = mo->method(ii); + QString methodName = QString::fromUtf8(method.signature()); + int idx = methodName.indexOf(QLatin1Char('(')); + methodName = methodName.left(idx); + + if (methodName == name) + return method; + } + return QMetaMethod(); +} + +/*! + Returns the property value. +*/ +QVariant QDeclarativeProperty::read() const +{ + if (!d->object) + return QVariant(); + + if (type() & SignalProperty) { + + return QVariant(); + + } else if (type() & Property) { + + return d->readValueProperty(); + + } + return QVariant(); +} + +QVariant QDeclarativePropertyPrivate::readValueProperty() +{ + uint type = q->type(); + if(type & QDeclarativeProperty::ValueTypeProperty) { + + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); + QDeclarativeValueType *valueType = 0; + if (ep) valueType = ep->valueTypes[core.propType]; + else valueType = QDeclarativeValueTypeFactory::valueType(core.propType); + Q_ASSERT(valueType); + + valueType->read(object, core.coreIndex); + + QVariant rv = + valueType->metaObject()->property(this->valueType.valueTypeCoreIdx).read(valueType); + + if (!ep) delete valueType; + return rv; + + } else if(core.flags & QDeclarativePropertyCache::Data::IsQList) { + + QDeclarativeListProperty prop; + void *args[] = { &prop, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args); + return QVariant::fromValue(QDeclarativeListReferencePrivate::init(prop, core.propType, context?context->engine():0)); + + } else { + + return object->metaObject()->property(core.coreIndex).read(object.data()); + + } +} + +//### +//writeEnumProperty MIRRORS the relelvant bit of QMetaProperty::write AND MUST BE KEPT IN SYNC! +//### +bool QDeclarativePropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, const QVariant &value, int flags) +{ + if (!object || !prop.isWritable()) + return false; + + QVariant v = value; + if (prop.isEnumType()) { + QMetaEnum menum = prop.enumerator(); + if (v.userType() == QVariant::String +#ifdef QT3_SUPPORT + || v.userType() == QVariant::CString +#endif + ) { + if (prop.isFlagType()) + v = QVariant(menum.keysToValue(value.toByteArray())); + else + v = QVariant(menum.keyToValue(value.toByteArray())); + } else if (v.userType() != QVariant::Int && v.userType() != QVariant::UInt) { + int enumMetaTypeId = QMetaType::type(QByteArray(menum.scope()) + "::" + menum.name()); + if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData()) + return false; + v = QVariant(*reinterpret_cast(v.constData())); + } + v.convert(QVariant::Int); + } + + // the status variable is changed by qt_metacall to indicate what it did + // this feature is currently only used by QtDBus and should not be depended + // upon. Don't change it without looking into QDBusAbstractInterface first + // -1 (unchanged): normal qt_metacall, result stored in argv[0] + // changed: result stored directly in value, return the value of status + int status = -1; + void *argv[] = { v.data(), &v, &status, &flags }; + QMetaObject::metacall(object, QMetaObject::WriteProperty, idx, argv); + return status; +} + +bool QDeclarativePropertyPrivate::writeValueProperty(const QVariant &value, WriteFlags flags) +{ + // Remove any existing bindings on this property + if (!(flags & DontRemoveBinding)) { + QDeclarativeAbstractBinding *binding = setBinding(*q, 0); + if (binding) binding->destroy(); + } + + bool rv = false; + uint type = q->type(); + if (type & QDeclarativeProperty::ValueTypeProperty) { + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); + + QDeclarativeValueType *writeBack = 0; + if (ep) { + writeBack = ep->valueTypes[core.propType]; + } else { + writeBack = QDeclarativeValueTypeFactory::valueType(core.propType); + } + + writeBack->read(object, core.coreIndex); + + QDeclarativePropertyCache::Data data = core; + data.flags = valueType.flags; + data.coreIndex = valueType.valueTypeCoreIdx; + data.propType = valueType.valueTypePropType; + rv = write(writeBack, data, value, context, flags); + + writeBack->write(object, core.coreIndex, flags); + if (!ep) delete writeBack; + + } else { + + rv = write(object, core, value, context, flags); + + } + + return rv; +} + +bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePropertyCache::Data &property, + const QVariant &value, QDeclarativeContext *context, + WriteFlags flags) +{ + int coreIdx = property.coreIndex; + int status = -1; //for dbus + + if (property.flags & QDeclarativePropertyCache::Data::IsEnumType) { + QMetaProperty prop = object->metaObject()->property(property.coreIndex); + QVariant v = value; + // Enum values come through the script engine as doubles + if (value.userType() == QVariant::Double) { + double integral; + double fractional = modf(value.toDouble(), &integral); + if (qFuzzyIsNull(fractional)) + v.convert(QVariant::Int); + } + return writeEnumProperty(prop, coreIdx, object, v, flags); + } + + int propertyType = property.propType; + int variantType = value.userType(); + + QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(context); + + if (propertyType == QVariant::Url) { + + QUrl u; + bool found = false; + if (variantType == QVariant::Url) { + u = value.toUrl(); + found = true; + } else if (variantType == QVariant::ByteArray) { + u = QUrl(QString::fromUtf8(value.toByteArray())); + found = true; + } else if (variantType == QVariant::String) { + u = QUrl(value.toString()); + found = true; + } + + if (!found) + return false; + + if (context && u.isRelative() && !u.isEmpty()) + u = context->resolvedUrl(u); + int status = -1; + void *argv[] = { &u, 0, &status, &flags }; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv); + + } else if (variantType == propertyType) { + + void *a[] = { (void *)value.constData(), 0, &status, &flags }; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); + + } else if (qMetaTypeId() == propertyType) { + + void *a[] = { (void *)&value, 0, &status, &flags }; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); + + } else if (property.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) { + + const QMetaObject *valMo = rawMetaObjectForType(enginePriv, value.userType()); + + if (!valMo) + return false; + + QObject *o = *(QObject **)value.constData(); + const QMetaObject *propMo = rawMetaObjectForType(enginePriv, propertyType); + + if (o) valMo = o->metaObject(); + + if (canConvert(valMo, propMo)) { + void *args[] = { &o, 0, &status, &flags }; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, + args); + } else if (!o && canConvert(propMo, valMo)) { + // In the case of a null QObject, we assign the null if there is + // any change that the null variant type could be up or down cast to + // the property type. + void *args[] = { &o, 0, &status, &flags }; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, + args); + } else { + return false; + } + + } else if (property.flags & QDeclarativePropertyCache::Data::IsQList) { + + const QMetaObject *listType = 0; + if (enginePriv) { + listType = enginePriv->rawMetaObjectForType(enginePriv->listType(property.propType)); + } else { + QDeclarativeType *type = QDeclarativeMetaType::qmlType(QDeclarativeMetaType::listType(property.propType)); + if (!type) return false; + listType = type->baseMetaObject(); + } + if (!listType) return false; + + QDeclarativeListProperty prop; + void *args[] = { &prop, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, coreIdx, args); + + if (!prop.clear) return false; + + prop.clear(&prop); + + if (value.userType() == qMetaTypeId >()) { + const QList &list = qvariant_cast >(value); + + for (int ii = 0; ii < list.count(); ++ii) { + QObject *o = list.at(ii); + if (!canConvert(o->metaObject(), listType)) + o = 0; + prop.append(&prop, (void *)o); + } + } else { + QObject *o = enginePriv?enginePriv->toQObject(value):QDeclarativeMetaType::toQObject(value); + if (!canConvert(o->metaObject(), listType)) + o = 0; + prop.append(&prop, (void *)o); + } + + } else { + Q_ASSERT(variantType != propertyType); + + QVariant v = value; + if (v.convert((QVariant::Type)propertyType)) { + void *a[] = { (void *)v.constData(), 0, &status, &flags}; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); + } else if ((uint)propertyType >= QVariant::UserType && variantType == QVariant::String) { + QDeclarativeMetaType::StringConverter con = QDeclarativeMetaType::customStringConverter(propertyType); + if (!con) + return false; + + QVariant v = con(value.toString()); + if (v.userType() == propertyType) { + void *a[] = { (void *)v.constData(), 0, &status, &flags}; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); + } + } else if (variantType == QVariant::String) { + bool ok = false; + QVariant v = QDeclarativeStringConverters::variantFromString(value.toString(), propertyType, &ok); + if (!ok) + return false; + + void *a[] = { (void *)v.constData(), 0, &status, &flags}; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); + } else { + return false; + } + } + + return true; +} + +const QMetaObject *QDeclarativePropertyPrivate::rawMetaObjectForType(QDeclarativeEnginePrivate *engine, int userType) +{ + if (engine) { + return engine->rawMetaObjectForType(userType); + } else { + QDeclarativeType *type = QDeclarativeMetaType::qmlType(userType); + return type?type->baseMetaObject():0; + } +} + +/*! + Set the property value to \a value. +*/ +bool QDeclarativeProperty::write(const QVariant &value) const +{ + return QDeclarativePropertyPrivate::write(*this, value, 0); +} + +/*! + Resets the property value. +*/ +bool QDeclarativeProperty::reset() const +{ + if (isResettable()) { + void *args[] = { 0 }; + QMetaObject::metacall(d->object, QMetaObject::ResetProperty, d->core.coreIndex, args); + return true; + } else { + return false; + } +} + +bool QDeclarativePropertyPrivate::write(const QDeclarativeProperty &that, + const QVariant &value, WriteFlags flags) +{ + if (that.d->object && that.type() & QDeclarativeProperty::Property && + that.d->core.isValid() && that.isWritable()) + return that.d->writeValueProperty(value, flags); + else + return false; +} + +/*! + Returns true if the property has a change notifier signal, otherwise false. +*/ +bool QDeclarativeProperty::hasChangedNotifier() const +{ + if (type() & Property && d->object) { + return d->object->metaObject()->property(d->core.coreIndex).hasNotifySignal(); + } + return false; +} + +/*! + Returns true if the property needs a change notifier signal for bindings + to remain upto date, false otherwise. + + Some properties, such as attached properties or those whose value never + changes, do not require a change notifier. +*/ +bool QDeclarativeProperty::needsChangedNotifier() const +{ + return type() & Property && !property().isConstant(); +} + +/*! + Connects the property's change notifier signal to the + specified \a method of the \a dest object and returns + true. Returns false if this metaproperty does not + represent a regular Qt property or if it has no + change notifier signal, or if the \a dest object does + not have the specified \a method. +*/ +bool QDeclarativeProperty::connectNotifier(QObject *dest, int method) const +{ + if (!(type() & Property) || !d->object) + return false; + + QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex); + if (prop.hasNotifySignal()) { + return QMetaObject::connect(d->object, prop.notifySignalIndex(), dest, method, Qt::DirectConnection); + } else { + return false; + } +} + +/*! + Connects the property's change notifier signal to the + specified \a slot of the \a dest object and returns + true. Returns false if this metaproperty does not + represent a regular Qt property or if it has no + change notifier signal, or if the \a dest object does + not have the specified \a slot. +*/ +bool QDeclarativeProperty::connectNotifier(QObject *dest, const char *slot) const +{ + if (!(type() & Property) || !d->object) + return false; + + QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex); + if (prop.hasNotifySignal()) { + QByteArray signal(QByteArray("2") + prop.notifySignal().signature()); + return QObject::connect(d->object, signal.constData(), dest, slot); + } else { + return false; + } +} + +/*! + Return the Qt metaobject index of the property. +*/ +int QDeclarativeProperty::coreIndex() const +{ + return d->core.coreIndex; +} + +int QDeclarativePropertyPrivate::valueTypeCoreIndex(const QDeclarativeProperty &that) +{ + return that.d->valueType.valueTypeCoreIdx; +} + +struct SerializedData { + QDeclarativeProperty::Type type; + QDeclarativePropertyCache::Data core; +}; + +struct ValueTypeSerializedData : public SerializedData { + QDeclarativePropertyCache::ValueTypeData valueType; +}; + +QByteArray QDeclarativePropertyPrivate::saveValueType(const QMetaObject *metaObject, int index, + const QMetaObject *subObject, int subIndex) +{ + QMetaProperty prop = metaObject->property(index); + QMetaProperty subProp = subObject->property(subIndex); + + ValueTypeSerializedData sd; + sd.type = QDeclarativeProperty::ValueTypeProperty; + sd.core.load(metaObject->property(index)); + sd.valueType.flags = QDeclarativePropertyCache::Data::flagsForProperty(subProp); + sd.valueType.valueTypeCoreIdx = subIndex; + sd.valueType.valueTypePropType = subProp.userType(); + + QByteArray rv((const char *)&sd, sizeof(sd)); + + return rv; +} + +QByteArray QDeclarativePropertyPrivate::saveProperty(const QMetaObject *metaObject, int index) +{ + SerializedData sd; + sd.type = QDeclarativeProperty::Property; + sd.core.load(metaObject->property(index)); + + QByteArray rv((const char *)&sd, sizeof(sd)); + return rv; +} + +QDeclarativeProperty +QDeclarativePropertyPrivate::restore(const QByteArray &data, QObject *object, QDeclarativeContext *ctxt) +{ + QDeclarativeProperty prop; + + if (data.isEmpty()) + return prop; + + prop.d->object = object; + prop.d->context = ctxt; + + const SerializedData *sd = (const SerializedData *)data.constData(); + if (sd->type == QDeclarativeProperty::Property) { + prop.d->core = sd->core; + } else if(sd->type == QDeclarativeProperty::ValueTypeProperty) { + const ValueTypeSerializedData *vt = (const ValueTypeSerializedData *)sd; + prop.d->core = vt->core; + prop.d->valueType = vt->valueType; + } + + return prop; +} + +/*! + Returns true if lhs and rhs refer to the same metaobject data +*/ +bool QDeclarativePropertyPrivate::equal(const QMetaObject *lhs, const QMetaObject *rhs) +{ + return lhs == rhs || (1 && lhs && rhs && lhs->d.stringdata == rhs->d.stringdata); +} + +/*! + Returns true if from inherits to. +*/ +bool QDeclarativePropertyPrivate::canConvert(const QMetaObject *from, const QMetaObject *to) +{ + if (from && to == &QObject::staticMetaObject) + return true; + + while (from) { + if (equal(from, to)) + return true; + from = from->superClass(); + } + + return false; +} + +QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeproperty.h b/src/declarative/qml/qdeclarativeproperty.h new file mode 100644 index 0000000..be1065e --- /dev/null +++ b/src/declarative/qml/qdeclarativeproperty.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEPROPERTY_H +#define QDECLARATIVEPROPERTY_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QObject; +class QDeclarativeAbstractBinding; +class QDeclarativeExpression; +class QStringList; +class QVariant; +struct QMetaObject; +class QDeclarativeContext; +class QDeclarativeEngine; + +class QDeclarativePropertyPrivate; +class Q_DECLARATIVE_EXPORT QDeclarativeProperty +{ +public: + enum PropertyTypeCategory { + InvalidCategory, + List, + Object, + Normal + }; + + enum Type { Invalid = 0x00, + Property = 0x01, + SignalProperty = 0x02, + Default = 0x08, + ValueTypeProperty = 0x10 + }; + + QDeclarativeProperty(); + ~QDeclarativeProperty(); + + QDeclarativeProperty(QObject *); + QDeclarativeProperty(QObject *, QDeclarativeContext *); + + QDeclarativeProperty(QObject *, const QString &); + QDeclarativeProperty(QObject *, const QString &, QDeclarativeContext *); + + QDeclarativeProperty(const QDeclarativeProperty &); + QDeclarativeProperty &operator=(const QDeclarativeProperty &); + + QString name() const; + + QVariant read() const; + bool write(const QVariant &) const; + bool reset() const; + + bool hasChangedNotifier() const; + bool needsChangedNotifier() const; + bool connectNotifier(QObject *dest, const char *slot) const; + bool connectNotifier(QObject *dest, int method) const; + + Type type() const; + bool isProperty() const; + bool isDefault() const; + bool isWritable() const; + bool isDesignable() const; + bool isResettable() const; + bool isValid() const; + QObject *object() const; + + int propertyType() const; + PropertyTypeCategory propertyTypeCategory() const; + const char *propertyTypeName() const; + + bool operator==(const QDeclarativeProperty &) const; + + int coreIndex() const; + QMetaProperty property() const; + QMetaMethod method() const; + +private: + friend class QDeclarativeEnginePrivate; + friend class QDeclarativePropertyPrivate; + QDeclarativePropertyPrivate *d; +}; +typedef QList QDeclarativeProperties; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEPROPERTY_H diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h new file mode 100644 index 0000000..d0ad09c --- /dev/null +++ b/src/declarative/qml/qdeclarativeproperty_p.h @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEPROPERTY_P_H +#define QDECLARATIVEPROPERTY_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 "qdeclarativeproperty.h" + +#include "qdeclarativepropertycache_p.h" +#include "qdeclarativeguard_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QDeclarativeContext; +class QDeclarativeEnginePrivate; +class Q_AUTOTEST_EXPORT QDeclarativePropertyPrivate +{ +public: + enum WriteFlag { BypassInterceptor = 0x01, DontRemoveBinding = 0x02 }; + Q_DECLARE_FLAGS(WriteFlags, WriteFlag) + + QDeclarativePropertyPrivate() + : q(0), context(0), object(0), isDefaultProperty(false), isNameCached(false) {} + + + QDeclarativePropertyPrivate(const QDeclarativePropertyPrivate &other) + : q(0), context(other.context), object(other.object), + isDefaultProperty(other.isDefaultProperty), isNameCached(other.isNameCached), + core(other.core), nameCache(other.nameCache), + valueType(other.valueType) {} + + QDeclarativeProperty *q; + QDeclarativeContext *context; + QDeclarativeGuard object; + + bool isDefaultProperty:1; + bool isNameCached:1; + QDeclarativePropertyCache::Data core; + QString nameCache; + + // Describes the "virtual" value-type sub-property. + QDeclarativePropertyCache::ValueTypeData valueType; + + void initProperty(QObject *obj, const QString &name); + void initDefault(QObject *obj); + + QMetaMethod findSignal(QObject *, const QString &); + + int propertyType() const; + QDeclarativeProperty::PropertyTypeCategory propertyTypeCategory() const; + + QVariant readValueProperty(); + bool writeValueProperty(const QVariant &, WriteFlags); + + static const QMetaObject *rawMetaObjectForType(QDeclarativeEnginePrivate *, int); + static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, + const QVariant &value, int flags); + static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &, + QDeclarativeContext *, WriteFlags flags = 0); + static QDeclarativeAbstractBinding *setBinding(QObject *, const QDeclarativePropertyCache::Data &, + QDeclarativeAbstractBinding *, + WriteFlags flags = DontRemoveBinding); + + static QByteArray saveValueType(const QMetaObject *, int, + const QMetaObject *, int); + static QByteArray saveProperty(const QMetaObject *, int); + static QDeclarativeProperty restore(const QByteArray &, QObject *, QDeclarativeContext *); + + static bool equal(const QMetaObject *, const QMetaObject *); + static bool canConvert(const QMetaObject *from, const QMetaObject *to); + + + // "Public" (to QML) methods + static QDeclarativeAbstractBinding *binding(const QDeclarativeProperty &that); + static QDeclarativeAbstractBinding *setBinding(const QDeclarativeProperty &that, + QDeclarativeAbstractBinding *, + WriteFlags flags = DontRemoveBinding); + static QDeclarativeExpression *signalExpression(const QDeclarativeProperty &that); + static QDeclarativeExpression *setSignalExpression(const QDeclarativeProperty &that, + QDeclarativeExpression *) ; + static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags); + static int valueTypeCoreIndex(const QDeclarativeProperty &that); +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyPrivate::WriteFlags) + +QT_END_NAMESPACE + +#endif // QDECLARATIVEPROPERTY_P_H diff --git a/src/declarative/qml/qdeclarativepropertyvalueinterceptor.cpp b/src/declarative/qml/qdeclarativepropertyvalueinterceptor.cpp index 7626d56..3f6d805 100644 --- a/src/declarative/qml/qdeclarativepropertyvalueinterceptor.cpp +++ b/src/declarative/qml/qdeclarativepropertyvalueinterceptor.cpp @@ -66,7 +66,7 @@ QDeclarativePropertyValueInterceptor::~QDeclarativePropertyValueInterceptor() } /*! - \fn void QDeclarativePropertyValueInterceptor::setTarget(const QDeclarativeMetaProperty &property) + \fn void QDeclarativePropertyValueInterceptor::setTarget(const QDeclarativeProperty &property) Set the target \a property for the value interceptor. This method will be called by the QML engine when assigning a value interceptor. */ diff --git a/src/declarative/qml/qdeclarativepropertyvalueinterceptor.h b/src/declarative/qml/qdeclarativepropertyvalueinterceptor.h index 2a29d5b..3de5abc 100644 --- a/src/declarative/qml/qdeclarativepropertyvalueinterceptor.h +++ b/src/declarative/qml/qdeclarativepropertyvalueinterceptor.h @@ -50,13 +50,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeMetaProperty; +class QDeclarativeProperty; class Q_DECLARATIVE_EXPORT QDeclarativePropertyValueInterceptor { public: QDeclarativePropertyValueInterceptor(); virtual ~QDeclarativePropertyValueInterceptor(); - virtual void setTarget(const QDeclarativeMetaProperty &property) = 0; + virtual void setTarget(const QDeclarativeProperty &property) = 0; virtual void write(const QVariant &value) = 0; }; Q_DECLARE_INTERFACE(QDeclarativePropertyValueInterceptor, "com.trolltech.qml.QDeclarativePropertyValueInterceptor") diff --git a/src/declarative/qml/qdeclarativepropertyvaluesource.cpp b/src/declarative/qml/qdeclarativepropertyvaluesource.cpp index 626e391..b106d4f 100644 --- a/src/declarative/qml/qdeclarativepropertyvaluesource.cpp +++ b/src/declarative/qml/qdeclarativepropertyvaluesource.cpp @@ -63,7 +63,7 @@ QDeclarativePropertyValueSource::~QDeclarativePropertyValueSource() } /*! - \fn void QDeclarativePropertyValueSource::setTarget(const QDeclarativeMetaProperty &property) + \fn void QDeclarativePropertyValueSource::setTarget(const QDeclarativeProperty &property) Set the target \a property for the value source. This method will be called by the QML engine when assigning a value source. */ diff --git a/src/declarative/qml/qdeclarativepropertyvaluesource.h b/src/declarative/qml/qdeclarativepropertyvaluesource.h index 99c80af..70d2c03 100644 --- a/src/declarative/qml/qdeclarativepropertyvaluesource.h +++ b/src/declarative/qml/qdeclarativepropertyvaluesource.h @@ -50,13 +50,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeMetaProperty; +class QDeclarativeProperty; class Q_DECLARATIVE_EXPORT QDeclarativePropertyValueSource { public: QDeclarativePropertyValueSource(); virtual ~QDeclarativePropertyValueSource(); - virtual void setTarget(const QDeclarativeMetaProperty &) = 0; + virtual void setTarget(const QDeclarativeProperty &) = 0; }; Q_DECLARE_INTERFACE(QDeclarativePropertyValueSource, "com.trolltech.qml.QDeclarativePropertyValueSource") diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index d35371f..01fa214 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -100,7 +100,7 @@ void QDeclarativePointFValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativePointFValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativePointFValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &point, 0, &status, &flags }; @@ -148,7 +148,7 @@ void QDeclarativePointValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativePointValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativePointValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &point, 0, &status, &flags }; @@ -196,7 +196,7 @@ void QDeclarativeSizeFValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativeSizeFValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeSizeFValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &size, 0, &status, &flags }; @@ -244,7 +244,7 @@ void QDeclarativeSizeValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativeSizeValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeSizeValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &size, 0, &status, &flags }; @@ -292,7 +292,7 @@ void QDeclarativeRectFValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativeRectFValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeRectFValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &rect, 0, &status, &flags }; @@ -360,7 +360,7 @@ void QDeclarativeRectValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativeRectValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeRectValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &rect, 0, &status, &flags }; @@ -428,7 +428,7 @@ void QDeclarativeVector3DValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativeVector3DValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeVector3DValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &vector, 0, &status, &flags }; @@ -486,7 +486,7 @@ void QDeclarativeEasingValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativeEasingValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeEasingValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &easing, 0, &status, &flags }; @@ -554,7 +554,7 @@ void QDeclarativeFontValueType::read(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } -void QDeclarativeFontValueType::write(QObject *obj, int idx, QDeclarativeMetaPropertyPrivate::WriteFlags flags) +void QDeclarativeFontValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) { int status = -1; void *a[] = { &font, 0, &status, &flags }; diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index 792598b..cb153be 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -53,8 +53,8 @@ // We mean it. // -#include "qdeclarativemetaproperty.h" -#include "qdeclarativemetaproperty_p.h" +#include "qdeclarativeproperty.h" +#include "qdeclarativeproperty_p.h" #include #include @@ -71,7 +71,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeValueType : public QObject public: QDeclarativeValueType(QObject *parent = 0); virtual void read(QObject *, int) = 0; - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags flags) = 0; + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags flags) = 0; virtual QVariant value() = 0; virtual void setValue(QVariant) = 0; }; @@ -96,7 +96,7 @@ public: QDeclarativePointFValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -118,7 +118,7 @@ public: QDeclarativePointValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -140,7 +140,7 @@ public: QDeclarativeSizeFValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -162,7 +162,7 @@ public: QDeclarativeSizeValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -186,7 +186,7 @@ public: QDeclarativeRectFValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -215,7 +215,7 @@ public: QDeclarativeRectValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -243,7 +243,7 @@ public: QDeclarativeVector3DValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -297,7 +297,7 @@ public: QDeclarativeEasingValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); @@ -348,7 +348,7 @@ public: QDeclarativeFontValueType(QObject *parent = 0); virtual void read(QObject *, int); - virtual void write(QObject *, int, QDeclarativeMetaPropertyPrivate::WriteFlags); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); virtual QVariant value(); virtual void setValue(QVariant value); diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index f7af843..baa98bd 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -156,7 +156,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarati QDeclarativeContextPrivate *cp = (QDeclarativeContextPrivate *)QObjectPrivate::get(ctxt); int status = -1; //for dbus - QDeclarativeMetaPropertyPrivate::WriteFlags flags = QDeclarativeMetaPropertyPrivate::BypassInterceptor; + QDeclarativePropertyPrivate::WriteFlags flags = QDeclarativePropertyPrivate::BypassInterceptor; for (int ii = start; !isError() && ii < (start + count); ++ii) { const QDeclarativeInstruction &instr = comp->bytecode.at(ii); @@ -515,8 +515,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarati int sigIdx = instr.assignSignalObject.signal; const QByteArray &pr = datas.at(sigIdx); - QDeclarativeMetaProperty prop(target, QString::fromUtf8(pr)); - if (prop.type() & QDeclarativeMetaProperty::SignalProperty) { + QDeclarativeProperty prop(target, QString::fromUtf8(pr)); + if (prop.type() & QDeclarativeProperty::SignalProperty) { QMetaMethod method = QDeclarativeMetaType::defaultMethod(assign); if (method.signature() == 0) @@ -590,8 +590,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarati QObject *context = stack.at(stack.count() - 1 - instr.assignBinding.context); - QDeclarativeMetaProperty mp = - QDeclarativeMetaPropertyPrivate::restore(datas.at(instr.assignBinding.property), target, ctxt); + QDeclarativeProperty mp = + QDeclarativePropertyPrivate::restore(datas.at(instr.assignBinding.property), target, ctxt); int coreIndex = mp.coreIndex(); @@ -631,8 +631,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarati QDeclarativePropertyValueSource *vs = reinterpret_cast(reinterpret_cast(obj) + instr.assignValueSource.castValue); QObject *target = stack.at(stack.count() - 1 - instr.assignValueSource.owner); - QDeclarativeMetaProperty prop = - QDeclarativeMetaPropertyPrivate::restore(datas.at(instr.assignValueSource.property), target, ctxt); + QDeclarativeProperty prop = + QDeclarativePropertyPrivate::restore(datas.at(instr.assignValueSource.property), target, ctxt); obj->setParent(target); vs->setTarget(prop); } @@ -643,12 +643,12 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarati QObject *obj = stack.pop(); QDeclarativePropertyValueInterceptor *vi = reinterpret_cast(reinterpret_cast(obj) + instr.assignValueInterceptor.castValue); QObject *target = stack.at(stack.count() - 1 - instr.assignValueInterceptor.owner); - QDeclarativeMetaProperty prop = - QDeclarativeMetaPropertyPrivate::restore(datas.at(instr.assignValueInterceptor.property), target, ctxt); + QDeclarativeProperty prop = + QDeclarativePropertyPrivate::restore(datas.at(instr.assignValueInterceptor.property), target, ctxt); obj->setParent(target); vi->setTarget(prop); QDeclarativeVMEMetaObject *mo = static_cast((QMetaObject*)target->metaObject()); - mo->registerInterceptor(prop.coreIndex(), QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), vi); + mo->registerInterceptor(prop.coreIndex(), QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), vi); } break; @@ -807,7 +807,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarati static_cast(stack.pop()); QObject *target = stack.top(); valueHandler->write(target, instr.fetchValue.property, - QDeclarativeMetaPropertyPrivate::BypassInterceptor); + QDeclarativePropertyPrivate::BypassInterceptor); } break; diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp index 6edb707..d67c834 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject.cpp +++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp @@ -105,7 +105,7 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) int id = _id; if(c == QMetaObject::WriteProperty) { int flags = *reinterpret_cast(a[3]); - if (!(flags & QDeclarativeMetaPropertyPrivate::BypassInterceptor) + if (!(flags & QDeclarativePropertyPrivate::BypassInterceptor) && !aInterceptors.isEmpty() && aInterceptors.testBit(id)) { QPair pair = interceptors.value(id); diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 8a43cec..aa1a34b 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -6,7 +6,7 @@ SOURCES += \ $$PWD/qdeclarativeengine.cpp \ $$PWD/qdeclarativeexpression.cpp \ $$PWD/qdeclarativebinding.cpp \ - $$PWD/qdeclarativemetaproperty.cpp \ + $$PWD/qdeclarativeproperty.cpp \ $$PWD/qdeclarativecomponent.cpp \ $$PWD/qdeclarativecontext.cpp \ $$PWD/qdeclarativecustomparser.cpp \ @@ -62,7 +62,7 @@ HEADERS += \ $$PWD/qdeclarative.h \ $$PWD/qdeclarativebinding_p.h \ $$PWD/qdeclarativebinding_p_p.h \ - $$PWD/qdeclarativemetaproperty.h \ + $$PWD/qdeclarativeproperty.h \ $$PWD/qdeclarativecomponent.h \ $$PWD/qdeclarativecomponent_p.h \ $$PWD/qdeclarativecustomparser_p.h \ @@ -87,7 +87,7 @@ HEADERS += \ $$PWD/qdeclarativestringconverters_p.h \ $$PWD/qdeclarativeclassfactory_p.h \ $$PWD/qdeclarativeinfo.h \ - $$PWD/qdeclarativemetaproperty_p.h \ + $$PWD/qdeclarativeproperty_p.h \ $$PWD/qdeclarativecontext_p.h \ $$PWD/qdeclarativecompositetypedata_p.h \ $$PWD/qdeclarativecompositetypemanager_p.h \ diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index a327ccb..264b88c 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include @@ -145,7 +145,7 @@ void QDeclarativeAbstractAnimationPrivate::commence() Q_Q(QDeclarativeAbstractAnimation); QDeclarativeStateActions actions; - QDeclarativeMetaProperties properties; + QDeclarativeProperties properties; q->transition(actions, properties, QDeclarativeAbstractAnimation::Forward); q->qtAnimation()->start(); @@ -155,15 +155,15 @@ void QDeclarativeAbstractAnimationPrivate::commence() } } -QDeclarativeMetaProperty QDeclarativeAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str, QObject *infoObj) +QDeclarativeProperty QDeclarativeAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str, QObject *infoObj) { - QDeclarativeMetaProperty prop(obj, str, qmlContext(infoObj)); + QDeclarativeProperty prop(obj, str, qmlContext(infoObj)); if (!prop.isValid()) { qmlInfo(infoObj) << QDeclarativeAbstractAnimation::tr("Cannot animate non-existent property \"%1\"").arg(str); - return QDeclarativeMetaProperty(); + return QDeclarativeProperty(); } else if (!prop.isWritable()) { qmlInfo(infoObj) << QDeclarativeAbstractAnimation::tr("Cannot animate read-only property \"%1\"").arg(str); - return QDeclarativeMetaProperty(); + return QDeclarativeProperty(); } return prop; } @@ -466,7 +466,7 @@ void QDeclarativeAbstractAnimation::complete() } } -void QDeclarativeAbstractAnimation::setTarget(const QDeclarativeMetaProperty &p) +void QDeclarativeAbstractAnimation::setTarget(const QDeclarativeProperty &p) { Q_D(QDeclarativeAbstractAnimation); d->defaultProperty = p; @@ -480,7 +480,7 @@ void QDeclarativeAbstractAnimation::setTarget(const QDeclarativeMetaProperty &p) so this function allows us to do the same thing as setTarget without that assumption */ -void QDeclarativeAbstractAnimation::setDefaultTarget(const QDeclarativeMetaProperty &p) +void QDeclarativeAbstractAnimation::setDefaultTarget(const QDeclarativeProperty &p) { Q_D(QDeclarativeAbstractAnimation); d->defaultProperty = p; @@ -498,7 +498,7 @@ void QDeclarativeAbstractAnimation::setDisableUserControl() } void QDeclarativeAbstractAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction) { Q_UNUSED(actions); @@ -729,7 +729,7 @@ void QDeclarativeScriptActionPrivate::execute() } void QDeclarativeScriptAction::transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction) { Q_D(QDeclarativeScriptAction); @@ -912,7 +912,7 @@ QAbstractAnimation *QDeclarativePropertyAction::qtAnimation() } void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction) { Q_D(QDeclarativePropertyAction); @@ -925,7 +925,7 @@ void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions, { for (int ii = 0; ii < actions.count(); ++ii) { const QDeclarativeAction &action = actions.at(ii); - QDeclarativeMetaPropertyPrivate::write(action.property, action.toValue, QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::write(action.property, action.toValue, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); } } }; @@ -1133,7 +1133,7 @@ QAbstractAnimation *QDeclarativeParentAction::qtAnimation() } void QDeclarativeParentAction::transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction) { Q_D(QDeclarativeParentAction); @@ -1582,7 +1582,7 @@ QAbstractAnimation *QDeclarativeSequentialAnimation::qtAnimation() } void QDeclarativeSequentialAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction) { Q_D(QDeclarativeAnimationGroup); @@ -1647,7 +1647,7 @@ QAbstractAnimation *QDeclarativeParallelAnimation::qtAnimation() } void QDeclarativeParallelAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction) { Q_D(QDeclarativeAnimationGroup); @@ -2231,7 +2231,7 @@ struct PropertyUpdater : public QDeclarativeTimeLineValue QDeclarativeAction &action = actions[ii]; if (v == 1.) - QDeclarativeMetaPropertyPrivate::write(action.property, action.toValue, QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::write(action.property, action.toValue, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); else { if (!fromSourced && !fromDefined) { action.fromValue = action.property.read(); @@ -2246,7 +2246,7 @@ struct PropertyUpdater : public QDeclarativeTimeLineValue } } if (interpolator) - QDeclarativeMetaPropertyPrivate::write(action.property, interpolator(action.fromValue.constData(), action.toValue.constData(), v), QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::write(action.property, interpolator(action.fromValue.constData(), action.toValue.constData(), v), QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); } if (deleted) return; @@ -2257,7 +2257,7 @@ struct PropertyUpdater : public QDeclarativeTimeLineValue }; void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction) { Q_D(QDeclarativePropertyAnimation); diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 02dacb3..53afbb5 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -95,7 +95,7 @@ public: QDeclarativeAnimationGroup *group() const; void setGroup(QDeclarativeAnimationGroup *); - void setDefaultTarget(const QDeclarativeMetaProperty &); + void setDefaultTarget(const QDeclarativeProperty &); void setDisableUserControl(); void classBegin(); @@ -123,7 +123,7 @@ protected: public: enum TransitionDirection { Forward, Backward }; virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction); virtual QAbstractAnimation *qtAnimation() = 0; @@ -131,7 +131,7 @@ private Q_SLOTS: void timelineComplete(); private: - virtual void setTarget(const QDeclarativeMetaProperty &); + virtual void setTarget(const QDeclarativeProperty &); }; class QDeclarativePauseAnimationPrivate; @@ -177,7 +177,7 @@ public: protected: virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction); virtual QAbstractAnimation *qtAnimation(); }; @@ -221,7 +221,7 @@ Q_SIGNALS: protected: virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction); virtual QAbstractAnimation *qtAnimation(); }; @@ -248,7 +248,7 @@ public: protected: virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction); virtual QAbstractAnimation *qtAnimation(); }; @@ -300,7 +300,7 @@ public: protected: QDeclarativePropertyAnimation(QDeclarativePropertyAnimationPrivate &dd, QObject *parent); virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction); virtual QAbstractAnimation *qtAnimation(); @@ -426,7 +426,7 @@ public: protected: virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction); virtual QAbstractAnimation *qtAnimation(); }; @@ -442,7 +442,7 @@ public: protected: virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeMetaProperties &modified, + QDeclarativeProperties &modified, TransitionDirection direction); virtual QAbstractAnimation *qtAnimation(); }; diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index 65c9807..fc4e6e6 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -226,11 +226,11 @@ public: void commence(); - QDeclarativeMetaProperty defaultProperty; + QDeclarativeProperty defaultProperty; QDeclarativeAnimationGroup *group; - static QDeclarativeMetaProperty createProperty(QObject *obj, const QString &str, QObject *infoObj); + static QDeclarativeProperty createProperty(QObject *obj, const QString &str, QObject *infoObj); }; class QDeclarativePauseAnimationPrivate : public QDeclarativeAbstractAnimationPrivate diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index b1f1677..e0189dc 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include #include @@ -62,7 +62,7 @@ class QDeclarativeBehaviorPrivate : public QObjectPrivate public: QDeclarativeBehaviorPrivate() : animation(0), enabled(true) {} - QDeclarativeMetaProperty property; + QDeclarativeProperty property; QVariant currentValue; QDeclarativeAbstractAnimation *animation; bool enabled; @@ -157,7 +157,7 @@ void QDeclarativeBehavior::write(const QVariant &value) { Q_D(QDeclarativeBehavior); if (!d->animation || !d->enabled) { - QDeclarativeMetaPropertyPrivate::write(d->property, value, QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); return; } @@ -172,15 +172,15 @@ void QDeclarativeBehavior::write(const QVariant &value) action.toValue = value; actions << action; - QList after; + QList after; if (d->animation) d->animation->transition(actions, after, QDeclarativeAbstractAnimation::Forward); d->animation->qtAnimation()->start(); if (!after.contains(d->property)) - QDeclarativeMetaPropertyPrivate::write(d->property, value, QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); } -void QDeclarativeBehavior::setTarget(const QDeclarativeMetaProperty &property) +void QDeclarativeBehavior::setTarget(const QDeclarativeProperty &property) { Q_D(QDeclarativeBehavior); d->property = property; diff --git a/src/declarative/util/qdeclarativebehavior_p.h b/src/declarative/util/qdeclarativebehavior_p.h index fbc19f8..a633b55 100644 --- a/src/declarative/util/qdeclarativebehavior_p.h +++ b/src/declarative/util/qdeclarativebehavior_p.h @@ -70,7 +70,7 @@ public: QDeclarativeBehavior(QObject *parent=0); ~QDeclarativeBehavior(); - virtual void setTarget(const QDeclarativeMetaProperty &); + virtual void setTarget(const QDeclarativeProperty &); virtual void write(const QVariant &value); QDeclarativeAbstractAnimation *animation(); diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp index d75e98d..e95a03e 100644 --- a/src/declarative/util/qdeclarativebind.cpp +++ b/src/declarative/util/qdeclarativebind.cpp @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include @@ -196,7 +196,7 @@ void QDeclarativeBind::eval() if (!d->obj || d->value.isNull || !d->when || !d->componentComplete) return; - QDeclarativeMetaProperty prop(d->obj, d->prop); + QDeclarativeProperty prop(d->obj, d->prop); prop.write(d->value.value); } diff --git a/src/declarative/util/qdeclarativeeasefollow.cpp b/src/declarative/util/qdeclarativeeasefollow.cpp index 0430a0b..232dc90 100644 --- a/src/declarative/util/qdeclarativeeasefollow.cpp +++ b/src/declarative/util/qdeclarativeeasefollow.cpp @@ -43,7 +43,7 @@ #include "qdeclarativeanimation_p_p.h" -#include +#include #include @@ -77,7 +77,7 @@ public: qreal trackVelocity; - QDeclarativeMetaProperty target; + QDeclarativeProperty target; int clockOffset; int lastTick; @@ -500,7 +500,7 @@ void QDeclarativeEaseFollow::setEnabled(bool enabled) emit enabledChanged(); } -void QDeclarativeEaseFollow::setTarget(const QDeclarativeMetaProperty &t) +void QDeclarativeEaseFollow::setTarget(const QDeclarativeProperty &t) { Q_D(QDeclarativeEaseFollow); d->target = t; diff --git a/src/declarative/util/qdeclarativeeasefollow_p.h b/src/declarative/util/qdeclarativeeasefollow_p.h index 6d14eb5..83d1eff 100644 --- a/src/declarative/util/qdeclarativeeasefollow_p.h +++ b/src/declarative/util/qdeclarativeeasefollow_p.h @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeMetaProperty; +class QDeclarativeProperty; class QDeclarativeEaseFollowPrivate; class Q_DECLARATIVE_EXPORT QDeclarativeEaseFollow : public QObject, public QDeclarativePropertyValueSource @@ -94,7 +94,7 @@ public: qreal maximumEasingTime() const; void setMaximumEasingTime(qreal); - virtual void setTarget(const QDeclarativeMetaProperty &); + virtual void setTarget(const QDeclarativeProperty &); Q_SIGNALS: void sourceChanged(); diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 454fb06..9c2b1e6 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include @@ -153,19 +153,19 @@ public: virtual QString typeName() const { return QLatin1String("ReplaceSignalHandler"); } - QDeclarativeMetaProperty property; + QDeclarativeProperty property; QDeclarativeExpression *expression; QDeclarativeExpression *reverseExpression; QDeclarativeExpression *rewindExpression; QDeclarativeGuard ownedExpression; virtual void execute() { - ownedExpression = QDeclarativeMetaPropertyPrivate::setSignalExpression(property, expression); + ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, expression); } virtual bool isReversable() { return true; } virtual void reverse() { - ownedExpression = QDeclarativeMetaPropertyPrivate::setSignalExpression(property, reverseExpression); + ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, reverseExpression); } virtual void saveOriginals() { @@ -174,10 +174,10 @@ public: } virtual void rewind() { - ownedExpression = QDeclarativeMetaPropertyPrivate::setSignalExpression(property, rewindExpression); + ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, rewindExpression); } virtual void saveCurrentValues() { - rewindExpression = QDeclarativeMetaPropertyPrivate::signalExpression(property); + rewindExpression = QDeclarativePropertyPrivate::signalExpression(property); } virtual bool override(QDeclarativeActionEvent*other) { @@ -212,7 +212,7 @@ public: QList > expressions; QList signalReplacements; - QDeclarativeMetaProperty property(const QByteArray &); + QDeclarativeProperty property(const QByteArray &); }; void @@ -296,8 +296,8 @@ void QDeclarativePropertyChangesPrivate::decode() ds >> isScript; ds >> data; - QDeclarativeMetaProperty prop = property(name); //### better way to check for signal property? - if (prop.type() & QDeclarativeMetaProperty::SignalProperty) { + QDeclarativeProperty prop = property(name); //### better way to check for signal property? + if (prop.type() & QDeclarativeProperty::SignalProperty) { QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), data.toString(), object); QDeclarativeReplaceSignalHandler *handler = new QDeclarativeReplaceSignalHandler; handler->property = prop; @@ -371,17 +371,17 @@ void QDeclarativePropertyChanges::setRestoreEntryValues(bool v) d->restore = v; } -QDeclarativeMetaProperty +QDeclarativeProperty QDeclarativePropertyChangesPrivate::property(const QByteArray &property) { Q_Q(QDeclarativePropertyChanges); - QDeclarativeMetaProperty prop(object, QString::fromUtf8(property)); + QDeclarativeProperty prop(object, QString::fromUtf8(property)); if (!prop.isValid()) { qmlInfo(q) << QDeclarativePropertyChanges::tr("Cannot assign to non-existent property \"%1\"").arg(QString::fromUtf8(property)); - return QDeclarativeMetaProperty(); - } else if (!(prop.type() & QDeclarativeMetaProperty::SignalProperty) && !prop.isWritable()) { + return QDeclarativeProperty(); + } else if (!(prop.type() & QDeclarativeProperty::SignalProperty) && !prop.isWritable()) { qmlInfo(q) << QDeclarativePropertyChanges::tr("Cannot assign to read-only property \"%1\"").arg(QString::fromUtf8(property)); - return QDeclarativeMetaProperty(); + return QDeclarativeProperty(); } return prop; } @@ -426,7 +426,7 @@ QDeclarativePropertyChanges::ActionList QDeclarativePropertyChanges::actions() for (int ii = 0; ii < d->expressions.count(); ++ii) { QByteArray property = d->expressions.at(ii).first; - QDeclarativeMetaProperty prop = d->property(property); + QDeclarativeProperty prop = d->property(property); if (prop.isValid()) { QDeclarativeAction a; diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp index b26a7e2..012e6a0 100644 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ b/src/declarative/util/qdeclarativespringfollow.cpp @@ -63,7 +63,7 @@ public: , mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.01) , modulus(0.0), useMass(false), haveModulus(false), enabled(true), mode(Track), clock(this) {} - QDeclarativeMetaProperty property; + QDeclarativeProperty property; qreal currentValue; qreal sourceValue; qreal maxVelocity; @@ -254,7 +254,7 @@ QDeclarativeSpringFollow::~QDeclarativeSpringFollow() { } -void QDeclarativeSpringFollow::setTarget(const QDeclarativeMetaProperty &property) +void QDeclarativeSpringFollow::setTarget(const QDeclarativeProperty &property) { Q_D(QDeclarativeSpringFollow); d->property = property; diff --git a/src/declarative/util/qdeclarativespringfollow_p.h b/src/declarative/util/qdeclarativespringfollow_p.h index 63d38a4..2ac0d82 100644 --- a/src/declarative/util/qdeclarativespringfollow_p.h +++ b/src/declarative/util/qdeclarativespringfollow_p.h @@ -74,7 +74,7 @@ public: QDeclarativeSpringFollow(QObject *parent=0); ~QDeclarativeSpringFollow(); - virtual void setTarget(const QDeclarativeMetaProperty &); + virtual void setTarget(const QDeclarativeProperty &); qreal sourceValue() const; void setSourceValue(qreal value); diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp index 3b06e33..1d70d33 100644 --- a/src/declarative/util/qdeclarativestate.cpp +++ b/src/declarative/util/qdeclarativestate.cpp @@ -334,7 +334,7 @@ void QDeclarativeState::cancel() void QDeclarativeAction::deleteFromBinding() { if (fromBinding) { - QDeclarativeMetaPropertyPrivate::setBinding(property, 0); + QDeclarativePropertyPrivate::setBinding(property, 0); fromBinding->destroy(); fromBinding = 0; } @@ -388,7 +388,7 @@ void QDeclarativeState::apply(QDeclarativeStateGroup *group, QDeclarativeTransit else if (action.event->isRewindable()) action.event->saveCurrentValues(); } else { - action.fromBinding = QDeclarativeMetaPropertyPrivate::binding(action.property); + action.fromBinding = QDeclarativePropertyPrivate::binding(action.property); for (jj = 0; jj < d->revertList.count(); ++jj) { if (d->revertList.at(jj).property == action.property) { @@ -437,7 +437,7 @@ void QDeclarativeState::apply(QDeclarativeStateGroup *group, QDeclarativeTransit if (!found) { QVariant cur = d->revertList.at(ii).property.read(); QDeclarativeAbstractBinding *delBinding = - QDeclarativeMetaPropertyPrivate::setBinding(d->revertList.at(ii).property, 0); + QDeclarativePropertyPrivate::setBinding(d->revertList.at(ii).property, 0); if (delBinding) delBinding->destroy(); diff --git a/src/declarative/util/qdeclarativestate_p.h b/src/declarative/util/qdeclarativestate_p.h index 4a62481..abdbec5 100644 --- a/src/declarative/util/qdeclarativestate_p.h +++ b/src/declarative/util/qdeclarativestate_p.h @@ -43,7 +43,7 @@ #define QDECLARATIVESTATE_H #include -#include +#include #include QT_BEGIN_HEADER @@ -65,7 +65,7 @@ public: bool reverseEvent:1; bool deletableToBinding:1; - QDeclarativeMetaProperty property; + QDeclarativeProperty property; QVariant fromValue; QVariant toValue; diff --git a/src/declarative/util/qdeclarativestate_p_p.h b/src/declarative/util/qdeclarativestate_p_p.h index 6b32f04..6f52219 100644 --- a/src/declarative/util/qdeclarativestate_p_p.h +++ b/src/declarative/util/qdeclarativestate_p_p.h @@ -58,7 +58,7 @@ #include "qdeclarativeanimation_p_p.h" #include "qdeclarativetransitionmanager_p_p.h" -#include +#include #include #include @@ -77,7 +77,7 @@ public: event = a.event; if (state == StartState) { value = a.fromValue; - binding = QDeclarativeMetaPropertyPrivate::binding(property); + binding = QDeclarativePropertyPrivate::binding(property); reverseEvent = true; } else { value = a.toValue; @@ -86,7 +86,7 @@ public: } } - QDeclarativeMetaProperty property; + QDeclarativeProperty property; QVariant value; QDeclarativeAbstractBinding *binding; QObject *specifiedObject; @@ -139,7 +139,7 @@ public: QDeclarativeTransitionManager transitionManager; SimpleActionList revertList; - QList reverting; + QList reverting; QString extends; mutable bool inState; QDeclarativeStateGroup *group; diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 98edf85..9df8658 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -661,19 +661,19 @@ QList QDeclarativeAnchorChanges::extraActions() if (d->target) { QDeclarativeAction a; a.fromValue = d->fromX; - a.property = QDeclarativeMetaProperty(d->target, QLatin1String("x")); + a.property = QDeclarativeProperty(d->target, QLatin1String("x")); extra << a; a.fromValue = d->fromY; - a.property = QDeclarativeMetaProperty(d->target, QLatin1String("y")); + a.property = QDeclarativeProperty(d->target, QLatin1String("y")); extra << a; a.fromValue = d->fromWidth; - a.property = QDeclarativeMetaProperty(d->target, QLatin1String("width")); + a.property = QDeclarativeProperty(d->target, QLatin1String("width")); extra << a; a.fromValue = d->fromHeight; - a.property = QDeclarativeMetaProperty(d->target, QLatin1String("height")); + a.property = QDeclarativeProperty(d->target, QLatin1String("height")); extra << a; } diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp index 3482814..ac07b10 100644 --- a/src/declarative/util/qdeclarativetransition.cpp +++ b/src/declarative/util/qdeclarativetransition.cpp @@ -148,7 +148,7 @@ void QDeclarativeTransition::setReversed(bool r) } void QDeclarativeTransition::prepare(QDeclarativeStateOperation::ActionList &actions, - QList &after, + QList &after, QDeclarativeTransitionManager *endState) { Q_D(QDeclarativeTransition); diff --git a/src/declarative/util/qdeclarativetransition_p.h b/src/declarative/util/qdeclarativetransition_p.h index 96448b8..861111a 100644 --- a/src/declarative/util/qdeclarativetransition_p.h +++ b/src/declarative/util/qdeclarativetransition_p.h @@ -85,7 +85,7 @@ public: QDeclarativeListProperty animations(); void prepare(QDeclarativeStateOperation::ActionList &actions, - QList &after, + QList &after, QDeclarativeTransitionManager *end); void setReversed(bool r); diff --git a/src/declarative/util/qdeclarativetransitionmanager.cpp b/src/declarative/util/qdeclarativetransitionmanager.cpp index 6429dab..e1143fa 100644 --- a/src/declarative/util/qdeclarativetransitionmanager.cpp +++ b/src/declarative/util/qdeclarativetransitionmanager.cpp @@ -45,7 +45,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -85,7 +85,7 @@ void QDeclarativeTransitionManager::complete() d->applyBindings(); for (int ii = 0; ii < d->completeList.count(); ++ii) { - const QDeclarativeMetaProperty &prop = d->completeList.at(ii).property; + const QDeclarativeProperty &prop = d->completeList.at(ii).property; prop.write(d->completeList.at(ii).value); } @@ -99,7 +99,7 @@ void QDeclarativeTransitionManagerPrivate::applyBindings() { foreach(const QDeclarativeAction &action, bindingsList) { if (action.toBinding) { - QDeclarativeMetaPropertyPrivate::setBinding(action.property, action.toBinding); + QDeclarativePropertyPrivate::setBinding(action.property, action.toBinding); } else if (action.event) { if (action.reverseEvent) action.event->reverse(); @@ -123,7 +123,7 @@ void QDeclarativeTransitionManager::transition(const QList & if (action.toBinding) d->bindingsList << action; if (action.fromBinding) - QDeclarativeMetaPropertyPrivate::setBinding(action.property, 0); // Disable current binding + QDeclarativePropertyPrivate::setBinding(action.property, 0); // Disable current binding if (action.event && action.event->changesBindings()) { //### assume isReversable()? d->bindingsList << action; if (action.reverseEvent) @@ -150,9 +150,9 @@ void QDeclarativeTransitionManager::transition(const QList & for (int ii = 0; ii < applyList.size(); ++ii) { const QDeclarativeAction &action = applyList.at(ii); if (action.toBinding) { - QDeclarativeMetaPropertyPrivate::setBinding(action.property, action.toBinding, QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::setBinding(action.property, action.toBinding, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); } else if (!action.event) { - QDeclarativeMetaPropertyPrivate::write(action.property, action.toValue, QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::write(action.property, action.toValue, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); } else if (action.event->isReversable()) { if (action.reverseEvent) action.event->reverse(); @@ -167,7 +167,7 @@ void QDeclarativeTransitionManager::transition(const QList & QDeclarativeAction *action = &applyList[ii]; if (action->event) continue; - const QDeclarativeMetaProperty &prop = action->property; + const QDeclarativeProperty &prop = action->property; if (action->toBinding || !action->toValue.isValid()) { //### is this always right (used for exta actions) action->toValue = prop.read(); } @@ -191,14 +191,14 @@ void QDeclarativeTransitionManager::transition(const QList & } if (action.toBinding) - QDeclarativeMetaPropertyPrivate::setBinding(action.property, 0); // Make sure this is disabled during the transition + QDeclarativePropertyPrivate::setBinding(action.property, 0); // Make sure this is disabled during the transition - QDeclarativeMetaPropertyPrivate::write(action.property, action.fromValue, QDeclarativeMetaPropertyPrivate::BypassInterceptor | QDeclarativeMetaPropertyPrivate::DontRemoveBinding); + QDeclarativePropertyPrivate::write(action.property, action.fromValue, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); } } if (transition) { - QList touched; + QList touched; d->transition = transition; d->transition->prepare(applyList, touched, this); @@ -267,7 +267,7 @@ void QDeclarativeTransitionManager::cancel() for(int i = 0; i < d->bindingsList.count(); ++i) { QDeclarativeAction action = d->bindingsList[i]; if (action.toBinding && action.deletableToBinding) { - QDeclarativeMetaPropertyPrivate::setBinding(action.property, 0); + QDeclarativePropertyPrivate::setBinding(action.property, 0); action.toBinding->destroy(); action.toBinding = 0; action.deletableToBinding = false; diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 669213c..42ff523 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -41,7 +41,7 @@ SUBDIRS += \ qdeclarativelanguage \ # Cover qdeclarativelistreference \ # Cover qdeclarativelistmodel \ # Cover - qdeclarativemetaproperty \ # Cover + qdeclarativeproperty \ # Cover qdeclarativemetatype \ # Cover qdeclarativemoduleplugin \ # Cover qdeclarativenumberformatter \ # Cover diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp index 8d5a1f6..0c3ca76 100644 --- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp +++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include "../shared/debugutil_p.h" @@ -218,7 +218,7 @@ void tst_QDeclarativeDebug::recursiveObjectTest(QObject *o, const QDeclarativeDe QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName())); QDeclarativeAbstractBinding *binding = - QDeclarativeMetaPropertyPrivate::binding(QDeclarativeMetaProperty(o, p.name())); + QDeclarativePropertyPrivate::binding(QDeclarativeProperty(o, p.name())); if (binding) QCOMPARE(binding->expression(), p.binding()); diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h index fc1ede7..8ac7aa6 100644 --- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h +++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h @@ -52,7 +52,7 @@ #include #include #include -#include +#include QVariant myCustomVariantTypeConverter(const QString &data); @@ -480,8 +480,8 @@ public: MyPropertyValueSource() : QDeclarativePropertyValueSource() {} - QDeclarativeMetaProperty prop; - virtual void setTarget(const QDeclarativeMetaProperty &p) + QDeclarativeProperty prop; + virtual void setTarget(const QDeclarativeProperty &p) { prop = p; } diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 2907757..1ba4454 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include "testtypes.h" @@ -747,14 +747,14 @@ void tst_qdeclarativelanguage::valueTypes() // ### #if 0 - QDeclarativeMetaProperty p(object, "rectProperty.x"); + QDeclarativeProperty p(object, "rectProperty.x"); QCOMPARE(p.read(), QVariant(12)); p.write(13); QCOMPARE(p.read(), QVariant(13)); - quint32 r = QDeclarativeMetaPropertyPrivate::saveValueType(p.coreIndex(), p.valueTypeCoreIndex()); - QDeclarativeMetaProperty p2; - QDeclarativeMetaPropertyPrivate::restore(p2, r, object); + quint32 r = QDeclarativePropertyPrivate::saveValueType(p.coreIndex(), p.valueTypeCoreIndex()); + QDeclarativeProperty p2; + QDeclarativePropertyPrivate::restore(p2, r, object); QCOMPARE(p2.read(), QVariant(13)); #endif } diff --git a/tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp b/tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp index fdcb98a..1b7af19 100644 --- a/tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp +++ b/tests/auto/declarative/qdeclarativelistreference/tst_qdeclarativelistreference.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include inline QUrl TEST_FILE(const QString &filename) @@ -530,7 +530,7 @@ void tst_qdeclarativelistreference::qmlmetaproperty() tt.data.append(0); tt.data.append(&tt); - QDeclarativeMetaProperty prop(&tt, QLatin1String("data")); + QDeclarativeProperty prop(&tt, QLatin1String("data")); QVariant v = prop.read(); QVERIFY(v.userType() == qMetaTypeId()); QDeclarativeListReference ref = qvariant_cast(v); @@ -546,11 +546,11 @@ void tst_qdeclarativelistreference::engineTypes() QObject *o = component.create(); QVERIFY(o); - QDeclarativeMetaProperty p1(o, QLatin1String("myList")); - QVERIFY(p1.propertyTypeCategory() == QDeclarativeMetaProperty::Normal); + QDeclarativeProperty p1(o, QLatin1String("myList")); + QVERIFY(p1.propertyTypeCategory() == QDeclarativeProperty::Normal); - QDeclarativeMetaProperty p2(o, QLatin1String("myList"), engine.rootContext()); - QVERIFY(p2.propertyTypeCategory() == QDeclarativeMetaProperty::List); + QDeclarativeProperty p2(o, QLatin1String("myList"), engine.rootContext()); + QVERIFY(p2.propertyTypeCategory() == QDeclarativeProperty::List); QVariant v = p2.read(); QVERIFY(v.userType() == qMetaTypeId()); QDeclarativeListReference ref = qvariant_cast(v); diff --git a/tests/auto/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro b/tests/auto/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro deleted file mode 100644 index 7170469..0000000 --- a/tests/auto/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_qdeclarativemetaproperty.cpp diff --git a/tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp b/tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp deleted file mode 100644 index a7e9d0d..0000000 --- a/tests/auto/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp +++ /dev/null @@ -1,1186 +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 test suite 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$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include - -class MyQmlObject : public QObject -{ - Q_OBJECT -public: - MyQmlObject() {} -}; - -QML_DECLARE_TYPE(MyQmlObject); - -class MyAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(int foo READ foo WRITE setFoo) -public: - MyAttached(QObject *parent) : QObject(parent), m_foo(13) {} - - int foo() const { return m_foo; } - void setFoo(int f) { m_foo = f; } - -private: - int m_foo; -}; - -class MyContainer : public QObject -{ - Q_OBJECT - Q_PROPERTY(QDeclarativeListProperty children READ children) -public: - MyContainer() {} - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, m_children); } - - static MyAttached *qmlAttachedProperties(QObject *o) { - return new MyAttached(o); - } - -private: - QList m_children; -}; - -QML_DECLARE_TYPE(MyContainer); -QML_DECLARE_TYPEINFO(MyContainer, QML_HAS_ATTACHED_PROPERTIES) - -class tst_qdeclarativemetaproperty : public QObject -{ - Q_OBJECT -public: - tst_qdeclarativemetaproperty() {} - -private slots: - void initTestCase(); - - // Constructors - void qmlmetaproperty(); - void qmlmetaproperty_object(); - void qmlmetaproperty_object_string(); - void qmlmetaproperty_object_context(); - void qmlmetaproperty_object_string_context(); - - // Methods - void name(); - void read(); - void write(); - void reset(); - - // Functionality - void writeObjectToList(); - void writeListToList(); - - //writeToReadOnly(); - - // Bugs - void crashOnValueProperty(); - - void copy(); -private: - QDeclarativeEngine engine; -}; - -void tst_qdeclarativemetaproperty::qmlmetaproperty() -{ - QDeclarativeMetaProperty prop; - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString()); - QCOMPARE(prop.read(), QVariant()); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), false); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::Invalid); - QCOMPARE(prop.isProperty(), false); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), false); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), false); - QCOMPARE(prop.object(), (QObject *)0); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::InvalidCategory); - QCOMPARE(prop.propertyType(), 0); - QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), -1); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; -} - -class PropertyObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(int defaultProperty READ defaultProperty); - Q_PROPERTY(QRect rectProperty READ rectProperty); - Q_PROPERTY(QRect wrectProperty READ wrectProperty WRITE setWRectProperty); - Q_PROPERTY(QUrl url READ url WRITE setUrl); - Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty); - - Q_CLASSINFO("DefaultProperty", "defaultProperty"); -public: - PropertyObject() : m_resetProperty(9) {} - - int defaultProperty() { return 10; } - QRect rectProperty() { return QRect(10, 10, 1, 209); } - - QRect wrectProperty() { return m_rect; } - void setWRectProperty(const QRect &r) { m_rect = r; } - - QUrl url() { return m_url; } - void setUrl(const QUrl &u) { m_url = u; } - - int resettableProperty() const { return m_resetProperty; } - void setResettableProperty(int r) { m_resetProperty = r; } - void resetProperty() { m_resetProperty = 9; } - -signals: - void clicked(); - -private: - int m_resetProperty; - QRect m_rect; - QUrl m_url; -}; - -QML_DECLARE_TYPE(PropertyObject); - -void tst_qdeclarativemetaproperty::qmlmetaproperty_object() -{ - QObject object; // Has no default property - PropertyObject dobject; // Has default property - - { - QDeclarativeMetaProperty prop(&object); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString()); - QCOMPARE(prop.read(), QVariant()); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), false); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::Invalid); - QCOMPARE(prop.isProperty(), false); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), false); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), false); - QCOMPARE(prop.object(), (QObject *)0); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::InvalidCategory); - QCOMPARE(prop.propertyType(), 0); - QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), -1); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } - - { - QDeclarativeMetaProperty prop(&dobject); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - binding->setTarget(prop); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString("defaultProperty")); - QCOMPARE(prop.read(), QVariant(10)); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), true); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), (QDeclarativeMetaProperty::Type)(QDeclarativeMetaProperty::Property | QDeclarativeMetaProperty::Default)); - QCOMPARE(prop.isProperty(), true); - QCOMPARE(prop.isDefault(), true); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), true); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), true); - QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(prop.propertyType(), (int)QVariant::Int); - QCOMPARE(prop.propertyTypeName(), "int"); - QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding != 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == binding); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } -} - -void tst_qdeclarativemetaproperty::qmlmetaproperty_object_string() -{ - QObject object; - PropertyObject dobject; - - { - QDeclarativeMetaProperty prop(&object, QString("defaultProperty")); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString()); - QCOMPARE(prop.read(), QVariant()); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), false); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::Invalid); - QCOMPARE(prop.isProperty(), false); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), false); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), false); - QCOMPARE(prop.object(), (QObject *)0); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::InvalidCategory); - QCOMPARE(prop.propertyType(), 0); - QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), -1); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } - - { - QDeclarativeMetaProperty prop(&dobject, QString("defaultProperty")); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - binding->setTarget(prop); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString("defaultProperty")); - QCOMPARE(prop.read(), QVariant(10)); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), true); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::Property); - QCOMPARE(prop.isProperty(), true); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), true); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), true); - QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(prop.propertyType(), (int)QVariant::Int); - QCOMPARE(prop.propertyTypeName(), "int"); - QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding != 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == binding); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } - - { - QDeclarativeMetaProperty prop(&dobject, QString("onClicked")); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - binding->setTarget(prop); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString("onClicked")); - QCOMPARE(prop.read(), QVariant()); - QCOMPARE(prop.write(QVariant("Hello")), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), false); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QCOMPARE(QString(prop.method().signature()), QString("clicked()")); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::SignalProperty); - QCOMPARE(prop.isProperty(), false); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), false); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), true); - QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::InvalidCategory); - QCOMPARE(prop.propertyType(), 0); - QCOMPARE(prop.propertyTypeName(), (const char *)0); - QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression != 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == expression); - QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("clicked()")); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } -} - -void tst_qdeclarativemetaproperty::qmlmetaproperty_object_context() -{ - QObject object; // Has no default property - PropertyObject dobject; // Has default property - - { - QDeclarativeMetaProperty prop(&object, engine.rootContext()); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString()); - QCOMPARE(prop.read(), QVariant()); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), false); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::Invalid); - QCOMPARE(prop.isProperty(), false); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), false); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), false); - QCOMPARE(prop.object(), (QObject *)0); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::InvalidCategory); - QCOMPARE(prop.propertyType(), 0); - QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), -1); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } - - { - QDeclarativeMetaProperty prop(&dobject, engine.rootContext()); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - binding->setTarget(prop); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString("defaultProperty")); - QCOMPARE(prop.read(), QVariant(10)); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), true); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), (QDeclarativeMetaProperty::Type)(QDeclarativeMetaProperty::Property | QDeclarativeMetaProperty::Default)); - QCOMPARE(prop.isProperty(), true); - QCOMPARE(prop.isDefault(), true); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), true); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), true); - QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(prop.propertyType(), (int)QVariant::Int); - QCOMPARE(prop.propertyTypeName(), "int"); - QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding != 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == binding); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } -} - -void tst_qdeclarativemetaproperty::qmlmetaproperty_object_string_context() -{ - QObject object; - PropertyObject dobject; - - { - QDeclarativeMetaProperty prop(&object, QString("defaultProperty"), engine.rootContext()); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString()); - QCOMPARE(prop.read(), QVariant()); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), false); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::Invalid); - QCOMPARE(prop.isProperty(), false); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), false); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), false); - QCOMPARE(prop.object(), (QObject *)0); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::InvalidCategory); - QCOMPARE(prop.propertyType(), 0); - QCOMPARE(prop.propertyTypeName(), (const char *)0); - QVERIFY(prop.property().name() == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), -1); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } - - { - QDeclarativeMetaProperty prop(&dobject, QString("defaultProperty"), engine.rootContext()); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - binding->setTarget(prop); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString("defaultProperty")); - QCOMPARE(prop.read(), QVariant(10)); - QCOMPARE(prop.write(QVariant()), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), true); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QVERIFY(prop.method().signature() == 0); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::Property); - QCOMPARE(prop.isProperty(), true); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), true); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), true); - QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(prop.propertyType(), (int)QVariant::Int); - QCOMPARE(prop.propertyTypeName(), "int"); - QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding != 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == binding); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression == 0); - QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } - - { - QDeclarativeMetaProperty prop(&dobject, QString("onClicked"), engine.rootContext()); - - QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); - binding->setTarget(prop); - QVERIFY(binding != 0); - QGuard expression(new QDeclarativeExpression()); - QVERIFY(expression != 0); - - QObject *obj = new QObject; - - QCOMPARE(prop.name(), QString("onClicked")); - QCOMPARE(prop.read(), QVariant()); - QCOMPARE(prop.write(QVariant("Hello")), false); - QCOMPARE(prop.hasChangedNotifier(), false); - QCOMPARE(prop.needsChangedNotifier(), false); - QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); - QCOMPARE(prop.connectNotifier(obj, 0), false); - QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); - QCOMPARE(prop.connectNotifier(obj, -1), false); - QCOMPARE(QString(prop.method().signature()), QString("clicked()")); - QCOMPARE(prop.type(), QDeclarativeMetaProperty::SignalProperty); - QCOMPARE(prop.isProperty(), false); - QCOMPARE(prop.isDefault(), false); - QCOMPARE(prop.isWritable(), false); - QCOMPARE(prop.isDesignable(), false); - QCOMPARE(prop.isResettable(), false); - QCOMPARE(prop.isValid(), true); - QCOMPARE(prop.object(), &dobject); - QCOMPARE(prop.propertyTypeCategory(), QDeclarativeMetaProperty::InvalidCategory); - QCOMPARE(prop.propertyType(), 0); - QCOMPARE(prop.propertyTypeName(), (const char *)0); - QCOMPARE(prop.property().name(), (const char *)0); - QVERIFY(QDeclarativeMetaPropertyPrivate::binding(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setBinding(prop, binding) == 0); - QVERIFY(binding == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::setSignalExpression(prop, expression) == 0); - QVERIFY(expression != 0); - QVERIFY(QDeclarativeMetaPropertyPrivate::signalExpression(prop) == expression); - QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("clicked()")); - QCOMPARE(QDeclarativeMetaPropertyPrivate::valueTypeCoreIndex(prop), -1); - - delete obj; - } -} - -void tst_qdeclarativemetaproperty::name() -{ - { - QDeclarativeMetaProperty p; - QCOMPARE(p.name(), QString()); - } - - { - PropertyObject o; - QDeclarativeMetaProperty p(&o); - QCOMPARE(p.name(), QString("defaultProperty")); - } - - { - QObject o; - QDeclarativeMetaProperty p(&o, QString("objectName")); - QCOMPARE(p.name(), QString("objectName")); - } - - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "onClicked"); - QCOMPARE(p.name(), QString("onClicked")); - } - - { - QObject o; - QDeclarativeMetaProperty p(&o, "onClicked"); - QCOMPARE(p.name(), QString()); - } - - { - QObject o; - QDeclarativeMetaProperty p(&o, "foo"); - QCOMPARE(p.name(), QString()); - } - - { - QDeclarativeMetaProperty p(0, "foo"); - QCOMPARE(p.name(), QString()); - } - - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "rectProperty"); - QCOMPARE(p.name(), QString("rectProperty")); - } - - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "rectProperty.x"); - QCOMPARE(p.name(), QString("rectProperty.x")); - } - - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "rectProperty.foo"); - QCOMPARE(p.name(), QString()); - } -} - -void tst_qdeclarativemetaproperty::read() -{ - // Invalid - { - QDeclarativeMetaProperty p; - QCOMPARE(p.read(), QVariant()); - } - - // Default prop - { - PropertyObject o; - QDeclarativeMetaProperty p(&o); - QCOMPARE(p.read(), QVariant(10)); - } - - // Invalid default prop - { - QObject o; - QDeclarativeMetaProperty p(&o); - QCOMPARE(p.read(), QVariant()); - } - - // Value prop by name - { - QObject o; - - QDeclarativeMetaProperty p(&o, "objectName"); - QCOMPARE(p.read(), QVariant(QString())); - - o.setObjectName("myName"); - - QCOMPARE(p.read(), QVariant("myName")); - } - - // Value-type prop - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "rectProperty.x"); - QCOMPARE(p.read(), QVariant(10)); - } - - // Invalid value-type prop - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "rectProperty.foo"); - QCOMPARE(p.read(), QVariant()); - } - - // Signal property - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "onClicked"); - QCOMPARE(p.read(), QVariant()); - - QVERIFY(0 == QDeclarativeMetaPropertyPrivate::setSignalExpression(p, new QDeclarativeExpression())); - QVERIFY(0 != QDeclarativeMetaPropertyPrivate::signalExpression(p)); - - QCOMPARE(p.read(), QVariant()); - } - - // Deleted object - { - PropertyObject *o = new PropertyObject; - QDeclarativeMetaProperty p(o, "rectProperty.x"); - QCOMPARE(p.read(), QVariant(10)); - delete o; - QCOMPARE(p.read(), QVariant()); - } - - // Attached property - { - QDeclarativeComponent component(&engine); - component.setData("import Test 1.0\nMyContainer { }", QUrl()); - QObject *object = component.create(); - QVERIFY(object != 0); - - QDeclarativeMetaProperty p(object, "MyContainer.foo", qmlContext(object)); - QCOMPARE(p.read(), QVariant(13)); - delete object; - } - { - QDeclarativeComponent component(&engine); - component.setData("import Test 1.0\nMyContainer { MyContainer.foo: 10 }", QUrl()); - QObject *object = component.create(); - QVERIFY(object != 0); - - QDeclarativeMetaProperty p(object, "MyContainer.foo", qmlContext(object)); - QCOMPARE(p.read(), QVariant(10)); - delete object; - } - { - QDeclarativeComponent component(&engine); - component.setData("import Test 1.0 as Foo\nFoo.MyContainer { Foo.MyContainer.foo: 10 }", QUrl()); - QObject *object = component.create(); - QVERIFY(object != 0); - - QDeclarativeMetaProperty p(object, "Foo.MyContainer.foo", qmlContext(object)); - QCOMPARE(p.read(), QVariant(10)); - delete object; - } -} - -void tst_qdeclarativemetaproperty::write() -{ - // Invalid - { - QDeclarativeMetaProperty p; - QCOMPARE(p.write(QVariant(10)), false); - } - - // Read-only default prop - { - PropertyObject o; - QDeclarativeMetaProperty p(&o); - QCOMPARE(p.write(QVariant(10)), false); - } - - // Invalid default prop - { - QObject o; - QDeclarativeMetaProperty p(&o); - QCOMPARE(p.write(QVariant(10)), false); - } - - // Read-only prop by name - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, QString("defaultProperty")); - QCOMPARE(p.write(QVariant(10)), false); - } - - // Writable prop by name - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, QString("objectName")); - QCOMPARE(o.objectName(), QString()); - QCOMPARE(p.write(QVariant(QString("myName"))), true); - QCOMPARE(o.objectName(), QString("myName")); - } - - // Deleted object - { - PropertyObject *o = new PropertyObject; - QDeclarativeMetaProperty p(o, QString("objectName")); - QCOMPARE(p.write(QVariant(QString("myName"))), true); - QCOMPARE(o->objectName(), QString("myName")); - - delete o; - - QCOMPARE(p.write(QVariant(QString("myName"))), false); - } - - // Signal property - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "onClicked"); - QCOMPARE(p.write(QVariant("console.log(1921)")), false); - - QVERIFY(0 == QDeclarativeMetaPropertyPrivate::setSignalExpression(p, new QDeclarativeExpression())); - QVERIFY(0 != QDeclarativeMetaPropertyPrivate::signalExpression(p)); - - QCOMPARE(p.write(QVariant("console.log(1921)")), false); - - QVERIFY(0 != QDeclarativeMetaPropertyPrivate::signalExpression(p)); - } - - // Value-type property - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "wrectProperty"); - - QCOMPARE(o.wrectProperty(), QRect()); - QCOMPARE(p.write(QRect(1, 13, 99, 8)), true); - QCOMPARE(o.wrectProperty(), QRect(1, 13, 99, 8)); - - QDeclarativeMetaProperty p2(&o, "wrectProperty.x"); - QCOMPARE(p2.read(), QVariant(1)); - QCOMPARE(p2.write(QVariant(6)), true); - QCOMPARE(p2.read(), QVariant(6)); - QCOMPARE(o.wrectProperty(), QRect(6, 13, 99, 8)); - } - - // URL-property - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "url"); - - QCOMPARE(p.write(QUrl("main.qml")), true); - QCOMPARE(o.url(), QUrl("main.qml")); - - QDeclarativeMetaProperty p2(&o, "url", engine.rootContext()); - - QUrl result = engine.baseUrl().resolved(QUrl("main.qml")); - QVERIFY(result != QUrl("main.qml")); - - QCOMPARE(p2.write(QUrl("main.qml")), true); - QCOMPARE(o.url(), result); - } - - // Attached property - { - QDeclarativeComponent component(&engine); - component.setData("import Test 1.0\nMyContainer { }", QUrl()); - QObject *object = component.create(); - QVERIFY(object != 0); - - QDeclarativeMetaProperty p(object, "MyContainer.foo", qmlContext(object)); - p.write(QVariant(99)); - QCOMPARE(p.read(), QVariant(99)); - delete object; - } - { - QDeclarativeComponent component(&engine); - component.setData("import Test 1.0 as Foo\nFoo.MyContainer { Foo.MyContainer.foo: 10 }", QUrl()); - QObject *object = component.create(); - QVERIFY(object != 0); - - QDeclarativeMetaProperty p(object, "Foo.MyContainer.foo", qmlContext(object)); - p.write(QVariant(99)); - QCOMPARE(p.read(), QVariant(99)); - delete object; - } -} - -void tst_qdeclarativemetaproperty::reset() -{ - // Invalid - { - QDeclarativeMetaProperty p; - QCOMPARE(p.isResettable(), false); - QCOMPARE(p.reset(), false); - } - - // Read-only default prop - { - PropertyObject o; - QDeclarativeMetaProperty p(&o); - QCOMPARE(p.isResettable(), false); - QCOMPARE(p.reset(), false); - } - - // Invalid default prop - { - QObject o; - QDeclarativeMetaProperty p(&o); - QCOMPARE(p.isResettable(), false); - QCOMPARE(p.reset(), false); - } - - // Non-resettable-only prop by name - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, QString("defaultProperty")); - QCOMPARE(p.isResettable(), false); - QCOMPARE(p.reset(), false); - } - - // Resettable prop by name - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, QString("resettableProperty")); - - QCOMPARE(p.read(), QVariant(9)); - QCOMPARE(p.write(QVariant(11)), true); - QCOMPARE(p.read(), QVariant(11)); - - QCOMPARE(p.isResettable(), true); - QCOMPARE(p.reset(), true); - - QCOMPARE(p.read(), QVariant(9)); - } - - // Deleted object - { - PropertyObject *o = new PropertyObject; - - QDeclarativeMetaProperty p(o, QString("resettableProperty")); - - QCOMPARE(p.isResettable(), true); - QCOMPARE(p.reset(), true); - - delete o; - - QCOMPARE(p.isResettable(), false); - QCOMPARE(p.reset(), false); - } - - // Signal property - { - PropertyObject o; - QDeclarativeMetaProperty p(&o, "onClicked"); - - QCOMPARE(p.isResettable(), false); - QCOMPARE(p.reset(), false); - } -} - -void tst_qdeclarativemetaproperty::writeObjectToList() -{ - QDeclarativeComponent containerComponent(&engine); - containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl()); - MyContainer *container = qobject_cast(containerComponent.create()); - QVERIFY(container != 0); - QDeclarativeListReference list(container, "children"); - QVERIFY(list.count() == 1); - - MyQmlObject *object = new MyQmlObject; - QDeclarativeMetaProperty prop(container, "children"); - prop.write(qVariantFromValue(object)); - QCOMPARE(list.count(), 1); - QCOMPARE(list.at(0), object); -} - -Q_DECLARE_METATYPE(QList); -void tst_qdeclarativemetaproperty::writeListToList() -{ - QDeclarativeComponent containerComponent(&engine); - containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl()); - MyContainer *container = qobject_cast(containerComponent.create()); - QVERIFY(container != 0); - QDeclarativeListReference list(container, "children"); - QVERIFY(list.count() == 1); - - QList objList; - objList << new MyQmlObject() << new MyQmlObject() << new MyQmlObject() << new MyQmlObject(); - QDeclarativeMetaProperty prop(container, "children"); - prop.write(qVariantFromValue(objList)); - QCOMPARE(list.count(), 4); - - //XXX need to try this with read/write prop (for read-only it correctly doesn't write) - /*QList typedObjList; - typedObjList << new MyQmlObject(); - prop.write(qVariantFromValue(&typedObjList)); - QCOMPARE(container->children()->size(), 1);*/ -} - -void tst_qdeclarativemetaproperty::crashOnValueProperty() -{ - QDeclarativeEngine *engine = new QDeclarativeEngine; - QDeclarativeComponent component(engine); - - component.setData("import Test 1.0\nPropertyObject { wrectProperty.x: 10 }", QUrl()); - PropertyObject *obj = qobject_cast(component.create()); - QVERIFY(obj != 0); - - QDeclarativeMetaProperty p(obj, "wrectProperty.x", qmlContext(obj)); - QCOMPARE(p.name(), QString("wrectProperty.x")); - - QCOMPARE(p.read(), QVariant(10)); - - //don't crash once the engine is deleted - delete engine; - engine = 0; - - QCOMPARE(p.propertyTypeName(), "int"); - QCOMPARE(p.read(), QVariant(10)); - p.write(QVariant(20)); - QCOMPARE(p.read(), QVariant(20)); -} - -void tst_qdeclarativemetaproperty::copy() -{ - PropertyObject object; - - QDeclarativeMetaProperty *property = new QDeclarativeMetaProperty(&object, QLatin1String("defaultProperty")); - QCOMPARE(property->name(), QString("defaultProperty")); - QCOMPARE(property->read(), QVariant(10)); - QCOMPARE(property->type(), QDeclarativeMetaProperty::Property); - QCOMPARE(property->propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(property->propertyType(), (int)QVariant::Int); - - QDeclarativeMetaProperty p1(*property); - QCOMPARE(p1.name(), QString("defaultProperty")); - QCOMPARE(p1.read(), QVariant(10)); - QCOMPARE(p1.type(), QDeclarativeMetaProperty::Property); - QCOMPARE(p1.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(p1.propertyType(), (int)QVariant::Int); - - QDeclarativeMetaProperty p2(&object, QLatin1String("url")); - QCOMPARE(p2.name(), QString("url")); - p2 = *property; - QCOMPARE(p2.name(), QString("defaultProperty")); - QCOMPARE(p2.read(), QVariant(10)); - QCOMPARE(p2.type(), QDeclarativeMetaProperty::Property); - QCOMPARE(p2.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(p2.propertyType(), (int)QVariant::Int); - - delete property; property = 0; - - QCOMPARE(p1.name(), QString("defaultProperty")); - QCOMPARE(p1.read(), QVariant(10)); - QCOMPARE(p1.type(), QDeclarativeMetaProperty::Property); - QCOMPARE(p1.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(p1.propertyType(), (int)QVariant::Int); - - QCOMPARE(p2.name(), QString("defaultProperty")); - QCOMPARE(p2.read(), QVariant(10)); - QCOMPARE(p2.type(), QDeclarativeMetaProperty::Property); - QCOMPARE(p2.propertyTypeCategory(), QDeclarativeMetaProperty::Normal); - QCOMPARE(p2.propertyType(), (int)QVariant::Int); -} - -void tst_qdeclarativemetaproperty::initTestCase() -{ - QML_REGISTER_TYPE(Test,1,0,MyQmlObject,MyQmlObject); - QML_REGISTER_TYPE(Test,1,0,PropertyObject,PropertyObject); - QML_REGISTER_TYPE(Test,1,0,MyContainer,MyContainer); -} - - -QTEST_MAIN(tst_qdeclarativemetaproperty) - -#include "tst_qdeclarativemetaproperty.moc" diff --git a/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp b/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp index 4333e02..818f108 100644 --- a/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp +++ b/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp @@ -97,7 +97,7 @@ class ValueSourceTestType : public QObject, public QDeclarativePropertyValueSour Q_OBJECT Q_INTERFACES(QDeclarativePropertyValueSource) public: - virtual void setTarget(const QDeclarativeMetaProperty &) {} + virtual void setTarget(const QDeclarativeProperty &) {} }; QML_DECLARE_TYPE(ValueSourceTestType); @@ -106,7 +106,7 @@ class ValueInterceptorTestType : public QObject, public QDeclarativePropertyValu Q_OBJECT Q_INTERFACES(QDeclarativePropertyValueInterceptor) public: - virtual void setTarget(const QDeclarativeMetaProperty &) {} + virtual void setTarget(const QDeclarativeProperty &) {} virtual void write(const QVariant &) {} }; QML_DECLARE_TYPE(ValueInterceptorTestType); diff --git a/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro b/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro new file mode 100644 index 0000000..22e50cc --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qdeclarativeproperty.cpp diff --git a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp new file mode 100644 index 0000000..d4b0808 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp @@ -0,0 +1,1186 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + +class MyQmlObject : public QObject +{ + Q_OBJECT +public: + MyQmlObject() {} +}; + +QML_DECLARE_TYPE(MyQmlObject); + +class MyAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(int foo READ foo WRITE setFoo) +public: + MyAttached(QObject *parent) : QObject(parent), m_foo(13) {} + + int foo() const { return m_foo; } + void setFoo(int f) { m_foo = f; } + +private: + int m_foo; +}; + +class MyContainer : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty children READ children) +public: + MyContainer() {} + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, m_children); } + + static MyAttached *qmlAttachedProperties(QObject *o) { + return new MyAttached(o); + } + +private: + QList m_children; +}; + +QML_DECLARE_TYPE(MyContainer); +QML_DECLARE_TYPEINFO(MyContainer, QML_HAS_ATTACHED_PROPERTIES) + +class tst_qdeclarativeproperty : public QObject +{ + Q_OBJECT +public: + tst_qdeclarativeproperty() {} + +private slots: + void initTestCase(); + + // Constructors + void qmlmetaproperty(); + void qmlmetaproperty_object(); + void qmlmetaproperty_object_string(); + void qmlmetaproperty_object_context(); + void qmlmetaproperty_object_string_context(); + + // Methods + void name(); + void read(); + void write(); + void reset(); + + // Functionality + void writeObjectToList(); + void writeListToList(); + + //writeToReadOnly(); + + // Bugs + void crashOnValueProperty(); + + void copy(); +private: + QDeclarativeEngine engine; +}; + +void tst_qdeclarativeproperty::qmlmetaproperty() +{ + QDeclarativeProperty prop; + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString()); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), QDeclarativeProperty::Invalid); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), false); + QCOMPARE(prop.object(), (QObject *)0); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QVERIFY(prop.property().name() == 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), -1); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; +} + +class PropertyObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int defaultProperty READ defaultProperty); + Q_PROPERTY(QRect rectProperty READ rectProperty); + Q_PROPERTY(QRect wrectProperty READ wrectProperty WRITE setWRectProperty); + Q_PROPERTY(QUrl url READ url WRITE setUrl); + Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty); + + Q_CLASSINFO("DefaultProperty", "defaultProperty"); +public: + PropertyObject() : m_resetProperty(9) {} + + int defaultProperty() { return 10; } + QRect rectProperty() { return QRect(10, 10, 1, 209); } + + QRect wrectProperty() { return m_rect; } + void setWRectProperty(const QRect &r) { m_rect = r; } + + QUrl url() { return m_url; } + void setUrl(const QUrl &u) { m_url = u; } + + int resettableProperty() const { return m_resetProperty; } + void setResettableProperty(int r) { m_resetProperty = r; } + void resetProperty() { m_resetProperty = 9; } + +signals: + void clicked(); + +private: + int m_resetProperty; + QRect m_rect; + QUrl m_url; +}; + +QML_DECLARE_TYPE(PropertyObject); + +void tst_qdeclarativeproperty::qmlmetaproperty_object() +{ + QObject object; // Has no default property + PropertyObject dobject; // Has default property + + { + QDeclarativeProperty prop(&object); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString()); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), QDeclarativeProperty::Invalid); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), false); + QCOMPARE(prop.object(), (QObject *)0); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QVERIFY(prop.property().name() == 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), -1); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } + + { + QDeclarativeProperty prop(&dobject); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("defaultProperty")); + QCOMPARE(prop.read(), QVariant(10)); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), true); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), (QDeclarativeProperty::Type)(QDeclarativeProperty::Property | QDeclarativeProperty::Default)); + QCOMPARE(prop.isProperty(), true); + QCOMPARE(prop.isDefault(), true); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(prop.propertyType(), (int)QVariant::Int); + QCOMPARE(prop.propertyTypeName(), "int"); + QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding != 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } +} + +void tst_qdeclarativeproperty::qmlmetaproperty_object_string() +{ + QObject object; + PropertyObject dobject; + + { + QDeclarativeProperty prop(&object, QString("defaultProperty")); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString()); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), QDeclarativeProperty::Invalid); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), false); + QCOMPARE(prop.object(), (QObject *)0); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QVERIFY(prop.property().name() == 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), -1); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } + + { + QDeclarativeProperty prop(&dobject, QString("defaultProperty")); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("defaultProperty")); + QCOMPARE(prop.read(), QVariant(10)); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), true); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), QDeclarativeProperty::Property); + QCOMPARE(prop.isProperty(), true); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(prop.propertyType(), (int)QVariant::Int); + QCOMPARE(prop.propertyTypeName(), "int"); + QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding != 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } + + { + QDeclarativeProperty prop(&dobject, QString("onClicked")); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("onClicked")); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant("Hello")), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QCOMPARE(QString(prop.method().signature()), QString("clicked()")); + QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QCOMPARE(prop.property().name(), (const char *)0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression != 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("clicked()")); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } +} + +void tst_qdeclarativeproperty::qmlmetaproperty_object_context() +{ + QObject object; // Has no default property + PropertyObject dobject; // Has default property + + { + QDeclarativeProperty prop(&object, engine.rootContext()); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString()); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), QDeclarativeProperty::Invalid); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), false); + QCOMPARE(prop.object(), (QObject *)0); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QVERIFY(prop.property().name() == 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), -1); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } + + { + QDeclarativeProperty prop(&dobject, engine.rootContext()); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("defaultProperty")); + QCOMPARE(prop.read(), QVariant(10)); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), true); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), (QDeclarativeProperty::Type)(QDeclarativeProperty::Property | QDeclarativeProperty::Default)); + QCOMPARE(prop.isProperty(), true); + QCOMPARE(prop.isDefault(), true); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(prop.propertyType(), (int)QVariant::Int); + QCOMPARE(prop.propertyTypeName(), "int"); + QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding != 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } +} + +void tst_qdeclarativeproperty::qmlmetaproperty_object_string_context() +{ + QObject object; + PropertyObject dobject; + + { + QDeclarativeProperty prop(&object, QString("defaultProperty"), engine.rootContext()); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString()); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), QDeclarativeProperty::Invalid); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), false); + QCOMPARE(prop.object(), (QObject *)0); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QVERIFY(prop.property().name() == 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), -1); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } + + { + QDeclarativeProperty prop(&dobject, QString("defaultProperty"), engine.rootContext()); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("defaultProperty")); + QCOMPARE(prop.read(), QVariant(10)); + QCOMPARE(prop.write(QVariant()), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), true); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QVERIFY(prop.method().signature() == 0); + QCOMPARE(prop.type(), QDeclarativeProperty::Property); + QCOMPARE(prop.isProperty(), true); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), true); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(prop.propertyType(), (int)QVariant::Int); + QCOMPARE(prop.propertyTypeName(), "int"); + QCOMPARE(QString(prop.property().name()), QString("defaultProperty")); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QTest::ignoreMessage(QtWarningMsg, ":-1: Unable to assign null to int"); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding != 0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression == 0); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfProperty("defaultProperty")); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } + + { + QDeclarativeProperty prop(&dobject, QString("onClicked"), engine.rootContext()); + + QGuard binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext())); + binding->setTarget(prop); + QVERIFY(binding != 0); + QGuard expression(new QDeclarativeExpression()); + QVERIFY(expression != 0); + + QObject *obj = new QObject; + + QCOMPARE(prop.name(), QString("onClicked")); + QCOMPARE(prop.read(), QVariant()); + QCOMPARE(prop.write(QVariant("Hello")), false); + QCOMPARE(prop.hasChangedNotifier(), false); + QCOMPARE(prop.needsChangedNotifier(), false); + QCOMPARE(prop.connectNotifier(0, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, SLOT(deleteLater())), false); + QCOMPARE(prop.connectNotifier(obj, 0), false); + QCOMPARE(prop.connectNotifier(0, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false); + QCOMPARE(prop.connectNotifier(obj, -1), false); + QCOMPARE(QString(prop.method().signature()), QString("clicked()")); + QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty); + QCOMPARE(prop.isProperty(), false); + QCOMPARE(prop.isDefault(), false); + QCOMPARE(prop.isWritable(), false); + QCOMPARE(prop.isDesignable(), false); + QCOMPARE(prop.isResettable(), false); + QCOMPARE(prop.isValid(), true); + QCOMPARE(prop.object(), &dobject); + QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory); + QCOMPARE(prop.propertyType(), 0); + QCOMPARE(prop.propertyTypeName(), (const char *)0); + QCOMPARE(prop.property().name(), (const char *)0); + QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding) == 0); + QVERIFY(binding == 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0); + QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression) == 0); + QVERIFY(expression != 0); + QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression); + QCOMPARE(prop.coreIndex(), dobject.metaObject()->indexOfMethod("clicked()")); + QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1); + + delete obj; + } +} + +void tst_qdeclarativeproperty::name() +{ + { + QDeclarativeProperty p; + QCOMPARE(p.name(), QString()); + } + + { + PropertyObject o; + QDeclarativeProperty p(&o); + QCOMPARE(p.name(), QString("defaultProperty")); + } + + { + QObject o; + QDeclarativeProperty p(&o, QString("objectName")); + QCOMPARE(p.name(), QString("objectName")); + } + + { + PropertyObject o; + QDeclarativeProperty p(&o, "onClicked"); + QCOMPARE(p.name(), QString("onClicked")); + } + + { + QObject o; + QDeclarativeProperty p(&o, "onClicked"); + QCOMPARE(p.name(), QString()); + } + + { + QObject o; + QDeclarativeProperty p(&o, "foo"); + QCOMPARE(p.name(), QString()); + } + + { + QDeclarativeProperty p(0, "foo"); + QCOMPARE(p.name(), QString()); + } + + { + PropertyObject o; + QDeclarativeProperty p(&o, "rectProperty"); + QCOMPARE(p.name(), QString("rectProperty")); + } + + { + PropertyObject o; + QDeclarativeProperty p(&o, "rectProperty.x"); + QCOMPARE(p.name(), QString("rectProperty.x")); + } + + { + PropertyObject o; + QDeclarativeProperty p(&o, "rectProperty.foo"); + QCOMPARE(p.name(), QString()); + } +} + +void tst_qdeclarativeproperty::read() +{ + // Invalid + { + QDeclarativeProperty p; + QCOMPARE(p.read(), QVariant()); + } + + // Default prop + { + PropertyObject o; + QDeclarativeProperty p(&o); + QCOMPARE(p.read(), QVariant(10)); + } + + // Invalid default prop + { + QObject o; + QDeclarativeProperty p(&o); + QCOMPARE(p.read(), QVariant()); + } + + // Value prop by name + { + QObject o; + + QDeclarativeProperty p(&o, "objectName"); + QCOMPARE(p.read(), QVariant(QString())); + + o.setObjectName("myName"); + + QCOMPARE(p.read(), QVariant("myName")); + } + + // Value-type prop + { + PropertyObject o; + QDeclarativeProperty p(&o, "rectProperty.x"); + QCOMPARE(p.read(), QVariant(10)); + } + + // Invalid value-type prop + { + PropertyObject o; + QDeclarativeProperty p(&o, "rectProperty.foo"); + QCOMPARE(p.read(), QVariant()); + } + + // Signal property + { + PropertyObject o; + QDeclarativeProperty p(&o, "onClicked"); + QCOMPARE(p.read(), QVariant()); + + QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression())); + QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p)); + + QCOMPARE(p.read(), QVariant()); + } + + // Deleted object + { + PropertyObject *o = new PropertyObject; + QDeclarativeProperty p(o, "rectProperty.x"); + QCOMPARE(p.read(), QVariant(10)); + delete o; + QCOMPARE(p.read(), QVariant()); + } + + // Attached property + { + QDeclarativeComponent component(&engine); + component.setData("import Test 1.0\nMyContainer { }", QUrl()); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDeclarativeProperty p(object, "MyContainer.foo", qmlContext(object)); + QCOMPARE(p.read(), QVariant(13)); + delete object; + } + { + QDeclarativeComponent component(&engine); + component.setData("import Test 1.0\nMyContainer { MyContainer.foo: 10 }", QUrl()); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDeclarativeProperty p(object, "MyContainer.foo", qmlContext(object)); + QCOMPARE(p.read(), QVariant(10)); + delete object; + } + { + QDeclarativeComponent component(&engine); + component.setData("import Test 1.0 as Foo\nFoo.MyContainer { Foo.MyContainer.foo: 10 }", QUrl()); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDeclarativeProperty p(object, "Foo.MyContainer.foo", qmlContext(object)); + QCOMPARE(p.read(), QVariant(10)); + delete object; + } +} + +void tst_qdeclarativeproperty::write() +{ + // Invalid + { + QDeclarativeProperty p; + QCOMPARE(p.write(QVariant(10)), false); + } + + // Read-only default prop + { + PropertyObject o; + QDeclarativeProperty p(&o); + QCOMPARE(p.write(QVariant(10)), false); + } + + // Invalid default prop + { + QObject o; + QDeclarativeProperty p(&o); + QCOMPARE(p.write(QVariant(10)), false); + } + + // Read-only prop by name + { + PropertyObject o; + QDeclarativeProperty p(&o, QString("defaultProperty")); + QCOMPARE(p.write(QVariant(10)), false); + } + + // Writable prop by name + { + PropertyObject o; + QDeclarativeProperty p(&o, QString("objectName")); + QCOMPARE(o.objectName(), QString()); + QCOMPARE(p.write(QVariant(QString("myName"))), true); + QCOMPARE(o.objectName(), QString("myName")); + } + + // Deleted object + { + PropertyObject *o = new PropertyObject; + QDeclarativeProperty p(o, QString("objectName")); + QCOMPARE(p.write(QVariant(QString("myName"))), true); + QCOMPARE(o->objectName(), QString("myName")); + + delete o; + + QCOMPARE(p.write(QVariant(QString("myName"))), false); + } + + // Signal property + { + PropertyObject o; + QDeclarativeProperty p(&o, "onClicked"); + QCOMPARE(p.write(QVariant("console.log(1921)")), false); + + QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression())); + QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p)); + + QCOMPARE(p.write(QVariant("console.log(1921)")), false); + + QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p)); + } + + // Value-type property + { + PropertyObject o; + QDeclarativeProperty p(&o, "wrectProperty"); + + QCOMPARE(o.wrectProperty(), QRect()); + QCOMPARE(p.write(QRect(1, 13, 99, 8)), true); + QCOMPARE(o.wrectProperty(), QRect(1, 13, 99, 8)); + + QDeclarativeProperty p2(&o, "wrectProperty.x"); + QCOMPARE(p2.read(), QVariant(1)); + QCOMPARE(p2.write(QVariant(6)), true); + QCOMPARE(p2.read(), QVariant(6)); + QCOMPARE(o.wrectProperty(), QRect(6, 13, 99, 8)); + } + + // URL-property + { + PropertyObject o; + QDeclarativeProperty p(&o, "url"); + + QCOMPARE(p.write(QUrl("main.qml")), true); + QCOMPARE(o.url(), QUrl("main.qml")); + + QDeclarativeProperty p2(&o, "url", engine.rootContext()); + + QUrl result = engine.baseUrl().resolved(QUrl("main.qml")); + QVERIFY(result != QUrl("main.qml")); + + QCOMPARE(p2.write(QUrl("main.qml")), true); + QCOMPARE(o.url(), result); + } + + // Attached property + { + QDeclarativeComponent component(&engine); + component.setData("import Test 1.0\nMyContainer { }", QUrl()); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDeclarativeProperty p(object, "MyContainer.foo", qmlContext(object)); + p.write(QVariant(99)); + QCOMPARE(p.read(), QVariant(99)); + delete object; + } + { + QDeclarativeComponent component(&engine); + component.setData("import Test 1.0 as Foo\nFoo.MyContainer { Foo.MyContainer.foo: 10 }", QUrl()); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDeclarativeProperty p(object, "Foo.MyContainer.foo", qmlContext(object)); + p.write(QVariant(99)); + QCOMPARE(p.read(), QVariant(99)); + delete object; + } +} + +void tst_qdeclarativeproperty::reset() +{ + // Invalid + { + QDeclarativeProperty p; + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Read-only default prop + { + PropertyObject o; + QDeclarativeProperty p(&o); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Invalid default prop + { + QObject o; + QDeclarativeProperty p(&o); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Non-resettable-only prop by name + { + PropertyObject o; + QDeclarativeProperty p(&o, QString("defaultProperty")); + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Resettable prop by name + { + PropertyObject o; + QDeclarativeProperty p(&o, QString("resettableProperty")); + + QCOMPARE(p.read(), QVariant(9)); + QCOMPARE(p.write(QVariant(11)), true); + QCOMPARE(p.read(), QVariant(11)); + + QCOMPARE(p.isResettable(), true); + QCOMPARE(p.reset(), true); + + QCOMPARE(p.read(), QVariant(9)); + } + + // Deleted object + { + PropertyObject *o = new PropertyObject; + + QDeclarativeProperty p(o, QString("resettableProperty")); + + QCOMPARE(p.isResettable(), true); + QCOMPARE(p.reset(), true); + + delete o; + + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } + + // Signal property + { + PropertyObject o; + QDeclarativeProperty p(&o, "onClicked"); + + QCOMPARE(p.isResettable(), false); + QCOMPARE(p.reset(), false); + } +} + +void tst_qdeclarativeproperty::writeObjectToList() +{ + QDeclarativeComponent containerComponent(&engine); + containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl()); + MyContainer *container = qobject_cast(containerComponent.create()); + QVERIFY(container != 0); + QDeclarativeListReference list(container, "children"); + QVERIFY(list.count() == 1); + + MyQmlObject *object = new MyQmlObject; + QDeclarativeProperty prop(container, "children"); + prop.write(qVariantFromValue(object)); + QCOMPARE(list.count(), 1); + QCOMPARE(list.at(0), object); +} + +Q_DECLARE_METATYPE(QList); +void tst_qdeclarativeproperty::writeListToList() +{ + QDeclarativeComponent containerComponent(&engine); + containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl()); + MyContainer *container = qobject_cast(containerComponent.create()); + QVERIFY(container != 0); + QDeclarativeListReference list(container, "children"); + QVERIFY(list.count() == 1); + + QList objList; + objList << new MyQmlObject() << new MyQmlObject() << new MyQmlObject() << new MyQmlObject(); + QDeclarativeProperty prop(container, "children"); + prop.write(qVariantFromValue(objList)); + QCOMPARE(list.count(), 4); + + //XXX need to try this with read/write prop (for read-only it correctly doesn't write) + /*QList typedObjList; + typedObjList << new MyQmlObject(); + prop.write(qVariantFromValue(&typedObjList)); + QCOMPARE(container->children()->size(), 1);*/ +} + +void tst_qdeclarativeproperty::crashOnValueProperty() +{ + QDeclarativeEngine *engine = new QDeclarativeEngine; + QDeclarativeComponent component(engine); + + component.setData("import Test 1.0\nPropertyObject { wrectProperty.x: 10 }", QUrl()); + PropertyObject *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + + QDeclarativeProperty p(obj, "wrectProperty.x", qmlContext(obj)); + QCOMPARE(p.name(), QString("wrectProperty.x")); + + QCOMPARE(p.read(), QVariant(10)); + + //don't crash once the engine is deleted + delete engine; + engine = 0; + + QCOMPARE(p.propertyTypeName(), "int"); + QCOMPARE(p.read(), QVariant(10)); + p.write(QVariant(20)); + QCOMPARE(p.read(), QVariant(20)); +} + +void tst_qdeclarativeproperty::copy() +{ + PropertyObject object; + + QDeclarativeProperty *property = new QDeclarativeProperty(&object, QLatin1String("defaultProperty")); + QCOMPARE(property->name(), QString("defaultProperty")); + QCOMPARE(property->read(), QVariant(10)); + QCOMPARE(property->type(), QDeclarativeProperty::Property); + QCOMPARE(property->propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(property->propertyType(), (int)QVariant::Int); + + QDeclarativeProperty p1(*property); + QCOMPARE(p1.name(), QString("defaultProperty")); + QCOMPARE(p1.read(), QVariant(10)); + QCOMPARE(p1.type(), QDeclarativeProperty::Property); + QCOMPARE(p1.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(p1.propertyType(), (int)QVariant::Int); + + QDeclarativeProperty p2(&object, QLatin1String("url")); + QCOMPARE(p2.name(), QString("url")); + p2 = *property; + QCOMPARE(p2.name(), QString("defaultProperty")); + QCOMPARE(p2.read(), QVariant(10)); + QCOMPARE(p2.type(), QDeclarativeProperty::Property); + QCOMPARE(p2.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(p2.propertyType(), (int)QVariant::Int); + + delete property; property = 0; + + QCOMPARE(p1.name(), QString("defaultProperty")); + QCOMPARE(p1.read(), QVariant(10)); + QCOMPARE(p1.type(), QDeclarativeProperty::Property); + QCOMPARE(p1.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(p1.propertyType(), (int)QVariant::Int); + + QCOMPARE(p2.name(), QString("defaultProperty")); + QCOMPARE(p2.read(), QVariant(10)); + QCOMPARE(p2.type(), QDeclarativeProperty::Property); + QCOMPARE(p2.propertyTypeCategory(), QDeclarativeProperty::Normal); + QCOMPARE(p2.propertyType(), (int)QVariant::Int); +} + +void tst_qdeclarativeproperty::initTestCase() +{ + QML_REGISTER_TYPE(Test,1,0,MyQmlObject,MyQmlObject); + QML_REGISTER_TYPE(Test,1,0,PropertyObject,PropertyObject); + QML_REGISTER_TYPE(Test,1,0,MyContainer,MyContainer); +} + + +QTEST_MAIN(tst_qdeclarativeproperty) + +#include "tst_qdeclarativeproperty.moc" diff --git a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h index 82a9c8a..dfc2829 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h +++ b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h @@ -52,8 +52,8 @@ #include #include #include -#include -#include +#include +#include class MyTypeObject : public QObject { @@ -135,7 +135,7 @@ class MyConstantValueSource : public QObject, public QDeclarativePropertyValueSo { Q_OBJECT public: - virtual void setTarget(const QDeclarativeMetaProperty &p) { p.write(3345); } + virtual void setTarget(const QDeclarativeProperty &p) { p.write(3345); } }; QML_DECLARE_TYPE(MyConstantValueSource); @@ -143,11 +143,11 @@ class MyOffsetValueInterceptor : public QObject, public QDeclarativePropertyValu { Q_OBJECT public: - virtual void setTarget(const QDeclarativeMetaProperty &p) { prop = p; } - virtual void write(const QVariant &value) { QDeclarativeMetaPropertyPrivate::write(prop, value.toInt() + 13, QDeclarativeMetaPropertyPrivate::BypassInterceptor); } + virtual void setTarget(const QDeclarativeProperty &p) { prop = p; } + virtual void write(const QVariant &value) { QDeclarativePropertyPrivate::write(prop, value.toInt() + 13, QDeclarativePropertyPrivate::BypassInterceptor); } private: - QDeclarativeMetaProperty prop; + QDeclarativeProperty prop; }; QML_DECLARE_TYPE(MyOffsetValueInterceptor); -- cgit v0.12