diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-03-17 06:26:20 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-03-17 06:26:20 (GMT) |
commit | 1c4bb7a951ae50983a38acaf633eab272d3603b9 (patch) | |
tree | 09adb6ee05b253858447192bac9991554e3675e6 /src/declarative/util | |
parent | 0a52765f1c7fbd7d5286bcaab32cff35feb89a95 (diff) | |
download | Qt-1c4bb7a951ae50983a38acaf633eab272d3603b9.zip Qt-1c4bb7a951ae50983a38acaf633eab272d3603b9.tar.gz Qt-1c4bb7a951ae50983a38acaf633eab272d3603b9.tar.bz2 |
Allow enum constants as list element properties.
Task-number: QTBUG-5974
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qdeclarativelistmodel.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index 824e1b5..32a996d 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -94,9 +94,12 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM } \endcode - Roles (properties) must begin with a lower-case letter. The above example defines a + Roles (properties) must begin with a lower-case letter.The above example defines a ListModel containing three elements, with the roles "name" and "cost". + Values must be simple constants - either strings (quoted), bools (true, false), numbers, + or enum values (like Text.AlignHCenter). + The defined model can be used in views such as ListView: \code Component { @@ -167,6 +170,8 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM } \endcode + \section2 Modifying list models + The content of a ListModel may be created and modified using the clear(), append(), and set() methods. For example: @@ -674,10 +679,17 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser d += char(variant.asBoolean()); } else if (variant.isScript()) { if (definesEmptyList(variant.asScript())) { - d[0] = 0; // QDeclarativeParser::Variant::Invalid - marks empty list + d[0] = char(QDeclarativeParser::Variant::Invalid); // marks empty list } else { - error(prop, QDeclarativeListModel::tr("ListElement: cannot use script for property value")); - return false; + QByteArray script = variant.asScript().toUtf8(); + int v = evaluateEnum(script); + if (v<0) { + error(prop, QDeclarativeListModel::tr("ListElement: cannot use script for property value")); + return false; + } else { + d[0] = char(QDeclarativeParser::Variant::Number); + d += QByteArray::number(v); + } } } d.append('\0'); |