diff options
| author | Frank Reininghaus <[email protected]> | 2013-10-30 23:21:09 +0100 |
|---|---|---|
| committer | Frank Reininghaus <[email protected]> | 2013-10-30 23:22:23 +0100 |
| commit | fc2ab478989fb4effc14c06aa56fdb29d3143b35 (patch) | |
| tree | 1ab12809d805c06137d34a2b1fe088cdbb8b4edf /src/kitemviews/kitemlistselectionmanager.h | |
| parent | 903381a8982a0aefc7b1eba223f9ee38ded3f018 (diff) | |
Store the selected items in a more efficient way
Since Dolphin 2.0, we have stored the selected items in a QSet<int>,
which is neither space-efficient nor particularly fast when inserting
many items which are in a consecutive range.
This commit replaces the QSet<int> by a new class "KItemSet", which
stores the items in a sorted list of ranges. For each range, we only
store the first index and the length of the range, so we need a lot
less memory for most common selection patterns, and we also save quite
a few CPU cycles in many situations, because adding an item to the
KItemSet will in many cases not need a memory allocation at all, and
it's particularly easy when inserting sorted items into the KItemSet in
a row.
KItemSet contains a minimal subset of QSet's API which makes it
suitable as a drop-in replacement for our needs. It also has iterators,
such that the items can be iterated through easily, also with foreach.
One advantage of KItemSet compared to QSet<int> is that the items are
always iterated through in ascending order.
REVIEW: 113488
Diffstat (limited to 'src/kitemviews/kitemlistselectionmanager.h')
| -rw-r--r-- | src/kitemviews/kitemlistselectionmanager.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/kitemviews/kitemlistselectionmanager.h b/src/kitemviews/kitemlistselectionmanager.h index c89b8a4b8..c4decd39e 100644 --- a/src/kitemviews/kitemlistselectionmanager.h +++ b/src/kitemviews/kitemlistselectionmanager.h @@ -26,9 +26,9 @@ #include <libdolphin_export.h> #include <kitemviews/kitemmodelbase.h> +#include <kitemviews/kitemset.h> #include <QObject> -#include <QSet> class KItemModelBase; @@ -57,8 +57,8 @@ public: void setCurrentItem(int current); int currentItem() const; - void setSelectedItems(const QSet<int>& items); - QSet<int> selectedItems() const; + void setSelectedItems(const KItemSet& items); + KItemSet selectedItems() const; bool isSelected(int index) const; bool hasSelection() const; @@ -73,7 +73,7 @@ public: signals: void currentChanged(int current, int previous); - void selectionChanged(const QSet<int>& current, const QSet<int>& previous); + void selectionChanged(const KItemSet& current, const KItemSet& previous); private: void setModel(KItemModelBase* model); @@ -91,7 +91,7 @@ private: private: int m_currentItem; int m_anchorItem; - QSet<int> m_selectedItems; + KItemSet m_selectedItems; bool m_isAnchoredSelectionActive; KItemModelBase* m_model; |
