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

KDEUI

kidentityproxymodel.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2010 Klarälvdalens Datakonsult AB,
00003         a KDAB Group company, info@kdab.net,
00004         author Stephen Kelly <stephen@kdab.com>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "kidentityproxymodel.h"
00023 
00024 #include <QtGui/QItemSelection>
00025 
00026 class KIdentityProxyModelPrivate
00027 {
00028   KIdentityProxyModelPrivate(KIdentityProxyModel *qq)
00029     : q_ptr(qq),
00030       ignoreNextLayoutAboutToBeChanged(false),
00031       ignoreNextLayoutChanged(false)
00032   {
00033 
00034   }
00035 
00036   Q_DECLARE_PUBLIC(KIdentityProxyModel)
00037   KIdentityProxyModel * const q_ptr;
00038 
00039   bool ignoreNextLayoutAboutToBeChanged;
00040   bool ignoreNextLayoutChanged;
00041   QList<QPersistentModelIndex> layoutChangePersistentIndexes;
00042   QModelIndexList proxyIndexes;
00043 
00044   void _k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
00045   void _k_sourceRowsInserted(const QModelIndex &parent, int start, int end);
00046   void _k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
00047   void _k_sourceRowsRemoved(const QModelIndex &parent, int start, int end);
00048   void _k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00049   void _k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00050 
00051   void _k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
00052   void _k_sourceColumnsInserted(const QModelIndex &parent, int start, int end);
00053   void _k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
00054   void _k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end);
00055   void _k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00056   void _k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00057 
00058   void _k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00059   void _k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last);
00060 
00061   void _k_sourceLayoutAboutToBeChanged();
00062   void _k_sourceLayoutChanged();
00063   void _k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2);
00064   void _k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2);
00065   void _k_sourceModelAboutToBeReset();
00066   void _k_sourceModelReset();
00067   void _k_sourceModelDestroyed();
00068 
00069 };
00070 
00121 KIdentityProxyModel::KIdentityProxyModel(QObject* parent)
00122   : QAbstractProxyModel(parent), d_ptr(new KIdentityProxyModelPrivate(this))
00123 {
00124 
00125 }
00126 
00129 KIdentityProxyModel::KIdentityProxyModel(KIdentityProxyModelPrivate* privateClass, QObject* parent)
00130   : QAbstractProxyModel(parent), d_ptr(privateClass)
00131 {
00132 
00133 }
00134 
00138 KIdentityProxyModel::~KIdentityProxyModel()
00139 {
00140     delete d_ptr;
00141 }
00142 
00146 int KIdentityProxyModel::columnCount(const QModelIndex& parent) const
00147 {
00148     if (!sourceModel())
00149         return 0;
00150     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00151     return sourceModel()->columnCount(mapToSource(parent));
00152 }
00153 
00157 bool KIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
00158 {
00159     if (!sourceModel())
00160         return false;
00161     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00162     return sourceModel()->dropMimeData(data, action, row, column, mapToSource(parent));
00163 }
00164 
00168 QModelIndex KIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const
00169 {
00170     if (!sourceModel())
00171         return QModelIndex();
00172     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00173     if (!hasIndex(row, column, parent))
00174         return QModelIndex();
00175     const QModelIndex sourceParent = mapToSource(parent);
00176     const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent);
00177     Q_ASSERT(sourceIndex.isValid());
00178     return mapFromSource(sourceIndex);
00179 }
00180 
00184 bool KIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent)
00185 {
00186     if (!sourceModel())
00187         return false;
00188     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00189     return sourceModel()->insertColumns(column, count, mapToSource(parent));
00190 }
00191 
00195 bool KIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent)
00196 {
00197     if (!sourceModel())
00198         return false;
00199     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00200     return sourceModel()->insertRows(row, count, mapToSource(parent));
00201 }
00202 
00206 QModelIndex KIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
00207 {
00208     if (!sourceModel() || !sourceIndex.isValid())
00209         return QModelIndex();
00210 
00211     Q_ASSERT(sourceIndex.model() == sourceModel());
00212     return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
00213 }
00214 
00218 QItemSelection KIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const
00219 {
00220     QItemSelection proxySelection;
00221 
00222     if (!sourceModel())
00223         return proxySelection;
00224 
00225     QItemSelection::const_iterator it = selection.constBegin();
00226     const QItemSelection::const_iterator end = selection.constEnd();
00227     for ( ; it != end; ++it) {
00228         Q_ASSERT(it->model() == sourceModel());
00229         const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
00230         proxySelection.append(range);
00231     }
00232 
00233     return proxySelection;
00234 }
00235 
00239 QItemSelection KIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
00240 {
00241     QItemSelection sourceSelection;
00242 
00243     if (!sourceModel())
00244       return sourceSelection;
00245 
00246     QItemSelection::const_iterator it = selection.constBegin();
00247     const QItemSelection::const_iterator end = selection.constEnd();
00248     for ( ; it != end; ++it) {
00249         Q_ASSERT(it->model() == this);
00250         const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
00251         sourceSelection.append(range);
00252     }
00253 
00254     return sourceSelection;
00255 }
00256 
00257 struct SourceModelIndex
00258 {
00259     SourceModelIndex(int _r, int _c, void *_p, QAbstractItemModel *_m)
00260       : r(_r), c(_c), p(_p), m(_m)
00261     {
00262 
00263     }
00264 
00265     operator QModelIndex() { return reinterpret_cast<QModelIndex&>(*this); }
00266 
00267     int r, c;
00268     void *p;
00269     const QAbstractItemModel *m;
00270 };
00271 
00275 QModelIndex KIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const
00276 {
00277     if (!sourceModel() || !proxyIndex.isValid())
00278         return QModelIndex();
00279     Q_ASSERT(proxyIndex.model() == this);
00280     return SourceModelIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer(), sourceModel());
00281 }
00282 
00286 QModelIndexList KIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
00287 {
00288     Q_ASSERT(start.isValid() ? start.model() == this : true);
00289     if (!sourceModel())
00290         return QModelIndexList();
00291 
00292     const QModelIndexList sourceList = sourceModel()->match(mapToSource(start), role, value, hits, flags);
00293     QModelIndexList::const_iterator it = sourceList.constBegin();
00294     const QModelIndexList::const_iterator end = sourceList.constEnd();
00295     QModelIndexList proxyList;
00296     for ( ; it != end; ++it)
00297         proxyList.append(mapFromSource(*it));
00298     return proxyList;
00299 }
00300 
00304 QModelIndex KIdentityProxyModel::parent(const QModelIndex& child) const
00305 {
00306     if (!sourceModel())
00307         return QModelIndex();
00308 
00309     Q_ASSERT(child.isValid() ? child.model() == this : true);
00310     const QModelIndex sourceIndex = mapToSource(child);
00311     const QModelIndex sourceParent = sourceIndex.parent();
00312     return mapFromSource(sourceParent);
00313 }
00314 
00318 bool KIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent)
00319 {
00320     if (!sourceModel())
00321         return false;
00322 
00323     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00324     return sourceModel()->removeColumns(column, count, mapToSource(parent));
00325 }
00326 
00330 bool KIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent)
00331 {
00332     if (!sourceModel())
00333         return false;
00334 
00335     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00336     return sourceModel()->removeRows(row, count, mapToSource(parent));
00337 }
00338 
00342 int KIdentityProxyModel::rowCount(const QModelIndex& parent) const
00343 {
00344     if (!sourceModel())
00345         return 0;
00346     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00347     return sourceModel()->rowCount(mapToSource(parent));
00348 }
00349 
00353 void KIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
00354 {
00355     beginResetModel();
00356 
00357     if (sourceModel) {
00358         disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
00359                    this, SLOT(_k_sourceRowsAboutToBeInserted(const QModelIndex &, int, int)));
00360         disconnect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
00361                    this, SLOT(_k_sourceRowsInserted(const QModelIndex &, int, int)));
00362         disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
00363                    this, SLOT(_k_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)));
00364         disconnect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
00365                    this, SLOT(_k_sourceRowsRemoved(const QModelIndex &, int, int)));
00366         disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00367                    this, SLOT(_k_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00368         disconnect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00369                    this, SLOT(_k_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00370         disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
00371                    this, SLOT(_k_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int)));
00372         disconnect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)),
00373                    this, SLOT(_k_sourceColumnsInserted(const QModelIndex &, int, int)));
00374         disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)),
00375                    this, SLOT(_k_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int)));
00376         disconnect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
00377                    this, SLOT(_k_sourceColumnsRemoved(const QModelIndex &, int, int)));
00378         disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00379                    this, SLOT(_k_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00380         disconnect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00381                    this, SLOT(_k_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00382         disconnect(sourceModel, SIGNAL(modelAboutToBeReset()),
00383                    this, SLOT(_k_sourceModelAboutToBeReset()));
00384 //        disconnect(sourceModel, SIGNAL(internalDataReset()),
00385 //                   this, SLOT(resetInternalData()));
00386         disconnect(sourceModel, SIGNAL(modelReset()),
00387                    this, SLOT(_k_sourceModelReset()));
00388         disconnect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
00389                    this, SLOT(_k_sourceDataChanged(const QModelIndex &, const QModelIndex &)));
00390         disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
00391                    this, SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
00392         disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
00393                    this, SLOT(_k_sourceLayoutAboutToBeChanged()));
00394         disconnect(sourceModel, SIGNAL(layoutChanged()),
00395                    this, SLOT(_k_sourceLayoutChanged()));
00396 //         disconnect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
00397 //                    this, SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
00398 //         disconnect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
00399 //                    this, SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
00400         disconnect(sourceModel, SIGNAL(destroyed()),
00401                    this, SLOT(_k_sourceModelDestroyed()));
00402     }
00403 
00404     QAbstractProxyModel::setSourceModel(sourceModel);
00405 
00406     if (sourceModel) {
00407         connect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
00408                 SLOT(_k_sourceRowsAboutToBeInserted(const QModelIndex &, int, int)));
00409         connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
00410                 SLOT(_k_sourceRowsInserted(const QModelIndex &, int, int)));
00411         connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
00412                 SLOT(_k_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)));
00413         connect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
00414                 SLOT(_k_sourceRowsRemoved(const QModelIndex &, int, int)));
00415         connect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00416                 SLOT(_k_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00417         connect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00418                 SLOT(_k_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00419         connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
00420                 SLOT(_k_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int)));
00421         connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)),
00422                 SLOT(_k_sourceColumnsInserted(const QModelIndex &, int, int)));
00423         connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)),
00424                 SLOT(_k_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int)));
00425         connect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
00426                 SLOT(_k_sourceColumnsRemoved(const QModelIndex &, int, int)));
00427         connect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00428                 SLOT(_k_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00429         connect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
00430                 SLOT(_k_sourceColumnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
00431         connect(sourceModel, SIGNAL(modelAboutToBeReset()),
00432                 SLOT(_k_sourceModelAboutToBeReset()));
00433 //        connect(sourceModel, SIGNAL(internalDataReset()),
00434 //                SLOT(resetInternalData()));
00435         connect(sourceModel, SIGNAL(modelReset()),
00436                 SLOT(_k_sourceModelReset()));
00437         connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
00438                 SLOT(_k_sourceDataChanged(const QModelIndex &, const QModelIndex &)));
00439         connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
00440                 SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
00441         connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
00442                 SLOT(_k_sourceLayoutAboutToBeChanged()));
00443         connect(sourceModel, SIGNAL(layoutChanged()),
00444                 SLOT(_k_sourceLayoutChanged()));
00445         // Hopefully this will be in Qt4.8
00446 //         connect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
00447 //                 SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
00448 //         connect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
00449 //                 SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
00450         connect(sourceModel, SIGNAL(destroyed()),
00451                 SLOT(_k_sourceModelDestroyed()));
00452     }
00453 
00454     endResetModel();
00455 }
00456 
00457 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
00458 {
00459     Q_Q(KIdentityProxyModel);
00460     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00461     q->beginInsertColumns(q->mapFromSource(parent), start, end);
00462 }
00463 
00464 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00465 {
00466     Q_Q(KIdentityProxyModel);
00467     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00468     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00469     q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
00470 }
00471 
00472 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
00473 {
00474     Q_Q(KIdentityProxyModel);
00475     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00476     q->beginRemoveColumns(q->mapFromSource(parent), start, end);
00477 }
00478 
00479 void KIdentityProxyModelPrivate::_k_sourceColumnsInserted(const QModelIndex &parent, int start, int end)
00480 {
00481     Q_Q(KIdentityProxyModel);
00482     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00483     Q_UNUSED(parent)
00484     Q_UNUSED(start)
00485     Q_UNUSED(end)
00486     q->endInsertColumns();
00487 }
00488 
00489 void KIdentityProxyModelPrivate::_k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00490 {
00491     Q_Q(KIdentityProxyModel);
00492     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00493     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00494     Q_UNUSED(sourceParent)
00495     Q_UNUSED(sourceStart)
00496     Q_UNUSED(sourceEnd)
00497     Q_UNUSED(destParent)
00498     Q_UNUSED(dest)
00499     q->endMoveColumns();
00500 }
00501 
00502 void KIdentityProxyModelPrivate::_k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end)
00503 {
00504     Q_Q(KIdentityProxyModel);
00505     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00506     Q_UNUSED(parent)
00507     Q_UNUSED(start)
00508     Q_UNUSED(end)
00509     q->endRemoveColumns();
00510 }
00511 
00512 void KIdentityProxyModelPrivate::_k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
00513 {
00514     Q_Q(KIdentityProxyModel);
00515     Q_ASSERT(topLeft.model() == q->sourceModel());
00516     Q_ASSERT(bottomRight.model() == q->sourceModel());
00517     q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight));
00518 }
00519 
00520 void KIdentityProxyModelPrivate::_k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)
00521 {
00522     Q_Q(KIdentityProxyModel);
00523     q->headerDataChanged(orientation, first, last);
00524 }
00525 
00526 void KIdentityProxyModelPrivate::_k_sourceLayoutAboutToBeChanged()
00527 {
00528     if (ignoreNextLayoutAboutToBeChanged)
00529         return;
00530 
00531     Q_Q(KIdentityProxyModel);
00532 
00533     q->layoutAboutToBeChanged();
00534 
00535     Q_FOREACH(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
00536         proxyIndexes << proxyPersistentIndex;
00537         Q_ASSERT(proxyPersistentIndex.isValid());
00538         const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
00539         Q_ASSERT(srcPersistentIndex.isValid());
00540         layoutChangePersistentIndexes << srcPersistentIndex;
00541     }
00542 }
00543 
00544 void KIdentityProxyModelPrivate::_k_sourceLayoutChanged()
00545 {
00546     if (ignoreNextLayoutChanged)
00547         return;
00548 
00549     Q_Q(KIdentityProxyModel);
00550 
00551     for (int i = 0; i < proxyIndexes.size(); ++i) {
00552         q->changePersistentIndex(proxyIndexes.at(i), q->mapFromSource(layoutChangePersistentIndexes.at(i)));
00553     }
00554 
00555     layoutChangePersistentIndexes.clear();
00556     proxyIndexes.clear();
00557 
00558     q->layoutChanged();
00559 }
00560 
00561 
00562 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2)
00563 {
00564     Q_Q(KIdentityProxyModel);
00565     Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
00566     Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
00567 
00568 
00569     ignoreNextLayoutAboutToBeChanged = true;
00570 
00571     const QModelIndex proxyParent1 = q->mapFromSource(parent1);
00572     const QModelIndex proxyParent2 = q->mapFromSource(parent2);
00573     //emit q->childrenLayoutsAboutToBeChanged(proxyParent1, proxyParent2);
00574     emit q->layoutAboutToBeChanged();
00575 
00576     if (q->persistentIndexList().isEmpty())
00577         return;
00578 
00579     Q_FOREACH(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
00580         const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
00581         Q_ASSERT(proxyPersistentIndex.isValid());
00582         Q_ASSERT(srcPersistentIndex.isValid());
00583         const QModelIndex idxParent = srcPersistentIndex.parent();
00584         if (idxParent != parent1 && idxParent != parent2)
00585             continue;
00586         proxyIndexes << proxyPersistentIndex;
00587         layoutChangePersistentIndexes << srcPersistentIndex;
00588     }
00589 }
00590 
00591 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2)
00592 {
00593     Q_Q(KIdentityProxyModel);
00594     Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
00595     Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
00596 
00597     ignoreNextLayoutChanged = true;
00598 
00599     QModelIndexList oldList, newList;
00600     for( int i = 0; i < layoutChangePersistentIndexes.size(); ++i) {
00601       const QModelIndex srcIdx = layoutChangePersistentIndexes.at(i);
00602       const QModelIndex oldProxyIdx = proxyIndexes.at(i);
00603       oldList << oldProxyIdx;
00604       newList << q->mapFromSource(srcIdx);
00605     }
00606     q->changePersistentIndexList(oldList, newList);
00607     layoutChangePersistentIndexes.clear();
00608     proxyIndexes.clear();
00609 
00610     const QModelIndex proxyParent1 = q->mapFromSource(parent1);
00611     const QModelIndex proxyParent2 = q->mapFromSource(parent2);
00612 //     emit q->childrenLayoutsChanged(proxyParent1, proxyParent2);
00613     emit q->layoutChanged();
00614 }
00615 
00616 void KIdentityProxyModelPrivate::_k_sourceModelAboutToBeReset()
00617 {
00618     Q_Q(KIdentityProxyModel);
00619     q->beginResetModel();
00620 }
00621 
00622 void KIdentityProxyModelPrivate::_k_sourceModelReset()
00623 {
00624     Q_Q(KIdentityProxyModel);
00625     q->endResetModel();
00626 }
00627 
00628 void KIdentityProxyModelPrivate::_k_sourceModelDestroyed()
00629 {
00630     Q_Q(KIdentityProxyModel);
00631 //   q->endResetModel();
00632 }
00633 
00634 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
00635 {
00636     Q_Q(KIdentityProxyModel);
00637     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00638     q->beginInsertRows(q->mapFromSource(parent), start, end);
00639 }
00640 
00641 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00642 {
00643     Q_Q(KIdentityProxyModel);
00644     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00645     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00646     q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
00647 }
00648 
00649 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
00650 {
00651     Q_Q(KIdentityProxyModel);
00652     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00653     q->beginRemoveRows(q->mapFromSource(parent), start, end);
00654 }
00655 
00656 void KIdentityProxyModelPrivate::_k_sourceRowsInserted(const QModelIndex &parent, int start, int end)
00657 {
00658     Q_Q(KIdentityProxyModel);
00659     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00660     Q_UNUSED(parent)
00661     Q_UNUSED(start)
00662     Q_UNUSED(end)
00663     q->endInsertRows();
00664 }
00665 
00666 void KIdentityProxyModelPrivate::_k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00667 {
00668     Q_Q(KIdentityProxyModel);
00669     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00670     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00671     Q_UNUSED(sourceParent)
00672     Q_UNUSED(sourceStart)
00673     Q_UNUSED(sourceEnd)
00674     Q_UNUSED(destParent)
00675     Q_UNUSED(dest)
00676     q->endMoveRows();
00677 }
00678 
00679 void KIdentityProxyModelPrivate::_k_sourceRowsRemoved(const QModelIndex &parent, int start, int end)
00680 {
00681     Q_Q(KIdentityProxyModel);
00682     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00683     Q_UNUSED(parent)
00684     Q_UNUSED(start)
00685     Q_UNUSED(end)
00686     q->endRemoveRows();
00687 }
00688 
00694 void KIdentityProxyModel::resetInternalData()
00695 {
00696 
00697 }
00698 
00699 #include "kidentityproxymodel.moc"

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal