summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-05-24 23:58:54 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-05-24 23:58:54 (GMT)
commit19038ba0847d3b8ed476d8c3c1d29332d4f80677 (patch)
tree0374a25291e47d576dc9c45ef43acd7d830195cc /src/declarative/qml
parent641c7cbdc52f84c07cf5bb628840bd6072e64764 (diff)
parentbfff04ba4fab92e1cfa57954c9df2d3b5ed807ef (diff)
downloadQt-19038ba0847d3b8ed476d8c3c1d29332d4f80677.zip
Qt-19038ba0847d3b8ed476d8c3c1d29332d4f80677.tar.gz
Qt-19038ba0847d3b8ed476d8c3c1d29332d4f80677.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlcompiler.cpp4
-rw-r--r--src/declarative/qml/qmlcompositetypemanager.cpp4
-rw-r--r--src/declarative/qml/qmlcontext.cpp2
-rw-r--r--src/declarative/qml/qmlcustomparser.cpp1
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp16
-rw-r--r--src/declarative/qml/qmlmetatype.cpp14
-rw-r--r--src/declarative/qml/qmlmetatype.h24
-rw-r--r--src/declarative/qml/qmlprivate.h96
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp13
-rw-r--r--src/declarative/qml/qmlvme.cpp3
-rw-r--r--src/declarative/qml/script/qmlbasicscript.cpp9
11 files changed, 121 insertions, 65 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 8990732..5f92721 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -862,6 +862,10 @@ bool QmlCompiler::compileProperty(Property *prop, Object *obj, int ctxt)
prop->type = t;
}
}
+ } else if(isAttachedProperty(prop->name) && prop->value) {
+ QmlType *type = QmlMetaType::qmlType(prop->name);
+ if (type && type->attachedPropertiesType())
+ prop->value->metatype = type->attachedPropertiesType();
}
if (prop->name == "id") {
diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp
index e1124a6..0da1a92 100644
--- a/src/declarative/qml/qmlcompositetypemanager.cpp
+++ b/src/declarative/qml/qmlcompositetypemanager.cpp
@@ -315,7 +315,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit)
continue;
}
- QUrl url = engine->componentUrl(QUrl(type + ".qml"), QUrl(unit->url));
+ QUrl url = engine->componentUrl(QUrl(QLatin1String(type + ".qml")), QUrl(unit->url));
QmlCompositeTypeData *urlUnit = components.value(url.toString());
if (!urlUnit) {
@@ -335,7 +335,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit)
{
QmlError error;
error.setUrl(unit->url);
- error.setDescription("Type " + type + " unavailable");
+ error.setDescription(tr("Type %1 unavailable").arg(QLatin1String(type)));
unit->errors << error;
}
if (urlUnit->errorType != QmlCompositeTypeData::AccessError)
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp
index ea72ebf..e5016f2 100644
--- a/src/declarative/qml/qmlcontext.cpp
+++ b/src/declarative/qml/qmlcontext.cpp
@@ -73,8 +73,6 @@ void QmlContextPrivate::dump(int depth)
void QmlContextPrivate::destroyed(QObject *obj)
{
- Q_Q(QmlContext);
-
defaultObjects.removeAll(obj);
QVariant variantObject = QVariant::fromValue(obj);
diff --git a/src/declarative/qml/qmlcustomparser.cpp b/src/declarative/qml/qmlcustomparser.cpp
index a60f783..2e8c8f6 100644
--- a/src/declarative/qml/qmlcustomparser.cpp
+++ b/src/declarative/qml/qmlcustomparser.cpp
@@ -224,6 +224,7 @@ QList<QVariant> QmlCustomParserProperty::assignedValues() const
QByteArray QmlCustomParser::compile(const QList<QmlCustomParserProperty> &, bool *ok)
{
+ Q_UNUSED(ok);
return QByteArray();
}
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index e3e9ff5..3aa4f1d 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -730,19 +730,19 @@ void QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value)
switch(t) {
case QVariant::Double:
{
- qreal r;
+ double d;
bool found = true;
if (vt == QVariant::Int) {
- r = value.toInt();
+ d = value.toInt();
} else if (vt == QVariant::UInt) {
- r = value.toUInt();
+ d = value.toUInt();
} else {
found = false;
}
if (found) {
void *a[1];
- a[0] = &r;
+ a[0] = &d;
QMetaObject::metacall(object,
QMetaObject::WriteProperty,
coreIdx, a);
@@ -906,19 +906,19 @@ void QmlMetaProperty::write(const QVariant &value) const
switch(t) {
case QVariant::Double:
{
- qreal r;
+ double dd;
bool found = true;
if (vt == QVariant::Int) {
- r = value.toInt();
+ dd = value.toInt();
} else if (vt == QVariant::UInt) {
- r = value.toUInt();
+ dd = value.toUInt();
} else {
found = false;
}
if (found) {
void *a[1];
- a[0] = &r;
+ a[0] = &dd;
QMetaObject::metacall(object(),
QMetaObject::WriteProperty,
d->coreIdx, a);
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index 2e490a4..6d44f7a 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -112,6 +112,7 @@ public:
QmlPrivate::Func m_opFunc;
const QMetaObject *m_baseMetaObject;
QmlAttachedPropertiesFunc m_attachedPropertiesFunc;
+ const QMetaObject *m_attachedPropertiesType;
int m_parserStatusCast;
QmlPrivate::CreateFunc m_extFunc;
const QMetaObject *m_extMetaObject;
@@ -124,7 +125,7 @@ public:
QmlTypePrivate::QmlTypePrivate()
: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_qmlListId(0),
- m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0),
+ m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
m_parserStatusCast(-1), m_extFunc(0), m_extMetaObject(0), m_index(-1),
m_customParser(0), m_isSetup(false)
{
@@ -149,6 +150,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
QmlPrivate::Func opFunc, const char *qmlName,
const QMetaObject *metaObject,
QmlAttachedPropertiesFunc attachedPropertiesFunc,
+ const QMetaObject *attachedType,
int parserStatusCast, QmlPrivate::CreateFunc extFunc,
const QMetaObject *extMetaObject, int index,
QmlCustomParser *customParser)
@@ -161,6 +163,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
d->m_opFunc = opFunc;
d->m_baseMetaObject = metaObject;
d->m_attachedPropertiesFunc = attachedPropertiesFunc;
+ d->m_attachedPropertiesType = attachedType;
d->m_parserStatusCast = parserStatusCast;
d->m_extFunc = extFunc;
d->m_index = index;
@@ -348,6 +351,11 @@ QmlAttachedPropertiesFunc QmlType::attachedPropertiesFunction() const
return d->m_attachedPropertiesFunc;
}
+const QMetaObject *QmlType::attachedPropertiesType() const
+{
+ return d->m_attachedPropertiesType;
+}
+
int QmlType::parserStatusCast() const
{
return d->m_parserStatusCast;
@@ -404,7 +412,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id,
return index;
}
-int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser)
+int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, const QMetaObject *attachMo, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser)
{
Q_UNUSED(object);
QWriteLocker lock(metaTypeDataLock());
@@ -421,7 +429,7 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun
int index = data->types.count();
QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId,
- func, cname, mo, attach, pStatus, extFunc,
+ func, cname, mo, attach, attachMo, pStatus, extFunc,
extmo, index, parser);
data->types.append(type);
diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h
index cc3887c..d10a0f0 100644
--- a/src/declarative/qml/qmlmetatype.h
+++ b/src/declarative/qml/qmlmetatype.h
@@ -59,7 +59,7 @@ class QmlCustomParser;
class Q_DECLARATIVE_EXPORT QmlMetaType
{
public:
- static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
+ static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *);
static bool copy(int type, void *data, const void *copy = 0);
@@ -136,6 +136,7 @@ public:
const QMetaObject *baseMetaObject() const;
QmlAttachedPropertiesFunc attachedPropertiesFunction() const;
+ const QMetaObject *attachedPropertiesType() const;
int parserStatusCast() const;
QVariant fromObject(QObject *) const;
@@ -146,7 +147,7 @@ private:
friend class QmlMetaType;
friend class QmlTypePrivate;
QmlType(int, int, int, QmlPrivate::Func, const char *, int);
- QmlType(int, int, int, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
+ QmlType(int, int, int, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
~QmlType();
QmlTypePrivate *d;
@@ -165,6 +166,7 @@ int qmlRegisterType(const char *typeName)
return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, 0);
@@ -183,6 +185,7 @@ int qmlRegisterType(const char *qmlName, const char *typeName)
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, 0);
@@ -200,11 +203,15 @@ int qmlRegisterExtendedType(const char *typeName)
QmlAttachedPropertiesFunc attached =
QmlPrivate::attachedPropertiesFunc<E>();
- if (!attached)
+ const QMetaObject * attachedMo =
+ QmlPrivate::attachedPropertiesMetaObject<E>();
+ if (!attached) {
attached = QmlPrivate::attachedPropertiesFunc<T>();
+ attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
+ }
return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0,
- &T::staticMetaObject, attached,
+ &T::staticMetaObject, attached, attachedMo,
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
&QmlPrivate::CreateParent<E>::create, &E::staticMetaObject, 0);
@@ -222,13 +229,17 @@ int qmlRegisterExtendedType(const char *qmlName, const char *typeName)
QmlAttachedPropertiesFunc attached =
QmlPrivate::attachedPropertiesFunc<E>();
- if (!attached)
+ const QMetaObject * attachedMo =
+ QmlPrivate::attachedPropertiesMetaObject<E>();
+ if (!attached) {
attached = QmlPrivate::attachedPropertiesFunc<T>();
+ attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
+ }
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
qmlName,
&T::staticMetaObject,
- attached,
+ attached, attachedMo,
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
&QmlPrivate::CreateParent<E>::create,
@@ -263,6 +274,7 @@ int qmlRegisterCustomType(const char *qmlName, const char *typeName, QmlCustomPa
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, parser);
diff --git a/src/declarative/qml/qmlprivate.h b/src/declarative/qml/qmlprivate.h
index 590e0c0..2a9c503 100644
--- a/src/declarative/qml/qmlprivate.h
+++ b/src/declarative/qml/qmlprivate.h
@@ -123,57 +123,81 @@ namespace QmlPrivate
}
};
- template<typename T, int N>
- struct AttachedPropertySelector
- {
- static inline QmlAttachedPropertiesFunc func()
- {
- return 0;
- }
- };
- template<typename T>
- struct AttachedPropertySelector<T, 1>
- {
- static inline QmlAttachedPropertiesFunc func()
- {
- return &T::qmlAttachedProperties;
- }
- };
-
- template < typename T >
- class has_attachedProperties {
+ template <typename T>
+ class has_attachedPropertiesMember
+ {
typedef int yes_type;
typedef char no_type;
+ template <int>
+ struct Selector {};
- template<typename S, QObject *(S::*)(QObject *)>
- struct dummy {};
-
- template<typename S, QObject *(S::*)(QObject *) const>
- struct dummy_const {};
-
- template<typename S, QObject *(*) (QObject *)>
- struct dummy_static {};
+ template <typename S>
+ static yes_type test(Selector<sizeof(&S::qmlAttachedProperties)>*);
- template<typename S>
- static no_type check(dummy<S, &S::qmlAttachedProperties> *);
+ template <typename S>
+ static no_type test(...);
- template<typename S>
- static no_type check(dummy_const<S, &S::qmlAttachedProperties> *);
+ public:
+ static bool const value = sizeof(test<T>(0)) == sizeof(yes_type);
+ };
- template<typename S>
- static yes_type check(dummy_static<S, &S::qmlAttachedProperties> *);
+ template <typename T, bool hasMember>
+ class has_attachedPropertiesMethod
+ {
+ typedef int yes_type;
+ typedef char no_type;
- template<typename S>
+ template<typename ReturnType>
+ static yes_type check(ReturnType *(*)(QObject *));
static no_type check(...);
public:
- static bool const value = sizeof(check<T>(0)) == sizeof(yes_type);
+ static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
};
+ template <typename T>
+ class has_attachedPropertiesMethod<T, false>
+ {
+ public:
+ static bool const value = false;
+ };
+
+ template<typename T, int N>
+ class AttachedPropertySelector
+ {
+ public:
+ static inline QmlAttachedPropertiesFunc func() { return 0; }
+ static inline const QMetaObject *metaObject() { return 0; }
+ };
+ template<typename T>
+ class AttachedPropertySelector<T, 1>
+ {
+ static inline QObject *attachedProperties(QObject *obj) {
+ return T::qmlAttachedProperties(obj);
+ }
+ template<typename ReturnType>
+ static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
+ return &ReturnType::staticMetaObject;
+ }
+ public:
+ static inline QmlAttachedPropertiesFunc func() {
+ return &attachedProperties;
+ }
+ static inline const QMetaObject *metaObject() {
+ return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
+ }
+ };
+
template<typename T>
inline QmlAttachedPropertiesFunc attachedPropertiesFunc()
{
- return AttachedPropertySelector<T, has_attachedProperties<T>::value>::func();
+ return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
+ }
+
+ template<typename T>
+ inline const QMetaObject *attachedPropertiesMetaObject()
+ {
+ return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
}
struct MetaTypeIds {
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 01600b9..5b3564f 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -10,6 +10,7 @@
#include "parser/javascriptast_p.h"
#include <QStack>
+#include <QCoreApplication>
#include <QtDebug>
#include <qfxperf.h>
@@ -207,8 +208,8 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName,
{
int lastTypeDot = objectType.lastIndexOf(QLatin1Char('.'));
bool isType = !objectType.isEmpty() &&
- (objectType.at(0).isUpper() |
- lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper());
+ (objectType.at(0).isUpper() ||
+ (lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper()));
int propertyCount = 0;
for (; propertyName; propertyName = propertyName->next){
@@ -221,7 +222,7 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName,
if(propertyCount || !currentObject()) {
QmlError error;
- error.setDescription("Expected type name");
+ error.setDescription(QCoreApplication::translate("QmlParser","Expected type name"));
error.setLine(typeLocation.startLine);
error.setColumn(typeLocation.startColumn);
_parser->_errors << error;
@@ -427,7 +428,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
if(!typeFound) {
QmlError error;
- error.setDescription("Expected property type");
+ error.setDescription(QCoreApplication::translate("QmlParser","Expected property type"));
error.setLine(node->typeToken.startLine);
error.setColumn(node->typeToken.startColumn);
_parser->_errors << error;
@@ -573,7 +574,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node)
if(funDecl->formals) {
QmlError error;
- error.setDescription("Slot declarations must be parameterless");
+ error.setDescription(QCoreApplication::translate("QmlParser","Slot declarations must be parameterless"));
error.setLine(funDecl->lparenToken.startLine);
error.setColumn(funDecl->lparenToken.startColumn);
_parser->_errors << error;
@@ -587,7 +588,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node)
obj->dynamicSlots << slot;
} else {
QmlError error;
- error.setDescription("JavaScript declaration outside Script element");
+ error.setDescription(QCoreApplication::translate("QmlParser","JavaScript declaration outside Script element"));
error.setLine(node->firstSourceLocation().startLine);
error.setColumn(node->firstSourceLocation().startColumn);
_parser->_errors << error;
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 1552cb5..a5cc649 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -1017,7 +1017,8 @@ void QmlVME::runStoreInstruction(QStack<QObject *> &stack,
QFxCompilerTimer<QFxCompiler::InstrStoreReal> cc;
#endif
QObject *target = stack.top();
- qreal r = instr.storeReal.value;
+ //### moc treats qreal properties as having type double
+ double r = static_cast<double>(instr.storeReal.value);
void *a[1];
a[0] = &r;
QMetaObject::metacall(target, QMetaObject::WriteProperty,
diff --git a/src/declarative/qml/script/qmlbasicscript.cpp b/src/declarative/qml/script/qmlbasicscript.cpp
index e0a668a..37a6678 100644
--- a/src/declarative/qml/script/qmlbasicscript.cpp
+++ b/src/declarative/qml/script/qmlbasicscript.cpp
@@ -139,9 +139,16 @@ static QVariant fetch_value(QObject *o, int idx, int type)
}
break;
case 135:
+ {
+ float val;
+ void *args[] = { &val, 0 };
+ QMetaObject::metacall(o, QMetaObject::ReadProperty, idx, args);
+ return QVariant(val);
+ }
+ break;
case QVariant::Double:
{
- qreal val;
+ double val;
void *args[] = { &val, 0 };
QMetaObject::metacall(o, QMetaObject::ReadProperty, idx, args);
return QVariant(val);