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

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