From 9fb7035d59ffa582edabf53c5d617524ab92ae52 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 29 Apr 2010 15:32:34 +1000 Subject: Return enum property values as numbers, not QVariant values Task-number: QTBUG-10291 Reviewed-by: akennedy --- src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index bb5c8b7..671a262 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -265,7 +265,7 @@ QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name) void *args[] = { &rv, 0 }; QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args); return Value(scriptEngine, rv); - } else if (lastData->propType == QMetaType::Int) { + } else if (lastData->propType == QMetaType::Int || lastData->flags & QDeclarativePropertyCache::Data::IsEnumType) { int rv = 0; void *args[] = { &rv, 0 }; QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args); -- cgit v0.12 From 96551e8af08c6f5eb506468a1a79070f23525bca Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 29 Apr 2010 15:39:47 +1000 Subject: Remove Component's isReady, isLoading, isError and isNull properties. The Component status enum covers all of these properties already and removing these also makes the API consistent with Image and Loader. Note this change only affects the QML Component API; the methods are still available for QDeclarativeComponent. --- .../declarative/samegame/SamegameCore/samegame.js | 2 +- demos/declarative/snake/content/snake.js | 8 +-- doc/src/snippets/declarative/componentCreation.js | 6 +-- examples/declarative/dynamic/qml/itemCreation.js | 6 +-- .../tutorials/samegame/samegame2/samegame.js | 8 +-- .../tutorials/samegame/samegame3/samegame.js | 8 +-- .../samegame/samegame4/content/samegame.js | 8 +-- src/declarative/qml/qdeclarativecomponent.cpp | 58 ++-------------------- src/declarative/qml/qdeclarativecomponent.h | 5 +- 9 files changed, 28 insertions(+), 81 deletions(-) diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js index bf99ca3..cc0a70d 100755 --- a/demos/declarative/samegame/SamegameCore/samegame.js +++ b/demos/declarative/samegame/SamegameCore/samegame.js @@ -175,7 +175,7 @@ function createBlock(column,row){ // only work if the block QML is a local file. Otherwise the component will // not be ready immediately. There is a statusChanged signal on the // component you could use if you want to wait to load remote files. - if(component.isReady){ + if(component.status == Component.Ready){ var dynamicObject = component.createObject(); if(dynamicObject == null){ console.log("error creating block"); diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index 02f9757..102bd87 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -52,8 +52,8 @@ function startNewGame() link.spawned = false; link.dying = false; } else { - if(linkComponent.isReady == false){ - if(linkComponent.isError == true) + if(linkComponent.status != Component.Ready) { + if(linkComponent.status == Component.Error) console.log(linkComponent.errorsString()); else console.log("Still loading linkComponent"); @@ -293,8 +293,8 @@ function createCookie(value) { } } - if(cookieComponent.isReady == false){ - if(cookieComponent.isError == true) + if(cookieComponent.status != Component.Ready) { + if(cookieComponent.status == Component.Error) console.log(cookieComponent.errorsString()); else console.log("Still loading cookieComponent"); diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js index be3e4d6..814545e 100644 --- a/doc/src/snippets/declarative/componentCreation.js +++ b/doc/src/snippets/declarative/componentCreation.js @@ -3,7 +3,7 @@ var component; var sprite; function finishCreation() { - if (component.isReady) { + if (component.status == Component.Ready) { sprite = component.createObject(); if (sprite == null) { // Error Handling @@ -13,7 +13,7 @@ function finishCreation() { sprite.y = 100; // ... } - } else if (component.isError()) { + } else if (component.status == Component.Error) { // Error Handling console.log("Error loading component:", component.errorsString()); } @@ -26,7 +26,7 @@ function createSpriteObjects() { //![2] component = Qt.createComponent("Sprite.qml"); - if (component.isReady) + if (component.status == Component.Ready) finishCreation(); else component.statusChanged.connect(finishCreation); diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js index 98d48a8..3c1b975 100644 --- a/examples/declarative/dynamic/qml/itemCreation.js +++ b/examples/declarative/dynamic/qml/itemCreation.js @@ -33,7 +33,7 @@ function loadComponent() { itemComponent = Qt.createComponent(itemButton.file); //console.log(itemButton.file) - if(itemComponent.isLoading){ + if(itemComponent.status == Component.Loading){ component.statusChanged.connect(finishCreation); }else{//Depending on the content, it can be ready or error immediately createItem(); @@ -41,7 +41,7 @@ function loadComponent() { } function createItem() { - if (itemComponent.isReady && draggedItem == null) { + if (itemComponent.status == Component.Ready && draggedItem == null) { draggedItem = itemComponent.createObject(); draggedItem.parent = window; draggedItem.image = itemButton.image; @@ -49,7 +49,7 @@ function createItem() { draggedItem.y = yOffset; startingZ = draggedItem.z; draggedItem.z = 4;//On top - } else if (itemComponent.isError) { + } else if (itemComponent.status == Component.Error) { draggedItem = null; console.log("error creating component"); console.log(component.errorsString()); diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index e5c790d..bcfb5b6 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -37,10 +37,10 @@ function createBlock(column, row) { if (component == null) component = Qt.createComponent("Block.qml"); - // Note that if Block.qml was not a local file, component.isReady would be - // false and we should wait for the component's statusChanged() signal to - // know when the file is downloaded and fully loaded before calling createObject(). - if (component.isReady) { + // Note that if Block.qml was not a local file, component.status would be + // Loading and we should wait for the component's statusChanged() signal to + // know when the file is downloaded and ready before calling createObject(). + if (component.status == Component.Ready) { var dynamicObject = component.createObject(); if (dynamicObject == null) { console.log("error creating block"); diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index da0f76e..4256aee 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -34,10 +34,10 @@ function createBlock(column, row) { if (component == null) component = Qt.createComponent("Block.qml"); - // Note that if Block.qml was not a local file, component.isReady would be - // false and we should wait for the component's statusChanged() signal to - // know when the file is downloaded and fully loaded before calling createObject(). - if (component.isReady) { + // Note that if Block.qml was not a local file, component.status would be + // Loading and we should wait for the component's statusChanged() signal to + // know when the file is downloaded and ready before calling createObject(). + if (component.status == Component.Ready) { var dynamicObject = component.createObject(); if (dynamicObject == null) { console.log("error creating block"); diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index 1454f0b..961cd66 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -45,10 +45,10 @@ function createBlock(column, row) { if (component == null) component = Qt.createComponent("content/BoomBlock.qml"); - // Note that if Block.qml was not a local file, component.isReady would be - // false and we should wait for the component's statusChanged() signal to - // know when the file is downloaded and fully loaded before calling createObject(). - if (component.isReady) { + // Note that if Block.qml was not a local file, component.status would be + // Loading and we should wait for the component's statusChanged() signal to + // know when the file is downloaded and ready before calling createObject(). + if (component.status == Component.Ready) { var dynamicObject = component.createObject(); if (dynamicObject == null) { console.log("error creating block"); diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index b83e9f4..f312497 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -269,19 +269,7 @@ QDeclarativeComponent::Status QDeclarativeComponent::status() const } /*! - \qmlproperty bool Component::isNull - - Is true if the component is in the Null state, false otherwise. - - Equivalent to status == Component.Null. -*/ - -/*! - \property QDeclarativeComponent::isNull - - Is true if the component is in the Null state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Null. + Returns true if status() == QDeclarativeComponent::Null. */ bool QDeclarativeComponent::isNull() const { @@ -289,19 +277,7 @@ bool QDeclarativeComponent::isNull() const } /*! - \qmlproperty bool Component::isReady - - Is true if the component is in the Ready state, false otherwise. - - Equivalent to status == Component.Ready. -*/ - -/*! - \property QDeclarativeComponent::isReady - - Is true if the component is in the Ready state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Ready. + Returns true if status() == QDeclarativeComponent::Ready. */ bool QDeclarativeComponent::isReady() const { @@ -309,21 +285,7 @@ bool QDeclarativeComponent::isReady() const } /*! - \qmlproperty bool Component::isError - - Is true if the component is in the Error state, false otherwise. - - Equivalent to status == Component.Error. - - Calling errorsString() will provide a human-readable description of any errors. -*/ - -/*! - \property QDeclarativeComponent::isError - - Is true if the component is in the Error state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Error. + Returns true if status() == QDeclarativeComponent::Error. */ bool QDeclarativeComponent::isError() const { @@ -331,19 +293,7 @@ bool QDeclarativeComponent::isError() const } /*! - \qmlproperty bool Component::isLoading - - Is true if the component is in the Loading state, false otherwise. - - Equivalent to status == Component::Loading. -*/ - -/*! - \property QDeclarativeComponent::isLoading - - Is true if the component is in the Loading state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Loading. + Returns true if status() == QDeclarativeComponent::Loading. */ bool QDeclarativeComponent::isLoading() const { diff --git a/src/declarative/qml/qdeclarativecomponent.h b/src/declarative/qml/qdeclarativecomponent.h index f3cfe3c..b078174 100644 --- a/src/declarative/qml/qdeclarativecomponent.h +++ b/src/declarative/qml/qdeclarativecomponent.h @@ -64,10 +64,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeComponent : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeComponent) - Q_PROPERTY(bool isNull READ isNull NOTIFY statusChanged) - Q_PROPERTY(bool isReady READ isReady NOTIFY statusChanged) - Q_PROPERTY(bool isError READ isError NOTIFY statusChanged) - Q_PROPERTY(bool isLoading READ isLoading NOTIFY statusChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(QUrl url READ url CONSTANT) -- cgit v0.12 From a5e5b178615cea0dc795fd2008ef258030d2e8e6 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 29 Apr 2010 15:41:55 +1000 Subject: Don't call qRegisterMetaType() in global scope --- src/declarative/qml/qdeclarativecomponent.cpp | 1 - src/declarative/qml/qdeclarativeengine.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index f312497..b81a32a 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -63,7 +63,6 @@ QT_BEGIN_NAMESPACE class QByteArray; -int statusId = qRegisterMetaType("QDeclarativeComponent::Status"); /*! \class QDeclarativeComponent diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index a22011a..19d4b57 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -347,6 +347,7 @@ void QDeclarativeEnginePrivate::init() qRegisterMetaType("QVariant"); qRegisterMetaType("QDeclarativeScriptString"); qRegisterMetaType("QScriptValue"); + qRegisterMetaType("QDeclarativeComponent::Status"); QDeclarativeData::init(); -- cgit v0.12