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
{
39 explicit KItemListSelectionManager(QObject
* parent
= nullptr);
40 ~KItemListSelectionManager() override
;
42 void setCurrentItem(int current
);
43 int currentItem() const;
45 void setSelectedItems(const KItemSet
& items
);
46 KItemSet
selectedItems() const;
47 bool isSelected(int index
) const;
48 bool hasSelection() const;
50 void setSelected(int index
, int count
= 1, SelectionMode mode
= Select
);
54 * setSelected(index, count);
55 * but emitting once only selectionChanged signal
57 void replaceSelection(int index
, int count
= 1);
58 void clearSelection();
60 void beginAnchoredSelection(int anchor
);
61 void endAnchoredSelection();
62 bool isAnchoredSelectionActive() const;
64 KItemModelBase
* model() const;
67 void currentChanged(int current
, int previous
);
68 void selectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
71 void setModel(KItemModelBase
* model
);
72 void itemsInserted(const KItemRangeList
& itemRanges
);
73 void itemsRemoved(const KItemRangeList
& itemRanges
);
74 void itemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
78 * Helper method for itemsRemoved. Returns the changed index after removing
79 * the given range. If the index is part of the range, -1 will be returned.
81 int indexAfterRangesRemoving(int index
, const KItemRangeList
& itemRanges
, const RangesRemovingBehaviour behaviour
) const;
86 KItemSet m_selectedItems
;
87 bool m_isAnchoredSelectionActive
;
89 KItemModelBase
* m_model
;
91 friend class KItemListController
; // Calls setModel()
92 friend class KItemListView
; // Calls itemsInserted(), itemsRemoved() and itemsMoved()
93 friend class KItemListSelectionManagerTest
;