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

KDEUI

  • home
  • ichiro
  • data
  • ssd
  • Momonga
  • trunk
  • pkgs
  • kdelibs
  • BUILD
  • kdelibs-4.14.3
  • 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 
192 QModelIndex KIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const
193 {
194  if (!sourceModel())
195  return QModelIndex();
196  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
197  const QModelIndex sourceParent = mapToSource(parent);
198  const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent);
199  return mapFromSource(sourceIndex);
200 }
201 
205 bool KIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent)
206 {
207  if (!sourceModel())
208  return false;
209  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
210  return sourceModel()->insertColumns(column, count, mapToSource(parent));
211 }
212 
216 bool KIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent)
217 {
218  if (!sourceModel())
219  return false;
220  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
221  return sourceModel()->insertRows(row, count, mapToSource(parent));
222 }
223 
227 QModelIndex KIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
228 {
229  if (!sourceModel() || !sourceIndex.isValid())
230  return QModelIndex();
231 
232  Q_ASSERT(sourceIndex.model() == sourceModel());
233  return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
234 }
235 
239 QItemSelection KIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const
240 {
241  QItemSelection proxySelection;
242 
243  if (!sourceModel())
244  return proxySelection;
245 
246  QItemSelection::const_iterator it = selection.constBegin();
247  const QItemSelection::const_iterator end = selection.constEnd();
248  for ( ; it != end; ++it) {
249  Q_ASSERT(it->model() == sourceModel());
250  const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
251  proxySelection.append(range);
252  }
253 
254  return proxySelection;
255 }
256 
260 QItemSelection KIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
261 {
262  QItemSelection sourceSelection;
263 
264  if (!sourceModel())
265  return sourceSelection;
266 
267  QItemSelection::const_iterator it = selection.constBegin();
268  const QItemSelection::const_iterator end = selection.constEnd();
269  for ( ; it != end; ++it) {
270  Q_ASSERT(it->model() == this);
271  const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
272  sourceSelection.append(range);
273  }
274 
275  return sourceSelection;
276 }
277 
278 struct SourceModelIndex
279 {
280  SourceModelIndex(int _r, int _c, void *_p, QAbstractItemModel *_m)
281  : r(_r), c(_c), p(_p), m(_m)
282  {
283 
284  }
285 
286  operator QModelIndex() { return reinterpret_cast<QModelIndex&>(*this); }
287 
288  int r, c;
289  void *p;
290  const QAbstractItemModel *m;
291 };
292 
296 QModelIndex KIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const
297 {
298  if (!sourceModel() || !proxyIndex.isValid())
299  return QModelIndex();
300  Q_ASSERT(proxyIndex.model() == this);
301  return SourceModelIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer(), sourceModel());
302 }
303 
307 QModelIndexList KIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
308 {
309  Q_ASSERT(start.isValid() ? start.model() == this : true);
310  if (!sourceModel())
311  return QModelIndexList();
312 
313  const QModelIndexList sourceList = sourceModel()->match(mapToSource(start), role, value, hits, flags);
314  QModelIndexList::const_iterator it = sourceList.constBegin();
315  const QModelIndexList::const_iterator end = sourceList.constEnd();
316  QModelIndexList proxyList;
317  for ( ; it != end; ++it)
318  proxyList.append(mapFromSource(*it));
319  return proxyList;
320 }
321 
325 QStringList KIdentityProxyModel::mimeTypes() const
326 {
327  if (sourceModel())
328  return sourceModel()->mimeTypes();
329  else
330  return QAbstractProxyModel::mimeTypes();
331 }
332 
333 QMimeData* KIdentityProxyModel::mimeData(const QModelIndexList& indexes) const
334 {
335  if (!sourceModel())
336  return QAbstractProxyModel::mimeData(indexes);
337 
338  QModelIndexList proxyIndexes;
339  foreach(const QModelIndex &index, indexes)
340  proxyIndexes.append(mapToSource(index));
341 
342  return sourceModel()->mimeData(proxyIndexes);
343 }
344 
345 
349 QModelIndex KIdentityProxyModel::parent(const QModelIndex& child) const
350 {
351  if (!sourceModel())
352  return QModelIndex();
353 
354  Q_ASSERT(child.isValid() ? child.model() == this : true);
355  const QModelIndex sourceIndex = mapToSource(child);
356  const QModelIndex sourceParent = sourceIndex.parent();
357  return mapFromSource(sourceParent);
358 }
359 
363 bool KIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent)
364 {
365  if (!sourceModel())
366  return false;
367 
368  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
369  return sourceModel()->removeColumns(column, count, mapToSource(parent));
370 }
371 
375 bool KIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent)
376 {
377  if (!sourceModel())
378  return false;
379 
380  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
381  return sourceModel()->removeRows(row, count, mapToSource(parent));
382 }
383 
387 int KIdentityProxyModel::rowCount(const QModelIndex& parent) const
388 {
389  if (!sourceModel())
390  return 0;
391  Q_ASSERT(parent.isValid() ? parent.model() == this : true);
392  return sourceModel()->rowCount(mapToSource(parent));
393 }
394 
398 void KIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
399 {
400  beginResetModel();
401 
402  if (sourceModel) {
403  disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
404  this, SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
405  disconnect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
406  this, SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
407  disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
408  this, SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
409  disconnect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
410  this, SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
411  disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
412  this, SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
413  disconnect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
414  this, SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
415  disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
416  this, SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
417  disconnect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
418  this, SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
419  disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
420  this, SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
421  disconnect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
422  this, SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
423  disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
424  this, SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
425  disconnect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
426  this, SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
427  disconnect(sourceModel, SIGNAL(modelAboutToBeReset()),
428  this, SLOT(_k_sourceModelAboutToBeReset()));
429 // disconnect(sourceModel, SIGNAL(internalDataReset()),
430 // this, SLOT(resetInternalData()));
431  disconnect(sourceModel, SIGNAL(modelReset()),
432  this, SLOT(_k_sourceModelReset()));
433  disconnect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
434  this, SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
435  disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
436  this, SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
437  disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
438  this, SLOT(_k_sourceLayoutAboutToBeChanged()));
439  disconnect(sourceModel, SIGNAL(layoutChanged()),
440  this, SLOT(_k_sourceLayoutChanged()));
441 // disconnect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
442 // this, SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
443 // disconnect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
444 // this, SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
445  disconnect(sourceModel, SIGNAL(destroyed()),
446  this, SLOT(_k_sourceModelDestroyed()));
447  }
448 
449  QAbstractProxyModel::setSourceModel(sourceModel);
450 
451  if (sourceModel) {
452  connect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
453  SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
454  connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
455  SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
456  connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
457  SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
458  connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
459  SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
460  connect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
461  SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
462  connect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
463  SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
464  connect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
465  SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
466  connect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
467  SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
468  connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
469  SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
470  connect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
471  SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
472  connect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
473  SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
474  connect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
475  SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
476  connect(sourceModel, SIGNAL(modelAboutToBeReset()),
477  SLOT(_k_sourceModelAboutToBeReset()));
478 // connect(sourceModel, SIGNAL(internalDataReset()),
479 // SLOT(resetInternalData()));
480  connect(sourceModel, SIGNAL(modelReset()),
481  SLOT(_k_sourceModelReset()));
482  connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
483  SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
484  connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
485  SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
486  connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
487  SLOT(_k_sourceLayoutAboutToBeChanged()));
488  connect(sourceModel, SIGNAL(layoutChanged()),
489  SLOT(_k_sourceLayoutChanged()));
490  // Hopefully this will be in Qt4.8
491 // connect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
492 // SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
493 // connect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
494 // SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
495  connect(sourceModel, SIGNAL(destroyed()),
496  SLOT(_k_sourceModelDestroyed()));
497  }
498 
499  endResetModel();
500 }
501 
502 Qt::DropActions KIdentityProxyModel::supportedDropActions() const
503 {
504  if (sourceModel())
505  return sourceModel()->supportedDropActions();
506  else
507  return QAbstractProxyModel::supportedDropActions();
508 }
509 
510 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
511 {
512  Q_Q(KIdentityProxyModel);
513  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
514  q->beginInsertColumns(q->mapFromSource(parent), start, end);
515 }
516 
517 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
518 {
519  Q_Q(KIdentityProxyModel);
520  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
521  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
522  q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
523 }
524 
525 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
526 {
527  Q_Q(KIdentityProxyModel);
528  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
529  q->beginRemoveColumns(q->mapFromSource(parent), start, end);
530 }
531 
532 void KIdentityProxyModelPrivate::_k_sourceColumnsInserted(const QModelIndex &parent, int start, int end)
533 {
534  Q_Q(KIdentityProxyModel);
535  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
536  Q_UNUSED(parent)
537  Q_UNUSED(start)
538  Q_UNUSED(end)
539  q->endInsertColumns();
540 }
541 
542 void KIdentityProxyModelPrivate::_k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
543 {
544  Q_Q(KIdentityProxyModel);
545  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
546  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
547  Q_UNUSED(sourceParent)
548  Q_UNUSED(sourceStart)
549  Q_UNUSED(sourceEnd)
550  Q_UNUSED(destParent)
551  Q_UNUSED(dest)
552  q->endMoveColumns();
553 }
554 
555 void KIdentityProxyModelPrivate::_k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end)
556 {
557  Q_Q(KIdentityProxyModel);
558  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
559  Q_UNUSED(parent)
560  Q_UNUSED(start)
561  Q_UNUSED(end)
562  q->endRemoveColumns();
563 }
564 
565 void KIdentityProxyModelPrivate::_k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
566 {
567  Q_Q(KIdentityProxyModel);
568  Q_ASSERT(topLeft.model() == q->sourceModel());
569  Q_ASSERT(bottomRight.model() == q->sourceModel());
570  q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight));
571 }
572 
573 void KIdentityProxyModelPrivate::_k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)
574 {
575  Q_Q(KIdentityProxyModel);
576  q->headerDataChanged(orientation, first, last);
577 }
578 
579 void KIdentityProxyModelPrivate::_k_sourceLayoutAboutToBeChanged()
580 {
581  //if (ignoreNextLayoutAboutToBeChanged)
582  // return;
583 
584  Q_Q(KIdentityProxyModel);
585 
586  q->layoutAboutToBeChanged();
587 
588  Q_FOREACH(const QModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
589  Q_ASSERT(proxyPersistentIndex.isValid());
590  const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
591  if (!srcPersistentIndex.isValid()) // can happen with extra columns, e.g. KPIM::StatisticsProxyModel
592  continue;
593  proxyIndexes << proxyPersistentIndex;
594  layoutChangePersistentIndexes << srcPersistentIndex;
595  }
596 }
597 
598 void KIdentityProxyModelPrivate::_k_sourceLayoutChanged()
599 {
600  //if (ignoreNextLayoutChanged)
601  // return;
602 
603  Q_Q(KIdentityProxyModel);
604 
605  for (int i = 0; i < proxyIndexes.size(); ++i) {
606  const QModelIndex oldProxyIndex = proxyIndexes.at(i);
607  const QModelIndex newProxyIndex = q->mapFromSource(layoutChangePersistentIndexes.at(i));
608  if (oldProxyIndex != newProxyIndex)
609  q->changePersistentIndex(oldProxyIndex, newProxyIndex);
610  }
611 
612  layoutChangePersistentIndexes.clear();
613  proxyIndexes.clear();
614 
615  q->layoutChanged();
616 }
617 
618 #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.
619 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2)
620 {
621  Q_Q(KIdentityProxyModel);
622  Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
623  Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
624 
625 
626  ignoreNextLayoutAboutToBeChanged = true;
627 
628  const QModelIndex proxyParent1 = q->mapFromSource(parent1);
629  const QModelIndex proxyParent2 = q->mapFromSource(parent2);
630  //emit q->childrenLayoutsAboutToBeChanged(proxyParent1, proxyParent2);
631  emit q->layoutAboutToBeChanged();
632 
633  if (q->persistentIndexList().isEmpty())
634  return;
635 
636  Q_FOREACH(const QModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
637  const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
638  Q_ASSERT(proxyPersistentIndex.isValid());
639  Q_ASSERT(srcPersistentIndex.isValid());
640  const QModelIndex idxParent = srcPersistentIndex.parent();
641  if (idxParent != parent1 && idxParent != parent2)
642  continue;
643  proxyIndexes << proxyPersistentIndex;
644  layoutChangePersistentIndexes << srcPersistentIndex;
645  }
646 }
647 
648 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2)
649 {
650  Q_Q(KIdentityProxyModel);
651  Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
652  Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
653 
654  ignoreNextLayoutChanged = true;
655 
656  QModelIndexList oldList, newList;
657  for( int i = 0; i < layoutChangePersistentIndexes.size(); ++i) {
658  const QModelIndex srcIdx = layoutChangePersistentIndexes.at(i);
659  const QModelIndex oldProxyIdx = proxyIndexes.at(i);
660  oldList << oldProxyIdx;
661  newList << q->mapFromSource(srcIdx);
662  }
663  q->changePersistentIndexList(oldList, newList);
664  layoutChangePersistentIndexes.clear();
665  proxyIndexes.clear();
666 
667  const QModelIndex proxyParent1 = q->mapFromSource(parent1);
668  const QModelIndex proxyParent2 = q->mapFromSource(parent2);
669 // emit q->childrenLayoutsChanged(proxyParent1, proxyParent2);
670  emit q->layoutChanged();
671 }
672 #endif
673 
674 void KIdentityProxyModelPrivate::_k_sourceModelAboutToBeReset()
675 {
676  Q_Q(KIdentityProxyModel);
677  q->beginResetModel();
678 }
679 
680 void KIdentityProxyModelPrivate::_k_sourceModelReset()
681 {
682  Q_Q(KIdentityProxyModel);
683  q->endResetModel();
684 }
685 
686 void KIdentityProxyModelPrivate::_k_sourceModelDestroyed()
687 {
688 // Q_Q(KIdentityProxyModel);
689 // q->endResetModel();
690 }
691 
692 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
693 {
694  Q_Q(KIdentityProxyModel);
695  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
696  q->beginInsertRows(q->mapFromSource(parent), start, end);
697 }
698 
699 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
700 {
701  Q_Q(KIdentityProxyModel);
702  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
703  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
704  q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
705 }
706 
707 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
708 {
709  Q_Q(KIdentityProxyModel);
710  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
711  q->beginRemoveRows(q->mapFromSource(parent), start, end);
712 }
713 
714 void KIdentityProxyModelPrivate::_k_sourceRowsInserted(const QModelIndex &parent, int start, int end)
715 {
716  Q_Q(KIdentityProxyModel);
717  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
718  Q_UNUSED(parent)
719  Q_UNUSED(start)
720  Q_UNUSED(end)
721  q->endInsertRows();
722 }
723 
724 void KIdentityProxyModelPrivate::_k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
725 {
726  Q_Q(KIdentityProxyModel);
727  Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
728  Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
729  Q_UNUSED(sourceParent)
730  Q_UNUSED(sourceStart)
731  Q_UNUSED(sourceEnd)
732  Q_UNUSED(destParent)
733  Q_UNUSED(dest)
734  q->endMoveRows();
735 }
736 
737 void KIdentityProxyModelPrivate::_k_sourceRowsRemoved(const QModelIndex &parent, int start, int end)
738 {
739  Q_Q(KIdentityProxyModel);
740  Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
741  Q_UNUSED(parent)
742  Q_UNUSED(start)
743  Q_UNUSED(end)
744  q->endRemoveRows();
745 }
746 
752 void KIdentityProxyModel::resetInternalData()
753 {
754 
755 }
756 
757 #include "kidentityproxymodel.moc"
KIdentityProxyModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: kidentityproxymodel.cpp:387
KIdentityProxyModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:375
KIdentityProxyModel::resetInternalData
virtual void resetInternalData()
Definition: kidentityproxymodel.cpp:752
KIdentityProxyModel
The KIdentityProxyModel class proxies its source model unmodified.
Definition: kidentityproxymodel.h:31
KIdentityProxyModel::insertColumns
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:205
KIdentityProxyModel::canFetchMore
virtual bool canFetchMore(const QModelIndex &parent) const
Definition: kidentityproxymodel.cpp:148
kdebug.h
KIdentityProxyModel::fetchMore
virtual void fetchMore(const QModelIndex &parent)
Definition: kidentityproxymodel.cpp:170
KIdentityProxyModel::mimeData
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Definition: kidentityproxymodel.cpp:333
KIdentityProxyModel::mimeTypes
virtual QStringList mimeTypes() const
Definition: kidentityproxymodel.cpp:325
KIdentityProxyModel::~KIdentityProxyModel
virtual ~KIdentityProxyModel()
Definition: kidentityproxymodel.cpp:140
KIdentityProxyModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: kidentityproxymodel.cpp:159
KIdentityProxyModel::mapSelectionFromSource
QItemSelection mapSelectionFromSource(const QItemSelection &selection) const
Definition: kidentityproxymodel.cpp:239
kidentityproxymodel.h
KIdentityProxyModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kidentityproxymodel.cpp:192
QObject
KIdentityProxyModel::supportedDropActions
virtual Qt::DropActions supportedDropActions() const
Definition: kidentityproxymodel.cpp:502
KIdentityProxyModel::mapToSource
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Definition: kidentityproxymodel.cpp:296
KIdentityProxyModel::mapFromSource
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Definition: kidentityproxymodel.cpp:227
KIdentityProxyModel::removeColumns
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:363
KIdentityProxyModel::setSourceModel
void setSourceModel(QAbstractItemModel *sourceModel)
Definition: kidentityproxymodel.cpp:398
QAbstractItemModel
QAbstractProxyModel
KIdentityProxyModel::mapSelectionToSource
QItemSelection mapSelectionToSource(const QItemSelection &selection) const
Definition: kidentityproxymodel.cpp:260
KIdentityProxyModel::KIdentityProxyModel
KIdentityProxyModel(QObject *parent=0)
Definition: kidentityproxymodel.cpp:123
KIdentityProxyModel::d_ptr
KIdentityProxyModelPrivate *const d_ptr
Definition: kidentityproxymodel.h:64
KIdentityProxyModel::dropMimeData
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Definition: kidentityproxymodel.cpp:181
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:307
KStandardShortcut::end
const KShortcut & end()
Goto end of the document.
Definition: kstandardshortcut.cpp:348
QList< QPersistentModelIndex >
KIdentityProxyModel::insertRows
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: kidentityproxymodel.cpp:216
KIdentityProxyModel::parent
QModelIndex parent(const QModelIndex &child) const
Definition: kidentityproxymodel.cpp:349
This file is part of the KDE documentation.
Documentation copyright © 1996-2018 The KDE developers.
Generated on Fri Oct 19 2018 17:12:34 by doxygen 1.8.13 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.14.3 API Reference

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