Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickpropertychanges.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 QtQuick 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 "qquickpropertychanges_p.h" | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | #include <private/qqmlopenmetaobject_p.h> | - | ||||||||||||||||||
43 | #include <private/qqmlengine_p.h> | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | #include <qqmlinfo.h> | - | ||||||||||||||||||
46 | #include <private/qqmlcustomparser_p.h> | - | ||||||||||||||||||
47 | #include <qqmlexpression.h> | - | ||||||||||||||||||
48 | #include <private/qqmlbinding_p.h> | - | ||||||||||||||||||
49 | #include <qqmlcontext.h> | - | ||||||||||||||||||
50 | #include <private/qqmlproperty_p.h> | - | ||||||||||||||||||
51 | #include <private/qqmlcontext_p.h> | - | ||||||||||||||||||
52 | #include <private/qquickstate_p_p.h> | - | ||||||||||||||||||
53 | #include <private/qqmlboundsignal_p.h> | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | #include <private/qobject_p.h> | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | /*! | - | ||||||||||||||||||
62 | \qmltype PropertyChanges | - | ||||||||||||||||||
63 | \inqmlmodule QtQuick | - | ||||||||||||||||||
64 | \ingroup qtquick-states | - | ||||||||||||||||||
65 | \brief Describes new property bindings or values for a state. | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | PropertyChanges is used to define the property values or bindings in a | - | ||||||||||||||||||
68 | \l State. This enables an item's property values to be changed when it | - | ||||||||||||||||||
69 | \l {Qt Quick States}{changes between states}. | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | To create a PropertyChanges object, specify the \l target item whose | - | ||||||||||||||||||
72 | properties are to be modified, and define the new property values or | - | ||||||||||||||||||
73 | bindings. For example: | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | \snippet qml/propertychanges.qml import | - | ||||||||||||||||||
76 | \codeline | - | ||||||||||||||||||
77 | \snippet qml/propertychanges.qml 0 | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | When the mouse is pressed, the \l Rectangle changes to the \e resized | - | ||||||||||||||||||
80 | state. In this state, the PropertyChanges object sets the rectangle's | - | ||||||||||||||||||
81 | color to blue and the \c height value to that of \c container.height. | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | Note this automatically binds \c rect.height to \c container.height | - | ||||||||||||||||||
84 | in the \e resized state. If a property binding should not be | - | ||||||||||||||||||
85 | established, and the height should just be set to the value of | - | ||||||||||||||||||
86 | \c container.height at the time of the state change, set the \l explicit | - | ||||||||||||||||||
87 | property to \c true. | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | A PropertyChanges object can also override the default signal handler | - | ||||||||||||||||||
90 | for an object to implement a signal handler specific to the new state: | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | \qml | - | ||||||||||||||||||
93 | PropertyChanges { | - | ||||||||||||||||||
94 | target: myMouseArea | - | ||||||||||||||||||
95 | onClicked: doSomethingDifferent() | - | ||||||||||||||||||
96 | } | - | ||||||||||||||||||
97 | \endqml | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | \note PropertyChanges can be used to change anchor margins, but not other anchor | - | ||||||||||||||||||
100 | values; use AnchorChanges for this instead. Similarly, to change an \l Item's | - | ||||||||||||||||||
101 | \l {Item::}{parent} value, use ParentChange instead. | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | - | |||||||||||||||||||
104 | \section2 Resetting Property Values | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | The \c undefined value can be used to reset the property value for a state. | - | ||||||||||||||||||
107 | In the following example, when \c myText changes to the \e widerText | - | ||||||||||||||||||
108 | state, its \c width property is reset, giving the text its natural width | - | ||||||||||||||||||
109 | and displaying the whole string on a single line. | - | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | \snippet qml/propertychanges.qml reset | - | ||||||||||||||||||
112 | - | |||||||||||||||||||
113 | - | |||||||||||||||||||
114 | \section2 Immediate Property Changes in Transitions | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | When \l{Animation and Transitions in Qt Quick}{Transitions} are used to animate | - | ||||||||||||||||||
117 | state changes, they animate properties from their values in the current | - | ||||||||||||||||||
118 | state to those defined in the new state (as defined by PropertyChanges | - | ||||||||||||||||||
119 | objects). However, it is sometimes desirable to set a property value | - | ||||||||||||||||||
120 | \e immediately during a \l Transition, without animation; in these cases, | - | ||||||||||||||||||
121 | the PropertyAction type can be used to force an immediate property | - | ||||||||||||||||||
122 | change. | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | See the PropertyAction documentation for more details. | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | \note The \l{Item::}{visible} and \l{Item::}{enabled} properties of \l Item do not behave | - | ||||||||||||||||||
127 | exactly the same as other properties in PropertyChanges. Since these properties can be | - | ||||||||||||||||||
128 | changed implicitly through their parent's state, they should be set explicitly in all PropertyChanges. | - | ||||||||||||||||||
129 | An item will still not be enabled/visible if one of its parents is not enabled or visible. | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | \sa {Qt Quick Examples - Animation#States}{States example}, {Qt Quick States}, {Qt QML} | - | ||||||||||||||||||
132 | */ | - | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | /*! | - | ||||||||||||||||||
135 | \qmlproperty Object QtQuick::PropertyChanges::target | - | ||||||||||||||||||
136 | This property holds the object which contains the properties to be changed. | - | ||||||||||||||||||
137 | */ | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | class QQuickReplaceSignalHandler : public QQuickStateActionEvent | - | ||||||||||||||||||
140 | { | - | ||||||||||||||||||
141 | public: | - | ||||||||||||||||||
142 | QQuickReplaceSignalHandler() {} | - | ||||||||||||||||||
143 | ~QQuickReplaceSignalHandler() {} | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | EventType type() const override { return SignalHandler; } executed 40 times by 1 test: return SignalHandler; Executed by:
| 40 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | QQmlProperty property; | - | ||||||||||||||||||
148 | QQmlBoundSignalExpressionPointer expression; | - | ||||||||||||||||||
149 | QQmlBoundSignalExpressionPointer reverseExpression; | - | ||||||||||||||||||
150 | QQmlBoundSignalExpressionPointer rewindExpression; | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | void execute() override { | - | ||||||||||||||||||
153 | QQmlPropertyPrivate::setSignalExpression(property, expression); | - | ||||||||||||||||||
154 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | bool isReversable() override { return true; } executed 84 times by 1 test: return true; Executed by:
| 84 | ||||||||||||||||||
157 | void reverse() override { | - | ||||||||||||||||||
158 | QQmlPropertyPrivate::setSignalExpression(property, reverseExpression); | - | ||||||||||||||||||
159 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | void saveOriginals() override { | - | ||||||||||||||||||
162 | saveCurrentValues(); | - | ||||||||||||||||||
163 | reverseExpression = rewindExpression; | - | ||||||||||||||||||
164 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | bool needsCopy() override { return true; } executed 6 times by 1 test: return true; Executed by:
| 6 | ||||||||||||||||||
167 | void copyOriginals(QQuickStateActionEvent *other) override | - | ||||||||||||||||||
168 | { | - | ||||||||||||||||||
169 | QQuickReplaceSignalHandler *rsh = static_cast<QQuickReplaceSignalHandler*>(other); | - | ||||||||||||||||||
170 | saveCurrentValues(); | - | ||||||||||||||||||
171 | if (rsh == this)
| 0-6 | ||||||||||||||||||
172 | return; never executed: return; | 0 | ||||||||||||||||||
173 | reverseExpression = rsh->reverseExpression; | - | ||||||||||||||||||
174 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | void rewind() override { | - | ||||||||||||||||||
177 | QQmlPropertyPrivate::setSignalExpression(property, rewindExpression); | - | ||||||||||||||||||
178 | } never executed: end of block | 0 | ||||||||||||||||||
179 | void saveCurrentValues() override { | - | ||||||||||||||||||
180 | rewindExpression = QQmlPropertyPrivate::signalExpression(property); | - | ||||||||||||||||||
181 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | bool mayOverride(QQuickStateActionEvent *other) override { | - | ||||||||||||||||||
184 | if (other == this)
| 6-8 | ||||||||||||||||||
185 | return true; executed 8 times by 1 test: return true; Executed by:
| 8 | ||||||||||||||||||
186 | if (other->type() != type())
| 0-6 | ||||||||||||||||||
187 | return false; never executed: return false; | 0 | ||||||||||||||||||
188 | if (static_cast<QQuickReplaceSignalHandler*>(other)->property == property)
| 0-6 | ||||||||||||||||||
189 | return true; executed 6 times by 1 test: return true; Executed by:
| 6 | ||||||||||||||||||
190 | return false; never executed: return false; | 0 | ||||||||||||||||||
191 | } | - | ||||||||||||||||||
192 | }; | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | - | |||||||||||||||||||
195 | class QQuickPropertyChangesPrivate : public QQuickStateOperationPrivate | - | ||||||||||||||||||
196 | { | - | ||||||||||||||||||
197 | Q_DECLARE_PUBLIC(QQuickPropertyChanges) | - | ||||||||||||||||||
198 | public: | - | ||||||||||||||||||
199 | QQuickPropertyChangesPrivate() : decoded(true), restore(true), | - | ||||||||||||||||||
200 | isExplicit(false) {} executed 456 times by 17 tests: end of block Executed by:
| 456 | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | QPointer<QObject> object; | - | ||||||||||||||||||
203 | QList<const QV4::CompiledData::Binding *> bindings; | - | ||||||||||||||||||
204 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit; | - | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | bool decoded : 1; | - | ||||||||||||||||||
207 | bool restore : 1; | - | ||||||||||||||||||
208 | bool isExplicit : 1; | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | void decode(); | - | ||||||||||||||||||
211 | void decodeBinding(const QString &propertyPrefix, const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding); | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | class ExpressionChange { | - | ||||||||||||||||||
214 | public: | - | ||||||||||||||||||
215 | ExpressionChange(const QString &_name, | - | ||||||||||||||||||
216 | const QV4::CompiledData::Binding *_binding, | - | ||||||||||||||||||
217 | QQmlBinding::Identifier _id, | - | ||||||||||||||||||
218 | const QString& _expr, | - | ||||||||||||||||||
219 | const QUrl &_url, | - | ||||||||||||||||||
220 | int _line, | - | ||||||||||||||||||
221 | int _column) | - | ||||||||||||||||||
222 | : name(_name), binding(_binding), id(_id), expression(_expr), url(_url), line(_line), column(_column) {} executed 72 times by 11 tests: end of block Executed by:
| 72 | ||||||||||||||||||
223 | QString name; | - | ||||||||||||||||||
224 | const QV4::CompiledData::Binding *binding; | - | ||||||||||||||||||
225 | QQmlBinding::Identifier id; | - | ||||||||||||||||||
226 | QString expression; | - | ||||||||||||||||||
227 | QUrl url; | - | ||||||||||||||||||
228 | int line; | - | ||||||||||||||||||
229 | int column; | - | ||||||||||||||||||
230 | }; | - | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | QList<QPair<QString, QVariant> > properties; | - | ||||||||||||||||||
233 | QList<ExpressionChange> expressions; | - | ||||||||||||||||||
234 | QList<QQuickReplaceSignalHandler*> signalReplacements; | - | ||||||||||||||||||
235 | - | |||||||||||||||||||
236 | QQmlProperty property(const QString &); | - | ||||||||||||||||||
237 | }; | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | void QQuickPropertyChangesParser::verifyList(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding) | - | ||||||||||||||||||
240 | { | - | ||||||||||||||||||
241 | if (binding->type == QV4::CompiledData::Binding::Type_Object) {
| 2-492 | ||||||||||||||||||
242 | error(qmlUnit->objectAt(binding->value.objectIndex), QQuickPropertyChanges::tr("PropertyChanges does not support creating state-specific objects.")); | - | ||||||||||||||||||
243 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||
244 | } | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | if (binding->type == QV4::CompiledData::Binding::Type_GroupProperty
| 22-470 | ||||||||||||||||||
247 | || binding->type == QV4::CompiledData::Binding::Type_AttachedProperty) {
| 6-464 | ||||||||||||||||||
248 | const QV4::CompiledData::Object *subObj = qmlUnit->objectAt(binding->value.objectIndex); | - | ||||||||||||||||||
249 | const QV4::CompiledData::Binding *subBinding = subObj->bindingTable(); | - | ||||||||||||||||||
250 | for (quint32 i = 0; i < subObj->nBindings; ++i, ++subBinding) {
| 28-32 | ||||||||||||||||||
251 | verifyList(qmlUnit, subBinding); | - | ||||||||||||||||||
252 | } executed 32 times by 6 tests: end of block Executed by:
| 32 | ||||||||||||||||||
253 | } executed 28 times by 6 tests: end of block Executed by:
| 28 | ||||||||||||||||||
254 | } executed 492 times by 17 tests: end of block Executed by:
| 492 | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | void QQuickPropertyChangesPrivate::decode() | - | ||||||||||||||||||
257 | { | - | ||||||||||||||||||
258 | if (decoded)
| 102-454 | ||||||||||||||||||
259 | return; executed 102 times by 5 tests: return; Executed by:
| 102 | ||||||||||||||||||
260 | - | |||||||||||||||||||
261 | for (const QV4::CompiledData::Binding *binding : qAsConst(bindings)) | - | ||||||||||||||||||
262 | decodeBinding(QString(), compilationUnit->data, binding); executed 480 times by 17 tests: decodeBinding(QString(), compilationUnit->data, binding); Executed by:
| 480 | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | bindings.clear(); | - | ||||||||||||||||||
265 | - | |||||||||||||||||||
266 | decoded = true; | - | ||||||||||||||||||
267 | } executed 454 times by 17 tests: end of block Executed by:
| 454 | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | void QQuickPropertyChangesPrivate::decodeBinding(const QString &propertyPrefix, const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding) | - | ||||||||||||||||||
270 | { | - | ||||||||||||||||||
271 | Q_Q(QQuickPropertyChanges); | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | QString propertyName = propertyPrefix + qmlUnit->stringAt(binding->propertyNameIndex); | - | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | if (binding->type == QV4::CompiledData::Binding::Type_GroupProperty
| 18-554 | ||||||||||||||||||
276 | || binding->type == QV4::CompiledData::Binding::Type_AttachedProperty) {
| 72-482 | ||||||||||||||||||
277 | QString pre = propertyName + QLatin1Char('.'); | - | ||||||||||||||||||
278 | const QV4::CompiledData::Object *subObj = qmlUnit->objectAt(binding->value.objectIndex); | - | ||||||||||||||||||
279 | const QV4::CompiledData::Binding *subBinding = subObj->bindingTable(); | - | ||||||||||||||||||
280 | for (quint32 i = 0; i < subObj->nBindings; ++i, ++subBinding) {
| 90-92 | ||||||||||||||||||
281 | decodeBinding(pre, qmlUnit, subBinding); | - | ||||||||||||||||||
282 | } executed 92 times by 6 tests: end of block Executed by:
| 92 | ||||||||||||||||||
283 | return; executed 90 times by 6 tests: return; Executed by:
| 90 | ||||||||||||||||||
284 | } | - | ||||||||||||||||||
285 | - | |||||||||||||||||||
286 | if (propertyName.count() >= 3 &&
| 56-426 | ||||||||||||||||||
287 | propertyName.at(0) == QLatin1Char('o') &&
| 38-388 | ||||||||||||||||||
288 | propertyName.at(1) == QLatin1Char('n') &&
| 18-20 | ||||||||||||||||||
289 | propertyName.at(2).isUpper()) {
| 0-18 | ||||||||||||||||||
290 | QQmlProperty prop = property(propertyName); | - | ||||||||||||||||||
291 | if (prop.isSignalProperty()) {
| 0-18 | ||||||||||||||||||
292 | QQuickReplaceSignalHandler *handler = new QQuickReplaceSignalHandler; | - | ||||||||||||||||||
293 | handler->property = prop; | - | ||||||||||||||||||
294 | handler->expression.take(new QQmlBoundSignalExpression(object, QQmlPropertyPrivate::get(prop)->signalIndex(), | - | ||||||||||||||||||
295 | QQmlContextData::get(qmlContext(q)), object, compilationUnit->runtimeFunctions.at(binding->value.compiledScriptIndex))); | - | ||||||||||||||||||
296 | signalReplacements << handler; | - | ||||||||||||||||||
297 | return; executed 18 times by 1 test: return; Executed by:
| 18 | ||||||||||||||||||
298 | } | - | ||||||||||||||||||
299 | } never executed: end of block | 0 | ||||||||||||||||||
300 | - | |||||||||||||||||||
301 | if (binding->type == QV4::CompiledData::Binding::Type_Script || binding->isTranslationBinding()) {
| 4-400 | ||||||||||||||||||
302 | QUrl url = QUrl(); | - | ||||||||||||||||||
303 | int line = -1; | - | ||||||||||||||||||
304 | int column = -1; | - | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | QQmlData *ddata = QQmlData::get(q); | - | ||||||||||||||||||
307 | if (ddata && ddata->outerContext && !ddata->outerContext->url().isEmpty()) {
| 0-68 | ||||||||||||||||||
308 | url = ddata->outerContext->url(); | - | ||||||||||||||||||
309 | line = ddata->lineNumber; | - | ||||||||||||||||||
310 | column = ddata->columnNumber; | - | ||||||||||||||||||
311 | } executed 68 times by 11 tests: end of block Executed by:
| 68 | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | QString expression; | - | ||||||||||||||||||
314 | QQmlBinding::Identifier id = QQmlBinding::Invalid; | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | if (!binding->isTranslationBinding()) {
| 4-64 | ||||||||||||||||||
317 | expression = binding->valueAsString(qmlUnit); | - | ||||||||||||||||||
318 | id = binding->value.compiledScriptIndex; | - | ||||||||||||||||||
319 | } executed 64 times by 10 tests: end of block Executed by:
| 64 | ||||||||||||||||||
320 | expressions << ExpressionChange(propertyName, binding, id, expression, url, line, column); | - | ||||||||||||||||||
321 | return; executed 68 times by 11 tests: return; Executed by:
| 68 | ||||||||||||||||||
322 | } | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | QVariant var; | - | ||||||||||||||||||
325 | switch (binding->type) { | - | ||||||||||||||||||
326 | case QV4::CompiledData::Binding::Type_Script: never executed: case QV4::CompiledData::Binding::Type_Script: | 0 | ||||||||||||||||||
327 | case QV4::CompiledData::Binding::Type_Translation: never executed: case QV4::CompiledData::Binding::Type_Translation: | 0 | ||||||||||||||||||
328 | case QV4::CompiledData::Binding::Type_TranslationById: never executed: case QV4::CompiledData::Binding::Type_TranslationById: | 0 | ||||||||||||||||||
329 | Q_UNREACHABLE(); | - | ||||||||||||||||||
330 | case QV4::CompiledData::Binding::Type_String: code before this statement never executed: case QV4::CompiledData::Binding::Type_String: executed 218 times by 6 tests: case QV4::CompiledData::Binding::Type_String: Executed by:
| 0-218 | ||||||||||||||||||
331 | var = binding->valueAsString(qmlUnit); | - | ||||||||||||||||||
332 | break; executed 218 times by 6 tests: break; Executed by:
| 218 | ||||||||||||||||||
333 | case QV4::CompiledData::Binding::Type_Number: executed 100 times by 8 tests: case QV4::CompiledData::Binding::Type_Number: Executed by:
| 100 | ||||||||||||||||||
334 | var = binding->valueAsNumber(); | - | ||||||||||||||||||
335 | break; executed 100 times by 8 tests: break; Executed by:
| 100 | ||||||||||||||||||
336 | case QV4::CompiledData::Binding::Type_Boolean: executed 78 times by 3 tests: case QV4::CompiledData::Binding::Type_Boolean: Executed by:
| 78 | ||||||||||||||||||
337 | var = binding->valueAsBoolean(); | - | ||||||||||||||||||
338 | break; executed 78 times by 3 tests: break; Executed by:
| 78 | ||||||||||||||||||
339 | default: never executed: default: | 0 | ||||||||||||||||||
340 | break; never executed: break; | 0 | ||||||||||||||||||
341 | } | - | ||||||||||||||||||
342 | - | |||||||||||||||||||
343 | properties << qMakePair(propertyName, var); | - | ||||||||||||||||||
344 | } executed 396 times by 10 tests: end of block Executed by:
| 396 | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | void QQuickPropertyChangesParser::verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props) | - | ||||||||||||||||||
347 | { | - | ||||||||||||||||||
348 | for (int ii = 0; ii < props.count(); ++ii)
| 398-462 | ||||||||||||||||||
349 | verifyList(qmlUnit, props.at(ii)); executed 462 times by 17 tests: verifyList(qmlUnit, props.at(ii)); Executed by:
| 462 | ||||||||||||||||||
350 | } executed 398 times by 17 tests: end of block Executed by:
| 398 | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | void QQuickPropertyChangesParser::applyBindings(QObject *obj, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) | - | ||||||||||||||||||
353 | { | - | ||||||||||||||||||
354 | QQuickPropertyChangesPrivate *p = | - | ||||||||||||||||||
355 | static_cast<QQuickPropertyChangesPrivate *>(QObjectPrivate::get(obj)); | - | ||||||||||||||||||
356 | p->bindings = bindings; | - | ||||||||||||||||||
357 | p->compilationUnit = compilationUnit; | - | ||||||||||||||||||
358 | p->decoded = false; | - | ||||||||||||||||||
359 | } executed 454 times by 17 tests: end of block Executed by:
| 454 | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | QQuickPropertyChanges::QQuickPropertyChanges() | - | ||||||||||||||||||
362 | : QQuickStateOperation(*(new QQuickPropertyChangesPrivate)) | - | ||||||||||||||||||
363 | { | - | ||||||||||||||||||
364 | } executed 456 times by 17 tests: end of block Executed by:
| 456 | ||||||||||||||||||
365 | - | |||||||||||||||||||
366 | QQuickPropertyChanges::~QQuickPropertyChanges() | - | ||||||||||||||||||
367 | { | - | ||||||||||||||||||
368 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
369 | for(int ii = 0; ii < d->signalReplacements.count(); ++ii)
| 14-352 | ||||||||||||||||||
370 | delete d->signalReplacements.at(ii); executed 14 times by 1 test: delete d->signalReplacements.at(ii); Executed by:
| 14 | ||||||||||||||||||
371 | } executed 352 times by 17 tests: end of block Executed by:
| 352 | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | QObject *QQuickPropertyChanges::object() const | - | ||||||||||||||||||
374 | { | - | ||||||||||||||||||
375 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
376 | return d->object; executed 198 times by 13 tests: return d->object; Executed by:
| 198 | ||||||||||||||||||
377 | } | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | void QQuickPropertyChanges::setObject(QObject *o) | - | ||||||||||||||||||
380 | { | - | ||||||||||||||||||
381 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
382 | d->object = o; | - | ||||||||||||||||||
383 | } executed 458 times by 17 tests: end of block Executed by:
| 458 | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | /*! | - | ||||||||||||||||||
386 | \qmlproperty bool QtQuick::PropertyChanges::restoreEntryValues | - | ||||||||||||||||||
387 | - | |||||||||||||||||||
388 | This property holds whether the previous values should be restored when | - | ||||||||||||||||||
389 | leaving the state. | - | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | The default value is \c true. Setting this value to \c false creates a | - | ||||||||||||||||||
392 | temporary state that has permanent effects on property values. | - | ||||||||||||||||||
393 | */ | - | ||||||||||||||||||
394 | bool QQuickPropertyChanges::restoreEntryValues() const | - | ||||||||||||||||||
395 | { | - | ||||||||||||||||||
396 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
397 | return d->restore; executed 580 times by 17 tests: return d->restore; Executed by:
| 580 | ||||||||||||||||||
398 | } | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | void QQuickPropertyChanges::setRestoreEntryValues(bool v) | - | ||||||||||||||||||
401 | { | - | ||||||||||||||||||
402 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
403 | d->restore = v; | - | ||||||||||||||||||
404 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | QQmlProperty | - | ||||||||||||||||||
407 | QQuickPropertyChangesPrivate::property(const QString &property) | - | ||||||||||||||||||
408 | { | - | ||||||||||||||||||
409 | Q_Q(QQuickPropertyChanges); | - | ||||||||||||||||||
410 | QQmlContextData *context = nullptr; | - | ||||||||||||||||||
411 | if (QQmlData *ddata = QQmlData::get(q))
| 0-612 | ||||||||||||||||||
412 | context = ddata->outerContext; executed 612 times by 17 tests: context = ddata->outerContext; Executed by:
| 612 | ||||||||||||||||||
413 | QQmlProperty prop = QQmlPropertyPrivate::create(object, property, context); | - | ||||||||||||||||||
414 | if (!prop.isValid()) {
| 4-608 | ||||||||||||||||||
415 | qmlWarning(q) << QQuickPropertyChanges::tr("Cannot assign to non-existent property \"%1\"").arg(property); | - | ||||||||||||||||||
416 | return QQmlProperty(); executed 4 times by 1 test: return QQmlProperty(); Executed by:
| 4 | ||||||||||||||||||
417 | } else if (!(prop.type() & QQmlProperty::SignalProperty) && !prop.isWritable()) {
| 2-590 | ||||||||||||||||||
418 | qmlWarning(q) << QQuickPropertyChanges::tr("Cannot assign to read-only property \"%1\"").arg(property); | - | ||||||||||||||||||
419 | return QQmlProperty(); executed 2 times by 1 test: return QQmlProperty(); Executed by:
| 2 | ||||||||||||||||||
420 | } | - | ||||||||||||||||||
421 | return prop; executed 606 times by 17 tests: return prop; Executed by:
| 606 | ||||||||||||||||||
422 | } | - | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | QQuickPropertyChanges::ActionList QQuickPropertyChanges::actions() | - | ||||||||||||||||||
425 | { | - | ||||||||||||||||||
426 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | d->decode(); | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | ActionList list; | - | ||||||||||||||||||
431 | - | |||||||||||||||||||
432 | for (int ii = 0; ii < d->properties.count(); ++ii) {
| 486-556 | ||||||||||||||||||
433 | QQmlProperty prop = d->property(d->properties.at(ii).first); | - | ||||||||||||||||||
434 | - | |||||||||||||||||||
435 | QQuickStateAction a(d->object, prop, d->properties.at(ii).first, | - | ||||||||||||||||||
436 | d->properties.at(ii).second); | - | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | if (a.property.isValid()) {
| 6-480 | ||||||||||||||||||
439 | a.restore = restoreEntryValues(); | - | ||||||||||||||||||
440 | list << a; | - | ||||||||||||||||||
441 | } executed 480 times by 10 tests: end of block Executed by:
| 480 | ||||||||||||||||||
442 | } executed 486 times by 10 tests: end of block Executed by:
| 486 | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | for (int ii = 0; ii < d->signalReplacements.count(); ++ii) {
| 26-556 | ||||||||||||||||||
445 | QQuickReplaceSignalHandler *handler = d->signalReplacements.at(ii); | - | ||||||||||||||||||
446 | - | |||||||||||||||||||
447 | if (handler->property.isValid()) {
| 0-26 | ||||||||||||||||||
448 | QQuickStateAction a; | - | ||||||||||||||||||
449 | a.event = handler; | - | ||||||||||||||||||
450 | list << a; | - | ||||||||||||||||||
451 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||
452 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | for (int ii = 0; ii < d->expressions.count(); ++ii) {
| 92-556 | ||||||||||||||||||
455 | - | |||||||||||||||||||
456 | QQuickPropertyChangesPrivate::ExpressionChange e = d->expressions.at(ii); | - | ||||||||||||||||||
457 | const QString &property = e.name; | - | ||||||||||||||||||
458 | QQmlProperty prop = d->property(property); | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | if (prop.isValid()) {
| 0-92 | ||||||||||||||||||
461 | QQuickStateAction a; | - | ||||||||||||||||||
462 | a.restore = restoreEntryValues(); | - | ||||||||||||||||||
463 | a.property = prop; | - | ||||||||||||||||||
464 | a.fromValue = a.property.read(); | - | ||||||||||||||||||
465 | a.specifiedObject = d->object; | - | ||||||||||||||||||
466 | a.specifiedProperty = property; | - | ||||||||||||||||||
467 | - | |||||||||||||||||||
468 | QQmlContextData *context = QQmlContextData::get(qmlContext(this)); | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | QQmlBinding *newBinding = nullptr; | - | ||||||||||||||||||
471 | if (e.binding && e.binding->isTranslationBinding()) {
| 4-88 | ||||||||||||||||||
472 | newBinding = QQmlBinding::createTranslationBinding(d->compilationUnit, e.binding, object(), context); | - | ||||||||||||||||||
473 | } else if (e.id != QQmlBinding::Invalid) { executed 4 times by 2 tests: end of block Executed by:
| 4-84 | ||||||||||||||||||
474 | QV4::Scope scope(qmlEngine(this)->handle()); | - | ||||||||||||||||||
475 | QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(scope.engine->rootContext(), context, object())); | - | ||||||||||||||||||
476 | newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(prop)->core, | - | ||||||||||||||||||
477 | d->compilationUnit->runtimeFunctions.at(e.id), object(), context, qmlContext); | - | ||||||||||||||||||
478 | } executed 84 times by 10 tests: end of block Executed by:
| 84 | ||||||||||||||||||
479 | if (!newBinding)
| 4-88 | ||||||||||||||||||
480 | newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(prop)->core, executed 4 times by 1 test: newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(prop)->core, e.expression, object(), context, e.url.toString(), e.line); Executed by:
| 4 | ||||||||||||||||||
481 | e.expression, object(), context, e.url.toString(), e.line); executed 4 times by 1 test: newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(prop)->core, e.expression, object(), context, e.url.toString(), e.line); Executed by:
| 4 | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | if (d->isExplicit) {
| 4-88 | ||||||||||||||||||
484 | // in this case, we don't want to assign a binding, per se, | - | ||||||||||||||||||
485 | // so we evaluate the expression and assign the result. | - | ||||||||||||||||||
486 | // XXX TODO: add a static QQmlJavaScriptExpression::evaluate(QString) | - | ||||||||||||||||||
487 | // so that we can avoid creating then destroying the binding in this case. | - | ||||||||||||||||||
488 | a.toValue = newBinding->evaluate(); | - | ||||||||||||||||||
489 | delete newBinding; | - | ||||||||||||||||||
490 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
491 | newBinding->setTarget(prop); | - | ||||||||||||||||||
492 | a.toBinding = newBinding; | - | ||||||||||||||||||
493 | a.deletableToBinding = true; | - | ||||||||||||||||||
494 | } executed 88 times by 11 tests: end of block Executed by:
| 88 | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | list << a; | - | ||||||||||||||||||
497 | } executed 92 times by 11 tests: end of block Executed by:
| 92 | ||||||||||||||||||
498 | } executed 92 times by 11 tests: end of block Executed by:
| 92 | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | return list; executed 556 times by 17 tests: return list; Executed by:
| 556 | ||||||||||||||||||
501 | } | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | /*! | - | ||||||||||||||||||
504 | \qmlproperty bool QtQuick::PropertyChanges::explicit | - | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | If explicit is set to true, any potential bindings will be interpreted as | - | ||||||||||||||||||
507 | once-off assignments that occur when the state is entered. | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | In the following example, the addition of explicit prevents \c myItem.width from | - | ||||||||||||||||||
510 | being bound to \c parent.width. Instead, it is assigned the value of \c parent.width | - | ||||||||||||||||||
511 | at the time of the state change. | - | ||||||||||||||||||
512 | \qml | - | ||||||||||||||||||
513 | PropertyChanges { | - | ||||||||||||||||||
514 | target: myItem | - | ||||||||||||||||||
515 | explicit: true | - | ||||||||||||||||||
516 | width: parent.width | - | ||||||||||||||||||
517 | } | - | ||||||||||||||||||
518 | \endqml | - | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | By default, explicit is false. | - | ||||||||||||||||||
521 | */ | - | ||||||||||||||||||
522 | bool QQuickPropertyChanges::isExplicit() const | - | ||||||||||||||||||
523 | { | - | ||||||||||||||||||
524 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
525 | return d->isExplicit; executed 6 times by 2 tests: return d->isExplicit; Executed by:
| 6 | ||||||||||||||||||
526 | } | - | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | void QQuickPropertyChanges::setIsExplicit(bool e) | - | ||||||||||||||||||
529 | { | - | ||||||||||||||||||
530 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
531 | d->isExplicit = e; | - | ||||||||||||||||||
532 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | bool QQuickPropertyChanges::containsValue(const QString &name) const | - | ||||||||||||||||||
535 | { | - | ||||||||||||||||||
536 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
537 | typedef QPair<QString, QVariant> PropertyEntry; | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | QListIterator<PropertyEntry> propertyIterator(d->properties); | - | ||||||||||||||||||
540 | while (propertyIterator.hasNext()) {
| 6-16 | ||||||||||||||||||
541 | const PropertyEntry &entry = propertyIterator.next(); | - | ||||||||||||||||||
542 | if (entry.first == name) {
| 4-12 | ||||||||||||||||||
543 | return true; executed 4 times by 1 test: return true; Executed by:
| 4 | ||||||||||||||||||
544 | } | - | ||||||||||||||||||
545 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
546 | - | |||||||||||||||||||
547 | return false; executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||||||||
548 | } | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | bool QQuickPropertyChanges::containsExpression(const QString &name) const | - | ||||||||||||||||||
551 | { | - | ||||||||||||||||||
552 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
553 | typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry; | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | QListIterator<ExpressionEntry> expressionIterator(d->expressions); | - | ||||||||||||||||||
556 | while (expressionIterator.hasNext()) {
| 4 | ||||||||||||||||||
557 | const ExpressionEntry &entry = expressionIterator.next(); | - | ||||||||||||||||||
558 | if (entry.name == name) {
| 0-4 | ||||||||||||||||||
559 | return true; executed 4 times by 1 test: return true; Executed by:
| 4 | ||||||||||||||||||
560 | } | - | ||||||||||||||||||
561 | } never executed: end of block | 0 | ||||||||||||||||||
562 | - | |||||||||||||||||||
563 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||||||||
564 | } | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | bool QQuickPropertyChanges::containsProperty(const QString &name) const | - | ||||||||||||||||||
567 | { | - | ||||||||||||||||||
568 | return containsValue(name) || containsExpression(name); executed 2 times by 1 test: return containsValue(name) || containsExpression(name); Executed by:
| 2 | ||||||||||||||||||
569 | } | - | ||||||||||||||||||
570 | - | |||||||||||||||||||
571 | void QQuickPropertyChanges::changeValue(const QString &name, const QVariant &value) | - | ||||||||||||||||||
572 | { | - | ||||||||||||||||||
573 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
574 | typedef QPair<QString, QVariant> PropertyEntry; | - | ||||||||||||||||||
575 | typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry; | - | ||||||||||||||||||
576 | - | |||||||||||||||||||
577 | QMutableListIterator<ExpressionEntry> expressionIterator(d->expressions); | - | ||||||||||||||||||
578 | while (expressionIterator.hasNext()) {
| 4-12 | ||||||||||||||||||
579 | const ExpressionEntry &entry = expressionIterator.next(); | - | ||||||||||||||||||
580 | if (entry.name == name) {
| 0-4 | ||||||||||||||||||
581 | expressionIterator.remove(); | - | ||||||||||||||||||
582 | if (state() && state()->isStateActive()) {
| 0-4 | ||||||||||||||||||
583 | QQmlPropertyPrivate::removeBinding(d->property(name)); | - | ||||||||||||||||||
584 | d->property(name).write(value); | - | ||||||||||||||||||
585 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
586 | - | |||||||||||||||||||
587 | d->properties.append(PropertyEntry(name, value)); | - | ||||||||||||||||||
588 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
589 | } | - | ||||||||||||||||||
590 | } never executed: end of block | 0 | ||||||||||||||||||
591 | - | |||||||||||||||||||
592 | QMutableListIterator<PropertyEntry> propertyIterator(d->properties); | - | ||||||||||||||||||
593 | while (propertyIterator.hasNext()) {
| 4-12 | ||||||||||||||||||
594 | PropertyEntry &entry = propertyIterator.next(); | - | ||||||||||||||||||
595 | if (entry.first == name) {
| 4-8 | ||||||||||||||||||
596 | entry.second = value; | - | ||||||||||||||||||
597 | if (state() && state()->isStateActive())
| 0-8 | ||||||||||||||||||
598 | d->property(name).write(value); executed 2 times by 1 test: d->property(name).write(value); Executed by:
| 2 | ||||||||||||||||||
599 | return; executed 8 times by 3 tests: return; Executed by:
| 8 | ||||||||||||||||||
600 | } | - | ||||||||||||||||||
601 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
602 | - | |||||||||||||||||||
603 | QQuickStateAction action; | - | ||||||||||||||||||
604 | action.restore = restoreEntryValues(); | - | ||||||||||||||||||
605 | action.property = d->property(name); | - | ||||||||||||||||||
606 | action.fromValue = action.property.read(); | - | ||||||||||||||||||
607 | action.specifiedObject = object(); | - | ||||||||||||||||||
608 | action.specifiedProperty = name; | - | ||||||||||||||||||
609 | action.toValue = value; | - | ||||||||||||||||||
610 | - | |||||||||||||||||||
611 | propertyIterator.insert(PropertyEntry(name, value)); | - | ||||||||||||||||||
612 | if (state() && state()->isStateActive()) {
| 0-4 | ||||||||||||||||||
613 | state()->addEntryToRevertList(action); | - | ||||||||||||||||||
614 | QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(action.property); | - | ||||||||||||||||||
615 | if (oldBinding)
| 0-2 | ||||||||||||||||||
616 | oldBinding->setEnabled(false, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); executed 2 times by 1 test: oldBinding->setEnabled(false, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); Executed by:
| 2 | ||||||||||||||||||
617 | d->property(name).write(value); | - | ||||||||||||||||||
618 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
619 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | void QQuickPropertyChanges::changeExpression(const QString &name, const QString &expression) | - | ||||||||||||||||||
622 | { | - | ||||||||||||||||||
623 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
624 | typedef QPair<QString, QVariant> PropertyEntry; | - | ||||||||||||||||||
625 | typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry; | - | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | bool hadValue = false; | - | ||||||||||||||||||
628 | - | |||||||||||||||||||
629 | QMutableListIterator<PropertyEntry> propertyIterator(d->properties); | - | ||||||||||||||||||
630 | while (propertyIterator.hasNext()) {
| 0-8 | ||||||||||||||||||
631 | PropertyEntry &entry = propertyIterator.next(); | - | ||||||||||||||||||
632 | if (entry.first == name) {
| 4 | ||||||||||||||||||
633 | propertyIterator.remove(); | - | ||||||||||||||||||
634 | hadValue = true; | - | ||||||||||||||||||
635 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
636 | } | - | ||||||||||||||||||
637 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
638 | - | |||||||||||||||||||
639 | QMutableListIterator<ExpressionEntry> expressionIterator(d->expressions); | - | ||||||||||||||||||
640 | while (expressionIterator.hasNext()) {
| 0-4 | ||||||||||||||||||
641 | ExpressionEntry &entry = expressionIterator.next(); | - | ||||||||||||||||||
642 | if (entry.name == name) {
| 0 | ||||||||||||||||||
643 | entry.expression = expression; | - | ||||||||||||||||||
644 | if (state() && state()->isStateActive()) {
| 0 | ||||||||||||||||||
645 | auto prop = d->property(name); | - | ||||||||||||||||||
646 | QQmlBinding *newBinding = QQmlBinding::create( | - | ||||||||||||||||||
647 | &QQmlPropertyPrivate::get(prop)->core, expression, object(), | - | ||||||||||||||||||
648 | QQmlContextData::get(qmlContext(this))); | - | ||||||||||||||||||
649 | newBinding->setTarget(prop); | - | ||||||||||||||||||
650 | QQmlPropertyPrivate::setBinding(newBinding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); | - | ||||||||||||||||||
651 | } never executed: end of block | 0 | ||||||||||||||||||
652 | return; never executed: return; | 0 | ||||||||||||||||||
653 | } | - | ||||||||||||||||||
654 | } never executed: end of block | 0 | ||||||||||||||||||
655 | - | |||||||||||||||||||
656 | // adding a new expression. | - | ||||||||||||||||||
657 | expressionIterator.insert(ExpressionEntry(name, nullptr, QQmlBinding::Invalid, expression, QUrl(), -1, -1)); | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | if (state() && state()->isStateActive()) {
| 0-4 | ||||||||||||||||||
660 | if (hadValue) {
| 0-2 | ||||||||||||||||||
661 | QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(d->property(name)); | - | ||||||||||||||||||
662 | if (oldBinding) {
| 0-2 | ||||||||||||||||||
663 | oldBinding->setEnabled(false, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); | - | ||||||||||||||||||
664 | state()->changeBindingInRevertList(object(), name, oldBinding); | - | ||||||||||||||||||
665 | } never executed: end of block | 0 | ||||||||||||||||||
666 | - | |||||||||||||||||||
667 | auto prop = d->property(name); | - | ||||||||||||||||||
668 | QQmlBinding *newBinding = QQmlBinding::create( | - | ||||||||||||||||||
669 | &QQmlPropertyPrivate::get(prop)->core, expression, object(), | - | ||||||||||||||||||
670 | QQmlContextData::get(qmlContext(this))); | - | ||||||||||||||||||
671 | newBinding->setTarget(prop); | - | ||||||||||||||||||
672 | QQmlPropertyPrivate::setBinding(newBinding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); | - | ||||||||||||||||||
673 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
674 | QQuickStateAction action; | - | ||||||||||||||||||
675 | action.restore = restoreEntryValues(); | - | ||||||||||||||||||
676 | action.property = d->property(name); | - | ||||||||||||||||||
677 | action.fromValue = action.property.read(); | - | ||||||||||||||||||
678 | action.specifiedObject = object(); | - | ||||||||||||||||||
679 | action.specifiedProperty = name; | - | ||||||||||||||||||
680 | - | |||||||||||||||||||
681 | QQmlBinding *newBinding = QQmlBinding::create( | - | ||||||||||||||||||
682 | &QQmlPropertyPrivate::get(action.property)->core, expression, | - | ||||||||||||||||||
683 | object(), QQmlContextData::get(qmlContext(this))); | - | ||||||||||||||||||
684 | if (d->isExplicit) {
| 0 | ||||||||||||||||||
685 | // don't assign the binding, merely evaluate the expression. | - | ||||||||||||||||||
686 | // XXX TODO: add a static QQmlJavaScriptExpression::evaluate(QString) | - | ||||||||||||||||||
687 | // so that we can avoid creating then destroying the binding in this case. | - | ||||||||||||||||||
688 | action.toValue = newBinding->evaluate(); | - | ||||||||||||||||||
689 | delete newBinding; | - | ||||||||||||||||||
690 | } else { never executed: end of block | 0 | ||||||||||||||||||
691 | newBinding->setTarget(action.property); | - | ||||||||||||||||||
692 | action.toBinding = newBinding; | - | ||||||||||||||||||
693 | action.deletableToBinding = true; | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | state()->addEntryToRevertList(action); | - | ||||||||||||||||||
696 | QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(action.property); | - | ||||||||||||||||||
697 | if (oldBinding)
| 0 | ||||||||||||||||||
698 | oldBinding->setEnabled(false, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); never executed: oldBinding->setEnabled(false, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); | 0 | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | QQmlPropertyPrivate::setBinding(newBinding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding | QQmlPropertyData::BypassInterceptor); | - | ||||||||||||||||||
701 | } never executed: end of block | 0 | ||||||||||||||||||
702 | } | - | ||||||||||||||||||
703 | } | - | ||||||||||||||||||
704 | // what about the signal handler? | - | ||||||||||||||||||
705 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
706 | - | |||||||||||||||||||
707 | QVariant QQuickPropertyChanges::property(const QString &name) const | - | ||||||||||||||||||
708 | { | - | ||||||||||||||||||
709 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
710 | typedef QPair<QString, QVariant> PropertyEntry; | - | ||||||||||||||||||
711 | typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry; | - | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | QListIterator<PropertyEntry> propertyIterator(d->properties); | - | ||||||||||||||||||
714 | while (propertyIterator.hasNext()) {
| 0 | ||||||||||||||||||
715 | const PropertyEntry &entry = propertyIterator.next(); | - | ||||||||||||||||||
716 | if (entry.first == name) {
| 0 | ||||||||||||||||||
717 | return entry.second; never executed: return entry.second; | 0 | ||||||||||||||||||
718 | } | - | ||||||||||||||||||
719 | } never executed: end of block | 0 | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | QListIterator<ExpressionEntry> expressionIterator(d->expressions); | - | ||||||||||||||||||
722 | while (expressionIterator.hasNext()) {
| 0 | ||||||||||||||||||
723 | const ExpressionEntry &entry = expressionIterator.next(); | - | ||||||||||||||||||
724 | if (entry.name == name) {
| 0 | ||||||||||||||||||
725 | return QVariant(entry.expression); never executed: return QVariant(entry.expression); | 0 | ||||||||||||||||||
726 | } | - | ||||||||||||||||||
727 | } never executed: end of block | 0 | ||||||||||||||||||
728 | - | |||||||||||||||||||
729 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||
730 | } | - | ||||||||||||||||||
731 | - | |||||||||||||||||||
732 | void QQuickPropertyChanges::removeProperty(const QString &name) | - | ||||||||||||||||||
733 | { | - | ||||||||||||||||||
734 | Q_D(QQuickPropertyChanges); | - | ||||||||||||||||||
735 | typedef QPair<QString, QVariant> PropertyEntry; | - | ||||||||||||||||||
736 | typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry; | - | ||||||||||||||||||
737 | - | |||||||||||||||||||
738 | QMutableListIterator<ExpressionEntry> expressionIterator(d->expressions); | - | ||||||||||||||||||
739 | while (expressionIterator.hasNext()) {
| 4-6 | ||||||||||||||||||
740 | const ExpressionEntry &entry = expressionIterator.next(); | - | ||||||||||||||||||
741 | if (entry.name == name) {
| 0-4 | ||||||||||||||||||
742 | expressionIterator.remove(); | - | ||||||||||||||||||
743 | state()->removeEntryFromRevertList(object(), name); | - | ||||||||||||||||||
744 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
745 | } | - | ||||||||||||||||||
746 | } never executed: end of block | 0 | ||||||||||||||||||
747 | - | |||||||||||||||||||
748 | QMutableListIterator<PropertyEntry> propertyIterator(d->properties); | - | ||||||||||||||||||
749 | while (propertyIterator.hasNext()) {
| 0-8 | ||||||||||||||||||
750 | const PropertyEntry &entry = propertyIterator.next(); | - | ||||||||||||||||||
751 | if (entry.first == name) {
| 2-6 | ||||||||||||||||||
752 | propertyIterator.remove(); | - | ||||||||||||||||||
753 | state()->removeEntryFromRevertList(object(), name); | - | ||||||||||||||||||
754 | return; executed 6 times by 3 tests: return; Executed by:
| 6 | ||||||||||||||||||
755 | } | - | ||||||||||||||||||
756 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
757 | } never executed: end of block | 0 | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | QVariant QQuickPropertyChanges::value(const QString &name) const | - | ||||||||||||||||||
760 | { | - | ||||||||||||||||||
761 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
762 | typedef QPair<QString, QVariant> PropertyEntry; | - | ||||||||||||||||||
763 | - | |||||||||||||||||||
764 | QListIterator<PropertyEntry> propertyIterator(d->properties); | - | ||||||||||||||||||
765 | while (propertyIterator.hasNext()) {
| 6-24 | ||||||||||||||||||
766 | const PropertyEntry &entry = propertyIterator.next(); | - | ||||||||||||||||||
767 | if (entry.first == name) {
| 8-16 | ||||||||||||||||||
768 | return entry.second; executed 8 times by 1 test: return entry.second; Executed by:
| 8 | ||||||||||||||||||
769 | } | - | ||||||||||||||||||
770 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
771 | - | |||||||||||||||||||
772 | return QVariant(); executed 6 times by 1 test: return QVariant(); Executed by:
| 6 | ||||||||||||||||||
773 | } | - | ||||||||||||||||||
774 | - | |||||||||||||||||||
775 | QString QQuickPropertyChanges::expression(const QString &name) const | - | ||||||||||||||||||
776 | { | - | ||||||||||||||||||
777 | Q_D(const QQuickPropertyChanges); | - | ||||||||||||||||||
778 | typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry; | - | ||||||||||||||||||
779 | - | |||||||||||||||||||
780 | QListIterator<ExpressionEntry> expressionIterator(d->expressions); | - | ||||||||||||||||||
781 | while (expressionIterator.hasNext()) {
| 0 | ||||||||||||||||||
782 | const ExpressionEntry &entry = expressionIterator.next(); | - | ||||||||||||||||||
783 | if (entry.name == name) {
| 0 | ||||||||||||||||||
784 | return entry.expression; never executed: return entry.expression; | 0 | ||||||||||||||||||
785 | } | - | ||||||||||||||||||
786 | } never executed: end of block | 0 | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
789 | } | - | ||||||||||||||||||
790 | - | |||||||||||||||||||
791 | void QQuickPropertyChanges::detachFromState() | - | ||||||||||||||||||
792 | { | - | ||||||||||||||||||
793 | if (state())
| 0 | ||||||||||||||||||
794 | state()->removeAllEntriesFromRevertList(object()); never executed: state()->removeAllEntriesFromRevertList(object()); | 0 | ||||||||||||||||||
795 | } never executed: end of block | 0 | ||||||||||||||||||
796 | - | |||||||||||||||||||
797 | void QQuickPropertyChanges::attachToState() | - | ||||||||||||||||||
798 | { | - | ||||||||||||||||||
799 | if (state())
| 0-2 | ||||||||||||||||||
800 | state()->addEntriesToRevertList(actions()); executed 2 times by 1 test: state()->addEntriesToRevertList(actions()); Executed by:
| 2 | ||||||||||||||||||
801 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
802 | - | |||||||||||||||||||
803 | QT_END_NAMESPACE | - | ||||||||||||||||||
804 | - | |||||||||||||||||||
805 | #include "moc_qquickpropertychanges_p.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |