summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-08-13 02:31:54 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-08-13 02:31:54 (GMT)
commit4a8f38ed6ef6c1cb4a0ac7d2e123b6c42332fd07 (patch)
tree40adb805bff19393f9534e0ed84ac3f1009a1e14 /src/declarative/qml
parent89a2087b7ec5e36f7f4dd16d942aa23d2c7a6042 (diff)
downloadQt-4a8f38ed6ef6c1cb4a0ac7d2e123b6c42332fd07.zip
Qt-4a8f38ed6ef6c1cb4a0ac7d2e123b6c42332fd07.tar.gz
Qt-4a8f38ed6ef6c1cb4a0ac7d2e123b6c42332fd07.tar.bz2
Add delay parameter to the destroy function on QML objects
Also updated dynamic example to have a fadeout effect on deletion. Also slipped in a toStr function, as it didn't work when I called it toString.
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlengine.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index bdbf2e7..5a10c3b 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -55,6 +55,7 @@
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QNetworkAccessManager>
+#include <QTimer>
#include <QList>
#include <QPair>
#include <QDebug>
@@ -929,12 +930,37 @@ void QmlValueTypeScriptClass::setProperty(QScriptValue &object,
QtScript for QML.
*/
+QScriptValue QmlObjectToString(QScriptContext *context, QScriptEngine *engine)
+{
+ QObject* obj = context->thisObject().data().toQObject();
+ QString ret = QLatin1String("Qml Object, ");
+ if(obj){
+ //###Should this be designer or developer details? Dev for now.
+ //TODO: Can we print the id too?
+ ret += QLatin1String("\"");
+ ret += obj->objectName();
+ ret += QLatin1String("\" ");
+ ret += obj->metaObject()->className();
+ ret += QLatin1String("(0x");
+ ret += QString::number((int)obj,16);
+ ret += QLatin1String(")");
+ }else{
+ ret += "null";
+ }
+ return engine->newVariant(ret);
+}
+
QScriptValue QmlObjectDestroy(QScriptContext *context, QScriptEngine *engine)
{
QObject* obj = context->thisObject().data().toQObject();
- if(obj)
- delete obj;
- context->thisObject().setData(QScriptValue(engine, 0));
+ if(obj){
+ int delay = 0;
+ if(context->argumentCount() > 0)
+ delay = context->argument(0).toInt32();
+ QTimer::singleShot(delay, obj, SLOT(deleteLater()));
+ //### Should this be delayed as well?
+ context->thisObject().setData(QScriptValue(engine, 0));
+ }
return engine->nullValue();
}
@@ -944,6 +970,8 @@ QmlObjectScriptClass::QmlObjectScriptClass(QmlEngine *bindEngine)
engine = bindEngine;
QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(bindEngine);
prototypeObject = scriptEngine->newObject();
+ prototypeObject.setProperty(QLatin1String("toStr"),//TODO: Why won't toString work?
+ scriptEngine->newFunction(QmlObjectToString));
prototypeObject.setProperty(QLatin1String("destroy"),
scriptEngine->newFunction(QmlObjectDestroy));
}