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

KDEUI

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