-
- Q_ASSERT(false);
- }
-
- // we've got a sorted list of ranges now. so we can easily check if there is a possibility to merge
- for(int i = newRanges.count() - 1; i > 0; i--) {
- _RangeRect &a = newRanges[i - 1];
- _RangeRect &b = newRanges[i];
- if(a.left != b.left || a.right != b.right)
- continue;
-
- if(a.bottom < b.top - 1) {
- continue;
- }
-
- // all merge checks passed!
- if(b.bottom > a.bottom) {
- a.bottom = b.bottom;
- a.bottomItem = b.bottomItem;
- } // otherwise b is totally enclosed in a -> nothing to do but drop b.
- newRanges.removeAt(i);
- }
-
- QItemSelection proxySelection;
- for(int i = 0; i < newRanges.count(); i++) {
- _RangeRect &r = newRanges[i];
- proxySelection << QItemSelectionRange(createIndex(r.top, r.left, r.topItem), createIndex(r.bottom, r.right, r.bottomItem));
- }
- return proxySelection;
-}
-
-QItemSelection FlatProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const {
- QItemSelection sourceSelection;
-
- for(int i = 0; i < proxySelection.count(); i++) {
- const QItemSelectionRange &range = proxySelection[i];
-
- SourceItem *topLeftItem = 0;
- SourceItem *bottomRightItem = 0;
- SourceItem *currentItem = static_cast<SourceItem *>(range.topLeft().internalPointer());
- int row = range.topLeft().row();
- int left = range.topLeft().column();
- int right = range.bottomRight().column();
- while(currentItem && row <= range.bottomRight().row()) {
- Q_ASSERT(currentItem->pos() == row);
- if(!topLeftItem)
- topLeftItem = currentItem;
-
- if(currentItem->parent() == topLeftItem->parent()) {
- bottomRightItem = currentItem;
- } else {
- Q_ASSERT(topLeftItem && bottomRightItem);
- sourceSelection << QItemSelectionRange(mapToSource(createIndex(topLeftItem->pos(), left, topLeftItem)), mapToSource(createIndex(bottomRightItem->pos(), right, bottomRightItem)));
- topLeftItem = 0;
- bottomRightItem = 0;
- }
-
- // update loop vars
- currentItem = currentItem->next();
- row++;
- }
-
- Q_ASSERT(topLeftItem && bottomRightItem); // there should be one range left.
- sourceSelection << QItemSelectionRange(mapToSource(createIndex(topLeftItem->pos(), left, topLeftItem)), mapToSource(createIndex(bottomRightItem->pos(), right, bottomRightItem)));
- }
-
- return sourceSelection;
-}
-
-void FlatProxyModel::setSourceModel(QAbstractItemModel *sourceModel) {
- if(QAbstractProxyModel::sourceModel()) {
- disconnect(QAbstractProxyModel::sourceModel(), 0, this, 0);
- }
-
- QAbstractProxyModel::setSourceModel(sourceModel);
-
- emit layoutAboutToBeChanged();
- removeSubTree(QModelIndex(), false /* don't emit removeRows() */);
- insertSubTree(QModelIndex(), false /* don't emit insertRows() */);
- emit layoutChanged();
-
- if(sourceModel) {
- connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),