diff options
-rw-r--r-- | demos/declarative/samegame/content/samegame.js | 4 | ||||
-rw-r--r-- | examples/declarative/dynamic/dynamic.js | 4 | ||||
-rw-r--r-- | src/declarative/qml/qml.pri | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmlbindablecomponent.cpp | 104 | ||||
-rw-r--r-- | src/declarative/qml/qmlbindablecomponent.h | 91 | ||||
-rw-r--r-- | src/declarative/qml/qmlbindablecomponent_p.h | 77 | ||||
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 17 | ||||
-rw-r--r-- | src/declarative/qml/qmlcomponent.h | 9 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 12 |
9 files changed, 290 insertions, 31 deletions
diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index 3592edc..b1b2c50 100644 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -201,7 +201,7 @@ var waitTop = -1; function finishCreatingBlock(xIdx,yIdx){ //TODO: Doc that the 'x', 'y' that were here are hidden properties from the calling QFxItem - if(component.isReady()){ + if(component.isReady){ if(xIdx == undefined){ //Called without arguments, create a previously stored (xIdx,yIdx) if(waitTop == -1) @@ -226,7 +226,7 @@ function finishCreatingBlock(xIdx,yIdx){ dynamicObject.spawned = true; board[index(xIdx,yIdx)] = dynamicObject; return true; - }else if(component.isError()){ + }else if(component.isError){ print("error creating block"); print(component.errorsString()); }else{ diff --git a/examples/declarative/dynamic/dynamic.js b/examples/declarative/dynamic/dynamic.js index 13317df..8f1e138 100644 --- a/examples/declarative/dynamic/dynamic.js +++ b/examples/declarative/dynamic/dynamic.js @@ -28,10 +28,10 @@ function instantCreateWithComponent() {//Like create, but assumes instant readyn } function finishCreation(){ - if(component.isReady() && dynamicObject == null){ + if(component.isReady && dynamicObject == null){ dynamicObject = component.createObject(); dynamicObject.parent = targetItem; - }else if(component.isError()){ + }else if(component.isError){ dynamicObject = null; print("error creating component"); print(component.errorsString()); diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index b3fa063..b71ca1f 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -5,6 +5,7 @@ SOURCES += qml/qmlparser.cpp \ qml/qmlexpression.cpp \ qml/qmlbinding.cpp \ qml/qmlmetaproperty.cpp \ + qml/qmlbindablecomponent.cpp \ qml/qmlcomponent.cpp \ qml/qmlcontext.cpp \ qml/qmlcustomparser.cpp \ @@ -36,6 +37,8 @@ HEADERS += qml/qmlparser_p.h \ qml/qmlbinding.h \ qml/qmlbinding_p.h \ qml/qmlmetaproperty.h \ + qml/qmlbindablecomponent.h \ + qml/qmlbindablecomponent_p.h \ qml/qmlcomponent.h \ qml/qmlcomponent_p.h \ qml/qmlcustomparser_p.h \ diff --git a/src/declarative/qml/qmlbindablecomponent.cpp b/src/declarative/qml/qmlbindablecomponent.cpp new file mode 100644 index 0000000..ed9924a --- /dev/null +++ b/src/declarative/qml/qmlbindablecomponent.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlbindablecomponent.h" +#include "qmlbindablecomponent_p.h" +#include "qmlcomponent.h" + +QT_BEGIN_NAMESPACE +QmlBindableComponent::QmlBindableComponent(QmlEngine *engine, QObject *parent) + : QmlComponent(*(new QmlBindableComponentPrivate), parent) +{ + Q_D(QmlBindableComponent); + d->engine = engine; + connect(this, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(statusChange(QmlComponent::Status))); +} + +QmlBindableComponent::QmlBindableComponent(QmlEngine *engine, const QUrl &url, QObject *parent) + : QmlComponent(*(new QmlBindableComponentPrivate), parent) +{ + Q_D(QmlBindableComponent); + d->engine = engine; + loadUrl(url); + connect(this, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(statusChange(QmlComponent::Status))); +} + +void QmlBindableComponent::setContext(QmlContext* c) +{ + Q_D(QmlBindableComponent); + d->ctxt =c; +} +/*! + Create a script object instance from this component. Returns a null + script object if creation failed. It will create the instance in the + same context that it was created it. QmlBindableComponent is only + meant to be created from with script - C++ developers should just use + QmlComponent directly. + + Similar to QmlComponent::create(), but creates an object suitable + for usage within scripts. +*/ +QScriptValue QmlBindableComponent::createObject() +{ + Q_D(QmlBindableComponent); + QObject* ret = create(d->ctxt); + return QmlEngine::qmlScriptObject(ret, d->engine); +} + +void QmlBindableComponent::statusChange(QmlComponent::Status newStatus) +{ + Q_D(QmlBindableComponent); + if(newStatus == d->prevStatus) + return; + if(newStatus == QmlComponent::Null || d->prevStatus == QmlComponent::Null) + emit isNullChanged(); + if(newStatus == QmlComponent::Ready || d->prevStatus == QmlComponent::Ready) + emit isReadyChanged(); + if(newStatus == QmlComponent::Loading || d->prevStatus == QmlComponent::Loading) + emit isLoadingChanged(); + if(newStatus == QmlComponent::Error || d->prevStatus == QmlComponent::Error) + emit isErrorChanged(); + d->prevStatus = newStatus; +} + +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlbindablecomponent.h b/src/declarative/qml/qmlbindablecomponent.h new file mode 100644 index 0000000..2b3e0ce --- /dev/null +++ b/src/declarative/qml/qmlbindablecomponent.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLBINDABLECOMPONENT_H +#define QMLBINDABLECOMPONENT_H + +#include <QtCore/qobject.h> +#include <QtCore/qstring.h> +#include <QtDeclarative/qfxglobal.h> +#include <QtDeclarative/qml.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qmlerror.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlBindableComponentPrivate; +class QmlEngine; +class QmlContext; +class Q_DECLARATIVE_EXPORT QmlBindableComponent : public QmlComponent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlBindableComponent) + friend class QmlEngine; +public: + QmlBindableComponent(QmlEngine *, const QUrl &url, QObject *parent = 0); + QmlBindableComponent(QmlEngine *, QObject *parent=0); + Q_PROPERTY(bool isNull READ isNull NOTIFY isNullChanged); + Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged); + Q_PROPERTY(bool isError READ isError NOTIFY isErrorChanged); + Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged); + + Q_INVOKABLE QScriptValue createObject(); + + void setContext(QmlContext* c); +Q_SIGNALS: + void isNullChanged(); + void isErrorChanged(); + void isReadyChanged(); + void isLoadingChanged(); +private slots: + void statusChange(QmlComponent::Status newStatus); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlBindableComponent) + +QT_END_HEADER +#endif diff --git a/src/declarative/qml/qmlbindablecomponent_p.h b/src/declarative/qml/qmlbindablecomponent_p.h new file mode 100644 index 0000000..79335df --- /dev/null +++ b/src/declarative/qml/qmlbindablecomponent_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLBINDABLECOMPONENT_P_H +#define QMLBINDABLECOMPONENT_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 "qmlcomponent.h" +#include "qmlbindablecomponent.h" +#include "qmlcomponent_p.h" + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QmlBindableComponentPrivate : public QmlComponentPrivate +{ + Q_DECLARE_PUBLIC(QmlBindableComponent) +public: + QmlBindableComponentPrivate() : QmlComponentPrivate(), + prevStatus(QmlBindableComponent::Null), ctxt(0) + { } + + QmlComponent::Status prevStatus; + QmlContext* ctxt; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 4e39d7f..0fdba64 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -431,23 +431,6 @@ QmlComponent::QmlComponent(QmlComponentPrivate &dd, QObject *parent) { } -/*! - Create a script object instance from this component. Returns a null - script object if creation failed. It will create the instance in the - engine's \l {QmlEngine::rootContext()}{root context}. - - Similar to QmlComponent::create(), but creates an object suitable - for usage within scripts. -*/ -QScriptValue QmlComponent::createObject() -{ - Q_D(QmlComponent); - QObject* ret = create(); - if(ret) - return QmlEngine::qmlScriptObject(ret, d->engine); - else - return d->engine->scriptEngine()->nullValue(); -} /*! Create an object instance from this component. Returns 0 if creation diff --git a/src/declarative/qml/qmlcomponent.h b/src/declarative/qml/qmlcomponent.h index 9c712df..45b26eb 100644 --- a/src/declarative/qml/qmlcomponent.h +++ b/src/declarative/qml/qmlcomponent.h @@ -77,17 +77,16 @@ public: enum Status { Null, Ready, Loading, Error }; Status status() const; - Q_INVOKABLE bool isNull() const; - Q_INVOKABLE bool isReady() const; - Q_INVOKABLE bool isError() const; - Q_INVOKABLE bool isLoading() const; + bool isNull() const; + bool isReady() const; + bool isError() const; + bool isLoading() const; QList<QmlError> errors() const; Q_INVOKABLE QString errorsString() const; QUrl url() const; - Q_INVOKABLE QScriptValue createObject(); virtual QObject *create(QmlContext *context = 0); virtual QObject *beginCreate(QmlContext *); virtual void completeCreate(); diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 8b21290..c4b3c0d 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -71,6 +71,7 @@ #include <QtCore/qcoreapplication.h> #include <QtCore/qdir.h> #include <qmlcomponent.h> +#include <qmlbindablecomponent.h> #include "private/qmlmetaproperty_p.h" #include <private/qmlbinding_p.h> #include <private/qmlvme_p.h> @@ -583,19 +584,20 @@ QScriptValue QmlEngine::qmlScriptObject(QObject* object, QmlEngine* engine) */ QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *engine) { - QmlComponent* c; + QmlBindableComponent* c; QmlEngine* activeEngine = qobject_cast<QmlEngine*>( engine->globalObject().property(QLatin1String("qmlEngine")).toQObject()); + QmlContext* context =activeEngine->d_func()->currentExpression->context(); if(ctxt->argumentCount() != 1 || !activeEngine){ - c = new QmlComponent(activeEngine); + c = new QmlBindableComponent(activeEngine); }else{ - QUrl url = QUrl(activeEngine->d_func()->currentExpression->context() - ->resolvedUrl(ctxt->argument(0).toString())); + QUrl url = QUrl(context->resolvedUrl(ctxt->argument(0).toString())); if(!url.isValid()){ url = QUrl(ctxt->argument(0).toString()); } - c = new QmlComponent(activeEngine, url, activeEngine); + c = new QmlBindableComponent(activeEngine, url, activeEngine); } + c->setContext(context); return engine->newQObject(c); } |