Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/itemmodels/qsortfilterproxymodel.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qsortfilterproxymodel.h" | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #ifndef QT_NO_SORTFILTERPROXYMODEL | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | #include "qitemselectionmodel.h" | - | ||||||||||||||||||
39 | #include <qsize.h> | - | ||||||||||||||||||
40 | #include <qdebug.h> | - | ||||||||||||||||||
41 | #include <qdatetime.h> | - | ||||||||||||||||||
42 | #include <qpair.h> | - | ||||||||||||||||||
43 | #include <qstringlist.h> | - | ||||||||||||||||||
44 | #include <private/qabstractitemmodel_p.h> | - | ||||||||||||||||||
45 | #include <private/qabstractproxymodel_p.h> | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | #include <algorithm> | - | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | typedef QList<QPair<QModelIndex, QPersistentModelIndex> > QModelIndexPairList; | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | static inline QSet<int> qVectorToSet(const QVector<int> &vector) | - | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | QSet<int> set; | - | ||||||||||||||||||
56 | set.reserve(vector.size()); | - | ||||||||||||||||||
57 | for(int i=0; i < vector.size(); ++i)
| 87-787 | ||||||||||||||||||
58 | set << vector.at(i); executed 87 times by 4 tests: set << vector.at(i); Executed by:
| 87 | ||||||||||||||||||
59 | return set; executed 787 times by 5 tests: return set; Executed by:
| 787 | ||||||||||||||||||
60 | } | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | class QSortFilterProxyModelLessThan | - | ||||||||||||||||||
63 | { | - | ||||||||||||||||||
64 | public: | - | ||||||||||||||||||
65 | inline QSortFilterProxyModelLessThan(int column, const QModelIndex &parent, | - | ||||||||||||||||||
66 | const QAbstractItemModel *source, | - | ||||||||||||||||||
67 | const QSortFilterProxyModel *proxy) | - | ||||||||||||||||||
68 | : sort_column(column), source_parent(parent), source_model(source), proxy_model(proxy) {} executed 312 times by 7 tests: end of block Executed by:
| 312 | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | inline bool operator()(int r1, int r2) const | - | ||||||||||||||||||
71 | { | - | ||||||||||||||||||
72 | QModelIndex i1 = source_model->index(r1, sort_column, source_parent); | - | ||||||||||||||||||
73 | QModelIndex i2 = source_model->index(r2, sort_column, source_parent); | - | ||||||||||||||||||
74 | return proxy_model->lessThan(i1, i2); executed 87865 times by 6 tests: return proxy_model->lessThan(i1, i2); Executed by:
| 87865 | ||||||||||||||||||
75 | } | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | private: | - | ||||||||||||||||||
78 | int sort_column; | - | ||||||||||||||||||
79 | QModelIndex source_parent; | - | ||||||||||||||||||
80 | const QAbstractItemModel *source_model; | - | ||||||||||||||||||
81 | const QSortFilterProxyModel *proxy_model; | - | ||||||||||||||||||
82 | }; | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | class QSortFilterProxyModelGreaterThan | - | ||||||||||||||||||
85 | { | - | ||||||||||||||||||
86 | public: | - | ||||||||||||||||||
87 | inline QSortFilterProxyModelGreaterThan(int column, const QModelIndex &parent, | - | ||||||||||||||||||
88 | const QAbstractItemModel *source, | - | ||||||||||||||||||
89 | const QSortFilterProxyModel *proxy) | - | ||||||||||||||||||
90 | : sort_column(column), source_parent(parent), | - | ||||||||||||||||||
91 | source_model(source), proxy_model(proxy) {} executed 21 times by 4 tests: end of block Executed by:
| 21 | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | inline bool operator()(int r1, int r2) const | - | ||||||||||||||||||
94 | { | - | ||||||||||||||||||
95 | QModelIndex i1 = source_model->index(r1, sort_column, source_parent); | - | ||||||||||||||||||
96 | QModelIndex i2 = source_model->index(r2, sort_column, source_parent); | - | ||||||||||||||||||
97 | return proxy_model->lessThan(i2, i1); executed 177 times by 4 tests: return proxy_model->lessThan(i2, i1); Executed by:
| 177 | ||||||||||||||||||
98 | } | - | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | private: | - | ||||||||||||||||||
101 | int sort_column; | - | ||||||||||||||||||
102 | QModelIndex source_parent; | - | ||||||||||||||||||
103 | const QAbstractItemModel *source_model; | - | ||||||||||||||||||
104 | const QSortFilterProxyModel *proxy_model; | - | ||||||||||||||||||
105 | }; | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | - | |||||||||||||||||||
108 | //this struct is used to store what are the rows that are removed | - | ||||||||||||||||||
109 | //between a call to rowsAboutToBeRemoved and rowsRemoved | - | ||||||||||||||||||
110 | //it avoids readding rows to the mapping that are currently being removed | - | ||||||||||||||||||
111 | struct QRowsRemoval | - | ||||||||||||||||||
112 | { | - | ||||||||||||||||||
113 | QRowsRemoval(const QModelIndex &parent_source, int start, int end) : parent_source(parent_source), start(start), end(end) | - | ||||||||||||||||||
114 | { | - | ||||||||||||||||||
115 | } executed 47 times by 4 tests: end of block Executed by:
| 47 | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | QRowsRemoval() : start(-1), end(-1) | - | ||||||||||||||||||
118 | { | - | ||||||||||||||||||
119 | } executed 329 times by 13 tests: end of block Executed by:
| 329 | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | bool contains(QModelIndex parent, int row) | - | ||||||||||||||||||
122 | { | - | ||||||||||||||||||
123 | do { | - | ||||||||||||||||||
124 | if (parent == parent_source)
| 0-304 | ||||||||||||||||||
125 | return row >= start && row <= end; executed 304 times by 2 tests: return row >= start && row <= end; Executed by:
| 0-304 | ||||||||||||||||||
126 | row = parent.row(); | - | ||||||||||||||||||
127 | parent = parent.parent(); | - | ||||||||||||||||||
128 | } while (row >= 0); never executed: end of block
| 0 | ||||||||||||||||||
129 | return false; never executed: return false; | 0 | ||||||||||||||||||
130 | } | - | ||||||||||||||||||
131 | private: | - | ||||||||||||||||||
132 | QModelIndex parent_source; | - | ||||||||||||||||||
133 | int start; | - | ||||||||||||||||||
134 | int end; | - | ||||||||||||||||||
135 | }; | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate | - | ||||||||||||||||||
138 | { | - | ||||||||||||||||||
139 | Q_DECLARE_PUBLIC(QSortFilterProxyModel) | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | public: | - | ||||||||||||||||||
142 | struct Mapping { | - | ||||||||||||||||||
143 | QVector<int> source_rows; | - | ||||||||||||||||||
144 | QVector<int> source_columns; | - | ||||||||||||||||||
145 | QVector<int> proxy_rows; | - | ||||||||||||||||||
146 | QVector<int> proxy_columns; | - | ||||||||||||||||||
147 | QVector<QModelIndex> mapped_children; | - | ||||||||||||||||||
148 | QHash<QModelIndex, Mapping *>::const_iterator map_iter; | - | ||||||||||||||||||
149 | }; | - | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | mutable QHash<QModelIndex, Mapping*> source_index_mapping; | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | int source_sort_column; | - | ||||||||||||||||||
154 | int proxy_sort_column; | - | ||||||||||||||||||
155 | Qt::SortOrder sort_order; | - | ||||||||||||||||||
156 | Qt::CaseSensitivity sort_casesensitivity; | - | ||||||||||||||||||
157 | int sort_role; | - | ||||||||||||||||||
158 | bool sort_localeaware; | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | int filter_column; | - | ||||||||||||||||||
161 | QRegExp filter_regexp; | - | ||||||||||||||||||
162 | int filter_role; | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | bool dynamic_sortfilter; | - | ||||||||||||||||||
165 | QRowsRemoval itemsBeingRemoved; | - | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | QModelIndexPairList saved_persistent_indexes; | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | QHash<QModelIndex, Mapping *>::const_iterator create_mapping( | - | ||||||||||||||||||
170 | const QModelIndex &source_parent) const; | - | ||||||||||||||||||
171 | QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const; | - | ||||||||||||||||||
172 | QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const; | - | ||||||||||||||||||
173 | bool can_create_mapping(const QModelIndex &source_parent) const; | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | void remove_from_mapping(const QModelIndex &source_parent); | - | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator( | - | ||||||||||||||||||
178 | const QModelIndex &proxy_index) const | - | ||||||||||||||||||
179 | { | - | ||||||||||||||||||
180 | Q_ASSERT(proxy_index.isValid()); | - | ||||||||||||||||||
181 | Q_ASSERT(proxy_index.model() == q_func()); | - | ||||||||||||||||||
182 | const void *p = proxy_index.internalPointer(); | - | ||||||||||||||||||
183 | Q_ASSERT(p); | - | ||||||||||||||||||
184 | QHash<QModelIndex, Mapping *>::const_iterator it = | - | ||||||||||||||||||
185 | static_cast<const Mapping*>(p)->map_iter; | - | ||||||||||||||||||
186 | Q_ASSERT(it != source_index_mapping.constEnd()); | - | ||||||||||||||||||
187 | Q_ASSERT(it.value()); | - | ||||||||||||||||||
188 | return it; executed 149373 times by 13 tests: return it; Executed by:
| 149373 | ||||||||||||||||||
189 | } | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | inline QModelIndex create_index(int row, int column, | - | ||||||||||||||||||
192 | QHash<QModelIndex, Mapping*>::const_iterator it) const | - | ||||||||||||||||||
193 | { | - | ||||||||||||||||||
194 | return q_func()->createIndex(row, column, *it); executed 118259 times by 13 tests: return q_func()->createIndex(row, column, *it); Executed by:
| 118259 | ||||||||||||||||||
195 | } | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | void _q_sourceDataChanged(const QModelIndex &source_top_left, | - | ||||||||||||||||||
198 | const QModelIndex &source_bottom_right, | - | ||||||||||||||||||
199 | const QVector<int> &roles); | - | ||||||||||||||||||
200 | void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end); | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | void _q_sourceAboutToBeReset(); | - | ||||||||||||||||||
203 | void _q_sourceReset(); | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | void _q_sourceLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint); | - | ||||||||||||||||||
206 | void _q_sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint); | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | void _q_sourceRowsAboutToBeInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||
209 | int start, int end); | - | ||||||||||||||||||
210 | void _q_sourceRowsInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||
211 | int start, int end); | - | ||||||||||||||||||
212 | void _q_sourceRowsAboutToBeRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||
213 | int start, int end); | - | ||||||||||||||||||
214 | void _q_sourceRowsRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||
215 | int start, int end); | - | ||||||||||||||||||
216 | void _q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||
217 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||
218 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||
219 | void _q_sourceRowsMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||
220 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||
221 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||
222 | void _q_sourceColumnsAboutToBeInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||
223 | int start, int end); | - | ||||||||||||||||||
224 | void _q_sourceColumnsInserted(const QModelIndex &source_parent, | - | ||||||||||||||||||
225 | int start, int end); | - | ||||||||||||||||||
226 | void _q_sourceColumnsAboutToBeRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||
227 | int start, int end); | - | ||||||||||||||||||
228 | void _q_sourceColumnsRemoved(const QModelIndex &source_parent, | - | ||||||||||||||||||
229 | int start, int end); | - | ||||||||||||||||||
230 | void _q_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||
231 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||
232 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||
233 | void _q_sourceColumnsMoved(const QModelIndex &sourceParent, | - | ||||||||||||||||||
234 | int sourceStart, int sourceEnd, | - | ||||||||||||||||||
235 | const QModelIndex &destParent, int dest); | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | void _q_clearMapping(); | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | void sort(); | - | ||||||||||||||||||
240 | bool update_source_sort_column(); | - | ||||||||||||||||||
241 | void sort_source_rows(QVector<int> &source_rows, | - | ||||||||||||||||||
242 | const QModelIndex &source_parent) const; | - | ||||||||||||||||||
243 | QVector<QPair<int, QVector<int > > > proxy_intervals_for_source_items_to_add( | - | ||||||||||||||||||
244 | const QVector<int> &proxy_to_source, const QVector<int> &source_items, | - | ||||||||||||||||||
245 | const QModelIndex &source_parent, Qt::Orientation orient) const; | - | ||||||||||||||||||
246 | QVector<QPair<int, int > > proxy_intervals_for_source_items( | - | ||||||||||||||||||
247 | const QVector<int> &source_to_proxy, const QVector<int> &source_items) const; | - | ||||||||||||||||||
248 | void insert_source_items( | - | ||||||||||||||||||
249 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||
250 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||
251 | Qt::Orientation orient, bool emit_signal = true); | - | ||||||||||||||||||
252 | void remove_source_items( | - | ||||||||||||||||||
253 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||
254 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||
255 | Qt::Orientation orient, bool emit_signal = true); | - | ||||||||||||||||||
256 | void remove_proxy_interval( | - | ||||||||||||||||||
257 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||
258 | int proxy_start, int proxy_end, const QModelIndex &proxy_parent, | - | ||||||||||||||||||
259 | Qt::Orientation orient, bool emit_signal = true); | - | ||||||||||||||||||
260 | void build_source_to_proxy_mapping( | - | ||||||||||||||||||
261 | const QVector<int> &proxy_to_source, QVector<int> &source_to_proxy) const; | - | ||||||||||||||||||
262 | void source_items_inserted(const QModelIndex &source_parent, | - | ||||||||||||||||||
263 | int start, int end, Qt::Orientation orient); | - | ||||||||||||||||||
264 | void source_items_about_to_be_removed(const QModelIndex &source_parent, | - | ||||||||||||||||||
265 | int start, int end, Qt::Orientation orient); | - | ||||||||||||||||||
266 | void source_items_removed(const QModelIndex &source_parent, | - | ||||||||||||||||||
267 | int start, int end, Qt::Orientation orient); | - | ||||||||||||||||||
268 | void proxy_item_range( | - | ||||||||||||||||||
269 | const QVector<int> &source_to_proxy, const QVector<int> &source_items, | - | ||||||||||||||||||
270 | int &proxy_low, int &proxy_high) const; | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | QModelIndexPairList store_persistent_indexes(); | - | ||||||||||||||||||
273 | void update_persistent_indexes(const QModelIndexPairList &source_indexes); | - | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | void filter_about_to_be_changed(const QModelIndex &source_parent = QModelIndex()); | - | ||||||||||||||||||
276 | void filter_changed(const QModelIndex &source_parent = QModelIndex()); | - | ||||||||||||||||||
277 | QSet<int> handle_filter_changed( | - | ||||||||||||||||||
278 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||
279 | const QModelIndex &source_parent, Qt::Orientation orient); | - | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | void updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping, | - | ||||||||||||||||||
282 | Qt::Orientation orient, int start, int end, int delta_item_count, bool remove); | - | ||||||||||||||||||
283 | - | |||||||||||||||||||
284 | virtual void _q_sourceModelDestroyed() Q_DECL_OVERRIDE; | - | ||||||||||||||||||
285 | }; | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap; | - | ||||||||||||||||||
288 | - | |||||||||||||||||||
289 | void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed() | - | ||||||||||||||||||
290 | { | - | ||||||||||||||||||
291 | QAbstractProxyModelPrivate::_q_sourceModelDestroyed(); | - | ||||||||||||||||||
292 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
293 | source_index_mapping.clear(); | - | ||||||||||||||||||
294 | } executed 18 times by 9 tests: end of block Executed by:
| 18 | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | void QSortFilterProxyModelPrivate::remove_from_mapping(const QModelIndex &source_parent) | - | ||||||||||||||||||
297 | { | - | ||||||||||||||||||
298 | if (Mapping *m = source_index_mapping.take(source_parent)) {
| 0-38 | ||||||||||||||||||
299 | for (int i = 0; i < m->mapped_children.size(); ++i)
| 20-38 | ||||||||||||||||||
300 | remove_from_mapping(m->mapped_children.at(i)); executed 20 times by 2 tests: remove_from_mapping(m->mapped_children.at(i)); Executed by:
| 20 | ||||||||||||||||||
301 | delete m; | - | ||||||||||||||||||
302 | } executed 38 times by 2 tests: end of block Executed by:
| 38 | ||||||||||||||||||
303 | } executed 38 times by 2 tests: end of block Executed by:
| 38 | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | void QSortFilterProxyModelPrivate::_q_clearMapping() | - | ||||||||||||||||||
306 | { | - | ||||||||||||||||||
307 | // store the persistent indexes | - | ||||||||||||||||||
308 | QModelIndexPairList source_indexes = store_persistent_indexes(); | - | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
311 | source_index_mapping.clear(); | - | ||||||||||||||||||
312 | if (dynamic_sortfilter && update_source_sort_column()) {
| 6-828 | ||||||||||||||||||
313 | //update_source_sort_column might have created wrong mapping so we have to clear it again | - | ||||||||||||||||||
314 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
315 | source_index_mapping.clear(); | - | ||||||||||||||||||
316 | } executed 8 times by 2 tests: end of block Executed by:
| 8 | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | // update the persistent indexes | - | ||||||||||||||||||
319 | update_persistent_indexes(source_indexes); | - | ||||||||||||||||||
320 | } executed 834 times by 13 tests: end of block Executed by:
| 834 | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | IndexMap::const_iterator QSortFilterProxyModelPrivate::create_mapping( | - | ||||||||||||||||||
323 | const QModelIndex &source_parent) const | - | ||||||||||||||||||
324 | { | - | ||||||||||||||||||
325 | Q_Q(const QSortFilterProxyModel); | - | ||||||||||||||||||
326 | - | |||||||||||||||||||
327 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||
328 | if (it != source_index_mapping.constEnd()) // was mapped already
| 1248-150731 | ||||||||||||||||||
329 | return it; executed 150731 times by 13 tests: return it; Executed by:
| 150731 | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | Mapping *m = new Mapping; | - | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | int source_rows = model->rowCount(source_parent); | - | ||||||||||||||||||
334 | m->source_rows.reserve(source_rows); | - | ||||||||||||||||||
335 | for (int i = 0; i < source_rows; ++i) {
| 1248-11660 | ||||||||||||||||||
336 | if (q->filterAcceptsRow(i, source_parent))
| 4998-6662 | ||||||||||||||||||
337 | m->source_rows.append(i); executed 4998 times by 12 tests: m->source_rows.append(i); Executed by:
| 4998 | ||||||||||||||||||
338 | } executed 11660 times by 12 tests: end of block Executed by:
| 11660 | ||||||||||||||||||
339 | int source_cols = model->columnCount(source_parent); | - | ||||||||||||||||||
340 | m->source_columns.reserve(source_cols); | - | ||||||||||||||||||
341 | for (int i = 0; i < source_cols; ++i) {
| 459-1248 | ||||||||||||||||||
342 | if (q->filterAcceptsColumn(i, source_parent))
| 0-459 | ||||||||||||||||||
343 | m->source_columns.append(i); executed 459 times by 12 tests: m->source_columns.append(i); Executed by:
| 459 | ||||||||||||||||||
344 | } executed 459 times by 12 tests: end of block Executed by:
| 459 | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | sort_source_rows(m->source_rows, source_parent); | - | ||||||||||||||||||
347 | m->proxy_rows.resize(source_rows); | - | ||||||||||||||||||
348 | build_source_to_proxy_mapping(m->source_rows, m->proxy_rows); | - | ||||||||||||||||||
349 | m->proxy_columns.resize(source_cols); | - | ||||||||||||||||||
350 | build_source_to_proxy_mapping(m->source_columns, m->proxy_columns); | - | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | it = IndexMap::const_iterator(source_index_mapping.insert(source_parent, m)); | - | ||||||||||||||||||
353 | m->map_iter = it; | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | if (source_parent.isValid()) {
| 436-812 | ||||||||||||||||||
356 | QModelIndex source_grand_parent = source_parent.parent(); | - | ||||||||||||||||||
357 | IndexMap::const_iterator it2 = create_mapping(source_grand_parent); | - | ||||||||||||||||||
358 | Q_ASSERT(it2 != source_index_mapping.constEnd()); | - | ||||||||||||||||||
359 | it2.value()->mapped_children.append(source_parent); | - | ||||||||||||||||||
360 | } executed 812 times by 6 tests: end of block Executed by:
| 812 | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | Q_ASSERT(it != source_index_mapping.constEnd()); | - | ||||||||||||||||||
363 | Q_ASSERT(it.value()); | - | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | return it; executed 1248 times by 13 tests: return it; Executed by:
| 1248 | ||||||||||||||||||
366 | } | - | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | QModelIndex QSortFilterProxyModelPrivate::proxy_to_source(const QModelIndex &proxy_index) const | - | ||||||||||||||||||
369 | { | - | ||||||||||||||||||
370 | if (!proxy_index.isValid())
| 111353-111445 | ||||||||||||||||||
371 | return QModelIndex(); // for now; we may want to be able to set a root index later executed 111353 times by 13 tests: return QModelIndex(); Executed by:
| 111353 | ||||||||||||||||||
372 | if (proxy_index.model() != q_func()) {
| 0-111445 | ||||||||||||||||||
373 | qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapToSource"; | - | ||||||||||||||||||
374 | Q_ASSERT(!"QSortFilterProxyModel: index from wrong model passed to mapToSource"); | - | ||||||||||||||||||
375 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
376 | } | - | ||||||||||||||||||
377 | IndexMap::const_iterator it = index_to_iterator(proxy_index); | - | ||||||||||||||||||
378 | Mapping *m = it.value(); | - | ||||||||||||||||||
379 | if ((proxy_index.row() >= m->source_rows.size()) || (proxy_index.column() >= m->source_columns.size()))
| 0-111445 | ||||||||||||||||||
380 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
381 | int source_row = m->source_rows.at(proxy_index.row()); | - | ||||||||||||||||||
382 | int source_col = m->source_columns.at(proxy_index.column()); | - | ||||||||||||||||||
383 | return model->index(source_row, source_col, it.key()); executed 111445 times by 13 tests: return model->index(source_row, source_col, it.key()); Executed by:
| 111445 | ||||||||||||||||||
384 | } | - | ||||||||||||||||||
385 | - | |||||||||||||||||||
386 | QModelIndex QSortFilterProxyModelPrivate::source_to_proxy(const QModelIndex &source_index) const | - | ||||||||||||||||||
387 | { | - | ||||||||||||||||||
388 | if (!source_index.isValid())
| 7916-15987 | ||||||||||||||||||
389 | return QModelIndex(); // for now; we may want to be able to set a root index later executed 15987 times by 13 tests: return QModelIndex(); Executed by:
| 15987 | ||||||||||||||||||
390 | if (source_index.model() != model) {
| 0-7916 | ||||||||||||||||||
391 | qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapFromSource"; | - | ||||||||||||||||||
392 | Q_ASSERT(!"QSortFilterProxyModel: index from wrong model passed to mapFromSource"); | - | ||||||||||||||||||
393 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
394 | } | - | ||||||||||||||||||
395 | QModelIndex source_parent = source_index.parent(); | - | ||||||||||||||||||
396 | IndexMap::const_iterator it = create_mapping(source_parent); | - | ||||||||||||||||||
397 | Mapping *m = it.value(); | - | ||||||||||||||||||
398 | if ((source_index.row() >= m->proxy_rows.size()) || (source_index.column() >= m->proxy_columns.size()))
| 0-7916 | ||||||||||||||||||
399 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
400 | int proxy_row = m->proxy_rows.at(source_index.row()); | - | ||||||||||||||||||
401 | int proxy_column = m->proxy_columns.at(source_index.column()); | - | ||||||||||||||||||
402 | if (proxy_row == -1 || proxy_column == -1)
| 0-7876 | ||||||||||||||||||
403 | return QModelIndex(); executed 40 times by 2 tests: return QModelIndex(); Executed by:
| 40 | ||||||||||||||||||
404 | return create_index(proxy_row, proxy_column, it); executed 7876 times by 11 tests: return create_index(proxy_row, proxy_column, it); Executed by:
| 7876 | ||||||||||||||||||
405 | } | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | bool QSortFilterProxyModelPrivate::can_create_mapping(const QModelIndex &source_parent) const | - | ||||||||||||||||||
408 | { | - | ||||||||||||||||||
409 | if (source_parent.isValid()) {
| 604-1677 | ||||||||||||||||||
410 | QModelIndex source_grand_parent = source_parent.parent(); | - | ||||||||||||||||||
411 | IndexMap::const_iterator it = source_index_mapping.constFind(source_grand_parent); | - | ||||||||||||||||||
412 | if (it == source_index_mapping.constEnd()) {
| 2-1675 | ||||||||||||||||||
413 | // Don't care, since we don't have mapping for the grand parent | - | ||||||||||||||||||
414 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
415 | } | - | ||||||||||||||||||
416 | Mapping *gm = it.value(); | - | ||||||||||||||||||
417 | if (gm->proxy_rows.at(source_parent.row()) == -1 ||
| 4-1671 | ||||||||||||||||||
418 | gm->proxy_columns.at(source_parent.column()) == -1) {
| 0-1671 | ||||||||||||||||||
419 | // Don't care, since parent is filtered | - | ||||||||||||||||||
420 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||||||||
421 | } | - | ||||||||||||||||||
422 | } executed 1671 times by 4 tests: end of block Executed by:
| 1671 | ||||||||||||||||||
423 | return true; executed 2275 times by 7 tests: return true; Executed by:
| 2275 | ||||||||||||||||||
424 | } | - | ||||||||||||||||||
425 | - | |||||||||||||||||||
426 | /*! | - | ||||||||||||||||||
427 | \internal | - | ||||||||||||||||||
428 | - | |||||||||||||||||||
429 | Sorts the existing mappings. | - | ||||||||||||||||||
430 | */ | - | ||||||||||||||||||
431 | void QSortFilterProxyModelPrivate::sort() | - | ||||||||||||||||||
432 | { | - | ||||||||||||||||||
433 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
434 | emit q->layoutAboutToBeChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||
435 | QModelIndexPairList source_indexes = store_persistent_indexes(); | - | ||||||||||||||||||
436 | IndexMap::const_iterator it = source_index_mapping.constBegin(); | - | ||||||||||||||||||
437 | for (; it != source_index_mapping.constEnd(); ++it) {
| 261-267 | ||||||||||||||||||
438 | QModelIndex source_parent = it.key(); | - | ||||||||||||||||||
439 | Mapping *m = it.value(); | - | ||||||||||||||||||
440 | sort_source_rows(m->source_rows, source_parent); | - | ||||||||||||||||||
441 | build_source_to_proxy_mapping(m->source_rows, m->proxy_rows); | - | ||||||||||||||||||
442 | } executed 267 times by 10 tests: end of block Executed by:
| 267 | ||||||||||||||||||
443 | update_persistent_indexes(source_indexes); | - | ||||||||||||||||||
444 | emit q->layoutChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||
445 | } executed 261 times by 11 tests: end of block Executed by:
| 261 | ||||||||||||||||||
446 | - | |||||||||||||||||||
447 | /*! | - | ||||||||||||||||||
448 | \internal | - | ||||||||||||||||||
449 | - | |||||||||||||||||||
450 | update the source_sort_column according to the proxy_sort_column | - | ||||||||||||||||||
451 | return true if the column was changed | - | ||||||||||||||||||
452 | */ | - | ||||||||||||||||||
453 | bool QSortFilterProxyModelPrivate::update_source_sort_column() | - | ||||||||||||||||||
454 | { | - | ||||||||||||||||||
455 | int old_source_sort_column = source_sort_column; | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | if (proxy_sort_column == -1) {
| 149-2659 | ||||||||||||||||||
458 | source_sort_column = -1; | - | ||||||||||||||||||
459 | } else { executed 2659 times by 13 tests: end of block Executed by:
| 2659 | ||||||||||||||||||
460 | // We cannot use index mapping here because in case of a still-empty | - | ||||||||||||||||||
461 | // proxy model there's no valid proxy index we could map to source. | - | ||||||||||||||||||
462 | // So always use the root mapping directly instead. | - | ||||||||||||||||||
463 | Mapping *m = create_mapping(QModelIndex()).value(); | - | ||||||||||||||||||
464 | if (proxy_sort_column < m->source_columns.size())
| 13-136 | ||||||||||||||||||
465 | source_sort_column = m->source_columns.at(proxy_sort_column); executed 136 times by 8 tests: source_sort_column = m->source_columns.at(proxy_sort_column); Executed by:
| 136 | ||||||||||||||||||
466 | else | - | ||||||||||||||||||
467 | source_sort_column = -1; executed 13 times by 3 tests: source_sort_column = -1; Executed by:
| 13 | ||||||||||||||||||
468 | } | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | return old_source_sort_column != source_sort_column; executed 2808 times by 13 tests: return old_source_sort_column != source_sort_column; Executed by:
| 2808 | ||||||||||||||||||
471 | } | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | - | |||||||||||||||||||
474 | /*! | - | ||||||||||||||||||
475 | \internal | - | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | Sorts the given \a source_rows according to current sort column and order. | - | ||||||||||||||||||
478 | */ | - | ||||||||||||||||||
479 | void QSortFilterProxyModelPrivate::sort_source_rows( | - | ||||||||||||||||||
480 | QVector<int> &source_rows, const QModelIndex &source_parent) const | - | ||||||||||||||||||
481 | { | - | ||||||||||||||||||
482 | Q_Q(const QSortFilterProxyModel); | - | ||||||||||||||||||
483 | if (source_sort_column >= 0) {
| 333-2381 | ||||||||||||||||||
484 | if (sort_order == Qt::AscendingOrder) {
| 21-312 | ||||||||||||||||||
485 | QSortFilterProxyModelLessThan lt(source_sort_column, source_parent, model, q); | - | ||||||||||||||||||
486 | std::stable_sort(source_rows.begin(), source_rows.end(), lt); | - | ||||||||||||||||||
487 | } else { executed 312 times by 7 tests: end of block Executed by:
| 312 | ||||||||||||||||||
488 | QSortFilterProxyModelGreaterThan gt(source_sort_column, source_parent, model, q); | - | ||||||||||||||||||
489 | std::stable_sort(source_rows.begin(), source_rows.end(), gt); | - | ||||||||||||||||||
490 | } executed 21 times by 4 tests: end of block Executed by:
| 21 | ||||||||||||||||||
491 | } else { // restore the source model order | - | ||||||||||||||||||
492 | std::stable_sort(source_rows.begin(), source_rows.end()); | - | ||||||||||||||||||
493 | } executed 2381 times by 13 tests: end of block Executed by:
| 2381 | ||||||||||||||||||
494 | } | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | /*! | - | ||||||||||||||||||
497 | \internal | - | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | Given source-to-proxy mapping \a source_to_proxy and the set of | - | ||||||||||||||||||
500 | source items \a source_items (which are part of that mapping), | - | ||||||||||||||||||
501 | determines the corresponding proxy item intervals that should | - | ||||||||||||||||||
502 | be removed from the proxy model. | - | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | The result is a vector of pairs, where each pair represents a | - | ||||||||||||||||||
505 | (start, end) tuple, sorted in ascending order. | - | ||||||||||||||||||
506 | */ | - | ||||||||||||||||||
507 | QVector<QPair<int, int > > QSortFilterProxyModelPrivate::proxy_intervals_for_source_items( | - | ||||||||||||||||||
508 | const QVector<int> &source_to_proxy, const QVector<int> &source_items) const | - | ||||||||||||||||||
509 | { | - | ||||||||||||||||||
510 | QVector<QPair<int, int> > proxy_intervals; | - | ||||||||||||||||||
511 | if (source_items.isEmpty())
| 13-132 | ||||||||||||||||||
512 | return proxy_intervals; executed 13 times by 3 tests: return proxy_intervals; Executed by:
| 13 | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | int source_items_index = 0; | - | ||||||||||||||||||
515 | while (source_items_index < source_items.size()) {
| 132-152 | ||||||||||||||||||
516 | int first_proxy_item = source_to_proxy.at(source_items.at(source_items_index)); | - | ||||||||||||||||||
517 | Q_ASSERT(first_proxy_item != -1); | - | ||||||||||||||||||
518 | int last_proxy_item = first_proxy_item; | - | ||||||||||||||||||
519 | ++source_items_index; | - | ||||||||||||||||||
520 | // Find end of interval | - | ||||||||||||||||||
521 | while ((source_items_index < source_items.size())
| 132-485 | ||||||||||||||||||
522 | && (source_to_proxy.at(source_items.at(source_items_index)) == last_proxy_item + 1)) {
| 20-465 | ||||||||||||||||||
523 | ++last_proxy_item; | - | ||||||||||||||||||
524 | ++source_items_index; | - | ||||||||||||||||||
525 | } executed 465 times by 3 tests: end of block Executed by:
| 465 | ||||||||||||||||||
526 | // Add interval to result | - | ||||||||||||||||||
527 | proxy_intervals.append(QPair<int, int>(first_proxy_item, last_proxy_item)); | - | ||||||||||||||||||
528 | } executed 152 times by 6 tests: end of block Executed by:
| 152 | ||||||||||||||||||
529 | std::stable_sort(proxy_intervals.begin(), proxy_intervals.end()); | - | ||||||||||||||||||
530 | return proxy_intervals; executed 132 times by 6 tests: return proxy_intervals; Executed by:
| 132 | ||||||||||||||||||
531 | } | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | /*! | - | ||||||||||||||||||
534 | \internal | - | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | Given source-to-proxy mapping \a src_to_proxy and proxy-to-source mapping | - | ||||||||||||||||||
537 | \a proxy_to_source, removes \a source_items from this proxy model. | - | ||||||||||||||||||
538 | The corresponding proxy items are removed in intervals, so that the proper | - | ||||||||||||||||||
539 | rows/columnsRemoved(start, end) signals will be generated. | - | ||||||||||||||||||
540 | */ | - | ||||||||||||||||||
541 | void QSortFilterProxyModelPrivate::remove_source_items( | - | ||||||||||||||||||
542 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||
543 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||
544 | Qt::Orientation orient, bool emit_signal) | - | ||||||||||||||||||
545 | { | - | ||||||||||||||||||
546 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
547 | QModelIndex proxy_parent = q->mapFromSource(source_parent); | - | ||||||||||||||||||
548 | if (!proxy_parent.isValid() && source_parent.isValid())
| 0-87 | ||||||||||||||||||
549 | return; // nothing to do (already removed) never executed: return; | 0 | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | QVector<QPair<int, int> > proxy_intervals; | - | ||||||||||||||||||
552 | proxy_intervals = proxy_intervals_for_source_items(source_to_proxy, source_items); | - | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | for (int i = proxy_intervals.size()-1; i >= 0; --i) {
| 145-152 | ||||||||||||||||||
555 | QPair<int, int> interval = proxy_intervals.at(i); | - | ||||||||||||||||||
556 | int proxy_start = interval.first; | - | ||||||||||||||||||
557 | int proxy_end = interval.second; | - | ||||||||||||||||||
558 | remove_proxy_interval(source_to_proxy, proxy_to_source, proxy_start, proxy_end, | - | ||||||||||||||||||
559 | proxy_parent, orient, emit_signal); | - | ||||||||||||||||||
560 | } executed 152 times by 6 tests: end of block Executed by:
| 152 | ||||||||||||||||||
561 | } executed 145 times by 6 tests: end of block Executed by:
| 145 | ||||||||||||||||||
562 | - | |||||||||||||||||||
563 | /*! | - | ||||||||||||||||||
564 | \internal | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | Given source-to-proxy mapping \a source_to_proxy and proxy-to-source mapping | - | ||||||||||||||||||
567 | \a proxy_to_source, removes items from \a proxy_start to \a proxy_end | - | ||||||||||||||||||
568 | (inclusive) from this proxy model. | - | ||||||||||||||||||
569 | */ | - | ||||||||||||||||||
570 | void QSortFilterProxyModelPrivate::remove_proxy_interval( | - | ||||||||||||||||||
571 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, int proxy_start, int proxy_end, | - | ||||||||||||||||||
572 | const QModelIndex &proxy_parent, Qt::Orientation orient, bool emit_signal) | - | ||||||||||||||||||
573 | { | - | ||||||||||||||||||
574 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
575 | if (emit_signal) {
| 13-139 | ||||||||||||||||||
576 | if (orient == Qt::Vertical)
| 35-104 | ||||||||||||||||||
577 | q->beginRemoveRows(proxy_parent, proxy_start, proxy_end); executed 104 times by 6 tests: q->beginRemoveRows(proxy_parent, proxy_start, proxy_end); Executed by:
| 104 | ||||||||||||||||||
578 | else | - | ||||||||||||||||||
579 | q->beginRemoveColumns(proxy_parent, proxy_start, proxy_end); executed 35 times by 3 tests: q->beginRemoveColumns(proxy_parent, proxy_start, proxy_end); Executed by:
| 35 | ||||||||||||||||||
580 | } | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | // Remove items from proxy-to-source mapping | - | ||||||||||||||||||
583 | proxy_to_source.remove(proxy_start, proxy_end - proxy_start + 1); | - | ||||||||||||||||||
584 | - | |||||||||||||||||||
585 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||
586 | - | |||||||||||||||||||
587 | if (emit_signal) {
| 13-139 | ||||||||||||||||||
588 | if (orient == Qt::Vertical)
| 35-104 | ||||||||||||||||||
589 | q->endRemoveRows(); executed 104 times by 6 tests: q->endRemoveRows(); Executed by:
| 104 | ||||||||||||||||||
590 | else | - | ||||||||||||||||||
591 | q->endRemoveColumns(); executed 35 times by 3 tests: q->endRemoveColumns(); Executed by:
| 35 | ||||||||||||||||||
592 | } | - | ||||||||||||||||||
593 | } executed 152 times by 6 tests: end of block Executed by:
| 152 | ||||||||||||||||||
594 | - | |||||||||||||||||||
595 | /*! | - | ||||||||||||||||||
596 | \internal | - | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | Given proxy-to-source mapping \a proxy_to_source and a set of | - | ||||||||||||||||||
599 | unmapped source items \a source_items, determines the proxy item | - | ||||||||||||||||||
600 | intervals at which the subsets of source items should be inserted | - | ||||||||||||||||||
601 | (but does not actually add them to the mapping). | - | ||||||||||||||||||
602 | - | |||||||||||||||||||
603 | The result is a vector of pairs, each pair representing a tuple (start, | - | ||||||||||||||||||
604 | items), where items is a vector containing the (sorted) source items that | - | ||||||||||||||||||
605 | should be inserted at that proxy model location. | - | ||||||||||||||||||
606 | */ | - | ||||||||||||||||||
607 | QVector<QPair<int, QVector<int > > > QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add( | - | ||||||||||||||||||
608 | const QVector<int> &proxy_to_source, const QVector<int> &source_items, | - | ||||||||||||||||||
609 | const QModelIndex &source_parent, Qt::Orientation orient) const | - | ||||||||||||||||||
610 | { | - | ||||||||||||||||||
611 | Q_Q(const QSortFilterProxyModel); | - | ||||||||||||||||||
612 | QVector<QPair<int, QVector<int> > > proxy_intervals; | - | ||||||||||||||||||
613 | if (source_items.isEmpty())
| 38-2304 | ||||||||||||||||||
614 | return proxy_intervals; executed 38 times by 4 tests: return proxy_intervals; Executed by:
| 38 | ||||||||||||||||||
615 | - | |||||||||||||||||||
616 | int proxy_low = 0; | - | ||||||||||||||||||
617 | int proxy_item = 0; | - | ||||||||||||||||||
618 | int source_items_index = 0; | - | ||||||||||||||||||
619 | QVector<int> source_items_in_interval; | - | ||||||||||||||||||
620 | bool compare = (orient == Qt::Vertical && source_sort_column >= 0 && dynamic_sortfilter);
| 1-1161 | ||||||||||||||||||
621 | while (source_items_index < source_items.size()) {
| 2304-2317 | ||||||||||||||||||
622 | source_items_in_interval.clear(); | - | ||||||||||||||||||
623 | int first_new_source_item = source_items.at(source_items_index); | - | ||||||||||||||||||
624 | source_items_in_interval.append(first_new_source_item); | - | ||||||||||||||||||
625 | ++source_items_index; | - | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | // Find proxy item at which insertion should be started | - | ||||||||||||||||||
628 | int proxy_high = proxy_to_source.size() - 1; | - | ||||||||||||||||||
629 | QModelIndex i1 = compare ? model->index(first_new_source_item, source_sort_column, source_parent) : QModelIndex();
| 30-2287 | ||||||||||||||||||
630 | while (proxy_low <= proxy_high) {
| 1193-2317 | ||||||||||||||||||
631 | proxy_item = (proxy_low + proxy_high) / 2; | - | ||||||||||||||||||
632 | if (compare) {
| 58-1135 | ||||||||||||||||||
633 | QModelIndex i2 = model->index(proxy_to_source.at(proxy_item), source_sort_column, source_parent); | - | ||||||||||||||||||
634 | if ((sort_order == Qt::AscendingOrder) ? q->lessThan(i1, i2) : q->lessThan(i2, i1))
| 6-52 | ||||||||||||||||||
635 | proxy_high = proxy_item - 1; executed 19 times by 3 tests: proxy_high = proxy_item - 1; Executed by:
| 19 | ||||||||||||||||||
636 | else | - | ||||||||||||||||||
637 | proxy_low = proxy_item + 1; executed 39 times by 3 tests: proxy_low = proxy_item + 1; Executed by:
| 39 | ||||||||||||||||||
638 | } else { | - | ||||||||||||||||||
639 | if (first_new_source_item < proxy_to_source.at(proxy_item))
| 252-883 | ||||||||||||||||||
640 | proxy_high = proxy_item - 1; executed 883 times by 5 tests: proxy_high = proxy_item - 1; Executed by:
| 883 | ||||||||||||||||||
641 | else | - | ||||||||||||||||||
642 | proxy_low = proxy_item + 1; executed 252 times by 7 tests: proxy_low = proxy_item + 1; Executed by:
| 252 | ||||||||||||||||||
643 | } | - | ||||||||||||||||||
644 | } | - | ||||||||||||||||||
645 | proxy_item = proxy_low; | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | // Find the sequence of new source items that should be inserted here | - | ||||||||||||||||||
648 | if (proxy_item >= proxy_to_source.size()) {
| 255-2062 | ||||||||||||||||||
649 | for ( ; source_items_index < source_items.size(); ++source_items_index)
| 2062-55128 | ||||||||||||||||||
650 | source_items_in_interval.append(source_items.at(source_items_index)); executed 55128 times by 6 tests: source_items_in_interval.append(source_items.at(source_items_index)); Executed by:
| 55128 | ||||||||||||||||||
651 | } else { executed 2062 times by 7 tests: end of block Executed by:
| 2062 | ||||||||||||||||||
652 | i1 = compare ? model->index(proxy_to_source.at(proxy_item), source_sort_column, source_parent) : QModelIndex();
| 14-241 | ||||||||||||||||||
653 | for ( ; source_items_index < source_items.size(); ++source_items_index) {
| 242-4845 | ||||||||||||||||||
654 | int new_source_item = source_items.at(source_items_index); | - | ||||||||||||||||||
655 | if (compare) {
| 18-4827 | ||||||||||||||||||
656 | QModelIndex i2 = model->index(new_source_item, source_sort_column, source_parent); | - | ||||||||||||||||||
657 | if ((sort_order == Qt::AscendingOrder) ? q->lessThan(i1, i2) : q->lessThan(i2, i1))
| 0-18 | ||||||||||||||||||
658 | break; executed 4 times by 2 tests: break; Executed by:
| 4 | ||||||||||||||||||
659 | } else { executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
660 | if (proxy_to_source.at(proxy_item) < new_source_item)
| 9-4818 | ||||||||||||||||||
661 | break; executed 9 times by 2 tests: break; Executed by:
| 9 | ||||||||||||||||||
662 | } executed 4818 times by 3 tests: end of block Executed by:
| 4818 | ||||||||||||||||||
663 | source_items_in_interval.append(new_source_item); | - | ||||||||||||||||||
664 | } executed 4832 times by 4 tests: end of block Executed by:
| 4832 | ||||||||||||||||||
665 | } executed 255 times by 7 tests: end of block Executed by:
| 255 | ||||||||||||||||||
666 | - | |||||||||||||||||||
667 | // Add interval to result | - | ||||||||||||||||||
668 | proxy_intervals.append(QPair<int, QVector<int> >(proxy_item, source_items_in_interval)); | - | ||||||||||||||||||
669 | } executed 2317 times by 9 tests: end of block Executed by:
| 2317 | ||||||||||||||||||
670 | return proxy_intervals; executed 2304 times by 9 tests: return proxy_intervals; Executed by:
| 2304 | ||||||||||||||||||
671 | } | - | ||||||||||||||||||
672 | - | |||||||||||||||||||
673 | /*! | - | ||||||||||||||||||
674 | \internal | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | Given source-to-proxy mapping \a source_to_proxy and proxy-to-source mapping | - | ||||||||||||||||||
677 | \a proxy_to_source, inserts the given \a source_items into this proxy model. | - | ||||||||||||||||||
678 | The source items are inserted in intervals (based on some sorted order), so | - | ||||||||||||||||||
679 | that the proper rows/columnsInserted(start, end) signals will be generated. | - | ||||||||||||||||||
680 | */ | - | ||||||||||||||||||
681 | void QSortFilterProxyModelPrivate::insert_source_items( | - | ||||||||||||||||||
682 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||
683 | const QVector<int> &source_items, const QModelIndex &source_parent, | - | ||||||||||||||||||
684 | Qt::Orientation orient, bool emit_signal) | - | ||||||||||||||||||
685 | { | - | ||||||||||||||||||
686 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
687 | QModelIndex proxy_parent = q->mapFromSource(source_parent); | - | ||||||||||||||||||
688 | if (!proxy_parent.isValid() && source_parent.isValid())
| 0-1683 | ||||||||||||||||||
689 | return; // nothing to do (source_parent is not mapped) never executed: return; | 0 | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | QVector<QPair<int, QVector<int> > > proxy_intervals; | - | ||||||||||||||||||
692 | proxy_intervals = proxy_intervals_for_source_items_to_add( | - | ||||||||||||||||||
693 | proxy_to_source, source_items, source_parent, orient); | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | for (int i = proxy_intervals.size()-1; i >= 0; --i) {
| 2317-2342 | ||||||||||||||||||
696 | QPair<int, QVector<int> > interval = proxy_intervals.at(i); | - | ||||||||||||||||||
697 | int proxy_start = interval.first; | - | ||||||||||||||||||
698 | QVector<int> source_items = interval.second; | - | ||||||||||||||||||
699 | int proxy_end = proxy_start + source_items.size() - 1; | - | ||||||||||||||||||
700 | - | |||||||||||||||||||
701 | if (emit_signal) {
| 13-2304 | ||||||||||||||||||
702 | if (orient == Qt::Vertical)
| 1143-1161 | ||||||||||||||||||
703 | q->beginInsertRows(proxy_parent, proxy_start, proxy_end); executed 1161 times by 9 tests: q->beginInsertRows(proxy_parent, proxy_start, proxy_end); Executed by:
| 1161 | ||||||||||||||||||
704 | else | - | ||||||||||||||||||
705 | q->beginInsertColumns(proxy_parent, proxy_start, proxy_end); executed 1143 times by 4 tests: q->beginInsertColumns(proxy_parent, proxy_start, proxy_end); Executed by:
| 1143 | ||||||||||||||||||
706 | } | - | ||||||||||||||||||
707 | - | |||||||||||||||||||
708 | for (int i = 0; i < source_items.size(); ++i)
| 2317-62277 | ||||||||||||||||||
709 | proxy_to_source.insert(proxy_start + i, source_items.at(i)); executed 62277 times by 9 tests: proxy_to_source.insert(proxy_start + i, source_items.at(i)); Executed by:
| 62277 | ||||||||||||||||||
710 | - | |||||||||||||||||||
711 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | if (emit_signal) {
| 13-2304 | ||||||||||||||||||
714 | if (orient == Qt::Vertical)
| 1143-1161 | ||||||||||||||||||
715 | q->endInsertRows(); executed 1161 times by 9 tests: q->endInsertRows(); Executed by:
| 1161 | ||||||||||||||||||
716 | else | - | ||||||||||||||||||
717 | q->endInsertColumns(); executed 1143 times by 4 tests: q->endInsertColumns(); Executed by:
| 1143 | ||||||||||||||||||
718 | } | - | ||||||||||||||||||
719 | } executed 2317 times by 9 tests: end of block Executed by:
| 2317 | ||||||||||||||||||
720 | } executed 2342 times by 9 tests: end of block Executed by:
| 2342 | ||||||||||||||||||
721 | - | |||||||||||||||||||
722 | /*! | - | ||||||||||||||||||
723 | \internal | - | ||||||||||||||||||
724 | - | |||||||||||||||||||
725 | Handles source model items insertion (columnsInserted(), rowsInserted()). | - | ||||||||||||||||||
726 | Determines | - | ||||||||||||||||||
727 | 1) which of the inserted items to also insert into proxy model (filtering), | - | ||||||||||||||||||
728 | 2) where to insert the items into the proxy model (sorting), | - | ||||||||||||||||||
729 | then inserts those items. | - | ||||||||||||||||||
730 | The items are inserted into the proxy model in intervals (based on | - | ||||||||||||||||||
731 | sorted order), so that the proper rows/columnsInserted(start, end) | - | ||||||||||||||||||
732 | signals will be generated. | - | ||||||||||||||||||
733 | */ | - | ||||||||||||||||||
734 | void QSortFilterProxyModelPrivate::source_items_inserted( | - | ||||||||||||||||||
735 | const QModelIndex &source_parent, int start, int end, Qt::Orientation orient) | - | ||||||||||||||||||
736 | { | - | ||||||||||||||||||
737 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
738 | if ((start < 0) || (end < 0))
| 0-2278 | ||||||||||||||||||
739 | return; never executed: return; | 0 | ||||||||||||||||||
740 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||
741 | if (it == source_index_mapping.constEnd()) {
| 3-2275 | ||||||||||||||||||
742 | if (!can_create_mapping(source_parent))
| 0-3 | ||||||||||||||||||
743 | return; executed 3 times by 2 tests: return; Executed by:
| 3 | ||||||||||||||||||
744 | it = create_mapping(source_parent); | - | ||||||||||||||||||
745 | Mapping *m = it.value(); | - | ||||||||||||||||||
746 | QModelIndex proxy_parent = q->mapFromSource(source_parent); | - | ||||||||||||||||||
747 | if (m->source_rows.count() > 0) {
| 0 | ||||||||||||||||||
748 | q->beginInsertRows(proxy_parent, 0, m->source_rows.count() - 1); | - | ||||||||||||||||||
749 | q->endInsertRows(); | - | ||||||||||||||||||
750 | } never executed: end of block | 0 | ||||||||||||||||||
751 | if (m->source_columns.count() > 0) {
| 0 | ||||||||||||||||||
752 | q->beginInsertColumns(proxy_parent, 0, m->source_columns.count() - 1); | - | ||||||||||||||||||
753 | q->endInsertColumns(); | - | ||||||||||||||||||
754 | } never executed: end of block | 0 | ||||||||||||||||||
755 | return; never executed: return; | 0 | ||||||||||||||||||
756 | } | - | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | Mapping *m = it.value(); | - | ||||||||||||||||||
759 | QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns;
| 1132-1143 | ||||||||||||||||||
760 | QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns;
| 1132-1143 | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | int delta_item_count = end - start + 1; | - | ||||||||||||||||||
763 | int old_item_count = source_to_proxy.size(); | - | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count, false); | - | ||||||||||||||||||
766 | - | |||||||||||||||||||
767 | // Expand source-to-proxy mapping to account for new items | - | ||||||||||||||||||
768 | if (start < 0 || start > source_to_proxy.size()) {
| 0-2275 | ||||||||||||||||||
769 | qWarning("QSortFilterProxyModel: invalid inserted rows reported by source model"); | - | ||||||||||||||||||
770 | remove_from_mapping(source_parent); | - | ||||||||||||||||||
771 | return; never executed: return; | 0 | ||||||||||||||||||
772 | } | - | ||||||||||||||||||
773 | source_to_proxy.insert(start, delta_item_count, -1); | - | ||||||||||||||||||
774 | - | |||||||||||||||||||
775 | if (start < old_item_count) {
| 234-2041 | ||||||||||||||||||
776 | // Adjust existing "stale" indexes in proxy-to-source mapping | - | ||||||||||||||||||
777 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||
778 | for (int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) {
| 234-6708 | ||||||||||||||||||
779 | int source_item = proxy_to_source.at(proxy_item); | - | ||||||||||||||||||
780 | if (source_item >= start)
| 567-6141 | ||||||||||||||||||
781 | proxy_to_source.replace(proxy_item, source_item + delta_item_count); executed 6141 times by 4 tests: proxy_to_source.replace(proxy_item, source_item + delta_item_count); Executed by:
| 6141 | ||||||||||||||||||
782 | } executed 6708 times by 4 tests: end of block Executed by:
| 6708 | ||||||||||||||||||
783 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||
784 | } executed 234 times by 4 tests: end of block Executed by:
| 234 | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | // Figure out which items to add to mapping based on filter | - | ||||||||||||||||||
787 | QVector<int> source_items; | - | ||||||||||||||||||
788 | for (int i = start; i <= end; ++i) {
| 2275-62229 | ||||||||||||||||||
789 | if ((orient == Qt::Vertical)
| 10-62219 | ||||||||||||||||||
790 | ? q->filterAcceptsRow(i, source_parent)
| 10-62219 | ||||||||||||||||||
791 | : q->filterAcceptsColumn(i, source_parent)) {
| 10-62219 | ||||||||||||||||||
792 | source_items.append(i); | - | ||||||||||||||||||
793 | } executed 62219 times by 7 tests: end of block Executed by:
| 62219 | ||||||||||||||||||
794 | } executed 62229 times by 7 tests: end of block Executed by:
| 62229 | ||||||||||||||||||
795 | - | |||||||||||||||||||
796 | if (model->rowCount(source_parent) == delta_item_count) {
| 509-1766 | ||||||||||||||||||
797 | // Items were inserted where there were none before. | - | ||||||||||||||||||
798 | // If it was new rows make sure to create mappings for columns so that a | - | ||||||||||||||||||
799 | // valid mapping can be retrieved later and vice-versa. | - | ||||||||||||||||||
800 | - | |||||||||||||||||||
801 | QVector<int> &orthogonal_proxy_to_source = (orient == Qt::Horizontal) ? m->source_rows : m->source_columns;
| 836-930 | ||||||||||||||||||
802 | QVector<int> &orthogonal_source_to_proxy = (orient == Qt::Horizontal) ? m->proxy_rows : m->proxy_columns;
| 836-930 | ||||||||||||||||||
803 | - | |||||||||||||||||||
804 | if (orthogonal_source_to_proxy.isEmpty()) {
| 843-923 | ||||||||||||||||||
805 | const int ortho_end = (orient == Qt::Horizontal) ? model->rowCount(source_parent) : model->columnCount(source_parent);
| 0-843 | ||||||||||||||||||
806 | - | |||||||||||||||||||
807 | orthogonal_source_to_proxy.resize(ortho_end); | - | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | for (int ortho_item = 0; ortho_item < ortho_end; ++ortho_item) {
| 12-843 | ||||||||||||||||||
810 | if ((orient == Qt::Horizontal) ? q->filterAcceptsRow(ortho_item, source_parent)
| 0-12 | ||||||||||||||||||
811 | : q->filterAcceptsColumn(ortho_item, source_parent)) {
| 1-11 | ||||||||||||||||||
812 | orthogonal_proxy_to_source.append(ortho_item); | - | ||||||||||||||||||
813 | } executed 11 times by 2 tests: end of block Executed by:
| 11 | ||||||||||||||||||
814 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
815 | if (orient == Qt::Horizontal) {
| 0-843 | ||||||||||||||||||
816 | // We're reacting to columnsInserted, but we've just inserted new rows. Sort them. | - | ||||||||||||||||||
817 | sort_source_rows(orthogonal_proxy_to_source, source_parent); | - | ||||||||||||||||||
818 | } never executed: end of block | 0 | ||||||||||||||||||
819 | build_source_to_proxy_mapping(orthogonal_proxy_to_source, orthogonal_source_to_proxy); | - | ||||||||||||||||||
820 | } executed 843 times by 3 tests: end of block Executed by:
| 843 | ||||||||||||||||||
821 | } executed 1766 times by 5 tests: end of block Executed by:
| 1766 | ||||||||||||||||||
822 | - | |||||||||||||||||||
823 | // Sort and insert the items | - | ||||||||||||||||||
824 | if (orient == Qt::Vertical) // Only sort rows
| 1132-1143 | ||||||||||||||||||
825 | sort_source_rows(source_items, source_parent); executed 1132 times by 7 tests: sort_source_rows(source_items, source_parent); Executed by:
| 1132 | ||||||||||||||||||
826 | insert_source_items(source_to_proxy, proxy_to_source, source_items, source_parent, orient); | - | ||||||||||||||||||
827 | } executed 2275 times by 7 tests: end of block Executed by:
| 2275 | ||||||||||||||||||
828 | - | |||||||||||||||||||
829 | /*! | - | ||||||||||||||||||
830 | \internal | - | ||||||||||||||||||
831 | - | |||||||||||||||||||
832 | Handles source model items removal | - | ||||||||||||||||||
833 | (columnsAboutToBeRemoved(), rowsAboutToBeRemoved()). | - | ||||||||||||||||||
834 | */ | - | ||||||||||||||||||
835 | void QSortFilterProxyModelPrivate::source_items_about_to_be_removed( | - | ||||||||||||||||||
836 | const QModelIndex &source_parent, int start, int end, Qt::Orientation orient) | - | ||||||||||||||||||
837 | { | - | ||||||||||||||||||
838 | if ((start < 0) || (end < 0))
| 0-82 | ||||||||||||||||||
839 | return; never executed: return; | 0 | ||||||||||||||||||
840 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||
841 | if (it == source_index_mapping.constEnd()) {
| 2-80 | ||||||||||||||||||
842 | // Don't care, since we don't have mapping for this index | - | ||||||||||||||||||
843 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||
844 | } | - | ||||||||||||||||||
845 | - | |||||||||||||||||||
846 | Mapping *m = it.value(); | - | ||||||||||||||||||
847 | QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns;
| 35-45 | ||||||||||||||||||
848 | QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns;
| 35-45 | ||||||||||||||||||
849 | - | |||||||||||||||||||
850 | // figure out which items to remove | - | ||||||||||||||||||
851 | QVector<int> source_items_to_remove; | - | ||||||||||||||||||
852 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||
853 | for (int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) {
| 80-2066 | ||||||||||||||||||
854 | int source_item = proxy_to_source.at(proxy_item); | - | ||||||||||||||||||
855 | if ((source_item >= start) && (source_item <= end))
| 517-1455 | ||||||||||||||||||
856 | source_items_to_remove.append(source_item); executed 517 times by 4 tests: source_items_to_remove.append(source_item); Executed by:
| 517 | ||||||||||||||||||
857 | } executed 2066 times by 4 tests: end of block Executed by:
| 2066 | ||||||||||||||||||
858 | - | |||||||||||||||||||
859 | remove_source_items(source_to_proxy, proxy_to_source, source_items_to_remove, | - | ||||||||||||||||||
860 | source_parent, orient); | - | ||||||||||||||||||
861 | } executed 80 times by 4 tests: end of block Executed by:
| 80 | ||||||||||||||||||
862 | - | |||||||||||||||||||
863 | /*! | - | ||||||||||||||||||
864 | \internal | - | ||||||||||||||||||
865 | - | |||||||||||||||||||
866 | Handles source model items removal (columnsRemoved(), rowsRemoved()). | - | ||||||||||||||||||
867 | */ | - | ||||||||||||||||||
868 | void QSortFilterProxyModelPrivate::source_items_removed( | - | ||||||||||||||||||
869 | const QModelIndex &source_parent, int start, int end, Qt::Orientation orient) | - | ||||||||||||||||||
870 | { | - | ||||||||||||||||||
871 | if ((start < 0) || (end < 0))
| 0-82 | ||||||||||||||||||
872 | return; never executed: return; | 0 | ||||||||||||||||||
873 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||
874 | if (it == source_index_mapping.constEnd()) {
| 2-80 | ||||||||||||||||||
875 | // Don't care, since we don't have mapping for this index | - | ||||||||||||||||||
876 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||
877 | } | - | ||||||||||||||||||
878 | - | |||||||||||||||||||
879 | Mapping *m = it.value(); | - | ||||||||||||||||||
880 | QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns;
| 35-45 | ||||||||||||||||||
881 | QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns;
| 35-45 | ||||||||||||||||||
882 | - | |||||||||||||||||||
883 | if (end >= source_to_proxy.size())
| 0-80 | ||||||||||||||||||
884 | end = source_to_proxy.size() - 1; never executed: end = source_to_proxy.size() - 1; | 0 | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | // Shrink the source-to-proxy mapping to reflect the new item count | - | ||||||||||||||||||
887 | int delta_item_count = end - start + 1; | - | ||||||||||||||||||
888 | source_to_proxy.remove(start, delta_item_count); | - | ||||||||||||||||||
889 | - | |||||||||||||||||||
890 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||
891 | if (proxy_count > source_to_proxy.size()) {
| 0-80 | ||||||||||||||||||
892 | // mapping is in an inconsistent state -- redo the whole mapping | - | ||||||||||||||||||
893 | qWarning("QSortFilterProxyModel: inconsistent changes reported by source model"); | - | ||||||||||||||||||
894 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
895 | q->beginResetModel(); | - | ||||||||||||||||||
896 | remove_from_mapping(source_parent); | - | ||||||||||||||||||
897 | q->endResetModel(); | - | ||||||||||||||||||
898 | return; never executed: return; | 0 | ||||||||||||||||||
899 | } | - | ||||||||||||||||||
900 | - | |||||||||||||||||||
901 | // Adjust "stale" indexes in proxy-to-source mapping | - | ||||||||||||||||||
902 | for (int proxy_item = 0; proxy_item < proxy_count; ++proxy_item) {
| 80-1549 | ||||||||||||||||||
903 | int source_item = proxy_to_source.at(proxy_item); | - | ||||||||||||||||||
904 | if (source_item >= start) {
| 611-938 | ||||||||||||||||||
905 | Q_ASSERT(source_item - delta_item_count >= 0); | - | ||||||||||||||||||
906 | proxy_to_source.replace(proxy_item, source_item - delta_item_count); | - | ||||||||||||||||||
907 | } executed 938 times by 4 tests: end of block Executed by:
| 938 | ||||||||||||||||||
908 | } executed 1549 times by 4 tests: end of block Executed by:
| 1549 | ||||||||||||||||||
909 | build_source_to_proxy_mapping(proxy_to_source, source_to_proxy); | - | ||||||||||||||||||
910 | - | |||||||||||||||||||
911 | updateChildrenMapping(source_parent, m, orient, start, end, delta_item_count, true); | - | ||||||||||||||||||
912 | - | |||||||||||||||||||
913 | } executed 80 times by 4 tests: end of block Executed by:
| 80 | ||||||||||||||||||
914 | - | |||||||||||||||||||
915 | - | |||||||||||||||||||
916 | /*! | - | ||||||||||||||||||
917 | \internal | - | ||||||||||||||||||
918 | updates the mapping of the children when inserting or removing items | - | ||||||||||||||||||
919 | */ | - | ||||||||||||||||||
920 | void QSortFilterProxyModelPrivate::updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping, | - | ||||||||||||||||||
921 | Qt::Orientation orient, int start, int end, int delta_item_count, bool remove) | - | ||||||||||||||||||
922 | { | - | ||||||||||||||||||
923 | // see if any mapped children should be (re)moved | - | ||||||||||||||||||
924 | QVector<QPair<QModelIndex, Mapping*> > moved_source_index_mappings; | - | ||||||||||||||||||
925 | QVector<QModelIndex>::iterator it2 = parent_mapping->mapped_children.begin(); | - | ||||||||||||||||||
926 | for ( ; it2 != parent_mapping->mapped_children.end();) {
| 330-2355 | ||||||||||||||||||
927 | const QModelIndex source_child_index = *it2; | - | ||||||||||||||||||
928 | const int pos = (orient == Qt::Vertical)
| 151-179 | ||||||||||||||||||
929 | ? source_child_index.row() | - | ||||||||||||||||||
930 | : source_child_index.column(); | - | ||||||||||||||||||
931 | if (pos < start) {
| 80-250 | ||||||||||||||||||
932 | // not affected | - | ||||||||||||||||||
933 | ++it2; | - | ||||||||||||||||||
934 | } else if (remove && pos <= end) { executed 80 times by 3 tests: end of block Executed by:
| 14-220 | ||||||||||||||||||
935 | // in the removed interval | - | ||||||||||||||||||
936 | it2 = parent_mapping->mapped_children.erase(it2); | - | ||||||||||||||||||
937 | remove_from_mapping(source_child_index); | - | ||||||||||||||||||
938 | } else { executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||||||||||||||
939 | // below the removed items -- recompute the index | - | ||||||||||||||||||
940 | QModelIndex new_index; | - | ||||||||||||||||||
941 | const int newpos = remove ? pos - delta_item_count : pos + delta_item_count;
| 16-220 | ||||||||||||||||||
942 | if (orient == Qt::Vertical) {
| 115-121 | ||||||||||||||||||
943 | new_index = model->index(newpos, | - | ||||||||||||||||||
944 | source_child_index.column(), | - | ||||||||||||||||||
945 | source_parent); | - | ||||||||||||||||||
946 | } else { executed 121 times by 2 tests: end of block Executed by:
| 121 | ||||||||||||||||||
947 | new_index = model->index(source_child_index.row(), | - | ||||||||||||||||||
948 | newpos, | - | ||||||||||||||||||
949 | source_parent); | - | ||||||||||||||||||
950 | } executed 115 times by 1 test: end of block Executed by:
| 115 | ||||||||||||||||||
951 | *it2 = new_index; | - | ||||||||||||||||||
952 | ++it2; | - | ||||||||||||||||||
953 | - | |||||||||||||||||||
954 | // update mapping | - | ||||||||||||||||||
955 | Mapping *cm = source_index_mapping.take(source_child_index); | - | ||||||||||||||||||
956 | Q_ASSERT(cm); | - | ||||||||||||||||||
957 | // we do not reinsert right away, because the new index might be identical with another, old index | - | ||||||||||||||||||
958 | moved_source_index_mappings.append(QPair<QModelIndex, Mapping*>(new_index, cm)); | - | ||||||||||||||||||
959 | } executed 236 times by 2 tests: end of block Executed by:
| 236 | ||||||||||||||||||
960 | } | - | ||||||||||||||||||
961 | - | |||||||||||||||||||
962 | // reinsert moved, mapped indexes | - | ||||||||||||||||||
963 | QVector<QPair<QModelIndex, Mapping*> >::iterator it = moved_source_index_mappings.begin(); | - | ||||||||||||||||||
964 | for (; it != moved_source_index_mappings.end(); ++it) {
| 236-2355 | ||||||||||||||||||
965 | #ifdef QT_STRICT_ITERATORS | - | ||||||||||||||||||
966 | source_index_mapping.insert((*it).first, (*it).second); | - | ||||||||||||||||||
967 | (*it).second->map_iter = source_index_mapping.constFind((*it).first); | - | ||||||||||||||||||
968 | #else | - | ||||||||||||||||||
969 | (*it).second->map_iter = source_index_mapping.insert((*it).first, (*it).second); | - | ||||||||||||||||||
970 | #endif | - | ||||||||||||||||||
971 | } executed 236 times by 2 tests: end of block Executed by:
| 236 | ||||||||||||||||||
972 | } executed 2355 times by 7 tests: end of block Executed by:
| 2355 | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | /*! | - | ||||||||||||||||||
975 | \internal | - | ||||||||||||||||||
976 | */ | - | ||||||||||||||||||
977 | void QSortFilterProxyModelPrivate::proxy_item_range( | - | ||||||||||||||||||
978 | const QVector<int> &source_to_proxy, const QVector<int> &source_items, | - | ||||||||||||||||||
979 | int &proxy_low, int &proxy_high) const | - | ||||||||||||||||||
980 | { | - | ||||||||||||||||||
981 | proxy_low = INT_MAX; | - | ||||||||||||||||||
982 | proxy_high = INT_MIN; | - | ||||||||||||||||||
983 | for (int i = 0; i < source_items.count(); ++i) {
| 6552 | ||||||||||||||||||
984 | int proxy_item = source_to_proxy.at(source_items.at(i)); | - | ||||||||||||||||||
985 | Q_ASSERT(proxy_item != -1); | - | ||||||||||||||||||
986 | if (proxy_item < proxy_low)
| 0-6552 | ||||||||||||||||||
987 | proxy_low = proxy_item; executed 6552 times by 4 tests: proxy_low = proxy_item; Executed by:
| 6552 | ||||||||||||||||||
988 | if (proxy_item > proxy_high)
| 0-6552 | ||||||||||||||||||
989 | proxy_high = proxy_item; executed 6552 times by 4 tests: proxy_high = proxy_item; Executed by:
| 6552 | ||||||||||||||||||
990 | } executed 6552 times by 4 tests: end of block Executed by:
| 6552 | ||||||||||||||||||
991 | } executed 6552 times by 4 tests: end of block Executed by:
| 6552 | ||||||||||||||||||
992 | - | |||||||||||||||||||
993 | /*! | - | ||||||||||||||||||
994 | \internal | - | ||||||||||||||||||
995 | */ | - | ||||||||||||||||||
996 | void QSortFilterProxyModelPrivate::build_source_to_proxy_mapping( | - | ||||||||||||||||||
997 | const QVector<int> &proxy_to_source, QVector<int> &source_to_proxy) const | - | ||||||||||||||||||
998 | { | - | ||||||||||||||||||
999 | source_to_proxy.fill(-1); | - | ||||||||||||||||||
1000 | int proxy_count = proxy_to_source.size(); | - | ||||||||||||||||||
1001 | for (int i = 0; i < proxy_count; ++i)
| 6389-111218 | ||||||||||||||||||
1002 | source_to_proxy[proxy_to_source.at(i)] = i; executed 111218 times by 13 tests: source_to_proxy[proxy_to_source.at(i)] = i; Executed by:
| 111218 | ||||||||||||||||||
1003 | } executed 6389 times by 13 tests: end of block Executed by:
| 6389 | ||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | /*! | - | ||||||||||||||||||
1006 | \internal | - | ||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | Maps the persistent proxy indexes to source indexes and | - | ||||||||||||||||||
1009 | returns the list of source indexes. | - | ||||||||||||||||||
1010 | */ | - | ||||||||||||||||||
1011 | QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes() | - | ||||||||||||||||||
1012 | { | - | ||||||||||||||||||
1013 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1014 | QModelIndexPairList source_indexes; | - | ||||||||||||||||||
1015 | source_indexes.reserve(persistent.indexes.count()); | - | ||||||||||||||||||
1016 | foreach (QPersistentModelIndexData *data, persistent.indexes) { | - | ||||||||||||||||||
1017 | QModelIndex proxy_index = data->index; | - | ||||||||||||||||||
1018 | QModelIndex source_index = q->mapToSource(proxy_index); | - | ||||||||||||||||||
1019 | source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(source_index))); | - | ||||||||||||||||||
1020 | } executed 402 times by 10 tests: end of block Executed by:
| 402 | ||||||||||||||||||
1021 | return source_indexes; executed 1118 times by 13 tests: return source_indexes; Executed by:
| 1118 | ||||||||||||||||||
1022 | } | - | ||||||||||||||||||
1023 | - | |||||||||||||||||||
1024 | /*! | - | ||||||||||||||||||
1025 | \internal | - | ||||||||||||||||||
1026 | - | |||||||||||||||||||
1027 | Maps \a source_indexes to proxy indexes and stores those | - | ||||||||||||||||||
1028 | as persistent indexes. | - | ||||||||||||||||||
1029 | */ | - | ||||||||||||||||||
1030 | void QSortFilterProxyModelPrivate::update_persistent_indexes( | - | ||||||||||||||||||
1031 | const QModelIndexPairList &source_indexes) | - | ||||||||||||||||||
1032 | { | - | ||||||||||||||||||
1033 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1034 | QModelIndexList from, to; | - | ||||||||||||||||||
1035 | const int numSourceIndexes = source_indexes.count(); | - | ||||||||||||||||||
1036 | from.reserve(numSourceIndexes); | - | ||||||||||||||||||
1037 | to.reserve(numSourceIndexes); | - | ||||||||||||||||||
1038 | for (int i = 0; i < numSourceIndexes; ++i) {
| 402-1123 | ||||||||||||||||||
1039 | QModelIndex source_index = source_indexes.at(i).second; | - | ||||||||||||||||||
1040 | QModelIndex old_proxy_index = source_indexes.at(i).first; | - | ||||||||||||||||||
1041 | create_mapping(source_index.parent()); | - | ||||||||||||||||||
1042 | QModelIndex proxy_index = q->mapFromSource(source_index); | - | ||||||||||||||||||
1043 | from << old_proxy_index; | - | ||||||||||||||||||
1044 | to << proxy_index; | - | ||||||||||||||||||
1045 | } executed 402 times by 10 tests: end of block Executed by:
| 402 | ||||||||||||||||||
1046 | q->changePersistentIndexList(from, to); | - | ||||||||||||||||||
1047 | } executed 1123 times by 13 tests: end of block Executed by:
| 1123 | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | /*! | - | ||||||||||||||||||
1050 | \internal | - | ||||||||||||||||||
1051 | - | |||||||||||||||||||
1052 | Updates the source_index mapping in case it's invalid and we | - | ||||||||||||||||||
1053 | need it because we have a valid filter | - | ||||||||||||||||||
1054 | */ | - | ||||||||||||||||||
1055 | void QSortFilterProxyModelPrivate::filter_about_to_be_changed(const QModelIndex &source_parent) | - | ||||||||||||||||||
1056 | { | - | ||||||||||||||||||
1057 | if (!filter_regexp.pattern().isEmpty() &&
| 25-204 | ||||||||||||||||||
1058 | source_index_mapping.constFind(source_parent) == source_index_mapping.constEnd())
| 1-24 | ||||||||||||||||||
1059 | create_mapping(source_parent); executed 1 time by 1 test: create_mapping(source_parent); Executed by:
| 1 | ||||||||||||||||||
1060 | } executed 229 times by 5 tests: end of block Executed by:
| 229 | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | /*! | - | ||||||||||||||||||
1064 | \internal | - | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | Updates the proxy model (adds/removes rows) based on the | - | ||||||||||||||||||
1067 | new filter. | - | ||||||||||||||||||
1068 | */ | - | ||||||||||||||||||
1069 | void QSortFilterProxyModelPrivate::filter_changed(const QModelIndex &source_parent) | - | ||||||||||||||||||
1070 | { | - | ||||||||||||||||||
1071 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||
1072 | if (it == source_index_mapping.constEnd())
| 14-393 | ||||||||||||||||||
1073 | return; executed 14 times by 1 test: return; Executed by:
| 14 | ||||||||||||||||||
1074 | Mapping *m = it.value(); | - | ||||||||||||||||||
1075 | QSet<int> rows_removed = handle_filter_changed(m->proxy_rows, m->source_rows, source_parent, Qt::Vertical); | - | ||||||||||||||||||
1076 | QSet<int> columns_removed = handle_filter_changed(m->proxy_columns, m->source_columns, source_parent, Qt::Horizontal); | - | ||||||||||||||||||
1077 | - | |||||||||||||||||||
1078 | // We need to iterate over a copy of m->mapped_children because otherwise it may be changed by other code, invalidating | - | ||||||||||||||||||
1079 | // the iterator it2. | - | ||||||||||||||||||
1080 | // The m->mapped_children vector can be appended to with indexes which are no longer filtered | - | ||||||||||||||||||
1081 | // out (in create_mapping) when this function recurses for child indexes. | - | ||||||||||||||||||
1082 | const QVector<QModelIndex> mappedChildren = m->mapped_children; | - | ||||||||||||||||||
1083 | QVector<int> indexesToRemove; | - | ||||||||||||||||||
1084 | for (int i = 0; i < mappedChildren.size(); ++i) {
| 178-393 | ||||||||||||||||||
1085 | const QModelIndex source_child_index = mappedChildren.at(i); | - | ||||||||||||||||||
1086 | if (rows_removed.contains(source_child_index.row()) || columns_removed.contains(source_child_index.column())) {
| 0-175 | ||||||||||||||||||
1087 | indexesToRemove.push_back(i); | - | ||||||||||||||||||
1088 | remove_from_mapping(source_child_index); | - | ||||||||||||||||||
1089 | } else { executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1090 | filter_changed(source_child_index); | - | ||||||||||||||||||
1091 | } executed 175 times by 3 tests: end of block Executed by:
| 175 | ||||||||||||||||||
1092 | } | - | ||||||||||||||||||
1093 | QVector<int>::const_iterator removeIt = indexesToRemove.constEnd(); | - | ||||||||||||||||||
1094 | const QVector<int>::const_iterator removeBegin = indexesToRemove.constBegin(); | - | ||||||||||||||||||
1095 | - | |||||||||||||||||||
1096 | // We can't just remove these items from mappedChildren while iterating above and then | - | ||||||||||||||||||
1097 | // do something like m->mapped_children = mappedChildren, because mapped_children might | - | ||||||||||||||||||
1098 | // be appended to in create_mapping, and we would lose those new items. | - | ||||||||||||||||||
1099 | // Because they are always appended in create_mapping, we can still remove them by | - | ||||||||||||||||||
1100 | // position here. | - | ||||||||||||||||||
1101 | while (removeIt != removeBegin) {
| 3-393 | ||||||||||||||||||
1102 | --removeIt; | - | ||||||||||||||||||
1103 | m->mapped_children.remove(*removeIt); | - | ||||||||||||||||||
1104 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1105 | } executed 393 times by 5 tests: end of block Executed by:
| 393 | ||||||||||||||||||
1106 | - | |||||||||||||||||||
1107 | /*! | - | ||||||||||||||||||
1108 | \internal | - | ||||||||||||||||||
1109 | returns the removed items indexes | - | ||||||||||||||||||
1110 | */ | - | ||||||||||||||||||
1111 | QSet<int> QSortFilterProxyModelPrivate::handle_filter_changed( | - | ||||||||||||||||||
1112 | QVector<int> &source_to_proxy, QVector<int> &proxy_to_source, | - | ||||||||||||||||||
1113 | const QModelIndex &source_parent, Qt::Orientation orient) | - | ||||||||||||||||||
1114 | { | - | ||||||||||||||||||
1115 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1116 | // Figure out which mapped items to remove | - | ||||||||||||||||||
1117 | QVector<int> source_items_remove; | - | ||||||||||||||||||
1118 | for (int i = 0; i < proxy_to_source.count(); ++i) {
| 786-21737 | ||||||||||||||||||
1119 | const int source_item = proxy_to_source.at(i); | - | ||||||||||||||||||
1120 | if ((orient == Qt::Vertical)
| 86-21651 | ||||||||||||||||||
1121 | ? !q->filterAcceptsRow(source_item, source_parent)
| 86-21651 | ||||||||||||||||||
1122 | : !q->filterAcceptsColumn(source_item, source_parent)) {
| 86-21651 | ||||||||||||||||||
1123 | // This source item does not satisfy the filter, so it must be removed | - | ||||||||||||||||||
1124 | source_items_remove.append(source_item); | - | ||||||||||||||||||
1125 | } executed 86 times by 4 tests: end of block Executed by:
| 86 | ||||||||||||||||||
1126 | } executed 21737 times by 5 tests: end of block Executed by:
| 21737 | ||||||||||||||||||
1127 | // Figure out which non-mapped items to insert | - | ||||||||||||||||||
1128 | QVector<int> source_items_insert; | - | ||||||||||||||||||
1129 | int source_count = source_to_proxy.size(); | - | ||||||||||||||||||
1130 | for (int source_item = 0; source_item < source_count; ++source_item) {
| 786-21795 | ||||||||||||||||||
1131 | if (source_to_proxy.at(source_item) == -1) {
| 58-21737 | ||||||||||||||||||
1132 | if ((orient == Qt::Vertical)
| 0-58 | ||||||||||||||||||
1133 | ? q->filterAcceptsRow(source_item, source_parent)
| 16-42 | ||||||||||||||||||
1134 | : q->filterAcceptsColumn(source_item, source_parent)) {
| 16-42 | ||||||||||||||||||
1135 | // This source item satisfies the filter, so it must be added | - | ||||||||||||||||||
1136 | source_items_insert.append(source_item); | - | ||||||||||||||||||
1137 | } executed 42 times by 3 tests: end of block Executed by:
| 42 | ||||||||||||||||||
1138 | } executed 58 times by 3 tests: end of block Executed by:
| 58 | ||||||||||||||||||
1139 | } executed 21795 times by 5 tests: end of block Executed by:
| 21795 | ||||||||||||||||||
1140 | if (!source_items_remove.isEmpty() || !source_items_insert.isEmpty()) {
| 13-748 | ||||||||||||||||||
1141 | // Do item removal and insertion | - | ||||||||||||||||||
1142 | remove_source_items(source_to_proxy, proxy_to_source, | - | ||||||||||||||||||
1143 | source_items_remove, source_parent, orient); | - | ||||||||||||||||||
1144 | if (orient == Qt::Vertical)
| 0-51 | ||||||||||||||||||
1145 | sort_source_rows(source_items_insert, source_parent); executed 51 times by 4 tests: sort_source_rows(source_items_insert, source_parent); Executed by:
| 51 | ||||||||||||||||||
1146 | insert_source_items(source_to_proxy, proxy_to_source, | - | ||||||||||||||||||
1147 | source_items_insert, source_parent, orient); | - | ||||||||||||||||||
1148 | } executed 51 times by 4 tests: end of block Executed by:
| 51 | ||||||||||||||||||
1149 | return qVectorToSet(source_items_remove); executed 786 times by 5 tests: return qVectorToSet(source_items_remove); Executed by:
| 786 | ||||||||||||||||||
1150 | } | - | ||||||||||||||||||
1151 | - | |||||||||||||||||||
1152 | void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &source_top_left, | - | ||||||||||||||||||
1153 | const QModelIndex &source_bottom_right, | - | ||||||||||||||||||
1154 | const QVector<int> &roles) | - | ||||||||||||||||||
1155 | { | - | ||||||||||||||||||
1156 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1157 | if (!source_top_left.isValid() || !source_bottom_right.isValid())
| 0-6863 | ||||||||||||||||||
1158 | return; never executed: return; | 0 | ||||||||||||||||||
1159 | QModelIndex source_parent = source_top_left.parent(); | - | ||||||||||||||||||
1160 | IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); | - | ||||||||||||||||||
1161 | if (it == source_index_mapping.constEnd()) {
| 6-6857 | ||||||||||||||||||
1162 | // Don't care, since we don't have mapping for this index | - | ||||||||||||||||||
1163 | return; executed 6 times by 1 test: return; Executed by:
| 6 | ||||||||||||||||||
1164 | } | - | ||||||||||||||||||
1165 | Mapping *m = it.value(); | - | ||||||||||||||||||
1166 | - | |||||||||||||||||||
1167 | // Figure out how the source changes affect us | - | ||||||||||||||||||
1168 | QVector<int> source_rows_remove; | - | ||||||||||||||||||
1169 | QVector<int> source_rows_insert; | - | ||||||||||||||||||
1170 | QVector<int> source_rows_change; | - | ||||||||||||||||||
1171 | QVector<int> source_rows_resort; | - | ||||||||||||||||||
1172 | int end = qMin(source_bottom_right.row(), m->proxy_rows.count() - 1); | - | ||||||||||||||||||
1173 | for (int source_row = source_top_left.row(); source_row <= end; ++source_row) {
| 6857 | ||||||||||||||||||
1174 | if (dynamic_sortfilter) {
| 7-6850 | ||||||||||||||||||
1175 | if (m->proxy_rows.at(source_row) != -1) {
| 304-6546 | ||||||||||||||||||
1176 | if (!q->filterAcceptsRow(source_row, source_parent)) {
| 1-6545 | ||||||||||||||||||
1177 | // This source row no longer satisfies the filter, so it must be removed | - | ||||||||||||||||||
1178 | source_rows_remove.append(source_row); | - | ||||||||||||||||||
1179 | } else if (source_sort_column >= source_top_left.column() && source_sort_column <= source_bottom_right.column()) { executed 1 time by 1 test: end of block Executed by:
| 0-6532 | ||||||||||||||||||
1180 | // This source row has changed in a way that may affect sorted order | - | ||||||||||||||||||
1181 | source_rows_resort.append(source_row); | - | ||||||||||||||||||
1182 | } else { executed 13 times by 2 tests: end of block Executed by:
| 13 | ||||||||||||||||||
1183 | // This row has simply changed, without affecting filtering nor sorting | - | ||||||||||||||||||
1184 | source_rows_change.append(source_row); | - | ||||||||||||||||||
1185 | } executed 6532 times by 3 tests: end of block Executed by:
| 6532 | ||||||||||||||||||
1186 | } else { | - | ||||||||||||||||||
1187 | if (!itemsBeingRemoved.contains(source_parent, source_row) && q->filterAcceptsRow(source_row, source_parent)) {
| 0-304 | ||||||||||||||||||
1188 | // This source row now satisfies the filter, so it must be added | - | ||||||||||||||||||
1189 | source_rows_insert.append(source_row); | - | ||||||||||||||||||
1190 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1191 | } executed 304 times by 2 tests: end of block Executed by:
| 304 | ||||||||||||||||||
1192 | } else { | - | ||||||||||||||||||
1193 | if (m->proxy_rows.at(source_row) != -1)
| 0-7 | ||||||||||||||||||
1194 | source_rows_change.append(source_row); executed 7 times by 1 test: source_rows_change.append(source_row); Executed by:
| 7 | ||||||||||||||||||
1195 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
1196 | } | - | ||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | if (!source_rows_remove.isEmpty()) {
| 1-6856 | ||||||||||||||||||
1199 | remove_source_items(m->proxy_rows, m->source_rows, | - | ||||||||||||||||||
1200 | source_rows_remove, source_parent, Qt::Vertical); | - | ||||||||||||||||||
1201 | QSet<int> source_rows_remove_set = qVectorToSet(source_rows_remove); | - | ||||||||||||||||||
1202 | QVector<QModelIndex>::iterator childIt = m->mapped_children.end(); | - | ||||||||||||||||||
1203 | while (childIt != m->mapped_children.begin()) {
| 1 | ||||||||||||||||||
1204 | --childIt; | - | ||||||||||||||||||
1205 | const QModelIndex source_child_index = *childIt; | - | ||||||||||||||||||
1206 | if (source_rows_remove_set.contains(source_child_index.row())) {
| 0-1 | ||||||||||||||||||
1207 | childIt = m->mapped_children.erase(childIt); | - | ||||||||||||||||||
1208 | remove_from_mapping(source_child_index); | - | ||||||||||||||||||
1209 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
1210 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
1211 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
1212 | - | |||||||||||||||||||
1213 | if (!source_rows_resort.isEmpty()) {
| 13-6844 | ||||||||||||||||||
1214 | // Re-sort the rows of this level | - | ||||||||||||||||||
1215 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
1216 | parents << q->mapFromSource(source_parent); | - | ||||||||||||||||||
1217 | emit q->layoutAboutToBeChanged(parents, QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||
1218 | QModelIndexPairList source_indexes = store_persistent_indexes(); | - | ||||||||||||||||||
1219 | remove_source_items(m->proxy_rows, m->source_rows, source_rows_resort, | - | ||||||||||||||||||
1220 | source_parent, Qt::Vertical, false); | - | ||||||||||||||||||
1221 | sort_source_rows(source_rows_resort, source_parent); | - | ||||||||||||||||||
1222 | insert_source_items(m->proxy_rows, m->source_rows, source_rows_resort, | - | ||||||||||||||||||
1223 | source_parent, Qt::Vertical, false); | - | ||||||||||||||||||
1224 | update_persistent_indexes(source_indexes); | - | ||||||||||||||||||
1225 | emit q->layoutChanged(parents, QAbstractItemModel::VerticalSortHint); | - | ||||||||||||||||||
1226 | // Make sure we also emit dataChanged for the rows | - | ||||||||||||||||||
1227 | source_rows_change += source_rows_resort; | - | ||||||||||||||||||
1228 | } executed 13 times by 2 tests: end of block Executed by:
| 13 | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | if (!source_rows_change.isEmpty()) {
| 305-6552 | ||||||||||||||||||
1231 | // Find the proxy row range | - | ||||||||||||||||||
1232 | int proxy_start_row; | - | ||||||||||||||||||
1233 | int proxy_end_row; | - | ||||||||||||||||||
1234 | proxy_item_range(m->proxy_rows, source_rows_change, | - | ||||||||||||||||||
1235 | proxy_start_row, proxy_end_row); | - | ||||||||||||||||||
1236 | // ### Find the proxy column range also | - | ||||||||||||||||||
1237 | if (proxy_end_row >= 0) {
| 0-6552 | ||||||||||||||||||
1238 | // the row was accepted, but some columns might still be filtered out | - | ||||||||||||||||||
1239 | int source_left_column = source_top_left.column(); | - | ||||||||||||||||||
1240 | while (source_left_column < source_bottom_right.column()
| 0-6552 | ||||||||||||||||||
1241 | && m->proxy_columns.at(source_left_column) == -1)
| 0 | ||||||||||||||||||
1242 | ++source_left_column; never executed: ++source_left_column; | 0 | ||||||||||||||||||
1243 | const QModelIndex proxy_top_left = create_index( | - | ||||||||||||||||||
1244 | proxy_start_row, m->proxy_columns.at(source_left_column), it); | - | ||||||||||||||||||
1245 | int source_right_column = source_bottom_right.column(); | - | ||||||||||||||||||
1246 | while (source_right_column > source_top_left.column()
| 0-6552 | ||||||||||||||||||
1247 | && m->proxy_columns.at(source_right_column) == -1)
| 0 | ||||||||||||||||||
1248 | --source_right_column; never executed: --source_right_column; | 0 | ||||||||||||||||||
1249 | const QModelIndex proxy_bottom_right = create_index( | - | ||||||||||||||||||
1250 | proxy_end_row, m->proxy_columns.at(source_right_column), it); | - | ||||||||||||||||||
1251 | emit q->dataChanged(proxy_top_left, proxy_bottom_right, roles); | - | ||||||||||||||||||
1252 | } executed 6552 times by 4 tests: end of block Executed by:
| 6552 | ||||||||||||||||||
1253 | } executed 6552 times by 4 tests: end of block Executed by:
| 6552 | ||||||||||||||||||
1254 | - | |||||||||||||||||||
1255 | if (!source_rows_insert.isEmpty()) {
| 3-6854 | ||||||||||||||||||
1256 | sort_source_rows(source_rows_insert, source_parent); | - | ||||||||||||||||||
1257 | insert_source_items(m->proxy_rows, m->source_rows, | - | ||||||||||||||||||
1258 | source_rows_insert, source_parent, Qt::Vertical); | - | ||||||||||||||||||
1259 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1260 | } executed 6857 times by 4 tests: end of block Executed by:
| 6857 | ||||||||||||||||||
1261 | - | |||||||||||||||||||
1262 | void QSortFilterProxyModelPrivate::_q_sourceHeaderDataChanged(Qt::Orientation orientation, | - | ||||||||||||||||||
1263 | int start, int end) | - | ||||||||||||||||||
1264 | { | - | ||||||||||||||||||
1265 | Q_ASSERT(start <= end); | - | ||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1268 | Mapping *m = create_mapping(QModelIndex()).value(); | - | ||||||||||||||||||
1269 | - | |||||||||||||||||||
1270 | const QVector<int> &source_to_proxy = (orientation == Qt::Vertical) ? m->proxy_rows : m->proxy_columns;
| 9-120 | ||||||||||||||||||
1271 | - | |||||||||||||||||||
1272 | QVector<int> proxy_positions; | - | ||||||||||||||||||
1273 | proxy_positions.reserve(end - start + 1); | - | ||||||||||||||||||
1274 | { | - | ||||||||||||||||||
1275 | Q_ASSERT(source_to_proxy.size() > end); | - | ||||||||||||||||||
1276 | QVector<int>::const_iterator it = source_to_proxy.constBegin() + start; | - | ||||||||||||||||||
1277 | const QVector<int>::const_iterator endIt = source_to_proxy.constBegin() + end + 1; | - | ||||||||||||||||||
1278 | for ( ; it != endIt; ++it) {
| 129-138 | ||||||||||||||||||
1279 | if (*it != -1)
| 16-122 | ||||||||||||||||||
1280 | proxy_positions.push_back(*it); executed 122 times by 3 tests: proxy_positions.push_back(*it); Executed by:
| 122 | ||||||||||||||||||
1281 | } executed 138 times by 3 tests: end of block Executed by:
| 138 | ||||||||||||||||||
1282 | } | - | ||||||||||||||||||
1283 | - | |||||||||||||||||||
1284 | std::sort(proxy_positions.begin(), proxy_positions.end()); | - | ||||||||||||||||||
1285 | - | |||||||||||||||||||
1286 | int last_index = 0; | - | ||||||||||||||||||
1287 | const int numItems = proxy_positions.size(); | - | ||||||||||||||||||
1288 | while (last_index < numItems) {
| 113-129 | ||||||||||||||||||
1289 | const int proxyStart = proxy_positions.at(last_index); | - | ||||||||||||||||||
1290 | int proxyEnd = proxyStart; | - | ||||||||||||||||||
1291 | ++last_index; | - | ||||||||||||||||||
1292 | for (int i = last_index; i < numItems; ++i) {
| 9-113 | ||||||||||||||||||
1293 | if (proxy_positions.at(i) == proxyEnd + 1) {
| 0-9 | ||||||||||||||||||
1294 | ++last_index; | - | ||||||||||||||||||
1295 | ++proxyEnd; | - | ||||||||||||||||||
1296 | } else { executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||
1297 | break; never executed: break; | 0 | ||||||||||||||||||
1298 | } | - | ||||||||||||||||||
1299 | } | - | ||||||||||||||||||
1300 | emit q->headerDataChanged(orientation, proxyStart, proxyEnd); | - | ||||||||||||||||||
1301 | } executed 113 times by 3 tests: end of block Executed by:
| 113 | ||||||||||||||||||
1302 | } executed 129 times by 3 tests: end of block Executed by:
| 129 | ||||||||||||||||||
1303 | - | |||||||||||||||||||
1304 | void QSortFilterProxyModelPrivate::_q_sourceAboutToBeReset() | - | ||||||||||||||||||
1305 | { | - | ||||||||||||||||||
1306 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1307 | q->beginResetModel(); | - | ||||||||||||||||||
1308 | } executed 126 times by 4 tests: end of block Executed by:
| 126 | ||||||||||||||||||
1309 | - | |||||||||||||||||||
1310 | void QSortFilterProxyModelPrivate::_q_sourceReset() | - | ||||||||||||||||||
1311 | { | - | ||||||||||||||||||
1312 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1313 | invalidatePersistentIndexes(); | - | ||||||||||||||||||
1314 | _q_clearMapping(); | - | ||||||||||||||||||
1315 | // All internal structures are deleted in clear() | - | ||||||||||||||||||
1316 | q->endResetModel(); | - | ||||||||||||||||||
1317 | update_source_sort_column(); | - | ||||||||||||||||||
1318 | if (dynamic_sortfilter)
| 0-126 | ||||||||||||||||||
1319 | sort(); executed 126 times by 4 tests: sort(); Executed by:
| 126 | ||||||||||||||||||
1320 | } executed 126 times by 4 tests: end of block Executed by:
| 126 | ||||||||||||||||||
1321 | - | |||||||||||||||||||
1322 | void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint) | - | ||||||||||||||||||
1323 | { | - | ||||||||||||||||||
1324 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1325 | Q_UNUSED(hint); // We can't forward Hint because we might filter additional rows or columns | - | ||||||||||||||||||
1326 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||
1327 | - | |||||||||||||||||||
1328 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
1329 | foreach (const QPersistentModelIndex &parent, sourceParents) { | - | ||||||||||||||||||
1330 | if (!parent.isValid()) {
| 4-5 | ||||||||||||||||||
1331 | parents << QPersistentModelIndex(); | - | ||||||||||||||||||
1332 | continue; executed 4 times by 2 tests: continue; Executed by:
| 4 | ||||||||||||||||||
1333 | } | - | ||||||||||||||||||
1334 | const QModelIndex mappedParent = q->mapFromSource(parent); | - | ||||||||||||||||||
1335 | // Might be filtered out. | - | ||||||||||||||||||
1336 | if (mappedParent.isValid())
| 2-3 | ||||||||||||||||||
1337 | parents << mappedParent; executed 2 times by 1 test: parents << mappedParent; Executed by:
| 2 | ||||||||||||||||||
1338 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
1339 | - | |||||||||||||||||||
1340 | // All parents filtered out. | - | ||||||||||||||||||
1341 | if (!sourceParents.isEmpty() && parents.isEmpty())
| 1-7 | ||||||||||||||||||
1342 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
1343 | - | |||||||||||||||||||
1344 | emit q->layoutAboutToBeChanged(parents); | - | ||||||||||||||||||
1345 | if (persistent.indexes.isEmpty())
| 4-6 | ||||||||||||||||||
1346 | return; executed 4 times by 2 tests: return; Executed by:
| 4 | ||||||||||||||||||
1347 | - | |||||||||||||||||||
1348 | saved_persistent_indexes = store_persistent_indexes(); | - | ||||||||||||||||||
1349 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||
1350 | - | |||||||||||||||||||
1351 | void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint) | - | ||||||||||||||||||
1352 | { | - | ||||||||||||||||||
1353 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1354 | Q_UNUSED(hint); // We can't forward Hint because we might filter additional rows or columns | - | ||||||||||||||||||
1355 | - | |||||||||||||||||||
1356 | // Optimize: We only actually have to clear the mapping related to the contents of | - | ||||||||||||||||||
1357 | // sourceParents, not everything. | - | ||||||||||||||||||
1358 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
1359 | source_index_mapping.clear(); | - | ||||||||||||||||||
1360 | - | |||||||||||||||||||
1361 | update_persistent_indexes(saved_persistent_indexes); | - | ||||||||||||||||||
1362 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||
1363 | - | |||||||||||||||||||
1364 | if (dynamic_sortfilter && update_source_sort_column()) {
| 0-11 | ||||||||||||||||||
1365 | //update_source_sort_column might have created wrong mapping so we have to clear it again | - | ||||||||||||||||||
1366 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
1367 | source_index_mapping.clear(); | - | ||||||||||||||||||
1368 | } never executed: end of block | 0 | ||||||||||||||||||
1369 | - | |||||||||||||||||||
1370 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
1371 | foreach (const QPersistentModelIndex &parent, sourceParents) { | - | ||||||||||||||||||
1372 | if (!parent.isValid()) {
| 4-5 | ||||||||||||||||||
1373 | parents << QPersistentModelIndex(); | - | ||||||||||||||||||
1374 | continue; executed 4 times by 2 tests: continue; Executed by:
| 4 | ||||||||||||||||||
1375 | } | - | ||||||||||||||||||
1376 | const QModelIndex mappedParent = q->mapFromSource(parent); | - | ||||||||||||||||||
1377 | if (mappedParent.isValid())
| 2-3 | ||||||||||||||||||
1378 | parents << mappedParent; executed 2 times by 1 test: parents << mappedParent; Executed by:
| 2 | ||||||||||||||||||
1379 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
1380 | - | |||||||||||||||||||
1381 | if (!sourceParents.isEmpty() && parents.isEmpty())
| 1-7 | ||||||||||||||||||
1382 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
1383 | - | |||||||||||||||||||
1384 | emit q->layoutChanged(parents); | - | ||||||||||||||||||
1385 | } executed 10 times by 3 tests: end of block Executed by:
| 10 | ||||||||||||||||||
1386 | - | |||||||||||||||||||
1387 | void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeInserted( | - | ||||||||||||||||||
1388 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1389 | { | - | ||||||||||||||||||
1390 | Q_UNUSED(start); | - | ||||||||||||||||||
1391 | Q_UNUSED(end); | - | ||||||||||||||||||
1392 | //Force the creation of a mapping now, even if its empty. | - | ||||||||||||||||||
1393 | //We need it because the proxy can be acessed at the moment it emits rowsAboutToBeInserted in insert_source_items | - | ||||||||||||||||||
1394 | if (can_create_mapping(source_parent))
| 2-1132 | ||||||||||||||||||
1395 | create_mapping(source_parent); executed 1132 times by 7 tests: create_mapping(source_parent); Executed by:
| 1132 | ||||||||||||||||||
1396 | } executed 1134 times by 7 tests: end of block Executed by:
| 1134 | ||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | void QSortFilterProxyModelPrivate::_q_sourceRowsInserted( | - | ||||||||||||||||||
1399 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1400 | { | - | ||||||||||||||||||
1401 | source_items_inserted(source_parent, start, end, Qt::Vertical); | - | ||||||||||||||||||
1402 | if (update_source_sort_column() && dynamic_sortfilter) //previous call to update_source_sort_column may fail if the model has no column.
| 0-1134 | ||||||||||||||||||
1403 | sort(); // now it should succeed so we need to make sure to sort again never executed: sort(); | 0 | ||||||||||||||||||
1404 | } executed 1134 times by 7 tests: end of block Executed by:
| 1134 | ||||||||||||||||||
1405 | - | |||||||||||||||||||
1406 | void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeRemoved( | - | ||||||||||||||||||
1407 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1408 | { | - | ||||||||||||||||||
1409 | itemsBeingRemoved = QRowsRemoval(source_parent, start, end); | - | ||||||||||||||||||
1410 | source_items_about_to_be_removed(source_parent, start, end, | - | ||||||||||||||||||
1411 | Qt::Vertical); | - | ||||||||||||||||||
1412 | } executed 47 times by 4 tests: end of block Executed by:
| 47 | ||||||||||||||||||
1413 | - | |||||||||||||||||||
1414 | void QSortFilterProxyModelPrivate::_q_sourceRowsRemoved( | - | ||||||||||||||||||
1415 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1416 | { | - | ||||||||||||||||||
1417 | itemsBeingRemoved = QRowsRemoval(); | - | ||||||||||||||||||
1418 | source_items_removed(source_parent, start, end, Qt::Vertical); | - | ||||||||||||||||||
1419 | } executed 47 times by 4 tests: end of block Executed by:
| 47 | ||||||||||||||||||
1420 | - | |||||||||||||||||||
1421 | void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeMoved( | - | ||||||||||||||||||
1422 | const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) | - | ||||||||||||||||||
1423 | { | - | ||||||||||||||||||
1424 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1425 | // Because rows which are contiguous in the source model might not be contiguous | - | ||||||||||||||||||
1426 | // in the proxy due to sorting, the best thing we can do here is be specific about what | - | ||||||||||||||||||
1427 | // parents are having their children changed. | - | ||||||||||||||||||
1428 | // Optimize: Emit move signals if the proxy is not sorted. Will need to account for rows | - | ||||||||||||||||||
1429 | // being filtered out though. | - | ||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
1434 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||
1435 | if (sourceParent != destParent)
| 0-4 | ||||||||||||||||||
1436 | parents << q->mapFromSource(destParent); executed 4 times by 3 tests: parents << q->mapFromSource(destParent); Executed by:
| 4 | ||||||||||||||||||
1437 | emit q->layoutAboutToBeChanged(parents); | - | ||||||||||||||||||
1438 | if (persistent.indexes.isEmpty())
| 0-4 | ||||||||||||||||||
1439 | return; never executed: return; | 0 | ||||||||||||||||||
1440 | saved_persistent_indexes = store_persistent_indexes(); | - | ||||||||||||||||||
1441 | } executed 4 times by 3 tests: end of block Executed by:
| 4 | ||||||||||||||||||
1442 | - | |||||||||||||||||||
1443 | void QSortFilterProxyModelPrivate::_q_sourceRowsMoved( | - | ||||||||||||||||||
1444 | const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) | - | ||||||||||||||||||
1445 | { | - | ||||||||||||||||||
1446 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | // Optimize: We only need to clear and update the persistent indexes which are children of | - | ||||||||||||||||||
1449 | // sourceParent or destParent | - | ||||||||||||||||||
1450 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
1451 | source_index_mapping.clear(); | - | ||||||||||||||||||
1452 | - | |||||||||||||||||||
1453 | update_persistent_indexes(saved_persistent_indexes); | - | ||||||||||||||||||
1454 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||
1455 | - | |||||||||||||||||||
1456 | if (dynamic_sortfilter && update_source_sort_column()) {
| 0-4 | ||||||||||||||||||
1457 | //update_source_sort_column might have created wrong mapping so we have to clear it again | - | ||||||||||||||||||
1458 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
1459 | source_index_mapping.clear(); | - | ||||||||||||||||||
1460 | } never executed: end of block | 0 | ||||||||||||||||||
1461 | - | |||||||||||||||||||
1462 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
1463 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||
1464 | if (sourceParent != destParent)
| 0-4 | ||||||||||||||||||
1465 | parents << q->mapFromSource(destParent); executed 4 times by 3 tests: parents << q->mapFromSource(destParent); Executed by:
| 4 | ||||||||||||||||||
1466 | emit q->layoutChanged(parents); | - | ||||||||||||||||||
1467 | } executed 4 times by 3 tests: end of block Executed by:
| 4 | ||||||||||||||||||
1468 | - | |||||||||||||||||||
1469 | void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeInserted( | - | ||||||||||||||||||
1470 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1471 | { | - | ||||||||||||||||||
1472 | Q_UNUSED(start); | - | ||||||||||||||||||
1473 | Q_UNUSED(end); | - | ||||||||||||||||||
1474 | //Force the creation of a mapping now, even if its empty. | - | ||||||||||||||||||
1475 | //We need it because the proxy can be acessed at the moment it emits columnsAboutToBeInserted in insert_source_items | - | ||||||||||||||||||
1476 | if (can_create_mapping(source_parent))
| 1-1143 | ||||||||||||||||||
1477 | create_mapping(source_parent); executed 1143 times by 4 tests: create_mapping(source_parent); Executed by:
| 1143 | ||||||||||||||||||
1478 | } executed 1144 times by 4 tests: end of block Executed by:
| 1144 | ||||||||||||||||||
1479 | - | |||||||||||||||||||
1480 | void QSortFilterProxyModelPrivate::_q_sourceColumnsInserted( | - | ||||||||||||||||||
1481 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1482 | { | - | ||||||||||||||||||
1483 | Q_Q(const QSortFilterProxyModel); | - | ||||||||||||||||||
1484 | source_items_inserted(source_parent, start, end, Qt::Horizontal); | - | ||||||||||||||||||
1485 | - | |||||||||||||||||||
1486 | if (source_parent.isValid())
| 318-826 | ||||||||||||||||||
1487 | return; //we sort according to the root column only executed 826 times by 3 tests: return; Executed by:
| 826 | ||||||||||||||||||
1488 | if (source_sort_column == -1) {
| 3-315 | ||||||||||||||||||
1489 | //we update the source_sort_column depending on the proxy_sort_column | - | ||||||||||||||||||
1490 | if (update_source_sort_column() && dynamic_sortfilter)
| 0-314 | ||||||||||||||||||
1491 | sort(); executed 1 time by 1 test: sort(); Executed by:
| 1 | ||||||||||||||||||
1492 | } else { executed 315 times by 4 tests: end of block Executed by:
| 315 | ||||||||||||||||||
1493 | if (start <= source_sort_column)
| 1-2 | ||||||||||||||||||
1494 | source_sort_column += end - start + 1; executed 1 time by 1 test: source_sort_column += end - start + 1; Executed by:
| 1 | ||||||||||||||||||
1495 | - | |||||||||||||||||||
1496 | proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column(); | - | ||||||||||||||||||
1497 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1498 | } | - | ||||||||||||||||||
1499 | - | |||||||||||||||||||
1500 | void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeRemoved( | - | ||||||||||||||||||
1501 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1502 | { | - | ||||||||||||||||||
1503 | source_items_about_to_be_removed(source_parent, start, end, | - | ||||||||||||||||||
1504 | Qt::Horizontal); | - | ||||||||||||||||||
1505 | } executed 35 times by 3 tests: end of block Executed by:
| 35 | ||||||||||||||||||
1506 | - | |||||||||||||||||||
1507 | void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( | - | ||||||||||||||||||
1508 | const QModelIndex &source_parent, int start, int end) | - | ||||||||||||||||||
1509 | { | - | ||||||||||||||||||
1510 | Q_Q(const QSortFilterProxyModel); | - | ||||||||||||||||||
1511 | source_items_removed(source_parent, start, end, Qt::Horizontal); | - | ||||||||||||||||||
1512 | - | |||||||||||||||||||
1513 | if (source_parent.isValid())
| 13-22 | ||||||||||||||||||
1514 | return; //we sort according to the root column only executed 22 times by 2 tests: return; Executed by:
| 22 | ||||||||||||||||||
1515 | if (start <= source_sort_column) {
| 2-11 | ||||||||||||||||||
1516 | if (end < source_sort_column)
| 1 | ||||||||||||||||||
1517 | source_sort_column -= end - start + 1; executed 1 time by 1 test: source_sort_column -= end - start + 1; Executed by:
| 1 | ||||||||||||||||||
1518 | else | - | ||||||||||||||||||
1519 | source_sort_column = -1; executed 1 time by 1 test: source_sort_column = -1; Executed by:
| 1 | ||||||||||||||||||
1520 | } | - | ||||||||||||||||||
1521 | - | |||||||||||||||||||
1522 | proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column(); | - | ||||||||||||||||||
1523 | } executed 13 times by 2 tests: end of block Executed by:
| 13 | ||||||||||||||||||
1524 | - | |||||||||||||||||||
1525 | void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeMoved( | - | ||||||||||||||||||
1526 | const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) | - | ||||||||||||||||||
1527 | { | - | ||||||||||||||||||
1528 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1529 | - | |||||||||||||||||||
1530 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
1533 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||
1534 | if (sourceParent != destParent)
| 0 | ||||||||||||||||||
1535 | parents << q->mapFromSource(destParent); never executed: parents << q->mapFromSource(destParent); | 0 | ||||||||||||||||||
1536 | emit q->layoutAboutToBeChanged(parents); | - | ||||||||||||||||||
1537 | - | |||||||||||||||||||
1538 | if (persistent.indexes.isEmpty())
| 0 | ||||||||||||||||||
1539 | return; never executed: return; | 0 | ||||||||||||||||||
1540 | saved_persistent_indexes = store_persistent_indexes(); | - | ||||||||||||||||||
1541 | } never executed: end of block | 0 | ||||||||||||||||||
1542 | - | |||||||||||||||||||
1543 | void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved( | - | ||||||||||||||||||
1544 | const QModelIndex &sourceParent, int /* sourceStart */, int /* sourceEnd */, const QModelIndex &destParent, int /* dest */) | - | ||||||||||||||||||
1545 | { | - | ||||||||||||||||||
1546 | Q_Q(QSortFilterProxyModel); | - | ||||||||||||||||||
1547 | - | |||||||||||||||||||
1548 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
1549 | source_index_mapping.clear(); | - | ||||||||||||||||||
1550 | - | |||||||||||||||||||
1551 | update_persistent_indexes(saved_persistent_indexes); | - | ||||||||||||||||||
1552 | saved_persistent_indexes.clear(); | - | ||||||||||||||||||
1553 | - | |||||||||||||||||||
1554 | if (dynamic_sortfilter && update_source_sort_column()) {
| 0 | ||||||||||||||||||
1555 | qDeleteAll(source_index_mapping); | - | ||||||||||||||||||
1556 | source_index_mapping.clear(); | - | ||||||||||||||||||
1557 | } never executed: end of block | 0 | ||||||||||||||||||
1558 | - | |||||||||||||||||||
1559 | QList<QPersistentModelIndex> parents; | - | ||||||||||||||||||
1560 | parents << q->mapFromSource(sourceParent); | - | ||||||||||||||||||
1561 | if (sourceParent != destParent)
| 0 | ||||||||||||||||||
1562 | parents << q->mapFromSource(destParent); never executed: parents << q->mapFromSource(destParent); | 0 | ||||||||||||||||||
1563 | emit q->layoutChanged(parents); | - | ||||||||||||||||||
1564 | } never executed: end of block | 0 | ||||||||||||||||||
1565 | - | |||||||||||||||||||
1566 | /*! | - | ||||||||||||||||||
1567 | \since 4.1 | - | ||||||||||||||||||
1568 | \class QSortFilterProxyModel | - | ||||||||||||||||||
1569 | \inmodule QtCore | - | ||||||||||||||||||
1570 | \brief The QSortFilterProxyModel class provides support for sorting and | - | ||||||||||||||||||
1571 | filtering data passed between another model and a view. | - | ||||||||||||||||||
1572 | - | |||||||||||||||||||
1573 | \ingroup model-view | - | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | QSortFilterProxyModel can be used for sorting items, filtering out items, | - | ||||||||||||||||||
1576 | or both. The model transforms the structure of a source model by mapping | - | ||||||||||||||||||
1577 | the model indexes it supplies to new indexes, corresponding to different | - | ||||||||||||||||||
1578 | locations, for views to use. This approach allows a given source model to | - | ||||||||||||||||||
1579 | be restructured as far as views are concerned without requiring any | - | ||||||||||||||||||
1580 | transformations on the underlying data, and without duplicating the data in | - | ||||||||||||||||||
1581 | memory. | - | ||||||||||||||||||
1582 | - | |||||||||||||||||||
1583 | Let's assume that we want to sort and filter the items provided by a custom | - | ||||||||||||||||||
1584 | model. The code to set up the model and the view, \e without sorting and | - | ||||||||||||||||||
1585 | filtering, would look like this: | - | ||||||||||||||||||
1586 | - | |||||||||||||||||||
1587 | \snippet qsortfilterproxymodel-details/main.cpp 1 | - | ||||||||||||||||||
1588 | - | |||||||||||||||||||
1589 | To add sorting and filtering support to \c MyItemModel, we need to create | - | ||||||||||||||||||
1590 | a QSortFilterProxyModel, call setSourceModel() with the \c MyItemModel as | - | ||||||||||||||||||
1591 | argument, and install the QSortFilterProxyModel on the view: | - | ||||||||||||||||||
1592 | - | |||||||||||||||||||
1593 | \snippet qsortfilterproxymodel-details/main.cpp 0 | - | ||||||||||||||||||
1594 | \snippet qsortfilterproxymodel-details/main.cpp 2 | - | ||||||||||||||||||
1595 | - | |||||||||||||||||||
1596 | At this point, neither sorting nor filtering is enabled; the original data | - | ||||||||||||||||||
1597 | is displayed in the view. Any changes made through the | - | ||||||||||||||||||
1598 | QSortFilterProxyModel are applied to the original model. | - | ||||||||||||||||||
1599 | - | |||||||||||||||||||
1600 | The QSortFilterProxyModel acts as a wrapper for the original model. If you | - | ||||||||||||||||||
1601 | need to convert source \l{QModelIndex}es to sorted/filtered model indexes | - | ||||||||||||||||||
1602 | or vice versa, use mapToSource(), mapFromSource(), mapSelectionToSource(), | - | ||||||||||||||||||
1603 | and mapSelectionFromSource(). | - | ||||||||||||||||||
1604 | - | |||||||||||||||||||
1605 | \note By default, the model dynamically re-sorts and re-filters data | - | ||||||||||||||||||
1606 | whenever the original model changes. This behavior can be changed by | - | ||||||||||||||||||
1607 | setting the \l{QSortFilterProxyModel::dynamicSortFilter}{dynamicSortFilter} | - | ||||||||||||||||||
1608 | property. | - | ||||||||||||||||||
1609 | - | |||||||||||||||||||
1610 | The \l{itemviews/basicsortfiltermodel}{Basic Sort/Filter Model} and | - | ||||||||||||||||||
1611 | \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} examples | - | ||||||||||||||||||
1612 | illustrate how to use QSortFilterProxyModel to perform basic sorting and | - | ||||||||||||||||||
1613 | filtering and how to subclass it to implement custom behavior. | - | ||||||||||||||||||
1614 | - | |||||||||||||||||||
1615 | \section1 Sorting | - | ||||||||||||||||||
1616 | - | |||||||||||||||||||
1617 | QTableView and QTreeView have a | - | ||||||||||||||||||
1618 | \l{QTreeView::sortingEnabled}{sortingEnabled} property that controls | - | ||||||||||||||||||
1619 | whether the user can sort the view by clicking the view's horizontal | - | ||||||||||||||||||
1620 | header. For example: | - | ||||||||||||||||||
1621 | - | |||||||||||||||||||
1622 | \snippet qsortfilterproxymodel-details/main.cpp 3 | - | ||||||||||||||||||
1623 | - | |||||||||||||||||||
1624 | When this feature is on (the default is off), clicking on a header section | - | ||||||||||||||||||
1625 | sorts the items according to that column. By clicking repeatedly, the user | - | ||||||||||||||||||
1626 | can alternate between ascending and descending order. | - | ||||||||||||||||||
1627 | - | |||||||||||||||||||
1628 | \image qsortfilterproxymodel-sorting.png A sorted QTreeView | - | ||||||||||||||||||
1629 | - | |||||||||||||||||||
1630 | Behind the scene, the view calls the sort() virtual function on the model | - | ||||||||||||||||||
1631 | to reorder the data in the model. To make your data sortable, you can | - | ||||||||||||||||||
1632 | either implement sort() in your model, or use a QSortFilterProxyModel to | - | ||||||||||||||||||
1633 | wrap your model -- QSortFilterProxyModel provides a generic sort() | - | ||||||||||||||||||
1634 | reimplementation that operates on the sortRole() (Qt::DisplayRole by | - | ||||||||||||||||||
1635 | default) of the items and that understands several data types, including | - | ||||||||||||||||||
1636 | \c int, QString, and QDateTime. For hierarchical models, sorting is applied | - | ||||||||||||||||||
1637 | recursively to all child items. String comparisons are case sensitive by | - | ||||||||||||||||||
1638 | default; this can be changed by setting the \l{QSortFilterProxyModel::} | - | ||||||||||||||||||
1639 | {sortCaseSensitivity} property. | - | ||||||||||||||||||
1640 | - | |||||||||||||||||||
1641 | Custom sorting behavior is achieved by subclassing | - | ||||||||||||||||||
1642 | QSortFilterProxyModel and reimplementing lessThan(), which is | - | ||||||||||||||||||
1643 | used to compare items. For example: | - | ||||||||||||||||||
1644 | - | |||||||||||||||||||
1645 | \snippet ../widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 5 | - | ||||||||||||||||||
1646 | - | |||||||||||||||||||
1647 | (This code snippet comes from the | - | ||||||||||||||||||
1648 | \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} | - | ||||||||||||||||||
1649 | example.) | - | ||||||||||||||||||
1650 | - | |||||||||||||||||||
1651 | An alternative approach to sorting is to disable sorting on the view and to | - | ||||||||||||||||||
1652 | impose a certain order to the user. This is done by explicitly calling | - | ||||||||||||||||||
1653 | sort() with the desired column and order as arguments on the | - | ||||||||||||||||||
1654 | QSortFilterProxyModel (or on the original model if it implements sort()). | - | ||||||||||||||||||
1655 | For example: | - | ||||||||||||||||||
1656 | - | |||||||||||||||||||
1657 | \snippet qsortfilterproxymodel-details/main.cpp 4 | - | ||||||||||||||||||
1658 | - | |||||||||||||||||||
1659 | QSortFilterProxyModel can be sorted by column -1, in which case it returns | - | ||||||||||||||||||
1660 | to the sort order of the underlying source model. | - | ||||||||||||||||||
1661 | - | |||||||||||||||||||
1662 | \section1 Filtering | - | ||||||||||||||||||
1663 | - | |||||||||||||||||||
1664 | In addition to sorting, QSortFilterProxyModel can be used to hide items | - | ||||||||||||||||||
1665 | that do not match a certain filter. The filter is specified using a QRegExp | - | ||||||||||||||||||
1666 | object and is applied to the filterRole() (Qt::DisplayRole by default) of | - | ||||||||||||||||||
1667 | each item, for a given column. The QRegExp object can be used to match a | - | ||||||||||||||||||
1668 | regular expression, a wildcard pattern, or a fixed string. For example: | - | ||||||||||||||||||
1669 | - | |||||||||||||||||||
1670 | \snippet qsortfilterproxymodel-details/main.cpp 5 | - | ||||||||||||||||||
1671 | - | |||||||||||||||||||
1672 | For hierarchical models, the filter is applied recursively to all children. | - | ||||||||||||||||||
1673 | If a parent item doesn't match the filter, none of its children will be | - | ||||||||||||||||||
1674 | shown. | - | ||||||||||||||||||
1675 | - | |||||||||||||||||||
1676 | A common use case is to let the user specify the filter regexp, wildcard | - | ||||||||||||||||||
1677 | pattern, or fixed string in a QLineEdit and to connect the | - | ||||||||||||||||||
1678 | \l{QLineEdit::textChanged()}{textChanged()} signal to setFilterRegExp(), | - | ||||||||||||||||||
1679 | setFilterWildcard(), or setFilterFixedString() to reapply the filter. | - | ||||||||||||||||||
1680 | - | |||||||||||||||||||
1681 | Custom filtering behavior can be achieved by reimplementing the | - | ||||||||||||||||||
1682 | filterAcceptsRow() and filterAcceptsColumn() functions. For | - | ||||||||||||||||||
1683 | example (from the \l{itemviews/customsortfiltermodel} | - | ||||||||||||||||||
1684 | {Custom Sort/Filter Model} example), the following implementation ignores | - | ||||||||||||||||||
1685 | the \l{QSortFilterProxyModel::filterKeyColumn}{filterKeyColumn} property | - | ||||||||||||||||||
1686 | and performs filtering on columns 0, 1, and 2: | - | ||||||||||||||||||
1687 | - | |||||||||||||||||||
1688 | \snippet ../widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 3 | - | ||||||||||||||||||
1689 | - | |||||||||||||||||||
1690 | (This code snippet comes from the | - | ||||||||||||||||||
1691 | \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} | - | ||||||||||||||||||
1692 | example.) | - | ||||||||||||||||||
1693 | - | |||||||||||||||||||
1694 | If you are working with large amounts of filtering and have to invoke | - | ||||||||||||||||||
1695 | invalidateFilter() repeatedly, using reset() may be more efficient, | - | ||||||||||||||||||
1696 | depending on the implementation of your model. However, reset() returns the | - | ||||||||||||||||||
1697 | proxy model to its original state, losing selection information, and will | - | ||||||||||||||||||
1698 | cause the proxy model to be repopulated. | - | ||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | \section1 Subclassing | - | ||||||||||||||||||
1701 | - | |||||||||||||||||||
1702 | Since QAbstractProxyModel and its subclasses are derived from | - | ||||||||||||||||||
1703 | QAbstractItemModel, much of the same advice about subclassing normal models | - | ||||||||||||||||||
1704 | also applies to proxy models. In addition, it is worth noting that many of | - | ||||||||||||||||||
1705 | the default implementations of functions in this class are written so that | - | ||||||||||||||||||
1706 | they call the equivalent functions in the relevant source model. This | - | ||||||||||||||||||
1707 | simple proxying mechanism may need to be overridden for source models with | - | ||||||||||||||||||
1708 | more complex behavior; for example, if the source model provides a custom | - | ||||||||||||||||||
1709 | hasChildren() implementation, you should also provide one in the proxy | - | ||||||||||||||||||
1710 | model. | - | ||||||||||||||||||
1711 | - | |||||||||||||||||||
1712 | \note Some general guidelines for subclassing models are available in the | - | ||||||||||||||||||
1713 | \l{Model Subclassing Reference}. | - | ||||||||||||||||||
1714 | - | |||||||||||||||||||
1715 | \sa QAbstractProxyModel, QAbstractItemModel, {Model/View Programming}, | - | ||||||||||||||||||
1716 | {Basic Sort/Filter Model Example}, {Custom Sort/Filter Model Example}, QIdentityProxyModel | - | ||||||||||||||||||
1717 | */ | - | ||||||||||||||||||
1718 | - | |||||||||||||||||||
1719 | /*! | - | ||||||||||||||||||
1720 | Constructs a sorting filter model with the given \a parent. | - | ||||||||||||||||||
1721 | */ | - | ||||||||||||||||||
1722 | - | |||||||||||||||||||
1723 | QSortFilterProxyModel::QSortFilterProxyModel(QObject *parent) | - | ||||||||||||||||||
1724 | : QAbstractProxyModel(*new QSortFilterProxyModelPrivate, parent) | - | ||||||||||||||||||
1725 | { | - | ||||||||||||||||||
1726 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
1727 | d->proxy_sort_column = d->source_sort_column = -1; | - | ||||||||||||||||||
1728 | d->sort_order = Qt::AscendingOrder; | - | ||||||||||||||||||
1729 | d->sort_casesensitivity = Qt::CaseSensitive; | - | ||||||||||||||||||
1730 | d->sort_role = Qt::DisplayRole; | - | ||||||||||||||||||
1731 | d->sort_localeaware = false; | - | ||||||||||||||||||
1732 | d->filter_column = 0; | - | ||||||||||||||||||
1733 | d->filter_role = Qt::DisplayRole; | - | ||||||||||||||||||
1734 | d->dynamic_sortfilter = true; | - | ||||||||||||||||||
1735 | connect(this, SIGNAL(modelReset()), this, SLOT(_q_clearMapping())); | - | ||||||||||||||||||
1736 | } executed 282 times by 13 tests: end of block Executed by:
| 282 | ||||||||||||||||||
1737 | - | |||||||||||||||||||
1738 | /*! | - | ||||||||||||||||||
1739 | Destroys this sorting filter model. | - | ||||||||||||||||||
1740 | */ | - | ||||||||||||||||||
1741 | QSortFilterProxyModel::~QSortFilterProxyModel() | - | ||||||||||||||||||
1742 | { | - | ||||||||||||||||||
1743 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
1744 | qDeleteAll(d->source_index_mapping); | - | ||||||||||||||||||
1745 | d->source_index_mapping.clear(); | - | ||||||||||||||||||
1746 | } executed 278 times by 15 tests: end of block Executed by:
| 278 | ||||||||||||||||||
1747 | - | |||||||||||||||||||
1748 | /*! | - | ||||||||||||||||||
1749 | \reimp | - | ||||||||||||||||||
1750 | */ | - | ||||||||||||||||||
1751 | void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel) | - | ||||||||||||||||||
1752 | { | - | ||||||||||||||||||
1753 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
1754 | - | |||||||||||||||||||
1755 | beginResetModel(); | - | ||||||||||||||||||
1756 | - | |||||||||||||||||||
1757 | disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), | - | ||||||||||||||||||
1758 | this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>))); | - | ||||||||||||||||||
1759 | - | |||||||||||||||||||
1760 | disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), | - | ||||||||||||||||||
1761 | this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int))); | - | ||||||||||||||||||
1762 | - | |||||||||||||||||||
1763 | disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1764 | this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1765 | - | |||||||||||||||||||
1766 | disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1767 | this, SLOT(_q_sourceRowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1768 | - | |||||||||||||||||||
1769 | disconnect(d->model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1770 | this, SLOT(_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1771 | - | |||||||||||||||||||
1772 | disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1773 | this, SLOT(_q_sourceColumnsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1774 | - | |||||||||||||||||||
1775 | disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1776 | this, SLOT(_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1777 | - | |||||||||||||||||||
1778 | disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1779 | this, SLOT(_q_sourceRowsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1780 | - | |||||||||||||||||||
1781 | disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1782 | this, SLOT(_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1783 | - | |||||||||||||||||||
1784 | disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1785 | this, SLOT(_q_sourceColumnsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1786 | - | |||||||||||||||||||
1787 | disconnect(d->model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1788 | this, SLOT(_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1789 | - | |||||||||||||||||||
1790 | disconnect(d->model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1791 | this, SLOT(_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1792 | - | |||||||||||||||||||
1793 | disconnect(d->model, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1794 | this, SLOT(_q_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1795 | - | |||||||||||||||||||
1796 | disconnect(d->model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1797 | this, SLOT(_q_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1798 | - | |||||||||||||||||||
1799 | disconnect(d->model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)), | - | ||||||||||||||||||
1800 | this, SLOT(_q_sourceLayoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint))); | - | ||||||||||||||||||
1801 | - | |||||||||||||||||||
1802 | disconnect(d->model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)), | - | ||||||||||||||||||
1803 | this, SLOT(_q_sourceLayoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint))); | - | ||||||||||||||||||
1804 | - | |||||||||||||||||||
1805 | disconnect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceAboutToBeReset())); | - | ||||||||||||||||||
1806 | disconnect(d->model, SIGNAL(modelReset()), this, SLOT(_q_sourceReset())); | - | ||||||||||||||||||
1807 | - | |||||||||||||||||||
1808 | QAbstractProxyModel::setSourceModel(sourceModel); | - | ||||||||||||||||||
1809 | - | |||||||||||||||||||
1810 | connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), | - | ||||||||||||||||||
1811 | this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>))); | - | ||||||||||||||||||
1812 | - | |||||||||||||||||||
1813 | connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), | - | ||||||||||||||||||
1814 | this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int))); | - | ||||||||||||||||||
1815 | - | |||||||||||||||||||
1816 | connect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1817 | this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1818 | - | |||||||||||||||||||
1819 | connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1820 | this, SLOT(_q_sourceRowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1821 | - | |||||||||||||||||||
1822 | connect(d->model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1823 | this, SLOT(_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1824 | - | |||||||||||||||||||
1825 | connect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||
1826 | this, SLOT(_q_sourceColumnsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||
1827 | - | |||||||||||||||||||
1828 | connect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1829 | this, SLOT(_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1830 | - | |||||||||||||||||||
1831 | connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1832 | this, SLOT(_q_sourceRowsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1833 | - | |||||||||||||||||||
1834 | connect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1835 | this, SLOT(_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1836 | - | |||||||||||||||||||
1837 | connect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||
1838 | this, SLOT(_q_sourceColumnsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||
1839 | - | |||||||||||||||||||
1840 | connect(d->model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1841 | this, SLOT(_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1842 | - | |||||||||||||||||||
1843 | connect(d->model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1844 | this, SLOT(_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1845 | - | |||||||||||||||||||
1846 | connect(d->model, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1847 | this, SLOT(_q_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1848 | - | |||||||||||||||||||
1849 | connect(d->model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||
1850 | this, SLOT(_q_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||
1851 | - | |||||||||||||||||||
1852 | connect(d->model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)), | - | ||||||||||||||||||
1853 | this, SLOT(_q_sourceLayoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint))); | - | ||||||||||||||||||
1854 | - | |||||||||||||||||||
1855 | connect(d->model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)), | - | ||||||||||||||||||
1856 | this, SLOT(_q_sourceLayoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint))); | - | ||||||||||||||||||
1857 | - | |||||||||||||||||||
1858 | connect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceAboutToBeReset())); | - | ||||||||||||||||||
1859 | connect(d->model, SIGNAL(modelReset()), this, SLOT(_q_sourceReset())); | - | ||||||||||||||||||
1860 | - | |||||||||||||||||||
1861 | d->_q_clearMapping(); | - | ||||||||||||||||||
1862 | endResetModel(); | - | ||||||||||||||||||
1863 | if (d->update_source_sort_column() && d->dynamic_sortfilter)
| 0-287 | ||||||||||||||||||
1864 | d->sort(); never executed: d->sort(); | 0 | ||||||||||||||||||
1865 | } executed 288 times by 13 tests: end of block Executed by:
| 288 | ||||||||||||||||||
1866 | - | |||||||||||||||||||
1867 | /*! | - | ||||||||||||||||||
1868 | \reimp | - | ||||||||||||||||||
1869 | */ | - | ||||||||||||||||||
1870 | QModelIndex QSortFilterProxyModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||
1871 | { | - | ||||||||||||||||||
1872 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1873 | if (row < 0 || column < 0)
| 166-80969 | ||||||||||||||||||
1874 | return QModelIndex(); executed 575 times by 3 tests: return QModelIndex(); Executed by:
| 575 | ||||||||||||||||||
1875 | - | |||||||||||||||||||
1876 | QModelIndex source_parent = mapToSource(parent); // parent is already mapped at this point | - | ||||||||||||||||||
1877 | IndexMap::const_iterator it = d->create_mapping(source_parent); // but make sure that the children are mapped | - | ||||||||||||||||||
1878 | if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column)
| 60-80330 | ||||||||||||||||||
1879 | return QModelIndex(); executed 290 times by 7 tests: return QModelIndex(); Executed by:
| 290 | ||||||||||||||||||
1880 | - | |||||||||||||||||||
1881 | return d->create_index(row, column, it); executed 80270 times by 13 tests: return d->create_index(row, column, it); Executed by:
| 80270 | ||||||||||||||||||
1882 | } | - | ||||||||||||||||||
1883 | - | |||||||||||||||||||
1884 | /*! | - | ||||||||||||||||||
1885 | \reimp | - | ||||||||||||||||||
1886 | */ | - | ||||||||||||||||||
1887 | QModelIndex QSortFilterProxyModel::parent(const QModelIndex &child) const | - | ||||||||||||||||||
1888 | { | - | ||||||||||||||||||
1889 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1890 | if (!d->indexValid(child))
| 144-20919 | ||||||||||||||||||
1891 | return QModelIndex(); executed 144 times by 3 tests: return QModelIndex(); Executed by:
| 144 | ||||||||||||||||||
1892 | IndexMap::const_iterator it = d->index_to_iterator(child); | - | ||||||||||||||||||
1893 | Q_ASSERT(it != d->source_index_mapping.constEnd()); | - | ||||||||||||||||||
1894 | QModelIndex source_parent = it.key(); | - | ||||||||||||||||||
1895 | QModelIndex proxy_parent = mapFromSource(source_parent); | - | ||||||||||||||||||
1896 | return proxy_parent; executed 20919 times by 12 tests: return proxy_parent; Executed by:
| 20919 | ||||||||||||||||||
1897 | } | - | ||||||||||||||||||
1898 | - | |||||||||||||||||||
1899 | /*! | - | ||||||||||||||||||
1900 | \reimp | - | ||||||||||||||||||
1901 | */ | - | ||||||||||||||||||
1902 | QModelIndex QSortFilterProxyModel::sibling(int row, int column, const QModelIndex &idx) const | - | ||||||||||||||||||
1903 | { | - | ||||||||||||||||||
1904 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1905 | if (!d->indexValid(idx))
| 48-17009 | ||||||||||||||||||
1906 | return QModelIndex(); executed 48 times by 3 tests: return QModelIndex(); Executed by:
| 48 | ||||||||||||||||||
1907 | - | |||||||||||||||||||
1908 | const IndexMap::const_iterator it = d->index_to_iterator(idx); | - | ||||||||||||||||||
1909 | if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column)
| 0-17009 | ||||||||||||||||||
1910 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
1911 | - | |||||||||||||||||||
1912 | return d->create_index(row, column, it); executed 17009 times by 7 tests: return d->create_index(row, column, it); Executed by:
| 17009 | ||||||||||||||||||
1913 | } | - | ||||||||||||||||||
1914 | - | |||||||||||||||||||
1915 | /*! | - | ||||||||||||||||||
1916 | \reimp | - | ||||||||||||||||||
1917 | */ | - | ||||||||||||||||||
1918 | int QSortFilterProxyModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||
1919 | { | - | ||||||||||||||||||
1920 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1921 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||
1922 | if (parent.isValid() && !source_parent.isValid())
| 0-38779 | ||||||||||||||||||
1923 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1924 | IndexMap::const_iterator it = d->create_mapping(source_parent); | - | ||||||||||||||||||
1925 | return it.value()->source_rows.count(); executed 45528 times by 12 tests: return it.value()->source_rows.count(); Executed by:
| 45528 | ||||||||||||||||||
1926 | } | - | ||||||||||||||||||
1927 | - | |||||||||||||||||||
1928 | /*! | - | ||||||||||||||||||
1929 | \reimp | - | ||||||||||||||||||
1930 | */ | - | ||||||||||||||||||
1931 | int QSortFilterProxyModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||||||||
1932 | { | - | ||||||||||||||||||
1933 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1934 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||
1935 | if (parent.isValid() && !source_parent.isValid())
| 0-6465 | ||||||||||||||||||
1936 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1937 | IndexMap::const_iterator it = d->create_mapping(source_parent); | - | ||||||||||||||||||
1938 | return it.value()->source_columns.count(); executed 10945 times by 12 tests: return it.value()->source_columns.count(); Executed by:
| 10945 | ||||||||||||||||||
1939 | } | - | ||||||||||||||||||
1940 | - | |||||||||||||||||||
1941 | /*! | - | ||||||||||||||||||
1942 | \reimp | - | ||||||||||||||||||
1943 | */ | - | ||||||||||||||||||
1944 | bool QSortFilterProxyModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||
1945 | { | - | ||||||||||||||||||
1946 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1947 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||
1948 | if (parent.isValid() && !source_parent.isValid())
| 0-8698 | ||||||||||||||||||
1949 | return false; never executed: return false; | 0 | ||||||||||||||||||
1950 | if (!d->model->hasChildren(source_parent))
| 648-8377 | ||||||||||||||||||
1951 | return false; executed 8377 times by 5 tests: return false; Executed by:
| 8377 | ||||||||||||||||||
1952 | - | |||||||||||||||||||
1953 | if (d->model->canFetchMore(source_parent))
| 47-601 | ||||||||||||||||||
1954 | return true; //we assume we might have children that can be fetched executed 47 times by 2 tests: return true; Executed by:
| 47 | ||||||||||||||||||
1955 | - | |||||||||||||||||||
1956 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||
1957 | return m->source_rows.count() != 0 && m->source_columns.count() != 0; executed 601 times by 6 tests: return m->source_rows.count() != 0 && m->source_columns.count() != 0; Executed by:
| 0-601 | ||||||||||||||||||
1958 | } | - | ||||||||||||||||||
1959 | - | |||||||||||||||||||
1960 | /*! | - | ||||||||||||||||||
1961 | \reimp | - | ||||||||||||||||||
1962 | */ | - | ||||||||||||||||||
1963 | QVariant QSortFilterProxyModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||
1964 | { | - | ||||||||||||||||||
1965 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1966 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||
1967 | if (index.isValid() && !source_index.isValid())
| 0-51719 | ||||||||||||||||||
1968 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||
1969 | return d->model->data(source_index, role); executed 64123 times by 9 tests: return d->model->data(source_index, role); Executed by:
| 64123 | ||||||||||||||||||
1970 | } | - | ||||||||||||||||||
1971 | - | |||||||||||||||||||
1972 | /*! | - | ||||||||||||||||||
1973 | \reimp | - | ||||||||||||||||||
1974 | */ | - | ||||||||||||||||||
1975 | bool QSortFilterProxyModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||||||||
1976 | { | - | ||||||||||||||||||
1977 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
1978 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||
1979 | if (index.isValid() && !source_index.isValid())
| 0-6065 | ||||||||||||||||||
1980 | return false; never executed: return false; | 0 | ||||||||||||||||||
1981 | return d->model->setData(source_index, value, role); executed 6156 times by 3 tests: return d->model->setData(source_index, value, role); Executed by:
| 6156 | ||||||||||||||||||
1982 | } | - | ||||||||||||||||||
1983 | - | |||||||||||||||||||
1984 | /*! | - | ||||||||||||||||||
1985 | \reimp | - | ||||||||||||||||||
1986 | */ | - | ||||||||||||||||||
1987 | QVariant QSortFilterProxyModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||||||||
1988 | { | - | ||||||||||||||||||
1989 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
1990 | IndexMap::const_iterator it = d->create_mapping(QModelIndex()); | - | ||||||||||||||||||
1991 | if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
| 149-2249 | ||||||||||||||||||
1992 | return QAbstractProxyModel::headerData(section, orientation, role); executed 2249 times by 8 tests: return QAbstractProxyModel::headerData(section, orientation, role); Executed by:
| 2249 | ||||||||||||||||||
1993 | int source_section; | - | ||||||||||||||||||
1994 | if (orientation == Qt::Vertical) {
| 0-149 | ||||||||||||||||||
1995 | if (section < 0 || section >= it.value()->source_rows.count())
| 0 | ||||||||||||||||||
1996 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||
1997 | source_section = it.value()->source_rows.at(section); | - | ||||||||||||||||||
1998 | } else { never executed: end of block | 0 | ||||||||||||||||||
1999 | if (section < 0 || section >= it.value()->source_columns.count())
| 0-149 | ||||||||||||||||||
2000 | return QVariant(); executed 5 times by 3 tests: return QVariant(); Executed by:
| 5 | ||||||||||||||||||
2001 | source_section = it.value()->source_columns.at(section); | - | ||||||||||||||||||
2002 | } executed 144 times by 3 tests: end of block Executed by:
| 144 | ||||||||||||||||||
2003 | return d->model->headerData(source_section, orientation, role); executed 144 times by 3 tests: return d->model->headerData(source_section, orientation, role); Executed by:
| 144 | ||||||||||||||||||
2004 | } | - | ||||||||||||||||||
2005 | - | |||||||||||||||||||
2006 | /*! | - | ||||||||||||||||||
2007 | \reimp | - | ||||||||||||||||||
2008 | */ | - | ||||||||||||||||||
2009 | bool QSortFilterProxyModel::setHeaderData(int section, Qt::Orientation orientation, | - | ||||||||||||||||||
2010 | const QVariant &value, int role) | - | ||||||||||||||||||
2011 | { | - | ||||||||||||||||||
2012 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2013 | IndexMap::const_iterator it = d->create_mapping(QModelIndex()); | - | ||||||||||||||||||
2014 | if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
| 19-102 | ||||||||||||||||||
2015 | return QAbstractProxyModel::setHeaderData(section, orientation, value, role); executed 102 times by 3 tests: return QAbstractProxyModel::setHeaderData(section, orientation, value, role); Executed by:
| 102 | ||||||||||||||||||
2016 | int source_section; | - | ||||||||||||||||||
2017 | if (orientation == Qt::Vertical) {
| 1-18 | ||||||||||||||||||
2018 | if (section < 0 || section >= it.value()->source_rows.count())
| 0-1 | ||||||||||||||||||
2019 | return false; executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
2020 | source_section = it.value()->source_rows.at(section); | - | ||||||||||||||||||
2021 | } else { never executed: end of block | 0 | ||||||||||||||||||
2022 | if (section < 0 || section >= it.value()->source_columns.count())
| 0-9 | ||||||||||||||||||
2023 | return false; executed 18 times by 3 tests: return false; Executed by:
| 18 | ||||||||||||||||||
2024 | source_section = it.value()->source_columns.at(section); | - | ||||||||||||||||||
2025 | } never executed: end of block | 0 | ||||||||||||||||||
2026 | return d->model->setHeaderData(source_section, orientation, value, role); never executed: return d->model->setHeaderData(source_section, orientation, value, role); | 0 | ||||||||||||||||||
2027 | } | - | ||||||||||||||||||
2028 | - | |||||||||||||||||||
2029 | /*! | - | ||||||||||||||||||
2030 | \reimp | - | ||||||||||||||||||
2031 | */ | - | ||||||||||||||||||
2032 | QMimeData *QSortFilterProxyModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||||||||
2033 | { | - | ||||||||||||||||||
2034 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2035 | QModelIndexList source_indexes; | - | ||||||||||||||||||
2036 | const int numIndexes = indexes.count(); | - | ||||||||||||||||||
2037 | source_indexes.reserve(numIndexes); | - | ||||||||||||||||||
2038 | for (int i = 0; i < numIndexes; ++i)
| 0 | ||||||||||||||||||
2039 | source_indexes << mapToSource(indexes.at(i)); never executed: source_indexes << mapToSource(indexes.at(i)); | 0 | ||||||||||||||||||
2040 | return d->model->mimeData(source_indexes); never executed: return d->model->mimeData(source_indexes); | 0 | ||||||||||||||||||
2041 | } | - | ||||||||||||||||||
2042 | - | |||||||||||||||||||
2043 | /*! | - | ||||||||||||||||||
2044 | \reimp | - | ||||||||||||||||||
2045 | */ | - | ||||||||||||||||||
2046 | QStringList QSortFilterProxyModel::mimeTypes() const | - | ||||||||||||||||||
2047 | { | - | ||||||||||||||||||
2048 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2049 | return d->model->mimeTypes(); executed 48 times by 3 tests: return d->model->mimeTypes(); Executed by:
| 48 | ||||||||||||||||||
2050 | } | - | ||||||||||||||||||
2051 | - | |||||||||||||||||||
2052 | /*! | - | ||||||||||||||||||
2053 | \reimp | - | ||||||||||||||||||
2054 | */ | - | ||||||||||||||||||
2055 | Qt::DropActions QSortFilterProxyModel::supportedDropActions() const | - | ||||||||||||||||||
2056 | { | - | ||||||||||||||||||
2057 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2058 | return d->model->supportedDropActions(); executed 48 times by 3 tests: return d->model->supportedDropActions(); Executed by:
| 48 | ||||||||||||||||||
2059 | } | - | ||||||||||||||||||
2060 | - | |||||||||||||||||||
2061 | // Qt6: remove unnecessary reimplementation | - | ||||||||||||||||||
2062 | /*! | - | ||||||||||||||||||
2063 | \reimp | - | ||||||||||||||||||
2064 | */ | - | ||||||||||||||||||
2065 | bool QSortFilterProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||
2066 | int row, int column, const QModelIndex &parent) | - | ||||||||||||||||||
2067 | { | - | ||||||||||||||||||
2068 | return QAbstractProxyModel::dropMimeData(data, action, row, column, parent); executed 1 time by 1 test: return QAbstractProxyModel::dropMimeData(data, action, row, column, parent); Executed by:
| 1 | ||||||||||||||||||
2069 | } | - | ||||||||||||||||||
2070 | - | |||||||||||||||||||
2071 | /*! | - | ||||||||||||||||||
2072 | \reimp | - | ||||||||||||||||||
2073 | */ | - | ||||||||||||||||||
2074 | bool QSortFilterProxyModel::insertRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||
2075 | { | - | ||||||||||||||||||
2076 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2077 | if (row < 0 || count <= 0)
| 9-51 | ||||||||||||||||||
2078 | return false; executed 30 times by 1 test: return false; Executed by:
| 30 | ||||||||||||||||||
2079 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||
2080 | if (parent.isValid() && !source_parent.isValid())
| 0-27 | ||||||||||||||||||
2081 | return false; never executed: return false; | 0 | ||||||||||||||||||
2082 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||
2083 | if (row > m->source_rows.count())
| 6-24 | ||||||||||||||||||
2084 | return false; executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||||||||
2085 | int source_row = (row >= m->source_rows.count()
| 1-23 | ||||||||||||||||||
2086 | ? m->source_rows.count() | - | ||||||||||||||||||
2087 | : m->source_rows.at(row)); | - | ||||||||||||||||||
2088 | return d->model->insertRows(source_row, count, source_parent); executed 24 times by 2 tests: return d->model->insertRows(source_row, count, source_parent); Executed by:
| 24 | ||||||||||||||||||
2089 | } | - | ||||||||||||||||||
2090 | - | |||||||||||||||||||
2091 | /*! | - | ||||||||||||||||||
2092 | \reimp | - | ||||||||||||||||||
2093 | */ | - | ||||||||||||||||||
2094 | bool QSortFilterProxyModel::insertColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||
2095 | { | - | ||||||||||||||||||
2096 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2097 | if (column < 0|| count <= 0)
| 9-48 | ||||||||||||||||||
2098 | return false; executed 30 times by 1 test: return false; Executed by:
| 30 | ||||||||||||||||||
2099 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||
2100 | if (parent.isValid() && !source_parent.isValid())
| 0-27 | ||||||||||||||||||
2101 | return false; never executed: return false; | 0 | ||||||||||||||||||
2102 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||
2103 | if (column > m->source_columns.count())
| 6-21 | ||||||||||||||||||
2104 | return false; executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||||||||
2105 | int source_column = (column >= m->source_columns.count()
| 0-21 | ||||||||||||||||||
2106 | ? m->source_columns.count() | - | ||||||||||||||||||
2107 | : m->source_columns.at(column)); | - | ||||||||||||||||||
2108 | return d->model->insertColumns(source_column, count, source_parent); executed 21 times by 1 test: return d->model->insertColumns(source_column, count, source_parent); Executed by:
| 21 | ||||||||||||||||||
2109 | } | - | ||||||||||||||||||
2110 | - | |||||||||||||||||||
2111 | /*! | - | ||||||||||||||||||
2112 | \reimp | - | ||||||||||||||||||
2113 | */ | - | ||||||||||||||||||
2114 | bool QSortFilterProxyModel::removeRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||
2115 | { | - | ||||||||||||||||||
2116 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2117 | if (row < 0 || count <= 0)
| 13-65 | ||||||||||||||||||
2118 | return false; executed 34 times by 2 tests: return false; Executed by:
| 34 | ||||||||||||||||||
2119 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||
2120 | if (parent.isValid() && !source_parent.isValid())
| 0-33 | ||||||||||||||||||
2121 | return false; never executed: return false; | 0 | ||||||||||||||||||
2122 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||
2123 | if (row + count > m->source_rows.count())
| 13-31 | ||||||||||||||||||
2124 | return false; executed 13 times by 2 tests: return false; Executed by:
| 13 | ||||||||||||||||||
2125 | if ((count == 1)
| 14-17 | ||||||||||||||||||
2126 | || ((d->source_sort_column < 0) && (m->proxy_rows.count() == m->source_rows.count()))) {
| 0-14 | ||||||||||||||||||
2127 | int source_row = m->source_rows.at(row); | - | ||||||||||||||||||
2128 | return d->model->removeRows(source_row, count, source_parent); executed 28 times by 2 tests: return d->model->removeRows(source_row, count, source_parent); Executed by:
| 28 | ||||||||||||||||||
2129 | } | - | ||||||||||||||||||
2130 | // remove corresponding source intervals | - | ||||||||||||||||||
2131 | // ### if this proves to be slow, we can switch to single-row removal | - | ||||||||||||||||||
2132 | QVector<int> rows; | - | ||||||||||||||||||
2133 | rows.reserve(count); | - | ||||||||||||||||||
2134 | for (int i = row; i < row + count; ++i)
| 3-9 | ||||||||||||||||||
2135 | rows.append(m->source_rows.at(i)); executed 9 times by 1 test: rows.append(m->source_rows.at(i)); Executed by:
| 9 | ||||||||||||||||||
2136 | std::sort(rows.begin(), rows.end()); | - | ||||||||||||||||||
2137 | - | |||||||||||||||||||
2138 | int pos = rows.count() - 1; | - | ||||||||||||||||||
2139 | bool ok = true; | - | ||||||||||||||||||
2140 | while (pos >= 0) {
| 3-4 | ||||||||||||||||||
2141 | const int source_end = rows.at(pos--); | - | ||||||||||||||||||
2142 | int source_start = source_end; | - | ||||||||||||||||||
2143 | while ((pos >= 0) && (rows.at(pos) == (source_start - 1))) {
| 1-6 | ||||||||||||||||||
2144 | --source_start; | - | ||||||||||||||||||
2145 | --pos; | - | ||||||||||||||||||
2146 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
2147 | ok = ok && d->model->removeRows(source_start, source_end - source_start + 1,
| 0-4 | ||||||||||||||||||
2148 | source_parent);
| 0-4 | ||||||||||||||||||
2149 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
2150 | return ok; executed 3 times by 1 test: return ok; Executed by:
| 3 | ||||||||||||||||||
2151 | } | - | ||||||||||||||||||
2152 | - | |||||||||||||||||||
2153 | /*! | - | ||||||||||||||||||
2154 | \reimp | - | ||||||||||||||||||
2155 | */ | - | ||||||||||||||||||
2156 | bool QSortFilterProxyModel::removeColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||
2157 | { | - | ||||||||||||||||||
2158 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2159 | if (column < 0 || count <= 0)
| 13-62 | ||||||||||||||||||
2160 | return false; executed 34 times by 2 tests: return false; Executed by:
| 34 | ||||||||||||||||||
2161 | QModelIndex source_parent = mapToSource(parent); | - | ||||||||||||||||||
2162 | if (parent.isValid() && !source_parent.isValid())
| 0-33 | ||||||||||||||||||
2163 | return false; never executed: return false; | 0 | ||||||||||||||||||
2164 | QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); | - | ||||||||||||||||||
2165 | if (column + count > m->source_columns.count())
| 14-27 | ||||||||||||||||||
2166 | return false; executed 14 times by 2 tests: return false; Executed by:
| 14 | ||||||||||||||||||
2167 | if ((count == 1) || (m->proxy_columns.count() == m->source_columns.count())) {
| 1-14 | ||||||||||||||||||
2168 | int source_column = m->source_columns.at(column); | - | ||||||||||||||||||
2169 | return d->model->removeColumns(source_column, count, source_parent); executed 26 times by 2 tests: return d->model->removeColumns(source_column, count, source_parent); Executed by:
| 26 | ||||||||||||||||||
2170 | } | - | ||||||||||||||||||
2171 | // remove corresponding source intervals | - | ||||||||||||||||||
2172 | QVector<int> columns; | - | ||||||||||||||||||
2173 | columns.reserve(count); | - | ||||||||||||||||||
2174 | for (int i = column; i < column + count; ++i)
| 1-3 | ||||||||||||||||||
2175 | columns.append(m->source_columns.at(i)); executed 3 times by 1 test: columns.append(m->source_columns.at(i)); Executed by:
| 3 | ||||||||||||||||||
2176 | - | |||||||||||||||||||
2177 | int pos = columns.count() - 1; | - | ||||||||||||||||||
2178 | bool ok = true; | - | ||||||||||||||||||
2179 | while (pos >= 0) {
| 1-3 | ||||||||||||||||||
2180 | const int source_end = columns.at(pos--); | - | ||||||||||||||||||
2181 | int source_start = source_end; | - | ||||||||||||||||||
2182 | while ((pos >= 0) && (columns.at(pos) == (source_start - 1))) {
| 0-2 | ||||||||||||||||||
2183 | --source_start; | - | ||||||||||||||||||
2184 | --pos; | - | ||||||||||||||||||
2185 | } never executed: end of block | 0 | ||||||||||||||||||
2186 | ok = ok && d->model->removeColumns(source_start, source_end - source_start + 1,
| 0-3 | ||||||||||||||||||
2187 | source_parent);
| 0-3 | ||||||||||||||||||
2188 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
2189 | return ok; executed 1 time by 1 test: return ok; Executed by:
| 1 | ||||||||||||||||||
2190 | } | - | ||||||||||||||||||
2191 | - | |||||||||||||||||||
2192 | /*! | - | ||||||||||||||||||
2193 | \reimp | - | ||||||||||||||||||
2194 | */ | - | ||||||||||||||||||
2195 | void QSortFilterProxyModel::fetchMore(const QModelIndex &parent) | - | ||||||||||||||||||
2196 | { | - | ||||||||||||||||||
2197 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2198 | QModelIndex source_parent; | - | ||||||||||||||||||
2199 | if (d->indexValid(parent))
| 1-51 | ||||||||||||||||||
2200 | source_parent = mapToSource(parent); executed 1 time by 1 test: source_parent = mapToSource(parent); Executed by:
| 1 | ||||||||||||||||||
2201 | d->model->fetchMore(source_parent); | - | ||||||||||||||||||
2202 | } executed 52 times by 5 tests: end of block Executed by:
| 52 | ||||||||||||||||||
2203 | - | |||||||||||||||||||
2204 | /*! | - | ||||||||||||||||||
2205 | \reimp | - | ||||||||||||||||||
2206 | */ | - | ||||||||||||||||||
2207 | bool QSortFilterProxyModel::canFetchMore(const QModelIndex &parent) const | - | ||||||||||||||||||
2208 | { | - | ||||||||||||||||||
2209 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2210 | QModelIndex source_parent; | - | ||||||||||||||||||
2211 | if (d->indexValid(parent))
| 277-449 | ||||||||||||||||||
2212 | source_parent = mapToSource(parent); executed 277 times by 5 tests: source_parent = mapToSource(parent); Executed by:
| 277 | ||||||||||||||||||
2213 | return d->model->canFetchMore(source_parent); executed 726 times by 10 tests: return d->model->canFetchMore(source_parent); Executed by:
| 726 | ||||||||||||||||||
2214 | } | - | ||||||||||||||||||
2215 | - | |||||||||||||||||||
2216 | /*! | - | ||||||||||||||||||
2217 | \reimp | - | ||||||||||||||||||
2218 | */ | - | ||||||||||||||||||
2219 | Qt::ItemFlags QSortFilterProxyModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||
2220 | { | - | ||||||||||||||||||
2221 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2222 | QModelIndex source_index; | - | ||||||||||||||||||
2223 | if (d->indexValid(index))
| 48-3093 | ||||||||||||||||||
2224 | source_index = mapToSource(index); executed 3093 times by 8 tests: source_index = mapToSource(index); Executed by:
| 3093 | ||||||||||||||||||
2225 | return d->model->flags(source_index); executed 3141 times by 10 tests: return d->model->flags(source_index); Executed by:
| 3141 | ||||||||||||||||||
2226 | } | - | ||||||||||||||||||
2227 | - | |||||||||||||||||||
2228 | /*! | - | ||||||||||||||||||
2229 | \reimp | - | ||||||||||||||||||
2230 | */ | - | ||||||||||||||||||
2231 | QModelIndex QSortFilterProxyModel::buddy(const QModelIndex &index) const | - | ||||||||||||||||||
2232 | { | - | ||||||||||||||||||
2233 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2234 | if (!d->indexValid(index))
| 48-100 | ||||||||||||||||||
2235 | return QModelIndex(); executed 48 times by 3 tests: return QModelIndex(); Executed by:
| 48 | ||||||||||||||||||
2236 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||
2237 | QModelIndex source_buddy = d->model->buddy(source_index); | - | ||||||||||||||||||
2238 | if (source_index == source_buddy)
| 0-100 | ||||||||||||||||||
2239 | return index; executed 100 times by 5 tests: return index; Executed by:
| 100 | ||||||||||||||||||
2240 | return mapFromSource(source_buddy); never executed: return mapFromSource(source_buddy); | 0 | ||||||||||||||||||
2241 | } | - | ||||||||||||||||||
2242 | - | |||||||||||||||||||
2243 | /*! | - | ||||||||||||||||||
2244 | \reimp | - | ||||||||||||||||||
2245 | */ | - | ||||||||||||||||||
2246 | QModelIndexList QSortFilterProxyModel::match(const QModelIndex &start, int role, | - | ||||||||||||||||||
2247 | const QVariant &value, int hits, | - | ||||||||||||||||||
2248 | Qt::MatchFlags flags) const | - | ||||||||||||||||||
2249 | { | - | ||||||||||||||||||
2250 | return QAbstractProxyModel::match(start, role, value, hits, flags); executed 54 times by 3 tests: return QAbstractProxyModel::match(start, role, value, hits, flags); Executed by:
| 54 | ||||||||||||||||||
2251 | } | - | ||||||||||||||||||
2252 | - | |||||||||||||||||||
2253 | /*! | - | ||||||||||||||||||
2254 | \reimp | - | ||||||||||||||||||
2255 | */ | - | ||||||||||||||||||
2256 | QSize QSortFilterProxyModel::span(const QModelIndex &index) const | - | ||||||||||||||||||
2257 | { | - | ||||||||||||||||||
2258 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2259 | QModelIndex source_index = mapToSource(index); | - | ||||||||||||||||||
2260 | if (index.isValid() && !source_index.isValid())
| 0-48 | ||||||||||||||||||
2261 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
2262 | return d->model->span(source_index); executed 48 times by 3 tests: return d->model->span(source_index); Executed by:
| 48 | ||||||||||||||||||
2263 | } | - | ||||||||||||||||||
2264 | - | |||||||||||||||||||
2265 | /*! | - | ||||||||||||||||||
2266 | \reimp | - | ||||||||||||||||||
2267 | */ | - | ||||||||||||||||||
2268 | void QSortFilterProxyModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||||||||
2269 | { | - | ||||||||||||||||||
2270 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2271 | if (d->dynamic_sortfilter && d->proxy_sort_column == column && d->sort_order == order)
| 4-214 | ||||||||||||||||||
2272 | return; executed 117 times by 4 tests: return; Executed by:
| 117 | ||||||||||||||||||
2273 | d->sort_order = order; | - | ||||||||||||||||||
2274 | d->proxy_sort_column = column; | - | ||||||||||||||||||
2275 | d->update_source_sort_column(); | - | ||||||||||||||||||
2276 | d->sort(); | - | ||||||||||||||||||
2277 | } executed 102 times by 8 tests: end of block Executed by:
| 102 | ||||||||||||||||||
2278 | - | |||||||||||||||||||
2279 | /*! | - | ||||||||||||||||||
2280 | \since 4.5 | - | ||||||||||||||||||
2281 | \brief the column currently used for sorting | - | ||||||||||||||||||
2282 | - | |||||||||||||||||||
2283 | This returns the most recently used sort column. | - | ||||||||||||||||||
2284 | */ | - | ||||||||||||||||||
2285 | int QSortFilterProxyModel::sortColumn() const | - | ||||||||||||||||||
2286 | { | - | ||||||||||||||||||
2287 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2288 | return d->proxy_sort_column; executed 13 times by 1 test: return d->proxy_sort_column; Executed by:
| 13 | ||||||||||||||||||
2289 | } | - | ||||||||||||||||||
2290 | - | |||||||||||||||||||
2291 | /*! | - | ||||||||||||||||||
2292 | \since 4.5 | - | ||||||||||||||||||
2293 | \brief the order currently used for sorting | - | ||||||||||||||||||
2294 | - | |||||||||||||||||||
2295 | This returns the most recently used sort order. | - | ||||||||||||||||||
2296 | */ | - | ||||||||||||||||||
2297 | Qt::SortOrder QSortFilterProxyModel::sortOrder() const | - | ||||||||||||||||||
2298 | { | - | ||||||||||||||||||
2299 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2300 | return d->sort_order; never executed: return d->sort_order; | 0 | ||||||||||||||||||
2301 | } | - | ||||||||||||||||||
2302 | - | |||||||||||||||||||
2303 | /*! | - | ||||||||||||||||||
2304 | \property QSortFilterProxyModel::filterRegExp | - | ||||||||||||||||||
2305 | \brief the QRegExp used to filter the contents of the source model | - | ||||||||||||||||||
2306 | - | |||||||||||||||||||
2307 | Setting this property overwrites the current | - | ||||||||||||||||||
2308 | \l{QSortFilterProxyModel::filterCaseSensitivity}{filterCaseSensitivity}. | - | ||||||||||||||||||
2309 | By default, the QRegExp is an empty string matching all contents. | - | ||||||||||||||||||
2310 | - | |||||||||||||||||||
2311 | If no QRegExp or an empty string is set, everything in the source model | - | ||||||||||||||||||
2312 | will be accepted. | - | ||||||||||||||||||
2313 | - | |||||||||||||||||||
2314 | \sa filterCaseSensitivity, setFilterWildcard(), setFilterFixedString() | - | ||||||||||||||||||
2315 | */ | - | ||||||||||||||||||
2316 | QRegExp QSortFilterProxyModel::filterRegExp() const | - | ||||||||||||||||||
2317 | { | - | ||||||||||||||||||
2318 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2319 | return d->filter_regexp; executed 45 times by 1 test: return d->filter_regexp; Executed by:
| 45 | ||||||||||||||||||
2320 | } | - | ||||||||||||||||||
2321 | - | |||||||||||||||||||
2322 | void QSortFilterProxyModel::setFilterRegExp(const QRegExp ®Exp) | - | ||||||||||||||||||
2323 | { | - | ||||||||||||||||||
2324 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2325 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||
2326 | d->filter_regexp = regExp; | - | ||||||||||||||||||
2327 | d->filter_changed(); | - | ||||||||||||||||||
2328 | } executed 179 times by 4 tests: end of block Executed by:
| 179 | ||||||||||||||||||
2329 | - | |||||||||||||||||||
2330 | /*! | - | ||||||||||||||||||
2331 | \property QSortFilterProxyModel::filterKeyColumn | - | ||||||||||||||||||
2332 | \brief the column where the key used to filter the contents of the | - | ||||||||||||||||||
2333 | source model is read from. | - | ||||||||||||||||||
2334 | - | |||||||||||||||||||
2335 | The default value is 0. If the value is -1, the keys will be read | - | ||||||||||||||||||
2336 | from all columns. | - | ||||||||||||||||||
2337 | */ | - | ||||||||||||||||||
2338 | int QSortFilterProxyModel::filterKeyColumn() const | - | ||||||||||||||||||
2339 | { | - | ||||||||||||||||||
2340 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2341 | return d->filter_column; executed 3 times by 1 test: return d->filter_column; Executed by:
| 3 | ||||||||||||||||||
2342 | } | - | ||||||||||||||||||
2343 | - | |||||||||||||||||||
2344 | void QSortFilterProxyModel::setFilterKeyColumn(int column) | - | ||||||||||||||||||
2345 | { | - | ||||||||||||||||||
2346 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2347 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||
2348 | d->filter_column = column; | - | ||||||||||||||||||
2349 | d->filter_changed(); | - | ||||||||||||||||||
2350 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
2351 | - | |||||||||||||||||||
2352 | /*! | - | ||||||||||||||||||
2353 | \property QSortFilterProxyModel::filterCaseSensitivity | - | ||||||||||||||||||
2354 | - | |||||||||||||||||||
2355 | \brief the case sensitivity of the QRegExp pattern used to filter the | - | ||||||||||||||||||
2356 | contents of the source model | - | ||||||||||||||||||
2357 | - | |||||||||||||||||||
2358 | By default, the filter is case sensitive. | - | ||||||||||||||||||
2359 | - | |||||||||||||||||||
2360 | \sa filterRegExp, sortCaseSensitivity | - | ||||||||||||||||||
2361 | */ | - | ||||||||||||||||||
2362 | Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity() const | - | ||||||||||||||||||
2363 | { | - | ||||||||||||||||||
2364 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2365 | return d->filter_regexp.caseSensitivity(); never executed: return d->filter_regexp.caseSensitivity(); | 0 | ||||||||||||||||||
2366 | } | - | ||||||||||||||||||
2367 | - | |||||||||||||||||||
2368 | void QSortFilterProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs) | - | ||||||||||||||||||
2369 | { | - | ||||||||||||||||||
2370 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2371 | if (cs == d->filter_regexp.caseSensitivity())
| 0 | ||||||||||||||||||
2372 | return; never executed: return; | 0 | ||||||||||||||||||
2373 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||
2374 | d->filter_regexp.setCaseSensitivity(cs); | - | ||||||||||||||||||
2375 | d->filter_changed(); | - | ||||||||||||||||||
2376 | } never executed: end of block | 0 | ||||||||||||||||||
2377 | - | |||||||||||||||||||
2378 | /*! | - | ||||||||||||||||||
2379 | \since 4.2 | - | ||||||||||||||||||
2380 | \property QSortFilterProxyModel::sortCaseSensitivity | - | ||||||||||||||||||
2381 | \brief the case sensitivity setting used for comparing strings when sorting | - | ||||||||||||||||||
2382 | - | |||||||||||||||||||
2383 | By default, sorting is case sensitive. | - | ||||||||||||||||||
2384 | - | |||||||||||||||||||
2385 | \sa filterCaseSensitivity, lessThan() | - | ||||||||||||||||||
2386 | */ | - | ||||||||||||||||||
2387 | Qt::CaseSensitivity QSortFilterProxyModel::sortCaseSensitivity() const | - | ||||||||||||||||||
2388 | { | - | ||||||||||||||||||
2389 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2390 | return d->sort_casesensitivity; never executed: return d->sort_casesensitivity; | 0 | ||||||||||||||||||
2391 | } | - | ||||||||||||||||||
2392 | - | |||||||||||||||||||
2393 | void QSortFilterProxyModel::setSortCaseSensitivity(Qt::CaseSensitivity cs) | - | ||||||||||||||||||
2394 | { | - | ||||||||||||||||||
2395 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2396 | if (d->sort_casesensitivity == cs)
| 3 | ||||||||||||||||||
2397 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||||||||
2398 | - | |||||||||||||||||||
2399 | d->sort_casesensitivity = cs; | - | ||||||||||||||||||
2400 | d->sort(); | - | ||||||||||||||||||
2401 | } executed 3 times by 2 tests: end of block Executed by:
| 3 | ||||||||||||||||||
2402 | - | |||||||||||||||||||
2403 | /*! | - | ||||||||||||||||||
2404 | \since 4.3 | - | ||||||||||||||||||
2405 | \property QSortFilterProxyModel::isSortLocaleAware | - | ||||||||||||||||||
2406 | \brief the local aware setting used for comparing strings when sorting | - | ||||||||||||||||||
2407 | - | |||||||||||||||||||
2408 | By default, sorting is not local aware. | - | ||||||||||||||||||
2409 | - | |||||||||||||||||||
2410 | \sa sortCaseSensitivity, lessThan() | - | ||||||||||||||||||
2411 | */ | - | ||||||||||||||||||
2412 | bool QSortFilterProxyModel::isSortLocaleAware() const | - | ||||||||||||||||||
2413 | { | - | ||||||||||||||||||
2414 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2415 | return d->sort_localeaware; never executed: return d->sort_localeaware; | 0 | ||||||||||||||||||
2416 | } | - | ||||||||||||||||||
2417 | - | |||||||||||||||||||
2418 | void QSortFilterProxyModel::setSortLocaleAware(bool on) | - | ||||||||||||||||||
2419 | { | - | ||||||||||||||||||
2420 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2421 | if (d->sort_localeaware == on)
| 0 | ||||||||||||||||||
2422 | return; never executed: return; | 0 | ||||||||||||||||||
2423 | - | |||||||||||||||||||
2424 | d->sort_localeaware = on; | - | ||||||||||||||||||
2425 | d->sort(); | - | ||||||||||||||||||
2426 | } never executed: end of block | 0 | ||||||||||||||||||
2427 | - | |||||||||||||||||||
2428 | /*! | - | ||||||||||||||||||
2429 | \overload | - | ||||||||||||||||||
2430 | - | |||||||||||||||||||
2431 | Sets the regular expression used to filter the contents | - | ||||||||||||||||||
2432 | of the source model to \a pattern. | - | ||||||||||||||||||
2433 | - | |||||||||||||||||||
2434 | \sa setFilterCaseSensitivity(), setFilterWildcard(), setFilterFixedString(), filterRegExp() | - | ||||||||||||||||||
2435 | */ | - | ||||||||||||||||||
2436 | void QSortFilterProxyModel::setFilterRegExp(const QString &pattern) | - | ||||||||||||||||||
2437 | { | - | ||||||||||||||||||
2438 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2439 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||
2440 | d->filter_regexp.setPatternSyntax(QRegExp::RegExp); | - | ||||||||||||||||||
2441 | d->filter_regexp.setPattern(pattern); | - | ||||||||||||||||||
2442 | d->filter_changed(); | - | ||||||||||||||||||
2443 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
2444 | - | |||||||||||||||||||
2445 | /*! | - | ||||||||||||||||||
2446 | Sets the wildcard expression used to filter the contents | - | ||||||||||||||||||
2447 | of the source model to the given \a pattern. | - | ||||||||||||||||||
2448 | - | |||||||||||||||||||
2449 | \sa setFilterCaseSensitivity(), setFilterRegExp(), setFilterFixedString(), filterRegExp() | - | ||||||||||||||||||
2450 | */ | - | ||||||||||||||||||
2451 | void QSortFilterProxyModel::setFilterWildcard(const QString &pattern) | - | ||||||||||||||||||
2452 | { | - | ||||||||||||||||||
2453 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2454 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||
2455 | d->filter_regexp.setPatternSyntax(QRegExp::Wildcard); | - | ||||||||||||||||||
2456 | d->filter_regexp.setPattern(pattern); | - | ||||||||||||||||||
2457 | d->filter_changed(); | - | ||||||||||||||||||
2458 | } never executed: end of block | 0 | ||||||||||||||||||
2459 | - | |||||||||||||||||||
2460 | /*! | - | ||||||||||||||||||
2461 | Sets the fixed string used to filter the contents | - | ||||||||||||||||||
2462 | of the source model to the given \a pattern. | - | ||||||||||||||||||
2463 | - | |||||||||||||||||||
2464 | \sa setFilterCaseSensitivity(), setFilterRegExp(), setFilterWildcard(), filterRegExp() | - | ||||||||||||||||||
2465 | */ | - | ||||||||||||||||||
2466 | void QSortFilterProxyModel::setFilterFixedString(const QString &pattern) | - | ||||||||||||||||||
2467 | { | - | ||||||||||||||||||
2468 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2469 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||
2470 | d->filter_regexp.setPatternSyntax(QRegExp::FixedString); | - | ||||||||||||||||||
2471 | d->filter_regexp.setPattern(pattern); | - | ||||||||||||||||||
2472 | d->filter_changed(); | - | ||||||||||||||||||
2473 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||||||||
2474 | - | |||||||||||||||||||
2475 | /*! | - | ||||||||||||||||||
2476 | \since 4.2 | - | ||||||||||||||||||
2477 | \property QSortFilterProxyModel::dynamicSortFilter | - | ||||||||||||||||||
2478 | \brief whether the proxy model is dynamically sorted and filtered | - | ||||||||||||||||||
2479 | whenever the contents of the source model change | - | ||||||||||||||||||
2480 | - | |||||||||||||||||||
2481 | Note that you should not update the source model through the proxy | - | ||||||||||||||||||
2482 | model when dynamicSortFilter is true. For instance, if you set the | - | ||||||||||||||||||
2483 | proxy model on a QComboBox, then using functions that update the | - | ||||||||||||||||||
2484 | model, e.g., \l{QComboBox::}{addItem()}, will not work as | - | ||||||||||||||||||
2485 | expected. An alternative is to set dynamicSortFilter to false and | - | ||||||||||||||||||
2486 | call \l{QSortFilterProxyModel::}{sort()} after adding items to the | - | ||||||||||||||||||
2487 | QComboBox. | - | ||||||||||||||||||
2488 | - | |||||||||||||||||||
2489 | The default value is true. | - | ||||||||||||||||||
2490 | */ | - | ||||||||||||||||||
2491 | bool QSortFilterProxyModel::dynamicSortFilter() const | - | ||||||||||||||||||
2492 | { | - | ||||||||||||||||||
2493 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2494 | return d->dynamic_sortfilter; never executed: return d->dynamic_sortfilter; | 0 | ||||||||||||||||||
2495 | } | - | ||||||||||||||||||
2496 | - | |||||||||||||||||||
2497 | void QSortFilterProxyModel::setDynamicSortFilter(bool enable) | - | ||||||||||||||||||
2498 | { | - | ||||||||||||||||||
2499 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2500 | d->dynamic_sortfilter = enable; | - | ||||||||||||||||||
2501 | if (enable)
| 4-28 | ||||||||||||||||||
2502 | d->sort(); executed 28 times by 5 tests: d->sort(); Executed by:
| 28 | ||||||||||||||||||
2503 | } executed 32 times by 5 tests: end of block Executed by:
| 32 | ||||||||||||||||||
2504 | - | |||||||||||||||||||
2505 | /*! | - | ||||||||||||||||||
2506 | \since 4.2 | - | ||||||||||||||||||
2507 | \property QSortFilterProxyModel::sortRole | - | ||||||||||||||||||
2508 | \brief the item role that is used to query the source model's data when sorting items | - | ||||||||||||||||||
2509 | - | |||||||||||||||||||
2510 | The default value is Qt::DisplayRole. | - | ||||||||||||||||||
2511 | - | |||||||||||||||||||
2512 | \sa lessThan() | - | ||||||||||||||||||
2513 | */ | - | ||||||||||||||||||
2514 | int QSortFilterProxyModel::sortRole() const | - | ||||||||||||||||||
2515 | { | - | ||||||||||||||||||
2516 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2517 | return d->sort_role; never executed: return d->sort_role; | 0 | ||||||||||||||||||
2518 | } | - | ||||||||||||||||||
2519 | - | |||||||||||||||||||
2520 | void QSortFilterProxyModel::setSortRole(int role) | - | ||||||||||||||||||
2521 | { | - | ||||||||||||||||||
2522 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2523 | if (d->sort_role == role)
| 1 | ||||||||||||||||||
2524 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
2525 | d->sort_role = role; | - | ||||||||||||||||||
2526 | d->sort(); | - | ||||||||||||||||||
2527 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
2528 | - | |||||||||||||||||||
2529 | /*! | - | ||||||||||||||||||
2530 | \since 4.2 | - | ||||||||||||||||||
2531 | \property QSortFilterProxyModel::filterRole | - | ||||||||||||||||||
2532 | \brief the item role that is used to query the source model's data when filtering items | - | ||||||||||||||||||
2533 | - | |||||||||||||||||||
2534 | The default value is Qt::DisplayRole. | - | ||||||||||||||||||
2535 | - | |||||||||||||||||||
2536 | \sa filterAcceptsRow() | - | ||||||||||||||||||
2537 | */ | - | ||||||||||||||||||
2538 | int QSortFilterProxyModel::filterRole() const | - | ||||||||||||||||||
2539 | { | - | ||||||||||||||||||
2540 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2541 | return d->filter_role; never executed: return d->filter_role; | 0 | ||||||||||||||||||
2542 | } | - | ||||||||||||||||||
2543 | - | |||||||||||||||||||
2544 | void QSortFilterProxyModel::setFilterRole(int role) | - | ||||||||||||||||||
2545 | { | - | ||||||||||||||||||
2546 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2547 | if (d->filter_role == role)
| 1-4 | ||||||||||||||||||
2548 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
2549 | d->filter_about_to_be_changed(); | - | ||||||||||||||||||
2550 | d->filter_role = role; | - | ||||||||||||||||||
2551 | d->filter_changed(); | - | ||||||||||||||||||
2552 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
2553 | - | |||||||||||||||||||
2554 | /*! | - | ||||||||||||||||||
2555 | \obsolete | - | ||||||||||||||||||
2556 | - | |||||||||||||||||||
2557 | This function is obsolete. Use invalidate() instead. | - | ||||||||||||||||||
2558 | */ | - | ||||||||||||||||||
2559 | void QSortFilterProxyModel::clear() | - | ||||||||||||||||||
2560 | { | - | ||||||||||||||||||
2561 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2562 | emit layoutAboutToBeChanged(); | - | ||||||||||||||||||
2563 | d->_q_clearMapping(); | - | ||||||||||||||||||
2564 | emit layoutChanged(); | - | ||||||||||||||||||
2565 | } never executed: end of block | 0 | ||||||||||||||||||
2566 | - | |||||||||||||||||||
2567 | /*! | - | ||||||||||||||||||
2568 | \since 4.3 | - | ||||||||||||||||||
2569 | - | |||||||||||||||||||
2570 | Invalidates the current sorting and filtering. | - | ||||||||||||||||||
2571 | - | |||||||||||||||||||
2572 | \sa invalidateFilter() | - | ||||||||||||||||||
2573 | */ | - | ||||||||||||||||||
2574 | void QSortFilterProxyModel::invalidate() | - | ||||||||||||||||||
2575 | { | - | ||||||||||||||||||
2576 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2577 | emit layoutAboutToBeChanged(); | - | ||||||||||||||||||
2578 | d->_q_clearMapping(); | - | ||||||||||||||||||
2579 | emit layoutChanged(); | - | ||||||||||||||||||
2580 | } executed 5 times by 3 tests: end of block Executed by:
| 5 | ||||||||||||||||||
2581 | - | |||||||||||||||||||
2582 | /*! | - | ||||||||||||||||||
2583 | \obsolete | - | ||||||||||||||||||
2584 | - | |||||||||||||||||||
2585 | This function is obsolete. Use invalidateFilter() instead. | - | ||||||||||||||||||
2586 | */ | - | ||||||||||||||||||
2587 | void QSortFilterProxyModel::filterChanged() | - | ||||||||||||||||||
2588 | { | - | ||||||||||||||||||
2589 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2590 | d->filter_changed(); | - | ||||||||||||||||||
2591 | } never executed: end of block | 0 | ||||||||||||||||||
2592 | - | |||||||||||||||||||
2593 | /*! | - | ||||||||||||||||||
2594 | \since 4.3 | - | ||||||||||||||||||
2595 | - | |||||||||||||||||||
2596 | Invalidates the current filtering. | - | ||||||||||||||||||
2597 | - | |||||||||||||||||||
2598 | This function should be called if you are implementing custom filtering | - | ||||||||||||||||||
2599 | (e.g. filterAcceptsRow()), and your filter parameters have changed. | - | ||||||||||||||||||
2600 | - | |||||||||||||||||||
2601 | \sa invalidate() | - | ||||||||||||||||||
2602 | */ | - | ||||||||||||||||||
2603 | void QSortFilterProxyModel::invalidateFilter() | - | ||||||||||||||||||
2604 | { | - | ||||||||||||||||||
2605 | Q_D(QSortFilterProxyModel); | - | ||||||||||||||||||
2606 | d->filter_changed(); | - | ||||||||||||||||||
2607 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
2608 | - | |||||||||||||||||||
2609 | /*! | - | ||||||||||||||||||
2610 | Returns \c true if the value of the item referred to by the given | - | ||||||||||||||||||
2611 | index \a source_left is less than the value of the item referred to by | - | ||||||||||||||||||
2612 | the given index \a source_right, otherwise returns \c false. | - | ||||||||||||||||||
2613 | - | |||||||||||||||||||
2614 | This function is used as the < operator when sorting, and handles | - | ||||||||||||||||||
2615 | the following QVariant types: | - | ||||||||||||||||||
2616 | - | |||||||||||||||||||
2617 | \list | - | ||||||||||||||||||
2618 | \li QMetaType::Int | - | ||||||||||||||||||
2619 | \li QMetaType::UInt | - | ||||||||||||||||||
2620 | \li QMetaType::LongLong | - | ||||||||||||||||||
2621 | \li QMetaType::ULongLong | - | ||||||||||||||||||
2622 | \li QMetaType::Float | - | ||||||||||||||||||
2623 | \li QMetaType::Double | - | ||||||||||||||||||
2624 | \li QMetaType::QChar | - | ||||||||||||||||||
2625 | \li QMetaType::QDate | - | ||||||||||||||||||
2626 | \li QMetaType::QTime | - | ||||||||||||||||||
2627 | \li QMetaType::QDateTime | - | ||||||||||||||||||
2628 | \li QMetaType::QString | - | ||||||||||||||||||
2629 | \endlist | - | ||||||||||||||||||
2630 | - | |||||||||||||||||||
2631 | Any other type will be converted to a QString using | - | ||||||||||||||||||
2632 | QVariant::toString(). | - | ||||||||||||||||||
2633 | - | |||||||||||||||||||
2634 | Comparison of \l{QString}s is case sensitive by default; this can | - | ||||||||||||||||||
2635 | be changed using the \l {QSortFilterProxyModel::sortCaseSensitivity} | - | ||||||||||||||||||
2636 | {sortCaseSensitivity} property. | - | ||||||||||||||||||
2637 | - | |||||||||||||||||||
2638 | By default, the Qt::DisplayRole associated with the | - | ||||||||||||||||||
2639 | \l{QModelIndex}es is used for comparisons. This can be changed by | - | ||||||||||||||||||
2640 | setting the \l {QSortFilterProxyModel::sortRole} {sortRole} property. | - | ||||||||||||||||||
2641 | - | |||||||||||||||||||
2642 | \note The indices passed in correspond to the source model. | - | ||||||||||||||||||
2643 | - | |||||||||||||||||||
2644 | \sa sortRole, sortCaseSensitivity, dynamicSortFilter | - | ||||||||||||||||||
2645 | */ | - | ||||||||||||||||||
2646 | bool QSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const | - | ||||||||||||||||||
2647 | { | - | ||||||||||||||||||
2648 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2649 | QVariant l = (source_left.model() ? source_left.model()->data(source_left, d->sort_role) : QVariant());
| 3-88008 | ||||||||||||||||||
2650 | QVariant r = (source_right.model() ? source_right.model()->data(source_right, d->sort_role) : QVariant());
| 3-88008 | ||||||||||||||||||
2651 | // Duplicated in QStandardItem::operator<() | - | ||||||||||||||||||
2652 | if (l.userType() == QVariant::Invalid)
| 12990-75021 | ||||||||||||||||||
2653 | return false; executed 12990 times by 2 tests: return false; Executed by:
| 12990 | ||||||||||||||||||
2654 | if (r.userType() == QVariant::Invalid)
| 6-75015 | ||||||||||||||||||
2655 | return true; executed 6 times by 1 test: return true; Executed by:
| 6 | ||||||||||||||||||
2656 | switch (l.userType()) { | - | ||||||||||||||||||
2657 | case QVariant::Int: executed 8 times by 2 tests: case QVariant::Int: Executed by:
| 8 | ||||||||||||||||||
2658 | return l.toInt() < r.toInt(); executed 8 times by 2 tests: return l.toInt() < r.toInt(); Executed by:
| 8 | ||||||||||||||||||
2659 | case QVariant::UInt: never executed: case QVariant::UInt: | 0 | ||||||||||||||||||
2660 | return l.toUInt() < r.toUInt(); never executed: return l.toUInt() < r.toUInt(); | 0 | ||||||||||||||||||
2661 | case QVariant::LongLong: never executed: case QVariant::LongLong: | 0 | ||||||||||||||||||
2662 | return l.toLongLong() < r.toLongLong(); never executed: return l.toLongLong() < r.toLongLong(); | 0 | ||||||||||||||||||
2663 | case QVariant::ULongLong: never executed: case QVariant::ULongLong: | 0 | ||||||||||||||||||
2664 | return l.toULongLong() < r.toULongLong(); never executed: return l.toULongLong() < r.toULongLong(); | 0 | ||||||||||||||||||
2665 | case QMetaType::Float: never executed: case QMetaType::Float: | 0 | ||||||||||||||||||
2666 | return l.toFloat() < r.toFloat(); never executed: return l.toFloat() < r.toFloat(); | 0 | ||||||||||||||||||
2667 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||||||||
2668 | return l.toDouble() < r.toDouble(); never executed: return l.toDouble() < r.toDouble(); | 0 | ||||||||||||||||||
2669 | case QVariant::Char: never executed: case QVariant::Char: | 0 | ||||||||||||||||||
2670 | return l.toChar() < r.toChar(); never executed: return l.toChar() < r.toChar(); | 0 | ||||||||||||||||||
2671 | case QVariant::Date: never executed: case QVariant::Date: | 0 | ||||||||||||||||||
2672 | return l.toDate() < r.toDate(); never executed: return l.toDate() < r.toDate(); | 0 | ||||||||||||||||||
2673 | case QVariant::Time: never executed: case QVariant::Time: | 0 | ||||||||||||||||||
2674 | return l.toTime() < r.toTime(); never executed: return l.toTime() < r.toTime(); | 0 | ||||||||||||||||||
2675 | case QVariant::DateTime: never executed: case QVariant::DateTime: | 0 | ||||||||||||||||||
2676 | return l.toDateTime() < r.toDateTime(); never executed: return l.toDateTime() < r.toDateTime(); | 0 | ||||||||||||||||||
2677 | case QVariant::String: executed 75007 times by 5 tests: case QVariant::String: Executed by:
| 75007 | ||||||||||||||||||
2678 | default: never executed: default: | 0 | ||||||||||||||||||
2679 | if (d->sort_localeaware)
| 0-75007 | ||||||||||||||||||
2680 | return l.toString().localeAwareCompare(r.toString()) < 0; never executed: return l.toString().localeAwareCompare(r.toString()) < 0; | 0 | ||||||||||||||||||
2681 | else | - | ||||||||||||||||||
2682 | return l.toString().compare(r.toString(), d->sort_casesensitivity) < 0; executed 75007 times by 5 tests: return l.toString().compare(r.toString(), d->sort_casesensitivity) < 0; Executed by:
| 75007 | ||||||||||||||||||
2683 | } | - | ||||||||||||||||||
2684 | return false; dead code: return false; | - | ||||||||||||||||||
2685 | } | - | ||||||||||||||||||
2686 | - | |||||||||||||||||||
2687 | /*! | - | ||||||||||||||||||
2688 | Returns \c true if the item in the row indicated by the given \a source_row | - | ||||||||||||||||||
2689 | and \a source_parent should be included in the model; otherwise returns | - | ||||||||||||||||||
2690 | false. | - | ||||||||||||||||||
2691 | - | |||||||||||||||||||
2692 | The default implementation returns \c true if the value held by the relevant item | - | ||||||||||||||||||
2693 | matches the filter string, wildcard string or regular expression. | - | ||||||||||||||||||
2694 | - | |||||||||||||||||||
2695 | \note By default, the Qt::DisplayRole is used to determine if the row | - | ||||||||||||||||||
2696 | should be accepted or not. This can be changed by setting the | - | ||||||||||||||||||
2697 | \l{QSortFilterProxyModel::filterRole}{filterRole} property. | - | ||||||||||||||||||
2698 | - | |||||||||||||||||||
2699 | \sa filterAcceptsColumn(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard() | - | ||||||||||||||||||
2700 | */ | - | ||||||||||||||||||
2701 | bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | - | ||||||||||||||||||
2702 | { | - | ||||||||||||||||||
2703 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2704 | if (d->filter_regexp.isEmpty())
| 23768-46226 | ||||||||||||||||||
2705 | return true; executed 46226 times by 13 tests: return true; Executed by:
| 46226 | ||||||||||||||||||
2706 | if (d->filter_column == -1) {
| 5-23763 | ||||||||||||||||||
2707 | int column_count = d->model->columnCount(source_parent); | - | ||||||||||||||||||
2708 | for (int column = 0; column < column_count; ++column) {
| 2-11 | ||||||||||||||||||
2709 | QModelIndex source_index = d->model->index(source_row, column, source_parent); | - | ||||||||||||||||||
2710 | QString key = d->model->data(source_index, d->filter_role).toString(); | - | ||||||||||||||||||
2711 | if (key.contains(d->filter_regexp))
| 3-8 | ||||||||||||||||||
2712 | return true; executed 3 times by 1 test: return true; Executed by:
| 3 | ||||||||||||||||||
2713 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
2714 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
2715 | } | - | ||||||||||||||||||
2716 | QModelIndex source_index = d->model->index(source_row, d->filter_column, source_parent); | - | ||||||||||||||||||
2717 | if (!source_index.isValid()) // the column may not exist
| 3696-20067 | ||||||||||||||||||
2718 | return true; executed 3696 times by 1 test: return true; Executed by:
| 3696 | ||||||||||||||||||
2719 | QString key = d->model->data(source_index, d->filter_role).toString(); | - | ||||||||||||||||||
2720 | return key.contains(d->filter_regexp); executed 20067 times by 5 tests: return key.contains(d->filter_regexp); Executed by:
| 20067 | ||||||||||||||||||
2721 | } | - | ||||||||||||||||||
2722 | - | |||||||||||||||||||
2723 | /*! | - | ||||||||||||||||||
2724 | Returns \c true if the item in the column indicated by the given \a source_column | - | ||||||||||||||||||
2725 | and \a source_parent should be included in the model; otherwise returns \c false. | - | ||||||||||||||||||
2726 | - | |||||||||||||||||||
2727 | The default implementation returns \c true if the value held by the relevant item | - | ||||||||||||||||||
2728 | matches the filter string, wildcard string or regular expression. | - | ||||||||||||||||||
2729 | - | |||||||||||||||||||
2730 | \note By default, the Qt::DisplayRole is used to determine if the column | - | ||||||||||||||||||
2731 | should be accepted or not. This can be changed by setting the \l | - | ||||||||||||||||||
2732 | filterRole property. | - | ||||||||||||||||||
2733 | - | |||||||||||||||||||
2734 | \sa filterAcceptsRow(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard() | - | ||||||||||||||||||
2735 | */ | - | ||||||||||||||||||
2736 | bool QSortFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const | - | ||||||||||||||||||
2737 | { | - | ||||||||||||||||||
2738 | Q_UNUSED(source_column); | - | ||||||||||||||||||
2739 | Q_UNUSED(source_parent); | - | ||||||||||||||||||
2740 | return true; executed 32152 times by 13 tests: return true; Executed by:
| 32152 | ||||||||||||||||||
2741 | } | - | ||||||||||||||||||
2742 | - | |||||||||||||||||||
2743 | /*! | - | ||||||||||||||||||
2744 | Returns the source model index corresponding to the given \a | - | ||||||||||||||||||
2745 | proxyIndex from the sorting filter model. | - | ||||||||||||||||||
2746 | - | |||||||||||||||||||
2747 | \sa mapFromSource() | - | ||||||||||||||||||
2748 | */ | - | ||||||||||||||||||
2749 | QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const | - | ||||||||||||||||||
2750 | { | - | ||||||||||||||||||
2751 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2752 | return d->proxy_to_source(proxyIndex); executed 222798 times by 13 tests: return d->proxy_to_source(proxyIndex); Executed by:
| 222798 | ||||||||||||||||||
2753 | } | - | ||||||||||||||||||
2754 | - | |||||||||||||||||||
2755 | /*! | - | ||||||||||||||||||
2756 | Returns the model index in the QSortFilterProxyModel given the \a | - | ||||||||||||||||||
2757 | sourceIndex from the source model. | - | ||||||||||||||||||
2758 | - | |||||||||||||||||||
2759 | \sa mapToSource() | - | ||||||||||||||||||
2760 | */ | - | ||||||||||||||||||
2761 | QModelIndex QSortFilterProxyModel::mapFromSource(const QModelIndex &sourceIndex) const | - | ||||||||||||||||||
2762 | { | - | ||||||||||||||||||
2763 | Q_D(const QSortFilterProxyModel); | - | ||||||||||||||||||
2764 | return d->source_to_proxy(sourceIndex); executed 23903 times by 13 tests: return d->source_to_proxy(sourceIndex); Executed by:
| 23903 | ||||||||||||||||||
2765 | } | - | ||||||||||||||||||
2766 | - | |||||||||||||||||||
2767 | /*! | - | ||||||||||||||||||
2768 | \reimp | - | ||||||||||||||||||
2769 | */ | - | ||||||||||||||||||
2770 | QItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const | - | ||||||||||||||||||
2771 | { | - | ||||||||||||||||||
2772 | return QAbstractProxyModel::mapSelectionToSource(proxySelection); never executed: return QAbstractProxyModel::mapSelectionToSource(proxySelection); | 0 | ||||||||||||||||||
2773 | } | - | ||||||||||||||||||
2774 | - | |||||||||||||||||||
2775 | /*! | - | ||||||||||||||||||
2776 | \reimp | - | ||||||||||||||||||
2777 | */ | - | ||||||||||||||||||
2778 | QItemSelection QSortFilterProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const | - | ||||||||||||||||||
2779 | { | - | ||||||||||||||||||
2780 | return QAbstractProxyModel::mapSelectionFromSource(sourceSelection); executed 1 time by 1 test: return QAbstractProxyModel::mapSelectionFromSource(sourceSelection); Executed by:
| 1 | ||||||||||||||||||
2781 | } | - | ||||||||||||||||||
2782 | - | |||||||||||||||||||
2783 | QT_END_NAMESPACE | - | ||||||||||||||||||
2784 | - | |||||||||||||||||||
2785 | #include "moc_qsortfilterproxymodel.cpp" | - | ||||||||||||||||||
2786 | - | |||||||||||||||||||
2787 | #endif // QT_NO_SORTFILTERPROXYMODEL | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |