diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-07-21 07:00:45 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-07-21 07:00:45 (GMT) |
commit | 8db694cb38e1f7f5096db96fcc1f168b13e643a4 (patch) | |
tree | 994c34bc6a0d39d697067f331547ee6a20877a8f /src/declarative/qml | |
parent | ae8e2b626a9acc0cdaed8dbc3fb4c2a3b13d19f4 (diff) | |
parent | 4dc3189aea1c619828abdf87e553587c656ede63 (diff) | |
download | Qt-8db694cb38e1f7f5096db96fcc1f168b13e643a4.zip Qt-8db694cb38e1f7f5096db96fcc1f168b13e643a4.tar.gz Qt-8db694cb38e1f7f5096db96fcc1f168b13e643a4.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-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 |
7 files changed, 286 insertions, 27 deletions
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); } |