OpenCoverage

qqmlscriptstring.cpp

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

Generated by Squish Coco 4.2.0