1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
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:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see 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 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qidentityproxymodel.h"
43
44 #ifndef QT_NO_IDENTITYPROXYMODEL
45
46 #include "qitemselectionmodel.h"
47 #include <private/qabstractproxymodel_p.h>
48
49 QT_BEGIN_NAMESPACE
50
51 class QIdentityProxyModelPrivate : public QAbstractProxyModelPrivate
52 {
QIdentityProxyModelPrivate()53 QIdentityProxyModelPrivate()
54 : ignoreNextLayoutAboutToBeChanged(false),
55 ignoreNextLayoutChanged(false)
56 {
57
58 }
59
60 Q_DECLARE_PUBLIC(QIdentityProxyModel)
61
62 bool ignoreNextLayoutAboutToBeChanged;
63 bool ignoreNextLayoutChanged;
64 QList<QPersistentModelIndex> layoutChangePersistentIndexes;
65 QModelIndexList proxyIndexes;
66
67 void _q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
68 void _q_sourceRowsInserted(const QModelIndex &parent, int start, int end);
69 void _q_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
70 void _q_sourceRowsRemoved(const QModelIndex &parent, int start, int end);
71 void _q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
72 void _q_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
73
74 void _q_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
75 void _q_sourceColumnsInserted(const QModelIndex &parent, int start, int end);
76 void _q_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
77 void _q_sourceColumnsRemoved(const QModelIndex &parent, int start, int end);
78 void _q_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
79 void _q_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
80
81 void _q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
82 void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last);
83
84 void _q_sourceLayoutAboutToBeChanged();
85 void _q_sourceLayoutChanged();
86 void _q_sourceModelAboutToBeReset();
87 void _q_sourceModelReset();
88
89 };
90
91 /*!
92 \since 4.8
93 \class QIdentityProxyModel
94 \brief The QIdentityProxyModel class proxies its source model unmodified
95
96 \ingroup model-view
97
98 QIdentityProxyModel can be used to forward the structure of a source model exactly, with no sorting, filtering or other transformation.
99 This is similar in concept to an identity matrix where A.I = A.
100
101 Because it does no sorting or filtering, this class is most suitable to proxy models which transform the data() of the source model.
102 For example, a proxy model could be created to define the font used, or the background colour, or the tooltip etc. This removes the
103 need to implement all data handling in the same class that creates the structure of the model, and can also be used to create
104 re-usable components.
105
106 This also provides a way to change the data in the case where a source model is supplied by a third party which can not be modified.
107
108 \snippet doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp 0
109
110 \sa QAbstractProxyModel, {Model/View Programming}, QAbstractItemModel
111
112 */
113
114 /*!
115 Constructs an identity model with the given \a parent.
116 */
QIdentityProxyModel(QObject * parent)117 QIdentityProxyModel::QIdentityProxyModel(QObject* parent)
118 : QAbstractProxyModel(*new QIdentityProxyModelPrivate, parent)
119 {
120
121 }
122
123 /*! \internal
124 */
QIdentityProxyModel(QIdentityProxyModelPrivate & dd,QObject * parent)125 QIdentityProxyModel::QIdentityProxyModel(QIdentityProxyModelPrivate &dd, QObject* parent)
126 : QAbstractProxyModel(dd, parent)
127 {
128
129 }
130
131 /*!
132 Destroys this identity model.
133 */
~QIdentityProxyModel()134 QIdentityProxyModel::~QIdentityProxyModel()
135 {
136 }
137
138 /*!
139 \reimp
140 */
columnCount(const QModelIndex & parent) const141 int QIdentityProxyModel::columnCount(const QModelIndex& parent) const
142 {
143 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
144 Q_D(const QIdentityProxyModel);
145 return d->model->columnCount(mapToSource(parent));
146 }
147
148 /*!
149 \reimp
150 */
dropMimeData(const QMimeData * data,Qt::DropAction action,int row,int column,const QModelIndex & parent)151 bool QIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
152 {
153 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
154 Q_D(QIdentityProxyModel);
155 return d->model->dropMimeData(data, action, row, column, mapToSource(parent));
156 }
157
158 /*!
159 \reimp
160 */
index(int row,int column,const QModelIndex & parent) const161 QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const
162 {
163 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
164 Q_D(const QIdentityProxyModel);
165 const QModelIndex sourceParent = mapToSource(parent);
166 const QModelIndex sourceIndex = d->model->index(row, column, sourceParent);
167 return mapFromSource(sourceIndex);
168 }
169
170 /*!
171 \reimp
172 */
insertColumns(int column,int count,const QModelIndex & parent)173 bool QIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent)
174 {
175 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
176 Q_D(QIdentityProxyModel);
177 return d->model->insertColumns(column, count, mapToSource(parent));
178 }
179
180 /*!
181 \reimp
182 */
insertRows(int row,int count,const QModelIndex & parent)183 bool QIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent)
184 {
185 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
186 Q_D(QIdentityProxyModel);
187 return d->model->insertRows(row, count, mapToSource(parent));
188 }
189
190 /*!
191 \reimp
192 */
mapFromSource(const QModelIndex & sourceIndex) const193 QModelIndex QIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
194 {
195 Q_D(const QIdentityProxyModel);
196 if (!d->model || !sourceIndex.isValid())
197 return QModelIndex();
198
199 Q_ASSERT(sourceIndex.model() == d->model);
200 return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
201 }
202
203 /*!
204 \reimp
205 */
mapSelectionFromSource(const QItemSelection & selection) const206 QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const
207 {
208 Q_D(const QIdentityProxyModel);
209 QItemSelection proxySelection;
210
211 if (!d->model)
212 return proxySelection;
213
214 QItemSelection::const_iterator it = selection.constBegin();
215 const QItemSelection::const_iterator end = selection.constEnd();
216 for ( ; it != end; ++it) {
217 Q_ASSERT(it->model() == d->model);
218 const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
219 proxySelection.append(range);
220 }
221
222 return proxySelection;
223 }
224
225 /*!
226 \reimp
227 */
mapSelectionToSource(const QItemSelection & selection) const228 QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
229 {
230 Q_D(const QIdentityProxyModel);
231 QItemSelection sourceSelection;
232
233 if (!d->model)
234 return sourceSelection;
235
236 QItemSelection::const_iterator it = selection.constBegin();
237 const QItemSelection::const_iterator end = selection.constEnd();
238 for ( ; it != end; ++it) {
239 Q_ASSERT(it->model() == this);
240 const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
241 sourceSelection.append(range);
242 }
243
244 return sourceSelection;
245 }
246
247 /*!
248 \reimp
249 */
mapToSource(const QModelIndex & proxyIndex) const250 QModelIndex QIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const
251 {
252 Q_D(const QIdentityProxyModel);
253 if (!d->model || !proxyIndex.isValid())
254 return QModelIndex();
255 Q_ASSERT(proxyIndex.model() == this);
256 return d->model->createIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer());
257 }
258
259 /*!
260 \reimp
261 */
match(const QModelIndex & start,int role,const QVariant & value,int hits,Qt::MatchFlags flags) const262 QModelIndexList QIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
263 {
264 Q_D(const QIdentityProxyModel);
265 Q_ASSERT(start.isValid() ? start.model() == this : true);
266 if (!d->model)
267 return QModelIndexList();
268
269 const QModelIndexList sourceList = d->model->match(mapToSource(start), role, value, hits, flags);
270 QModelIndexList::const_iterator it = sourceList.constBegin();
271 const QModelIndexList::const_iterator end = sourceList.constEnd();
272 QModelIndexList proxyList;
273 for ( ; it != end; ++it)
274 proxyList.append(mapFromSource(*it));
275 return proxyList;
276 }
277
278 /*!
279 \reimp
280 */
parent(const QModelIndex & child) const281 QModelIndex QIdentityProxyModel::parent(const QModelIndex& child) const
282 {
283 Q_ASSERT(child.isValid() ? child.model() == this : true);
284 const QModelIndex sourceIndex = mapToSource(child);
285 const QModelIndex sourceParent = sourceIndex.parent();
286 return mapFromSource(sourceParent);
287 }
288
289 /*!
290 \reimp
291 */
removeColumns(int column,int count,const QModelIndex & parent)292 bool QIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent)
293 {
294 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
295 Q_D(QIdentityProxyModel);
296 return d->model->removeColumns(column, count, mapToSource(parent));
297 }
298
299 /*!
300 \reimp
301 */
removeRows(int row,int count,const QModelIndex & parent)302 bool QIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent)
303 {
304 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
305 Q_D(QIdentityProxyModel);
306 return d->model->removeRows(row, count, mapToSource(parent));
307 }
308
309 /*!
310 \reimp
311 */
rowCount(const QModelIndex & parent) const312 int QIdentityProxyModel::rowCount(const QModelIndex& parent) const
313 {
314 Q_ASSERT(parent.isValid() ? parent.model() == this : true);
315 Q_D(const QIdentityProxyModel);
316 return d->model->rowCount(mapToSource(parent));
317 }
318
319 /*!
320 \reimp
321 */
setSourceModel(QAbstractItemModel * newSourceModel)322 void QIdentityProxyModel::setSourceModel(QAbstractItemModel* newSourceModel)
323 {
324 beginResetModel();
325
326 if (sourceModel()) {
327 disconnect(sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
328 this, SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int)));
329 disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
330 this, SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int)));
331 disconnect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
332 this, SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)));
333 disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
334 this, SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int)));
335 disconnect(sourceModel(), SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
336 this, SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
337 disconnect(sourceModel(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
338 this, SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
339 disconnect(sourceModel(), SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
340 this, SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int)));
341 disconnect(sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)),
342 this, SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int)));
343 disconnect(sourceModel(), SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)),
344 this, SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int)));
345 disconnect(sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
346 this, SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int)));
347 disconnect(sourceModel(), SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
348 this, SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
349 disconnect(sourceModel(), SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
350 this, SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
351 disconnect(sourceModel(), SIGNAL(modelAboutToBeReset()),
352 this, SLOT(_q_sourceModelAboutToBeReset()));
353 disconnect(sourceModel(), SIGNAL(modelReset()),
354 this, SLOT(_q_sourceModelReset()));
355 disconnect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
356 this, SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &)));
357 disconnect(sourceModel(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
358 this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
359 disconnect(sourceModel(), SIGNAL(layoutAboutToBeChanged()),
360 this, SLOT(_q_sourceLayoutAboutToBeChanged()));
361 disconnect(sourceModel(), SIGNAL(layoutChanged()),
362 this, SLOT(_q_sourceLayoutChanged()));
363 }
364
365 QAbstractProxyModel::setSourceModel(newSourceModel);
366
367 if (sourceModel()) {
368 connect(sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
369 SLOT(_q_sourceRowsAboutToBeInserted(const QModelIndex &, int, int)));
370 connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
371 SLOT(_q_sourceRowsInserted(const QModelIndex &, int, int)));
372 connect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
373 SLOT(_q_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)));
374 connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
375 SLOT(_q_sourceRowsRemoved(const QModelIndex &, int, int)));
376 connect(sourceModel(), SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
377 SLOT(_q_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
378 connect(sourceModel(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
379 SLOT(_q_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
380 connect(sourceModel(), SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
381 SLOT(_q_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int)));
382 connect(sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)),
383 SLOT(_q_sourceColumnsInserted(const QModelIndex &, int, int)));
384 connect(sourceModel(), SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)),
385 SLOT(_q_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int)));
386 connect(sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
387 SLOT(_q_sourceColumnsRemoved(const QModelIndex &, int, int)));
388 connect(sourceModel(), SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
389 SLOT(_q_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
390 connect(sourceModel(), SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
391 SLOT(_q_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
392 connect(sourceModel(), SIGNAL(modelAboutToBeReset()),
393 SLOT(_q_sourceModelAboutToBeReset()));
394 connect(sourceModel(), SIGNAL(modelReset()),
395 SLOT(_q_sourceModelReset()));
396 connect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
397 SLOT(_q_sourceDataChanged(const QModelIndex &, const QModelIndex &)));
398 connect(sourceModel(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
399 SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
400 connect(sourceModel(), SIGNAL(layoutAboutToBeChanged()),
401 SLOT(_q_sourceLayoutAboutToBeChanged()));
402 connect(sourceModel(), SIGNAL(layoutChanged()),
403 SLOT(_q_sourceLayoutChanged()));
404 }
405
406 endResetModel();
407 }
408
_q_sourceColumnsAboutToBeInserted(const QModelIndex & parent,int start,int end)409 void QIdentityProxyModelPrivate::_q_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
410 {
411 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
412 Q_Q(QIdentityProxyModel);
413 q->beginInsertColumns(q->mapFromSource(parent), start, end);
414 }
415
_q_sourceColumnsAboutToBeMoved(const QModelIndex & sourceParent,int sourceStart,int sourceEnd,const QModelIndex & destParent,int dest)416 void QIdentityProxyModelPrivate::_q_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
417 {
418 Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true);
419 Q_ASSERT(destParent.isValid() ? destParent.model() == model : true);
420 Q_Q(QIdentityProxyModel);
421 q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
422 }
423
_q_sourceColumnsAboutToBeRemoved(const QModelIndex & parent,int start,int end)424 void QIdentityProxyModelPrivate::_q_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
425 {
426 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
427 Q_Q(QIdentityProxyModel);
428 q->beginRemoveColumns(q->mapFromSource(parent), start, end);
429 }
430
_q_sourceColumnsInserted(const QModelIndex & parent,int start,int end)431 void QIdentityProxyModelPrivate::_q_sourceColumnsInserted(const QModelIndex &parent, int start, int end)
432 {
433 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
434 Q_Q(QIdentityProxyModel);
435 Q_UNUSED(parent)
436 Q_UNUSED(start)
437 Q_UNUSED(end)
438 q->endInsertColumns();
439 }
440
_q_sourceColumnsMoved(const QModelIndex & sourceParent,int sourceStart,int sourceEnd,const QModelIndex & destParent,int dest)441 void QIdentityProxyModelPrivate::_q_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
442 {
443 Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true);
444 Q_ASSERT(destParent.isValid() ? destParent.model() == model : true);
445 Q_Q(QIdentityProxyModel);
446 Q_UNUSED(sourceParent)
447 Q_UNUSED(sourceStart)
448 Q_UNUSED(sourceEnd)
449 Q_UNUSED(destParent)
450 Q_UNUSED(dest)
451 q->endMoveColumns();
452 }
453
_q_sourceColumnsRemoved(const QModelIndex & parent,int start,int end)454 void QIdentityProxyModelPrivate::_q_sourceColumnsRemoved(const QModelIndex &parent, int start, int end)
455 {
456 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
457 Q_Q(QIdentityProxyModel);
458 Q_UNUSED(parent)
459 Q_UNUSED(start)
460 Q_UNUSED(end)
461 q->endRemoveColumns();
462 }
463
_q_sourceDataChanged(const QModelIndex & topLeft,const QModelIndex & bottomRight)464 void QIdentityProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
465 {
466 Q_ASSERT(topLeft.isValid() ? topLeft.model() == model : true);
467 Q_ASSERT(bottomRight.isValid() ? bottomRight.model() == model : true);
468 Q_Q(QIdentityProxyModel);
469 q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight));
470 }
471
_q_sourceHeaderDataChanged(Qt::Orientation orientation,int first,int last)472 void QIdentityProxyModelPrivate::_q_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)
473 {
474 Q_Q(QIdentityProxyModel);
475 q->headerDataChanged(orientation, first, last);
476 }
477
_q_sourceLayoutAboutToBeChanged()478 void QIdentityProxyModelPrivate::_q_sourceLayoutAboutToBeChanged()
479 {
480 if (ignoreNextLayoutAboutToBeChanged)
481 return;
482
483 Q_Q(QIdentityProxyModel);
484
485 foreach(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
486 proxyIndexes << proxyPersistentIndex;
487 Q_ASSERT(proxyPersistentIndex.isValid());
488 const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
489 Q_ASSERT(srcPersistentIndex.isValid());
490 layoutChangePersistentIndexes << srcPersistentIndex;
491 }
492
493 q->layoutAboutToBeChanged();
494 }
495
_q_sourceLayoutChanged()496 void QIdentityProxyModelPrivate::_q_sourceLayoutChanged()
497 {
498 if (ignoreNextLayoutChanged)
499 return;
500
501 Q_Q(QIdentityProxyModel);
502
503 for (int i = 0; i < proxyIndexes.size(); ++i) {
504 q->changePersistentIndex(proxyIndexes.at(i), q->mapFromSource(layoutChangePersistentIndexes.at(i)));
505 }
506
507 layoutChangePersistentIndexes.clear();
508 proxyIndexes.clear();
509
510 q->layoutChanged();
511 }
512
_q_sourceModelAboutToBeReset()513 void QIdentityProxyModelPrivate::_q_sourceModelAboutToBeReset()
514 {
515 Q_Q(QIdentityProxyModel);
516 q->beginResetModel();
517 }
518
_q_sourceModelReset()519 void QIdentityProxyModelPrivate::_q_sourceModelReset()
520 {
521 Q_Q(QIdentityProxyModel);
522 q->endResetModel();
523 }
524
_q_sourceRowsAboutToBeInserted(const QModelIndex & parent,int start,int end)525 void QIdentityProxyModelPrivate::_q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
526 {
527 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
528 Q_Q(QIdentityProxyModel);
529 q->beginInsertRows(q->mapFromSource(parent), start, end);
530 }
531
_q_sourceRowsAboutToBeMoved(const QModelIndex & sourceParent,int sourceStart,int sourceEnd,const QModelIndex & destParent,int dest)532 void QIdentityProxyModelPrivate::_q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
533 {
534 Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true);
535 Q_ASSERT(destParent.isValid() ? destParent.model() == model : true);
536 Q_Q(QIdentityProxyModel);
537 q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
538 }
539
_q_sourceRowsAboutToBeRemoved(const QModelIndex & parent,int start,int end)540 void QIdentityProxyModelPrivate::_q_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
541 {
542 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
543 Q_Q(QIdentityProxyModel);
544 q->beginRemoveRows(q->mapFromSource(parent), start, end);
545 }
546
_q_sourceRowsInserted(const QModelIndex & parent,int start,int end)547 void QIdentityProxyModelPrivate::_q_sourceRowsInserted(const QModelIndex &parent, int start, int end)
548 {
549 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
550 Q_Q(QIdentityProxyModel);
551 Q_UNUSED(parent)
552 Q_UNUSED(start)
553 Q_UNUSED(end)
554 q->endInsertRows();
555 }
556
_q_sourceRowsMoved(const QModelIndex & sourceParent,int sourceStart,int sourceEnd,const QModelIndex & destParent,int dest)557 void QIdentityProxyModelPrivate::_q_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
558 {
559 Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == model : true);
560 Q_ASSERT(destParent.isValid() ? destParent.model() == model : true);
561 Q_Q(QIdentityProxyModel);
562 Q_UNUSED(sourceParent)
563 Q_UNUSED(sourceStart)
564 Q_UNUSED(sourceEnd)
565 Q_UNUSED(destParent)
566 Q_UNUSED(dest)
567 q->endMoveRows();
568 }
569
_q_sourceRowsRemoved(const QModelIndex & parent,int start,int end)570 void QIdentityProxyModelPrivate::_q_sourceRowsRemoved(const QModelIndex &parent, int start, int end)
571 {
572 Q_ASSERT(parent.isValid() ? parent.model() == model : true);
573 Q_Q(QIdentityProxyModel);
574 Q_UNUSED(parent)
575 Q_UNUSED(start)
576 Q_UNUSED(end)
577 q->endRemoveRows();
578 }
579
580 QT_END_NAMESPACE
581
582 #include "moc_qidentityproxymodel.cpp"
583
584 #endif // QT_NO_IDENTITYPROXYMODEL
585