Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/util/qqmlchangeset.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 "qqmlchangeset_p.h" | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | - | |||||||||||||||||||
45 | /*! | - | ||||||||||||||||||
46 | \class QQmlChangeSet | - | ||||||||||||||||||
47 | \brief The QQmlChangeSet class stores an ordered list of notifications about | - | ||||||||||||||||||
48 | changes to a linear data set. | - | ||||||||||||||||||
49 | \internal | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | QQmlChangeSet can be used to record a series of notifications about items in an indexed list | - | ||||||||||||||||||
52 | being inserted, removed, moved, and changed. Notifications in the set are re-ordered so that | - | ||||||||||||||||||
53 | all notifications of a single type are grouped together and sorted in order of ascending index, | - | ||||||||||||||||||
54 | with remove notifications preceding all others, followed by insert notification, and then | - | ||||||||||||||||||
55 | change notifications. | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | Moves in a change set are represented by a remove notification paired with an insert | - | ||||||||||||||||||
58 | notification by way of a shared unique moveId. Re-ordering may result in one or both of the | - | ||||||||||||||||||
59 | paired notifications being divided, when this happens the offset member of the notification | - | ||||||||||||||||||
60 | will indicate the relative offset of the divided notification from the beginning of the | - | ||||||||||||||||||
61 | original. | - | ||||||||||||||||||
62 | */ | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | /*! | - | ||||||||||||||||||
65 | Constructs an empty change set. | - | ||||||||||||||||||
66 | */ | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | QQmlChangeSet::QQmlChangeSet() | - | ||||||||||||||||||
69 | : m_difference(0) | - | ||||||||||||||||||
70 | { | - | ||||||||||||||||||
71 | } executed 26258 times by 29 tests: end of block Executed by:
| 26258 | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | /*! | - | ||||||||||||||||||
74 | Constructs a copy of a \a changeSet. | - | ||||||||||||||||||
75 | */ | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | QQmlChangeSet::QQmlChangeSet(const QQmlChangeSet &changeSet) | - | ||||||||||||||||||
78 | : m_removes(changeSet.m_removes) | - | ||||||||||||||||||
79 | , m_inserts(changeSet.m_inserts) | - | ||||||||||||||||||
80 | , m_changes(changeSet.m_changes) | - | ||||||||||||||||||
81 | , m_difference(changeSet.m_difference) | - | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | } executed 110 times by 3 tests: end of block Executed by:
| 110 | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | /*! | - | ||||||||||||||||||
86 | Destroys a change set. | - | ||||||||||||||||||
87 | */ | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | QQmlChangeSet::~QQmlChangeSet() | - | ||||||||||||||||||
90 | { | - | ||||||||||||||||||
91 | } | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | /*! | - | ||||||||||||||||||
94 | Assigns the value of a \a changeSet to another. | - | ||||||||||||||||||
95 | */ | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | QQmlChangeSet &QQmlChangeSet::operator =(const QQmlChangeSet &changeSet) | - | ||||||||||||||||||
98 | { | - | ||||||||||||||||||
99 | m_removes = changeSet.m_removes; | - | ||||||||||||||||||
100 | m_inserts = changeSet.m_inserts; | - | ||||||||||||||||||
101 | m_changes = changeSet.m_changes; | - | ||||||||||||||||||
102 | m_difference = changeSet.m_difference; | - | ||||||||||||||||||
103 | return *this; executed 28 times by 2 tests: return *this; Executed by:
| 28 | ||||||||||||||||||
104 | } | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | /*! | - | ||||||||||||||||||
107 | Appends a notification that \a count items were inserted at \a index. | - | ||||||||||||||||||
108 | */ | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | void QQmlChangeSet::insert(int index, int count) | - | ||||||||||||||||||
111 | { | - | ||||||||||||||||||
112 | insert(QVector<Change>() << Change(index, count)); | - | ||||||||||||||||||
113 | } executed 810 times by 7 tests: end of block Executed by:
| 810 | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | /*! | - | ||||||||||||||||||
116 | Appends a notification that \a count items were removed at \a index. | - | ||||||||||||||||||
117 | */ | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | void QQmlChangeSet::remove(int index, int count) | - | ||||||||||||||||||
120 | { | - | ||||||||||||||||||
121 | QVector<Change> removes; | - | ||||||||||||||||||
122 | removes.append(Change(index, count)); | - | ||||||||||||||||||
123 | remove(&removes, nullptr); | - | ||||||||||||||||||
124 | } executed 566 times by 7 tests: end of block Executed by:
| 566 | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | /*! | - | ||||||||||||||||||
127 | Appends a notification that \a count items were moved \a from one index \a to another. | - | ||||||||||||||||||
128 | - | |||||||||||||||||||
129 | The \a moveId must be unique across the lifetime of the change set and any related | - | ||||||||||||||||||
130 | change sets. | - | ||||||||||||||||||
131 | */ | - | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | void QQmlChangeSet::move(int from, int to, int count, int moveId) | - | ||||||||||||||||||
134 | { | - | ||||||||||||||||||
135 | QVector<Change> removes; | - | ||||||||||||||||||
136 | removes.append(Change(from, count, moveId)); | - | ||||||||||||||||||
137 | QVector<Change> inserts; | - | ||||||||||||||||||
138 | inserts.append(Change(to, count, moveId)); | - | ||||||||||||||||||
139 | remove(&removes, &inserts); | - | ||||||||||||||||||
140 | insert(inserts); | - | ||||||||||||||||||
141 | } executed 794 times by 5 tests: end of block Executed by:
| 794 | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | /*! | - | ||||||||||||||||||
144 | Appends a notification that \a count items were changed at \a index. | - | ||||||||||||||||||
145 | */ | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | void QQmlChangeSet::change(int index, int count) | - | ||||||||||||||||||
148 | { | - | ||||||||||||||||||
149 | QVector<Change> changes; | - | ||||||||||||||||||
150 | changes.append(Change(index, count)); | - | ||||||||||||||||||
151 | change(changes); | - | ||||||||||||||||||
152 | } executed 66 times by 1 test: end of block Executed by:
| 66 | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | /*! | - | ||||||||||||||||||
155 | Applies the changes in a \a changeSet to another. | - | ||||||||||||||||||
156 | */ | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | void QQmlChangeSet::apply(const QQmlChangeSet &changeSet) | - | ||||||||||||||||||
159 | { | - | ||||||||||||||||||
160 | QVector<Change> r = changeSet.m_removes; | - | ||||||||||||||||||
161 | QVector<Change> i = changeSet.m_inserts; | - | ||||||||||||||||||
162 | QVector<Change> c = changeSet.m_changes; | - | ||||||||||||||||||
163 | remove(&r, &i); | - | ||||||||||||||||||
164 | insert(i); | - | ||||||||||||||||||
165 | change(c); | - | ||||||||||||||||||
166 | } executed 16970 times by 12 tests: end of block Executed by:
| 16970 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | /*! | - | ||||||||||||||||||
169 | Applies a list of \a removes to a change set. | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | If a remove contains a moveId then any intersecting insert in the set will replace the | - | ||||||||||||||||||
172 | corresponding intersection in the optional \a inserts list. | - | ||||||||||||||||||
173 | */ | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | void QQmlChangeSet::remove(const QVector<Change> &removes, QVector<Change> *inserts) | - | ||||||||||||||||||
176 | { | - | ||||||||||||||||||
177 | QVector<Change> r = removes; | - | ||||||||||||||||||
178 | remove(&r, inserts); | - | ||||||||||||||||||
179 | } executed 5944 times by 13 tests: end of block Executed by:
| 5944 | ||||||||||||||||||
180 | - | |||||||||||||||||||
181 | void QQmlChangeSet::remove(QVector<Change> *removes, QVector<Change> *inserts) | - | ||||||||||||||||||
182 | { | - | ||||||||||||||||||
183 | int removeCount = 0; | - | ||||||||||||||||||
184 | int insertCount = 0; | - | ||||||||||||||||||
185 | QVector<Change>::iterator insert = m_inserts.begin(); | - | ||||||||||||||||||
186 | QVector<Change>::iterator change = m_changes.begin(); | - | ||||||||||||||||||
187 | QVector<Change>::iterator rit = removes->begin(); | - | ||||||||||||||||||
188 | for (; rit != removes->end(); ++rit) {
| 9708-32876 | ||||||||||||||||||
189 | int index = rit->index + removeCount; | - | ||||||||||||||||||
190 | int count = rit->count; | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | // Decrement the accumulated remove count from the indexes of any changes prior to the | - | ||||||||||||||||||
193 | // current remove. | - | ||||||||||||||||||
194 | for (; change != m_changes.end() && change->end() < rit->index; ++change)
| 0-9700 | ||||||||||||||||||
195 | change->index -= removeCount; never executed: change->index -= removeCount; | 0 | ||||||||||||||||||
196 | // Remove any portion of a change notification that intersects the current remove. | - | ||||||||||||||||||
197 | for (; change != m_changes.end() && change->index > rit->end(); ++change) {
| 2-9702 | ||||||||||||||||||
198 | change->count -= qMin(change->end(), rit->end()) - qMax(change->index, rit->index); | - | ||||||||||||||||||
199 | if (change->count == 0) {
| 0-2 | ||||||||||||||||||
200 | change = m_changes.erase(change); | - | ||||||||||||||||||
201 | } else if (rit->index < change->index) { never executed: end of block
| 0-2 | ||||||||||||||||||
202 | change->index = rit->index; | - | ||||||||||||||||||
203 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
204 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | // Decrement the accumulated remove count from the indexes of any inserts prior to the | - | ||||||||||||||||||
207 | // current remove. | - | ||||||||||||||||||
208 | for (; insert != m_inserts.end() && insert->end() <= index; ++insert) {
| 958-8750 | ||||||||||||||||||
209 | insertCount += insert->count; | - | ||||||||||||||||||
210 | insert->index -= removeCount; | - | ||||||||||||||||||
211 | } executed 1386 times by 2 tests: end of block Executed by:
| 1386 | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | rit->index -= insertCount; | - | ||||||||||||||||||
214 | - | |||||||||||||||||||
215 | // Remove any portion of a insert notification that intersects the current remove. | - | ||||||||||||||||||
216 | while (insert != m_inserts.end() && insert->index < index + count) {
| 270-9026 | ||||||||||||||||||
217 | int offset = index - insert->index; | - | ||||||||||||||||||
218 | const int difference = qMin(insert->end(), index + count) - qMax(insert->index, index); | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | // If part of the remove or insert that precedes the intersection has a moveId create | - | ||||||||||||||||||
221 | // a new delta for that portion and subtract the size of that delta from the current | - | ||||||||||||||||||
222 | // one. | - | ||||||||||||||||||
223 | if (offset < 0 && rit->moveId != -1) {
| 118-620 | ||||||||||||||||||
224 | rit = removes->insert(rit, Change( | - | ||||||||||||||||||
225 | rit->index, -offset, rit->moveId, rit->offset)); | - | ||||||||||||||||||
226 | ++rit; | - | ||||||||||||||||||
227 | rit->count -= -offset; | - | ||||||||||||||||||
228 | rit->offset += -offset; | - | ||||||||||||||||||
229 | index += -offset; | - | ||||||||||||||||||
230 | count -= -offset; | - | ||||||||||||||||||
231 | removeCount += -offset; | - | ||||||||||||||||||
232 | offset = 0; | - | ||||||||||||||||||
233 | } else if (offset > 0 && insert->moveId != -1) { executed 138 times by 1 test: end of block Executed by:
| 122-478 | ||||||||||||||||||
234 | insert = m_inserts.insert(insert, Change( | - | ||||||||||||||||||
235 | insert->index - removeCount, offset, insert->moveId, insert->offset)); | - | ||||||||||||||||||
236 | ++insert; | - | ||||||||||||||||||
237 | insert->index += offset; | - | ||||||||||||||||||
238 | insert->count -= offset; | - | ||||||||||||||||||
239 | insert->offset += offset; | - | ||||||||||||||||||
240 | rit->index -= offset; | - | ||||||||||||||||||
241 | insertCount += offset; | - | ||||||||||||||||||
242 | } executed 138 times by 4 tests: end of block Executed by:
| 138 | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | // If the current remove has a move id, find any inserts with the same move id and | - | ||||||||||||||||||
245 | // replace the corresponding sections with the insert removed from the change set. | - | ||||||||||||||||||
246 | if (rit->moveId != -1 && difference > 0 && inserts) {
| 0-548 | ||||||||||||||||||
247 | for (QVector<Change>::iterator iit = inserts->begin(); iit != inserts->end(); ++iit) {
| 548-1120 | ||||||||||||||||||
248 | if (iit->moveId != rit->moveId
| 518-602 | ||||||||||||||||||
249 | || rit->offset > iit->offset + iit->count
| 42-560 | ||||||||||||||||||
250 | || iit->offset > rit->offset + difference) {
| 6-554 | ||||||||||||||||||
251 | continue; executed 566 times by 4 tests: continue; Executed by:
| 566 | ||||||||||||||||||
252 | } | - | ||||||||||||||||||
253 | // If the intersecting insert starts before the replacement one create | - | ||||||||||||||||||
254 | // a new insert for the portion prior to the replacement insert. | - | ||||||||||||||||||
255 | const int overlapOffset = rit->offset - iit->offset; | - | ||||||||||||||||||
256 | if (overlapOffset > 0) {
| 140-414 | ||||||||||||||||||
257 | iit = inserts->insert(iit, Change( | - | ||||||||||||||||||
258 | iit->index, overlapOffset, iit->moveId, iit->offset)); | - | ||||||||||||||||||
259 | ++iit; | - | ||||||||||||||||||
260 | iit->index += overlapOffset; | - | ||||||||||||||||||
261 | iit->count -= overlapOffset; | - | ||||||||||||||||||
262 | iit->offset += overlapOffset; | - | ||||||||||||||||||
263 | } executed 140 times by 1 test: end of block Executed by:
| 140 | ||||||||||||||||||
264 | if (iit->offset >= rit->offset
| 0-554 | ||||||||||||||||||
265 | && iit->offset + iit->count <= rit->offset + difference) {
| 204-350 | ||||||||||||||||||
266 | // If the replacement insert completely encapsulates the existing | - | ||||||||||||||||||
267 | // one just change the moveId. | - | ||||||||||||||||||
268 | iit->moveId = insert->moveId; | - | ||||||||||||||||||
269 | iit->offset = insert->offset + qMax(0, -overlapOffset); | - | ||||||||||||||||||
270 | } else { executed 350 times by 5 tests: end of block Executed by:
| 350 | ||||||||||||||||||
271 | // Create a new insertion before the intersecting one with the number of intersecting | - | ||||||||||||||||||
272 | // items and remove that number from that insert. | - | ||||||||||||||||||
273 | const int count | - | ||||||||||||||||||
274 | = qMin(iit->offset + iit->count, rit->offset + difference) | - | ||||||||||||||||||
275 | - qMax(iit->offset, rit->offset); | - | ||||||||||||||||||
276 | iit = inserts->insert(iit, Change( | - | ||||||||||||||||||
277 | iit->index, | - | ||||||||||||||||||
278 | count, | - | ||||||||||||||||||
279 | insert->moveId, | - | ||||||||||||||||||
280 | insert->offset + qMax(0, -overlapOffset))); | - | ||||||||||||||||||
281 | ++iit; | - | ||||||||||||||||||
282 | iit->index += count; | - | ||||||||||||||||||
283 | iit->count -= count; | - | ||||||||||||||||||
284 | iit->offset += count; | - | ||||||||||||||||||
285 | } executed 204 times by 3 tests: end of block Executed by:
| 204 | ||||||||||||||||||
286 | } | - | ||||||||||||||||||
287 | } executed 548 times by 5 tests: end of block Executed by:
| 548 | ||||||||||||||||||
288 | - | |||||||||||||||||||
289 | // Subtract the number of intersecting items from the current remove and insert. | - | ||||||||||||||||||
290 | insert->count -= difference; | - | ||||||||||||||||||
291 | insert->offset += difference; | - | ||||||||||||||||||
292 | rit->count -= difference; | - | ||||||||||||||||||
293 | rit->offset += difference; | - | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | index += difference; | - | ||||||||||||||||||
296 | count -= difference; | - | ||||||||||||||||||
297 | removeCount += difference; | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | if (insert->count == 0) {
| 412-464 | ||||||||||||||||||
300 | insert = m_inserts.erase(insert); | - | ||||||||||||||||||
301 | } else if (rit->count == -offset || rit->count == 0) { executed 412 times by 5 tests: end of block Executed by:
| 52-412 | ||||||||||||||||||
302 | insert->index += difference; | - | ||||||||||||||||||
303 | break; executed 412 times by 3 tests: break; Executed by:
| 412 | ||||||||||||||||||
304 | } else { | - | ||||||||||||||||||
305 | insert->index -= removeCount - difference; | - | ||||||||||||||||||
306 | rit->index -= insert->count; | - | ||||||||||||||||||
307 | insertCount += insert->count; | - | ||||||||||||||||||
308 | ++insert; | - | ||||||||||||||||||
309 | } executed 52 times by 3 tests: end of block Executed by:
| 52 | ||||||||||||||||||
310 | } | - | ||||||||||||||||||
311 | removeCount += rit->count; | - | ||||||||||||||||||
312 | } executed 9708 times by 14 tests: end of block Executed by:
| 9708 | ||||||||||||||||||
313 | for (; insert != m_inserts.end(); ++insert)
| 5730-32876 | ||||||||||||||||||
314 | insert->index -= removeCount; executed 5730 times by 5 tests: insert->index -= removeCount; Executed by:
| 5730 | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | removeCount = 0; | - | ||||||||||||||||||
317 | QVector<Change>::iterator remove = m_removes.begin(); | - | ||||||||||||||||||
318 | for (rit = removes->begin(); rit != removes->end(); ++rit) {
| 9506-32876 | ||||||||||||||||||
319 | if (rit->count == 0)
| 620-8886 | ||||||||||||||||||
320 | continue; executed 620 times by 7 tests: continue; Executed by:
| 620 | ||||||||||||||||||
321 | // Accumulate consecutive removes into a single delta before attempting to apply. | - | ||||||||||||||||||
322 | for (QVector<Change>::iterator next = rit + 1; next != removes->end()
| 816-8410 | ||||||||||||||||||
323 | && next->index == rit->index
| 54-762 | ||||||||||||||||||
324 | && next->moveId == -1
| 346-416 | ||||||||||||||||||
325 | && rit->moveId == -1; ++next) {
| 76-340 | ||||||||||||||||||
326 | next->count += rit->count; | - | ||||||||||||||||||
327 | rit = next; | - | ||||||||||||||||||
328 | } executed 340 times by 5 tests: end of block Executed by:
| 340 | ||||||||||||||||||
329 | int index = rit->index + removeCount; | - | ||||||||||||||||||
330 | // Decrement the accumulated remove count from the indexes of any inserts prior to the | - | ||||||||||||||||||
331 | // current remove. | - | ||||||||||||||||||
332 | for (; remove != m_removes.end() && index > remove->index; ++remove)
| 525-7614 | ||||||||||||||||||
333 | remove->index -= removeCount; executed 525 times by 4 tests: remove->index -= removeCount; Executed by:
| 525 | ||||||||||||||||||
334 | while (remove != m_removes.end() && index + rit->count >= remove->index) {
| 422-8464 | ||||||||||||||||||
335 | int count = 0; | - | ||||||||||||||||||
336 | const int offset = remove->index - index; | - | ||||||||||||||||||
337 | QVector<Change>::iterator rend = remove; | - | ||||||||||||||||||
338 | for (; rend != m_removes.end()
| 654-1141 | ||||||||||||||||||
339 | && rit->moveId == -1
| 228-913 | ||||||||||||||||||
340 | && rend->moveId == -1
| 124-789 | ||||||||||||||||||
341 | && index + rit->count >= rend->index; ++rend) {
| 55-734 | ||||||||||||||||||
342 | count += rend->count; | - | ||||||||||||||||||
343 | } executed 734 times by 4 tests: end of block Executed by:
| 734 | ||||||||||||||||||
344 | if (remove != rend) {
| 346-715 | ||||||||||||||||||
345 | // Accumulate all existing non-move removes that are encapsulated by or immediately | - | ||||||||||||||||||
346 | // follow the current remove into it. | - | ||||||||||||||||||
347 | int difference = 0; | - | ||||||||||||||||||
348 | if (rend == m_removes.end()) {
| 61-654 | ||||||||||||||||||
349 | difference = rit->count; | - | ||||||||||||||||||
350 | } else if (rit->index + rit->count < rend->index - removeCount) { executed 654 times by 4 tests: end of block Executed by:
| 4-654 | ||||||||||||||||||
351 | difference = rit->count; | - | ||||||||||||||||||
352 | } else if (rend->moveId != -1) { executed 57 times by 3 tests: end of block Executed by:
| 0-57 | ||||||||||||||||||
353 | difference = rend->index - removeCount - rit->index; | - | ||||||||||||||||||
354 | index += difference; | - | ||||||||||||||||||
355 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
356 | count += difference; | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | rit->count -= difference; | - | ||||||||||||||||||
359 | removeCount += difference; | - | ||||||||||||||||||
360 | remove->index = rit->index; | - | ||||||||||||||||||
361 | remove->count = count; | - | ||||||||||||||||||
362 | remove = m_removes.erase(++remove, rend); | - | ||||||||||||||||||
363 | } else { executed 715 times by 4 tests: end of block Executed by:
| 715 | ||||||||||||||||||
364 | // Insert a remove for the portion of the unmergable current remove prior to the | - | ||||||||||||||||||
365 | // point of intersection. | - | ||||||||||||||||||
366 | if (offset > 0) {
| 140-206 | ||||||||||||||||||
367 | remove = m_removes.insert(remove, Change( | - | ||||||||||||||||||
368 | rit->index, offset, rit->moveId, rit->offset)); | - | ||||||||||||||||||
369 | ++remove; | - | ||||||||||||||||||
370 | rit->count -= offset; | - | ||||||||||||||||||
371 | rit->offset += offset; | - | ||||||||||||||||||
372 | removeCount += offset; | - | ||||||||||||||||||
373 | index += offset; | - | ||||||||||||||||||
374 | } executed 206 times by 2 tests: end of block Executed by:
| 206 | ||||||||||||||||||
375 | remove->index = rit->index; | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | ++remove; | - | ||||||||||||||||||
378 | } executed 346 times by 4 tests: end of block Executed by:
| 346 | ||||||||||||||||||
379 | } | - | ||||||||||||||||||
380 | - | |||||||||||||||||||
381 | if (rit->count > 0) {
| 773-8113 | ||||||||||||||||||
382 | remove = m_removes.insert(remove, *rit); | - | ||||||||||||||||||
383 | ++remove; | - | ||||||||||||||||||
384 | } executed 8113 times by 14 tests: end of block Executed by:
| 8113 | ||||||||||||||||||
385 | removeCount += rit->count; | - | ||||||||||||||||||
386 | } executed 8886 times by 14 tests: end of block Executed by:
| 8886 | ||||||||||||||||||
387 | for (; remove != m_removes.end(); ++remove)
| 2931-32876 | ||||||||||||||||||
388 | remove->index -= removeCount; executed 2931 times by 4 tests: remove->index -= removeCount; Executed by:
| 2931 | ||||||||||||||||||
389 | m_difference -= removeCount; | - | ||||||||||||||||||
390 | } executed 32876 times by 29 tests: end of block Executed by:
| 32876 | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | /*! | - | ||||||||||||||||||
393 | Applies a list of \a inserts to a change set. | - | ||||||||||||||||||
394 | */ | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | void QQmlChangeSet::insert(const QVector<Change> &inserts) | - | ||||||||||||||||||
397 | { | - | ||||||||||||||||||
398 | int insertCount = 0; | - | ||||||||||||||||||
399 | QVector<Change>::iterator insert = m_inserts.begin(); | - | ||||||||||||||||||
400 | QVector<Change>::iterator change = m_changes.begin(); | - | ||||||||||||||||||
401 | for (QVector<Change>::const_iterator iit = inserts.begin(); iit != inserts.end(); ++iit) {
| 29464-60200 | ||||||||||||||||||
402 | if (iit->count == 0)
| 1504-27960 | ||||||||||||||||||
403 | continue; executed 1504 times by 11 tests: continue; Executed by:
| 1504 | ||||||||||||||||||
404 | int index = iit->index - insertCount; | - | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | Change current = *iit; | - | ||||||||||||||||||
407 | // Accumulate consecutive inserts into a single delta before attempting to insert. | - | ||||||||||||||||||
408 | for (QVector<Change>::const_iterator next = iit + 1; next != inserts.end()
| 724-27268 | ||||||||||||||||||
409 | && next->index == iit->index + iit->count
| 104-620 | ||||||||||||||||||
410 | && next->moveId == -1
| 172-448 | ||||||||||||||||||
411 | && iit->moveId == -1; ++next) {
| 32-140 | ||||||||||||||||||
412 | current.count += next->count; | - | ||||||||||||||||||
413 | iit = next; | - | ||||||||||||||||||
414 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | // Increment the index of any changes before the current insert by the accumlated insert | - | ||||||||||||||||||
417 | // count. | - | ||||||||||||||||||
418 | for (; change != m_changes.end() && change->index >= index; ++change)
| 2-27958 | ||||||||||||||||||
419 | change->index += insertCount; executed 12 times by 1 test: change->index += insertCount; Executed by:
| 12 | ||||||||||||||||||
420 | // If the current insert index is in the middle of a change split it in two at that | - | ||||||||||||||||||
421 | // point and increment the index of the latter half. | - | ||||||||||||||||||
422 | if (change != m_changes.end() && change->index < index + iit->count) {
| 0-27958 | ||||||||||||||||||
423 | int offset = index - change->index; | - | ||||||||||||||||||
424 | change = m_changes.insert(change, Change(change->index + insertCount, offset)); | - | ||||||||||||||||||
425 | ++change; | - | ||||||||||||||||||
426 | change->index += iit->count + offset; | - | ||||||||||||||||||
427 | change->count -= offset; | - | ||||||||||||||||||
428 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | // Increment the index of any inserts before the current insert by the accumlated insert | - | ||||||||||||||||||
431 | // count. | - | ||||||||||||||||||
432 | for (; insert != m_inserts.end() && index > insert->index + insert->count; ++insert)
| 1325-22901 | ||||||||||||||||||
433 | insert->index += insertCount; executed 1325 times by 4 tests: insert->index += insertCount; Executed by:
| 1325 | ||||||||||||||||||
434 | if (insert == m_inserts.end()) {
| 5059-22901 | ||||||||||||||||||
435 | insert = m_inserts.insert(insert, current); | - | ||||||||||||||||||
436 | ++insert; | - | ||||||||||||||||||
437 | } else { executed 22901 times by 27 tests: end of block Executed by:
| 22901 | ||||||||||||||||||
438 | const int offset = index - insert->index; | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | if (offset < 0) {
| 425-4634 | ||||||||||||||||||
441 | // If the current insert is before an existing insert and not adjacent just insert | - | ||||||||||||||||||
442 | // it into the list. | - | ||||||||||||||||||
443 | insert = m_inserts.insert(insert, current); | - | ||||||||||||||||||
444 | ++insert; | - | ||||||||||||||||||
445 | } else if (iit->moveId == -1 && insert->moveId == -1) { executed 425 times by 4 tests: end of block Executed by:
| 154-4480 | ||||||||||||||||||
446 | // If neither the current nor existing insert has a moveId add the current insert | - | ||||||||||||||||||
447 | // to the existing one. | - | ||||||||||||||||||
448 | if (offset < insert->count) {
| 256-4064 | ||||||||||||||||||
449 | insert->index -= current.count; | - | ||||||||||||||||||
450 | insert->count += current.count; | - | ||||||||||||||||||
451 | } else { executed 256 times by 4 tests: end of block Executed by:
| 256 | ||||||||||||||||||
452 | insert->index += insertCount; | - | ||||||||||||||||||
453 | insert->count += current.count; | - | ||||||||||||||||||
454 | ++insert; | - | ||||||||||||||||||
455 | } executed 4064 times by 5 tests: end of block Executed by:
| 4064 | ||||||||||||||||||
456 | } else if (offset < insert->count) {
| 26-288 | ||||||||||||||||||
457 | // If either insert has a moveId then split the existing insert and insert the | - | ||||||||||||||||||
458 | // current one in the middle. | - | ||||||||||||||||||
459 | if (offset > 0) {
| 108-180 | ||||||||||||||||||
460 | insert = m_inserts.insert(insert, Change( | - | ||||||||||||||||||
461 | insert->index + insertCount, offset, insert->moveId, insert->offset)); | - | ||||||||||||||||||
462 | ++insert; | - | ||||||||||||||||||
463 | insert->index += offset; | - | ||||||||||||||||||
464 | insert->count -= offset; | - | ||||||||||||||||||
465 | insert->offset += offset; | - | ||||||||||||||||||
466 | } executed 180 times by 1 test: end of block Executed by:
| 180 | ||||||||||||||||||
467 | insert = m_inserts.insert(insert, current); | - | ||||||||||||||||||
468 | ++insert; | - | ||||||||||||||||||
469 | } else { executed 288 times by 3 tests: end of block Executed by:
| 288 | ||||||||||||||||||
470 | insert->index += insertCount; | - | ||||||||||||||||||
471 | ++insert; | - | ||||||||||||||||||
472 | insert = m_inserts.insert(insert, current); | - | ||||||||||||||||||
473 | ++insert; | - | ||||||||||||||||||
474 | } executed 26 times by 3 tests: end of block Executed by:
| 26 | ||||||||||||||||||
475 | } | - | ||||||||||||||||||
476 | insertCount += current.count; | - | ||||||||||||||||||
477 | } executed 27960 times by 27 tests: end of block Executed by:
| 27960 | ||||||||||||||||||
478 | for (; insert != m_inserts.end(); ++insert)
| 1947-60200 | ||||||||||||||||||
479 | insert->index += insertCount; executed 1947 times by 5 tests: insert->index += insertCount; Executed by:
| 1947 | ||||||||||||||||||
480 | m_difference += insertCount; | - | ||||||||||||||||||
481 | } executed 60200 times by 29 tests: end of block Executed by:
| 60200 | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | /*! | - | ||||||||||||||||||
484 | Applies a combined list of \a removes and \a inserts to a change set. This is equivalent | - | ||||||||||||||||||
485 | calling \l remove() followed by \l insert() with the same lists. | - | ||||||||||||||||||
486 | */ | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | void QQmlChangeSet::move(const QVector<Change> &removes, const QVector<Change> &inserts) | - | ||||||||||||||||||
489 | { | - | ||||||||||||||||||
490 | QVector<Change> r = removes; | - | ||||||||||||||||||
491 | QVector<Change> i = inserts; | - | ||||||||||||||||||
492 | remove(&r, &i); | - | ||||||||||||||||||
493 | insert(i); | - | ||||||||||||||||||
494 | } executed 8602 times by 27 tests: end of block Executed by:
| 8602 | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | /*! | - | ||||||||||||||||||
497 | Applies a list of \a changes to a change set. | - | ||||||||||||||||||
498 | */ | - | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | void QQmlChangeSet::change(const QVector<Change> &changes) | - | ||||||||||||||||||
501 | { | - | ||||||||||||||||||
502 | QVector<Change> c = changes; | - | ||||||||||||||||||
503 | change(&c); | - | ||||||||||||||||||
504 | } executed 17888 times by 12 tests: end of block Executed by:
| 17888 | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | void QQmlChangeSet::change(QVector<Change> *changes) | - | ||||||||||||||||||
507 | { | - | ||||||||||||||||||
508 | QVector<Change>::iterator insert = m_inserts.begin(); | - | ||||||||||||||||||
509 | QVector<Change>::iterator change = m_changes.begin(); | - | ||||||||||||||||||
510 | for (QVector<Change>::iterator cit = changes->begin(); cit != changes->end(); ++cit) {
| 916-17888 | ||||||||||||||||||
511 | for (; insert != m_inserts.end() && insert->end() < cit->index; ++insert) {} executed 10 times by 1 test: end of block Executed by:
| 10-896 | ||||||||||||||||||
512 | for (; insert != m_inserts.end() && insert->index < cit->end(); ++insert) {
| 4-912 | ||||||||||||||||||
513 | const int offset = insert->index - cit->index; | - | ||||||||||||||||||
514 | const int count = cit->count + cit->index - insert->index - insert->count; | - | ||||||||||||||||||
515 | if (offset == 0) {
| 4-12 | ||||||||||||||||||
516 | cit->index = insert->index + insert->count; | - | ||||||||||||||||||
517 | cit->count = count; | - | ||||||||||||||||||
518 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
519 | cit = changes->insert(++cit, Change(insert->index + insert->count, count)); | - | ||||||||||||||||||
520 | --cit; | - | ||||||||||||||||||
521 | cit->count = offset; | - | ||||||||||||||||||
522 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
523 | } | - | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | for (; change != m_changes.end() && change->index + change->count < cit->index; ++change) {} executed 4 times by 1 test: end of block Executed by:
| 4-700 | ||||||||||||||||||
526 | if (change == m_changes.end() || change->index > cit->index + cit->count) {
| 2-700 | ||||||||||||||||||
527 | if (cit->count > 0) {
| 18-684 | ||||||||||||||||||
528 | change = m_changes.insert(change, *cit); | - | ||||||||||||||||||
529 | ++change; | - | ||||||||||||||||||
530 | } executed 684 times by 3 tests: end of block Executed by:
| 684 | ||||||||||||||||||
531 | } else { executed 702 times by 3 tests: end of block Executed by:
| 702 | ||||||||||||||||||
532 | if (cit->index < change->index) {
| 8-206 | ||||||||||||||||||
533 | change->count += change->index - cit->index; | - | ||||||||||||||||||
534 | change->index = cit->index; | - | ||||||||||||||||||
535 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | if (cit->index + cit->count > change->index + change->count) {
| 46-168 | ||||||||||||||||||
538 | change->count = cit->index + cit->count - change->index; | - | ||||||||||||||||||
539 | QVector<Change>::iterator cbegin = change; | - | ||||||||||||||||||
540 | QVector<Change>::iterator cend = ++cbegin; | - | ||||||||||||||||||
541 | for (; cend != m_changes.end() && cend->index <= change->index + change->count; ++cend) {
| 0-46 | ||||||||||||||||||
542 | if (cend->index + cend->count > change->index + change->count)
| 0-2 | ||||||||||||||||||
543 | change->count = cend->index + cend->count - change->index; executed 2 times by 1 test: change->count = cend->index + cend->count - change->index; Executed by:
| 2 | ||||||||||||||||||
544 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
545 | if (cbegin != cend) {
| 2-44 | ||||||||||||||||||
546 | change = m_changes.erase(cbegin, cend); | - | ||||||||||||||||||
547 | --change; | - | ||||||||||||||||||
548 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
549 | } executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
550 | } executed 214 times by 2 tests: end of block Executed by:
| 214 | ||||||||||||||||||
551 | } | - | ||||||||||||||||||
552 | } executed 17888 times by 12 tests: end of block Executed by:
| 17888 | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | /*! | - | ||||||||||||||||||
555 | Prints the contents of a change \a set to the \a debug stream. | - | ||||||||||||||||||
556 | */ | - | ||||||||||||||||||
557 | - | |||||||||||||||||||
558 | QDebug operator <<(QDebug debug, const QQmlChangeSet &set) | - | ||||||||||||||||||
559 | { | - | ||||||||||||||||||
560 | debug.nospace() << "QQmlChangeSet("; | - | ||||||||||||||||||
561 | const QVector<QQmlChangeSet::Change> &removes = set.removes(); | - | ||||||||||||||||||
562 | for (const QQmlChangeSet::Change &remove : removes) | - | ||||||||||||||||||
563 | debug << remove; executed 6 times by 1 test: debug << remove; Executed by:
| 6 | ||||||||||||||||||
564 | const QVector<QQmlChangeSet::Change> &inserts = set.inserts(); | - | ||||||||||||||||||
565 | for (const QQmlChangeSet::Change &insert : inserts) | - | ||||||||||||||||||
566 | debug << insert; executed 6 times by 1 test: debug << insert; Executed by:
| 6 | ||||||||||||||||||
567 | const QVector<QQmlChangeSet::Change> &changes = set.changes(); | - | ||||||||||||||||||
568 | for (const QQmlChangeSet::Change &change : changes) | - | ||||||||||||||||||
569 | debug << change; executed 2 times by 1 test: debug << change; Executed by:
| 2 | ||||||||||||||||||
570 | return debug.nospace() << ')'; executed 4 times by 1 test: return debug.nospace() << ')'; Executed by:
| 4 | ||||||||||||||||||
571 | } | - | ||||||||||||||||||
572 | - | |||||||||||||||||||
573 | /*! | - | ||||||||||||||||||
574 | Prints a \a change to the \a debug stream. | - | ||||||||||||||||||
575 | */ | - | ||||||||||||||||||
576 | - | |||||||||||||||||||
577 | QDebug operator <<(QDebug debug, const QQmlChangeSet::Change &change) | - | ||||||||||||||||||
578 | { | - | ||||||||||||||||||
579 | return (debug.nospace() << "Change(" << change.index << ',' << change.count << ')').space(); executed 14 times by 1 test: return (debug.nospace() << "Change(" << change.index << ',' << change.count << ')').space(); Executed by:
| 14 | ||||||||||||||||||
580 | } | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | QT_END_NAMESPACE | - | ||||||||||||||||||
583 | - | |||||||||||||||||||
Source code | Switch to Preprocessed file |