diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2012-07-11 13:01:33 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-03 03:38:49 +0200 |
commit | aa25ad8d5f476d6db59012a122833ebe677eaf69 (patch) | |
tree | 37eb955dabc252304aefe821d03be5e3857f22c9 /src/qml/qml/qqmlscriptstring.cpp | |
parent | d64224041efe9febc683cf5ee7155a9cc88058d9 (diff) |
Make QQmlScriptString opaque.
Allow for future optimization by encapsulating the
raw script data.
Change-Id: I1863103e8e6d74ede60593cabb240e16f2ae657e
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlscriptstring.cpp')
-rw-r--r-- | src/qml/qml/qqmlscriptstring.cpp | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/src/qml/qml/qqmlscriptstring.cpp b/src/qml/qml/qqmlscriptstring.cpp index ed7a6affa1..c38105d4eb 100644 --- a/src/qml/qml/qqmlscriptstring.cpp +++ b/src/qml/qml/qqmlscriptstring.cpp @@ -73,6 +73,11 @@ expr.evaluate(); \sa QQmlExpression */ +const QQmlScriptStringPrivate* QQmlScriptStringPrivate::get(const QQmlScriptString &script) +{ + return script.d.constData(); +} + /*! Constructs an empty instance. */ @@ -82,6 +87,17 @@ QQmlScriptString::QQmlScriptString() } /*! + \internal +*/ +QQmlScriptString::QQmlScriptString(const QString &script, QQmlContext *context, QObject *scope) +: d(new QQmlScriptStringPrivate) +{ + d->script = script; + d->context = context; + d->scope = scope; +} + +/*! Copies \a other. */ QQmlScriptString::QQmlScriptString(const QQmlScriptString &other) @@ -106,51 +122,62 @@ QQmlScriptString &QQmlScriptString::operator=(const QQmlScriptString &other) } /*! -Returns the context for the script. +Returns whether the QQmlScriptString is empty. */ -QQmlContext *QQmlScriptString::context() const +bool QQmlScriptString::isEmpty() const { - return d->context; + return d->script.isEmpty(); } /*! -Sets the \a context for the script. +Returns whether the content of the QQmlScriptString is the \c undefined literal. */ -void QQmlScriptString::setContext(QQmlContext *context) +bool QQmlScriptString::isUndefinedLiteral() const { - d->context = context; + return d->script == QStringLiteral("undefined"); } /*! -Returns the scope object for the script. +Returns whether the content of the QQmlScriptString is the \c null literal. */ -QObject *QQmlScriptString::scopeObject() const +bool QQmlScriptString::isNullLiteral() const { - return d->scope; + return d->script == QStringLiteral("null"); } /*! -Sets the scope \a object for the script. +If the content of the QQmlScriptString is a string literal, returns that string. +Otherwise returns a null QString. */ -void QQmlScriptString::setScopeObject(QObject *object) +QString QQmlScriptString::stringLiteral() const { - d->scope = object; + if (d->isStringLiteral) + return d->script.mid(1, d->script.length()-2); + return QString(); } /*! -Returns the script text. +If the content of the QQmlScriptString is a number literal, returns that number and +sets \a ok to true. Otherwise returns 0.0 and sets \a ok to false. */ -QString QQmlScriptString::script() const +qreal QQmlScriptString::numberLiteral(bool *ok) const { - return d->script; + if (ok) + *ok = d->isNumberLiteral; + return d->isNumberLiteral ? d->numberValue : 0.; } /*! -Sets the \a script text. +If the content of the QQmlScriptString is a boolean literal, returns the boolean value and +sets \a ok to true. Otherwise returns false and sets \a ok to false. */ -void QQmlScriptString::setScript(const QString &script) +bool QQmlScriptString::booleanLiteral(bool *ok) const { - d->script = script; + bool isTrue = d->script == QStringLiteral("true"); + bool isFalse = !isTrue && d->script == QStringLiteral("false"); + if (ok) + *ok = isTrue || isFalse; + return isTrue ? true : false; } QT_END_NAMESPACE |