diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-02-19 07:18:42 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-02-19 07:18:42 (GMT) |
commit | b988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce (patch) | |
tree | db065658178c6a2387f8e289ff303b2bf87aa421 /src/declarative/util/qmllistmodel.cpp | |
parent | b442982fed0f1c40eb936babbba197ce09e28c37 (diff) | |
download | Qt-b988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce.zip Qt-b988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce.tar.gz Qt-b988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce.tar.bz2 |
More strict type checking of ListElement properties.
Task-number: QTBUG-6203
Diffstat (limited to 'src/declarative/util/qmllistmodel.cpp')
-rw-r--r-- | src/declarative/util/qmllistmodel.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index ee35d2e..af41dfd 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -806,7 +806,23 @@ bool QmlListModelParser::compileProperty(const QmlCustomParserProperty &prop, QL qvariant_cast<QmlParser::Variant>(value); int ref = data.count(); - QByteArray d = variant.asScript().toUtf8(); + + QByteArray d; + d += char(variant.type()); // type tag + if (variant.isString()) { + d += variant.asString().toUtf8(); + } else if (variant.isNumber()) { + d += QByteArray::number(variant.asNumber(),'g',20); + } else if (variant.isBoolean()) { + d += char(variant.asBoolean()); + } else if (variant.isScript()) { + if (definesEmptyList(variant.asScript())) { + d[0] = 0; // QmlParser::Variant::Invalid - marks empty list + } else { + error(prop, QmlListModel::tr("ListElement: cannot use script for property value")); + return false; + } + } d.append('\0'); data.append(d); @@ -814,7 +830,6 @@ bool QmlListModelParser::compileProperty(const QmlCustomParserProperty &prop, QL li.type = ListInstruction::Value; li.dataIdx = ref; instr << li; - } } @@ -892,15 +907,22 @@ void QmlListModelParser::setCustomData(QObject *obj, const QByteArray &d) case ListInstruction::Value: { ModelNode *n = nodes.top(); - QString s = QString::fromUtf8(QByteArray(data + instr.dataIdx)); - - bool isEmptyList = false; - if (!n->isArray) - isEmptyList = definesEmptyList(s); - if (isEmptyList) + switch (QmlParser::Variant::Type(data[instr.dataIdx])) { + case QmlParser::Variant::Invalid: n->isArray = true; - else - n->values.append(s); + break; + case QmlParser::Variant::Boolean: + n->values.append(bool(data[1 + instr.dataIdx])); + break; + case QmlParser::Variant::Number: + n->values.append(QByteArray(data + 1 + instr.dataIdx).toDouble()); + break; + case QmlParser::Variant::String: + n->values.append(QString::fromUtf8(data + 1 + instr.dataIdx)); + break; + default: + Q_ASSERT("Format error in ListInstruction"); + } processingSet = false; } |