From 7aa4e177bbc01b7385cb345f3ad620a935dbe2d4 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 13 Oct 2009 13:06:50 +1000 Subject: i18n --- src/declarative/qml/parser/qmljs.g | 2 +- src/declarative/qml/parser/qmljslexer.cpp | 20 +-- src/declarative/qml/parser/qmljsparser.cpp | 2 +- src/declarative/qml/qmlcompiler.cpp | 143 +++++++++++---------- src/declarative/qml/qmlcompiler_p.h | 3 +- src/declarative/qml/qmlinfo.cpp | 10 +- src/declarative/qml/qmlvme.cpp | 29 ++--- tests/auto/declarative/anchors/tst_anchors.cpp | 12 +- .../auto/declarative/animations/tst_animations.cpp | 2 +- .../qmlecmascript/tst_qmlecmascript.cpp | 2 +- 10 files changed, 114 insertions(+), 111 deletions(-) diff --git a/src/declarative/qml/parser/qmljs.g b/src/declarative/qml/parser/qmljs.g index ed6c272..eb9a8ab 100644 --- a/src/declarative/qml/parser/qmljs.g +++ b/src/declarative/qml/parser/qmljs.g @@ -142,7 +142,7 @@ ****************************************************************************/ #include -#include +#include #include diff --git a/src/declarative/qml/parser/qmljslexer.cpp b/src/declarative/qml/parser/qmljslexer.cpp index 54f8d78..2c03c21 100644 --- a/src/declarative/qml/parser/qmljslexer.cpp +++ b/src/declarative/qml/parser/qmljslexer.cpp @@ -48,6 +48,8 @@ #include "qmljslexer_p.h" #include "qmljsgrammar_p.h" +#include + #include #include #include @@ -548,7 +550,7 @@ int Lexer::lex() else { setDone(Bad); err = IllegalCharacter; - errmsg = QLatin1String("Illegal character"); + errmsg = qApp->translate("QmlParser", "Illegal character"); } } break; @@ -562,7 +564,7 @@ int Lexer::lex() } else if (current == 0 || isLineTerminator()) { setDone(Bad); err = UnclosedStringLiteral; - errmsg = QLatin1String("Unclosed string at end of line"); + errmsg = qApp->translate("QmlParser", "Unclosed string at end of line"); } else if (current == '\\') { state = InEscapeSequence; } else { @@ -588,7 +590,7 @@ int Lexer::lex() } else { setDone(Bad); err = IllegalEscapeSequence; - errmsg = QLatin1String("Illegal escape squence"); + errmsg = qApp->translate("QmlParser", "Illegal escape squence"); } } else if (current == 'x') state = InHexEscape; @@ -634,7 +636,7 @@ int Lexer::lex() } else { setDone(Bad); err = IllegalUnicodeEscapeSequence; - errmsg = QLatin1String("Illegal unicode escape sequence"); + errmsg = qApp->translate("QmlParser", "Illegal unicode escape sequence"); } break; case InSingleLineComment: @@ -660,7 +662,7 @@ int Lexer::lex() if (current == 0) { setDone(Bad); err = UnclosedComment; - errmsg = QLatin1String("Unclosed comment at end of file"); + errmsg = qApp->translate("QmlParser", "Unclosed comment at end of file"); driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (isLineTerminator()) { shiftWindowsLineBreak(); @@ -747,7 +749,7 @@ int Lexer::lex() } else { setDone(Bad); err = IllegalExponentIndicator; - errmsg = QLatin1String("Illegal syntax for exponential number"); + errmsg = qApp->translate("QmlParser", "Illegal syntax for exponential number"); } break; case InExponent: @@ -773,7 +775,7 @@ int Lexer::lex() && isIdentLetter(current)) { state = Bad; err = IllegalIdentifier; - errmsg = QLatin1String("Identifier cannot start with numeric literal"); + errmsg = qApp->translate("QmlParser", "Identifier cannot start with numeric literal"); } // terminate string @@ -1104,7 +1106,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) while (1) { if (isLineTerminator() || current == 0) { - errmsg = QLatin1String("Unterminated regular expression literal"); + errmsg = qApp->translate("QmlParser", "Unterminated regular expression literal"); return false; } else if (current != '/' || lastWasEscape == true) @@ -1128,7 +1130,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) while (isIdentLetter(current)) { int flag = Ecma::RegExp::flagFromChar(current); if (flag == 0) { - errmsg = QString::fromLatin1("Invalid regular expression flag '%0'") + errmsg = qApp->translate("QmlParser", "Invalid regular expression flag '%0'") .arg(QChar(current)); return false; } diff --git a/src/declarative/qml/parser/qmljsparser.cpp b/src/declarative/qml/parser/qmljsparser.cpp index 2c8162b..402aaeb 100644 --- a/src/declarative/qml/parser/qmljsparser.cpp +++ b/src/declarative/qml/parser/qmljsparser.cpp @@ -42,7 +42,7 @@ ****************************************************************************/ #include -#include +#include #include diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index fa7e473..c744509 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include "private/qmlcustomparser_p_p.h" #include #include @@ -157,7 +158,7 @@ bool QmlCompiler::isSignalPropertyName(const QByteArray &name) For example: \code - COMPILE_EXCEPTION(property, tr("Error for property \"%1\"").arg(QString::fromUtf8(property->name))); + COMPILE_EXCEPTION(property, qApp->translate("QmlCompiler","Error for property \"%1\"").arg(QString::fromUtf8(property->name))); \endcode */ #define COMPILE_EXCEPTION(token, desc) \ @@ -193,7 +194,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, QString string = v->value.asScript(); if (!prop.isWritable()) - COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name()))); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name()))); if (prop.isEnumType()) { int value; @@ -202,7 +203,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, } else value = prop.enumerator().keyToValue(string.toUtf8().constData()); if (value == -1) - COMPILE_EXCEPTION(v, tr("Invalid property assignment: unknown enumeration")); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: unknown enumeration")); return true; } int type = prop.userType(); @@ -210,61 +211,61 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, case -1: break; case QVariant::String: - if (!v->value.isString()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: string expected")); + if (!v->value.isString()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: string expected")); break; case QVariant::Url: - if (!v->value.isString()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: url expected")); + if (!v->value.isString()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: url expected")); break; case QVariant::UInt: { bool ok; string.toUInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsigned int expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: unsigned int expected")); } break; case QVariant::Int: { bool ok; string.toInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: int expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: int expected")); } break; case QMetaType::Float: { bool ok; string.toFloat(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: float expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: float expected")); } break; case QVariant::Double: { bool ok; string.toDouble(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: double expected")); + if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: double expected")); } break; case QVariant::Color: { QColor c = QmlStringConverters::colorFromString(string); - if (!c.isValid()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: color expected")); + if (!c.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: color expected")); } break; case QVariant::Date: { QDate d = QDate::fromString(string, Qt::ISODate); - if (!d.isValid()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: date expected")); + if (!d.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: date expected")); } break; case QVariant::Time: { QTime time = QTime::fromString(string, Qt::ISODate); - if (!time.isValid()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: time expected")); + if (!time.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: time expected")); } break; case QVariant::DateTime: { QDateTime dateTime = QDateTime::fromString(string, Qt::ISODate); - if (!dateTime.isValid()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: datetime expected")); + if (!dateTime.isValid()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: datetime expected")); } break; case QVariant::Point: @@ -272,7 +273,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, { bool ok; QPointF point = QmlStringConverters::pointFFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: point expected")); + if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: point expected")); } break; case QVariant::Size: @@ -280,7 +281,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, { bool ok; QSizeF size = QmlStringConverters::sizeFFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: size expected")); + if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: size expected")); } break; case QVariant::Rect: @@ -288,19 +289,19 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, { bool ok; QRectF rect = QmlStringConverters::rectFFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: rect expected")); + if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: rect expected")); } break; case QVariant::Bool: { - if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: boolean expected")); + if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: boolean expected")); } break; case QVariant::Vector3D: { bool ok; QVector3D point = QmlStringConverters::vector3DFromString(string, &ok); - if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: 3D vector expected")); + if (!ok) COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: 3D vector expected")); } break; default: @@ -311,7 +312,7 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop, QmlMetaType::StringConverter converter = QmlMetaType::customStringConverter(t); if (!converter) - COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsupported type \"%1\"").arg(QString::fromLatin1(QVariant::typeToName(prop.type())))); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid property assignment: unsupported type \"%1\"").arg(QString::fromLatin1(QVariant::typeToName(prop.type())))); } break; } @@ -1023,18 +1024,18 @@ bool QmlCompiler::buildComponent(QmlParser::Object *obj, if (obj->properties.count() > 1 || (obj->properties.count() == 1 && obj->properties.begin().key() != "id") || !obj->scriptBlockObjects.isEmpty()) - COMPILE_EXCEPTION(obj, tr("Invalid component specification")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid component specification")); if (obj->properties.count()) idProp = *obj->properties.begin(); if (idProp && (idProp->value || idProp->values.count() > 1 || !isValidId(idProp->values.first()->primitive()))) - COMPILE_EXCEPTION(obj, tr("Invalid component id specification")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid component id specification")); if (idProp) { QString idVal = idProp->values.first()->primitive(); if (compileState.ids.contains(idVal)) - COMPILE_EXCEPTION(obj, tr("id is not unique")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","id is not unique")); obj->id = idVal; addId(idVal, obj); @@ -1044,14 +1045,14 @@ bool QmlCompiler::buildComponent(QmlParser::Object *obj, if (obj->defaultProperty && (obj->defaultProperty->value || obj->defaultProperty->values.count() > 1 || (obj->defaultProperty->values.count() == 1 && !obj->defaultProperty->values.first()->object))) - COMPILE_EXCEPTION(obj, tr("Invalid component body specification")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid component body specification")); Object *root = 0; if (obj->defaultProperty && obj->defaultProperty->values.count()) root = obj->defaultProperty->values.first()->object; if (!root) - COMPILE_EXCEPTION(obj, tr("Cannot create empty component specification")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Cannot create empty component specification")); // Build the component tree COMPILE_CHECK(buildComponentFromRoot(root, ctxt)); @@ -1070,11 +1071,11 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) Property *source = *script->properties.begin(); if (script->defaultProperty) - COMPILE_EXCEPTION(source, tr("Invalid Script block. Specify either the source property or inline script.")); + COMPILE_EXCEPTION(source, qApp->translate("QmlCompiler","Invalid Script block. Specify either the source property or inline script.")); if (source->value || source->values.count() != 1 || source->values.at(0)->object || !source->values.at(0)->value.isString()) - COMPILE_EXCEPTION(source, tr("Invalid Script source value")); + COMPILE_EXCEPTION(source, qApp->translate("QmlCompiler","Invalid Script source value")); sourceUrl = output->url.resolved(QUrl(source->values.at(0)->value.asString())).toString(); @@ -1086,7 +1087,7 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) } } else if (!script->properties.isEmpty()) { - COMPILE_EXCEPTION(*script->properties.begin(), tr("Properties cannot be set on Script block")); + COMPILE_EXCEPTION(*script->properties.begin(), qApp->translate("QmlCompiler","Properties cannot be set on Script block")); } else if (script->defaultProperty) { sourceUrl = output->url.toString(); @@ -1097,7 +1098,7 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) if (lineNumber == 1) lineNumber = v->location.start.line; if (v->object || !v->value.isString()) - COMPILE_EXCEPTION(v, tr("Invalid Script block")); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Invalid Script block")); if (ii == 0) { currentLocation = v->location.start; @@ -1203,7 +1204,7 @@ bool QmlCompiler::buildSignal(QmlParser::Property *prop, QmlParser::Object *obj, Q_ASSERT(obj->metaObject()); if (prop->isEmpty()) - COMPILE_EXCEPTION(prop, tr("Empty property assignment")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Empty property assignment")); QByteArray name = prop->name; Q_ASSERT(name.startsWith("on")); @@ -1222,7 +1223,7 @@ bool QmlCompiler::buildSignal(QmlParser::Property *prop, QmlParser::Object *obj, } else { if (prop->value || prop->values.count() > 1) - COMPILE_EXCEPTION(prop, tr("Incorrectly specified signal")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Incorrectly specified signal")); prop->index = sigIdx; obj->addSignalProperty(prop); @@ -1267,7 +1268,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, const BindingContext &ctxt) { if (prop->isEmpty()) - COMPILE_EXCEPTION(prop, tr("Empty property assignment")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Empty property assignment")); const QMetaObject *metaObject = obj->metaObject(); Q_ASSERT(metaObject); @@ -1279,7 +1280,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, // Attached properties cannot be used on sub-objects. Sub-objects // always exist in a binding sub-context, which is what we test // for here. - COMPILE_EXCEPTION(prop, tr("Attached properties cannot be used here")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Attached properties cannot be used here")); } QmlType *type = 0; @@ -1294,11 +1295,11 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, ctxt)); return true; } else if (!type || !type->attachedPropertiesType()) { - COMPILE_EXCEPTION(prop, tr("Non-existant attached object")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Non-existant attached object")); } if (!prop->value) - COMPILE_EXCEPTION(prop, tr("Invalid attached object assignment")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid attached object assignment")); Q_ASSERT(type->attachedPropertiesFunction()); prop->index = type->index(); @@ -1356,9 +1357,9 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, } else if (prop->index == -1) { if (prop->isDefault) { - COMPILE_EXCEPTION(prop->values.first(), tr("Cannot assign to non-existant default property")); + COMPILE_EXCEPTION(prop->values.first(), qApp->translate("QmlCompiler","Cannot assign to non-existant default property")); } else { - COMPILE_EXCEPTION(prop, tr("Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); } } else if (prop->value) { @@ -1386,12 +1387,12 @@ QmlCompiler::buildPropertyInNamespace(QmlEnginePrivate::ImportedNamespace *ns, const BindingContext &ctxt) { if (!nsProp->value) - COMPILE_EXCEPTION(nsProp, tr("Invalid use of namespace")); + COMPILE_EXCEPTION(nsProp, qApp->translate("QmlCompiler","Invalid use of namespace")); foreach (Property *prop, nsProp->value->properties) { if (!isAttachedPropertyName(prop->name)) - COMPILE_EXCEPTION(prop, tr("Not an attached property name")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Not an attached property name")); // Setup attached property data @@ -1400,10 +1401,10 @@ QmlCompiler::buildPropertyInNamespace(QmlEnginePrivate::ImportedNamespace *ns, &type, 0, 0, 0); if (!type || !type->attachedPropertiesType()) - COMPILE_EXCEPTION(prop, tr("Non-existant attached object")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Non-existant attached object")); if (!prop->value) - COMPILE_EXCEPTION(prop, tr("Invalid attached object assignment")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid attached object assignment")); Q_ASSERT(type->attachedPropertiesFunction()); prop->index = type->index(); @@ -1575,13 +1576,13 @@ bool QmlCompiler::buildIdProperty(QmlParser::Property *prop, if (prop->value || prop->values.count() > 1 || prop->values.at(0)->object) - COMPILE_EXCEPTION(prop, tr("Invalid use of id property")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid use of id property")); QmlParser::Value *idValue = prop->values.at(0); QString val = idValue->primitive(); if (!isValidId(val)) - COMPILE_EXCEPTION(prop, tr("\"%1\" is not a valid object id").arg(val)); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","\"%1\" is not a valid object id").arg(val)); // We disallow id's that conflict with import prefixes and types QmlEnginePrivate::ImportedNamespace *ns = 0; @@ -1589,12 +1590,12 @@ bool QmlCompiler::buildIdProperty(QmlParser::Property *prop, QmlEnginePrivate::get(engine)->resolveType(unit->imports, val.toUtf8(), &type, 0, 0, 0, &ns); if (type) - COMPILE_EXCEPTION(idValue, tr("id conflicts with type name")); + COMPILE_EXCEPTION(idValue, qApp->translate("QmlCompiler","id conflicts with type name")); if (ns) - COMPILE_EXCEPTION(idValue, tr("id conflicts with namespace prefix")); + COMPILE_EXCEPTION(idValue, qApp->translate("QmlCompiler","id conflicts with namespace prefix")); if (compileState.ids.contains(val)) - COMPILE_EXCEPTION(prop, tr("id is not unique")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","id is not unique")); prop->values.at(0)->type = Value::Id; @@ -1675,7 +1676,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, prop->value, obj, ctxt.incr())); obj->addValueTypeProperty(prop); } else { - COMPILE_EXCEPTION(prop, tr("Invalid property access")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property access")); } } else { @@ -1683,7 +1684,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, prop->value->metatype = QmlEnginePrivate::get(engine)->metaObjectForType(prop->type); if (!prop->value->metatype) - COMPILE_EXCEPTION(prop, tr("Cannot nest non-QObject property \"%1\"").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot nest non-QObject property \"%1\"").arg(QString::fromUtf8(prop->name))); obj->addGroupedProperty(prop); @@ -1699,19 +1700,19 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type, const BindingContext &ctxt) { if (obj->defaultProperty) - COMPILE_EXCEPTION(obj, tr("Invalid property use")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Invalid property use")); obj->metatype = type->metaObject(); foreach (Property *prop, obj->properties) { int idx = type->metaObject()->indexOfProperty(prop->name.constData()); if (idx == -1) - COMPILE_EXCEPTION(prop, tr("Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(prop->name))); QMetaProperty p = type->metaObject()->property(idx); prop->index = idx; prop->type = p.userType(); if (prop->value || prop->values.count() != 1) - COMPILE_EXCEPTION(prop, tr("Invalid property use")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use")); Value *value = prop->values.at(0); @@ -1719,7 +1720,7 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type, bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1; bool isPropertyInterceptor = output->types.at(value->object->type).type->propertyValueInterceptorCast() != -1; if (!isPropertyValue && !isPropertyInterceptor) { - COMPILE_EXCEPTION(prop, tr("Invalid property use")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use")); } else { COMPILE_CHECK(buildObject(value->object, ctxt)); @@ -1777,12 +1778,12 @@ bool QmlCompiler::buildListProperty(QmlParser::Property *prop, // at runtime. if (!listTypeIsInterface) { if (!canCoerce(listType, v->object)) { - COMPILE_EXCEPTION(v, tr("Cannot assign object to list")); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign object to list")); } } } else { - COMPILE_EXCEPTION(v, tr("Cannot assign primitives to lists")); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign primitives to lists")); } } @@ -1801,19 +1802,19 @@ bool QmlCompiler::buildListProperty(QmlParser::Property *prop, // at runtime. if (!listTypeIsInterface) { if (!canCoerce(listType, v->object)) { - COMPILE_EXCEPTION(v, tr("Cannot assign object to list")); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign object to list")); } } } else if (v->value.isScript()) { if (assignedBinding) - COMPILE_EXCEPTION(v, tr("Can only assign one binding to lists")); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Can only assign one binding to lists")); assignedBinding = true; COMPILE_CHECK(buildBinding(v, prop, ctxt)); v->type = Value::PropertyBinding; } else { - COMPILE_EXCEPTION(v, tr("Cannot assign primitives to lists")); + COMPILE_EXCEPTION(v, qApp->translate("QmlCompiler","Cannot assign primitives to lists")); } } @@ -1941,7 +1942,7 @@ bool QmlCompiler::buildPropertyObjectAssignment(QmlParser::Property *prop, buildDynamicMeta(prop->parent, ForceCreation); v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; } else { - COMPILE_EXCEPTION(v->object, tr("Cannot assign object to property")); + COMPILE_EXCEPTION(v->object, qApp->translate("QmlCompiler","Cannot assign object to property")); } } @@ -1986,12 +1987,12 @@ bool QmlCompiler::checkDynamicMeta(QmlParser::Object *obj) if (prop.isDefaultProperty) { if (seenDefaultProperty) - COMPILE_EXCEPTION(obj, tr("Duplicate default property")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Duplicate default property")); seenDefaultProperty = true; } if (propNames.contains(prop.name)) - COMPILE_EXCEPTION(obj, tr("Duplicate property name")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Duplicate property name")); propNames.insert(prop.name); } @@ -1999,13 +2000,13 @@ bool QmlCompiler::checkDynamicMeta(QmlParser::Object *obj) for (int ii = 0; ii < obj->dynamicSignals.count(); ++ii) { QByteArray name = obj->dynamicSignals.at(ii).name; if (methodNames.contains(name)) - COMPILE_EXCEPTION(obj, tr("Duplicate signal name")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Duplicate signal name")); methodNames.insert(name); } for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) { QByteArray name = obj->dynamicSlots.at(ii).name; if (methodNames.contains(name)) - COMPILE_EXCEPTION(obj, tr("Duplicate method name")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","Duplicate method name")); methodNames.insert(name); } @@ -2027,7 +2028,7 @@ bool QmlCompiler::mergeDynamicMetaProperties(QmlParser::Object *obj) property = obj->getProperty(p.name); if (property->value) - COMPILE_EXCEPTION(property, tr("Invalid property nesting")); + COMPILE_EXCEPTION(property, qApp->translate("QmlCompiler","Invalid property nesting")); for (int ii = 0; ii < p.defaultValue->values.count(); ++ii) { Value *v = p.defaultValue->values.at(ii); @@ -2073,7 +2074,7 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) if (-1 != propIdx) { QMetaProperty prop = obj->metaObject()->property(propIdx); if (prop.isFinal()) - COMPILE_EXCEPTION(&p, tr("Cannot override FINAL property")); + COMPILE_EXCEPTION(&p, qApp->translate("QmlCompiler","Cannot override FINAL property")); } if (p.isDefaultProperty && @@ -2098,7 +2099,7 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) QmlEnginePrivate *priv = QmlEnginePrivate::get(engine); if (!priv->resolveType(unit->imports, p.customType, &qmltype, &url, 0, 0, 0)) - COMPILE_EXCEPTION(&p, tr("Invalid property type")); + COMPILE_EXCEPTION(&p, qApp->translate("QmlCompiler","Invalid property type")); if (!qmltype) { QmlCompositeTypeData *tdata = priv->typeManager.get(url); @@ -2257,24 +2258,24 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder, const Object::DynamicProperty &prop) { if (!prop.defaultValue) - COMPILE_EXCEPTION(obj, tr("No property alias location")); + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","No property alias location")); if (prop.defaultValue->values.count() != 1 || prop.defaultValue->values.at(0)->object || !prop.defaultValue->values.at(0)->value.isScript()) - COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); QmlJS::AST::Node *node = prop.defaultValue->values.at(0)->value.asAST(); if (!node) - COMPILE_EXCEPTION(obj, tr("No property alias location")); // ### Can this happen? + COMPILE_EXCEPTION(obj, qApp->translate("QmlCompiler","No property alias location")); // ### Can this happen? QStringList alias = astNodeToStringList(node); if (alias.count() != 1 && alias.count() != 2) - COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); if (!compileState.ids.contains(alias.at(0))) - COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); Object *idObject = compileState.ids[alias.at(0)]; @@ -2286,7 +2287,7 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder, propIdx = idObject->metaObject()->indexOfProperty(alias.at(1).toUtf8().constData()); if (-1 == propIdx) - COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location")); + COMPILE_EXCEPTION(prop.defaultValue, qApp->translate("QmlCompiler","Invalid alias location")); QMetaProperty aliasProperty = idObject->metaObject()->property(propIdx); writable = aliasProperty.isWritable(); @@ -2321,7 +2322,7 @@ bool QmlCompiler::buildBinding(QmlParser::Value *value, QMetaProperty mp = prop->parent->metaObject()->property(prop->index); if (!mp.isWritable() && !QmlMetaType::isList(prop->type)) - COMPILE_EXCEPTION(prop, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); BindingReference reference; reference.expression = value->value; diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h index 6d6a25e..cff4937 100644 --- a/src/declarative/qml/qmlcompiler_p.h +++ b/src/declarative/qml/qmlcompiler_p.h @@ -135,9 +135,8 @@ private: }; class QMetaObjectBuilder; -class Q_DECLARATIVE_EXPORT QmlCompiler : public QObject +class Q_DECLARATIVE_EXPORT QmlCompiler { - Q_OBJECT public: QmlCompiler(); diff --git a/src/declarative/qml/qmlinfo.cpp b/src/declarative/qml/qmlinfo.cpp index 75de985..862d6ba 100644 --- a/src/declarative/qml/qmlinfo.cpp +++ b/src/declarative/qml/qmlinfo.cpp @@ -75,9 +75,13 @@ QT_BEGIN_NAMESPACE void qmlInfo(const QString& msg, QObject* object) { - QString pos = QLatin1String("QML ") + QLatin1String(object->metaObject()->className()); + QString pos = QLatin1String("QML"); + if (object) { + pos += " "; + pos += QLatin1String(object->metaObject()->className()); + } QmlDeclarativeData *ddata = QmlDeclarativeData::get(object); - pos += QLatin1String("("); + pos += QLatin1String(" ("); if (ddata) { if (ddata->outerContext) { pos += ddata->outerContext->baseUrl().toString(); @@ -91,7 +95,7 @@ void qmlInfo(const QString& msg, QObject* object) } else { pos += qApp->translate("QmlInfo","unknown location"); } - pos += QLatin1String(")"); + pos += QLatin1String(") "); qWarning((pos + msg).toLocal8Bit()); // XXX allow other processing? } diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 675f5ae..1f3903d 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -63,6 +63,7 @@ #include "private/qmlvmemetaobject_p.h" #include #include +#include #include #include #include @@ -75,12 +76,8 @@ QmlVME::QmlVME() #define VME_EXCEPTION(desc) \ { \ - QString str; \ - QDebug d(&str); \ - d << desc; \ - str = str.trimmed(); \ QmlError error; \ - error.setDescription(str); \ + error.setDescription(desc.trimmed()); \ error.setLine(instr.line); \ error.setUrl(comp->url); \ vmeErrors << error; \ @@ -191,7 +188,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, if(types.at(instr.create.type).component) vmeErrors << types.at(instr.create.type).component->errors(); - VME_EXCEPTION("Unable to create object of type" << types.at(instr.create.type).className); + VME_EXCEPTION(qApp->translate("QmlVME","Unable to create object of type %1").arg(QString::fromLatin1(types.at(instr.create.type).className))); } QmlDeclarativeData *ddata = QmlDeclarativeData::get(o); @@ -498,7 +495,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QMetaProperty prop = target->metaObject()->property(instr.assignCustomType.propertyIndex); if (v.isNull() || ((int)prop.type() != data.type && prop.userType() != data.type)) - VME_EXCEPTION("Cannot assign value" << primitive << "to property" << prop.name()); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign value %1 to property %2").arg(primitive).arg(QString::fromUtf8(prop.name()))); void *a[] = { (void *)v.data(), 0, &status, &flags }; QMetaObject::metacall(target, QMetaObject::WriteProperty, @@ -520,15 +517,15 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QMetaMethod method = QmlMetaType::defaultMethod(assign); if (method.signature() == 0) - VME_EXCEPTION("Cannot assign object type" << assign->metaObject()->className() << "with no default method"); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign object type %1 with no default method").arg(QString::fromLatin1(assign->metaObject()->className()))); if (!QMetaObject::checkConnectArgs(prop.method().signature(), method.signature())) - VME_EXCEPTION("Cannot connect mismatched signal/slot" << method.signature() << prop.method().signature()); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot connect mismatched signal/slot %1 %vs. %2").arg(QString::fromLatin1(method.signature())).arg(QString::fromLatin1(prop.method().signature()))); QMetaObject::connect(target, prop.coreIndex(), assign, method.methodIndex()); } else { - VME_EXCEPTION("Cannot assign an object to signal property" << pr); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign an object to signal property %1").arg(QString::fromUtf8(pr))); } @@ -684,7 +681,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, if (iid) ptr = assign->qt_metacast(iid); if (!ptr) - VME_EXCEPTION("Cannot assign object to list"); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign object to list")); if (list.qmlListInterface) { @@ -730,7 +727,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, } if (!ok) - VME_EXCEPTION("Cannot assign object to interface property"); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign object to interface property")); } break; @@ -741,7 +738,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QObject *qmlObject = qmlAttachedPropertiesObjectById(instr.fetchAttached.id, target); if (!qmlObject) - VME_EXCEPTION("Unable to create attached object"); + VME_EXCEPTION(qApp->translate("QmlVME","Unable to create attached object")); stack.push(qmlObject); } @@ -759,7 +756,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QMetaObject::metacall(target, QMetaObject::ReadProperty, instr.fetchQmlList.property, a); if (!list) - VME_EXCEPTION("Cannot assign to null list"); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign to null list")); qliststack.push(ListInstance(list, instr.fetchQmlList.type)); } @@ -777,7 +774,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QMetaObject::metacall(target, QMetaObject::ReadProperty, instr.fetchQmlList.property, a); if (!list) - VME_EXCEPTION("Cannot assign to null list"); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot assign to null list")); qliststack.push(ListInstance(list, instr.fetchQmlList.type)); } @@ -796,7 +793,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, instr.fetch.property, a); if (!obj) - VME_EXCEPTION("Cannot set properties on" << target->metaObject()->property(instr.fetch.property).name() << "as it is null"); + VME_EXCEPTION(qApp->translate("QmlVME","Cannot set properties on %1 as it is null").arg(QString::fromUtf8(target->metaObject()->property(instr.fetch.property).name()))); stack.push(obj); } diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 38b7fe8..ec977da 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -102,7 +102,7 @@ void tst_anchors::loops() view->setUrl(QUrl("file://" SRCDIR "/data/loop1.qml")); - QString expect = "QML QFxText (" + view->url().toString() + ":7:5" + ") Possible anchor loop detected on horizontal anchor. "; + QString expect = "QML QFxText (" + view->url().toString() + ":7:5" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); @@ -117,7 +117,7 @@ void tst_anchors::loops() view->setUrl(QUrl("file://" SRCDIR "/data/loop2.qml")); - QString expect = "QML QFxImage (" + view->url().toString() + ":14:3" + ") Possible anchor loop detected on horizontal anchor. "; + QString expect = "QML QFxImage (" + view->url().toString() + ":14:3" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); qApp->processEvents(); @@ -133,7 +133,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal1.qml")); - QString expect = "QML QFxRect (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors. "; + QString expect = "QML QFxRect (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); qApp->processEvents(); @@ -146,7 +146,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal2.qml")); - QString expect = "QML QFxText (" + view->url().toString() + ":7:5" + ") Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors. "; + QString expect = "QML QFxText (" + view->url().toString() + ":7:5" + ") Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); //qApp->processEvents(); @@ -159,7 +159,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal3.qml")); - QString expect = "QML QFxRect (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling. "; + QString expect = "QML QFxRect (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); //qApp->processEvents(); @@ -187,7 +187,7 @@ void tst_anchors::nullItem() { QFxAnchorLine anchor; - QTest::ignoreMessage(QtWarningMsg, "QML QFxItem (unknown location): Can't anchor to a null item. "); + QTest::ignoreMessage(QtWarningMsg, "QML QFxItem (unknown location) Can't anchor to a null item."); QFxItem *item = new QFxItem; item->anchors()->setBottom(anchor); } diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index f627527..0e46224 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -152,7 +152,7 @@ void tst_animations::badProperties() QFxRect *rect = qobject_cast(c.create()); QVERIFY(rect); - QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\" "); + QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\""); rect->setState("state1"); } } diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index f976e41..7fb1703 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -154,7 +154,7 @@ void tst_qmlecmascript::methods() void tst_qmlecmascript::bindingLoop() { QmlComponent component(&engine, TEST_FILE("bindingLoop.qml")); - QString warning = "QML MyQmlObject (" + component.url().toString() + ":9:9) Binding loop detected for property \"stringProperty\" "; + QString warning = "QML MyQmlObject (" + component.url().toString() + ":9:9) Binding loop detected for property \"stringProperty\""; QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); QObject *object = component.create(); QVERIFY(object != 0); -- cgit v0.12