summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-04-30 07:21:31 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-04-30 07:21:31 (GMT)
commitd8683cd18c852569672e43237c06dc619f193eba (patch)
tree32dfe36ba1d99aa2817dc3bdb91f0ec01b1d4c67
parent85db980578cb9f1b95be160a4386d9822c6ec6d0 (diff)
parent5d34515465d143d08d198b799489f472741a340f (diff)
downloadQt-d8683cd18c852569672e43237c06dc619f193eba.zip
Qt-d8683cd18c852569672e43237c06dc619f193eba.tar.gz
Qt-d8683cd18c852569672e43237c06dc619f193eba.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
-rw-r--r--doc/src/declarative/dynamicobjects.qdoc14
-rw-r--r--doc/src/declarative/globalobject.qdoc3
-rw-r--r--examples/declarative/fonts/availableFonts.qml17
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp20
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h1
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp18
-rw-r--r--tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml14
-rw-r--r--tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp14
9 files changed, 93 insertions, 14 deletions
diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc
index c376266..5cdd768 100644
--- a/doc/src/declarative/dynamicobjects.qdoc
+++ b/doc/src/declarative/dynamicobjects.qdoc
@@ -68,7 +68,7 @@ the \l {Qt.createComponent(url file)}{Qt.createComponent()} function on the \l{Q
This function takes the URL of the QML file as its only argument and returns
a component object which can be used to create and load that QML file.
-Once you have a component you can use its \c createObject() method to create an instance of
+Once you have a component you can use its \l {Component::createObject()}{createObject()} method to create an instance of
the component.
Here is an example. Here is a \c Sprite.qml, which defines a simple QML component:
@@ -123,19 +123,13 @@ The actual creation context depends on how an item is created:
is the QDeclarativeContext in which this method is called
\o If \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()}
if called, it is the context of the item used as the second argument to this method
-\o If a \c {Component \{\}} item is defined and \c {Component::}{createObject()} is called,
- it is the context in which the \c Component item is defined
+\o If a \c {Component{}} item is defined and \l {Component::createObject()}{createObject()}
+ is called on that item, it is the context in which the \c Component is defined
+\endlist
Also, note that while dynamically created objects may be used the same as other objects, they
do not have an id in QML.
-A restriction which you need to manage with dynamically created items,
-is that the creation context must outlive the
-created item. The creation context is the QDeclarativeContext in which \c Qt.createComponent()
-was called, or the context in which the Component element, or the item used as the
-second argument to \c Qt.createQmlObject(), was specified. If the creation
-context is destroyed before the dynamic item is, then bindings in the dynamic item will
-fail to work.
\section1 Deleting Objects Dynamically
You should generally avoid dynamically deleting objects that you did not
diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc
index 47460cf..7c27ae4 100644
--- a/doc/src/declarative/globalobject.qdoc
+++ b/doc/src/declarative/globalobject.qdoc
@@ -226,6 +226,9 @@ This function causes the QML engine to emit the quit signal, which in
This function returns \c url resolved relative to the URL of the
caller.
+\section3 Qt.fontFamilies()
+This function returns a list of the font families available to the application.
+
\section3 Qt.isQtObject(object)
Returns true if \c object is a valid reference to a Qt or QML object, otherwise false.
diff --git a/examples/declarative/fonts/availableFonts.qml b/examples/declarative/fonts/availableFonts.qml
new file mode 100644
index 0000000..defa4ce
--- /dev/null
+++ b/examples/declarative/fonts/availableFonts.qml
@@ -0,0 +1,17 @@
+import Qt 4.7
+
+Rectangle {
+ width: 480; height: 640; color: "steelblue"
+
+ ListView {
+ anchors.fill: parent; model: Qt.fontFamilies()
+
+ delegate: Item {
+ height: 40; width: ListView.view.width
+ Text {
+ anchors.centerIn: parent
+ text: modelData; font.family: modelData; font.pixelSize: 24; color: "white"
+ }
+ }
+ }
+}
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 3f4a735..dee5ec6 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -82,6 +82,7 @@
#include <QStack>
#include <QMap>
#include <QPluginLoader>
+#include <QtGui/qfontdatabase.h>
#include <QtCore/qlibraryinfo.h>
#include <QtCore/qthreadstorage.h>
#include <QtCore/qthread.h>
@@ -225,6 +226,7 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
//misc methods
qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1));
+ qtObject.setProperty(QLatin1String("fontFamilies"),newFunction(QDeclarativeEnginePrivate::fontFamilies, 0));
qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1));
qtObject.setProperty(QLatin1String("btoa"),newFunction(QDeclarativeEnginePrivate::btoa, 1));
qtObject.setProperty(QLatin1String("atob"),newFunction(QDeclarativeEnginePrivate::atob, 1));
@@ -1075,7 +1077,7 @@ QScriptValue QDeclarativeEnginePrivate::vector(QScriptContext *ctxt, QScriptEngi
qsreal x = ctxt->argument(0).toNumber();
qsreal y = ctxt->argument(1).toNumber();
qsreal z = ctxt->argument(2).toNumber();
- return engine->newVariant(qVariantFromValue(QVector3D(x, y, z)));
+ return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QVector3D(x, y, z)));
}
QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine)
@@ -1198,7 +1200,7 @@ QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine
if (w < 0 || h < 0)
return engine->nullValue();
- return qScriptValueFromValue(engine, qVariantFromValue(QRectF(x, y, w, h)));
+ return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QRectF(x, y, w, h)));
}
QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine)
@@ -1207,7 +1209,7 @@ QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngin
return ctxt->throwError("Qt.point(): Invalid arguments");
qsreal x = ctxt->argument(0).toNumber();
qsreal y = ctxt->argument(1).toNumber();
- return qScriptValueFromValue(engine, qVariantFromValue(QPointF(x, y)));
+ return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QPointF(x, y)));
}
QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine)
@@ -1216,7 +1218,7 @@ QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine
return ctxt->throwError("Qt.size(): Invalid arguments");
qsreal w = ctxt->argument(0).toNumber();
qsreal h = ctxt->argument(1).toNumber();
- return qScriptValueFromValue(engine, qVariantFromValue(QSizeF(w, h)));
+ return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QSizeF(w, h)));
}
QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine)
@@ -1274,6 +1276,16 @@ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QSc
return QScriptValue(e, ret);
}
+QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e)
+{
+ if(ctxt->argumentCount() != 0)
+ return ctxt->throwError("Qt.fontFamilies(): Invalid arguments");
+
+ QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(e);
+ QFontDatabase database;
+ return p->scriptValueFromVariant(database.families());
+}
+
QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *)
{
if (ctxt->argumentCount() != 1)
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 45656e8..531ac97 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -294,6 +294,7 @@ public:
static QScriptValue tint(QScriptContext*, QScriptEngine*);
static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*);
+ static QScriptValue fontFamilies(QScriptContext*, QScriptEngine*);
static QScriptValue md5(QScriptContext*, QScriptEngine*);
static QScriptValue btoa(QScriptContext*, QScriptEngine*);
static QScriptValue atob(QScriptContext*, QScriptEngine*);
diff --git a/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml b/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml
new file mode 100644
index 0000000..e66c7be
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+QtObject {
+ property variant test1: Qt.fontFamilies(10)
+ property variant test2: Qt.fontFamilies();
+}
diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
index 17b7925..5095be8 100644
--- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
+++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
@@ -42,6 +42,7 @@
#include <qtest.h>
#include <QDebug>
#include <QDeclarativeEngine>
+#include <QFontDatabase>
#include <QFileInfo>
#include <QDeclarativeComponent>
#include <QDesktopServices>
@@ -76,6 +77,7 @@ private slots:
void isQtObject();
void btoa();
void atob();
+ void fontFamilies();
private:
QDeclarativeEngine engine;
@@ -483,6 +485,22 @@ void tst_qdeclarativeqt::atob()
delete object;
}
+void tst_qdeclarativeqt::fontFamilies()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("fontFamilies.qml"));
+
+ QString warning1 = component.url().toString() + ":4: Error: Qt.fontFamilies(): Invalid arguments";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QFontDatabase database;
+ QCOMPARE(object->property("test2"), QVariant::fromValue(database.families()));
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeqt)
#include "tst_qdeclarativeqt.moc"
diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml
new file mode 100644
index 0000000..e4715ab
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml
@@ -0,0 +1,14 @@
+import Qt 4.7
+
+QtObject {
+ property int x;
+ property int y;
+ property int z;
+
+ Component.onCompleted: {
+ var vec3 = Qt.vector3d(1, 2, 3);
+ x = vec3.x;
+ y = vec3.y;
+ z = vec3.z;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp
index c18fbf5..95b9baa 100644
--- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp
+++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp
@@ -84,6 +84,7 @@ private slots:
void enums();
void conflictingBindings();
void returnValues();
+ void varAssignment();
private:
QDeclarativeEngine engine;
@@ -911,6 +912,19 @@ void tst_qdeclarativevaluetypes::returnValues()
delete object;
}
+void tst_qdeclarativevaluetypes::varAssignment()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("varAssignment.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("x").toInt(), 1);
+ QCOMPARE(object->property("y").toInt(), 2);
+ QCOMPARE(object->property("z").toInt(), 3);
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativevaluetypes)
#include "tst_qdeclarativevaluetypes.moc"