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(const QModelIndex &, int, int)), 00406 this, SLOT(_k_sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); 00407 disconnect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), 00408 this, SLOT(_k_sourceRowsInserted(const QModelIndex &, int, int))); 00409 disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), 00410 this, SLOT(_k_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); 00411 disconnect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), 00412 this, SLOT(_k_sourceRowsRemoved(const QModelIndex &, int, int))); 00413 disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00414 this, SLOT(_k_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); 00415 disconnect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00416 this, SLOT(_k_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); 00417 disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), 00418 this, SLOT(_k_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int))); 00419 disconnect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)), 00420 this, SLOT(_k_sourceColumnsInserted(const QModelIndex &, int, int))); 00421 disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), 00422 this, SLOT(_k_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int))); 00423 disconnect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), 00424 this, SLOT(_k_sourceColumnsRemoved(const QModelIndex &, int, int))); 00425 disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00426 this, SLOT(_k_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); 00427 disconnect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00428 this, SLOT(_k_sourceColumnsMoved(const QModelIndex &, int, int, const 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(const QModelIndex &, const QModelIndex &)), 00436 this, SLOT(_k_sourceDataChanged(const QModelIndex &, const 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(const QModelIndex &, int, int)), 00455 SLOT(_k_sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); 00456 connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), 00457 SLOT(_k_sourceRowsInserted(const QModelIndex &, int, int))); 00458 connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), 00459 SLOT(_k_sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); 00460 connect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), 00461 SLOT(_k_sourceRowsRemoved(const QModelIndex &, int, int))); 00462 connect(sourceModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00463 SLOT(_k_sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); 00464 connect(sourceModel, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00465 SLOT(_k_sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))); 00466 connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), 00467 SLOT(_k_sourceColumnsAboutToBeInserted(const QModelIndex &, int, int))); 00468 connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)), 00469 SLOT(_k_sourceColumnsInserted(const QModelIndex &, int, int))); 00470 connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), 00471 SLOT(_k_sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int))); 00472 connect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), 00473 SLOT(_k_sourceColumnsRemoved(const QModelIndex &, int, int))); 00474 connect(sourceModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00475 SLOT(_k_sourceColumnsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))); 00476 connect(sourceModel, SIGNAL(columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), 00477 SLOT(_k_sourceColumnsMoved(const QModelIndex &, int, int, const 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(const QModelIndex &, const QModelIndex &)), 00485 SLOT(_k_sourceDataChanged(const QModelIndex &, const 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 for (int i = 0; i < proxyIndexes.size(); ++i) { 00607 q->changePersistentIndex(proxyIndexes.at(i), q->mapFromSource(layoutChangePersistentIndexes.at(i))); 00608 } 00609 00610 layoutChangePersistentIndexes.clear(); 00611 proxyIndexes.clear(); 00612 00613 q->layoutChanged(); 00614 } 00615 00616 00617 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2) 00618 { 00619 Q_Q(KIdentityProxyModel); 00620 Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true); 00621 Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true); 00622 00623 00624 ignoreNextLayoutAboutToBeChanged = true; 00625 00626 const QModelIndex proxyParent1 = q->mapFromSource(parent1); 00627 const QModelIndex proxyParent2 = q->mapFromSource(parent2); 00628 //emit q->childrenLayoutsAboutToBeChanged(proxyParent1, proxyParent2); 00629 emit q->layoutAboutToBeChanged(); 00630 00631 if (q->persistentIndexList().isEmpty()) 00632 return; 00633 00634 Q_FOREACH(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) { 00635 const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); 00636 Q_ASSERT(proxyPersistentIndex.isValid()); 00637 Q_ASSERT(srcPersistentIndex.isValid()); 00638 const QModelIndex idxParent = srcPersistentIndex.parent(); 00639 if (idxParent != parent1 && idxParent != parent2) 00640 continue; 00641 proxyIndexes << proxyPersistentIndex; 00642 layoutChangePersistentIndexes << srcPersistentIndex; 00643 } 00644 } 00645 00646 void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2) 00647 { 00648 Q_Q(KIdentityProxyModel); 00649 Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true); 00650 Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true); 00651 00652 ignoreNextLayoutChanged = true; 00653 00654 QModelIndexList oldList, newList; 00655 for( int i = 0; i < layoutChangePersistentIndexes.size(); ++i) { 00656 const QModelIndex srcIdx = layoutChangePersistentIndexes.at(i); 00657 const QModelIndex oldProxyIdx = proxyIndexes.at(i); 00658 oldList << oldProxyIdx; 00659 newList << q->mapFromSource(srcIdx); 00660 } 00661 q->changePersistentIndexList(oldList, newList); 00662 layoutChangePersistentIndexes.clear(); 00663 proxyIndexes.clear(); 00664 00665 const QModelIndex proxyParent1 = q->mapFromSource(parent1); 00666 const QModelIndex proxyParent2 = q->mapFromSource(parent2); 00667 // emit q->childrenLayoutsChanged(proxyParent1, proxyParent2); 00668 emit q->layoutChanged(); 00669 } 00670 00671 void KIdentityProxyModelPrivate::_k_sourceModelAboutToBeReset() 00672 { 00673 Q_Q(KIdentityProxyModel); 00674 q->beginResetModel(); 00675 } 00676 00677 void KIdentityProxyModelPrivate::_k_sourceModelReset() 00678 { 00679 Q_Q(KIdentityProxyModel); 00680 q->endResetModel(); 00681 } 00682 00683 void KIdentityProxyModelPrivate::_k_sourceModelDestroyed() 00684 { 00685 // Q_Q(KIdentityProxyModel); 00686 // q->endResetModel(); 00687 } 00688 00689 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end) 00690 { 00691 Q_Q(KIdentityProxyModel); 00692 Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); 00693 q->beginInsertRows(q->mapFromSource(parent), start, end); 00694 } 00695 00696 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) 00697 { 00698 Q_Q(KIdentityProxyModel); 00699 Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true); 00700 Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true); 00701 q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest); 00702 } 00703 00704 void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) 00705 { 00706 Q_Q(KIdentityProxyModel); 00707 Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); 00708 q->beginRemoveRows(q->mapFromSource(parent), start, end); 00709 } 00710 00711 void KIdentityProxyModelPrivate::_k_sourceRowsInserted(const QModelIndex &parent, int start, int end) 00712 { 00713 Q_Q(KIdentityProxyModel); 00714 Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); 00715 Q_UNUSED(parent) 00716 Q_UNUSED(start) 00717 Q_UNUSED(end) 00718 q->endInsertRows(); 00719 } 00720 00721 void KIdentityProxyModelPrivate::_k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) 00722 { 00723 Q_Q(KIdentityProxyModel); 00724 Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true); 00725 Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true); 00726 Q_UNUSED(sourceParent) 00727 Q_UNUSED(sourceStart) 00728 Q_UNUSED(sourceEnd) 00729 Q_UNUSED(destParent) 00730 Q_UNUSED(dest) 00731 q->endMoveRows(); 00732 } 00733 00734 void KIdentityProxyModelPrivate::_k_sourceRowsRemoved(const QModelIndex &parent, int start, int end) 00735 { 00736 Q_Q(KIdentityProxyModel); 00737 Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); 00738 Q_UNUSED(parent) 00739 Q_UNUSED(start) 00740 Q_UNUSED(end) 00741 q->endRemoveRows(); 00742 } 00743 00749 void KIdentityProxyModel::resetInternalData() 00750 { 00751 00752 } 00753 00754 #include "kidentityproxymodel.moc"
KDE 4.7 API Reference