summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-06-09 05:57:17 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-06-09 05:57:17 (GMT)
commit1ef0d84c8e5d706e60e487fc801f90bbf5fddaa6 (patch)
tree0e630af6b2e38af7615f4e334ce2bb51d8856b36
parentfd346fc1f24ca39385a9e0b4cb188f157eea2b55 (diff)
parent45ad5f8e643f8a1bd52143ad628e5418f5ae8fa3 (diff)
downloadQt-1ef0d84c8e5d706e60e487fc801f90bbf5fddaa6.zip
Qt-1ef0d84c8e5d706e60e487fc801f90bbf5fddaa6.tar.gz
Qt-1ef0d84c8e5d706e60e487fc801f90bbf5fddaa6.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--src/declarative/qml/qmlcomponent.cpp1
-rw-r--r--src/declarative/qml/qmlcomponent.h1
-rw-r--r--src/declarative/qml/qmlengine.cpp74
-rw-r--r--src/declarative/qml/qmlengine.h1
-rw-r--r--src/declarative/qml/qmlengine_p.h3
5 files changed, 62 insertions, 18 deletions
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp
index 267fba8..f90af4a 100644
--- a/src/declarative/qml/qmlcomponent.cpp
+++ b/src/declarative/qml/qmlcomponent.cpp
@@ -59,6 +59,7 @@
QT_BEGIN_NAMESPACE
class QByteArray;
+int statusId = qRegisterMetaType<QmlComponent::Status>("QmlComponent::Status");
/*!
\class QmlComponent
diff --git a/src/declarative/qml/qmlcomponent.h b/src/declarative/qml/qmlcomponent.h
index bb76c8b..fe0c422 100644
--- a/src/declarative/qml/qmlcomponent.h
+++ b/src/declarative/qml/qmlcomponent.h
@@ -104,6 +104,7 @@ private:
friend class QmlVME;
friend struct QmlCompositeTypeData;
};
+Q_DECLARE_METATYPE(QmlComponent::Status);
QML_DECLARE_TYPE(QmlComponent)
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index d8ca809..73b9245 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -842,27 +842,48 @@ QScriptValue QmlEngine::qmlScriptObject(QObject* object, QmlEngine* engine)
This function takes the URL of a QML file as its only argument. It returns
a component object which can be used to create and load that QML file.
- Example JavaScript:
+ Example JavaScript is below, remember that QML files that might be loaded
+ over the network cannot be expected to be ready immediately.
\code
- component = createComponent("Sprite.qml");
- if(component.isReady()){
- sprite = component.create();
- if(sprite == 0){
+ var component;
+ var sprite;
+ function finishCreation(){
+ if(component.isReady()){
+ sprite = component.createObject();
+ if(sprite == 0){
+ // Error Handling
+ }else{
+ sprite.parent = page;
+ sprite.x = 200;
+ //...
+ }
+ }else if(component.isError()){
// Error Handling
- }else{
- sprite.parent = page;
- sprite.x = 200;
- //...
}
+ }
+
+ component = createComponent("Sprite.qml");
+ if(component.isReady()){
+ finishCreation();
}else{
- // The finishCreation function does the same thing as the above
- // if(component.isReady()) branch
component.statusChanged.connect(finishCreation);
}
\endcode
- Remember that QML files that might be loaded over the network cannot be
- expected to be ready immediately.
+ If you are certain the files will be local, you could simplify to
+
+ \code
+ component = createComponent("Sprite.qml");
+ sprite = component.createObject();
+ if(sprite == 0){
+ // Error Handling
+ }else{
+ sprite.parent = page;
+ sprite.x = 200;
+ //...
+ }
+ \endcode
+
*/
QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *engine)
{
@@ -872,8 +893,8 @@ QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *eng
if(ctxt->argumentCount() != 1 || !activeEngine){
c = new QmlComponent(activeEngine);
}else{
- c = new QmlComponent(activeEngine, QUrl(ctxt->argument(0).toString()),
- activeEngine);
+ QUrl url = QUrl(ctxt->argument(0).toString());
+ c = new QmlComponent(activeEngine, url, activeEngine);
}
return engine->newQObject(c);
}
@@ -897,7 +918,7 @@ QScriptValue QmlEngine::createQMLObject(QScriptContext *ctxt, QScriptEngine *eng
if(ctxt->argumentCount() < 1){
qWarning() << "createQMLObject requires a string argument.";
}else{
- qWarning() << "createQMLObject failed inexplicably.";
+ qWarning() << "createQMLObject cannot find engine.";
}
return engine->nullValue();
}
@@ -1518,18 +1539,37 @@ void QmlContextScriptClass::setProperty(QScriptValue &object,
/////////////////////////////////////////////////////////////
/*
The QmlObjectScriptClass handles property access for QObjects
- via QtScript.
+ via QtScript. It is also used to provide a more useful API in
+ QtScript for QML.
*/
+
+QScriptValue QmlObjectDestroy(QScriptContext *context, QScriptEngine *engine)
+{
+ QObject* obj = context->thisObject().data().toQObject();
+ if(obj)
+ delete obj;
+ context->thisObject().setData(QScriptValue(engine, 0));
+ return engine->nullValue();
+}
+
QmlObjectScriptClass::QmlObjectScriptClass(QmlEngine *bindEngine)
: QmlScriptClass(bindEngine)
{
engine = bindEngine;
+ prototypeObject = engine->scriptEngine()->newObject();
+ prototypeObject.setProperty("destroy",
+ engine->scriptEngine()->newFunction(QmlObjectDestroy));
}
QmlObjectScriptClass::~QmlObjectScriptClass()
{
}
+QScriptValue QmlObjectScriptClass::prototype() const
+{
+ return prototypeObject;
+}
+
QScriptClass::QueryFlags QmlObjectScriptClass::queryProperty(const QScriptValue &object,
const QScriptString &name,
QueryFlags flags, uint *id)
diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h
index ca66097..f114379 100644
--- a/src/declarative/qml/qmlengine.h
+++ b/src/declarative/qml/qmlengine.h
@@ -90,7 +90,6 @@ public:
static QScriptValue qmlScriptObject(QObject*, QmlEngine*);
- // Below two functions provide a way to dynamically create objects from JS
static QScriptValue createComponent(QScriptContext*, QScriptEngine*);
static QScriptValue createQMLObject(QScriptContext*, QScriptEngine*);
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 89b0a4a..d7249e4 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -221,6 +221,9 @@ public:
QmlObjectScriptClass(QmlEngine *);
~QmlObjectScriptClass();
+ virtual QScriptValue prototype () const;
+ QScriptValue prototypeObject;
+
virtual QueryFlags queryProperty(const QScriptValue &object,
const QScriptString &name,
QueryFlags flags, uint *id);