| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlexpression.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qqmlexpression.h" | - | ||||||||||||||||||
| 41 | #include "qqmlexpression_p.h" | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include "qqmlglobal_p.h" | - | ||||||||||||||||||
| 44 | #include "qqmlengine_p.h" | - | ||||||||||||||||||
| 45 | #include "qqmlcontext_p.h" | - | ||||||||||||||||||
| 46 | #include "qqmlscriptstring_p.h" | - | ||||||||||||||||||
| 47 | #include "qqmlbinding_p.h" | - | ||||||||||||||||||
| 48 | #include <private/qv8engine_p.h> | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | QQmlExpressionPrivate::QQmlExpressionPrivate() | - | ||||||||||||||||||
| 55 | : QQmlJavaScriptExpression(), | - | ||||||||||||||||||
| 56 | expressionFunctionValid(true), | - | ||||||||||||||||||
| 57 | line(0), column(0) | - | ||||||||||||||||||
| 58 | { | - | ||||||||||||||||||
| 59 | } executed 1130416 times by 22 tests: end of blockExecuted by:
| 1130416 | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | QQmlExpressionPrivate::~QQmlExpressionPrivate() | - | ||||||||||||||||||
| 62 | { | - | ||||||||||||||||||
| 63 | } | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | void QQmlExpressionPrivate::init(QQmlContextData *ctxt, const QString &expr, QObject *me) | - | ||||||||||||||||||
| 66 | { | - | ||||||||||||||||||
| 67 | expression = expr; | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | QQmlJavaScriptExpression::setContext(ctxt); | - | ||||||||||||||||||
| 70 | setScopeObject(me); | - | ||||||||||||||||||
| 71 | expressionFunctionValid = false; | - | ||||||||||||||||||
| 72 | } executed 1112342 times by 15 tests: end of blockExecuted by:
| 1112342 | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | void QQmlExpressionPrivate::init(QQmlContextData *ctxt, QV4::Function *runtimeFunction, QObject *me) | - | ||||||||||||||||||
| 75 | { | - | ||||||||||||||||||
| 76 | expressionFunctionValid = true; | - | ||||||||||||||||||
| 77 | QV4::ExecutionEngine *engine = ctxt->engine->handle(); | - | ||||||||||||||||||
| 78 | QV4::Scope scope(engine); | - | ||||||||||||||||||
| 79 | QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(engine->rootContext(), ctxt, me)); | - | ||||||||||||||||||
| 80 | setupFunction(qmlContext, runtimeFunction); | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | QQmlJavaScriptExpression::setContext(ctxt); | - | ||||||||||||||||||
| 83 | setScopeObject(me); | - | ||||||||||||||||||
| 84 | } executed 18074 times by 11 tests: end of blockExecuted by:
| 18074 | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | /*! | - | ||||||||||||||||||
| 87 | \class QQmlExpression | - | ||||||||||||||||||
| 88 | \since 5.0 | - | ||||||||||||||||||
| 89 | \inmodule QtQml | - | ||||||||||||||||||
| 90 | \brief The QQmlExpression class evaluates JavaScript in a QML context. | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | For example, given a file \c main.qml like this: | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | \qml | - | ||||||||||||||||||
| 95 | import QtQuick 2.0 | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | Item { | - | ||||||||||||||||||
| 98 | width: 200; height: 200 | - | ||||||||||||||||||
| 99 | } | - | ||||||||||||||||||
| 100 | \endqml | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | The following code evaluates a JavaScript expression in the context of the | - | ||||||||||||||||||
| 103 | above QML: | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | \code | - | ||||||||||||||||||
| 106 | QQmlEngine *engine = new QQmlEngine; | - | ||||||||||||||||||
| 107 | QQmlComponent component(engine, QUrl::fromLocalFile("main.qml")); | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | QObject *myObject = component.create(); | - | ||||||||||||||||||
| 110 | QQmlExpression *expr = new QQmlExpression(engine->rootContext(), myObject, "width * 2"); | - | ||||||||||||||||||
| 111 | int result = expr->evaluate().toInt(); // result = 400 | - | ||||||||||||||||||
| 112 | \endcode | - | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | Note that the \l {Qt Quick 1} version is called QDeclarativeExpression. | - | ||||||||||||||||||
| 115 | */ | - | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | /*! | - | ||||||||||||||||||
| 118 | Create an invalid QQmlExpression. | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | As the expression will not have an associated QQmlContext, this will be a | - | ||||||||||||||||||
| 121 | null expression object and its value will always be an invalid QVariant. | - | ||||||||||||||||||
| 122 | */ | - | ||||||||||||||||||
| 123 | QQmlExpression::QQmlExpression() | - | ||||||||||||||||||
| 124 | : QObject(*new QQmlExpressionPrivate, nullptr) | - | ||||||||||||||||||
| 125 | { | - | ||||||||||||||||||
| 126 | } never executed: end of block | 0 | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | /*! | - | ||||||||||||||||||
| 129 | Create a QQmlExpression object that is a child of \a parent. | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | The \a script provides the expression to be evaluated, the context to evaluate it in, | - | ||||||||||||||||||
| 132 | and the scope object to evaluate it with. If provided, \a ctxt and \a scope will override | - | ||||||||||||||||||
| 133 | the context and scope object provided by \a script. | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | \sa QQmlScriptString | - | ||||||||||||||||||
| 136 | */ | - | ||||||||||||||||||
| 137 | QQmlExpression::QQmlExpression(const QQmlScriptString &script, QQmlContext *ctxt, QObject *scope, QObject *parent) | - | ||||||||||||||||||
| 138 | : QObject(*new QQmlExpressionPrivate, parent) | - | ||||||||||||||||||
| 139 | { | - | ||||||||||||||||||
| 140 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 141 | if (ctxt && !ctxt->isValid())
| 0-18070 | ||||||||||||||||||
| 142 | return; never executed: return; | 0 | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | const QQmlScriptStringPrivate *scriptPrivate = script.d.data(); | - | ||||||||||||||||||
| 145 | if (!ctxt && (!scriptPrivate->context || !scriptPrivate->context->isValid()))
| 0-18070 | ||||||||||||||||||
| 146 | return; never executed: return; | 0 | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | QQmlContextData *evalCtxtData = QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context); | - | ||||||||||||||||||
| 149 | QObject *scopeObject = scope ? scope : scriptPrivate->scope;
| 4-18070 | ||||||||||||||||||
| 150 | QV4::Function *runtimeFunction = nullptr; | - | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | if (scriptPrivate->context) {
| 0-18074 | ||||||||||||||||||
| 153 | QQmlContextData *ctxtdata = QQmlContextData::get(scriptPrivate->context); | - | ||||||||||||||||||
| 154 | QQmlEnginePrivate *engine = QQmlEnginePrivate::get(scriptPrivate->context->engine()); | - | ||||||||||||||||||
| 155 | if (engine && ctxtdata && !ctxtdata->urlString().isEmpty() && ctxtdata->typeCompilationUnit) {
| 0-18074 | ||||||||||||||||||
| 156 | d->url = ctxtdata->urlString(); | - | ||||||||||||||||||
| 157 | d->line = scriptPrivate->lineNumber; | - | ||||||||||||||||||
| 158 | d->column = scriptPrivate->columnNumber; | - | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | if (scriptPrivate->bindingId != QQmlBinding::Invalid)
| 0-18074 | ||||||||||||||||||
| 161 | runtimeFunction = ctxtdata->typeCompilationUnit->runtimeFunctions.at(scriptPrivate->bindingId); executed 18074 times by 11 tests: runtimeFunction = ctxtdata->typeCompilationUnit->runtimeFunctions.at(scriptPrivate->bindingId);Executed by:
| 18074 | ||||||||||||||||||
| 162 | } executed 18074 times by 11 tests: end of blockExecuted by:
| 18074 | ||||||||||||||||||
| 163 | } executed 18074 times by 11 tests: end of blockExecuted by:
| 18074 | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | if (runtimeFunction) {
| 0-18074 | ||||||||||||||||||
| 166 | d->expression = scriptPrivate->script; | - | ||||||||||||||||||
| 167 | d->init(evalCtxtData, runtimeFunction, scopeObject); | - | ||||||||||||||||||
| 168 | } else executed 18074 times by 11 tests: end of blockExecuted by:
| 18074 | ||||||||||||||||||
| 169 | d->init(evalCtxtData, scriptPrivate->script, scopeObject); never executed: d->init(evalCtxtData, scriptPrivate->script, scopeObject); | 0 | ||||||||||||||||||
| 170 | } | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | /*! | - | ||||||||||||||||||
| 173 | Create a QQmlExpression object that is a child of \a parent. | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | The \a expression JavaScript will be executed in the \a ctxt QQmlContext. | - | ||||||||||||||||||
| 176 | If specified, the \a scope object's properties will also be in scope during | - | ||||||||||||||||||
| 177 | the expression's execution. | - | ||||||||||||||||||
| 178 | */ | - | ||||||||||||||||||
| 179 | QQmlExpression::QQmlExpression(QQmlContext *ctxt, | - | ||||||||||||||||||
| 180 | QObject *scope, | - | ||||||||||||||||||
| 181 | const QString &expression, | - | ||||||||||||||||||
| 182 | QObject *parent) | - | ||||||||||||||||||
| 183 | : QObject(*new QQmlExpressionPrivate, parent) | - | ||||||||||||||||||
| 184 | { | - | ||||||||||||||||||
| 185 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 186 | d->init(QQmlContextData::get(ctxt), expression, scope); | - | ||||||||||||||||||
| 187 | } executed 1112342 times by 15 tests: end of blockExecuted by:
| 1112342 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | /*! | - | ||||||||||||||||||
| 190 | \internal | - | ||||||||||||||||||
| 191 | */ | - | ||||||||||||||||||
| 192 | QQmlExpression::QQmlExpression(QQmlContextData *ctxt, QObject *scope, | - | ||||||||||||||||||
| 193 | const QString &expression) | - | ||||||||||||||||||
| 194 | : QObject(*new QQmlExpressionPrivate, nullptr) | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 197 | d->init(ctxt, expression, scope); | - | ||||||||||||||||||
| 198 | } never executed: end of block | 0 | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | /*! | - | ||||||||||||||||||
| 201 | Destroy the QQmlExpression instance. | - | ||||||||||||||||||
| 202 | */ | - | ||||||||||||||||||
| 203 | QQmlExpression::~QQmlExpression() | - | ||||||||||||||||||
| 204 | { | - | ||||||||||||||||||
| 205 | } | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | /*! | - | ||||||||||||||||||
| 208 | Returns the QQmlEngine this expression is associated with, or 0 if there | - | ||||||||||||||||||
| 209 | is no association or the QQmlEngine has been destroyed. | - | ||||||||||||||||||
| 210 | */ | - | ||||||||||||||||||
| 211 | QQmlEngine *QQmlExpression::engine() const | - | ||||||||||||||||||
| 212 | { | - | ||||||||||||||||||
| 213 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 214 | return d->context()?d->context()->engine:nullptr; executed 1130746 times by 21 tests: return d->context()?d->context()->engine:nullptr;Executed by:
| 1130746 | ||||||||||||||||||
| 215 | } | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | /*! | - | ||||||||||||||||||
| 218 | Returns the QQmlContext this expression is associated with, or 0 if there | - | ||||||||||||||||||
| 219 | is no association or the QQmlContext has been destroyed. | - | ||||||||||||||||||
| 220 | */ | - | ||||||||||||||||||
| 221 | QQmlContext *QQmlExpression::context() const | - | ||||||||||||||||||
| 222 | { | - | ||||||||||||||||||
| 223 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 224 | QQmlContextData *data = d->context(); | - | ||||||||||||||||||
| 225 | return data?data->asQQmlContext():nullptr; executed 4 times by 1 test: return data?data->asQQmlContext():nullptr;Executed by:
| 4 | ||||||||||||||||||
| 226 | } | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | /*! | - | ||||||||||||||||||
| 229 | Returns the expression string. | - | ||||||||||||||||||
| 230 | */ | - | ||||||||||||||||||
| 231 | QString QQmlExpression::expression() const | - | ||||||||||||||||||
| 232 | { | - | ||||||||||||||||||
| 233 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 234 | return d->expression; never executed: return d->expression; | 0 | ||||||||||||||||||
| 235 | } | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | /*! | - | ||||||||||||||||||
| 238 | Set the expression to \a expression. | - | ||||||||||||||||||
| 239 | */ | - | ||||||||||||||||||
| 240 | void QQmlExpression::setExpression(const QString &expression) | - | ||||||||||||||||||
| 241 | { | - | ||||||||||||||||||
| 242 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | d->resetNotifyOnValueChanged(); | - | ||||||||||||||||||
| 245 | d->expression = expression; | - | ||||||||||||||||||
| 246 | d->expressionFunctionValid = false; | - | ||||||||||||||||||
| 247 | } executed 128 times by 1 test: end of blockExecuted by:
| 128 | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | // Must be called with a valid handle scope | - | ||||||||||||||||||
| 250 | QV4::ReturnedValue QQmlExpressionPrivate::v4value(bool *isUndefined) | - | ||||||||||||||||||
| 251 | { | - | ||||||||||||||||||
| 252 | if (!expressionFunctionValid) {
| 18104-1112468 | ||||||||||||||||||
| 253 | createQmlBinding(context(), scopeObject(), expression, url, line); | - | ||||||||||||||||||
| 254 | expressionFunctionValid = true; | - | ||||||||||||||||||
| 255 | if (hasError()) {
| 6-1112462 | ||||||||||||||||||
| 256 | if (isUndefined)
| 2-4 | ||||||||||||||||||
| 257 | *isUndefined = true; executed 2 times by 1 test: *isUndefined = true;Executed by:
| 2 | ||||||||||||||||||
| 258 | return QV4::Encode::undefined(); executed 6 times by 3 tests: return QV4::Encode::undefined();Executed by:
| 6 | ||||||||||||||||||
| 259 | } | - | ||||||||||||||||||
| 260 | } executed 1112462 times by 14 tests: end of blockExecuted by:
| 1112462 | ||||||||||||||||||
| 261 | - | |||||||||||||||||||
| 262 | return evaluate(isUndefined); executed 1130566 times by 21 tests: return evaluate(isUndefined);Executed by:
| 1130566 | ||||||||||||||||||
| 263 | } | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | QVariant QQmlExpressionPrivate::value(bool *isUndefined) | - | ||||||||||||||||||
| 266 | { | - | ||||||||||||||||||
| 267 | Q_Q(QQmlExpression); | - | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | if (!context() || !context()->isValid()) {
| 0-1130572 | ||||||||||||||||||
| 270 | qWarning("QQmlExpression: Attempted to evaluate an expression in an invalid context"); | - | ||||||||||||||||||
| 271 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||
| 272 | } | - | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | QQmlEngine *engine = q->engine(); | - | ||||||||||||||||||
| 275 | QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); | - | ||||||||||||||||||
| 276 | QVariant rv; | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. | - | ||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | { | - | ||||||||||||||||||
| 281 | QV4::Scope scope(engine->handle()); | - | ||||||||||||||||||
| 282 | QV4::ScopedValue result(scope, v4value(isUndefined)); | - | ||||||||||||||||||
| 283 | if (!hasError())
| 18-1130554 | ||||||||||||||||||
| 284 | rv = scope.engine->toVariant(result, -1); executed 1130554 times by 21 tests: rv = scope.engine->toVariant(result, -1);Executed by:
| 1130554 | ||||||||||||||||||
| 285 | } | - | ||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete. | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | return rv; executed 1130572 times by 21 tests: return rv;Executed by:
| 1130572 | ||||||||||||||||||
| 290 | } | - | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | /*! | - | ||||||||||||||||||
| 293 | Evaulates the expression, returning the result of the evaluation, | - | ||||||||||||||||||
| 294 | or an invalid QVariant if the expression is invalid or has an error. | - | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | \a valueIsUndefined is set to true if the expression resulted in an | - | ||||||||||||||||||
| 297 | undefined value. | - | ||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | \sa hasError(), error() | - | ||||||||||||||||||
| 300 | */ | - | ||||||||||||||||||
| 301 | QVariant QQmlExpression::evaluate(bool *valueIsUndefined) | - | ||||||||||||||||||
| 302 | { | - | ||||||||||||||||||
| 303 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 304 | return d->value(valueIsUndefined); executed 1130572 times by 21 tests: return d->value(valueIsUndefined);Executed by:
| 1130572 | ||||||||||||||||||
| 305 | } | - | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | /*! | - | ||||||||||||||||||
| 308 | Returns true if the valueChanged() signal is emitted when the expression's evaluated | - | ||||||||||||||||||
| 309 | value changes. | - | ||||||||||||||||||
| 310 | */ | - | ||||||||||||||||||
| 311 | bool QQmlExpression::notifyOnValueChanged() const | - | ||||||||||||||||||
| 312 | { | - | ||||||||||||||||||
| 313 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 314 | return d->notifyOnValueChanged(); never executed: return d->notifyOnValueChanged(); | 0 | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | /*! | - | ||||||||||||||||||
| 318 | Sets whether the valueChanged() signal is emitted when the | - | ||||||||||||||||||
| 319 | expression's evaluated value changes. | - | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | If \a notifyOnChange is true, the QQmlExpression will | - | ||||||||||||||||||
| 322 | monitor properties involved in the expression's evaluation, and emit | - | ||||||||||||||||||
| 323 | QQmlExpression::valueChanged() if they have changed. This | - | ||||||||||||||||||
| 324 | allows an application to ensure that any value associated with the | - | ||||||||||||||||||
| 325 | result of the expression remains up to date. | - | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | If \a notifyOnChange is false (default), the QQmlExpression | - | ||||||||||||||||||
| 328 | will not montitor properties involved in the expression's | - | ||||||||||||||||||
| 329 | evaluation, and QQmlExpression::valueChanged() will never be | - | ||||||||||||||||||
| 330 | emitted. This is more efficient if an application wants a "one off" | - | ||||||||||||||||||
| 331 | evaluation of the expression. | - | ||||||||||||||||||
| 332 | */ | - | ||||||||||||||||||
| 333 | void QQmlExpression::setNotifyOnValueChanged(bool notifyOnChange) | - | ||||||||||||||||||
| 334 | { | - | ||||||||||||||||||
| 335 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 336 | d->setNotifyOnValueChanged(notifyOnChange); | - | ||||||||||||||||||
| 337 | } executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | /*! | - | ||||||||||||||||||
| 340 | Returns the source file URL for this expression. The source location must | - | ||||||||||||||||||
| 341 | have been previously set by calling setSourceLocation(). | - | ||||||||||||||||||
| 342 | */ | - | ||||||||||||||||||
| 343 | QString QQmlExpression::sourceFile() const | - | ||||||||||||||||||
| 344 | { | - | ||||||||||||||||||
| 345 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 346 | return d->url; never executed: return d->url; | 0 | ||||||||||||||||||
| 347 | } | - | ||||||||||||||||||
| 348 | - | |||||||||||||||||||
| 349 | /*! | - | ||||||||||||||||||
| 350 | Returns the source file line number for this expression. The source location | - | ||||||||||||||||||
| 351 | must have been previously set by calling setSourceLocation(). | - | ||||||||||||||||||
| 352 | */ | - | ||||||||||||||||||
| 353 | int QQmlExpression::lineNumber() const | - | ||||||||||||||||||
| 354 | { | - | ||||||||||||||||||
| 355 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 356 | return qmlSourceCoordinate(d->line); never executed: return qmlSourceCoordinate(d->line); | 0 | ||||||||||||||||||
| 357 | } | - | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | /*! | - | ||||||||||||||||||
| 360 | Returns the source file column number for this expression. The source location | - | ||||||||||||||||||
| 361 | must have been previously set by calling setSourceLocation(). | - | ||||||||||||||||||
| 362 | */ | - | ||||||||||||||||||
| 363 | int QQmlExpression::columnNumber() const | - | ||||||||||||||||||
| 364 | { | - | ||||||||||||||||||
| 365 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 366 | return qmlSourceCoordinate(d->column); never executed: return qmlSourceCoordinate(d->column); | 0 | ||||||||||||||||||
| 367 | } | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | /*! | - | ||||||||||||||||||
| 370 | Set the location of this expression to \a line and \a column of \a url. This information | - | ||||||||||||||||||
| 371 | is used by the script engine. | - | ||||||||||||||||||
| 372 | */ | - | ||||||||||||||||||
| 373 | void QQmlExpression::setSourceLocation(const QString &url, int line, int column) | - | ||||||||||||||||||
| 374 | { | - | ||||||||||||||||||
| 375 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 376 | d->url = url; | - | ||||||||||||||||||
| 377 | d->line = qmlSourceCoordinate(line); | - | ||||||||||||||||||
| 378 | d->column = qmlSourceCoordinate(column); | - | ||||||||||||||||||
| 379 | } never executed: end of block | 0 | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | /*! | - | ||||||||||||||||||
| 382 | Returns the expression's scope object, if provided, otherwise 0. | - | ||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | In addition to data provided by the expression's QQmlContext, the scope | - | ||||||||||||||||||
| 385 | object's properties are also in scope during the expression's evaluation. | - | ||||||||||||||||||
| 386 | */ | - | ||||||||||||||||||
| 387 | QObject *QQmlExpression::scopeObject() const | - | ||||||||||||||||||
| 388 | { | - | ||||||||||||||||||
| 389 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 390 | return d->scopeObject(); never executed: return d->scopeObject(); | 0 | ||||||||||||||||||
| 391 | } | - | ||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | /*! | - | ||||||||||||||||||
| 394 | Returns true if the last call to evaluate() resulted in an error, | - | ||||||||||||||||||
| 395 | otherwise false. | - | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | \sa error(), clearError() | - | ||||||||||||||||||
| 398 | */ | - | ||||||||||||||||||
| 399 | bool QQmlExpression::hasError() const | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 402 | return d->hasError(); executed 84392 times by 17 tests: return d->hasError();Executed by:
| 84392 | ||||||||||||||||||
| 403 | } | - | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | /*! | - | ||||||||||||||||||
| 406 | Clear any expression errors. Calls to hasError() following this will | - | ||||||||||||||||||
| 407 | return false. | - | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | \sa hasError(), error() | - | ||||||||||||||||||
| 410 | */ | - | ||||||||||||||||||
| 411 | void QQmlExpression::clearError() | - | ||||||||||||||||||
| 412 | { | - | ||||||||||||||||||
| 413 | Q_D(QQmlExpression); | - | ||||||||||||||||||
| 414 | d->clearError(); | - | ||||||||||||||||||
| 415 | } never executed: end of block | 0 | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | /*! | - | ||||||||||||||||||
| 418 | Return any error from the last call to evaluate(). If there was no error, | - | ||||||||||||||||||
| 419 | this returns an invalid QQmlError instance. | - | ||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | \sa hasError(), clearError() | - | ||||||||||||||||||
| 422 | */ | - | ||||||||||||||||||
| 423 | - | |||||||||||||||||||
| 424 | QQmlError QQmlExpression::error() const | - | ||||||||||||||||||
| 425 | { | - | ||||||||||||||||||
| 426 | Q_D(const QQmlExpression); | - | ||||||||||||||||||
| 427 | return d->error(engine()); executed 174 times by 5 tests: return d->error(engine());Executed by:
| 174 | ||||||||||||||||||
| 428 | } | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | /*! | - | ||||||||||||||||||
| 431 | \fn void QQmlExpression::valueChanged() | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | Emitted each time the expression value changes from the last time it was | - | ||||||||||||||||||
| 434 | evaluated. The expression must have been evaluated at least once (by | - | ||||||||||||||||||
| 435 | calling QQmlExpression::evaluate()) before this signal will be emitted. | - | ||||||||||||||||||
| 436 | */ | - | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | void QQmlExpressionPrivate::expressionChanged() | - | ||||||||||||||||||
| 439 | { | - | ||||||||||||||||||
| 440 | Q_Q(QQmlExpression); | - | ||||||||||||||||||
| 441 | emit q->valueChanged(); | - | ||||||||||||||||||
| 442 | } executed 34 times by 2 tests: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | QString QQmlExpressionPrivate::expressionIdentifier() const | - | ||||||||||||||||||
| 445 | { | - | ||||||||||||||||||
| 446 | return QLatin1Char('"') + expression + QLatin1Char('"'); never executed: return QLatin1Char('"') + expression + QLatin1Char('"'); | 0 | ||||||||||||||||||
| 447 | } | - | ||||||||||||||||||
| 448 | - | |||||||||||||||||||
| 449 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | #include <moc_qqmlexpression.cpp> | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |