X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/d0e7eabcaa259eeef14fa9c29b36cfefc46f8143..d05e966ef46363efc77699c85d51a19b75c89fff:/src/kcategorizedview.cpp diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp index bb014b31e..7d717abd1 100644 --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -414,6 +414,36 @@ void KCategorizedView::Private::drawDraggedItems(QPainter *painter) } } +void KCategorizedView::Private::layoutChanged(bool forceItemReload) +{ + if ((listView->viewMode() == KCategorizedView::IconMode) && proxyModel && + categoryDrawer && proxyModel->isCategorizedModel() && + ((forceItemReload || + (modelSortRole != proxyModel->sortRole()) || + (modelSortColumn != proxyModel->sortColumn()) || + (modelSortOrder != proxyModel->sortOrder()) || + (modelLastRowCount != proxyModel->rowCount()) || + (modelCategorized != proxyModel->isCategorizedModel())))) + { + // Force the view to update all elements + listView->rowsInsertedArtifficial(QModelIndex(), 0, proxyModel->rowCount() - 1); + + if (!forceItemReload) + { + modelSortRole = proxyModel->sortRole(); + modelSortColumn = proxyModel->sortColumn(); + modelSortOrder = proxyModel->sortOrder(); + modelLastRowCount = proxyModel->rowCount(); + modelCategorized = proxyModel->isCategorizedModel(); + } + } + else if ((listView->viewMode() == KCategorizedView::IconMode) && proxyModel && + categoryDrawer && proxyModel->isCategorizedModel()) + { + updateScrollbars(); + } +} + void KCategorizedView::Private::drawDraggedItems() { QRect rectToUpdate; @@ -456,7 +486,7 @@ void KCategorizedView::setGridSize(const QSize &size) { QListView::setGridSize(size); - slotLayoutChanged(); + d->layoutChanged(true); } void KCategorizedView::setModel(QAbstractItemModel *model) @@ -476,10 +506,6 @@ void KCategorizedView::setModel(QAbstractItemModel *model) if (d->proxyModel) { - QObject::disconnect(d->proxyModel, - SIGNAL(layoutAboutToBeChanged()), - this, SLOT(slotLayoutAboutToBeChanged())); - QObject::disconnect(d->proxyModel, SIGNAL(layoutChanged()), this, SLOT(slotLayoutChanged())); @@ -487,6 +513,10 @@ void KCategorizedView::setModel(QAbstractItemModel *model) QObject::disconnect(d->proxyModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotLayoutChanged())); + + QObject::disconnect(d->proxyModel, + SIGNAL(rowsRemoved(QModelIndex,int,int)), + this, SLOT(rowsRemoved(QModelIndex,int,int))); } QListView::setModel(model); @@ -498,10 +528,8 @@ void KCategorizedView::setModel(QAbstractItemModel *model) d->modelSortRole = d->proxyModel->sortRole(); d->modelSortColumn = d->proxyModel->sortColumn(); d->modelSortOrder = d->proxyModel->sortOrder(); - - QObject::connect(d->proxyModel, - SIGNAL(layoutAboutToBeChanged()), - this, SLOT(slotLayoutAboutToBeChanged())); + d->modelLastRowCount = d->proxyModel->rowCount(); + d->modelCategorized = d->proxyModel->isCategorizedModel(); QObject::connect(d->proxyModel, SIGNAL(layoutChanged()), @@ -510,6 +538,19 @@ void KCategorizedView::setModel(QAbstractItemModel *model) QObject::connect(d->proxyModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotLayoutChanged())); + + QObject::connect(d->proxyModel, + SIGNAL(rowsRemoved(QModelIndex,int,int)), + this, SLOT(rowsRemoved(QModelIndex,int,int))); + + if (d->proxyModel->rowCount()) + { + d->layoutChanged(true); + } + } + else + { + d->modelCategorized = false; } } @@ -551,10 +592,6 @@ void KCategorizedView::setCategoryDrawer(KCategoryDrawer *categoryDrawer) if (!categoryDrawer && d->proxyModel) { - QObject::disconnect(d->proxyModel, - SIGNAL(layoutAboutToBeChanged()), - this, SLOT(slotLayoutAboutToBeChanged())); - QObject::disconnect(d->proxyModel, SIGNAL(layoutChanged()), this, SLOT(slotLayoutChanged())); @@ -562,13 +599,13 @@ void KCategorizedView::setCategoryDrawer(KCategoryDrawer *categoryDrawer) QObject::disconnect(d->proxyModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotLayoutChanged())); + + QObject::disconnect(d->proxyModel, + SIGNAL(rowsRemoved(QModelIndex,int,int)), + this, SLOT(rowsRemoved(QModelIndex,int,int))); } else if (categoryDrawer && d->proxyModel) { - QObject::connect(d->proxyModel, - SIGNAL(layoutAboutToBeChanged()), - this, SLOT(slotLayoutAboutToBeChanged())); - QObject::connect(d->proxyModel, SIGNAL(layoutChanged()), this, SLOT(slotLayoutChanged())); @@ -576,6 +613,10 @@ void KCategorizedView::setCategoryDrawer(KCategoryDrawer *categoryDrawer) QObject::connect(d->proxyModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotLayoutChanged())); + + QObject::connect(d->proxyModel, + SIGNAL(rowsRemoved(QModelIndex,int,int)), + this, SLOT(rowsRemoved(QModelIndex,int,int))); } d->categoryDrawer = categoryDrawer; @@ -584,7 +625,10 @@ void KCategorizedView::setCategoryDrawer(KCategoryDrawer *categoryDrawer) { if (d->proxyModel) { - rowsInserted(QModelIndex(), 0, d->proxyModel->rowCount() - 1); + if (d->proxyModel->rowCount()) + { + d->layoutChanged(true); + } } } else @@ -702,6 +746,7 @@ void KCategorizedView::paintEvent(QPaintEvent *event) // Redraw categories QStyleOptionViewItem otherOption; + bool intersectedInThePast = false; foreach (const QString &category, d->categories) { otherOption = option; @@ -710,11 +755,18 @@ void KCategorizedView::paintEvent(QPaintEvent *event) if (otherOption.rect.intersects(area)) { + intersectedInThePast = true; + QModelIndex indexToDraw = d->proxyModel->index(d->categoriesIndexes[category][0].row(), d->proxyModel->sortColumn()); d->drawNewCategory(indexToDraw, d->proxyModel->sortRole(), otherOption, &painter); } + else if (intersectedInThePast) + { + break; // the visible area has been finished, we don't need to keep asking, the rest won't intersect + // this is doable because we know that categories are correctly ordered on the list + } } if (d->mouseButtonPressed && !d->isDragging) @@ -1225,8 +1277,8 @@ void KCategorizedView::rowsInserted(const QModelIndex &parent, } void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent, - int start, - int end) + int start, + int end) { Q_UNUSED(parent); @@ -1249,25 +1301,24 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent, return; } - // Add all elements mapped to the source model - for (int k = 0; k < d->proxyModel->rowCount(); k++) - { - d->biggestItemSize = QSize(qMax(sizeHintForIndex(d->proxyModel->index(k, 0)).width(), - d->biggestItemSize.width()), - qMax(sizeHintForIndex(d->proxyModel->index(k, 0)).height(), - d->biggestItemSize.height())); - - d->modelIndexList << d->proxyModel->index(k, d->proxyModel->sortColumn()); - } - - // Explore categories - QString prevCategory = d->proxyModel->data(d->modelIndexList[0], KCategorizedSortFilterProxyModel::CategoryRole).toString(); + // Add all elements mapped to the source model and explore categories + QString prevCategory = d->proxyModel->data(d->proxyModel->index(0, d->proxyModel->sortColumn()), KCategorizedSortFilterProxyModel::CategoryRole).toString(); QString lastCategory = prevCategory; QModelIndexList modelIndexList; struct Private::ElementInfo elementInfo; int offset = -1; - foreach (const QModelIndex &index, d->modelIndexList) + for (int k = 0; k < d->proxyModel->rowCount(); ++k) { + QModelIndex index = d->proxyModel->index(k, d->proxyModel->sortColumn()); + QModelIndex indexSize = d->proxyModel->index(k, 0); + + d->biggestItemSize = QSize(qMax(sizeHintForIndex(indexSize).width(), + d->biggestItemSize.width()), + qMax(sizeHintForIndex(indexSize).height(), + d->biggestItemSize.height())); + + d->modelIndexList << index; + lastCategory = d->proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString(); elementInfo.category = lastCategory; @@ -1299,14 +1350,14 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent, } void KCategorizedView::rowsRemoved(const QModelIndex &parent, - int start, - int end) + int start, + int end) { if ((viewMode() == KCategorizedView::IconMode) && d->proxyModel && d->categoryDrawer && d->proxyModel->isCategorizedModel()) { // Force the view to update all elements - rowsInsertedArtifficial(parent, start, end); + rowsInsertedArtifficial(QModelIndex(), 0, d->proxyModel->rowCount() - 1); } } @@ -1324,32 +1375,9 @@ void KCategorizedView::updateGeometries() QAbstractItemView::updateGeometries(); } -void KCategorizedView::slotLayoutAboutToBeChanged() -{ - if ((viewMode() == KCategorizedView::IconMode) && d->proxyModel && - d->categoryDrawer && d->proxyModel->isCategorizedModel()) - { - d->modelSortRole = d->proxyModel->sortRole(); - d->modelSortColumn = d->proxyModel->sortColumn(); - d->modelSortOrder = d->proxyModel->sortOrder(); - } -} - void KCategorizedView::slotLayoutChanged() { - if ((viewMode() == KCategorizedView::IconMode) && d->proxyModel && - d->categoryDrawer && d->proxyModel->isCategorizedModel() && - ((d->modelSortRole != d->proxyModel->sortRole()) || - (d->modelSortColumn != d->proxyModel->sortColumn()) || - (d->modelSortOrder != d->proxyModel->sortOrder()))) - { - // Force the view to update all elements - rowsInsertedArtifficial(QModelIndex(), 0, d->proxyModel->rowCount() - 1); - - d->modelSortRole = d->proxyModel->sortRole(); - d->modelSortColumn = d->proxyModel->sortColumn(); - d->modelSortOrder = d->proxyModel->sortOrder(); - } + d->layoutChanged(); } #include "kcategorizedview.moc"