• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.3 API Reference
  • 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 #include <QtCore/QStringList>
00026 
00027 class KIdentityProxyModelPrivate
00028 {
00029   KIdentityProxyModelPrivate(KIdentityProxyModel *qq)
00030     : q_ptr(qq),
00031       ignoreNextLayoutAboutToBeChanged(false),
00032       ignoreNextLayoutChanged(false)
00033   {
00034 
00035   }
00036 
00037   Q_DECLARE_PUBLIC(KIdentityProxyModel)
00038   KIdentityProxyModel * const q_ptr;
00039 
00040   bool ignoreNextLayoutAboutToBeChanged;
00041   bool ignoreNextLayoutChanged;
00042   QList<QPersistentModelIndex> layoutChangePersistentIndexes;
00043   QModelIndexList proxyIndexes;
00044 
00045   void _k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
00046   void _k_sourceRowsInserted(const QModelIndex &parent, int start, int end);
00047   void _k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
00048   void _k_sourceRowsRemoved(const QModelIndex &parent, int start, int end);
00049   void _k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00050   void _k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00051 
00052   void _k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
00053   void _k_sourceColumnsInserted(const QModelIndex &parent, int start, int end);
00054   void _k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
00055   void _k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end);
00056   void _k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00057   void _k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
00058 
00059   void _k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00060   void _k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last);
00061 
00062   void _k_sourceLayoutAboutToBeChanged();
00063   void _k_sourceLayoutChanged();
00064   void _k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2);
00065   void _k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2);
00066   void _k_sourceModelAboutToBeReset();
00067   void _k_sourceModelReset();
00068   void _k_sourceModelDestroyed();
00069 
00070 };
00071 
00122 KIdentityProxyModel::KIdentityProxyModel(QObject* parent)
00123   : QAbstractProxyModel(parent), d_ptr(new KIdentityProxyModelPrivate(this))
00124 {
00125 
00126 }
00127 
00130 KIdentityProxyModel::KIdentityProxyModel(KIdentityProxyModelPrivate* privateClass, QObject* parent)
00131   : QAbstractProxyModel(parent), d_ptr(privateClass)
00132 {
00133 
00134 }
00135 
00139 KIdentityProxyModel::~KIdentityProxyModel()
00140 {
00141     delete d_ptr;
00142 }
00143 
00147 bool KIdentityProxyModel::canFetchMore(const QModelIndex& parent) const
00148 {
00149     if (!sourceModel())
00150         return 0;
00151     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00152     return sourceModel()->canFetchMore(mapToSource(parent));
00153 }
00154 
00158 int KIdentityProxyModel::columnCount(const QModelIndex& parent) const
00159 {
00160     if (!sourceModel())
00161         return 0;
00162     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00163     return sourceModel()->columnCount(mapToSource(parent));
00164 }
00165 
00169 void KIdentityProxyModel::fetchMore(const QModelIndex& parent)
00170 {
00171     if (!sourceModel())
00172         return;
00173     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00174     sourceModel()->fetchMore(mapToSource(parent));
00175 }
00176 
00180 bool KIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
00181 {
00182     if (!sourceModel())
00183         return false;
00184     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00185     return sourceModel()->dropMimeData(data, action, row, column, mapToSource(parent));
00186 }
00187 
00191 QModelIndex KIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const
00192 {
00193     if (!sourceModel())
00194         return QModelIndex();
00195     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00196     if (row < 0 || column < 0 || !hasIndex(row, column, parent))
00197         return QModelIndex();
00198     const QModelIndex sourceParent = mapToSource(parent);
00199     const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent);
00200     Q_ASSERT(sourceIndex.isValid());
00201     return mapFromSource(sourceIndex);
00202 }
00203 
00207 bool KIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent)
00208 {
00209     if (!sourceModel())
00210         return false;
00211     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00212     return sourceModel()->insertColumns(column, count, mapToSource(parent));
00213 }
00214 
00218 bool KIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent)
00219 {
00220     if (!sourceModel())
00221         return false;
00222     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00223     return sourceModel()->insertRows(row, count, mapToSource(parent));
00224 }
00225 
00229 QModelIndex KIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
00230 {
00231     if (!sourceModel() || !sourceIndex.isValid())
00232         return QModelIndex();
00233 
00234     Q_ASSERT(sourceIndex.model() == sourceModel());
00235     return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
00236 }
00237 
00241 QItemSelection KIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const
00242 {
00243     QItemSelection proxySelection;
00244 
00245     if (!sourceModel())
00246         return proxySelection;
00247 
00248     QItemSelection::const_iterator it = selection.constBegin();
00249     const QItemSelection::const_iterator end = selection.constEnd();
00250     for ( ; it != end; ++it) {
00251         Q_ASSERT(it->model() == sourceModel());
00252         const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
00253         proxySelection.append(range);
00254     }
00255 
00256     return proxySelection;
00257 }
00258 
00262 QItemSelection KIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
00263 {
00264     QItemSelection sourceSelection;
00265 
00266     if (!sourceModel())
00267       return sourceSelection;
00268 
00269     QItemSelection::const_iterator it = selection.constBegin();
00270     const QItemSelection::const_iterator end = selection.constEnd();
00271     for ( ; it != end; ++it) {
00272         Q_ASSERT(it->model() == this);
00273         const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
00274         sourceSelection.append(range);
00275     }
00276 
00277     return sourceSelection;
00278 }
00279 
00280 struct SourceModelIndex
00281 {
00282     SourceModelIndex(int _r, int _c, void *_p, QAbstractItemModel *_m)
00283       : r(_r), c(_c), p(_p), m(_m)
00284     {
00285 
00286     }
00287 
00288     operator QModelIndex() { return reinterpret_cast<QModelIndex&>(*this); }
00289 
00290     int r, c;
00291     void *p;
00292     const QAbstractItemModel *m;
00293 };
00294 
00298 QModelIndex KIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const
00299 {
00300     if (!sourceModel() || !proxyIndex.isValid())
00301         return QModelIndex();
00302     Q_ASSERT(proxyIndex.model() == this);
00303     return SourceModelIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer(), sourceModel());
00304 }
00305 
00309 QModelIndexList KIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
00310 {
00311     Q_ASSERT(start.isValid() ? start.model() == this : true);
00312     if (!sourceModel())
00313         return QModelIndexList();
00314 
00315     const QModelIndexList sourceList = sourceModel()->match(mapToSource(start), role, value, hits, flags);
00316     QModelIndexList::const_iterator it = sourceList.constBegin();
00317     const QModelIndexList::const_iterator end = sourceList.constEnd();
00318     QModelIndexList proxyList;
00319     for ( ; it != end; ++it)
00320         proxyList.append(mapFromSource(*it));
00321     return proxyList;
00322 }
00323 
00327 QStringList KIdentityProxyModel::mimeTypes() const
00328 {
00329     if (sourceModel())
00330         return sourceModel()->mimeTypes();
00331     else
00332         return QAbstractProxyModel::mimeTypes();
00333 }
00334 
00335 QMimeData* KIdentityProxyModel::mimeData(const QModelIndexList& indexes) const
00336 {
00337     if (!sourceModel())
00338         return QAbstractProxyModel::mimeData(indexes);
00339 
00340     QModelIndexList proxyIndexes;
00341     foreach(const QModelIndex &index, indexes)
00342         proxyIndexes.append(mapToSource(index));
00343 
00344     return sourceModel()->mimeData(proxyIndexes);
00345 }
00346 
00347 
00351 QModelIndex KIdentityProxyModel::parent(const QModelIndex& child) const
00352 {
00353     if (!sourceModel())
00354         return QModelIndex();
00355 
00356     Q_ASSERT(child.isValid() ? child.model() == this : true);
00357     const QModelIndex sourceIndex = mapToSource(child);
00358     const QModelIndex sourceParent = sourceIndex.parent();
00359     return mapFromSource(sourceParent);
00360 }
00361 
00365 bool KIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent)
00366 {
00367     if (!sourceModel())
00368         return false;
00369 
00370     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00371     return sourceModel()->removeColumns(column, count, mapToSource(parent));
00372 }
00373 
00377 bool KIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent)
00378 {
00379     if (!sourceModel())
00380         return false;
00381 
00382     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00383     return sourceModel()->removeRows(row, count, mapToSource(parent));
00384 }
00385 
00389 int KIdentityProxyModel::rowCount(const QModelIndex& parent) const
00390 {
00391     if (!sourceModel())
00392         return 0;
00393     Q_ASSERT(parent.isValid() ? parent.model() == this : true);
00394     return sourceModel()->rowCount(mapToSource(parent));
00395 }
00396 
00400 void KIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
00401 {
00402     beginResetModel();
00403 
00404     if (sourceModel) {
00405         disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
00406                    this, SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
00407         disconnect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
00408                    this, SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
00409         disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
00410                    this, SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
00411         disconnect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
00412                    this, SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
00413         disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
00414                    this, SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
00415         disconnect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
00416                    this, SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
00417         disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
00418                    this, SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
00419         disconnect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
00420                    this, SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
00421         disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
00422                    this, SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
00423         disconnect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
00424                    this, SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
00425         disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
00426                    this, SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
00427         disconnect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
00428                    this, SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
00429         disconnect(sourceModel, SIGNAL(modelAboutToBeReset()),
00430                    this, SLOT(_k_sourceModelAboutToBeReset()));
00431 //        disconnect(sourceModel, SIGNAL(internalDataReset()),
00432 //                   this, SLOT(resetInternalData()));
00433         disconnect(sourceModel, SIGNAL(modelReset()),
00434                    this, SLOT(_k_sourceModelReset()));
00435         disconnect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
00436                    this, SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
00437         disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
00438                    this, SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
00439         disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
00440                    this, SLOT(_k_sourceLayoutAboutToBeChanged()));
00441         disconnect(sourceModel, SIGNAL(layoutChanged()),
00442                    this, SLOT(_k_sourceLayoutChanged()));
00443 //         disconnect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
00444 //                    this, SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
00445 //         disconnect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
00446 //                    this, SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
00447         disconnect(sourceModel, SIGNAL(destroyed()),
00448                    this, SLOT(_k_sourceModelDestroyed()));
00449     }
00450 
00451     QAbstractProxyModel::setSourceModel(sourceModel);
00452 
00453     if (sourceModel) {
00454         connect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
00455                 SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
00456         connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
00457                 SLOT(_k_sourceRowsInserted(QModelIndex,int,int)));
00458         connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
00459                 SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
00460         connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
00461                 SLOT(_k_sourceRowsRemoved(QModelIndex,int,int)));
00462         connect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
00463                 SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
00464         connect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
00465                 SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
00466         connect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
00467                 SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
00468         connect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
00469                 SLOT(_k_sourceColumnsInserted(QModelIndex,int,int)));
00470         connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
00471                 SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
00472         connect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
00473                 SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int)));
00474         connect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
00475                 SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
00476         connect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
00477                 SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)));
00478         connect(sourceModel, SIGNAL(modelAboutToBeReset()),
00479                 SLOT(_k_sourceModelAboutToBeReset()));
00480 //        connect(sourceModel, SIGNAL(internalDataReset()),
00481 //                SLOT(resetInternalData()));
00482         connect(sourceModel, SIGNAL(modelReset()),
00483                 SLOT(_k_sourceModelReset()));
00484         connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
00485                 SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex)));
00486         connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
00487                 SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int)));
00488         connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
00489                 SLOT(_k_sourceLayoutAboutToBeChanged()));
00490         connect(sourceModel, SIGNAL(layoutChanged()),
00491                 SLOT(_k_sourceLayoutChanged()));
00492         // Hopefully this will be in Qt4.8
00493 //         connect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)),
00494 //                 SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)));
00495 //         connect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)),
00496 //                 SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex)));
00497         connect(sourceModel, SIGNAL(destroyed()),
00498                 SLOT(_k_sourceModelDestroyed()));
00499     }
00500 
00501     endResetModel();
00502 }
00503 
00504 Qt::DropActions KIdentityProxyModel::supportedDropActions() const
00505 {
00506     if (sourceModel())
00507         return sourceModel()->supportedDropActions();
00508     else
00509         return QAbstractProxyModel::supportedDropActions();
00510 }
00511 
00512 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
00513 {
00514     Q_Q(KIdentityProxyModel);
00515     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00516     q->beginInsertColumns(q->mapFromSource(parent), start, end);
00517 }
00518 
00519 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00520 {
00521     Q_Q(KIdentityProxyModel);
00522     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00523     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00524     q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
00525 }
00526 
00527 void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
00528 {
00529     Q_Q(KIdentityProxyModel);
00530     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00531     q->beginRemoveColumns(q->mapFromSource(parent), start, end);
00532 }
00533 
00534 void KIdentityProxyModelPrivate::_k_sourceColumnsInserted(const QModelIndex &parent, int start, int end)
00535 {
00536     Q_Q(KIdentityProxyModel);
00537     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00538     Q_UNUSED(parent)
00539     Q_UNUSED(start)
00540     Q_UNUSED(end)
00541     q->endInsertColumns();
00542 }
00543 
00544 void KIdentityProxyModelPrivate::_k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00545 {
00546     Q_Q(KIdentityProxyModel);
00547     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00548     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00549     Q_UNUSED(sourceParent)
00550     Q_UNUSED(sourceStart)
00551     Q_UNUSED(sourceEnd)
00552     Q_UNUSED(destParent)
00553     Q_UNUSED(dest)
00554     q->endMoveColumns();
00555 }
00556 
00557 void KIdentityProxyModelPrivate::_k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end)
00558 {
00559     Q_Q(KIdentityProxyModel);
00560     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00561     Q_UNUSED(parent)
00562     Q_UNUSED(start)
00563     Q_UNUSED(end)
00564     q->endRemoveColumns();
00565 }
00566 
00567 void KIdentityProxyModelPrivate::_k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
00568 {
00569     Q_Q(KIdentityProxyModel);
00570     Q_ASSERT(topLeft.model() == q->sourceModel());
00571     Q_ASSERT(bottomRight.model() == q->sourceModel());
00572     q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight));
00573 }
00574 
00575 void KIdentityProxyModelPrivate::_k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)
00576 {
00577     Q_Q(KIdentityProxyModel);
00578     q->headerDataChanged(orientation, first, last);
00579 }
00580 
00581 void KIdentityProxyModelPrivate::_k_sourceLayoutAboutToBeChanged()
00582 {
00583     if (ignoreNextLayoutAboutToBeChanged)
00584         return;
00585 
00586     Q_Q(KIdentityProxyModel);
00587 
00588     q->layoutAboutToBeChanged();
00589 
00590     Q_FOREACH(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
00591         proxyIndexes << proxyPersistentIndex;
00592         Q_ASSERT(proxyPersistentIndex.isValid());
00593         const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
00594         Q_ASSERT(srcPersistentIndex.isValid());
00595         layoutChangePersistentIndexes << srcPersistentIndex;
00596     }
00597 }
00598 
00599 void KIdentityProxyModelPrivate::_k_sourceLayoutChanged()
00600 {
00601     if (ignoreNextLayoutChanged)
00602         return;
00603 
00604     Q_Q(KIdentityProxyModel);
00605 
00606     // We need to ensure that we don't modify persistent model indexes whose
00607     // column lies outside the source model. For example, KPIM::StatisticsProxyModel
00608     // adds additional columns and manages their persistent indexes.
00609     // We need to avoid calling changePersistentIndex with those.
00610     const int columnCount = q->sourceModel()->columnCount();
00611     for (int i = 0; i < proxyIndexes.size(); ++i) {
00612         const QModelIndex oldProxyIndex = proxyIndexes.at(i);
00613         if (oldProxyIndex.column() < columnCount)
00614             q->changePersistentIndex(oldProxyIndex, q->mapFromSource(layoutChangePersistentIndexes.at(i)));
00615     }
00616 
00617     layoutChangePersistentIndexes.clear();
00618     proxyIndexes.clear();
00619 
00620     q->layoutChanged();
00621 }
00622 
00623 
00624 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2)
00625 {
00626     Q_Q(KIdentityProxyModel);
00627     Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
00628     Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
00629 
00630 
00631     ignoreNextLayoutAboutToBeChanged = true;
00632 
00633     const QModelIndex proxyParent1 = q->mapFromSource(parent1);
00634     const QModelIndex proxyParent2 = q->mapFromSource(parent2);
00635     //emit q->childrenLayoutsAboutToBeChanged(proxyParent1, proxyParent2);
00636     emit q->layoutAboutToBeChanged();
00637 
00638     if (q->persistentIndexList().isEmpty())
00639         return;
00640 
00641     Q_FOREACH(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) {
00642         const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex);
00643         Q_ASSERT(proxyPersistentIndex.isValid());
00644         Q_ASSERT(srcPersistentIndex.isValid());
00645         const QModelIndex idxParent = srcPersistentIndex.parent();
00646         if (idxParent != parent1 && idxParent != parent2)
00647             continue;
00648         proxyIndexes << proxyPersistentIndex;
00649         layoutChangePersistentIndexes << srcPersistentIndex;
00650     }
00651 }
00652 
00653 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2)
00654 {
00655     Q_Q(KIdentityProxyModel);
00656     Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true);
00657     Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true);
00658 
00659     ignoreNextLayoutChanged = true;
00660 
00661     QModelIndexList oldList, newList;
00662     for( int i = 0; i < layoutChangePersistentIndexes.size(); ++i) {
00663       const QModelIndex srcIdx = layoutChangePersistentIndexes.at(i);
00664       const QModelIndex oldProxyIdx = proxyIndexes.at(i);
00665       oldList << oldProxyIdx;
00666       newList << q->mapFromSource(srcIdx);
00667     }
00668     q->changePersistentIndexList(oldList, newList);
00669     layoutChangePersistentIndexes.clear();
00670     proxyIndexes.clear();
00671 
00672     const QModelIndex proxyParent1 = q->mapFromSource(parent1);
00673     const QModelIndex proxyParent2 = q->mapFromSource(parent2);
00674 //     emit q->childrenLayoutsChanged(proxyParent1, proxyParent2);
00675     emit q->layoutChanged();
00676 }
00677 
00678 void KIdentityProxyModelPrivate::_k_sourceModelAboutToBeReset()
00679 {
00680     Q_Q(KIdentityProxyModel);
00681     q->beginResetModel();
00682 }
00683 
00684 void KIdentityProxyModelPrivate::_k_sourceModelReset()
00685 {
00686     Q_Q(KIdentityProxyModel);
00687     q->endResetModel();
00688 }
00689 
00690 void KIdentityProxyModelPrivate::_k_sourceModelDestroyed()
00691 {
00692 //   Q_Q(KIdentityProxyModel);
00693 //   q->endResetModel();
00694 }
00695 
00696 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
00697 {
00698     Q_Q(KIdentityProxyModel);
00699     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00700     q->beginInsertRows(q->mapFromSource(parent), start, end);
00701 }
00702 
00703 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00704 {
00705     Q_Q(KIdentityProxyModel);
00706     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00707     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00708     q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest);
00709 }
00710 
00711 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
00712 {
00713     Q_Q(KIdentityProxyModel);
00714     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00715     q->beginRemoveRows(q->mapFromSource(parent), start, end);
00716 }
00717 
00718 void KIdentityProxyModelPrivate::_k_sourceRowsInserted(const QModelIndex &parent, int start, int end)
00719 {
00720     Q_Q(KIdentityProxyModel);
00721     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00722     Q_UNUSED(parent)
00723     Q_UNUSED(start)
00724     Q_UNUSED(end)
00725     q->endInsertRows();
00726 }
00727 
00728 void KIdentityProxyModelPrivate::_k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
00729 {
00730     Q_Q(KIdentityProxyModel);
00731     Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true);
00732     Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true);
00733     Q_UNUSED(sourceParent)
00734     Q_UNUSED(sourceStart)
00735     Q_UNUSED(sourceEnd)
00736     Q_UNUSED(destParent)
00737     Q_UNUSED(dest)
00738     q->endMoveRows();
00739 }
00740 
00741 void KIdentityProxyModelPrivate::_k_sourceRowsRemoved(const QModelIndex &parent, int start, int end)
00742 {
00743     Q_Q(KIdentityProxyModel);
00744     Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
00745     Q_UNUSED(parent)
00746     Q_UNUSED(start)
00747     Q_UNUSED(end)
00748     q->endRemoveRows();
00749 }
00750 
00756 void KIdentityProxyModel::resetInternalData()
00757 {
00758 
00759 }
00760 
00761 #include "kidentityproxymodel.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:53:03 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.8.3 API Reference

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