2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * Based on the Itemviews NG project from Trolltech Labs
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #ifndef KITEMLISTSELECTIONMANAGER_H
10 #define KITEMLISTSELECTIONMANAGER_H
12 #include "dolphin_export.h"
13 #include "kitemviews/kitemmodelbase.h"
14 #include "kitemviews/kitemset.h"
21 * @brief Allows to select and deselect items of a KItemListView.
23 class DOLPHIN_EXPORT KItemListSelectionManager
: public QObject
27 enum RangesRemovingBehaviour
{ DiscardRemovedIndex
, AdjustRemovedIndex
};
30 enum SelectionMode
{ Select
, Deselect
, Toggle
};
32 explicit KItemListSelectionManager(QObject
*parent
= nullptr);
33 ~KItemListSelectionManager() override
;
35 void setCurrentItem(int current
);
36 int currentItem() const;
38 void setSelectedItems(const KItemSet
&items
);
39 KItemSet
selectedItems() const;
40 bool isSelected(int index
) const;
41 bool hasSelection() const;
43 void setSelected(int index
, int count
= 1, SelectionMode mode
= Select
);
47 * setSelected(index, count);
48 * but emitting once only selectionChanged signal
50 void replaceSelection(int index
, int count
= 1);
51 void clearSelection();
53 void beginAnchoredSelection(int anchor
);
54 void endAnchoredSelection();
55 bool isAnchoredSelectionActive() const;
57 KItemModelBase
*model() const;
60 void currentChanged(int current
, int previous
);
61 void selectionChanged(const KItemSet
¤t
, const KItemSet
&previous
);
64 void setModel(KItemModelBase
*model
);
65 void itemsInserted(const KItemRangeList
&itemRanges
);
66 void itemsRemoved(const KItemRangeList
&itemRanges
);
67 void itemsMoved(const KItemRange
&itemRange
, const QList
<int> &movedToIndexes
);
70 * Helper method for itemsRemoved. Returns the changed index after removing
71 * the given range. If the index is part of the range, -1 will be returned.
73 int indexAfterRangesRemoving(int index
, const KItemRangeList
&itemRanges
, const RangesRemovingBehaviour behaviour
) const;
78 KItemSet m_selectedItems
;
79 bool m_isAnchoredSelectionActive
;
81 KItemModelBase
*m_model
;
83 friend class KItemListController
; // Calls setModel()
84 friend class KItemListView
; // Calls itemsInserted(), itemsRemoved() and itemsMoved()
85 friend class KItemListSelectionManagerTest
;