aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-12-15 12:01:39 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-19 01:13:53 +0100
commit8460eae44c241d5975b3041eedf6e08c9638fd41 (patch)
tree0e342e789966b86b2d320ecccee22477192ccfc0 /src/declarative
parent6859056a0924b3da52b045aa14a34fae59a5c75e (diff)
Correctly resolve elements of QList<QUrl> properties
Previously, the value of a QList<QUrl> sequence was only resolved if there was only one element in the sequence. This commit ensures that all elements in the sequence are resolved correctly. Task-number: QTBUG-23131 Change-Id: Id27748853fe01ae22800fbd02d062e268ad7ec70 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index 1e0b14ee02..9941342723 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -1052,6 +1052,39 @@ QVariant QDeclarativePropertyPrivate::readValueProperty()
}
}
+// helper function to allow assignment / binding to QList<QUrl> properties.
+static QVariant resolvedUrlSequence(const QVariant &value, QDeclarativeContextData *context)
+{
+ QList<QUrl> urls;
+ if (value.userType() == qMetaTypeId<QUrl>()) {
+ urls.append(value.toUrl());
+ } else if (value.userType() == qMetaTypeId<QString>()) {
+ urls.append(QUrl(value.toString()));
+ } else if (value.userType() == qMetaTypeId<QByteArray>()) {
+ urls.append(QUrl(QString::fromUtf8(value.toByteArray())));
+ } else if (value.userType() == qMetaTypeId<QList<QUrl> >()) {
+ urls = value.value<QList<QUrl> >();
+ } else if (value.userType() == qMetaTypeId<QStringList>()) {
+ QStringList urlStrings = value.value<QStringList>();
+ for (int i = 0; i < urlStrings.size(); ++i)
+ urls.append(QUrl(urlStrings.at(i)));
+ } else if (value.userType() == qMetaTypeId<QList<QString> >()) {
+ QList<QString> urlStrings = value.value<QList<QString> >();
+ for (int i = 0; i < urlStrings.size(); ++i)
+ urls.append(QUrl(urlStrings.at(i)));
+ } // note: QList<QByteArray> is not currently supported.
+
+ QList<QUrl> resolvedUrls;
+ for (int i = 0; i < urls.size(); ++i) {
+ QUrl u = urls.at(i);
+ if (context && u.isRelative() && !u.isEmpty())
+ u = context->resolvedUrl(u);
+ resolvedUrls.append(u);
+ }
+
+ return QVariant::fromValue<QList<QUrl> >(resolvedUrls);
+}
+
//writeEnumProperty MIRRORS the relelvant bit of QMetaProperty::write AND MUST BE KEPT IN SYNC!
bool QDeclarativePropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, const QVariant &value, int flags)
{
@@ -1194,6 +1227,11 @@ bool QDeclarativePropertyPrivate::write(QObject *object,
void *argv[] = { &u, 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv);
+ } else if (propertyType == qMetaTypeId<QList<QUrl> >()) {
+ QList<QUrl> urlSeq = resolvedUrlSequence(value, context).value<QList<QUrl> >();
+ int status = -1;
+ void *argv[] = { &urlSeq, 0, &status, &flags };
+ QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv);
} else if (variantType == propertyType) {
void *a[] = { (void *)value.constData(), 0, &status, &flags };
@@ -1299,6 +1337,7 @@ bool QDeclarativePropertyPrivate::write(QObject *object,
if (!ok) {
// the only other option is that they are assigning a single value
// to a sequence type property (eg, an int to a QList<int> property).
+ // Note that we've already handled single-value assignment to QList<QUrl> properties.
if (variantType == QVariant::Int && propertyType == qMetaTypeId<QList<int> >()) {
QList<int> list;
list << value.toInt();
@@ -1314,28 +1353,6 @@ bool QDeclarativePropertyPrivate::write(QObject *object,
list << value.toBool();
v = QVariant::fromValue<QList<bool> >(list);
ok = true;
- } else if ((variantType == QVariant::Url || variantType == QVariant::String || variantType == QVariant::ByteArray)
- && propertyType == qMetaTypeId<QList<QUrl> >()) {
- QUrl u;
- bool found = false;
- if (variantType == QVariant::Url) {
- u = value.toUrl();
- found = true;
- } else if (variantType == QVariant::ByteArray) {
- u = QUrl(QString::fromUtf8(value.toByteArray()));
- found = true;
- } else if (variantType == QVariant::String) {
- u = QUrl(value.toString());
- found = true;
- }
- if (!found)
- return false;
- if (context && u.isRelative() && !u.isEmpty())
- u = context->resolvedUrl(u);
- QList<QUrl> list;
- list << u;
- v = QVariant::fromValue<QList<QUrl> >(list);
- ok = true;
} else if (variantType == QVariant::String && propertyType == qMetaTypeId<QList<QString> >()) {
QList<QString> list;
list << value.toString();
@@ -1423,9 +1440,7 @@ bool QDeclarativePropertyPrivate::writeBinding(QObject *object,
} else if (result->IsNull() && core.isQObject()) {
value = QVariant::fromValue((QObject *)0);
} else if (core.propType == qMetaTypeId<QList<QUrl> >()) {
- value = v8engine->toVariant(result, qMetaTypeId<QList<QUrl> >());
- if (value.userType() == qMetaTypeId<QString>())
- value = QVariant(QUrl(value.toString()));
+ value = resolvedUrlSequence(v8engine->toVariant(result, qMetaTypeId<QList<QUrl> >()), context);
} else if (!isVmeProperty) {
value = v8engine->toVariant(result, type);
}