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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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 #include <kdebug.h>
27 
28 class KIdentityProxyModelPrivate
29 {
30  KIdentityProxyModelPrivate(KIdentityProxyModel *qq)
31  : q_ptr(qq)
32 // ignoreNextLayoutAboutToBeChanged(false),
33 // ignoreNextLayoutChanged(false)
34  {
35 
36  }
37 
38  Q_DECLARE_PUBLIC(KIdentityProxyModel)
39  KIdentityProxyModel * const q_ptr;
40 
41 // bool ignoreNextLayoutAboutToBeChanged;
42 // bool ignoreNextLayoutChanged;
43  QList<QPersistentModelIndex> layoutChangePersistentIndexes;
44  QModelIndexList proxyIndexes;
45 
46  void _k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
47  void _k_sourceRowsInserted(const QModelIndex &parent, int start, int end);
48  void _k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
49  void _k_sourceRowsRemoved(const QModelIndex &parent, int start, int end);
50  void _k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
51  void _k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
52 
53  void _k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
54  void _k_sourceColumnsInserted(const QModelIndex &parent, int start, int end);
55  void _k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
56  void _k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end);
57  void _k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
58  void _k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
59 
60  void _k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
61  void _k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last);
62 
63  void _k_sourceLayoutAboutToBeChanged();
64  void _k_sourceLayoutChanged();
65 // void _k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2);
66 // void _k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2);
67  void _k_sourceModelAboutToBeReset();
68  void _k_sourceModelReset();
69  void _k_sourceModelDestroyed();
70 
71 };
72 
123 KIdentityProxyModel::KIdentityProxyModel(QObject* parent)
124  : QAbstractProxyModel(parent), d_ptr(new KIdentityProxyModelPrivate(this))
125 {
126 
127 }
128 
131 KIdentityProxyModel::KIdentityProxyModel(KIdentityProxyModelPrivate* privateClass, QObject* parent)
132  : QAbstractProxyModel(parent), d_ptr(privateClass)
133 {
134 
135 }
136 
140 KIdentityProxyModel::~KIdentityProxyModel()
141 {
142  delete d_ptr;
143 }
144 
148 bool KIdentityProxyModel::canFetchMore(const QModelIndex& parent) const
149 {
150  if (!sourceModel())
151  return 0;
152  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
153  return sourceModel()->canFetchMore(mapToSource(parent));
154 }
155 
159 int KIdentityProxyModel::columnCount(const QModelIndex& parent) const
160 {
161  if (!sourceModel())
162  return 0;
163  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
164  return sourceModel()->columnCount(mapToSource(parent));
165 }
166 
170 void KIdentityProxyModel::fetchMore(const QModelIndex& parent)
171 {
172  if (!sourceModel())
173  return;
174  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
175  sourceModel()->fetchMore(mapToSource(parent));
176 }
177 
181 bool KIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
182 {
183  if (!sourceModel())
184  return false;
185  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
186  return sourceModel()->dropMimeData(data, action, row, column, mapToSource(parent));
187 }
188 
193 QVariant KIdentityProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
194 {
195  if (!sourceModel())
196  return QVariant();
197  return sourceModel()->headerData(section, orientation, role);
198 }
199 
203 QModelIndex KIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const
204 {
205  if (!sourceModel())
206  return QModelIndex();
207  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
208  const QModelIndex sourceParent = mapToSource(parent);
209  const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent);
210  return mapFromSource(sourceIndex);
211 }
212 
216 bool KIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent)
217 {
218  if (!sourceModel())
219  return false;
220  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
221  return sourceModel()->insertColumns(column, count, mapToSource(parent));
222 }
223 
227 bool KIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent)
228 {
229  if (!sourceModel())
230  return false;
231  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
232  return sourceModel()->insertRows(row, count, mapToSource(parent));
233 }
234 
238 QModelIndex KIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
239 {
240  if (!sourceModel() || !sourceIndex.isValid())
241  return QModelIndex();
242 
243  Q_ASSERT(sourceIndex.model() == sourceModel());
244  return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
245 }
246 
250 QItemSelection KIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const
251 {
252  QItemSelection proxySelection;
253 
254  if (!sourceModel())
255  return proxySelection;
256 
257  QItemSelection::const_iterator it = selection.constBegin();
258  const QItemSelection::const_iterator end = selection.constEnd();
259  for ( ; it != end; ++it) {
260  Q_ASSERT(it->model() == sourceModel());
261  const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
262  proxySelection.append(range);
263  }
264 
265  return proxySelection;
266 }
267 
271 QItemSelection KIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
272 {
273  QItemSelection sourceSelection;
274 
275  if (!sourceModel())
276  return sourceSelection;
277 
278  QItemSelection::const_iterator it = selection.constBegin();
279  const QItemSelection::const_iterator end = selection.constEnd();
280  for ( ; it != end; ++it) {
281  Q_ASSERT(it->model() == this);
282  const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
283  sourceSelection.append(range);
284  }
285 
286  return sourceSelection;
287 }
288 
289 struct SourceModelIndex
290 {
291  SourceModelIndex(int _r, int _c, void *_p, QAbstractItemModel *_m)
292  : r(_r), c(_c), p(_p), m(_m)
293  {
294 
295  }
296 
297  operator QModelIndex() { return reinterpret_cast<QModelIndex&>(*this); }
298 
299  int r, c;
300  void *p;
301  const QAbstractItemModel *m;
302 };
303 
307 QModelIndex KIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const
308 {
309  if (!sourceModel() || !proxyIndex.isValid())
310  return QModelIndex();
311  Q_ASSERT(proxyIndex.model() == this);
312  return SourceModelIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer(), sourceModel());
313 }
314 
318 QModelIndexList KIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
319 {
320  Q_ASSERT(start.isValid() ? start.model() == this : true);
321  if (!sourceModel())
322  return QModelIndexList();
323 
324  const QModelIndexList sourceList = sourceModel()->match(mapToSource(start), role, value, hits, flags);
325  QModelIndexList::const_iterator it = sourceList.constBegin();
326  const QModelIndexList::const_iterator end = sourceList.constEnd();
327  QModelIndexList proxyList;
328  for ( ; it != end; ++it)
329  proxyList.append(mapFromSource(*it));
330  return proxyList;
331 }
332 
336 QStringList KIdentityProxyModel::mimeTypes() const
337 {
338  if (sourceModel())
339  return sourceModel()->mimeTypes();
340  else
341  return QAbstractProxyModel::mimeTypes();
342 }
343 
344 QMimeData* KIdentityProxyModel::mimeData(const QModelIndexList& indexes) const
345 {
346  if (!sourceModel())
347  return QAbstractProxyModel::mimeData(indexes);
348 
349  QModelIndexList proxyIndexes;
350  foreach(const QModelIndex &index, indexes)
351  proxyIndexes.append(mapToSource(index));
352 
353  return sourceModel()->mimeData(proxyIndexes);
354 }
355 
356 
360 QModelIndex KIdentityProxyModel::parent(const QModelIndex& child) const
361 {
362  if (!sourceModel())
363  return QModelIndex();
364 
365  Q_ASSERT(child.isValid() ? child.model() == this : true);
366  const QModelIndex sourceIndex = mapToSource(child);
367  const QModelIndex sourceParent = sourceIndex.parent();
368  return mapFromSource(sourceParent);
369 }
370 
374 bool KIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent)
375 {
376  if (!sourceModel())
377  return false;
378 
379  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
380  return sourceModel()->removeColumns(column, count, mapToSource(parent));
381 }
382 
386 bool KIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent)
387 {
388  if (!sourceModel())
389  return false;
390 
391  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
392  return sourceModel()->removeRows(row, count, mapToSource(parent));
393 }
394 
398 int KIdentityProxyModel::rowCount(const QModelIndex& parent) const
399 {
400  if (!sourceModel())
401  return 0;
402  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
403  return sourceModel()->rowCount(mapToSource(parent));
404 }
405 
409 void KIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
410 {
411  beginResetModel();
412 
413  if (sourceModel) {
414  disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
415  this, SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
416  disconnect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
417  this, SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
418  disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
419  this, SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
420  disconnect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
421  this, SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
422  disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
423  this, SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
424  disconnect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
425  this, SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
426  disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
427  this, SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
428  disconnect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
429  this, SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
430  disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
431  this, SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
432  disconnect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
433  this, SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
434  disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
435  this, SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
436  disconnect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
437  this, SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
438  disconnect(sourceModel, SIGNAL(modelAboutToBeReset()),
439  this, SLOT(_k_sourceModelAboutToBeReset()));
440 // disconnect(sourceModel, SIGNAL(internalDataReset()),
441 // this, SLOT(resetInternalData()));
442  disconnect(sourceModel, SIGNAL(modelReset()),
443  this, SLOT(_k_sourceModelReset()));
444  disconnect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
445  this, SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
446  disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
447  this, SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
448  disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
449  this, SLOT(_k_sourceLayoutAboutToBeChanged()));
450  disconnect(sourceModel, SIGNAL(layoutChanged()),
451  this, SLOT(_k_sourceLayoutChanged()));
452 // disconnect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
453 // this, SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
454 // disconnect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
455 // this, SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
456  disconnect(sourceModel, SIGNAL(destroyed()),
457  this, SLOT(_k_sourceModelDestroyed()));
458  }
459 
460  QAbstractProxyModel::setSourceModel(sourceModel);
461 
462  if (sourceModel) {
463  connect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
464  SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
465  connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
466  SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
467  connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
468  SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
469  connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
470  SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
471  connect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
472  SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
473  connect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
474  SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
475  connect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
476  SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
477  connect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
478  SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
479  connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
480  SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
481  connect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
482  SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
483  connect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
484  SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
485  connect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
486  SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
487  connect(sourceModel, SIGNAL(modelAboutToBeReset()),
488  SLOT(_k_sourceModelAboutToBeReset()));
489 // connect(sourceModel, SIGNAL(internalDataReset()),
490 // SLOT(resetInternalData()));
491  connect(sourceModel, SIGNAL(modelReset()),
492  SLOT(_k_sourceModelReset()));
493  connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
494  SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
495  connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
496  SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
497  connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
498  SLOT(_k_sourceLayoutAboutToBeChanged()));
499  connect(sourceModel, SIGNAL(layoutChanged()),
500  SLOT(_k_sourceLayoutChanged()));
501  // Hopefully this will be in Qt4.8
502 // connect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
503 // SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
504 // connect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
505 // SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
506  connect(sourceModel, SIGNAL(destroyed()),
507  SLOT(_k_sourceModelDestroyed()));
508  }
509 
510  endResetModel();
511 }
512 
513 Qt::DropActions KIdentityProxyModel::supportedDropActions() const
514 {
515  if (sourceModel())
516  return sourceModel()->supportedDropActions();
517  else
518  return QAbstractProxyModel::supportedDropActions();
519 }
520 
521 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
522 {
523  Q_Q(KIdentityProxyModel);
524  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
525  q->beginInsertColumns(q->mapFromSource(parent), start, end);
526 }
527 
528 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
529 {
530  Q_Q(KIdentityProxyModel);
531  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
532  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
533  q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
534 }
535 
536 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
537 {
538  Q_Q(KIdentityProxyModel);
539  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
540  q->beginRemoveColumns(q->mapFromSource(parent), start, end);
541 }
542 
543 void KIdentityProxyModelPrivate::_k_sourceColumnsInserted(const QModelIndex &parent, int start, int end)
544 {
545  Q_Q(KIdentityProxyModel);
546  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
547  Q_UNUSED(parent)
548  Q_UNUSED(start)
549  Q_UNUSED(end)
550  q->endInsertColumns();
551 }
552 
553 void KIdentityProxyModelPrivate::_k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
554 {
555  Q_Q(KIdentityProxyModel);
556  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
557  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
558  Q_UNUSED(sourceParent)
559  Q_UNUSED(sourceStart)
560  Q_UNUSED(sourceEnd)
561  Q_UNUSED(destParent)
562  Q_UNUSED(dest)
563  q->endMoveColumns();
564 }
565 
566 void KIdentityProxyModelPrivate::_k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end)
567 {
568  Q_Q(KIdentityProxyModel);
569  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
570  Q_UNUSED(parent)
571  Q_UNUSED(start)
572  Q_UNUSED(end)
573  q->endRemoveColumns();
574 }
575 
576 void KIdentityProxyModelPrivate::_k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
577 {
578  Q_Q(KIdentityProxyModel);
579  Q_ASSERT(topLeft.model() == q->sourceModel());
580  Q_ASSERT(bottomRight.model() == q->sourceModel());
581  q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight));
582 }
583 
584 void KIdentityProxyModelPrivate::_k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)
585 {
586  Q_Q(KIdentityProxyModel);
587  q->headerDataChanged(orientation, first, last);
588 }
589 
590 void KIdentityProxyModelPrivate::_k_sourceLayoutAboutToBeChanged()
591 {
592  //if (ignoreNextLayoutAboutToBeChanged)
593  // return;
594 
595  Q_Q(KIdentityProxyModel);
596 
597  q->layoutAboutToBeChanged();
598 
599  Q_FOREACH(const QModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
600  Q_ASSERT(proxyPersistentIndex.isValid());
601  const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
602  if (!srcPersistentIndex.isValid()) // can happen with extra columns, e.g. KPIM::StatisticsProxyModel
603  continue;
604  proxyIndexes << proxyPersistentIndex;
605  layoutChangePersistentIndexes << srcPersistentIndex;
606  }
607 }
608 
609 void KIdentityProxyModelPrivate::_k_sourceLayoutChanged()
610 {
611  //if (ignoreNextLayoutChanged)
612  // return;
613 
614  Q_Q(KIdentityProxyModel);
615 
616  for (int i = 0; i < proxyIndexes.size(); ++i) {
617  const QModelIndex oldProxyIndex = proxyIndexes.at(i);
618  const QModelIndex newProxyIndex = q->mapFromSource(layoutChangePersistentIndexes.at(i));
619  if (oldProxyIndex != newProxyIndex)
620  q->changePersistentIndex(oldProxyIndex, newProxyIndex);
621  }
622 
623  layoutChangePersistentIndexes.clear();
624  proxyIndexes.clear();
625 
626  q->layoutChanged();
627 }
628 
629 #if 0 // this code was for the stuff that never went into Qt-4.8. We are keeping it for the Qt5 QIPM sourceLayoutChanged(QModelIndex) future code.
630 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2)
631 {
632  Q_Q(KIdentityProxyModel);
633  Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
634  Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
635 
636 
637  ignoreNextLayoutAboutToBeChanged = true;
638 
639  const QModelIndex proxyParent1 = q->mapFromSource(parent1);
640  const QModelIndex proxyParent2 = q->mapFromSource(parent2);
641  //emit q->childrenLayoutsAboutToBeChanged(proxyParent1, proxyParent2);
642  emit q->layoutAboutToBeChanged();
643 
644  if (q->persistentIndexList().isEmpty())
645  return;
646 
647  Q_FOREACH(const QModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
648  const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
649  Q_ASSERT(proxyPersistentIndex.isValid());
650  Q_ASSERT(srcPersistentIndex.isValid());
651  const QModelIndex idxParent = srcPersistentIndex.parent();
652  if (idxParent != parent1 && idxParent != parent2)
653  continue;
654  proxyIndexes << proxyPersistentIndex;
655  layoutChangePersistentIndexes << srcPersistentIndex;
656  }
657 }
658 
659 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2)
660 {
661  Q_Q(KIdentityProxyModel);
662  Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
663  Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
664 
665  ignoreNextLayoutChanged = true;
666 
667  QModelIndexList oldList, newList;
668  for( int i = 0; i < layoutChangePersistentIndexes.size(); ++i) {
669  const QModelIndex srcIdx = layoutChangePersistentIndexes.at(i);
670  const QModelIndex oldProxyIdx = proxyIndexes.at(i);
671  oldList << oldProxyIdx;
672  newList << q->mapFromSource(srcIdx);
673  }
674  q->changePersistentIndexList(oldList, newList);
675  layoutChangePersistentIndexes.clear();
676  proxyIndexes.clear();
677 
678  const QModelIndex proxyParent1 = q->mapFromSource(parent1);
679  const QModelIndex proxyParent2 = q->mapFromSource(parent2);
680 // emit q->childrenLayoutsChanged(proxyParent1, proxyParent2);
681  emit q->layoutChanged();
682 }
683 #endif
684 
685 void KIdentityProxyModelPrivate::_k_sourceModelAboutToBeReset()
686 {
687  Q_Q(KIdentityProxyModel);
688  q->beginResetModel();
689 }
690 
691 void KIdentityProxyModelPrivate::_k_sourceModelReset()
692 {
693  Q_Q(KIdentityProxyModel);
694  q->endResetModel();
695 }
696 
697 void KIdentityProxyModelPrivate::_k_sourceModelDestroyed()
698 {
699 // Q_Q(KIdentityProxyModel);
700 // q->endResetModel();
701 }
702 
703 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
704 {
705  Q_Q(KIdentityProxyModel);
706  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
707  q->beginInsertRows(q->mapFromSource(parent), start, end);
708 }
709 
710 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
711 {
712  Q_Q(KIdentityProxyModel);
713  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
714  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
715  q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
716 }
717 
718 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
719 {
720  Q_Q(KIdentityProxyModel);
721  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
722  q->beginRemoveRows(q->mapFromSource(parent), start, end);
723 }
724 
725 void KIdentityProxyModelPrivate::_k_sourceRowsInserted(const QModelIndex &parent, int start, int end)
726 {
727  Q_Q(KIdentityProxyModel);
728  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
729  Q_UNUSED(parent)
730  Q_UNUSED(start)
731  Q_UNUSED(end)
732  q->endInsertRows();
733 }
734 
735 void KIdentityProxyModelPrivate::_k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
736 {
737  Q_Q(KIdentityProxyModel);
738  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
739  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
740  Q_UNUSED(sourceParent)
741  Q_UNUSED(sourceStart)
742  Q_UNUSED(sourceEnd)
743  Q_UNUSED(destParent)
744  Q_UNUSED(dest)
745  q->endMoveRows();
746 }
747 
748 void KIdentityProxyModelPrivate::_k_sourceRowsRemoved(const QModelIndex &parent, int start, int end)
749 {
750  Q_Q(KIdentityProxyModel);
751  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
752  Q_UNUSED(parent)
753  Q_UNUSED(start)
754  Q_UNUSED(end)
755  q->endRemoveRows();
756 }
757 
763 void KIdentityProxyModel::resetInternalData()
764 {
765 
766 }
767 
768 #include "kidentityproxymodel.moc"
QAbstractItemModel::columnsMoved
void columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
QModelIndex
KIdentityProxyModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:386
KIdentityProxyModel
The KIdentityProxyModel class proxies its source model unmodified.
Definition: kidentityproxymodel.h:31
QAbstractItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const =0
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
KIdentityProxyModel::insertColumns
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:216
QItemSelectionRange
kdebug.h
QAbstractItemModel::layoutChanged
void layoutChanged()
QAbstractProxyModel
QAbstractItemModel::canFetchMore
virtual bool canFetchMore(const QModelIndex &parent) const
KIdentityProxyModel::fetchMore
virtual void fetchMore(const QModelIndex &parent)
Definition: kidentityproxymodel.cpp:170
KIdentityProxyModel::mapSelectionToSource
QItemSelection mapSelectionToSource(const QItemSelection &selection) const
Definition: kidentityproxymodel.cpp:271
QAbstractProxyModel::supportedDropActions
virtual Qt::DropActions supportedDropActions() const
Qt::MatchFlags
typedef MatchFlags
QAbstractItemModel::columnsRemoved
void columnsRemoved(const QModelIndex &parent, int start, int end)
QAbstractItemModel::modelAboutToBeReset
void modelAboutToBeReset()
QAbstractItemModel::modelReset
void modelReset()
KIdentityProxyModel::~KIdentityProxyModel
virtual ~KIdentityProxyModel()
Definition: kidentityproxymodel.cpp:140
QAbstractItemModel::insertRows
virtual bool insertRows(int row, int count, const QModelIndex &parent)
kidentityproxymodel.h
QAbstractProxyModel::mimeData
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
QAbstractItemModel::columnsAboutToBeMoved
void columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
KIdentityProxyModel::mimeTypes
virtual QStringList mimeTypes() const
Definition: kidentityproxymodel.cpp:336
QAbstractItemModel::rowsAboutToBeRemoved
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QAbstractItemModel::dropMimeData
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
QList::const_iterator
QMimeData
QAbstractItemModel::mimeTypes
virtual QStringList mimeTypes() const
KIdentityProxyModel::mapFromSource
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Definition: kidentityproxymodel.cpp:238
QAbstractItemModel::beginResetModel
void beginResetModel()
QAbstractItemModel::match
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, QFlags< Qt::MatchFlag > flags) const
QAbstractItemModel::layoutAboutToBeChanged
void layoutAboutToBeChanged()
QModelIndex::isValid
bool isValid() const
QPersistentModelIndex::isValid
bool isValid() const
QAbstractItemModel::rowsMoved
void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
QList::append
void append(const T &value)
QAbstractItemModel::rowsAboutToBeInserted
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
KIdentityProxyModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kidentityproxymodel.cpp:203
QAbstractItemModel::dataChanged
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
KIdentityProxyModel::removeColumns
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:374
QObject
KIdentityProxyModel::setSourceModel
void setSourceModel(QAbstractItemModel *sourceModel)
Definition: kidentityproxymodel.cpp:409
KIdentityProxyModel::mapToSource
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Definition: kidentityproxymodel.cpp:307
KIdentityProxyModel::mimeData
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Definition: kidentityproxymodel.cpp:344
QModelIndex::row
int row() const
QAbstractItemModel::removeColumns
virtual bool removeColumns(int column, int count, const QModelIndex &parent)
QAbstractItemModel::supportedDropActions
virtual Qt::DropActions supportedDropActions() const
QAbstractProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QModelIndex::internalPointer
void * internalPointer() const
QList
QAbstractItemModel::mimeData
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
QModelIndex::parent
QModelIndex parent() const
QAbstractItemModel::columnsInserted
void columnsInserted(const QModelIndex &parent, int start, int end)
QAbstractItemModel::rowsRemoved
void rowsRemoved(const QModelIndex &parent, int start, int end)
QStringList
QAbstractItemModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
KIdentityProxyModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: kidentityproxymodel.cpp:193
KIdentityProxyModel::match
QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Definition: kidentityproxymodel.cpp:318
KIdentityProxyModel::KIdentityProxyModel
KIdentityProxyModel(QObject *parent=0)
Definition: kidentityproxymodel.cpp:123
QAbstractItemModel::createIndex
QModelIndex createIndex(int row, int column, void *ptr) const
QAbstractItemModel::insertColumns
virtual bool insertColumns(int column, int count, const QModelIndex &parent)
QAbstractItemModel::columnsAboutToBeRemoved
void columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
QAbstractItemModel::removeRows
virtual bool removeRows(int row, int count, const QModelIndex &parent)
QItemSelection
QAbstractProxyModel::mimeTypes
virtual QStringList mimeTypes() const
QPersistentModelIndex
QAbstractProxyModel::sourceModel
QAbstractItemModel * sourceModel() const
QModelIndex::model
const QAbstractItemModel * model() const
KIdentityProxyModel::canFetchMore
virtual bool canFetchMore(const QModelIndex &parent) const
Definition: kidentityproxymodel.cpp:148
Qt::DropActions
typedef DropActions
KIdentityProxyModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: kidentityproxymodel.cpp:159
QAbstractItemModel::headerDataChanged
void headerDataChanged(Qt::Orientation orientation, int first, int last)
QAbstractItemModel::columnCount
virtual int columnCount(const QModelIndex &parent) const =0
KIdentityProxyModel::supportedDropActions
virtual Qt::DropActions supportedDropActions() const
Definition: kidentityproxymodel.cpp:513
QModelIndex::column
int column() const
QAbstractItemModel::fetchMore
virtual void fetchMore(const QModelIndex &parent)
KIdentityProxyModel::d_ptr
KIdentityProxyModelPrivate *const d_ptr
Definition: kidentityproxymodel.h:65
QAbstractItemModel
KIdentityProxyModel::dropMimeData
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Definition: kidentityproxymodel.cpp:181
QAbstractItemModel::rowsAboutToBeMoved
void rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
QAbstractItemModel::rowsInserted
void rowsInserted(const QModelIndex &parent, int start, int end)
QAbstractItemModel::endResetModel
void endResetModel()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
KStandardShortcut::end
const KShortcut & end()
Goto end of the document.
Definition: kstandardshortcut.cpp:348
KIdentityProxyModel::mapSelectionFromSource
QItemSelection mapSelectionFromSource(const QItemSelection &selection) const
Definition: kidentityproxymodel.cpp:250
QPersistentModelIndex::parent
QModelIndex parent() const
KIdentityProxyModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: kidentityproxymodel.cpp:398
QObject::destroyed
void destroyed(QObject *obj)
QAbstractItemModel::columnsAboutToBeInserted
void columnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
KIdentityProxyModel::insertRows
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:227
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:59 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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