diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-06-22 02:23:25 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-06-22 02:23:25 (GMT) |
commit | 84a4a2ed1b17dd8d73404f52af032b959aada8b1 (patch) | |
tree | 82567474b3db63f194fb6c4d09bacbb186fa8766 | |
parent | 02c83c2adf0513041d9a3866d4e589ad79d61bda (diff) | |
download | Qt-84a4a2ed1b17dd8d73404f52af032b959aada8b1.zip Qt-84a4a2ed1b17dd8d73404f52af032b959aada8b1.tar.gz Qt-84a4a2ed1b17dd8d73404f52af032b959aada8b1.tar.bz2 |
Allow QT_TR_NOOP (as a no-op) in ListModel values.
Task-number: QTBUG-11403
-rw-r--r-- | src/declarative/util/qdeclarativelistmodel.cpp | 13 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp | 10 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index ff83227..9ed21a6 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -81,8 +81,8 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM 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). + Values must be simple constants - either strings (quoted and optionally within a call to QT_TR_NOOP), + bools (true, false), numbers, or enum values (like Text.AlignHCenter). The defined model can be used in views such as ListView: @@ -620,8 +620,13 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser 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; + if (script.startsWith("QT_TR_NOOP(\"") && script.endsWith("\")")) { + d[0] = char(QDeclarativeParser::Variant::String); + d += script.mid(12,script.length()-14); + } else { + error(prop, QDeclarativeListModel::tr("ListElement: cannot use script for property value")); + return false; + } } else { d[0] = char(QDeclarativeParser::Variant::Number); d += QByteArray::number(v); diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index b3b6c20..3d66733 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -48,6 +48,7 @@ #include <QtCore/qtimer.h> #include <QtCore/qdebug.h> +#include <QtCore/qtranslator.h> #include "../../../shared/util.h" @@ -124,14 +125,17 @@ void tst_qdeclarativelistmodel::waitForWorker(QDeclarativeItem *item) void tst_qdeclarativelistmodel::static_i18n() { QString expect = QString::fromUtf8("na\303\257ve"); - QString componentStr = "import Qt 4.7\nListModel { ListElement { prop1: \""+expect+"\" } }"; + + QString componentStr = "import Qt 4.7\nListModel { ListElement { prop1: \""+expect+"\"; prop2: QT_TR_NOOP(\""+expect+"\") } }"; QDeclarativeEngine engine; QDeclarativeComponent component(&engine); component.setData(componentStr.toUtf8(), QUrl::fromLocalFile("")); QDeclarativeListModel *obj = qobject_cast<QDeclarativeListModel*>(component.create()); QVERIFY(obj != 0); - QString prop = obj->get(0).property(QLatin1String("prop1")).toString(); - QCOMPARE(prop,expect); + QString prop1 = obj->get(0).property(QLatin1String("prop1")).toString(); + QCOMPARE(prop1,expect); + QString prop2 = obj->get(0).property(QLatin1String("prop2")).toString(); + QCOMPARE(prop2,expect); // (no, not translated, QT_TR_NOOP is a no-op) delete obj; } |