summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-09-03 00:54:01 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-09-03 00:54:01 (GMT)
commit46440f4549814ac0025eaf4b527a4c35afd6258c (patch)
tree18480680359cab2cac760bb779d43da8aac0d094
parentc452c44d8cee138dcdd62f8c0f0db48b4ada5c40 (diff)
parent8ac9c707306f0eb8804310f47894d4723e190bce (diff)
downloadQt-46440f4549814ac0025eaf4b527a4c35afd6258c.zip
Qt-46440f4549814ac0025eaf4b527a4c35afd6258c.tar.gz
Qt-46440f4549814ac0025eaf4b527a4c35afd6258c.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--src/declarative/qml/qmlcompiler.cpp2
-rw-r--r--src/declarative/qml/qmlcompiler_p.h1
-rw-r--r--src/declarative/qml/qmlcomponent.cpp1
-rw-r--r--src/declarative/qml/qmlcontext_p.h2
-rw-r--r--src/declarative/qml/qmlengine.cpp302
-rw-r--r--src/declarative/qml/qmlengine_p.h52
-rw-r--r--tests/auto/declarative/qmlbindengine/enums.1.qml20
-rw-r--r--tests/auto/declarative/qmlbindengine/testtypes.h19
-rw-r--r--tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp19
-rw-r--r--tests/auto/declarative/simplecanvasitem/data/test.qml60
-rw-r--r--tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp79
-rw-r--r--tests/auto/declarative/states/data/basicBinding.qml12
-rw-r--r--tests/auto/declarative/states/data/basicBinding2.qml12
-rw-r--r--tests/auto/declarative/states/data/basicBinding3.qml13
-rw-r--r--tests/auto/declarative/states/data/basicBinding4.qml17
-rw-r--r--tests/auto/declarative/states/data/basicChanges.qml10
-rw-r--r--tests/auto/declarative/states/data/basicChanges2.qml15
-rw-r--r--tests/auto/declarative/states/data/basicChanges3.qml15
-rw-r--r--tests/auto/declarative/states/data/basicExtension.qml16
-rw-r--r--tests/auto/declarative/states/data/fakeExtension.qml16
-rw-r--r--tests/auto/declarative/states/states.pro (renamed from tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro)3
-rw-r--r--tests/auto/declarative/states/tst_states.cpp267
-rw-r--r--tools/qmlviewer/main.cpp5
-rw-r--r--tools/qmlviewer/qmlviewer.cpp18
-rw-r--r--tools/qmlviewer/qmlviewer.h1
-rw-r--r--tools/qmlviewer/qmlviewer.pro5
26 files changed, 750 insertions, 232 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index c411b8d..b8e9d47 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -642,6 +642,8 @@ void QmlCompiler::compileTree(Object *tree)
def.type = QmlInstruction::SetDefault;
output->bytecode << def;
+ output->imports = unit->imports;
+
if (tree->metatype)
static_cast<QMetaObject &>(output->root) = *tree->metaObject();
else
diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h
index c42c2d9..83c415c 100644
--- a/src/declarative/qml/qmlcompiler_p.h
+++ b/src/declarative/qml/qmlcompiler_p.h
@@ -76,6 +76,7 @@ public:
QByteArray name;
QUrl url;
+ QmlEnginePrivate::Imports imports;
struct TypeReference
{
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp
index c844a32..e897cce 100644
--- a/src/declarative/qml/qmlcomponent.cpp
+++ b/src/declarative/qml/qmlcomponent.cpp
@@ -488,6 +488,7 @@ QObject *QmlComponent::beginCreate(QmlContext *context)
static_cast<QmlContextPrivate *>(QObjectPrivate::get(context));
QmlContext *ctxt = new QmlContext(context, 0, true);
static_cast<QmlContextPrivate*>(ctxt->d_func())->url = d->cc->url;
+ static_cast<QmlContextPrivate*>(ctxt->d_func())->imports = d->cc->imports;
QmlVME vme;
QObject *rv = vme.run(ctxt, d->cc, d->start, d->count);
diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h
index 84d990c..b305408 100644
--- a/src/declarative/qml/qmlcontext_p.h
+++ b/src/declarative/qml/qmlcontext_p.h
@@ -60,6 +60,7 @@
#include <QtScript/qscriptvalue.h>
#include <QtCore/qset.h>
#include <private/qguard_p.h>
+#include <private/qmlengine_p.h>
QT_BEGIN_NAMESPACE
@@ -91,6 +92,7 @@ public:
QScriptValueList scopeChain;
QUrl url;
+ QmlEnginePrivate::Imports imports;
void init();
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index e342d3f..3d8b2c4 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -181,6 +181,7 @@ void QmlEnginePrivate::init()
contextClass = new QmlContextScriptClass(q);
objectClass = new QmlObjectScriptClass(q);
valueTypeClass = new QmlValueTypeScriptClass(q);
+ typeNameClass = new QmlTypeNameScriptClass(q);
rootContext = new QmlContext(q,true);
#ifdef QT_SCRIPTTOOLS_LIB
if (qmlDebugger()){
@@ -211,40 +212,158 @@ QmlEnginePrivate::CapturedProperty::CapturedProperty(const QmlMetaProperty &p)
{
}
+struct QmlTypeNameBridge
+{
+ QObject *object;
+ QmlType *type;
+ QmlEnginePrivate::ImportedNamespace *ns;
+};
+Q_DECLARE_METATYPE(QmlTypeNameBridge);
+
+struct QmlValueTypeReference {
+ QmlValueType *type;
+ QGuard<QObject> object;
+ int property;
+};
+Q_DECLARE_METATYPE(QmlValueTypeReference);
+
////////////////////////////////////////////////////////////////////
-typedef QHash<QPair<const QMetaObject *, QString>, bool> FunctionCache;
-Q_GLOBAL_STATIC(FunctionCache, functionCache);
+QScriptClass::QueryFlags
+QmlEnginePrivate::queryContext(const QString &propName, uint *id,
+ QmlContext *bindContext)
+{
+ resolveData.safetyCheckId++;
+ *id = resolveData.safetyCheckId;
+ resolveData.clear();
+
+ QHash<QString, int>::Iterator contextProperty =
+ bindContext->d_func()->propertyNames.find(propName);
+
+ if (contextProperty != bindContext->d_func()->propertyNames.end()) {
+
+ resolveData.context = bindContext;
+ resolveData.contextIndex = *contextProperty;
+
+ return QScriptClass::HandlesReadAccess;
+ }
+
+ QmlType *type = 0; ImportedNamespace *ns = 0;
+ if (currentExpression && bindContext == currentExpression->context() &&
+ propName.at(0).isUpper() && resolveType(bindContext->d_func()->imports, propName.toUtf8(), &type, 0, 0, 0, &ns)) {
+
+ if (type || ns) {
+ // Must be either an attached property, or an enum
+ resolveData.object = bindContext->d_func()->defaultObjects.first();
+ resolveData.type = type;
+ resolveData.ns = ns;
+ return QScriptClass::HandlesReadAccess;
+ }
+
+ }
+
+ QScriptClass::QueryFlags rv = 0;
+ for (int ii = 0; !rv && ii < bindContext->d_func()->defaultObjects.count(); ++ii) {
+ rv = queryObject(propName, id,
+ bindContext->d_func()->defaultObjects.at(ii));
+ }
+
+ return rv;
+}
+
+QScriptValue
+QmlEnginePrivate::propertyContext(const QScriptString &name,
+ QmlContext *bindContext,
+ uint id)
+{
+ Q_ASSERT(id == resolveData.safetyCheckId);
+
+
+ if (resolveData.type || resolveData.ns) {
+ QmlTypeNameBridge tnb = {
+ resolveData.object,
+ resolveData.type,
+ resolveData.ns
+ };
+ return scriptEngine.newObject(typeNameClass, scriptEngine.newVariant(qVariantFromValue(tnb)));
+ } else if (resolveData.context) {
+ QmlContext *bindContext = resolveData.context;
+ QmlContextPrivate *contextPrivate = bindContext->d_func();
+ int index = resolveData.contextIndex;
+
+ QScriptValue rv;
+ if (index < contextPrivate->idValueCount) {
+ rv = scriptEngine.newObject(objectClass, scriptEngine.newVariant(QVariant::fromValue(contextPrivate->idValues[index].data())));
+ } else {
+ QVariant value = contextPrivate->propertyValues.at(index);
+ if (QmlMetaType::isObject(value.userType())) {
+ rv = scriptEngine.newObject(objectClass, scriptEngine.newVariant(value));
+ } else {
+ rv = scriptEngine.newVariant(value);
+ }
+ }
+ capturedProperties << QmlEnginePrivate::CapturedProperty(bindContext, -1, index + contextPrivate->notifyIndex);
+ return rv;
+
+ } else {
+
+ return propertyObject(name, resolveData.object, id);
+
+ }
+
+ return QScriptValue();
+}
+
+void QmlEnginePrivate::setPropertyContext(const QScriptValue &value, uint id)
+{
+ // As context properties cannot be written, we can assume that the
+ // write is a object property write
+ setPropertyObject(value, id);
+}
+
+void QmlEnginePrivate::setPropertyObject(const QScriptValue &value, uint id)
+{
+ Q_ASSERT(id == resolveData.safetyCheckId);
+ Q_Q(QmlEngine);
+
+ resolveData.property.write(QmlScriptClass::toVariant(q, value));
+}
QScriptClass::QueryFlags
QmlEnginePrivate::queryObject(const QString &propName,
uint *id, QObject *obj)
{
+ resolveData.safetyCheckId++;
+ *id = resolveData.safetyCheckId;
+ resolveData.clear();
+
QScriptClass::QueryFlags rv = 0;
QmlContext *ctxt = QmlEngine::contextForObject(obj);
if (!ctxt)
ctxt = rootContext;
QmlMetaProperty prop(obj, propName, ctxt);
+
if (prop.type() == QmlMetaProperty::Invalid) {
QPair<const QMetaObject *, QString> key =
qMakePair(obj->metaObject(), propName);
bool isFunction = false;
- if (functionCache()->contains(key)) {
- isFunction = functionCache()->value(key);
+ if (functionCache.contains(key)) {
+ isFunction = functionCache.value(key);
} else {
QScriptValue sobj = scriptEngine.newQObject(obj);
QScriptValue func = sobj.property(propName);
isFunction = func.isFunction();
- functionCache()->insert(key, isFunction);
+ functionCache.insert(key, isFunction);
}
if (isFunction) {
- *id = QmlScriptClass::FunctionId;
+ resolveData.object = obj;
+ resolveData.isFunction = true;
rv |= QScriptClass::HandlesReadAccess;
- }
+ }
} else {
- *id = QmlScriptClass::PropertyId;
- *id |= prop.save();
+ resolveData.object = obj;
+ resolveData.property = prop;
rv |= QScriptClass::HandlesReadAccess;
if (prop.isWritable())
@@ -254,25 +373,19 @@ QmlEnginePrivate::queryObject(const QString &propName,
return rv;
}
-struct QmlValueTypeReference {
- QmlValueType *type;
- QGuard<QObject> object;
- int property;
-};
-Q_DECLARE_METATYPE(QmlValueTypeReference);
-
QScriptValue QmlEnginePrivate::propertyObject(const QScriptString &propName,
QObject *obj, uint id)
{
- if (id == QmlScriptClass::FunctionId) {
+ Q_ASSERT(id == resolveData.safetyCheckId);
+ Q_ASSERT(resolveData.object);
+
+ if (resolveData.isFunction) {
+ // ### Optimize
QScriptValue sobj = scriptEngine.newQObject(obj);
QScriptValue func = sobj.property(propName);
return func;
} else {
- QmlMetaProperty prop;
- prop.restore(id, obj);
- if (!prop.isValid())
- return QScriptValue();
+ const QmlMetaProperty &prop = resolveData.property;
if (prop.needsChangedNotifier())
capturedProperties << CapturedProperty(prop);
@@ -968,23 +1081,11 @@ QmlContextScriptClass::queryProperty(const QScriptValue &object,
Q_UNUSED(flags);
QmlContext *bindContext =
static_cast<QmlContext*>(object.data().toQObject());
- QueryFlags rv = 0;
QString propName = name.toString();
- *id = InvalidId;
- if (bindContext->d_func()->propertyNames.contains(propName)) {
- rv |= HandlesReadAccess;
- *id = VariantPropertyId;
- }
-
- for (int ii = 0; !rv && ii < bindContext->d_func()->defaultObjects.count(); ++ii) {
- rv = QmlEnginePrivate::get(engine)->queryObject(propName, id, bindContext->d_func()->defaultObjects.at(ii));
- if (rv)
- *id |= (ii << 24);
- }
-
- return rv;
+ QmlEnginePrivate *ep = QmlEnginePrivate::get(engine);
+ return ep->queryContext(propName, id, bindContext);
}
QScriptValue QmlContextScriptClass::property(const QScriptValue &object,
@@ -994,46 +1095,8 @@ QScriptValue QmlContextScriptClass::property(const QScriptValue &object,
QmlContext *bindContext =
static_cast<QmlContext*>(object.data().toQObject());
- uint basicId = id & QmlScriptClass::ClassIdMask;
-
- QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
QmlEnginePrivate *ep = QmlEnginePrivate::get(engine);
-
- switch (basicId) {
- case VariantPropertyId:
- {
- QmlContextPrivate *contextPrivate = bindContext->d_func();
- QString propName = name.toString();
- int index = contextPrivate->propertyNames.value(propName);
-
- QScriptValue rv;
- if (index < contextPrivate->idValueCount) {
- rv = scriptEngine->newObject(ep->objectClass, scriptEngine->newVariant(QVariant::fromValue(contextPrivate->idValues[index].data())));
- } else {
- QVariant value = contextPrivate->propertyValues.at(index);
- if (QmlMetaType::isObject(value.userType())) {
- rv = scriptEngine->newObject(ep->objectClass, scriptEngine->newVariant(value));
- } else {
- rv = scriptEngine->newVariant(value);
- }
- }
- ep->capturedProperties << QmlEnginePrivate::CapturedProperty(bindContext, -1, index + bindContext->d_func()->notifyIndex);
- return rv;
- }
- default:
- {
- int objId = (id & ClassIdSelectorMask) >> 24;
- QObject *obj = bindContext->d_func()->defaultObjects.at(objId);
- QScriptValue rv = ep->propertyObject(name, obj,
- id & ~QmlScriptClass::ClassIdSelectorMask);
- if (rv.isValid()) {
- return rv;
- }
- break;
- }
- }
-
- return QScriptValue();
+ return ep->propertyContext(name, bindContext, id);
}
void QmlContextScriptClass::setProperty(QScriptValue &object,
@@ -1043,17 +1106,82 @@ void QmlContextScriptClass::setProperty(QScriptValue &object,
{
Q_UNUSED(name);
- QmlContext *bindContext =
- static_cast<QmlContext*>(object.data().toQObject());
+ QmlEnginePrivate::get(engine)->setPropertyContext(value, id);
+}
- int objIdx = (id & QmlScriptClass::ClassIdSelectorMask) >> 24;
- QObject *obj = bindContext->d_func()->defaultObjects.at(objIdx);
+/////////////////////////////////////////////////////////////
+QmlTypeNameScriptClass::QmlTypeNameScriptClass(QmlEngine *engine)
+: QmlScriptClass(engine), object(0), type(0)
+{
+}
- QmlMetaProperty prop;
- prop.restore(id, obj);
+QmlTypeNameScriptClass::~QmlTypeNameScriptClass()
+{
+}
- QVariant v = QmlScriptClass::toVariant(engine, value);
- prop.write(v);
+QmlTypeNameScriptClass::QueryFlags
+QmlTypeNameScriptClass::queryProperty(const QScriptValue &scriptObject,
+ const QScriptString &name,
+ QueryFlags flags, uint *id)
+{
+ QmlTypeNameBridge bridge =
+ qvariant_cast<QmlTypeNameBridge>(scriptObject.data().toVariant());
+
+ object = 0;
+ type = 0;
+ QmlEnginePrivate *ep = QmlEnginePrivate::get(engine);
+
+ if (bridge.ns) {
+ QmlType *type = 0;
+ ep->resolveTypeInNamespace(bridge.ns, name.toString().toUtf8(),
+ &type, 0, 0, 0);
+ if (type) {
+ object = bridge.object;
+ this->type = type;
+ return HandlesReadAccess;
+ } else {
+ return 0;
+ }
+
+ } else {
+ Q_ASSERT(bridge.type);
+ QString strName = name.toString();
+ if (strName.at(0).isUpper()) {
+ // Must be an enum
+ // ### Optimize
+ const char *enumName = strName.toUtf8().constData();
+ const QMetaObject *metaObject = bridge.type->baseMetaObject();
+ for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) {
+ QMetaEnum e = metaObject->enumerator(ii);
+ int value = e.keyToValue(enumName);
+ if (value != -1) {
+ enumValue = value;
+ return HandlesReadAccess;
+ }
+ }
+ return 0;
+ } else {
+ // Must be an attached property
+ this->object = qmlAttachedPropertiesObjectById(bridge.type->index(), bridge.object);
+ Q_ASSERT(this->object);
+ return ep->queryObject(strName, id, this->object);
+ }
+ }
+}
+
+QScriptValue QmlTypeNameScriptClass::property(const QScriptValue &,
+ const QScriptString &propName,
+ uint id)
+{
+ QmlEnginePrivate *ep = QmlEnginePrivate::get(engine);
+ if (type) {
+ QmlTypeNameBridge tnb = { object, type, 0 };
+ return ep->scriptEngine.newObject(ep->typeNameClass, ep->scriptEngine.newVariant(qVariantFromValue(tnb)));
+ } else if (object) {
+ return ep->propertyObject(propName, object, id);
+ } else {
+ return QScriptValue(enumValue);
+ }
}
/////////////////////////////////////////////////////////////
@@ -1231,14 +1359,8 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object,
const QScriptValue &value)
{
Q_UNUSED(name);
-
- QObject *obj = object.data().toQObject();
-
- QmlMetaProperty prop;
- prop.restore(id, obj);
-
- QVariant v = QmlScriptClass::toVariant(engine, value);
- prop.write(v);
+ Q_UNUSED(object);
+ QmlEnginePrivate::get(engine)->setPropertyObject(value, id);
}
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index a33add3..f492ccb 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -82,6 +82,7 @@ class QmlExpression;
class QmlBasicScriptNodeCache;
class QmlContextScriptClass;
class QmlObjectScriptClass;
+class QmlTypeNameScriptClass;
class QmlValueTypeScriptClass;
class QScriptEngineDebugger;
class QNetworkReply;
@@ -97,10 +98,17 @@ public:
void init();
+ QScriptClass::QueryFlags queryContext(const QString &name, uint *id,
+ QmlContext *);
+ QScriptValue propertyContext(const QScriptString &propName, QmlContext *,
+ uint id);
+ void setPropertyContext(const QScriptValue &, uint id);
QScriptClass::QueryFlags queryObject(const QString &name, uint *id,
QObject *);
QScriptValue propertyObject(const QScriptString &propName, QObject *,
uint id = 0);
+ void setPropertyObject(const QScriptValue &, uint id);
+
struct CapturedProperty {
CapturedProperty(QObject *o, int c, int n)
@@ -120,9 +128,30 @@ public:
QScriptEngineDebugger *debugger;
#endif
+ struct ImportedNamespace;
+ struct ResolveData {
+ ResolveData() : safetyCheckId(0) {}
+ int safetyCheckId;
+
+ void clear() {
+ object = 0; context = 0;
+ type = 0; ns = 0;
+ contextIndex = -1; isFunction = false;
+ }
+ QObject *object;
+ QmlContext *context;
+
+ QmlType *type;
+ QmlEnginePrivate::ImportedNamespace *ns;
+
+ int contextIndex;
+ bool isFunction;
+ QmlMetaProperty property;
+ } resolveData;
QmlContextScriptClass *contextClass;
QmlObjectScriptClass *objectClass;
QmlValueTypeScriptClass *valueTypeClass;
+ QmlTypeNameScriptClass *typeNameClass;
// Used by DOM Core 3 API
QScriptClass *nodeListClass;
QScriptClass *namedNodeMapClass;
@@ -178,6 +207,9 @@ public:
}
QmlValueTypeFactory valueTypes;
+ // ### Fixme
+ typedef QHash<QPair<const QMetaObject *, QString>, bool> FunctionCache;
+ FunctionCache functionCache;
QHash<const QMetaObject *, QmlMetaObjectCache> propertyCache;
static QmlMetaObjectCache *cache(QmlEnginePrivate *priv, QObject *obj) {
if (!priv || !obj || QObjectPrivate::get(obj)->metaObject) return 0;
@@ -198,7 +230,6 @@ public:
QmlImportsPrivate *d;
};
- struct ImportedNamespace;
bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const;
bool resolveType(const Imports&, const QByteArray& type,
QmlType** type_return, QUrl* url_return,
@@ -292,6 +323,25 @@ public:
const QScriptValue &value);
};
+class QmlTypeNameScriptClass : public QmlScriptClass
+{
+public:
+ QmlTypeNameScriptClass(QmlEngine *);
+ ~QmlTypeNameScriptClass();
+
+ virtual QueryFlags queryProperty(const QScriptValue &object,
+ const QScriptString &name,
+ QueryFlags flags, uint *id);
+ virtual QScriptValue property(const QScriptValue &object,
+ const QScriptString &name,
+ uint id);
+
+private:
+ QObject *object;
+ QmlType *type;
+ quint32 enumValue;
+};
+
class QmlValueTypeScriptClass : public QmlScriptClass
{
public:
diff --git a/tests/auto/declarative/qmlbindengine/enums.1.qml b/tests/auto/declarative/qmlbindengine/enums.1.qml
new file mode 100644
index 0000000..6351823
--- /dev/null
+++ b/tests/auto/declarative/qmlbindengine/enums.1.qml
@@ -0,0 +1,20 @@
+import Qt.test 1.0
+import Qt.test 1.0 as Namespace
+
+MyQmlObject {
+ // Enums from non-namespaced type
+ property int a: MyQmlObject.EnumValue1
+ property int b: MyQmlObject.EnumValue2
+ property int c: MyQmlObject.EnumValue3
+ property int d: MyQmlObject.EnumValue4
+
+ // Enums from namespaced type
+ property int e: Namespace.MyQmlObject.EnumValue1
+ property int f: Namespace.MyQmlObject.EnumValue2
+ property int g: Namespace.MyQmlObject.EnumValue3
+ property int h: Namespace.MyQmlObject.EnumValue4
+
+ // Test that enums don't mask attached properties
+ property int i: MyQmlObject.value
+ property int j: Namespace.MyQmlObject.value
+}
diff --git a/tests/auto/declarative/qmlbindengine/testtypes.h b/tests/auto/declarative/qmlbindengine/testtypes.h
index f5b309e..f27c0b0 100644
--- a/tests/auto/declarative/qmlbindengine/testtypes.h
+++ b/tests/auto/declarative/qmlbindengine/testtypes.h
@@ -5,9 +5,21 @@
#include <QtDeclarative/qml.h>
#include <QtDeclarative/qmlexpression.h>
+class MyQmlAttachedObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value CONSTANT)
+public:
+ MyQmlAttachedObject(QObject *parent) : QObject(parent) {}
+
+ int value() const { return 19; }
+};
+
class MyQmlObject : public QObject
{
Q_OBJECT
+ Q_ENUMS(MyEnum)
+ Q_ENUMS(MyEnum2)
Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT)
Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT)
Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged)
@@ -15,6 +27,9 @@ class MyQmlObject : public QObject
public:
MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false), m_object(0) {}
+ enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 };
+ enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 };
+
bool trueProperty() const { return true; }
bool falseProperty() const { return false; }
@@ -39,6 +54,10 @@ public:
bool methodIntCalled() const { return m_methodIntCalled; }
QString string() const { return m_string; }
+
+ static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) {
+ return new MyQmlAttachedObject(o);
+ }
signals:
void basicSignal();
void argumentSignal(int a, QString b, qreal c);
diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
index 01cb54b..80373fe 100644
--- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
+++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
@@ -38,6 +38,7 @@ private slots:
void objectPropertiesTriggerReeval();
void deferredProperties();
void extensionObjects();
+ void enums();
private:
QmlEngine engine;
@@ -366,6 +367,24 @@ void tst_qmlbindengine::extensionObjects()
QCOMPARE(object->baseProperty(), 92);
}
+void tst_qmlbindengine::enums()
+{
+ QmlComponent component(&engine, TEST_FILE("enums.1.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("a").toInt(), 0);
+ QCOMPARE(object->property("b").toInt(), 1);
+ QCOMPARE(object->property("c").toInt(), 2);
+ QCOMPARE(object->property("d").toInt(), 3);
+ QCOMPARE(object->property("e").toInt(), 0);
+ QCOMPARE(object->property("f").toInt(), 1);
+ QCOMPARE(object->property("g").toInt(), 2);
+ QCOMPARE(object->property("h").toInt(), 3);
+ QCOMPARE(object->property("i").toInt(), 19);
+ QCOMPARE(object->property("j").toInt(), 19);
+}
+
QTEST_MAIN(tst_qmlbindengine)
#include "tst_qmlbindengine.moc"
diff --git a/tests/auto/declarative/simplecanvasitem/data/test.qml b/tests/auto/declarative/simplecanvasitem/data/test.qml
deleted file mode 100644
index 8fbbc2e..0000000
--- a/tests/auto/declarative/simplecanvasitem/data/test.qml
+++ /dev/null
@@ -1,60 +0,0 @@
-import Qt 4.6
-
-Item {
- width: 320
- height: 480
- Rect {
- color: "blue"
- x: 20
- y: 20
- width: 20
- height: 20
- Rect {
- color: "black"
- x: 20
- y: 20
- width: 10
- height: 10
- }
- }
- Rect {
- color: "red"
- x: 40
- y: 20
- width: 20
- height: 20
- }
- Rect {
- color: "green"
- x: 60
- y: 20
- width: 20
- height: 20
- }
- Rect {
- color: "yellow"
- x: 20
- y: 40
- width: 20
- height: 20
- }
- Rect {
- color: "purple"
- x: 20
- y: 60
- width: 20
- height: 20
- }
- Rect {
- color: "white"
- x: 40
- y: 40
- width: 20
- height: 20
- }
- Rect {
- anchors.fill: parent
- color: "gray"
- z: -1
- }
-}
diff --git a/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp b/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp
deleted file mode 100644
index cce4df1..0000000
--- a/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <QtTest/QtTest>
-#include <qfxview.h>
-#include <qfxitem.h>
-#include <qsimplecanvasitem.h>
-
-/*
- Note: this autotest is specifically to test SimpleCanvasItem as a component of
- Qt Declarative, and therefore will have all items created in XML.
-*/
-class tst_SimpleCanvasItem : public QObject
-{
- Q_OBJECT
-public:
- tst_SimpleCanvasItem();
-
-private slots:
- void test_pos();
- void test_scenePos();
-private:
- QFxView *createView(const QString &filename);
-};
-
-tst_SimpleCanvasItem::tst_SimpleCanvasItem()
-{
-}
-
-void tst_SimpleCanvasItem::test_pos()
-{
- QFxView *canvas = createView(SRCDIR "/data/test.qml");
- canvas->execute();
- qApp->processEvents();
- QSimpleCanvasItem* root = qobject_cast<QSimpleCanvasItem*>(canvas->root());
- QVERIFY(root);
-
- QCOMPARE(root->pos(), QPointF(0,0));
- QCOMPARE(root->children().at(0)->pos(), QPointF(20,20));
- QCOMPARE(root->children().at(0)->children().at(0)->pos(), QPointF(20,20));
- QCOMPARE(root->children().at(2)->pos(), QPointF(60,20));
- QCOMPARE(root->children().at(3)->pos(), QPointF(20,40));
- QCOMPARE(root->children().at(5)->pos(), QPointF(40,40));
-}
-
-void tst_SimpleCanvasItem::test_scenePos()
-{
- QFxView *canvas = createView(SRCDIR "/data/test.qml");
- canvas->execute();
- qApp->processEvents();
- QSimpleCanvasItem* root = qobject_cast<QSimpleCanvasItem*>(canvas->root());
- QVERIFY(root);
-
-#ifdef CANVAS_GL
- QCOMPARE(root->transform(), QMatrix4x4());
-#else
- QCOMPARE(root->transform(), QTransform());
-#endif
- QCOMPARE(root->scenePos(), QPointF(0,0));
- QCOMPARE(root->children().at(0)->scenePos(), QPointF(20,20));
- QCOMPARE(root->children().at(0)->children().at(0)->scenePos(), QPointF(40,40));
- QCOMPARE(root->children().at(2)->scenePos(), QPointF(60,20));
- QCOMPARE(root->children().at(3)->scenePos(), QPointF(20,40));
- QCOMPARE(root->children().at(5)->scenePos(), QPointF(40,40));
-}
-
-QFxView *tst_SimpleCanvasItem::createView(const QString &filename)
-{
- QFxView *canvas = new QFxView(0);
- canvas->setFixedSize(240,320);
-
- QFile file(filename);
- file.open(QFile::ReadOnly);
- QString xml = file.readAll();
- canvas->setQml(xml, filename);
-
- return canvas;
-}
-
-QTEST_MAIN(tst_SimpleCanvasItem)
-
-#include "tst_simplecanvasitem.moc"
diff --git a/tests/auto/declarative/states/data/basicBinding.qml b/tests/auto/declarative/states/data/basicBinding.qml
new file mode 100644
index 0000000..930a6b2
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicBinding.qml
@@ -0,0 +1,12 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+
+ property color sourceColor: "blue"
+ width: 100; height: 100
+ color: "red"
+ states: State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: sourceColor }
+ }
+}
diff --git a/tests/auto/declarative/states/data/basicBinding2.qml b/tests/auto/declarative/states/data/basicBinding2.qml
new file mode 100644
index 0000000..6bfaf5a
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicBinding2.qml
@@ -0,0 +1,12 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+
+ property color sourceColor: "red"
+ width: 100; height: 100
+ color: sourceColor
+ states: State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: "blue" }
+ }
+} \ No newline at end of file
diff --git a/tests/auto/declarative/states/data/basicBinding3.qml b/tests/auto/declarative/states/data/basicBinding3.qml
new file mode 100644
index 0000000..344bfae
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicBinding3.qml
@@ -0,0 +1,13 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+
+ property color sourceColor: "red"
+ property color sourceColor2: "blue"
+ width: 100; height: 100
+ color: sourceColor
+ states: State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: sourceColor2 }
+ }
+} \ No newline at end of file
diff --git a/tests/auto/declarative/states/data/basicBinding4.qml b/tests/auto/declarative/states/data/basicBinding4.qml
new file mode 100644
index 0000000..f0b72bd
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicBinding4.qml
@@ -0,0 +1,17 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+
+ property color sourceColor: "blue"
+ width: 100; height: 100
+ color: "red"
+ states: [
+ State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: sourceColor }
+ },
+ State {
+ name: "green"
+ PropertyChanges { target: MyRectangle; color: "green" }
+ }]
+}
diff --git a/tests/auto/declarative/states/data/basicChanges.qml b/tests/auto/declarative/states/data/basicChanges.qml
new file mode 100644
index 0000000..8d560c6
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicChanges.qml
@@ -0,0 +1,10 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+ width: 100; height: 100
+ color: "red"
+ states: State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: "blue" }
+ }
+} \ No newline at end of file
diff --git a/tests/auto/declarative/states/data/basicChanges2.qml b/tests/auto/declarative/states/data/basicChanges2.qml
new file mode 100644
index 0000000..0f8783a
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicChanges2.qml
@@ -0,0 +1,15 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+ width: 100; height: 100
+ color: "red"
+ states: [
+ State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: "blue" }
+ },
+ State {
+ name: "green"
+ PropertyChanges { target: MyRectangle; color: "green" }
+ }]
+} \ No newline at end of file
diff --git a/tests/auto/declarative/states/data/basicChanges3.qml b/tests/auto/declarative/states/data/basicChanges3.qml
new file mode 100644
index 0000000..2a5ca5d
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicChanges3.qml
@@ -0,0 +1,15 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+ width: 100; height: 100
+ color: "red"
+ states: [
+ State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: "blue" }
+ },
+ State {
+ name: "bordered"
+ PropertyChanges { target: MyRectangle; border.width: 2 }
+ }]
+}
diff --git a/tests/auto/declarative/states/data/basicExtension.qml b/tests/auto/declarative/states/data/basicExtension.qml
new file mode 100644
index 0000000..230e00b
--- /dev/null
+++ b/tests/auto/declarative/states/data/basicExtension.qml
@@ -0,0 +1,16 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+ width: 100; height: 100
+ color: "red"
+ states: [
+ State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: "blue" }
+ },
+ State {
+ name: "bordered"
+ extend: "blue"
+ PropertyChanges { target: MyRectangle; border.width: 2 }
+ }]
+} \ No newline at end of file
diff --git a/tests/auto/declarative/states/data/fakeExtension.qml b/tests/auto/declarative/states/data/fakeExtension.qml
new file mode 100644
index 0000000..3d85c4f
--- /dev/null
+++ b/tests/auto/declarative/states/data/fakeExtension.qml
@@ -0,0 +1,16 @@
+import Qt 4.6
+Rectangle {
+ id: MyRectangle
+ width: 100; height: 100
+ color: "red"
+ states: [
+ State {
+ name: "blue"
+ PropertyChanges { target: MyRectangle; color: "blue" }
+ },
+ State {
+ name: "green"
+ extend: "blue"
+ PropertyChanges { target: MyRectangle; color: "green" }
+ }]
+} \ No newline at end of file
diff --git a/tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro b/tests/auto/declarative/states/states.pro
index f4aea32..0474ea5 100644
--- a/tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro
+++ b/tests/auto/declarative/states/states.pro
@@ -1,7 +1,6 @@
load(qttest_p4)
contains(QT_CONFIG,declarative): QT += declarative
-contains(QT_CONFIG, opengles2)|contains(QT_CONFIG, opengles1): QT += opengl
-SOURCES += tst_simplecanvasitem.cpp
+SOURCES += tst_states.cpp
# Define SRCDIR equal to test's source directory
DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp
new file mode 100644
index 0000000..3a61bd6
--- /dev/null
+++ b/tests/auto/declarative/states/tst_states.cpp
@@ -0,0 +1,267 @@
+#include <qtest.h>
+#include <QtDeclarative/qmlengine.h>
+#include <QtDeclarative/qmlcomponent.h>
+#include <QtDeclarative/qfxrect.h>
+
+class tst_states : public QObject
+{
+ Q_OBJECT
+public:
+ tst_states() {}
+
+private slots:
+ void basicChanges();
+ void basicExtension();
+ void basicBinding();
+};
+
+void tst_states::basicChanges()
+{
+ QmlEngine engine;
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+ }
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("green");
+ QCOMPARE(rect->color(),QColor("green"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("green");
+ QCOMPARE(rect->color(),QColor("green"));
+ }
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+ QCOMPARE(rect->border()->width(),1);
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ QCOMPARE(rect->border()->width(),1);
+
+ rect->setState("bordered");
+ QCOMPARE(rect->color(),QColor("red"));
+ QCOMPARE(rect->border()->width(),2);
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+ QCOMPARE(rect->border()->width(),1);
+ //### we should be checking that this is an implicit rather than explicit 1 (which currently fails)
+
+ rect->setState("bordered");
+ QCOMPARE(rect->color(),QColor("red"));
+ QCOMPARE(rect->border()->width(),2);
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ QCOMPARE(rect->border()->width(),1);
+
+ }
+}
+
+void tst_states::basicExtension()
+{
+ QmlEngine engine;
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+ QCOMPARE(rect->border()->width(),1);
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ QCOMPARE(rect->border()->width(),1);
+
+ rect->setState("bordered");
+ QCOMPARE(rect->color(),QColor("blue"));
+ QCOMPARE(rect->border()->width(),2);
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ QCOMPARE(rect->border()->width(),1);
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+ QCOMPARE(rect->border()->width(),1);
+
+ rect->setState("bordered");
+ QCOMPARE(rect->color(),QColor("blue"));
+ QCOMPARE(rect->border()->width(),2);
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+ QCOMPARE(rect->border()->width(),1);
+ }
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("green");
+ QCOMPARE(rect->color(),QColor("green"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("green");
+ QCOMPARE(rect->color(),QColor("green"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("green");
+ QCOMPARE(rect->color(),QColor("green"));
+ }
+}
+
+void tst_states::basicBinding()
+{
+ QmlEngine engine;
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ rect->setProperty("sourceColor", QColor("green"));
+ QCOMPARE(rect->color(),QColor("green"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+ rect->setProperty("sourceColor", QColor("yellow"));
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("yellow"));
+ }
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ rect->setProperty("sourceColor", QColor("green"));
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("green"));
+ rect->setProperty("sourceColor", QColor("yellow"));
+ QCOMPARE(rect->color(),QColor("yellow"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("yellow"));
+ }
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+ rect->setProperty("sourceColor", QColor("green"));
+ QCOMPARE(rect->color(),QColor("green"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ rect->setProperty("sourceColor", QColor("red"));
+ QCOMPARE(rect->color(),QColor("blue"));
+ rect->setProperty("sourceColor2", QColor("yellow"));
+ QCOMPARE(rect->color(),QColor("yellow"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+ rect->setProperty("sourceColor2", QColor("green"));
+ QCOMPARE(rect->color(),QColor("red"));
+ rect->setProperty("sourceColor", QColor("yellow"));
+ QCOMPARE(rect->color(),QColor("yellow"));
+ }
+
+ {
+ QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml");
+ QFxRect *rect = qobject_cast<QFxRect*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QCOMPARE(rect->color(),QColor("red"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("blue"));
+ rect->setProperty("sourceColor", QColor("yellow"));
+ QCOMPARE(rect->color(),QColor("yellow"));
+
+ rect->setState("green");
+ QCOMPARE(rect->color(),QColor("green"));
+ rect->setProperty("sourceColor", QColor("purple"));
+ QCOMPARE(rect->color(),QColor("green"));
+
+ rect->setState("blue");
+ QCOMPARE(rect->color(),QColor("purple"));
+
+ rect->setState("green");
+ QCOMPARE(rect->color(),QColor("green"));
+
+ rect->setState("");
+ QCOMPARE(rect->color(),QColor("red"));
+ }
+}
+
+QTEST_MAIN(tst_states)
+
+#include "tst_states.moc"
diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp
index a4ed054..87d1232 100644
--- a/tools/qmlviewer/main.cpp
+++ b/tools/qmlviewer/main.cpp
@@ -41,6 +41,7 @@ void usage()
qWarning(" -netcache <size> ......................... set disk cache to size bytes");
qWarning(" -translation <translationfile> ........... set the language to run in");
qWarning(" -L <directory> ........................... prepend to the library search path");
+ qWarning(" -opengl .................................. use a QGLWidget for the viewport");
qWarning(" ");
qWarning(" Press F1 for interactive help");
exit(1);
@@ -79,6 +80,7 @@ int main(int argc, char ** argv)
bool devkeys = false;
int cache = 0;
QString translationFile;
+ bool useGL = false;
for (int i = 1; i < argc; ++i) {
QString arg = argv[i];
@@ -114,6 +116,8 @@ int main(int argc, char ** argv)
usage();
translationFile = argv[i + 1];
++i;
+ } else if (arg == "-opengl") {
+ useGL = true;
} else if (arg == "-L") {
libraries << QString(argv[++i]);
} else if (arg[0] != '-') {
@@ -130,6 +134,7 @@ int main(int argc, char ** argv)
}
QmlViewer viewer(0, frameless ? Qt::FramelessWindowHint : Qt::Widget);
+ viewer.setUseGL(useGL);
foreach (QString lib, libraries)
viewer.addLibraryPath(lib);
viewer.setNetworkCacheSize(cache);
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp
index 272ebcb..3ae9a97 100644
--- a/tools/qmlviewer/qmlviewer.cpp
+++ b/tools/qmlviewer/qmlviewer.cpp
@@ -45,6 +45,10 @@
#include <QKeyEvent>
#include "proxysettings.h"
+#ifdef GL_SUPPORTED
+#include <QGLWidget>
+#endif
+
QT_BEGIN_NAMESPACE
class PreviewDeviceSkin : public DeviceSkin
@@ -1003,6 +1007,20 @@ void QmlViewer::setNetworkCacheSize(int size)
}
}
+void QmlViewer::setUseGL(bool useGL)
+{
+#ifdef GL_SUPPORTED
+ if (useGL) {
+ QGLFormat format = QGLFormat::defaultFormat();
+ format.setSampleBuffers(false);
+
+ QGLWidget *glWidget = new QGLWidget(format);
+ glWidget->setAutoFillBackground(false);
+ canvas->setViewport(glWidget);
+ }
+#endif
+}
+
QT_END_NAMESPACE
#include "qmlviewer.moc"
diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h
index c03c09f..e85acfa 100644
--- a/tools/qmlviewer/qmlviewer.h
+++ b/tools/qmlviewer/qmlviewer.h
@@ -43,6 +43,7 @@ public:
void setDeviceKeys(bool);
void setNetworkCacheSize(int size);
void addLibraryPath(const QString& lib);
+ void setUseGL(bool use);
QStringList builtinSkins() const;
diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro
index bcf361e..77cae97 100644
--- a/tools/qmlviewer/qmlviewer.pro
+++ b/tools/qmlviewer/qmlviewer.pro
@@ -7,6 +7,11 @@ QT += declarative \
network \
sql
+contains(QT_CONFIG, opengl) {
+ QT += opengl
+ DEFINES += GL_SUPPORTED
+}
+
# Input
HEADERS += qmlviewer.h \
proxysettings.h