diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-07-11 14:20:40 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-07-11 14:20:40 (GMT) |
commit | cbf18d5b24e9ae541bc7e6a7b6698666cce30478 (patch) | |
tree | 1351ac16edafb3550032e739ae4cd265a1fbd2d1 /src/gui | |
parent | 69a3c65d177a4a6ecc3d3fd63455dcd53d62b75f (diff) | |
download | Qt-cbf18d5b24e9ae541bc7e6a7b6698666cce30478.zip Qt-cbf18d5b24e9ae541bc7e6a7b6698666cce30478.tar.gz Qt-cbf18d5b24e9ae541bc7e6a7b6698666cce30478.tar.bz2 |
ItemViews selection: improve performance of QItemSelection::indexes
On windows it makes it 2x faster
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/itemviews/qitemselectionmodel.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp index e4cb0f0..87825d9 100644 --- a/src/gui/itemviews/qitemselectionmodel.cpp +++ b/src/gui/itemviews/qitemselectionmodel.cpp @@ -270,24 +270,35 @@ QItemSelectionRange QItemSelectionRange::intersect(const QItemSelectionRange &ot */ -/*! - Returns the list of model index items stored in the selection. -*/ +/* + \internal -QModelIndexList QItemSelectionRange::indexes() const + utility function for getting the indexes from a range + it avoid concatenating list and works on one + */ + +static void indexesFromRange(const QItemSelectionRange &range, QModelIndexList &result) { - QModelIndex index; - QModelIndexList result; - if (isValid() && model()) { - for (int column = left(); column <= right(); ++column) { - for (int row = top(); row <= bottom(); ++row) { - index = model()->index(row, column, parent()); - Qt::ItemFlags flags = model()->flags(index); + if (range.isValid() && range.model()) { + for (int column = range.left(); column <= range.right(); ++column) { + for (int row = range.top(); row <= range.bottom(); ++row) { + QModelIndex index = range.model()->index(row, column, range.parent()); + Qt::ItemFlags flags = range.model()->flags(index); if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) result.append(index); } } } +} + +/*! + Returns the list of model index items stored in the selection. +*/ + +QModelIndexList QItemSelectionRange::indexes() const +{ + QModelIndexList result; + indexesFromRange(*this, result); return result; } @@ -404,7 +415,7 @@ QModelIndexList QItemSelection::indexes() const QModelIndexList result; QList<QItemSelectionRange>::const_iterator it = begin(); for (; it != end(); ++it) - result += (*it).indexes(); + indexesFromRange(*it, result); return result; } |