• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.4 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • itemviews
kidentityproxymodel.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3  a KDAB Group company, info@kdab.net,
4  author Stephen Kelly <stephen@kdab.com>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "kidentityproxymodel.h"
23 
24 #include <QtGui/QItemSelection>
25 #include <QtCore/QStringList>
26 
27 class KIdentityProxyModelPrivate
28 {
29  KIdentityProxyModelPrivate(KIdentityProxyModel *qq)
30  : q_ptr(qq),
31  ignoreNextLayoutAboutToBeChanged(false),
32  ignoreNextLayoutChanged(false)
33  {
34 
35  }
36 
37  Q_DECLARE_PUBLIC(KIdentityProxyModel)
38  KIdentityProxyModel * const q_ptr;
39 
40  bool ignoreNextLayoutAboutToBeChanged;
41  bool ignoreNextLayoutChanged;
42  QList<QPersistentModelIndex> layoutChangePersistentIndexes;
43  QModelIndexList proxyIndexes;
44 
45  void _k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
46  void _k_sourceRowsInserted(const QModelIndex &parent, int start, int end);
47  void _k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
48  void _k_sourceRowsRemoved(const QModelIndex &parent, int start, int end);
49  void _k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
50  void _k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
51 
52  void _k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
53  void _k_sourceColumnsInserted(const QModelIndex &parent, int start, int end);
54  void _k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
55  void _k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end);
56  void _k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
57  void _k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
58 
59  void _k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
60  void _k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last);
61 
62  void _k_sourceLayoutAboutToBeChanged();
63  void _k_sourceLayoutChanged();
64  void _k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2);
65  void _k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2);
66  void _k_sourceModelAboutToBeReset();
67  void _k_sourceModelReset();
68  void _k_sourceModelDestroyed();
69 
70 };
71 
122 KIdentityProxyModel::KIdentityProxyModel(QObject* parent)
123  : QAbstractProxyModel(parent), d_ptr(new KIdentityProxyModelPrivate(this))
124 {
125 
126 }
127 
130 KIdentityProxyModel::KIdentityProxyModel(KIdentityProxyModelPrivate* privateClass, QObject* parent)
131  : QAbstractProxyModel(parent), d_ptr(privateClass)
132 {
133 
134 }
135 
139 KIdentityProxyModel::~KIdentityProxyModel()
140 {
141  delete d_ptr;
142 }
143 
147 bool KIdentityProxyModel::canFetchMore(const QModelIndex& parent) const
148 {
149  if (!sourceModel())
150  return 0;
151  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
152  return sourceModel()->canFetchMore(mapToSource(parent));
153 }
154 
158 int KIdentityProxyModel::columnCount(const QModelIndex& parent) const
159 {
160  if (!sourceModel())
161  return 0;
162  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
163  return sourceModel()->columnCount(mapToSource(parent));
164 }
165 
169 void KIdentityProxyModel::fetchMore(const QModelIndex& parent)
170 {
171  if (!sourceModel())
172  return;
173  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
174  sourceModel()->fetchMore(mapToSource(parent));
175 }
176 
180 bool KIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
181 {
182  if (!sourceModel())
183  return false;
184  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
185  return sourceModel()->dropMimeData(data, action, row, column, mapToSource(parent));
186 }
187 
191 QModelIndex KIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const
192 {
193  if (!sourceModel())
194  return QModelIndex();
195  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
196  if (row < 0 || column < 0 || !hasIndex(row, column, parent))
197  return QModelIndex();
198  const QModelIndex sourceParent = mapToSource(parent);
199  const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent);
200  Q_ASSERT(sourceIndex.isValid());
201  return mapFromSource(sourceIndex);
202 }
203 
207 bool KIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent)
208 {
209  if (!sourceModel())
210  return false;
211  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
212  return sourceModel()->insertColumns(column, count, mapToSource(parent));
213 }
214 
218 bool KIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent)
219 {
220  if (!sourceModel())
221  return false;
222  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
223  return sourceModel()->insertRows(row, count, mapToSource(parent));
224 }
225 
229 QModelIndex KIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
230 {
231  if (!sourceModel() || !sourceIndex.isValid())
232  return QModelIndex();
233 
234  Q_ASSERT(sourceIndex.model() == sourceModel());
235  return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
236 }
237 
241 QItemSelection KIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const
242 {
243  QItemSelection proxySelection;
244 
245  if (!sourceModel())
246  return proxySelection;
247 
248  QItemSelection::const_iterator it = selection.constBegin();
249  const QItemSelection::const_iterator end = selection.constEnd();
250  for ( ; it != end; ++it) {
251  Q_ASSERT(it->model() == sourceModel());
252  const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
253  proxySelection.append(range);
254  }
255 
256  return proxySelection;
257 }
258 
262 QItemSelection KIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
263 {
264  QItemSelection sourceSelection;
265 
266  if (!sourceModel())
267  return sourceSelection;
268 
269  QItemSelection::const_iterator it = selection.constBegin();
270  const QItemSelection::const_iterator end = selection.constEnd();
271  for ( ; it != end; ++it) {
272  Q_ASSERT(it->model() == this);
273  const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
274  sourceSelection.append(range);
275  }
276 
277  return sourceSelection;
278 }
279 
280 struct SourceModelIndex
281 {
282  SourceModelIndex(int _r, int _c, void *_p, QAbstractItemModel *_m)
283  : r(_r), c(_c), p(_p), m(_m)
284  {
285 
286  }
287 
288  operator QModelIndex() { return reinterpret_cast<QModelIndex&>(*this); }
289 
290  int r, c;
291  void *p;
292  const QAbstractItemModel *m;
293 };
294 
298 QModelIndex KIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const
299 {
300  if (!sourceModel() || !proxyIndex.isValid())
301  return QModelIndex();
302  Q_ASSERT(proxyIndex.model() == this);
303  return SourceModelIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer(), sourceModel());
304 }
305 
309 QModelIndexList KIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
310 {
311  Q_ASSERT(start.isValid() ? start.model() == this : true);
312  if (!sourceModel())
313  return QModelIndexList();
314 
315  const QModelIndexList sourceList = sourceModel()->match(mapToSource(start), role, value, hits, flags);
316  QModelIndexList::const_iterator it = sourceList.constBegin();
317  const QModelIndexList::const_iterator end = sourceList.constEnd();
318  QModelIndexList proxyList;
319  for ( ; it != end; ++it)
320  proxyList.append(mapFromSource(*it));
321  return proxyList;
322 }
323 
327 QStringList KIdentityProxyModel::mimeTypes() const
328 {
329  if (sourceModel())
330  return sourceModel()->mimeTypes();
331  else
332  return QAbstractProxyModel::mimeTypes();
333 }
334 
335 QMimeData* KIdentityProxyModel::mimeData(const QModelIndexList& indexes) const
336 {
337  if (!sourceModel())
338  return QAbstractProxyModel::mimeData(indexes);
339 
340  QModelIndexList proxyIndexes;
341  foreach(const QModelIndex &index, indexes)
342  proxyIndexes.append(mapToSource(index));
343 
344  return sourceModel()->mimeData(proxyIndexes);
345 }
346 
347 
351 QModelIndex KIdentityProxyModel::parent(const QModelIndex& child) const
352 {
353  if (!sourceModel())
354  return QModelIndex();
355 
356  Q_ASSERT(child.isValid() ? child.model() == this : true);
357  const QModelIndex sourceIndex = mapToSource(child);
358  const QModelIndex sourceParent = sourceIndex.parent();
359  return mapFromSource(sourceParent);
360 }
361 
365 bool KIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent)
366 {
367  if (!sourceModel())
368  return false;
369 
370  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
371  return sourceModel()->removeColumns(column, count, mapToSource(parent));
372 }
373 
377 bool KIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent)
378 {
379  if (!sourceModel())
380  return false;
381 
382  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
383  return sourceModel()->removeRows(row, count, mapToSource(parent));
384 }
385 
389 int KIdentityProxyModel::rowCount(const QModelIndex& parent) const
390 {
391  if (!sourceModel())
392  return 0;
393  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
394  return sourceModel()->rowCount(mapToSource(parent));
395 }
396 
400 void KIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
401 {
402  beginResetModel();
403 
404  if (sourceModel) {
405  disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
406  this, SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
407  disconnect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
408  this, SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
409  disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
410  this, SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
411  disconnect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
412  this, SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
413  disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
414  this, SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
415  disconnect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
416  this, SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
417  disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
418  this, SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
419  disconnect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
420  this, SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
421  disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
422  this, SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
423  disconnect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
424  this, SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
425  disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
426  this, SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
427  disconnect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
428  this, SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
429  disconnect(sourceModel, SIGNAL(modelAboutToBeReset()),
430  this, SLOT(_k_sourceModelAboutToBeReset()));
431 // disconnect(sourceModel, SIGNAL(internalDataReset()),
432 // this, SLOT(resetInternalData()));
433  disconnect(sourceModel, SIGNAL(modelReset()),
434  this, SLOT(_k_sourceModelReset()));
435  disconnect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
436  this, SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
437  disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
438  this, SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
439  disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
440  this, SLOT(_k_sourceLayoutAboutToBeChanged()));
441  disconnect(sourceModel, SIGNAL(layoutChanged()),
442  this, SLOT(_k_sourceLayoutChanged()));
443 // disconnect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
444 // this, SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
445 // disconnect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
446 // this, SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
447  disconnect(sourceModel, SIGNAL(destroyed()),
448  this, SLOT(_k_sourceModelDestroyed()));
449  }
450 
451  QAbstractProxyModel::setSourceModel(sourceModel);
452 
453  if (sourceModel) {
454  connect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
455  SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
456  connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
457  SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
458  connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
459  SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
460  connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
461  SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
462  connect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
463  SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
464  connect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
465  SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
466  connect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
467  SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
468  connect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
469  SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
470  connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
471  SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
472  connect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
473  SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
474  connect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
475  SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
476  connect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
477  SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
478  connect(sourceModel, SIGNAL(modelAboutToBeReset()),
479  SLOT(_k_sourceModelAboutToBeReset()));
480 // connect(sourceModel, SIGNAL(internalDataReset()),
481 // SLOT(resetInternalData()));
482  connect(sourceModel, SIGNAL(modelReset()),
483  SLOT(_k_sourceModelReset()));
484  connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
485  SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
486  connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
487  SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
488  connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
489  SLOT(_k_sourceLayoutAboutToBeChanged()));
490  connect(sourceModel, SIGNAL(layoutChanged()),
491  SLOT(_k_sourceLayoutChanged()));
492  // Hopefully this will be in Qt4.8
493 // connect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
494 // SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
495 // connect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
496 // SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
497  connect(sourceModel, SIGNAL(destroyed()),
498  SLOT(_k_sourceModelDestroyed()));
499  }
500 
501  endResetModel();
502 }
503 
504 Qt::DropActions KIdentityProxyModel::supportedDropActions() const
505 {
506  if (sourceModel())
507  return sourceModel()->supportedDropActions();
508  else
509  return QAbstractProxyModel::supportedDropActions();
510 }
511 
512 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
513 {
514  Q_Q(KIdentityProxyModel);
515  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
516  q->beginInsertColumns(q->mapFromSource(parent), start, end);
517 }
518 
519 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
520 {
521  Q_Q(KIdentityProxyModel);
522  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
523  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
524  q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
525 }
526 
527 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
528 {
529  Q_Q(KIdentityProxyModel);
530  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
531  q->beginRemoveColumns(q->mapFromSource(parent), start, end);
532 }
533 
534 void KIdentityProxyModelPrivate::_k_sourceColumnsInserted(const QModelIndex &parent, int start, int end)
535 {
536  Q_Q(KIdentityProxyModel);
537  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
538  Q_UNUSED(parent)
539  Q_UNUSED(start)
540  Q_UNUSED(end)
541  q->endInsertColumns();
542 }
543 
544 void KIdentityProxyModelPrivate::_k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
545 {
546  Q_Q(KIdentityProxyModel);
547  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
548  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
549  Q_UNUSED(sourceParent)
550  Q_UNUSED(sourceStart)
551  Q_UNUSED(sourceEnd)
552  Q_UNUSED(destParent)
553  Q_UNUSED(dest)
554  q->endMoveColumns();
555 }
556 
557 void KIdentityProxyModelPrivate::_k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end)
558 {
559  Q_Q(KIdentityProxyModel);
560  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
561  Q_UNUSED(parent)
562  Q_UNUSED(start)
563  Q_UNUSED(end)
564  q->endRemoveColumns();
565 }
566 
567 void KIdentityProxyModelPrivate::_k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
568 {
569  Q_Q(KIdentityProxyModel);
570  Q_ASSERT(topLeft.model() == q->sourceModel());
571  Q_ASSERT(bottomRight.model() == q->sourceModel());
572  q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight));
573 }
574 
575 void KIdentityProxyModelPrivate::_k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)
576 {
577  Q_Q(KIdentityProxyModel);
578  q->headerDataChanged(orientation, first, last);
579 }
580 
581 void KIdentityProxyModelPrivate::_k_sourceLayoutAboutToBeChanged()
582 {
583  if (ignoreNextLayoutAboutToBeChanged)
584  return;
585 
586  Q_Q(KIdentityProxyModel);
587 
588  q->layoutAboutToBeChanged();
589 
590  Q_FOREACH(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
591  proxyIndexes << proxyPersistentIndex;
592  Q_ASSERT(proxyPersistentIndex.isValid());
593  const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
594  Q_ASSERT(srcPersistentIndex.isValid());
595  layoutChangePersistentIndexes << srcPersistentIndex;
596  }
597 }
598 
599 void KIdentityProxyModelPrivate::_k_sourceLayoutChanged()
600 {
601  if (ignoreNextLayoutChanged)
602  return;
603 
604  Q_Q(KIdentityProxyModel);
605 
606  // We need to ensure that we don't modify persistent model indexes whose
607  // column lies outside the source model. For example, KPIM::StatisticsProxyModel
608  // adds additional columns and manages their persistent indexes.
609  // We need to avoid calling changePersistentIndex with those.
610  const int columnCount = q->sourceModel()->columnCount();
611  for (int i = 0; i < proxyIndexes.size(); ++i) {
612  const QModelIndex oldProxyIndex = proxyIndexes.at(i);
613  if (oldProxyIndex.column() < columnCount)
614  q->changePersistentIndex(oldProxyIndex, q->mapFromSource(layoutChangePersistentIndexes.at(i)));
615  }
616 
617  layoutChangePersistentIndexes.clear();
618  proxyIndexes.clear();
619 
620  q->layoutChanged();
621 }
622 
623 
624 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2)
625 {
626  Q_Q(KIdentityProxyModel);
627  Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
628  Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
629 
630 
631  ignoreNextLayoutAboutToBeChanged = true;
632 
633  const QModelIndex proxyParent1 = q->mapFromSource(parent1);
634  const QModelIndex proxyParent2 = q->mapFromSource(parent2);
635  //emit q->childrenLayoutsAboutToBeChanged(proxyParent1, proxyParent2);
636  emit q->layoutAboutToBeChanged();
637 
638  if (q->persistentIndexList().isEmpty())
639  return;
640 
641  Q_FOREACH(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
642  const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
643  Q_ASSERT(proxyPersistentIndex.isValid());
644  Q_ASSERT(srcPersistentIndex.isValid());
645  const QModelIndex idxParent = srcPersistentIndex.parent();
646  if (idxParent != parent1 && idxParent != parent2)
647  continue;
648  proxyIndexes << proxyPersistentIndex;
649  layoutChangePersistentIndexes << srcPersistentIndex;
650  }
651 }
652 
653 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2)
654 {
655  Q_Q(KIdentityProxyModel);
656  Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
657  Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
658 
659  ignoreNextLayoutChanged = true;
660 
661  QModelIndexList oldList, newList;
662  for( int i = 0; i < layoutChangePersistentIndexes.size(); ++i) {
663  const QModelIndex srcIdx = layoutChangePersistentIndexes.at(i);
664  const QModelIndex oldProxyIdx = proxyIndexes.at(i);
665  oldList << oldProxyIdx;
666  newList << q->mapFromSource(srcIdx);
667  }
668  q->changePersistentIndexList(oldList, newList);
669  layoutChangePersistentIndexes.clear();
670  proxyIndexes.clear();
671 
672  const QModelIndex proxyParent1 = q->mapFromSource(parent1);
673  const QModelIndex proxyParent2 = q->mapFromSource(parent2);
674 // emit q->childrenLayoutsChanged(proxyParent1, proxyParent2);
675  emit q->layoutChanged();
676 }
677 
678 void KIdentityProxyModelPrivate::_k_sourceModelAboutToBeReset()
679 {
680  Q_Q(KIdentityProxyModel);
681  q->beginResetModel();
682 }
683 
684 void KIdentityProxyModelPrivate::_k_sourceModelReset()
685 {
686  Q_Q(KIdentityProxyModel);
687  q->endResetModel();
688 }
689 
690 void KIdentityProxyModelPrivate::_k_sourceModelDestroyed()
691 {
692 // Q_Q(KIdentityProxyModel);
693 // q->endResetModel();
694 }
695 
696 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
697 {
698  Q_Q(KIdentityProxyModel);
699  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
700  q->beginInsertRows(q->mapFromSource(parent), start, end);
701 }
702 
703 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
704 {
705  Q_Q(KIdentityProxyModel);
706  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
707  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
708  q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
709 }
710 
711 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
712 {
713  Q_Q(KIdentityProxyModel);
714  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
715  q->beginRemoveRows(q->mapFromSource(parent), start, end);
716 }
717 
718 void KIdentityProxyModelPrivate::_k_sourceRowsInserted(const QModelIndex &parent, int start, int end)
719 {
720  Q_Q(KIdentityProxyModel);
721  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
722  Q_UNUSED(parent)
723  Q_UNUSED(start)
724  Q_UNUSED(end)
725  q->endInsertRows();
726 }
727 
728 void KIdentityProxyModelPrivate::_k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
729 {
730  Q_Q(KIdentityProxyModel);
731  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
732  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
733  Q_UNUSED(sourceParent)
734  Q_UNUSED(sourceStart)
735  Q_UNUSED(sourceEnd)
736  Q_UNUSED(destParent)
737  Q_UNUSED(dest)
738  q->endMoveRows();
739 }
740 
741 void KIdentityProxyModelPrivate::_k_sourceRowsRemoved(const QModelIndex &parent, int start, int end)
742 {
743  Q_Q(KIdentityProxyModel);
744  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
745  Q_UNUSED(parent)
746  Q_UNUSED(start)
747  Q_UNUSED(end)
748  q->endRemoveRows();
749 }
750 
756 void KIdentityProxyModel::resetInternalData()
757 {
758 
759 }
760 
761 #include "kidentityproxymodel.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Jul 17 2012 07:31:07 by doxygen 1.8.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.8.4 API Reference

Skip menu "kdelibs-4.8.4 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal