diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-08-27 08:21:33 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-08-27 08:21:33 (GMT) |
commit | 1651d5d9109d60f9f6a63e18e31b59b90aeda6f8 (patch) | |
tree | 5b921d91446efa24c5121dc4322b0b9e82c4cb19 | |
parent | dd60bef7c93a09a92228574bade084d520e711f9 (diff) | |
parent | f73d25d19a8978be3735f696f5f3bf6fe5ca68ee (diff) | |
download | Qt-1651d5d9109d60f9f6a63e18e31b59b90aeda6f8.zip Qt-1651d5d9109d60f9f6a63e18e31b59b90aeda6f8.tar.gz Qt-1651d5d9109d60f9f6a63e18e31b59b90aeda6f8.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r-- | src/declarative/fx/qfxgridview.cpp | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 6 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 66 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 5 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qmlengine/functions.qml | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qmlengine/tst_qmlengine.cpp | 87 |
7 files changed, 153 insertions, 24 deletions
diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index b429895..bf6e863 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -1254,6 +1254,7 @@ void QFxGridView::itemsInserted(int modelIndex, int count) void QFxGridView::itemsRemoved(int modelIndex, int count) { Q_D(QFxGridView); + bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; int index = d->mapFromModel(modelIndex); if (index == -1) { if (modelIndex + count - 1 < d->visibleIndex) { @@ -1269,7 +1270,7 @@ void QFxGridView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. d->releaseItem(d->currentItem); d->currentItem = 0; @@ -1311,7 +1312,7 @@ void QFxGridView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. d->releaseItem(d->currentItem); d->currentItem = 0; diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 0dfdce8..c1e03dd 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1522,6 +1522,7 @@ void QFxListView::itemsRemoved(int modelIndex, int count) { Q_D(QFxListView); d->updateUnrequestedIndexes(); + bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; if (!d->mapRangeFromModel(modelIndex, count)) { if (modelIndex + count - 1 < d->visibleIndex) { // Items removed before our visible items. @@ -1536,7 +1537,7 @@ void QFxListView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. d->releaseItem(d->currentItem); d->currentItem = 0; @@ -1579,8 +1580,9 @@ void QFxListView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. + d->currentItem->attached->setIsCurrentItem(false); d->releaseItem(d->currentItem); d->currentItem = 0; d->currentIndex = -1; diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index cf90fe7..de88241 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -72,6 +72,7 @@ #include <QtCore/qthread.h> #include <QtCore/qcoreapplication.h> #include <QtCore/qdir.h> +#include <QtGui/qcolor.h> #include <QtGui/qvector3d.h> #include <qmlcomponent.h> #include "private/qmlcomponentjs_p.h" @@ -116,6 +117,12 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) desktopObject.setProperty(QLatin1String("openUrl"),scriptEngine.newFunction(desktopOpenUrl, 1)); qtObject.setProperty(QLatin1String("DesktopServices"), desktopObject); scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject); + qtObject.setProperty(QLatin1String("rgba"), scriptEngine.newFunction(QmlEnginePrivate::rgba, 4)); + qtObject.setProperty(QLatin1String("hsla"), scriptEngine.newFunction(QmlEnginePrivate::hsla, 4)); + qtObject.setProperty(QLatin1String("rect"), scriptEngine.newFunction(QmlEnginePrivate::rect, 4)); + qtObject.setProperty(QLatin1String("point"), scriptEngine.newFunction(QmlEnginePrivate::point, 2)); + qtObject.setProperty(QLatin1String("size"), scriptEngine.newFunction(QmlEnginePrivate::size, 2)); + qtObject.setProperty(QLatin1String("vector3d"), scriptEngine.newFunction(QmlEnginePrivate::vector, 3)); } QmlEnginePrivate::~QmlEnginePrivate() @@ -172,7 +179,7 @@ void QmlEnginePrivate::init() scriptEngine.globalObject().setProperty(QLatin1String("createComponent"), scriptEngine.newFunction(QmlEnginePrivate::createComponent, 1)); scriptEngine.globalObject().setProperty(QLatin1String("vector"), - scriptEngine.newFunction(QmlEnginePrivate::vector, 1)); + scriptEngine.newFunction(QmlEnginePrivate::vector, 3)); if (QCoreApplication::instance()->thread() == q->thread() && QmlEngineDebugServer::isDebuggingEnabled()) { @@ -710,7 +717,7 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi QVector3D as usual. This function takes three numeric components and combines them into a - QMLJS string that can be used with any property that takes a + QVector3D value that can be used with any property that takes a QVector3D argument. The following QML code: \code @@ -741,6 +748,59 @@ QScriptValue QmlEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engin return engine->newVariant(qVariantFromValue(QVector3D(x, y, z))); } +QScriptValue QmlEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine) +{ + int argCount = ctxt->argumentCount(); + if(argCount < 3) + return engine->nullValue(); + qsreal r = ctxt->argument(0).toNumber(); + qsreal g = ctxt->argument(1).toNumber(); + qsreal b = ctxt->argument(2).toNumber(); + qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1; + return qScriptValueFromValue(engine, qVariantFromValue(QColor::fromRgbF(r, g, b, a))); +} + +QScriptValue QmlEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine *engine) +{ + int argCount = ctxt->argumentCount(); + if(argCount < 3) + return engine->nullValue(); + qsreal h = ctxt->argument(0).toNumber(); + qsreal s = ctxt->argument(1).toNumber(); + qsreal l = ctxt->argument(2).toNumber(); + qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1; + return qScriptValueFromValue(engine, qVariantFromValue(QColor::fromHslF(h, s, l, a))); +} + +QScriptValue QmlEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine) +{ + if(ctxt->argumentCount() < 4) + return engine->nullValue(); + qsreal x = ctxt->argument(0).toNumber(); + qsreal y = ctxt->argument(1).toNumber(); + qsreal w = ctxt->argument(2).toNumber(); + qsreal h = ctxt->argument(3).toNumber(); + return qScriptValueFromValue(engine, qVariantFromValue(QRectF(x, y, w, h))); +} + +QScriptValue QmlEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine) +{ + if(ctxt->argumentCount() < 2) + return engine->nullValue(); + qsreal x = ctxt->argument(0).toNumber(); + qsreal y = ctxt->argument(1).toNumber(); + return qScriptValueFromValue(engine, qVariantFromValue(QPointF(x, y))); +} + +QScriptValue QmlEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) +{ + if(ctxt->argumentCount() < 2) + return engine->nullValue(); + qsreal w = ctxt->argument(0).toNumber(); + qsreal h = ctxt->argument(1).toNumber(); + return qScriptValueFromValue(engine, qVariantFromValue(QSizeF(w, h))); +} + QmlScriptClass::QmlScriptClass(QmlEngine *bindengine) : QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)), engine(bindengine) @@ -983,7 +1043,7 @@ QScriptValue QmlObjectToString(QScriptContext *context, QScriptEngine *engine) ret += QString::number((quintptr)obj,16); ret += QLatin1String(")"); }else{ - ret += "null"; + ret += QLatin1String("null"); } return engine->newVariant(ret); } diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 53b2967..c2de72b 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -214,6 +214,11 @@ public: static QScriptValue createComponent(QScriptContext*, QScriptEngine*); static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*); static QScriptValue vector(QScriptContext*, QScriptEngine*); + static QScriptValue rgba(QScriptContext*, QScriptEngine*); + static QScriptValue hsla(QScriptContext*, QScriptEngine*); + static QScriptValue point(QScriptContext*, QScriptEngine*); + static QScriptValue size(QScriptContext*, QScriptEngine*); + static QScriptValue rect(QScriptContext*, QScriptEngine*); static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index cc5e4ee..1e8ce91 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -532,7 +532,7 @@ QmlAbstractBinding *QmlMetaProperty::binding() const QmlAbstractBinding *binding = data->bindings; while (binding) { // ### This wont work for value types - if (binding->propertyIndex() == d->coreIdx) + if (binding->propertyIndex() == d->coreIdx) //### should we check for enabled? return binding; binding = binding->m_nextBinding; } diff --git a/tests/auto/declarative/qmlengine/functions.qml b/tests/auto/declarative/qmlengine/functions.qml new file mode 100644 index 0000000..28e8ed4 --- /dev/null +++ b/tests/auto/declarative/qmlengine/functions.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + rectProperty: Qt.rect(0,0,100,100) + rectFProperty: Qt.rect(0,0.5,100,99.5) +} diff --git a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp index 9a04c61..8c050cb 100644 --- a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp +++ b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp @@ -1,4 +1,6 @@ #include <qtest.h> +#include <QtDeclarative/qml.h> +#include <QtDeclarative/QmlComponent> #include <QtDeclarative/QmlEngine> #include <QtCore/QDebug> @@ -12,30 +14,83 @@ public: tst_qmlengine() {} private slots: - void componentSearchPath(); -}; + void valueTypeFunctions(); +private: + QmlEngine engine; +}; -void tst_qmlengine::componentSearchPath() +class MyTypeObject : public QObject { - QFile file(SRCDIR "/imports.qml"); - QVERIFY(file.open(QIODevice::ReadOnly)); + Q_OBJECT + Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); + Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); + Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); + Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); + Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged); + Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); + +public: + MyTypeObject() {} - QmlEngine engine; + QPoint pointPropertyValue; + QPoint pointProperty() const { + return pointPropertyValue; + } + void setPointProperty(const QPoint &v) { + pointPropertyValue = v; + } - QList<QUrl> searchPath = engine.componentSearchPath(file.readAll(), - QUrl::fromLocalFile(file.fileName())); + QPointF pointFPropertyValue; + QPointF pointFProperty() const { + return pointFPropertyValue; + } + void setPointFProperty(const QPointF &v) { + pointFPropertyValue = v; + } - QList<QUrl> expected; - expected << QUrl::fromLocalFile(SRCDIR); - expected << QUrl::fromLocalFile(file.fileName()).resolved(QUrl("import1")); - expected << QUrl::fromLocalFile(file.fileName()).resolved(QUrl("import2")); + QSize sizePropertyValue; + QSize sizeProperty() const { + return sizePropertyValue; + } + void setSizeProperty(const QSize &v) { + sizePropertyValue = v; + } - QCOMPARE(searchPath.size(), expected.size()); - for (int i = 0; i < expected.size(); ++i) { - QCOMPARE(searchPath.at(i).toString(QUrl::StripTrailingSlash), - expected.at(i).toString(QUrl::StripTrailingSlash)); + QSizeF sizeFPropertyValue; + QSizeF sizeFProperty() const { + return sizeFPropertyValue; } + void setSizeFProperty(const QSizeF &v) { + sizeFPropertyValue = v; + } + + QRect rectPropertyValue; + QRect rectProperty() const { + return rectPropertyValue; + } + void setRectProperty(const QRect &v) { + rectPropertyValue = v; + } + + QRectF rectFPropertyValue; + QRectF rectFProperty() const { + return rectFPropertyValue; + } + void setRectFProperty(const QRectF &v) { + rectFPropertyValue = v; + } + +}; +QML_DECLARE_TYPE(MyTypeObject); +QML_DEFINE_TYPE(Test, 1, 0, 0, MyTypeObject, MyTypeObject); + +void tst_qmlengine::valueTypeFunctions() +{ + QmlComponent component(&engine, SRCDIR "/functions.qml"); + MyTypeObject *obj = qobject_cast<MyTypeObject*>(component.create()); + QCOMPARE(obj->rectProperty(), QRect(0,0,100,100)); + QCOMPARE(obj->rectFProperty(), QRectF(0,0.5,100,99.5)); } QTEST_MAIN(tst_qmlengine) |