| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlabstractbinding.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 "qqmlabstractbinding_p.h" | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #include <QtQml/qqmlinfo.h> | - | ||||||||||||
| 43 | #include <private/qqmlbinding_p.h> | - | ||||||||||||
| 44 | #include <private/qqmlvaluetypeproxybinding_p.h> | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | QQmlAbstractBinding::QQmlAbstractBinding() | - | ||||||||||||
| 49 | : m_targetIndex(-1) | - | ||||||||||||
| 50 | { | - | ||||||||||||
| 51 | Q_ASSERT(!isAddedToObject()); | - | ||||||||||||
| 52 | } executed 555488 times by 121 tests: end of blockExecuted by:
| 555488 | ||||||||||||
| 53 | - | |||||||||||||
| 54 | QQmlAbstractBinding::~QQmlAbstractBinding() | - | ||||||||||||
| 55 | { | - | ||||||||||||
| 56 | Q_ASSERT(!ref); | - | ||||||||||||
| 57 | Q_ASSERT(!isAddedToObject()); | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | if (m_nextBinding.data() && !m_nextBinding->ref.deref())
| 4-395072 | ||||||||||||
| 60 | delete m_nextBinding.data(); executed 119762 times by 58 tests: delete m_nextBinding.data();Executed by:
| 119762 | ||||||||||||
| 61 | } executed 514838 times by 120 tests: end of blockExecuted by:
| 514838 | ||||||||||||
| 62 | - | |||||||||||||
| 63 | /*! | - | ||||||||||||
| 64 | Add this binding to \a object. | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | This transfers ownership of the binding to the object, marks the object's property as | - | ||||||||||||
| 67 | being bound. | - | ||||||||||||
| 68 | - | |||||||||||||
| 69 | However, it does not enable the binding itself or call update() on it. | - | ||||||||||||
| 70 | */ | - | ||||||||||||
| 71 | void QQmlAbstractBinding::addToObject() | - | ||||||||||||
| 72 | { | - | ||||||||||||
| 73 | Q_ASSERT(!nextBinding()); | - | ||||||||||||
| 74 | Q_ASSERT(isAddedToObject() == false); | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | QObject *obj = targetObject(); | - | ||||||||||||
| 77 | Q_ASSERT(obj); | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | QQmlData *data = QQmlData::get(obj, true); | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | int coreIndex = targetPropertyIndex().coreIndex(); | - | ||||||||||||
| 82 | if (targetPropertyIndex().hasValueTypeIndex()) {
| 2342-553250 | ||||||||||||
| 83 | // Value type | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | // Find the value type proxy (if there is one) | - | ||||||||||||
| 86 | QQmlValueTypeProxyBinding *proxy = nullptr; | - | ||||||||||||
| 87 | if (data->hasBindingBit(coreIndex)) {
| 978-1364 | ||||||||||||
| 88 | QQmlAbstractBinding *b = data->bindings; | - | ||||||||||||
| 89 | while (b && (b->targetPropertyIndex().coreIndex() != coreIndex ||
| 0-982 | ||||||||||||
| 90 | b->targetPropertyIndex().hasValueTypeIndex()))
| 0-978 | ||||||||||||
| 91 | b = b->nextBinding(); executed 4 times by 1 test: b = b->nextBinding();Executed by:
| 4 | ||||||||||||
| 92 | Q_ASSERT(b && b->isValueTypeProxy()); | - | ||||||||||||
| 93 | proxy = static_cast<QQmlValueTypeProxyBinding *>(b); | - | ||||||||||||
| 94 | } executed 978 times by 7 tests: end of blockExecuted by:
| 978 | ||||||||||||
| 95 | - | |||||||||||||
| 96 | if (!proxy) {
| 978-1364 | ||||||||||||
| 97 | proxy = new QQmlValueTypeProxyBinding(obj, QQmlPropertyIndex(coreIndex)); | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | Q_ASSERT(proxy->targetPropertyIndex().coreIndex() == coreIndex); | - | ||||||||||||
| 100 | Q_ASSERT(!proxy->targetPropertyIndex().hasValueTypeIndex()); | - | ||||||||||||
| 101 | Q_ASSERT(proxy->targetObject() == obj); | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | proxy->addToObject(); | - | ||||||||||||
| 104 | } executed 1364 times by 12 tests: end of blockExecuted by:
| 1364 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | setNextBinding(proxy->m_bindings.data()); | - | ||||||||||||
| 107 | proxy->m_bindings = this; | - | ||||||||||||
| 108 | - | |||||||||||||
| 109 | } else { executed 2342 times by 12 tests: end of blockExecuted by:
| 2342 | ||||||||||||
| 110 | setNextBinding(data->bindings); | - | ||||||||||||
| 111 | if (data->bindings) {
| 124353-428897 | ||||||||||||
| 112 | data->bindings->ref.deref(); | - | ||||||||||||
| 113 | Q_ASSERT(data->bindings->ref.refCount > 0); | - | ||||||||||||
| 114 | } executed 124353 times by 67 tests: end of blockExecuted by:
| 124353 | ||||||||||||
| 115 | data->bindings = this; | - | ||||||||||||
| 116 | ref.ref(); | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | data->setBindingBit(obj, coreIndex); | - | ||||||||||||
| 119 | } executed 553250 times by 121 tests: end of blockExecuted by:
| 553250 | ||||||||||||
| 120 | - | |||||||||||||
| 121 | setAddedToObject(true); | - | ||||||||||||
| 122 | } executed 555592 times by 121 tests: end of blockExecuted by:
| 555592 | ||||||||||||
| 123 | - | |||||||||||||
| 124 | /*! | - | ||||||||||||
| 125 | Remove the binding from the object. | - | ||||||||||||
| 126 | */ | - | ||||||||||||
| 127 | void QQmlAbstractBinding::removeFromObject() | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | if (!isAddedToObject())
| 6-8379 | ||||||||||||
| 130 | return; executed 6 times by 1 test: return;Executed by:
| 6 | ||||||||||||
| 131 | - | |||||||||||||
| 132 | setAddedToObject(false); | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | QObject *obj = targetObject(); | - | ||||||||||||
| 135 | QQmlData *data = QQmlData::get(obj, false); | - | ||||||||||||
| 136 | Q_ASSERT(data); | - | ||||||||||||
| 137 | - | |||||||||||||
| 138 | QQmlAbstractBinding::Ptr next; | - | ||||||||||||
| 139 | next = nextBinding(); | - | ||||||||||||
| 140 | setNextBinding(nullptr); | - | ||||||||||||
| 141 | - | |||||||||||||
| 142 | int coreIndex = targetPropertyIndex().coreIndex(); | - | ||||||||||||
| 143 | if (targetPropertyIndex().hasValueTypeIndex()) {
| 158-8221 | ||||||||||||
| 144 | - | |||||||||||||
| 145 | // Find the value type binding | - | ||||||||||||
| 146 | QQmlAbstractBinding *vtbinding = data->bindings; | - | ||||||||||||
| 147 | while (vtbinding && (vtbinding->targetPropertyIndex().coreIndex() != coreIndex ||
| 0-158 | ||||||||||||
| 148 | vtbinding->targetPropertyIndex().hasValueTypeIndex())) {
| 0-158 | ||||||||||||
| 149 | vtbinding = vtbinding->nextBinding(); | - | ||||||||||||
| 150 | Q_ASSERT(vtbinding); | - | ||||||||||||
| 151 | } never executed: end of block | 0 | ||||||||||||
| 152 | Q_ASSERT(vtbinding->isValueTypeProxy()); | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | QQmlValueTypeProxyBinding *vtproxybinding = | - | ||||||||||||
| 155 | static_cast<QQmlValueTypeProxyBinding *>(vtbinding); | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | QQmlAbstractBinding *binding = vtproxybinding->m_bindings.data(); | - | ||||||||||||
| 158 | if (binding == this) {
| 0-158 | ||||||||||||
| 159 | vtproxybinding->m_bindings = next; | - | ||||||||||||
| 160 | } else { executed 158 times by 4 tests: end of blockExecuted by:
| 158 | ||||||||||||
| 161 | while (binding->nextBinding() != this) {
| 0 | ||||||||||||
| 162 | binding = binding->nextBinding(); | - | ||||||||||||
| 163 | Q_ASSERT(binding); | - | ||||||||||||
| 164 | } never executed: end of block | 0 | ||||||||||||
| 165 | binding->setNextBinding(next.data()); | - | ||||||||||||
| 166 | } never executed: end of block | 0 | ||||||||||||
| 167 | - | |||||||||||||
| 168 | // Value type - we don't remove the proxy from the object. It will sit their happily | - | ||||||||||||
| 169 | // doing nothing until it is removed by a write, a binding change or it is reused | - | ||||||||||||
| 170 | // to hold more sub-bindings. | - | ||||||||||||
| 171 | return; executed 158 times by 4 tests: return;Executed by:
| 158 | ||||||||||||
| 172 | } | - | ||||||||||||
| 173 | - | |||||||||||||
| 174 | if (data->bindings == this) {
| 919-7302 | ||||||||||||
| 175 | if (next.data())
| 2898-4404 | ||||||||||||
| 176 | next->ref.ref(); executed 4404 times by 23 tests: next->ref.ref();Executed by:
| 4404 | ||||||||||||
| 177 | data->bindings = next.data(); | - | ||||||||||||
| 178 | if (!ref.deref())
| 0-7302 | ||||||||||||
| 179 | delete this; never executed: delete this; | 0 | ||||||||||||
| 180 | } else { executed 7302 times by 66 tests: end of blockExecuted by:
| 7302 | ||||||||||||
| 181 | QQmlAbstractBinding *binding = data->bindings; | - | ||||||||||||
| 182 | while (binding->nextBinding() != this) {
| 919-1127 | ||||||||||||
| 183 | binding = binding->nextBinding(); | - | ||||||||||||
| 184 | Q_ASSERT(binding); | - | ||||||||||||
| 185 | } executed 1127 times by 16 tests: end of blockExecuted by:
| 1127 | ||||||||||||
| 186 | binding->setNextBinding(next.data()); | - | ||||||||||||
| 187 | } executed 919 times by 25 tests: end of blockExecuted by:
| 919 | ||||||||||||
| 188 | - | |||||||||||||
| 189 | data->clearBindingBit(coreIndex); | - | ||||||||||||
| 190 | } executed 8221 times by 70 tests: end of blockExecuted by:
| 8221 | ||||||||||||
| 191 | - | |||||||||||||
| 192 | void QQmlAbstractBinding::printBindingLoopError(QQmlProperty &prop) | - | ||||||||||||
| 193 | { | - | ||||||||||||
| 194 | qmlWarning(prop.object()) << QString(QLatin1String("Binding loop detected for property \"%1\"")).arg(prop.name()); | - | ||||||||||||
| 195 | } executed 20 times by 3 tests: end of blockExecuted by:
| 20 | ||||||||||||
| 196 | - | |||||||||||||
| 197 | QString QQmlAbstractBinding::expression() const | - | ||||||||||||
| 198 | { | - | ||||||||||||
| 199 | return QLatin1String("<Unknown>"); never executed: return QLatin1String("<Unknown>"); | 0 | ||||||||||||
| 200 | } | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | bool QQmlAbstractBinding::isValueTypeProxy() const | - | ||||||||||||
| 203 | { | - | ||||||||||||
| 204 | return false; executed 553400 times by 121 tests: return false;Executed by:
| 553400 | ||||||||||||
| 205 | } | - | ||||||||||||
| 206 | - | |||||||||||||
| 207 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |