QTreeView: speedup isFirstColumnSpanned/setFirstColumnSpanned

Change container of spanningIndexes from QVector to QSet to speedup
the isFirstColumnSpanned/setFirstColumnSpanned. The order of the indexes
in the container is not needed and therefore QSet can be used here.
This also simplifies the code a little bit.

Task-number: QTBUG-66714
Change-Id: I1692ca1df751b2b8d26b607faf60ff2b94f6f964
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
bb10
Christian Ehrlicher 2018-03-03 20:11:24 +01:00
parent bdc36cef67
commit 442c47e132
2 changed files with 8 additions and 17 deletions

View File

@ -632,11 +632,8 @@ bool QTreeView::isFirstColumnSpanned(int row, const QModelIndex &parent) const
Q_D(const QTreeView);
if (d->spanningIndexes.isEmpty() || !d->model)
return false;
QModelIndex index = d->model->index(row, 0, parent);
for (int i = 0; i < d->spanningIndexes.count(); ++i)
if (d->spanningIndexes.at(i) == index)
return true;
return false;
const QModelIndex index = d->model->index(row, 0, parent);
return d->spanningIndexes.contains(index);
}
/*!
@ -653,20 +650,14 @@ void QTreeView::setFirstColumnSpanned(int row, const QModelIndex &parent, bool s
Q_D(QTreeView);
if (!d->model)
return;
QModelIndex index = d->model->index(row, 0, parent);
const QModelIndex index = d->model->index(row, 0, parent);
if (!index.isValid())
return;
if (span) {
QPersistentModelIndex persistent(index);
if (!d->spanningIndexes.contains(persistent))
d->spanningIndexes.append(persistent);
} else {
QPersistentModelIndex persistent(index);
int i = d->spanningIndexes.indexOf(persistent);
if (i >= 0)
d->spanningIndexes.remove(i);
}
if (span)
d->spanningIndexes.insert(index);
else
d->spanningIndexes.remove(index);
d->executePostedLayout();
int i = d->viewIndex(index);

View File

@ -247,7 +247,7 @@ public:
void updateIndentationFromStyle();
// used for spanning rows
QVector<QPersistentModelIndex> spanningIndexes;
QSet<QPersistentModelIndex> spanningIndexes;
// used for updating resized columns
int columnResizeTimerID;