summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-05-18 03:15:56 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-05-18 03:15:56 (GMT)
commit00d012f3f2d8971d277a6177d6d707cf31e155f4 (patch)
treeb15ede8c15df318e16bfb84a8af58ab9c16150db /src/declarative
parent3e5c94c368c261190992b9c0f8b4223c35ede407 (diff)
downloadQt-00d012f3f2d8971d277a6177d6d707cf31e155f4.zip
Qt-00d012f3f2d8971d277a6177d6d707cf31e155f4.tar.gz
Qt-00d012f3f2d8971d277a6177d6d707cf31e155f4.tar.bz2
Start work on translation support in Qml.
Added basic support for qsTr in Qml, both in the engine and in lupdate.
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qmlengine.cpp19
-rw-r--r--src/declarative/qml/qmlengine_p.h2
-rw-r--r--src/declarative/qml/qmlexpression.h2
-rw-r--r--src/declarative/qml/qmlvme.cpp2
4 files changed, 21 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index b2d3a9c..0209c1d 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -193,6 +193,7 @@ void QmlEnginePrivate::clear(SimpleList<QmlParserStatus> &pss)
void QmlEnginePrivate::init()
{
+ scriptEngine.installTranslatorFunctions();
contextClass = new QmlContextScriptClass(q);
objectClass = new QmlObjectScriptClass(q);
rootContext = new QmlContext(q);
@@ -781,17 +782,17 @@ QmlEngine *QmlEngine::activeEngine()
QmlExpressionPrivate::QmlExpressionPrivate(QmlExpression *b)
-: q(b), ctxt(0), sseData(0), proxy(0), me(0), trackChange(false), id(0), log(0)
+: q(b), ctxt(0), sseData(0), proxy(0), me(0), trackChange(false), line(-1), id(0), log(0)
{
}
QmlExpressionPrivate::QmlExpressionPrivate(QmlExpression *b, void *expr, QmlRefCount *rc)
-: q(b), ctxt(0), sse((const char *)expr, rc), sseData(0), proxy(0), me(0), trackChange(true), id(0), log(0)
+: q(b), ctxt(0), sse((const char *)expr, rc), sseData(0), proxy(0), me(0), trackChange(true), line(-1), id(0), log(0)
{
}
QmlExpressionPrivate::QmlExpressionPrivate(QmlExpression *b, const QString &expr, bool ssecompile)
-: q(b), ctxt(0), expression(expr), sseData(0), proxy(0), me(0), trackChange(true), id(0), log(0)
+: q(b), ctxt(0), expression(expr), sseData(0), proxy(0), me(0), trackChange(true), line(-1), id(0), log(0)
{
if (ssecompile) {
#ifdef Q_ENABLE_PERFORMANCE_LOG
@@ -996,7 +997,7 @@ QVariant QmlExpression::value()
for (int i = context()->d_func()->scopeChain.size() - 1; i > -1; --i) {
scriptEngine->currentContext()->pushScope(context()->d_func()->scopeChain.at(i));
}
- QScriptValue svalue = scriptEngine->evaluate(expression());
+ QScriptValue svalue = scriptEngine->evaluate(expression(), d->fileName, d->line);
if (scriptEngine->hasUncaughtException()) {
if (scriptEngine->uncaughtException().isError()){
QScriptValue exception = scriptEngine->uncaughtException();
@@ -1151,6 +1152,16 @@ void QmlExpression::setTrackChange(bool trackChange)
}
/*!
+ Set the location of this expression to \a line of \a fileName. This information
+ is used by the script engine.
+*/
+void QmlExpression::setSourceLocation(const QString &fileName, int line)
+{
+ d->fileName = fileName;
+ d->line = line;
+}
+
+/*!
Returns the expression's scope object, if provided, otherwise 0.
In addition to data provided by the expression's QmlContext, the scope
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 7578fdf..7cafb59 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -277,6 +277,8 @@ public:
BindExpressionProxy *proxy;
QObject *me;
bool trackChange;
+ QString fileName;
+ int line;
quint32 id;
diff --git a/src/declarative/qml/qmlexpression.h b/src/declarative/qml/qmlexpression.h
index 2c6b1ad..ea3b093 100644
--- a/src/declarative/qml/qmlexpression.h
+++ b/src/declarative/qml/qmlexpression.h
@@ -78,6 +78,8 @@ public:
bool trackChange() const;
void setTrackChange(bool);
+ void setSourceLocation(const QString &fileName, int line);
+
QObject *scopeObject() const;
quint32 id() const;
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 53ed05a..f4ce891 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -526,6 +526,7 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in
QFx_setParent_noEvent(bind, target);
bind->setTarget(mp);
+ bind->setSourceLocation(comp->url.toString(), instr.line);
}
break;
@@ -551,6 +552,7 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in
QFx_setParent_noEvent(bind, target);
bind->setTarget(mp);
+ bind->setSourceLocation(comp->url.toString(), instr.line);
}
break;