| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlscriptstring.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 "qqmlscriptstring.h" | - | ||||||||||||
| 41 | #include "qqmlscriptstring_p.h" | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | /*! | - | ||||||||||||
| 46 | \class QQmlScriptString | - | ||||||||||||
| 47 | \brief The QQmlScriptString class encapsulates a script and its context. | - | ||||||||||||
| 48 | \inmodule QtQml | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | QQmlScriptString is used to create QObject properties that accept a script "assignment" from QML. | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | Normally, the following QML would result in a binding being established for the \c script | - | ||||||||||||
| 53 | property; i.e. \c script would be assigned the value obtained from running \c {myObj.value = Math.max(myValue, 100)} | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | \qml | - | ||||||||||||
| 56 | MyType { | - | ||||||||||||
| 57 | script: myObj.value = Math.max(myValue, 100) | - | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | \endqml | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | If instead the property had a type of QQmlScriptString, | - | ||||||||||||
| 62 | the script itself -- \e {myObj.value = Math.max(myValue, 100)} -- would be passed to the \c script property | - | ||||||||||||
| 63 | and the class could choose how to handle it. Typically, the class will evaluate | - | ||||||||||||
| 64 | the script at some later time using a QQmlExpression. | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | \code | - | ||||||||||||
| 67 | QQmlExpression expr(scriptString); | - | ||||||||||||
| 68 | expr.evaluate(); | - | ||||||||||||
| 69 | \endcode | - | ||||||||||||
| 70 | - | |||||||||||||
| 71 | \sa QQmlExpression | - | ||||||||||||
| 72 | */ | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | const QQmlScriptStringPrivate* QQmlScriptStringPrivate::get(const QQmlScriptString &script) | - | ||||||||||||
| 75 | { | - | ||||||||||||
| 76 | return script.d.constData(); never executed: return script.d.constData(); | 0 | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | /*! | - | ||||||||||||
| 80 | Constructs an empty instance. | - | ||||||||||||
| 81 | */ | - | ||||||||||||
| 82 | QQmlScriptString::QQmlScriptString() | - | ||||||||||||
| 83 | : d(new QQmlScriptStringPrivate) | - | ||||||||||||
| 84 | { | - | ||||||||||||
| 85 | } executed 9218 times by 14 tests: end of blockExecuted by:
| 9218 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | /*! | - | ||||||||||||
| 88 | \internal | - | ||||||||||||
| 89 | */ | - | ||||||||||||
| 90 | QQmlScriptString::QQmlScriptString(const QString &script, QQmlContext *context, QObject *scope) | - | ||||||||||||
| 91 | : d(new QQmlScriptStringPrivate) | - | ||||||||||||
| 92 | { | - | ||||||||||||
| 93 | d->script = script; | - | ||||||||||||
| 94 | d->context = context; | - | ||||||||||||
| 95 | d->scope = scope; | - | ||||||||||||
| 96 | } executed 4340 times by 13 tests: end of blockExecuted by:
| 4340 | ||||||||||||
| 97 | - | |||||||||||||
| 98 | /*! | - | ||||||||||||
| 99 | Copies \a other. | - | ||||||||||||
| 100 | */ | - | ||||||||||||
| 101 | QQmlScriptString::QQmlScriptString(const QQmlScriptString &other) | - | ||||||||||||
| 102 | : d(other.d) | - | ||||||||||||
| 103 | { | - | ||||||||||||
| 104 | } executed 18266 times by 11 tests: end of blockExecuted by:
| 18266 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | /*! | - | ||||||||||||
| 107 | \internal | - | ||||||||||||
| 108 | */ | - | ||||||||||||
| 109 | QQmlScriptString::~QQmlScriptString() | - | ||||||||||||
| 110 | { | - | ||||||||||||
| 111 | } | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | /*! | - | ||||||||||||
| 114 | Assigns \a other to this. | - | ||||||||||||
| 115 | */ | - | ||||||||||||
| 116 | QQmlScriptString &QQmlScriptString::operator=(const QQmlScriptString &other) | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | d = other.d; | - | ||||||||||||
| 119 | return *this; executed 4340 times by 13 tests: return *this;Executed by:
| 4340 | ||||||||||||
| 120 | } | - | ||||||||||||
| 121 | - | |||||||||||||
| 122 | /*! | - | ||||||||||||
| 123 | Returns \c true if this and the \a other QQmlScriptString objects are equal. | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | \sa operator!=() | - | ||||||||||||
| 126 | */ | - | ||||||||||||
| 127 | bool QQmlScriptString::operator==(const QQmlScriptString &other) const | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | if (d == other.d)
| 0-8 | ||||||||||||
| 130 | return true; never executed: return true; | 0 | ||||||||||||
| 131 | - | |||||||||||||
| 132 | if (d->isNumberLiteral || other.d->isNumberLiteral)
| 0-8 | ||||||||||||
| 133 | return d->isNumberLiteral && other.d->isNumberLiteral && d->numberValue == other.d->numberValue; never executed: return d->isNumberLiteral && other.d->isNumberLiteral && d->numberValue == other.d->numberValue; | 0 | ||||||||||||
| 134 | - | |||||||||||||
| 135 | if (d->isStringLiteral || other.d->isStringLiteral)
| 0-8 | ||||||||||||
| 136 | return d->isStringLiteral && other.d->isStringLiteral && d->script == other.d->script; never executed: return d->isStringLiteral && other.d->isStringLiteral && d->script == other.d->script; | 0 | ||||||||||||
| 137 | - | |||||||||||||
| 138 | if (d->script == QLatin1String("true") ||
| 0-8 | ||||||||||||
| 139 | d->script == QLatin1String("false") ||
| 0-8 | ||||||||||||
| 140 | d->script == QLatin1String("undefined") ||
| 0-8 | ||||||||||||
| 141 | d->script == QLatin1String("null"))
| 0-8 | ||||||||||||
| 142 | return d->script == other.d->script; never executed: return d->script == other.d->script; | 0 | ||||||||||||
| 143 | - | |||||||||||||
| 144 | return d->context == other.d->context && executed 8 times by 2 tests: return d->context == other.d->context && d->scope == other.d->scope && d->script == other.d->script && d->bindingId == other.d->bindingId;Executed by:
| 8 | ||||||||||||
| 145 | d->scope == other.d->scope && executed 8 times by 2 tests: return d->context == other.d->context && d->scope == other.d->scope && d->script == other.d->script && d->bindingId == other.d->bindingId;Executed by:
| 8 | ||||||||||||
| 146 | d->script == other.d->script && executed 8 times by 2 tests: return d->context == other.d->context && d->scope == other.d->scope && d->script == other.d->script && d->bindingId == other.d->bindingId;Executed by:
| 8 | ||||||||||||
| 147 | d->bindingId == other.d->bindingId; executed 8 times by 2 tests: return d->context == other.d->context && d->scope == other.d->scope && d->script == other.d->script && d->bindingId == other.d->bindingId;Executed by:
| 8 | ||||||||||||
| 148 | } | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | /*! | - | ||||||||||||
| 151 | Returns \c true if this and the \a other QQmlScriptString objects are different. | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | \sa operator==() | - | ||||||||||||
| 154 | */ | - | ||||||||||||
| 155 | bool QQmlScriptString::operator!=(const QQmlScriptString &other) const | - | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | return !operator==(other); never executed: return !operator==(other); | 0 | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | /*! | - | ||||||||||||
| 161 | Returns whether the QQmlScriptString is empty. | - | ||||||||||||
| 162 | */ | - | ||||||||||||
| 163 | bool QQmlScriptString::isEmpty() const | - | ||||||||||||
| 164 | { | - | ||||||||||||
| 165 | if (!d->script.isEmpty())
| 0-18086 | ||||||||||||
| 166 | return false; executed 18086 times by 11 tests: return false;Executed by:
| 18086 | ||||||||||||
| 167 | return d->bindingId == -1; never executed: return d->bindingId == -1; | 0 | ||||||||||||
| 168 | } | - | ||||||||||||
| 169 | - | |||||||||||||
| 170 | /*! | - | ||||||||||||
| 171 | Returns whether the content of the QQmlScriptString is the \c undefined literal. | - | ||||||||||||
| 172 | */ | - | ||||||||||||
| 173 | bool QQmlScriptString::isUndefinedLiteral() const | - | ||||||||||||
| 174 | { | - | ||||||||||||
| 175 | return d->script == QLatin1String("undefined"); executed 96 times by 5 tests: return d->script == QLatin1String("undefined");Executed by:
| 96 | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | /*! | - | ||||||||||||
| 179 | Returns whether the content of the QQmlScriptString is the \c null literal. | - | ||||||||||||
| 180 | */ | - | ||||||||||||
| 181 | bool QQmlScriptString::isNullLiteral() const | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | return d->script == QLatin1String("null"); never executed: return d->script == QLatin1String("null"); | 0 | ||||||||||||
| 184 | } | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | /*! | - | ||||||||||||
| 187 | If the content of the QQmlScriptString is a string literal, returns that string. | - | ||||||||||||
| 188 | Otherwise returns a null QString. | - | ||||||||||||
| 189 | */ | - | ||||||||||||
| 190 | QString QQmlScriptString::stringLiteral() const | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | if (d->isStringLiteral)
| 0 | ||||||||||||
| 193 | return d->script.mid(1, d->script.length()-2); never executed: return d->script.mid(1, d->script.length()-2); | 0 | ||||||||||||
| 194 | return QString(); never executed: return QString(); | 0 | ||||||||||||
| 195 | } | - | ||||||||||||
| 196 | - | |||||||||||||
| 197 | /*! | - | ||||||||||||
| 198 | If the content of the QQmlScriptString is a number literal, returns that number and | - | ||||||||||||
| 199 | sets \a ok to true. Otherwise returns 0.0 and sets \a ok to false. | - | ||||||||||||
| 200 | */ | - | ||||||||||||
| 201 | qreal QQmlScriptString::numberLiteral(bool *ok) const | - | ||||||||||||
| 202 | { | - | ||||||||||||
| 203 | if (ok)
| 0-186 | ||||||||||||
| 204 | *ok = d->isNumberLiteral; executed 186 times by 4 tests: *ok = d->isNumberLiteral;Executed by:
| 186 | ||||||||||||
| 205 | return d->isNumberLiteral ? d->numberValue : 0.; executed 186 times by 4 tests: return d->isNumberLiteral ? d->numberValue : 0.;Executed by:
| 186 | ||||||||||||
| 206 | } | - | ||||||||||||
| 207 | - | |||||||||||||
| 208 | /*! | - | ||||||||||||
| 209 | If the content of the QQmlScriptString is a boolean literal, returns the boolean value and | - | ||||||||||||
| 210 | sets \a ok to true. Otherwise returns false and sets \a ok to false. | - | ||||||||||||
| 211 | */ | - | ||||||||||||
| 212 | bool QQmlScriptString::booleanLiteral(bool *ok) const | - | ||||||||||||
| 213 | { | - | ||||||||||||
| 214 | bool isTrue = d->script == QLatin1String("true"); | - | ||||||||||||
| 215 | bool isFalse = !isTrue && d->script == QLatin1String("false");
| 0 | ||||||||||||
| 216 | if (ok)
| 0 | ||||||||||||
| 217 | *ok = isTrue || isFalse; never executed: *ok = isTrue || isFalse;
| 0 | ||||||||||||
| 218 | return isTrue ? true : false; never executed: return isTrue ? true : false; | 0 | ||||||||||||
| 219 | } | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | QT_END_NAMESPACE | - | ||||||||||||
| 222 | - | |||||||||||||
| Source code | Switch to Preprocessed file |