Commit bbdf7d89 authored by Rafael Fernández López's avatar Rafael Fernández López
Browse files

Improve selection speed. I think we can still improve this a little bit, but I...

Improve selection speed. I think we can still improve this a little bit, but I think we can live with this speed for now

svn path=/trunk/KDE/kdebase/apps/; revision=679308
parent f2cb65db
......@@ -529,6 +529,7 @@ void KListView::reset()
d->elementDictionary.clear();
d->categoriesIndexes.clear();
d->categoriesPosition.clear();
d->isIndexSelected.clear(); // selection cache
d->categories.clear();
d->intersectedIndexes.clear();
d->sourceModelIndexList.clear();
......@@ -670,39 +671,83 @@ void KListView::setSelection(const QRect &rect,
return;
}
// FIXME: I have to rethink and rewrite this method (ereslibre)
if (flags & QItemSelectionModel::Clear)
{
selectionModel()->clear();
d->isIndexSelected.clear();
d->isTemporarySelected.clear();
}
QItemSelection selection;
QModelIndexList dirtyIndexes = d->intersectionSet(rect);
foreach (const QModelIndex &index, dirtyIndexes)
{
if (!d->mouseButtonPressed && rect.intersects(visualRect(index)))
{
selectionModel()->select(index, flags);
if (d->isIndexSelected.contains(index))
{
if (!d->isIndexSelected[index])
selection.select(index, index);
d->isIndexSelected[index] = true;
}
else
{
d->isIndexSelected.insert(index, true);
selection.select(index, index);
}
}
else
else if (d->mouseButtonPressed) // selection cache
{
selectionModel()->select(index, QItemSelectionModel::Select);
if (!d->isIndexSelected.contains(index) ||
(d->isIndexSelected.contains(index) && !d->isIndexSelected[index]))
{
if (d->isTemporarySelected.contains(index))
{
d->isTemporarySelected[index] = true;
}
else
{
d->isTemporarySelected.insert(index, true);
}
}
if (d->isIndexSelected.contains(index))
{
if (!d->isIndexSelected[index])
selection.select(index, index);
if (d->mouseButtonPressed)
d->tempSelected.append(index);
d->isIndexSelected[index] = true;
}
else
{
d->isIndexSelected.insert(index, true);
selection.select(index, index);
}
}
}
if (d->mouseButtonPressed)
QItemSelection deselect;
foreach (const QModelIndex &index, d->isIndexSelected.keys())
{
foreach (const QModelIndex &index, selectionModel()->selectedIndexes())
if (!rect.intersects(visualRect(index)))
{
if (!rect.intersects(visualRect(index)))
if (d->isTemporarySelected.contains(index) &&
d->isTemporarySelected[index])
{
selectionModel()->select(index, QItemSelectionModel::Deselect);
if (d->mouseButtonPressed)
{
d->tempSelected.removeAll(index);
}
deselect.select(index, index);
d->isTemporarySelected[index] = false;
d->isIndexSelected[index] = false;
}
}
}
if (selection.count())
selectionModel()->select(selection, QItemSelectionModel::Select);
if (deselect.count())
selectionModel()->select(deselect, QItemSelectionModel::Deselect);
}
void KListView::mouseMoveEvent(QMouseEvent *event)
......@@ -726,8 +771,6 @@ void KListView::mousePressEvent(QMouseEvent *event)
{
QListView::mousePressEvent(event);
d->tempSelected.clear();
if ((viewMode() == KListView::ListMode) || !d->proxyModel ||
!d->itemCategorizer)
{
......@@ -764,7 +807,7 @@ void KListView::mouseReleaseEvent(QMouseEvent *event)
event->accept();
// FIXME: I have to rethink and rewrite this method (ereslibre)
d->isTemporarySelected.clear(); // selection cache
QPoint initialPressPosition = viewport()->mapFromGlobal(QCursor::pos());
initialPressPosition.setY(initialPressPosition.y() + verticalOffset());
......@@ -772,28 +815,23 @@ void KListView::mouseReleaseEvent(QMouseEvent *event)
if (initialPressPosition == d->initialPressPosition)
{
QItemSelection selection;
foreach(const QString &category, d->categories)
{
if (d->categoryVisualRect(category).contains(event->pos()))
{
QModelIndex index;
QItemSelectionModel::SelectionFlag flag;
foreach (const QModelIndex &mappedIndex,
d->categoriesIndexes[category])
{
index = d->proxyModel->mapFromSource(mappedIndex);
if (selectionModel()->selectedIndexes().contains(index))
{
flag = QItemSelectionModel::Deselect;
}
else
{
flag = QItemSelectionModel::Select;
}
selectionModel()->select(index, flag);
selection.select(index, index);
}
selectionModel()->select(selection, QItemSelectionModel::Toggle);
break;
}
}
}
......@@ -849,6 +887,7 @@ void KListView::rowsInsertedArtifficial(const QModelIndex &parent,
d->elementDictionary.clear();
d->categoriesIndexes.clear();
d->categoriesPosition.clear();
d->isIndexSelected.clear(); // selection cache
d->categories.clear();
d->intersectedIndexes.clear();
d->sourceModelIndexList.clear();
......
......@@ -127,7 +127,8 @@ public:
QHash<QString, QRect> categoriesPosition;
QStringList categories;
QModelIndexList intersectedIndexes;
QModelIndexList tempSelected;
QHash<QModelIndex, bool> isIndexSelected; // selection cache
QHash<QModelIndex, bool> isTemporarySelected; // selection cache
// Attributes for speed reasons
KSortFilterProxyModel *proxyModel;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment